This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: min/max macros
> > 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.
sorry, I was just too fast here in replyÄing (and I left the [EGCS] in, soory again ;)
> > 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.
no, mult(a,3) results in:
movl 4(%esp),%eax
imull $3,%eax,%eax
ret
which is highly suboptimal.. a mult(4,5), though, will be evaluated at compile
time. But macros *are* faster than inline functions, despite what the
documentation tells us.
---------------------------------------------------------------------
for a pentium-optimizing gcc, look at http://www.gcc.ml.org/
-----==- |
----==-- _ |
---==---(_)__ __ ____ __ Marc Lehmann +--
--==---/ / _ \/ // /\ \/ / pcg@goof.com |e|
-=====/_/_//_/\_,_/ /_/\_\ --+
The choice of a GNU generation |
|