public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [committed] arm: avoid use of GNU builtin function in s_arm_unwind_save_mixed
@ 2022-05-26 10:08 Richard Earnshaw
  0 siblings, 0 replies; only message in thread
From: Richard Earnshaw @ 2022-05-26 10:08 UTC (permalink / raw)
  To: binutils; +Cc: Richard Earnshaw

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-26 10:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-26 10:08 [committed] arm: avoid use of GNU builtin function in s_arm_unwind_save_mixed Richard Earnshaw

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