Avoid optimizing primitive #33 in vm.c (for VC++)
Lendvai Attila
Attila.Lendvai at netvisor.hu
Mon Aug 9 03:08:53 PDT 2004
hi!
Please find the disassembly below of the optimized/non-optimized
version. I've tried to surround the signed cast with an extra (), but
the same result
static INLINE signed long int ObjectPointer_asSmallInt(ObjectPointer
oop)
{
return ((signed long int) oop) >> 1;
}
in the optimized version the rotation is done with an "shr" opcode,
which clears the MSB. in the non-optimized version, "sar" is used, which
behaves as expected...
there are other >> 1 operations all around in vm.c, but still turning
off global optimizations with the #pragma results in a working vm.
I'm downloading VC++ 2005 beta now and see what's in there?
- 101
MSDN jokes, the search itself:
http://search.microsoft.com/search/results.aspx?view=msdn&st=a&na=81&qu=
&qp=global+optimizations&qa=&qn=&c=10&s=1
some intresting pieces:
http://support.microsoft.com/default.aspx?scid=kb;en-us;250887
http://support.microsoft.com/default.aspx?scid=kb;en-us;113427
NON-OPTIMIZED:
void _primitive33(struct Interpreter * interpreter, ObjectPointer *
arguments, unsigned long int argumentsSize, struct OopArray * optionals)
{
00408B50 push ebp
00408B51 mov ebp,esp
00408B53 sub esp,18h
ObjectPointer x;
ObjectPointer y;
x = arguments[0];
00408B56 mov eax,dword ptr [arguments]
00408B59 mov ecx,dword ptr [eax]
00408B5B mov dword ptr [x],ecx
y = arguments[1];
00408B5E mov edx,dword ptr [arguments]
00408B61 mov eax,dword ptr [edx+4]
00408B64 mov dword ptr [y],eax
PSInterpreter_stackPush_(interpreter, ObjectPointer_asSmallInt(x) <
ObjectPointer_asSmallInt(y)?CurrentMemory->TrueObject:CurrentMemory->Fal
seObject);
00408B67 mov ecx,dword ptr [x]
00408B6A sar ecx,1
00408B6C mov edx,dword ptr [y]
00408B6F sar edx,1
00408B71 cmp ecx,edx
00408B73 jge _primitive33+32h (408B82h)
00408B75 mov eax,dword ptr [_CurrentMemory (411D60h)]
00408B7A mov ecx,dword ptr [eax+24h]
00408B7D mov dword ptr [ebp-18h],ecx
00408B80 jmp _primitive33+3Eh (408B8Eh)
00408B82 mov edx,dword ptr [_CurrentMemory (411D60h)]
00408B88 mov eax,dword ptr [edx+28h]
00408B8B mov dword ptr [ebp-18h],eax
00408B8E mov ecx,dword ptr [ebp-18h]
00408B91 push ecx
00408B92 mov edx,dword ptr [interpreter]
00408B95 push edx
00408B96 call PSInterpreter_stackPush_ (406860h)
00408B9B add esp,8
}
00408B9E mov esp,ebp
00408BA0 pop ebp
00408BA1 ret
OPTIMIZED:
void _primitive33(struct Interpreter * interpreter, ObjectPointer *
arguments, unsigned long int argumentsSize, struct OopArray * optionals)
{
ObjectPointer x;
ObjectPointer y;
x = arguments[0];
y = arguments[1];
PSInterpreter_stackPush_(interpreter, ObjectPointer_asSmallInt(x) <
ObjectPointer_asSmallInt(y)?CurrentMemory->TrueObject:CurrentMemory->Fal
seObject);
004064E0 mov eax,dword ptr [esp+8]
004064E4 mov ecx,dword ptr [eax+4]
004064E7 mov edx,dword ptr [eax]
004064E9 shr ecx,1
004064EB shr edx,1
004064ED cmp edx,ecx
004064EF push esi
004064F0 push edi
004064F1 jge _primitive33+1Dh (4064FDh)
004064F3 mov eax,dword ptr [_CurrentMemory (40FD60h)]
004064F8 mov edi,dword ptr [eax+24h]
004064FB jmp _primitive33+26h (406506h)
004064FD mov ecx,dword ptr [_CurrentMemory (40FD60h)]
00406503 mov edi,dword ptr [ecx+28h]
00406506 mov esi,dword ptr [esp+0Ch]
0040650A mov edx,dword ptr [esi+24h]
0040650D cmp edx,dword ptr [esi+28h]
00406510 jne _primitive33+3Bh (40651Bh)
00406512 push esi
00406513 call PSInterpreter_growStack (404D60h)
00406518 add esp,4
0040651B mov eax,dword ptr [esi+24h]
0040651E mov ecx,dword ptr [esi+0Ch]
00406521 mov dword ptr [ecx+eax*4+0Ch],edi
00406525 add dword ptr [esi+24h],1
00406529 pop edi
0040652A pop esi
}
0040652B ret
:: -----Original Message-----
:: From: slate-bounces at tunes.org
:: [mailto:slate-bounces at tunes.org] On Behalf Of Lee Salzman
:: Sent: Monday, August 09, 2004 9:01 AM
:: To: Paul Dufresne
:: Cc: slate at tunes.org
:: Subject: Re: Avoid optimizing primitive #33 in vm.c (for VC++)
::
::
:: The primitive causing the problem is SmallInteger <
:: SmallInteger, not the Float one. Not sure why VC would do
:: this, though, other than that it
:: may just be a silly VC bug. Anyone has any ideas?
::
:: Lee
::
:: On Mon, Aug 09, 2004 at 06:11:45AM +0000, Paul Dufresne wrote:
:: > I said: "I think primitive 13 is this one:"
:: > but really meant primitive 33.
:: >
:: > Also, somehow I find it strange myself that the
:: > primitive causing problem be < for Floats,
:: > so it would be nice for someone to confirm.
:: >
:: > Finally, building bootstrap image have been done without a hitch.
:: > (Just hope the expression 'without a hitch' is Ok in english).
:: >
:: > --Paul
:: >
::
::
More information about the Slate
mailing list