From patchwork Thu Jun 2 10:37:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrill Tkachov X-Patchwork-Id: 629176 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rL3bK3C7tz9t3h for ; Thu, 2 Jun 2016 20:38:02 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=fJsybb7z; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=QjjBPBKQ7u3WnECUx d9ceRAHbHInogBsD94SnMenz88tEH7XOM91v5fGdN6LVNBJg9IVDcssOt6MqsrrL QTKIz/+eJPblHKWr6rX1YEIqknYJ5StKVgPo9nGSt1sRYAxO03X51fCLvkKyjsDo 3LAQQDVGpxBSUHOEtE+BibdJgg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=qjg0AytiO/cD+rVimzCFN2e q/OQ=; b=fJsybb7zl6kMC2fQ8JT+fvjdVc3DjCw3SlBGchWymlyDR0aYDWo8c8F y+EYQQDfl3IhuRjIR0KZfA9vJShiBOrBzmf1vvNJExTIjNSQAwd1GHIw6syqMs/v IQBfYF5lHJtIsQGDKUaK2bfrRm8aF74qX1QHMKaau+hak7NiMMmU= Received: (qmail 41355 invoked by alias); 2 Jun 2016 10:37:53 -0000 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 Received: (qmail 41336 invoked by uid 89); 2 Jun 2016 10:37:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=log2, 1047, archived X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 02 Jun 2016 10:37:42 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CC511F; Thu, 2 Jun 2016 03:38:10 -0700 (PDT) Received: from [10.2.206.43] (e100706-lin.cambridge.arm.com [10.2.206.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0E7393F212; Thu, 2 Jun 2016 03:37:39 -0700 (PDT) Message-ID: <57500C72.4010308@foss.arm.com> Date: Thu, 02 Jun 2016 11:37:38 +0100 From: Kyrill Tkachov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: GCC Patches CC: Ramana Radhakrishnan , Richard Earnshaw Subject: Re: [PATCH][ARM][1/4] Replace uses of int_log2 by exact_log2 References: <57445646.8080907@foss.arm.com> In-Reply-To: <57445646.8080907@foss.arm.com> I wanted to ping this patch, but checking the gcc-patches archive I see this wasn't archived, though I have confirmed that the patch was sent out and distributed by the mail server correctly. Anyway, resending... Thanks, Kyrill On 24/05/16 14:25, Kyrill Tkachov wrote: > Hi all, > > The int_log2 function in arm.c is not really useful since we already have a generic function for calculating > the log2 of HOST_WIDE_INTs. The only difference in functionality is that int_log2 also asserts that the result > is no greater than 31. > > This patch removes int_log2 in favour of exact_log2 and adds an assert on the result to make sure the return > value was as expected. > > Bootstrapped and tested on arm-none-linux-gnueabihf. > > Is this ok? Or is there something I'm missing about int_log2? > > Thanks, > Kyrill > > 2016-05-24 Kyrylo Tkachov > > * config/arm/arm.c (int_log2): Delete definition and prototype. > (shift_op): Use exact_log2 instead of int_log2. > (vfp3_const_double_for_fract_bits): Likewise. diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 6cc0feb6f87157171c889e998e52b4e5d8683c66..3fe6eab46f3c18ace6899b5be45ad646992f43e4 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -104,7 +104,6 @@ static void arm_print_operand_address (FILE *, machine_mode, rtx); static bool arm_print_operand_punct_valid_p (unsigned char code); static const char *fp_const_from_val (REAL_VALUE_TYPE *); static arm_cc get_arm_condition_code (rtx); -static HOST_WIDE_INT int_log2 (HOST_WIDE_INT); static const char *output_multi_immediate (rtx *, const char *, const char *, int, HOST_WIDE_INT); static const char *shift_op (rtx, HOST_WIDE_INT *); @@ -18920,7 +18919,8 @@ shift_op (rtx op, HOST_WIDE_INT *amountp) return NULL; } - *amountp = int_log2 (*amountp); + *amountp = exact_log2 (*amountp); + gcc_assert (IN_RANGE (*amountp, 0, 31)); return ARM_LSL_NAME; default: @@ -18952,22 +18952,6 @@ shift_op (rtx op, HOST_WIDE_INT *amountp) return mnem; } -/* Obtain the shift from the POWER of two. */ - -static HOST_WIDE_INT -int_log2 (HOST_WIDE_INT power) -{ - HOST_WIDE_INT shift = 0; - - while ((((HOST_WIDE_INT) 1 << shift) & power) == 0) - { - gcc_assert (shift <= 31); - shift++; - } - - return shift; -} - /* Output a .ascii pseudo-op, keeping track of lengths. This is because /bin/as is horribly restrictive. The judgement about whether or not each character is 'printable' (and can be output as @@ -27691,7 +27675,11 @@ vfp3_const_double_for_fract_bits (rtx operand) HOST_WIDE_INT value = real_to_integer (&r0); value = value & 0xffffffff; if ((value != 0) && ( (value & (value - 1)) == 0)) - return int_log2 (value); + { + int ret = exact_log2 (value); + gcc_assert (IN_RANGE (ret, 0, 31)); + return ret; + } } } return 0;