From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marc Lehmann To: egcs@cygnus.com Subject: Re: min/max macros Date: Fri, 12 Dec 1997 10:18:00 -0000 Message-id: <19971212170331.06147@cerebro.laendle> References: <19971212025753.58271@cerebro.laendle> <199712120317.TAA08800@atrus.synopsys.com> X-SW-Source: 1997-12/msg00753.html > > 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 | |