[PATCH] D43146: [builtin] Update c?zdi2 to cover Linux/sparc

James Clarke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 19 08:43:51 PST 2018


jrtc27 updated this revision to Diff 134930.
jrtc27 added a comment.
Herald added a subscriber: delcypher.

[builtins] Fix c?zdi2 on sparc64/Linux and refine mips64/riscv tests

On sparc64/Linux, __sparc64__ isn't defined; the canonical way of
checking for sparc64 is __sparc__ && __arch64__, which also works on the
BSDs and Solaris. Newer mips64 CPUs have a clz instruction which is used
for both clz and ctz (except in mips16 mode), so those do not need the
workaround, nor does riscv32. This fixes and refines https://reviews.llvm.org/rL324593.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D43146

Files:
  lib/builtins/clzdi2.c
  lib/builtins/ctzdi2.c


Index: lib/builtins/ctzdi2.c
===================================================================
--- lib/builtins/ctzdi2.c
+++ lib/builtins/ctzdi2.c
@@ -16,8 +16,14 @@
 
 /* Returns: the number of trailing 0-bits  */
 
-#if !defined(__clang__) && (defined(__sparc64__) || defined(__mips64) || defined(__riscv__))
-/* gcc resolves __builtin_ctz -> __ctzdi2 leading to infinite recursion */
+#if !defined(__clang__) \
+    && ((defined(__sparc__) && defined(__arch64__)) \
+        || (defined(__mips64) \
+            && (!defined(__mips_isa_rev) || __mips_isa_rev < 1 || defined(__mips16))) \
+        || (defined(__riscv__) && __SIZEOF_POINTER__ >= 8))
+/* On 64-bit architectures with neither a native clz instruction nor a native
+ * ctz instruction, gcc resolves __builtin_ctz to __ctzdi2 rather than
+ * __ctzsi2, leading to infinite recursion. */
 #define __builtin_ctz(a) __ctzsi2(a)
 extern si_int __ctzsi2(si_int);
 #endif
Index: lib/builtins/clzdi2.c
===================================================================
--- lib/builtins/clzdi2.c
+++ lib/builtins/clzdi2.c
@@ -16,8 +16,14 @@
 
 /* Returns: the number of leading 0-bits */
 
-#if !defined(__clang__) && (defined(__sparc64__) || defined(__mips64) || defined(__riscv__))
-/* gcc resolves __builtin_clz -> __clzdi2 leading to infinite recursion */
+#if !defined(__clang__) \
+    && ((defined(__sparc__) && defined(__arch64__)) \
+        || (defined(__mips64) \
+            && (!defined(__mips_isa_rev) || __mips_isa_rev < 1 || defined(__mips16))) \
+        || (defined(__riscv__) && __SIZEOF_POINTER__ >= 8))
+/* On 64-bit architectures with neither a native clz instruction nor a native
+ * ctz instruction, gcc resolves __builtin_clz to __clzdi2 rather than
+ * __clzsi2, leading to infinite recursion. */
 #define __builtin_clz(a) __clzsi2(a)
 extern si_int __clzsi2(si_int);
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43146.134930.patch
Type: text/x-patch
Size: 1862 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180219/dfcd9733/attachment.bin>


More information about the llvm-commits mailing list