From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 78F123856DFB for ; Thu, 26 May 2022 10:08:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 78F123856DFB Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B2AF71477; Thu, 26 May 2022 03:08:49 -0700 (PDT) Received: from e126323.arm.com (unknown [10.57.6.127]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 046053F70D; Thu, 26 May 2022 03:08:48 -0700 (PDT) From: Richard Earnshaw To: binutils@sourceware.org Cc: Richard Earnshaw Subject: [committed] arm: avoid use of GNU builtin function in s_arm_unwind_save_mixed Date: Thu, 26 May 2022 11:08:24 +0100 Message-Id: <20220526100824.3032439-1-rearnsha@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2.25.1" Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 May 2022 10:08:51 -0000 This is a multi-part message in MIME format. --------------2.25.1 Content-Type: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding: 8bit Whilst reviewing Luis' proposed change to s_arm_unwind_save_mixed yesterday I noticed that we were making use of __builting_clzl directly within the main function, which is not guaranteed to be portable. Whilst studying the code further, I also realized that it could be rewritten without using it and also reworked to remove a lot of unnecessary iterations steps. So this patch does that (and also removes the source of the warning that Luis was trying to fix). Finally, with the rewrite we can also simplify the caller of this routine as the new version can handle all the cases directly. * config/tc-arm.c (s_arm_unwind_save_mixed): Rewrite without using __builtin_clzl. (s_arm_unwind_save): Simplify logic for simple/mixed register saves. --- gas/config/tc-arm.c | 57 ++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 40 deletions(-) --------------2.25.1 Content-Type: text/x-patch; name="0001-arm-avoid-use-of-GNU-builtin-function-in-s_arm_unwin.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0001-arm-avoid-use-of-GNU-builtin-function-in-s_arm_unwin.patch" diff --git a/gas/config/tc-arm.c b/gas/config/tc-arm.c index 538d83f5462..1721097cfca 100644 --- a/gas/config/tc-arm.c +++ b/gas/config/tc-arm.c @@ -4716,39 +4716,29 @@ s_arm_unwind_save_mmxwcg (void) ignore_rest_of_line (); } +/* Convert range and mask_range into a sequence of s_arm_unwind_core + and s_arm_unwind_pseudo operations. We assume that mask_range will + not have consecutive bits set, or that one operation per bit is + acceptable. */ + static void s_arm_unwind_save_mixed (long range, long mask_range) { - const long roof = ((sizeof (long) * CHAR_BIT) - 1) - - __builtin_clzl (mask_range); - - long subrange = 0; - unsigned lim_lo = 0; - unsigned lim_hi = 0; - - /* Iterate over pseudoregister to establish subrange bounds. */ - for (; lim_hi <= roof; lim_hi++) + while (mask_range) { - if (mask_range & (1 << lim_hi)) - { - /* Once we know where to split our range, construct subrange. */ - for (unsigned n = lim_lo; n < lim_hi; n++) - { - if (range & (1 << n)) - subrange |= (1 << n); - } + long mask_bit = mask_range & -mask_range; + long subrange = range & (mask_bit - 1); - s_arm_unwind_save_core (subrange); - s_arm_unwind_save_pseudo (1 << lim_hi); + if (subrange) + s_arm_unwind_save_core (subrange); - subrange = 0; - lim_lo = lim_hi + 1; - } + s_arm_unwind_save_pseudo (mask_bit); + range &= ~subrange; + mask_range &= ~mask_bit; } - lim_lo = 0xffff << roof; - subrange = range & lim_lo; - s_arm_unwind_save_core (subrange); + if (range) + s_arm_unwind_save_core (range); } /* Parse an unwind_save directive. @@ -4810,21 +4800,8 @@ s_arm_unwind_save (int arch_v6) demand_empty_rest_of_line (); - if (!mask_range) - { - s_arm_unwind_save_core (range); - return; - } - else if (!range) - { - s_arm_unwind_save_pseudo (mask_range); - return; - } - else - { - s_arm_unwind_save_mixed (range, mask_range); - return; - } + s_arm_unwind_save_mixed (range, mask_range); + return; case REG_TYPE_VFD: if (arch_v6) --------------2.25.1--