[Vm-dev] Is bytecodePrimMultiply correct?

Levente Uzonyi leves at elte.hu
Tue Oct 4 20:25:34 UTC 2011


On Tue, 4 Oct 2011, Stefan Marr wrote:

snip

> Lets look at some beautiful assembly :-/
>
> This is RoarVM's bytecodePrimMultiply, C++ code for reference below. This is the output with clang and -O2.
>
> I think the critical part is:
>
> 0x00032f04  <+0068>  sar    %ebx               // oop_int_t ri = rcvr.integerValue();
> 0x00032f06  <+0070>  sar    %edx               // oop_int_t ai = arg.integerValue();
> 0x00032f08  <+0072>  imul   %edx,%ebx          // oop_int_t r  = ri * ai
> // The following should be: if (ai == 0  ||  (((r / ai)  ==  ri)    &&    Oop::isIntegerValue(r))) {
> 0x00032f0b  <+0075>  lea    (%ebx,%ebx,1),%eax

This is the first part of the isIntegerValue check (assign the value of 
r1 + (r1 * 1) to the eax register).

> 0x00032f0e  <+0078>  test   %edx,%edx
> 0x00032f10  <+0080>  je     0x32f1a <_ZN18Squeak_Interpreter20bytecodePrimMultiplyEv+90>

This is the ai == 0 check.

> 0x00032f12  <+0082>  xor    %eax,%ebx
> 0x00032f14  <+0084>  js     0x3301f <_ZN18Squeak_Interpreter20bytecodePrimMultiplyEv+351>

This is the second part of the #isIntegerValue check (xor 2 * r1 with r1)
So the (r / ai) == ri was assumed to be true by the compiler, therefore 
not checked.


Levente


More information about the Vm-dev mailing list