blob: 335f2d774b8c748a5216ba33f587ffde7eb6a28c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
diff --git a/libpcc/bitcnt.c b/libpcc/bitcnt.c
index 26ecc01..c3bd54e 100644
--- a/libpcc/bitcnt.c
+++ b/libpcc/bitcnt.c
@@ -1,9 +1,22 @@
+// Only use __has_builtin in compilers that support it.
+#ifndef __has_builtin
+ #define __has_builtin(x) 0
+#endif
+#if !__has_builtin(__builtin_clz)
int __builtin_clz(unsigned int);
+#endif
+#if !__has_builtin(__builtin_ctz)
int __builtin_ctz(unsigned int);
+#endif
+#if !__has_builtin(__builtin_clzl)
int __builtin_clzl(unsigned long);
+#endif
+#if !__has_builtin(__builtin_ctzl)
int __builtin_ctzl(unsigned long);
+#endif
+#if !__has_builtin(__builtin_clz)
int
__builtin_clz(unsigned int v)
{
@@ -14,7 +27,9 @@ __builtin_clz(unsigned int v)
break;
return i;
}
+#endif
+#if !__has_builtin(__builtin_ctz)
int
__builtin_ctz(unsigned int v)
{
@@ -25,7 +40,9 @@ __builtin_ctz(unsigned int v)
break;
return i;
}
+#endif
+#if !__has_builtin(__builtin_clzl)
int
__builtin_clzl(unsigned long v)
{
@@ -37,7 +54,9 @@ __builtin_clzl(unsigned long v)
break;
return i;
}
+#endif
+#if !__has_builtin(__builtin_ctzl)
int
__builtin_ctzl(unsigned long v)
{
@@ -48,3 +67,4 @@ __builtin_ctzl(unsigned long v)
break;
return i;
}
+#endif
|