From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1082 invoked by alias); 22 Oct 2002 00:39:13 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 1028 invoked from network); 22 Oct 2002 00:39:10 -0000 Received: from unknown (HELO mail-out2.apple.com) (17.254.0.51) by sources.redhat.com with SMTP; 22 Oct 2002 00:39:10 -0000 Received: from mailgate1.apple.com (A17-128-100-225.apple.com [17.128.100.225]) by mail-out2.apple.com (8.11.3/8.11.3) with ESMTP id g9M0d9s08074 for ; Mon, 21 Oct 2002 17:39:09 -0700 (PDT) Received: from scv1.apple.com (scv1.apple.com) by mailgate1.apple.com (Content Technologies SMTPRS 4.2.5) with ESMTP id ; Mon, 21 Oct 2002 17:38:56 -0700 Received: from apple.com (il0503d-dhcp84.apple.com [17.205.38.84]) by scv1.apple.com (8.11.3/8.11.3) with ESMTP id g9M0d8H05826; Mon, 21 Oct 2002 17:39:08 -0700 (PDT) Date: Mon, 21 Oct 2002 23:00:00 -0000 Subject: Re: help on adding new insns like min/max Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v546) Cc: Dale Johannesen , gcc@gcc.gnu.org To: Ming Ouyang From: Andrew Pinski In-Reply-To: <20021022003420.37287.qmail@web13305.mail.yahoo.com> Message-Id: Content-Transfer-Encoding: 7bit X-SW-Source: 2002-10/txt/msg01301.txt.bz2 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 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/ >