public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, x86_64]: Provide longlong.h definitions for 128bit operations
@ 2007-05-16 20:25 Uros Bizjak
  2007-05-16 20:34 ` Chris Lattner
  0 siblings, 1 reply; 36+ messages in thread
From: Uros Bizjak @ 2007-05-16 20:25 UTC (permalink / raw)
  To: GCC Patches

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

Hello!

This patch adds 128bit operations for x86_64 to longlong.h to speed up 
TImode and TFmode arithmetic. The patch also redefines i386's 
definitions of count_trailing/leading_zeros from asm to 
__builtin_ctz/__builtin_clz builtins, as provided by i386 backend.

Patch was bootstrapped on x86_64-pc-linux-gnu, regression tested for all 
default languages with and without -m32.

2007-05-16  Uros Bizjak  <ubizjak@gmail.com>

        * longlong.h (__x86_64__): Add definitions for add_ssaaaa,
        sub_ddmmss, umul_ppmm, udiv_qrnnd, count_leading_zeros and
        count_trailing_zeros.
        (__i386__): Implement count_leading_zeros using __builtin_clz().
        Implement count_trailing_zeros usign __builtin_ctz().

Uros.

[-- Attachment #2: x86_64-longlong.diff --]
[-- Type: text/x-patch, Size: 2243 bytes --]

Index: longlong.h
===================================================================
--- longlong.h	(revision 124771)
+++ longlong.h	(working copy)
@@ -341,19 +341,48 @@
 	   : "0" ((USItype) (n0)),					\
 	     "1" ((USItype) (n1)),					\
 	     "rm" ((USItype) (dv)))
-#define count_leading_zeros(count, x) \
-  do {									\
-    USItype __cbtmp;							\
-    __asm__ ("bsrl %1,%0"						\
-	     : "=r" (__cbtmp) : "rm" ((USItype) (x)));			\
-    (count) = __cbtmp ^ 31;						\
-  } while (0)
-#define count_trailing_zeros(count, x) \
-  __asm__ ("bsfl %1,%0" : "=r" (count) : "rm" ((USItype)(x)))
+#define count_leading_zeros(count, x)	((count) = __builtin_clz (x))
+#define count_trailing_zeros(count, x)	((count) = __builtin_ctz (x))
 #define UMUL_TIME 40
 #define UDIV_TIME 40
 #endif /* 80x86 */
 
+#if (defined (__x86_64__) || defined (__i386__)) && W_TYPE_SIZE == 64
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  __asm__ ("addq %5,%1\n\tadcq %3,%0"					\
+	   : "=r" ((UDItype) (sh)),					\
+	     "=&r" ((UDItype) (sl))					\
+	   : "%0" ((UDItype) (ah)),					\
+	     "rem" ((UDItype) (bh)),					\
+	     "%1" ((UDItype) (al)),					\
+	     "rem" ((UDItype) (bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  __asm__ ("subq %5,%1\n\tsbbq %3,%0"					\
+	   : "=r" ((UDItype) (sh)),					\
+	     "=&r" ((UDItype) (sl))					\
+	   : "0" ((UDItype) (ah)),					\
+	     "rem" ((UDItype) (bh)),					\
+	     "1" ((UDItype) (al)),					\
+	     "rem" ((UDItype) (bl)))
+#define umul_ppmm(w1, w0, u, v) \
+  __asm__ ("mulq %3"							\
+	   : "=a" ((UDItype) (w0)),					\
+	     "=d" ((UDItype) (w1))					\
+	   : "%0" ((UDItype) (u)),					\
+	     "rm" ((UDItype) (v)))
+#define udiv_qrnnd(q, r, n1, n0, dv) \
+  __asm__ ("divq %4"							\
+	   : "=a" ((UDItype) (q)),					\
+	     "=d" ((UDItype) (r))					\
+	   : "0" ((UDItype) (n0)),					\
+	     "1" ((UDItype) (n1)),					\
+	     "rm" ((UDItype) (dv)))
+#define count_leading_zeros(count, x)	((count) = __builtin_clzl (x))
+#define count_trailing_zeros(count, x)	((count) = __builtin_ctzl (x))
+#define UMUL_TIME 40
+#define UDIV_TIME 40
+#endif /* x86_64 */
+
 #if defined (__i960__) && W_TYPE_SIZE == 32
 #define umul_ppmm(w1, w0, u, v) \
   ({union {UDItype __ll;						\

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

end of thread, other threads:[~2007-05-24 19:56 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-16 20:25 [PATCH, x86_64]: Provide longlong.h definitions for 128bit operations Uros Bizjak
2007-05-16 20:34 ` Chris Lattner
2007-05-17  5:57   ` Uros Bizjak
2007-05-17  6:09     ` Eric Christopher
2007-05-17  6:12       ` Andrew Pinski
2007-05-17  6:22         ` Uros Bizjak
2007-05-17 11:13         ` Uros Bizjak
2007-05-17  6:43     ` Chris Lattner
2007-05-17  7:22       ` Paolo Bonzini
2007-05-17  9:25         ` Uros Bizjak
2007-05-17 11:15           ` Rask Ingemann Lambertsen
2007-05-17 21:38             ` Rask Ingemann Lambertsen
2007-05-18  6:54               ` Ian Lance Taylor
2007-05-18  7:10                 ` Eric Botcazou
2007-05-18 16:48                   ` Ian Lance Taylor
2007-05-18 20:37                     ` Eric Botcazou
2007-05-18 22:32                       ` Ian Lance Taylor
2007-05-22 17:27                     ` Roman Zippel
2007-05-22 17:36                       ` Ian Lance Taylor
2007-05-22 22:27                         ` Rask Ingemann Lambertsen
2007-05-22 22:32                           ` Ian Lance Taylor
2007-05-24 20:00                             ` Rask Ingemann Lambertsen
2007-05-23 17:27                         ` Roman Zippel
2007-05-23 17:48                           ` Ian Lance Taylor
2007-05-22 22:19                       ` Rask Ingemann Lambertsen
2007-05-17 16:49           ` Chris Lattner
2007-05-17 17:05             ` Eric Christopher
2007-05-18 10:23               ` Uros Bizjak
2007-05-18 18:31                 ` Chris Lattner
2007-05-18 19:58                   ` Uros Bizjak
2007-05-18 20:15                     ` Chris Lattner
2007-05-18 21:17                       ` Uros Bizjak
2007-05-18 21:49                       ` Uros Bizjak
2007-05-18 22:49                         ` Chris Lattner
2007-05-18 20:07                   ` Uros Bizjak
2007-05-18 19:43               ` Uros Bizjak

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