This is the mail archive of the 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]
Other format: [Raw text]

Re: help on adding new insns like min/max

try this, using extensions for gcc:

#define max(a,b) ({__typeof__(a) a1=(a); __typeof__(b) b1 = (b); (a>b)?a:b})

Andrew Pinski

On Monday, Oct 21, 2002, at 17:34 US/Pacific, Ming Ouyang wrote:

I just found that macro doesn't always work well, for any complicated
operands like: max(a, ++b), max(a+b, c), max(a, foo(c)), gcc won't
use max insn for them, it only use max insn for max(a,b).
In addition, if I have more than one maxs/mins, it seems gcc will
not generate max/min for them, could you give me some help on that?
Thanks a lot.


--- Dale Johannesen <> wrote:
On Monday, October 21, 2002, at 04:05  PM, Ming Ouyang wrote:

I tried my gcc with definition of sminsi3/smaxsi3 and I dumpped
all debug info, gcc always treats min as a function call in my
test.c.00.rtl through test.c.30.dbr:

(call (mem:SI (symbol_ref/v:SI ("smin")) ))

I think once gcc found that is a function call, it would not
optimize it, am I right?
What I should get is something like "(smin: SI ...", is that right?
So probably I need to change something other than
If you're using it as a function of course gcc will treat it as
a function. It is not one of the standard C functions so gcc does
not do anything special to it (and is not allowed to, that would
break standard conformance). The usual way to get min/max functionality
in C is to put a macro definition in a header file somewhere, something
#define MAX(x,y) ((x>y) ? x : y)
(watch out for ++ operators, improvement left as an exercise)

Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site

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