All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Vorontsov <avorontsov@ru.mvista.com>
To: systemtap@sourceware.org
Cc: linuxppc-dev@ozlabs.org
Subject: [PATCH 7/8] Implement _div64 and _mod64 for ppc32
Date: Sat, 28 Nov 2009 01:33:49 +0300	[thread overview]
Message-ID: <20091127223349.GG21805@oksana.dev.rtsoft.ru> (raw)
In-Reply-To: <20091127223251.GA17065@oksana.dev.rtsoft.ru>

_div64 and _mod64 arch-specific details were taken from gcc/longlong.h,
just as it was done for i386.

Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
---
 runtime/arith.c |   42 +++++++++++++++++++++++++++++++++++++++---
 1 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/runtime/arith.c b/runtime/arith.c
index 4c818a7..a032e9c 100644
--- a/runtime/arith.c
+++ b/runtime/arith.c
@@ -20,7 +20,8 @@
 /* 64-bit division for 64-bit cpus and i386 */
 /* Other 32-bit cpus will need to modify this file. */
 
-#if defined (__i386__) || defined(__arm__)
+#if defined (__i386__) || defined(__arm__) || \
+	(defined(__powerpc__) && !defined(__powerpc64__))
 static long long _div64 (long long u, long long v);
 static long long _mod64 (long long u, long long v);
 #endif
@@ -114,7 +115,8 @@ static int _stp_random_pm (unsigned n)
 
 
 
-#if defined (__i386__) || defined (__arm__)
+#if defined (__i386__) || defined (__arm__) || \
+	(defined(__powerpc__) && !defined(__powerpc64__))
 
 /* 64-bit division functions extracted from libgcc */
 typedef long long DWtype;
@@ -181,6 +183,40 @@ typedef union
 		(count) = __cbtmp ^ 31;					\
 	} while (0)
 
+#elif defined (__powerpc__)
+/* these are the ppc versions of these macros from gcc/longlong.h */
+
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  do {									\
+    if (__builtin_constant_p (ah) && (ah) == 0)				\
+      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2"	\
+	       : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
+    else if (__builtin_constant_p (ah) && (ah) == ~(USItype) 0)		\
+      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2"	\
+	       : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
+    else if (__builtin_constant_p (bh) && (bh) == 0)			\
+      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2"		\
+	       : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
+    else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0)		\
+      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2"		\
+	       : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
+    else								\
+      __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2"	\
+	       : "=r" (sh), "=&r" (sl)					\
+	       : "r" (ah), "r" (bh), "rI" (al), "r" (bl));		\
+  } while (0)
+
+#define count_leading_zeros(count, x) \
+  __asm__ ("{cntlz|cntlzw} %0,%1" : "=r" (count) : "r" (x))
+#define COUNT_LEADING_ZEROS_0 32
+
+#define umul_ppmm(ph, pl, m0, m1) \
+  do {									\
+    USItype __m0 = (m0), __m1 = (m1);					\
+    __asm__ ("mulhwu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1));	\
+    (pl) = __m0 * __m1;							\
+  } while (0)
+
 #elif defined (__arm__)
 
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
@@ -548,6 +584,6 @@ static long long _mod64 (long long u, long long v)
 	return w;
 }
 
-#endif /* __i386__ || __arm__ */
+#endif /* __i386__ || __arm__ || (__powerpc__ && !__powerpc64__) */
 
 #endif /* _ARITH_C_ */
-- 
1.6.3.3

  parent reply	other threads:[~2009-11-27 22:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-27 22:32 [PATCH 0/8 userland!] systemtap: Add initial support for ppc32 Anton Vorontsov
2009-11-27 22:33 ` [PATCH 1/8] Rename uprobes_ppc64.c to uprobes_ppc.c, use it " Anton Vorontsov
2009-11-27 22:33 ` [PATCH 2/8] Rename stack-ppc64.c to stack-ppc.c Anton Vorontsov
2009-11-27 22:33 ` [PATCH 3/8] stack-ppc: Adjust for ppc32 Anton Vorontsov
2009-11-27 22:33 ` [PATCH 4/8] Implement ppc32 variant of __is_user_regs Anton Vorontsov
2009-11-27 22:33 ` [PATCH 5/8] Share ppc64 and ppc32 code where possible Anton Vorontsov
2009-11-27 22:33 ` [PATCH 6/8] Use proper types for do_div Anton Vorontsov
2009-12-09 15:56   ` Mark Wielaard
2009-12-09 16:09     ` Anton Vorontsov
2009-12-09 22:47       ` Mark Wielaard
2009-11-27 22:33 ` Anton Vorontsov [this message]
2009-11-27 22:33 ` [PATCH 8/8] Change KERNEL_RELOC_SYMBOL to "_stext" on ppc32 Anton Vorontsov
2009-12-01 17:54 ` [PATCH 0/8 userland!] systemtap: Add initial support for ppc32 Frank Ch. Eigler
2009-12-01 19:13 ` Jim Keniston

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=20091127223349.GG21805@oksana.dev.rtsoft.ru \
    --to=avorontsov@ru.mvista.com \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=systemtap@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.