 It might be quite verbose.... let's just pick a few
TC++
__declspec(noinline) double fct(int i, int j)
{
01301000 push ebp
01301001 mov ebp,esp
return sqrt((double)i)
01301003 fild dword ptr [i]
}
01301006 pop ebp
return sqrt((double)i)
01301007 jmp _CIsqrt (13019B0h)
--- No source file -------------------------------------------------------------
0130100C int 3
0130100D int 3
0130100E int 3
0130100F int 3
--- c:\dev\test\perfdouble\pdouble\pdouble.cpp ---------------------------------
int primes(unsigned long n) {
01301010 push ebp
01301011 mov ebp,esp
01301013 sub esp,8
01301016 push esi
01301017 push edi
unsigned long i, j
int countprimes = 0
for(i = 1
01301018 mov edi,1
0130101D cmp ebx,edi
0130101F jb primes+55h (1301065h)
int isprime = 1
float limit = sqrt((double)i)
for(j = 2
01301021 push edi
01301022 mov esi,2
01301027 call fct (1301000h)
0130102C fcom qword ptr [__real@4000000000000000 (1302120h)]
01301032 add esp,4
01301035 fnstsw ax
01301037 test ah,41h
0130103A jne primes+4Eh (130105Eh)
if(!(i%j)) {
0130103C xor edx,edx
0130103E mov eax,edi
01301040 div eax,esi
01301042 test edx,edx
01301044 je primes+4Eh (130105Eh)
int isprime = 1
float limit = sqrt((double)i)
for(j = 2
01301046 inc esi
01301047 mov dword ptr [ebp-4],esi
0130104A fild dword ptr [ebp-4]
0130104D jns primes+45h (1301055h)
0130104F fadd qword ptr [__real@41f0000000000000 (1302118h)]
01301055 fcomp st(1)
01301057 fnstsw ax
01301059 test ah,5
0130105C jnp primes+2Ch (130103Ch)
unsigned long i, j
int countprimes = 0
for(i = 1
0130105E inc edi
int isprime = 1
float limit = sqrt((double)i)
for(j = 2
0130105F fstp st(0)
01301061 cmp edi,ebx
01301063 jbe primes+11h (1301021h)
isprime = 0
break
}
countprimes+= isprime
}
throw "break here"
01301065 push offset __TI2PAD (13022F8h)
0130106A lea ecx,[ebp-4]
0130106D push ecx
0130106E mov dword ptr [ebp-4],offset string "break here" (130210Ch)
01301075 call _CxxThrowException (13019B6h)
$LN23:
0130107A int 3
--- No source file -------------------------------------------------------------
0130107B int 3
0130107C int 3
0130107D int 3
0130107E int 3
0130107F int 3
--- c:\dev\test\perfdouble\pdouble\pdouble.cpp ---------------------------------
return countprimes
}
did the disassembly for the slow version (TC#1)
TC#1, .NET4, win7
00000000 push ebp
00000001 mov ebp,esp
00000003 push edi
00000004 push esi
00000005 sub esp,0Ch
00000008 mov dword ptr [ebp-0Ch],ecx
0000000b mov esi,1
00000010 mov eax,dword ptr [ebp-0Ch]
00000013 cdq
00000014 test edx,edx
00000016 jg 0000001F
00000018 jl 0000007B
0000001a cmp eax,1
0000001d jb 0000007B
0000001f mov edi,1
00000024 lea ecx,[edi+1]
00000027 jmp 00000038
00000029 mov eax,esi
0000002b xor edx,edx
0000002d div eax,ecx
0000002f test edx,edx
00000031 jne 00000037
00000033 xor edi,edi
00000035 jmp 00000062
00000037 inc ecx
00000038 xor eax,eax
0000003a mov dword ptr [ebp-14h],esi
0000003d mov dword ptr [ebp-10h],eax
00000040 fild qword ptr [ebp-14h]
00000043 fstp qword ptr [ebp-14h]
00000046 fld qword ptr [ebp-14h]
00000049 fsqrt
0000004b mov dword ptr [ebp-14h],ecx
0000004e mov dword ptr [ebp-10h],eax
00000051 fild qword ptr [ebp-14h]
00000054 fstp qword ptr [ebp-14h]
00000057 fld qword ptr [ebp-14h]
0000005a fcomip st,st(1)
0000005c fstp st(0)
0000005e jp 00000062
00000060 jbe 00000029
00000062 test edi,edi
00000064 je 00000066
00000066 inc esi
00000067 xor eax,eax
00000069 mov edx,dword ptr [ebp-0Ch]
0000006c mov ecx,edx
0000006e sar ecx,1Fh
00000071 cmp eax,ecx
00000073 jg 0000007B
00000075 jl 0000001F
00000077 cmp esi,edx
00000079 jbe 0000001F
0000007b mov ecx,60BDFC48h
00000080 call FFEB1E10
00000085 mov esi,eax
00000087 mov edx,182EA4h
0000008c mov ecx,70000001h
00000091 call 61524745
00000096 mov edx,eax
00000098 mov ecx,esi
0000009a call 60E023E0
0000009f mov ecx,esi
000000a1 call 61521086
000000a6 int 3
TC#1, .NET3.5, win7
00000000 push ebp
00000001 mov ebp,esp
00000003 push edi
00000004 push esi
00000005 sub esp,0Ch
00000008 mov dword ptr [ebp-0Ch],ecx
0000000b mov esi,1
00000010 mov eax,dword ptr [ebp-0Ch]
00000013 cdq
00000014 test edx,edx
00000016 jg 0000001F
00000018 jl 0000007B
0000001a cmp eax,1
0000001d jb 0000007B
0000001f mov edi,1
00000024 lea ecx,[edi+1]
00000027 jmp 00000038
00000029 mov eax,esi
0000002b xor edx,edx
0000002d div eax,ecx
0000002f test edx,edx
00000031 jne 00000037
00000033 xor edi,edi
00000035 jmp 00000062
00000037 inc ecx
00000038 xor eax,eax
0000003a mov dword ptr [ebp-14h],esi
0000003d mov dword ptr [ebp-10h],eax
00000040 fild qword ptr [ebp-14h]
00000043 fstp qword ptr [ebp-14h]
00000046 fld qword ptr [ebp-14h]
00000049 fsqrt
0000004b mov dword ptr [ebp-14h],ecx
0000004e mov dword ptr [ebp-10h],eax
00000051 fild qword ptr [ebp-14h]
00000054 fstp qword ptr [ebp-14h]
00000057 fld qword ptr [ebp-14h]
0000005a fcomip st,st(1)
0000005c fstp st(0)
0000005e jp 00000062
00000060 jbe 00000029
00000062 test edi,edi
00000064 je 00000066
00000066 inc esi
00000067 xor eax,eax
00000069 mov edx,dword ptr [ebp-0Ch]
0000006c mov ecx,edx
0000006e sar ecx,1Fh
00000071 cmp eax,ecx
00000073 jg 0000007B
00000075 jl 0000001F
00000077 cmp esi,edx
00000079 jbe 0000001F
0000007b mov ecx,66CA0D04h
00000080 call FFE41E4C
00000085 mov esi,eax
00000087 mov edx,292F2Ch
0000008c mov ecx,70000001h
00000091 call 671A9052
00000096 mov edx,eax
00000098 mov ecx,esi
0000009a call 6681A7A0
0000009f mov ecx,esi
000000a1 call 671A9187
000000a6 int 3
TC1, .NET4, win8
00000000 push rbx
00000001 push rdi
00000002 sub rsp,28h
00000006 movsxd r8,ecx
00000009 cmp r8,1
0000000d jl 0000000000000080
0000000f mov ecx,1
00000014 nop word ptr [rax+rax+00000000h]
00000020 mov eax,ecx
00000022 cvtsi2sd xmm0,rax
00000027 mov eax,2
0000002c mov eax,eax
0000002e cvtsi2sd xmm1,rax
00000033 sqrtsd xmm0,xmm0
00000037 ucomisd xmm0,xmm1
0000003b jb 000000000000006A
0000003d mov r9d,2
00000043 xor edx,edx
00000045 mov eax,ecx
00000047 div eax,r9d
0000004a test edx,edx
0000004c je 000000000000006A
0000004e inc r9d
00000051 mov eax,r9d
00000054 cvtsi2sd xmm2,rax
00000059 mov eax,ecx
0000005b cvtsi2sd xmm0,rax
00000060 sqrtsd xmm1,xmm0
00000064 ucomisd xmm1,xmm2
00000068 jae 0000000000000043
0000006a inc ecx
0000006c mov eax,ecx
0000006e cmp rax,r8
00000071 jle 0000000000000020
00000073 jmp 0000000000000080
00000075 add rsp,28h
00000079 pop rdi
0000007a pop rbx
0000007b ret
0000007c nop dword ptr [rax]
00000080 lea rdx,[FFEE2D70h]
00000087 mov ecx,70000001h
0000008c call 000000005F7A0A70
00000091 mov rbx,rax
00000094 lea rcx,[5E8109F0h]
0000009b call 000000005F682310
000000a0 mov rdi,rax
000000a3 mov rdx,rbx
000000a6 mov rcx,rdi
000000a9 call 000000005ED99BC0
000000ae mov rcx,rdi
000000b1 call 000000005F79EF24
000000b6 nop
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|