This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [EGCS] Re: min/max macros



> > > #define max(a,b)	(((a) > (b)) ? (a) : (b))
> > > #define min(a,b)	(((a) < (b)) ? (a) : (b))
> > 
> > That is a big no-no: Absolutely no performance benefits with any decent
> > compiler but nasty side effects.
> 
> so egcs isn't a decent compiler?
> 
> for example, the macro-max(2,3) will be evaluated at compile time,
> while the function-max(2,3) won't...

The function max(2,3) will indeed be evaluated at compile time, if it is
inlined.

> this get's even worse on things like:
> 
> int mult(int a, int b) { return a*b; };
> 
> mult(a,3) will result in an "imul 3" on x86... definitely
> slower than a lea, for example.

Same for mult: if it is inlined, it will be evaluated at compile time if
given constant arguments.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]