Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Macros versus Inline

Author: Robert Hyatt

Date: 11:15:11 09/29/03

Go up one level in this thread


On September 26, 2003 at 15:53:35, Gerd Isenberg wrote:

>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


I'm not sure why there should be _any_ difference, myself.  That is the
real question.  A decent optimizing compiler should turn either of the
above into the same code, it would seem to me...




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.