public
Created

MSVC version of the two functions

  • Download Gist
gistfile1.asm
Assembly
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
; http://stackoverflow.com/questions/10250419/why-does-gcc-generate-such-radically-different-assembly-for-nearly-the-same-c-co
PUBLIC ?fast_trunc_one@@YAHH@Z ; fast_trunc_one
; Function compile flags: /Ogtpy
_TEXT SEGMENT
_i$ = 8 ; size = 4
?fast_trunc_one@@YAHH@Z PROC ; fast_trunc_one
; File c:\program files (x86)\microsoft visual studio 10.0\vc\bin\c2.cpp
; Line 6
mov eax, DWORD PTR _i$[esp-4]
push esi
; Line 7
mov esi, eax
sar esi, 23 ; 00000017H
mov edx, eax
and esi, 255 ; 000000ffH
and edx, 8388607 ; 007fffffH
mov ecx, 150 ; 00000096H
sub ecx, esi
or edx, 8388608 ; 00800000H
; Line 8
and eax, -2147483648 ; 80000000H
pop esi
; Line 12
test ecx, ecx
jns SHORT $LN2@fast_trunc
; Line 13
neg ecx
shl edx, cl
; Line 15
add edx, eax
; Line 18
neg eax
xor eax, edx
; Line 19
ret 0
$LN2@fast_trunc:
; Line 15
sar edx, cl
add edx, eax
; Line 18
neg eax
xor eax, edx
; Line 19
ret 0
?fast_trunc_one@@YAHH@Z ENDP ; fast_trunc_one
_TEXT ENDS
PUBLIC ?fast_trunc_two@@YAHH@Z ; fast_trunc_two
; Function compile flags: /Ogtpy
_TEXT SEGMENT
_i$ = 8 ; size = 4
?fast_trunc_two@@YAHH@Z PROC ; fast_trunc_two
; Line 24
mov edx, DWORD PTR _i$[esp-4]
push esi
; Line 25
mov esi, edx
sar esi, 23 ; 00000017H
mov eax, edx
and esi, 255 ; 000000ffH
and eax, 8388607 ; 007fffffH
mov ecx, 150 ; 00000096H
sub ecx, esi
or eax, 8388608 ; 00800000H
; Line 26
and edx, -2147483648 ; 80000000H
pop esi
; Line 30
test ecx, ecx
jns SHORT $LN2@fast_trunc@2
; Line 31
neg ecx
shl eax, cl
; Line 33
mov ecx, edx
neg ecx
xor eax, ecx
add eax, edx
; Line 37
ret 0
$LN2@fast_trunc@2:
; Line 33
sar eax, cl
mov ecx, edx
neg ecx
xor eax, ecx
add eax, edx
; Line 37
ret 0
?fast_trunc_two@@YAHH@Z ENDP ; fast_trunc_two
_TEXT ENDS

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.