G
Guest
I have some code like this:
///////////////
void test(int* a)
{
a[0]+=((a[1]-a[2])<<3);
}
////////////////
after compilng with vc.net 2003, the asm code is:
///////////
PUBLIC ?test@@YIXPAH@Z ; test
; Function compile flags: /Ogty
; File c:\test.cpp
; COMDAT ?test@@YIXPAH@Z
_TEXT SEGMENT
?test@@YIXPAH@Z PROC NEAR ; test, COMDAT
; _a$ = eax
; 144 : void test(int* a)
mov ecx, DWORD PTR [eax+4]
sub ecx, DWORD PTR [eax+8]
add ecx, ecx
add ecx, ecx
add ecx, ecx
add DWORD PTR [eax], ecx
ret 0
?test@@YIXPAH@Z ENDP ; test
////////////////////////////////////////////
Question:
why using "add ecx,ecx" three times and not using "shl ecx,3" instead.
To my idea shl ecx,3 is faster.
Thanks for any answers.
///////////////
void test(int* a)
{
a[0]+=((a[1]-a[2])<<3);
}
////////////////
after compilng with vc.net 2003, the asm code is:
///////////
PUBLIC ?test@@YIXPAH@Z ; test
; Function compile flags: /Ogty
; File c:\test.cpp
; COMDAT ?test@@YIXPAH@Z
_TEXT SEGMENT
?test@@YIXPAH@Z PROC NEAR ; test, COMDAT
; _a$ = eax
; 144 : void test(int* a)
mov ecx, DWORD PTR [eax+4]
sub ecx, DWORD PTR [eax+8]
add ecx, ecx
add ecx, ecx
add ecx, ecx
add DWORD PTR [eax], ecx
ret 0
?test@@YIXPAH@Z ENDP ; test
////////////////////////////////////////////
Question:
why using "add ecx,ecx" three times and not using "shl ecx,3" instead.
To my idea shl ecx,3 is faster.
Thanks for any answers.