From patchwork Tue Jul 17 11:25:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 171396 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id AEA8B2C018D for ; Tue, 17 Jul 2012 21:25:53 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1343129153; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC: Subject:References:In-Reply-To:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=fGoqgD/zqEuuU3fbgOMz4y9tbUk=; b=gh5OwvmqImzi0sINvKWB/973DULACaEiInLil6G1Sn3nAo3gXp91q1vaA84rh9 iN+2CTNYSEY07h14A7w0MMSJXOnwaafFAIoQyvY344i0nulq3clMkEkHFiPmpWI9 ZD7egP2GgOxpN5MFTg9Zbu5BWpLumZWkDWAaRuDRNjXbc= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=yF+b8cJz2fUlWsmbJvH0RMxX0qWyMBbGnwteFdGXtfGzJJBsromvGnrHNWK5ob MU6tcthvuTK0NdNT3KysW8NOiy8fRI1bhSd6K2Tkwf4BLC7kbuyuHXNfxWKW5FLa QmyXj/q4sGVLmm4WXWc6Rgc5k6DggxdQWvx8ZRAgNiS1E=; Received: (qmail 802 invoked by alias); 17 Jul 2012 11:25:49 -0000 Received: (qmail 789 invoked by uid 22791); 17 Jul 2012 11:25:48 -0000 X-SWARE-Spam-Status: No, hits=-4.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, TW_CL X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 17 Jul 2012 11:25:35 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1Sr5uJ-0003bo-0s from Tom_deVries@mentor.com ; Tue, 17 Jul 2012 04:25:35 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Tue, 17 Jul 2012 04:25:34 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.1.289.1; Tue, 17 Jul 2012 12:25:32 +0100 Message-ID: <50054BA9.5020104@mentor.com> Date: Tue, 17 Jul 2012 13:25:29 +0200 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: Richard Guenther CC: "gcc-patches@gcc.gnu.org" , Jakub Jelinek , Steven Bosscher , Jan Hubicka Subject: Re: [PATCH 2/2] if-to-switch conversion pass -- infrastructure References: <50054A9C.4030404@mentor.com> In-Reply-To: <50054A9C.4030404@mentor.com> Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org On 17/07/12 13:21, Tom de Vries wrote: > attached patch implements an if-to-switch conversion tree pass > pass_if_to_switch. I will follow up this email with an infrastructure patch that > provides double_int_popcount and popcount_hwi. Bootstrapped and reg-tested (Ada inclusive) on x86_64, with pass_if_to_switch as only client. OK for trunk? Thanks, - Tom 2012-07-16 Tom de Vries * double-int.h (double_int_popcount): New inline function. * hwint.c (popcount_hwi): New function. * hwint.h (popcount_hwi): Declare function. New inline function. Index: gcc/double-int.h =================================================================== --- gcc/double-int.h (revision 189508) +++ gcc/double-int.h (working copy) @@ -284,6 +284,14 @@ double_int_equal_p (double_int cst1, dou return cst1.low == cst2.low && cst1.high == cst2.high; } +/* Return number of set bits of CST. */ + +static inline int +double_int_popcount (double_int cst) +{ + return popcount_hwi (cst.high) + popcount_hwi (cst.low); +} + /* Legacy interface with decomposed high/low parts. */ Index: gcc/hwint.c =================================================================== --- gcc/hwint.c (revision 189508) +++ gcc/hwint.c (working copy) @@ -107,6 +107,22 @@ ffs_hwi (unsigned HOST_WIDE_INT x) return 1 + floor_log2 (x & -x); } +/* Return the number of set bits in X. */ + +int +popcount_hwi (unsigned HOST_WIDE_INT x) +{ + int i, ret = 0; + + for (i = 0; i < sizeof (x); i += 1) + { + ret += x & 1; + x >>= 1; + } + + return ret; +} + #endif /* GCC_VERSION < 3004 */ Index: gcc/hwint.h =================================================================== --- gcc/hwint.h (revision 189508) +++ gcc/hwint.h (working copy) @@ -179,6 +179,9 @@ extern int clz_hwi (unsigned HOST_WIDE_I extern int ctz_hwi (unsigned HOST_WIDE_INT x); extern int ffs_hwi (unsigned HOST_WIDE_INT x); +/* Return the number of set bits in X. */ +extern int popcount_hwi (unsigned HOST_WIDE_INT x); + /* Return log2, or -1 if not exact. */ extern int exact_log2 (unsigned HOST_WIDE_INT); @@ -231,6 +234,18 @@ ffs_hwi (unsigned HOST_WIDE_INT x) # endif } +static inline int +popcount_hwi (unsigned HOST_WIDE_INT x) +{ +# if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG + return __builtin_popcountl (x); +# elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG + return __builtin_popcountll (x); +# else + return __builtin_popcount (x); +# endif +} + static inline int floor_log2 (unsigned HOST_WIDE_INT x) {