public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Richard Earnshaw <rearnsha@arm.com>
To: binutils@sourceware.org
Cc: Richard Earnshaw <rearnsha@arm.com>
Subject: [committed] arm: avoid use of GNU builtin function in s_arm_unwind_save_mixed
Date: Thu, 26 May 2022 11:08:24 +0100	[thread overview]
Message-ID: <20220526100824.3032439-1-rearnsha@arm.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 878 bytes --]


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(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-arm-avoid-use-of-GNU-builtin-function-in-s_arm_unwin.patch --]
[-- Type: text/x-patch; name="0001-arm-avoid-use-of-GNU-builtin-function-in-s_arm_unwin.patch", Size: 2109 bytes --]

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)

                 reply	other threads:[~2022-05-26 10:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220526100824.3032439-1-rearnsha@arm.com \
    --to=rearnsha@arm.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).