POV-Ray : Newsgroups : povray.programming : To POV-Team: Please put "#define fabs fabs" into config.h... : To POV-Team: Please put "#define fabs fabs" into config.h... Server Time
28 Jul 2024 10:13:50 EDT (-0400)
  To POV-Team: Please put "#define fabs fabs" into config.h...  
From: Vadim Sytnikov
Date: 28 May 2002 04:24:07
Message: <3cf33ea7$1@news.povray.org>
... 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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.