public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Better __ashlDI3, __ashrDI3 and __lshrDI3 functions, plus fixed __bswapsi2 function
@ 2020-11-10 17:59 Stefan Kanthak
  2020-11-10 18:08 ` Eric Botcazou
                   ` (3 more replies)
  0 siblings, 4 replies; 32+ messages in thread
From: Stefan Kanthak @ 2020-11-10 17:59 UTC (permalink / raw)
  To: gcc-patches

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

The implementation of the __ashlDI3(), __ashrDI3() and __lshrDI3() functions
is rather bad, it yields bad machine code at least on i386 and AMD64.
Since GCC knows how to shift integers twice the register size these functions
can be written as one-liners.

The implementation of the __bswapsi2() function uses SIGNED instead of
unsigned mask values; cf. __bswapdi2()

Stefan Kanthak

[-- Attachment #2: libgcc2.diff --]
[-- Type: application/octet-stream, Size: 2702 bytes --]

--- -/libgcc/libgcc2.h
+++ +/libgcc/libgcc2.h
@@ -391,7 +391,7 @@
 extern DWtype __negdi2 (DWtype);
 #endif
 
-extern DWtype __lshrdi3 (DWtype, shift_count_type);
+extern UDWtype __lshrdi3 (UDWtype, shift_count_type);
 extern DWtype __ashldi3 (DWtype, shift_count_type);
 extern DWtype __ashrdi3 (DWtype, shift_count_type);
 
--- -/libgcc/libgcc2.c
+++ +/libgcc/libgcc2.c
@@ -398,30 +398,10 @@
 /* Unless shift functions are defined with full ANSI prototypes,
    parameter b will be promoted to int if shift_count_type is smaller than an int.  */
 #ifdef L_lshrdi3
-DWtype
-__lshrdi3 (DWtype u, shift_count_type b)
+UDWtype
+__lshrdi3 (UDWtype u, shift_count_type b)
 {
-  if (b == 0)
-    return u;
-
-  const DWunion uu = {.ll = u};
-  const shift_count_type bm = W_TYPE_SIZE - b;
-  DWunion w;
-
-  if (bm <= 0)
-    {
-      w.s.high = 0;
-      w.s.low = (UWtype) uu.s.high >> -bm;
-    }
-  else
-    {
-      const UWtype carries = (UWtype) uu.s.high << bm;
-
-      w.s.high = (UWtype) uu.s.high >> b;
-      w.s.low = ((UWtype) uu.s.low >> b) | carries;
-    }
-
-  return w.ll;
+  return u >> b;
 }
 #endif
 
@@ -429,27 +409,7 @@
 DWtype
 __ashldi3 (DWtype u, shift_count_type b)
 {
-  if (b == 0)
-    return u;
-
-  const DWunion uu = {.ll = u};
-  const shift_count_type bm = W_TYPE_SIZE - b;
-  DWunion w;
-
-  if (bm <= 0)
-    {
-      w.s.low = 0;
-      w.s.high = (UWtype) uu.s.low << -bm;
-    }
-  else
-    {
-      const UWtype carries = (UWtype) uu.s.low >> bm;
-
-      w.s.low = (UWtype) uu.s.low << b;
-      w.s.high = ((UWtype) uu.s.high << b) | carries;
-    }
-
-  return w.ll;
+  return u << b;
 }
 #endif
 
@@ -457,28 +417,7 @@
 DWtype
 __ashrdi3 (DWtype u, shift_count_type b)
 {
-  if (b == 0)
-    return u;
-
-  const DWunion uu = {.ll = u};
-  const shift_count_type bm = W_TYPE_SIZE - b;
-  DWunion w;
-
-  if (bm <= 0)
-    {
-      /* w.s.high = 1..1 or 0..0 */
-      w.s.high = uu.s.high >> (W_TYPE_SIZE - 1);
-      w.s.low = uu.s.high >> -bm;
-    }
-  else
-    {
-      const UWtype carries = (UWtype) uu.s.high << bm;
-
-      w.s.high = uu.s.high >> b;
-      w.s.low = ((UWtype) uu.s.low >> b) | carries;
-    }
-
-  return w.ll;
+  return u >> b;
 }
 #endif
 \f
@@ -486,10 +425,10 @@
 SItype
 __bswapsi2 (SItype u)
 {
-  return ((((u) & 0xff000000) >> 24)
-	  | (((u) & 0x00ff0000) >>  8)
-	  | (((u) & 0x0000ff00) <<  8)
-	  | (((u) & 0x000000ff) << 24));
+  return ((((u) & 0xff000000u) >> 24)
+	  | (((u) & 0x00ff0000u) >>  8)
+	  | (((u) & 0x0000ff00u) <<  8)
+	  | (((u) & 0x000000ffu) << 24));
 }
 #endif
 #ifdef L_bswapdi2

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2020-11-30  1:06 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-10 17:59 [PATCH] Better __ashlDI3, __ashrDI3 and __lshrDI3 functions, plus fixed __bswapsi2 function Stefan Kanthak
2020-11-10 18:08 ` Eric Botcazou
2020-11-10 19:44   ` Stefan Kanthak
2020-11-10 20:14     ` Jakub Jelinek
2020-11-10 21:09       ` Jeff Law
2020-11-10 21:17         ` Jakub Jelinek
2020-11-10 23:42           ` Jeff Law
2020-11-24  0:21         ` Jeff Law
2020-11-10 22:12       ` Jeff Law
2020-11-10 22:01     ` Jeff Law
2020-11-11  0:00     ` Andreas Schwab
2020-11-24 13:57       ` Stefan Kanthak
2020-11-24 14:34         ` Andreas Schwab
2020-11-24 15:40           ` Stefan Kanthak
2020-11-24 15:49             ` Andreas Schwab
2020-11-25 18:53             ` Jeff Law
2020-11-25 20:22               ` Stefan Kanthak
2020-11-25 20:42                 ` Jakub Jelinek
2020-11-25 21:22                   ` Stefan Kanthak
2020-11-25 22:06                     ` Jeff Law
2020-11-25 23:06                       ` Stefan Kanthak
2020-11-25 20:44                 ` Jeff Law
2020-11-10 18:09 ` Jakub Jelinek
2020-11-10 18:32   ` Jeff Law
2020-11-10 18:26 ` Jakub Jelinek
2020-11-10 23:48 ` Jeff Law
2020-11-10 23:53   ` Jakub Jelinek
2020-11-11  8:33     ` Stefan Kanthak
2020-11-11  9:55       ` Jakub Jelinek
2020-11-11 17:54         ` Joseph Myers
2020-11-23 23:01         ` Jeff Law
2020-11-30  1:06       ` Jeff Law

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