Author: Oliver Roese
Date: 08:19:28 07/05/03
Go up one level in this thread
On July 05, 2003 at 10:17:38, Omid David Tabibi wrote: >In Genesis I heavily use the abs() function, and so tried to optimize it. >Instead of using the abs() function defined in <math.h>, I wrote the following >fucntion: > >long abs(long x) { > long y; > y = x >> 31; > return (x ^ y) - y; >} > >Testing it using a profiler, I found out that my implementation is about twice >slower than the math.h implementation of abs(). I haven't looked at the >implementation in math.h, but I can't see how a more optimized version of abs() >can be written. > >Any ideas? Hi, sorry i can't solve that for you, but it is interesting to hear that this cute trick is indeed slower than some simpler approach, since i was told exactly that some time ago. The reasoning ist, that there are more interdependencies between the arguments in your expression. That makes it harder for the cpu/compiler to parallelize your code. Oliver
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.