This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: help on adding new insns like min/max
- From: Ming Ouyang <mouyang at yahoo dot com>
- To: Andrew Pinski <apinski at apple dot com>
- Cc: Dale Johannesen <dalej at apple dot com>, gcc at gcc dot gnu dot org
- Date: Mon, 21 Oct 2002 18:03:36 -0700 (PDT)
- Subject: Re: help on adding new insns like min/max
Andrew,
Thanks for your reply. __typeof__ does make 2 or more min/max in one
function work, but it can't resolve complicated operands problem yet,
can you help on that?
Thanks so much.
Ming
--- Andrew Pinski <apinski@apple.com> wrote:
> try this, using extensions for gcc:
>
> #define max(a,b) ({__typeof__(a) a1=(a); __typeof__(b) b1 = (b);
> (a>b)?a:b})
>
> Thanks,
> Andrew Pinski
>
> On Monday, Oct 21, 2002, at 17:34 US/Pacific, Ming Ouyang wrote:
>
> > Dale,
> > 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.
> >
> > Ming
> >
> > --- Dale Johannesen <dalej@apple.com> 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 xxx.md?
> >>> Thanks.
> >>
> >> 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
> >> like
> >> #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
> > http://webhosting.yahoo.com/
> >
>
__________________________________________________
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site
http://webhosting.yahoo.com/