And like you said in a post above - don't forget to check what the compiler does for the standard functionGerd Isenberg wrote:Intel's revenge on Sun's patent was the P4Michael Sherwin wrote: Sorry but, please forgive me!![]()
But, how do you know that he did not go back in time and patent the routine before he invented it and then back in the future after having forgot about it, then copied it with out having to invent it?I guessed I've watched too many trek episodes!
![]()
Thanks for the link!
They made shift so slow that the mentioned sar trick became rather worthless.
As mentioned one may use cdq instead sar 31.
And there are two ways to define Two's Complement by One's Complement.
Code: Select all
int abs(int x) { int m = (int)( (unsigned __int64)((__int64)x) >> 32 ); return (x + m) ^ m; } ?abs@@YIHH@Z PROC NEAR ; abs, COMDAT 00000 8b c1 mov eax, ecx 00002 99 cdq 00003 8d 04 0a lea eax, [edx+ecx] 00006 33 c2 xor eax, edx 00008 c3 ret 0 ?abs@@YIHH@Z ENDP ; abs
Code: Select all
int test(int x)
{
return std::abs(x);
}
?test@@YAHH@Z PROC ; test, COMDAT
; _x$ = eax
; 6 : return std::abs(x);
00000 99 cdq
00001 33 c2 xor eax, edx
00003 2b c2 sub eax, edx
; 7 : }
00005 c3 ret 0
?test@@YAHH@Z ENDP ; test

Bo Persson