From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8223 invoked by alias); 16 Jun 2011 16:26:09 -0000 Received: (qmail 8208 invoked by uid 22791); 16 Jun 2011 16:26:07 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 16 Jun 2011 16:25:49 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p5GGPgMV032356 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 16 Jun 2011 12:25:42 -0400 Received: from anchor.twiddle.net (vpn-238-15.phx2.redhat.com [10.3.238.15]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p5GGPfJb003851; Thu, 16 Jun 2011 12:25:42 -0400 Message-ID: <4DFA2E85.2030601@redhat.com> Date: Thu, 16 Jun 2011 17:03:00 -0000 From: Richard Henderson User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc15 Thunderbird/3.1.10 MIME-Version: 1.0 To: Bernd Schmidt CC: GCC Patches Subject: Re: Add __builtin_clrsb, similar to clz/ctz References: <4DF9FA9A.8040505@codesourcery.com> In-Reply-To: <4DF9FA9A.8040505@codesourcery.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-06/txt/msg01273.txt.bz2 On 06/16/2011 05:44 AM, Bernd Schmidt wrote: > +@deftypefn {Built-in Function} int __builtin_clrsb (unsigned int x) > +Returns the number of leading redundant sign bits in @var{x}, starting > +at the most significant bit position. > +@end deftypefn Do we want a signed argument, since we're talking about signs? It would seem that unlike clz, this function is not undefined for zero. What about INT_MIN? Do all cpus handle those edge cases the same way? Both should probably be documented both for the builtin and the rtx code. > + if (x == 0 || x == (Wtype)-1) > + return W_TYPE_SIZE - 1; > + if (x > 0) > + count_leading_zeros (ret, x); > + else > + count_leading_zeros (ret, ~x); > + return ret - 1; Do you get smaller code in general from if (x < 0) x = ~x; if (x == 0) return W_TYPE_SIZE - 1; count_leading_zeros(ret, x); return ret - 1; ? > -(define_insn "signbitssi2" > +(define_insn "clrsbsi2" > [(set (match_operand:HI 0 "register_operand" "=d") > (if_then_else:HI > (lt (match_operand:SI 1 "register_operand" "d") (const_int 0)) No use of the new rtx code? Not that this couldn't be handled with a different patch, but I don't see how you're testing the code in simplify-rtx without at least one such use. r~