Debian Codegraph @

mysys/crc32/clang_workaround.h

raw symbols SCIP
1 #ifndef CLANG_WORKAROUNDS_H
2 #define CLANG_WORKAROUNDS_H
3
4 /*
5 * These stubs fix clang incompatibilities with GCC builtins.
6 */
7
8 #ifndef __builtin_crypto_vpmsumw
9 #define __builtin_crypto_vpmsumw __builtin_crypto_vpmsumb
10 #endif
11 #ifndef __builtin_crypto_vpmsumd
12 #define __builtin_crypto_vpmsumd __builtin_crypto_vpmsumb
13 #endif
14
15 static inline
16 __vector unsigned long long __attribute__((overloadable))
17 vec_ld(int __a, const __vector unsigned long long* __b)
18 {
19 return (__vector unsigned long long)__builtin_altivec_lvx(__a, __b);
20 }
21
22 /*
23 * GCC __builtin_pack_vector_int128 returns a vector __int128_t but Clang
24 * does not recognize this type. On GCC this builtin is translated to a
25 * xxpermdi instruction that only moves the registers __a, __b instead generates
26 * a load.
27 *
28 * Clang has vec_xxpermdi intrinsics. It was implemented in 4.0.0.
29 */
30 static inline
31 __vector unsigned long long __builtin_pack_vector (unsigned long __a,
32 unsigned long __b)
33 {
34 #if defined(__BIG_ENDIAN__)
35 __vector unsigned long long __v = {__a, __b};
36 #else
37 __vector unsigned long long __v = {__b, __a};
38 #endif
39 return __v;
40 }
41
42 /*
43 * Clang 7 changed the behavior of vec_xxpermdi in order to provide the same
44 * behavior of GCC. That means code adapted to Clang >= 7 does not work on
45 * Clang <= 6. So, fallback to __builtin_unpack_vector() on Clang <= 6.
46 */
47 #if !defined vec_xxpermdi || __clang_major__ <= 6
48
49 static inline
50 unsigned long __builtin_unpack_vector (__vector unsigned long long __v,
51 int __o)
52 {
53 return __v[__o];
54 }
55
56 #if defined(__BIG_ENDIAN__)
57 #define __builtin_unpack_vector_0(a) __builtin_unpack_vector ((a), 0)
58 #define __builtin_unpack_vector_1(a) __builtin_unpack_vector ((a), 1)
59 #else
60 #define __builtin_unpack_vector_0(a) __builtin_unpack_vector ((a), 1)
61 #define __builtin_unpack_vector_1(a) __builtin_unpack_vector ((a), 0)
62 #endif
63
64 #else
65
66 static inline
67 unsigned long __builtin_unpack_vector_0 (__vector unsigned long long __v)
68 {
69 #if defined(__BIG_ENDIAN__)
70 return vec_xxpermdi(__v, __v, 0x0)[0];
71 #else
72 return vec_xxpermdi(__v, __v, 0x3)[0];
73 #endif
74 }
75
76 static inline
77 unsigned long __builtin_unpack_vector_1 (__vector unsigned long long __v)
78 {
79 #if defined(__BIG_ENDIAN__)
80 return vec_xxpermdi(__v, __v, 0x3)[0];
81 #else
82 return vec_xxpermdi(__v, __v, 0x0)[0];
83 #endif
84 }
85 #endif /* vec_xxpermdi */
86
87 #endif