Author: Gerd Isenberg
Date: 12:53:35 09/26/03
Hi,
i played a bit with macros versus inline functions -
abs, max and min again.
I got best results with:
#define minusMask(a) ((a)>>(sizeof(int)*8-1))
#define ifLessZero(a) ((a) & minusMask(a))
__forceinline int _abs(int a) {return a - ifLessZero(a+a);}
__forceinline int _max(int a, int b) {return a - ifLessZero(a-b);}
__forceinline int _min(int a, int b) {return a + ifLessZero(b-a);}
Using inline functions for minusMask and ifLessZero was slighly worse.
But same for using macros for the fuctions too:
#define _abs(a) ((a) - ifLessZero((a)+(a)))
#define _max(a,b) ((a) - ifLessZero((a)-(b)))
#define _min(a,b) ((a) + ifLessZero((b)-(a)))
hmm, thought macros are _always_ faster than inlines.
Seems to be a bit more than noise in my program.
Does anybody confirm that?
Thanks,
Gerd
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.