From patchwork Wed Dec 19 21:34:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Teresa Johnson X-Patchwork-Id: 207519 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 4DC942C0094 for ; Thu, 20 Dec 2012 08:34:46 +1100 (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=1356557687; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:To:Subject:Message-Id:Date:From:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=uvlaQi1VKGBWUURynLpv+mwP0GY=; b=SgoluTO0dZcaMvBLCvPmzFCTvYrYV3T0ODGiZSGTWENlmK/qgo5muGTW+6ikwt 8Tctx6Am5wK0grfOoghNrrc6sNbHWzrJpxNkKUKTD4JyrWimjd39aGKM+oNdXs17 YUMFgG8HHlmvi0TEWENJyIIJubfSeG1vDILVBEREXCLgE= 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:X-Google-DKIM-Signature:X-Received:Received:Received:Received:To:Subject:Message-Id:Date:From:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=vPZiZGuOh/NkjMUUo7uxYmQqvaAKltDPCAB9HIHOiA7wQGQhsnVW+yb6o55uun iXqxtVjsNX6vDZU9wWgpiWhMaL9rVarcwBsTL1ifLLT9Y+xWzUQuoplym/F/4u/R HLiB2Q+ZfFp6IUnMKnCmfFmj8/hLv6iLa6HK1KwveBPyg=; Received: (qmail 28061 invoked by alias); 19 Dec 2012 21:34:43 -0000 Received: (qmail 27678 invoked by uid 22791); 19 Dec 2012 21:34:42 -0000 X-SWARE-Spam-Status: No, hits=-4.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, TW_CL, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-qc0-f201.google.com (HELO mail-qc0-f201.google.com) (209.85.216.201) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 19 Dec 2012 21:34:36 +0000 Received: by mail-qc0-f201.google.com with SMTP id a6so285571qch.2 for ; Wed, 19 Dec 2012 13:34:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:to:subject:message-id:date:from:x-gm-message-state; bh=xOtrTzES2yNAzJA1YM5x8uPaunPv9wwujnbxW5nQa6A=; b=kPERcK0xXBMeZYyJrqkAa0bhflLpnHSvvgsYfSGXNGJbtdkYw8wX9nmJ2zI109qVQw 4IsRjeV9DKoh7fYgQnaqd+eEOLaFP/RPu3ygI0YQH3dybgYoWgSVM0EL2/BKel6EG6vU 9EY9aBs/x7TJq01tDglKGtK/SHKogM5PDMvn5y6NWPl6Jl3CWdKOUxEyePC6bkCwB5s9 GYtfhNlhmRb9OEh5wxsAD0Fdc6xB9EJczNRndsjsSLz/Jq4ZOxcnb1TEXaGTrvQPa6KQ kSgvtQV3wk851TB5lQ75mjwsqWcUeBbdc02/13HxgcnypeFEJ3mcoMi7pPg5ePoqodui 0rtw== X-Received: by 10.236.193.106 with SMTP id j70mr3208950yhn.11.1355952875764; Wed, 19 Dec 2012 13:34:35 -0800 (PST) Received: from wpzn4.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id s78si549993yhh.3.2012.12.19.13.34.35 (version=TLSv1/SSLv3 cipher=AES128-SHA); Wed, 19 Dec 2012 13:34:35 -0800 (PST) Received: from tjsboxrox.mtv.corp.google.com (tjsboxrox.mtv.corp.google.com [172.17.129.49]) by wpzn4.hot.corp.google.com (Postfix) with ESMTP id 90D9E82004A; Wed, 19 Dec 2012 13:34:35 -0800 (PST) Received: by tjsboxrox.mtv.corp.google.com (Postfix, from userid 147431) id 2E8FE6112F; Wed, 19 Dec 2012 13:34:35 -0800 (PST) To: reply@codereview.appspotmail.com, jakub@redhat.com, rguenther@suse.de, gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR gcov-profile/55734 for bootstrapping with older compilers (issue6980044) Message-Id: <20121219213435.2E8FE6112F@tjsboxrox.mtv.corp.google.com> Date: Wed, 19 Dec 2012 13:34:34 -0800 (PST) From: tejohnson@google.com (Teresa Johnson) X-Gm-Message-State: ALoCoQm3ldYJXNHV7RUql6WDABn/f8MmOqxEZeS/XCrniMCynjqn/daKTYlpu0a27X+5Q+KDJ6VDilY7gmSj7ZU1rOe3NYEUmkvffD9oTralUu37L++1wBmz6hibtLHgv5HGqMIXKBw5XG/wKUVo0KtdtNId+SPDu9P2GVjDZr8E0GKVDeNN7gE0aeOvrbzjv2CmJ2zCwMuk X-IsSubscribed: yes 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 Fix PR gcov-profile/55734 by using methods from hwint.c instead of builtins, to handle non-GCC and older versions of GCC. When building libgcov.a, however, hwint.c is not available, but we are always using the bootstrapped compiler and can therefore use the builtins. Use __builtin_popcount instead of __builtin_popcountll, since we are operating on an int. Use floor_log2 directly, instead of clz_hwi for the non-libgcov case, and handle situations where the size of the gcov_type is bigger than HOST_WIDE_INT. Verified that the various cases compiled by forcing different HOST_BITS_PER_WIDE_INT values. Bootstrapped and tested on x86_64-unknown-linux-gnu. Ok for trunk? Thanks, Teresa 2012-12-19 Teresa Johnson Jakub Jelinek PR gcov-profile/55734 * gcov-io.c (gcov_read_summary): Use __builtin_popcount instead of __builtin_popcountll when building libgcov.a, otherwise use popcount_hwi. (gcov_histo_index): When not building libgcov.a, use floor_log2 instead of __builtin_clzll. --- This patch is available for review at http://codereview.appspot.com/6980044 Index: gcov-io.c =================================================================== --- gcov-io.c (revision 194585) +++ gcov-io.c (working copy) @@ -538,7 +538,15 @@ gcov_read_summary (struct gcov_summary *summary) for (bv_ix = 0; bv_ix < GCOV_HISTOGRAM_BITVECTOR_SIZE; bv_ix++) { histo_bitvector[bv_ix] = gcov_read_unsigned (); - h_cnt += __builtin_popcountll (histo_bitvector[bv_ix]); +#if IN_LIBGCOV + /* When building libgcov we don't include system.h, which includes + hwint.h (where popcount_hwi is declared). However, libgcov.a + is built by the bootstrapped compiler and therefore the builtins + are always available. */ + h_cnt += __builtin_popcount (histo_bitvector[bv_ix]); +#else + h_cnt += popcount_hwi (histo_bitvector[bv_ix]); +#endif } bv_ix = 0; h_ix = 0; @@ -642,7 +650,33 @@ gcov_histo_index (gcov_type value) /* Find the place of the most-significant bit set. */ if (v > 0) - r = 63 - __builtin_clzll (v); + { +#if IN_LIBGCOV + /* When building libgcov we don't include system.h, which includes + hwint.h (where floor_log2 is declared). However, libgcov.a + is built by the bootstrapped compiler and therefore the builtins + are always available. */ + r = 63 - __builtin_clzll (v); +#else + /* We use floor_log2 from hwint.c, which takes a HOST_WIDE_INT + that is either 32 or 64 bits, and gcov_type_unsigned may be 64 bits. + Need to check for the case where gcov_type_unsigned is 64 bits + and HOST_WIDE_INT is 32 bits and handle it specially. */ +#if LONG_LONG_TYPE_SIZE <= HOST_BITS_PER_WIDE_INT + r = floor_log2 (v); +#else +#if LONG_LONG_TYPE_SIZE == 2 * HOST_BITS_PER_WIDE_INT + HOST_WIDE_INT hwi_v = v >> HOST_BITS_PER_WIDE_INT; + if (hwi_v) + r = floor_log2 (hwi_v) + HOST_BITS_PER_WIDE_INT; + else + r = floor_log2 ((HOST_WIDE_INT)v); +#else + gcc_unreachable (); +#endif +#endif +#endif + } /* If at most the 2 least significant bits are set (value is 0 - 3) then that value is our index into the lowest set of