From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7880) id 2E158385B525; Thu, 16 Feb 2023 16:28:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E158385B525 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676564886; bh=7MBEUdoDSSm4RJqsj8HFodzwnFBCvDEWaakKCpenSjk=; h=From:To:Subject:Date:From; b=qPZ7WXj84Kzl+aLnh1YgZ8xEH0mv6JVcYgetiLuxPcYj09GR+R5qxZiPPjq9VZi1E zbB9UgLVWe5SmzPQWDMG4Ts4P0Hv6gDnMgR9j4BSCrgOi6dK1L4F8h+SpMIGgmjucA 6+zLOVhzARAB4LaRKPfhTtkZX1nDzQryVlk6LC5Q= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Ondrej Kubanek To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/kubaneko/heads/histogram)] messed with logarithms X-Act-Checkin: gcc X-Git-Author: kubaneko X-Git-Refname: refs/users/kubaneko/heads/histogram X-Git-Oldrev: 2ec0ddcc2d8a42904b3b41e67662584e5ae7008c X-Git-Newrev: fdb7878232b77209916d5b5813af3b922edccfdb Message-Id: <20230216162806.2E158385B525@sourceware.org> Date: Thu, 16 Feb 2023 16:28:06 +0000 (GMT) List-Id: https://gcc.gnu.org/g:fdb7878232b77209916d5b5813af3b922edccfdb commit fdb7878232b77209916d5b5813af3b922edccfdb Author: kubaneko Date: Tue Nov 1 17:48:30 2022 +0000 messed with logarithms Diff: --- libgcc/libgcov-profiler.c | 51 +++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/libgcc/libgcov-profiler.c b/libgcc/libgcov-profiler.c index f150d75fee1..8088f3d647a 100644 --- a/libgcc/libgcov-profiler.c +++ b/libgcc/libgcov-profiler.c @@ -32,6 +32,28 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see * otherwise we take its logarithm and increment corresponding counter */ +/* For convenience, define 0 -> word_size. */ +static inline int +clz_hwi (gcov_type x) +{ + if (x == 0) + return 64; +# if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG + return __builtin_clzl (x); +# elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG + return __builtin_clzll (x); +# else + return __builtin_clz (x); +# endif +} + +static inline int +floor_log2 (gcov_type x) +{ + return 63 - clz_hwi (x); +} + + void __gcov_histogram_profiler (gcov_type *counters, gcov_type value) { @@ -39,19 +61,10 @@ __gcov_histogram_profiler (gcov_type *counters, gcov_type value) counters[value]++; }else{ gcc_assert(value>0); - int pow2 = 3; - while (1 << pow2 <= value || 1 << pow2 > 1 << (pow2 + 1)){ - ++pow2; - } - // pow2 is first bigger power of 2 - // we increment closer power of 2 - if ((1<>10); - int pow2 = 3; - while (1 << pow2 <= value || 1 << pow2 > 1 << (pow2 + 1)){ - ++pow2; - } - // pow2 is first bigger power of 2 - // we increment closer power of 2 - if ((1<>1