summaryrefslogtreecommitdiff
path: root/lib/libcompiler_rt/clzdi2.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libcompiler_rt/clzdi2.c')
-rw-r--r--lib/libcompiler_rt/clzdi2.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/libcompiler_rt/clzdi2.c b/lib/libcompiler_rt/clzdi2.c
index b56d98f5c01..1819e6be436 100644
--- a/lib/libcompiler_rt/clzdi2.c
+++ b/lib/libcompiler_rt/clzdi2.c
@@ -16,8 +16,13 @@
/* 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(__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