Search This Blog

Friday, June 10, 2005

Ooooh. Shiny.

Have a look at what VC++ compiled a few lines of ThingyTron as, demonstrating the new atomic and endian function intrinsics (you can also see some calls that aren't intrinsic, but work nonetheless). Note that this is optimized code, so there isn't always a 1:1 relationship between the C++ line and the assembly lines below it.

int32 moosquish = 15, mooblah = 79;
00403EC0 mov dword ptr [esp+20h],0Fh

mooblah = AtomicExchangeAdd(&moosquish, mooblah);
00403EC8 mov eax,4Fh
00403ECD lea ecx,[esp+20h]
00403ED1 lock xadd dword ptr [ecx],eax

mooblah = AtomicExchange(&moosquish, mooblah);
00403ED5 mov edx,ecx
00403ED7 xchg eax,dword ptr [edx]
00403ED9 mov ecx,eax

mooblah = AtomicCompareExchange(&moosquish, mooblah, -15);
00403EDB mov eax,0FFFFFFF1h
00403EE0 lock cmpxchg dword ptr [edx],ecx

mooblah = AtomicBitExchange(&moosquish, 2, 0);
00403EE4 push 0
00403EE6 push 2
00403EE8 mov eax,edx
00403EEA push eax
00403EEB call _AtomicBitExchange@12 (401060h)

mooblah = AtomicBitExchangeCompliment(&moosquish, 7);
00403EF0 push 7
00403EF2 lea ecx,[esp+24h]
00403EF6 push ecx
00403EF7 call _AtomicBitExchangeCompliment@8 (401090h)

mooblah = AtomicSignedExchangeAdd(&moosquish, 29, false);
00403EFC push 0
00403EFE lea edx,[esp+24h]
00403F02 push 1Dh
00403F04 push edx
00403F05 call Q::AtomicSignedExchangeAdd (4010E0h)
00403F0A add esp,0Ch

void *squishyptr = (void *)0x1234567,
*fatptr = AtomicCompareExchangePointer(&squishyptr, (void *)0x76543210, (void *)0x1234567);
00403F0D push 1234567h
00403F12 mov dword ptr [esp+6Ch],eax
00403F16 push 76543210h
00403F1B lea eax,[esp+74h]
00403F1F push eax
00403F20 mov dword ptr [esp+78h],1234567h
00403F28 call _AtomicCompareExchangePointer@12 (401040h)

int64 x = ltoh(0x0011223344556677), y = btoh(x);
00403F2D mov ecx,44556677h
00403F32 bswap ecx

printf("mooblah = %d, mooblah = %d, squishyptr = 0x%X, fatptr = 0x%X, x = %i64X, y = %i64X", moosquish, mooblah, squishyptr, fatptr, x, y);
00403F34 push ecx
00403F35 mov esi,112233h
00403F3A bswap esi
00403F3C push esi
00403F3D push esi
00403F3E push ecx
00403F3F push eax
00403F40 mov ecx,dword ptr [esp+80h]
00403F47 mov edx,dword ptr [esp+7Ch]
00403F4B mov eax,dword ptr [esp+34h]
00403F4F push ecx
00403F50 push edx
00403F51 push eax
00403F52 push offset string "mooblah = %d, mooblah = %d, squi"... (40D4C0h)
00403F57 call printf (405697h)

No comments: