|
![](/i/fill.gif) |
... for x86-based platforms.
The thing is that the standard implementation (found in frame.h) is
drastically inefficient on Intel processors, which have the special "fabs"
floating point instruction. Good compilers always recognize calls to fabs()
and replace them with a single instruction, but they can do nothing with
your macro. Consider this example (the comparison itself currently takes 5
instructions instead of a single one it should take; not to say one of them
is an infamous conditional jump...):
------- test.c -------
#define fabs(x) ((x) < 0.0 ? -(x) : (x))
double func( double x )
{
return fabs( x );
}
------- command -------
cl /Ox /Fa /c /nologo test.c
------- result -------
CONST SEGMENT
__real@8@00000000000000000000 DQ 00000000000000000r ; 0
CONST ENDS
_TEXT SEGMENT
_x$ = 8
_func PROC NEAR
; File test.c
; Line 6
fld QWORD PTR _x$[esp-4]
fcom QWORD PTR __real@8@00000000000000000000
fnstsw ax
test ah, 1
je SHORT $L94
fchs
$L94:
; Line 7
ret 0
----- if #define is commented out, we get: -----
_TEXT SEGMENT
_x$ = 8
_func PROC NEAR
; File test.c
; Line 6
fld QWORD PTR _x$[esp-4]
fabs
; Line 7
ret 0
_func ENDP
_TEXT ENDS
END
Post a reply to this message
|
![](/i/fill.gif) |