Debian Codegraph @

debian/patches/cpuid

raw symbols SCIP
1 From: Michael R. Crusoe <[email protected]>
2 Subject: enable cpuid on arm64, pcc64el, and other architectures
3 Forwarded: https://github.com/jeffdaily/parasail/pull/102
4
5 --- canu.orig/src/utility/src/parasail/cpuid.c
6 +++ canu/src/utility/src/parasail/cpuid.c
7 @@ -13,6 +13,44 @@
8
9 #include "parasail/cpuid.h"
10
11 +#if defined(__arm__) || defined(__aarch64__) || defined(__powerpc__) || defined(__PPC__) || defined(__powerpc64__) || defined(__PPC64__)
12 +
13 +/* stubs for all non-x86_64 platforms */
14 +int parasail_can_use_avx512vbmi() { return 0; }
15 +int parasail_can_use_avx512bw() { return 0; }
16 +int parasail_can_use_avx512f() { return 0; }
17 +int parasail_can_use_avx2() { return 0; }
18 +int parasail_can_use_sse41() { return 0; }
19 +int parasail_can_use_sse2() { return 0; }
20 +
21 +#if defined(__powerpc__) || defined(__PPC__) || defined(__powerpc64__) || defined(__PPC64__)
22 +int parasail_can_use_altivec()
23 +{
24 +#if HAVE_ALTIVEC
25 + return 1;
26 +#else
27 + return 0;
28 +#endif
29 +}
30 +#else
31 +int parasail_can_use_altivec() { return 0; }
32 +#endif
33 +
34 +#if defined(__arm__) || defined(__aarch64__)
35 +int parasail_can_use_neon()
36 +{
37 +#if HAVE_NEON
38 + return 1;
39 +#else
40 + return 0;
41 +#endif
42 +}
43 +#else
44 +int parasail_can_use_neon() { return 0; }
45 +#endif
46 +
47 +#elif defined(__x86_64__) || defined(__i386__)
48 +
49 #include <stdint.h>
50 #if defined(_MSC_VER)
51 # include <intrin.h>
52 @@ -33,7 +71,7 @@
53 "+a" (eax), "+c" (ecx), "=d" (edx) );
54 abcd[0] = eax; abcd[1] = ebx; abcd[2] = ecx; abcd[3] = edx;
55 #endif
56 -}
57 +}
58
59
60 #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1300)
61 @@ -42,8 +80,13 @@
62
63 static int check_4th_gen_intel_core_features()
64 {
65 - const int the_4th_gen_features =
66 + /* we only care about avx2, not the other features */
67 +#if 0
68 + const int the_4th_gen_features =
69 (_FEATURE_AVX2 | _FEATURE_FMA | _FEATURE_BMI | _FEATURE_LZCNT | _FEATURE_MOVBE);
70 +#else
71 + const int the_4th_gen_features = _FEATURE_AVX2;
72 +#endif
73 return _may_i_use_cpu_feature( the_4th_gen_features );
74 }
75
76 @@ -69,7 +112,7 @@
77
78 #else /* non-Intel compiler */
79
80 -static int check_xcr0_ymm()
81 +static int check_xcr0_ymm()
82 {
83 #if HAVE_XGETBV
84 uint32_t xcr0;
85 @@ -102,31 +145,42 @@
86
87 static int check_4th_gen_intel_core_features()
88 {
89 + /* we only care about avx2, not the other features */
90 uint32_t abcd[4];
91 - uint32_t fma_movbe_osxsave_mask = ((1U << 12) | (1U << 22) | (1U << 27));
92 - uint32_t avx2_bmi12_mask = (1U << 5) | (1U << 3) | (1U << 8);
93 -
94 - /* CPUID.(EAX=01H, ECX=0H):ECX.FMA[bit 12]==1 &&
95 - CPUID.(EAX=01H, ECX=0H):ECX.MOVBE[bit 22]==1 &&
96 + //uint32_t fma_movbe_osxsave_mask = ((1U << 12) | (1U << 22) | (1U << 27));
97 + //uint32_t avx2_bmi12_mask = (1U << 5) | (1U << 3) | (1U << 8);
98 + uint32_t avx2_mask = (1U << 5);
99 +
100 +#if 0
101 + /* CPUID.(EAX=01H, ECX=0H):ECX.FMA[bit 12]==1 &&
102 + CPUID.(EAX=01H, ECX=0H):ECX.MOVBE[bit 22]==1 &&
103 CPUID.(EAX=01H, ECX=0H):ECX.OSXSAVE[bit 27]==1 */
104 run_cpuid( 1, 0, abcd );
105 - if ( (abcd[2] & fma_movbe_osxsave_mask) != fma_movbe_osxsave_mask )
106 + if ( (abcd[2] & fma_movbe_osxsave_mask) != fma_movbe_osxsave_mask )
107 return 0;
108
109 if ( ! check_xcr0_ymm() )
110 return 0;
111 +#endif
112
113 /* CPUID.(EAX=07H, ECX=0H):EBX.AVX2[bit 5]==1 &&
114 CPUID.(EAX=07H, ECX=0H):EBX.BMI1[bit 3]==1 &&
115 CPUID.(EAX=07H, ECX=0H):EBX.BMI2[bit 8]==1 */
116 run_cpuid( 7, 0, abcd );
117 - if ( (abcd[1] & avx2_bmi12_mask) != avx2_bmi12_mask )
118 +#if 0
119 + if ( (abcd[1] & avx2_bmi12_mask) != avx2_bmi12_mask )
120 return 0;
121 +#else
122 + if ( (abcd[1] & avx2_mask) != avx2_mask )
123 + return 0;
124 +#endif
125
126 +#if 0
127 /* CPUID.(EAX=80000001H):ECX.LZCNT[bit 5]==1 */
128 run_cpuid( 0x80000001, 0, abcd );
129 if ( (abcd[2] & (1U << 5)) == 0)
130 return 0;
131 +#endif
132
133 return 1;
134 }
135 @@ -141,7 +195,7 @@
136
137 /* CPUID.(EAX=01H, ECX=0H):ECX.OSXSAVE[bit 27]==1 */
138 run_cpuid( 1, 0, abcd );
139 - if ( (abcd[2] & osxsave_mask) != osxsave_mask )
140 + if ( (abcd[2] & osxsave_mask) != osxsave_mask )
141 return 0;
142
143 if ( ! check_xcr0_zmm() )
144 @@ -152,7 +206,7 @@
145 CPUID.(EAX=07H, ECX=0H):EBX.AVX-512ER[bit 27]==1 &&
146 CPUID.(EAX=07H, ECX=0H):EBX.AVX-512CD[bit 28]==1 */
147 run_cpuid( 7, 0, abcd );
148 - if ( (abcd[1] & avx512f_mask) != avx512f_mask )
149 + if ( (abcd[1] & avx512f_mask) != avx512f_mask )
150 return 0;
151
152 return 1;
153 @@ -167,7 +221,7 @@
154
155 /* CPUID.(EAX=01H, ECX=0H):ECX.OSXSAVE[bit 27]==1 */
156 run_cpuid( 1, 0, abcd );
157 - if ( (abcd[2] & osxsave_mask) != osxsave_mask )
158 + if ( (abcd[2] & osxsave_mask) != osxsave_mask )
159 return 0;
160
161 if ( ! check_xcr0_zmm() )
162 @@ -177,7 +231,7 @@
163 CPUID.(EAX=07H, ECX=0H):EBX.AVX-512DQ[bit 17]==1 &&
164 CPUID.(EAX=07H, ECX=0H):EBX.AVX-512VL[bit 31]==1 */
165 run_cpuid( 7, 0, abcd );
166 - if ( (abcd[1] & avx512bw_mask) != avx512bw_mask )
167 + if ( (abcd[1] & avx512bw_mask) != avx512bw_mask )
168 return 0;
169
170 return 1;
171 @@ -191,7 +245,7 @@
172
173 /* CPUID.(EAX=01H, ECX=0H):ECX.OSXSAVE[bit 27]==1 */
174 run_cpuid( 1, 0, abcd );
175 - if ( (abcd[2] & osxsave_mask) != osxsave_mask )
176 + if ( (abcd[2] & osxsave_mask) != osxsave_mask )
177 return 0;
178
179 if ( ! check_xcr0_zmm() )
180 @@ -199,7 +253,7 @@
181
182 /* CPUID.(EAX=07H, ECX=0H):ECX.AVX-512VBMI[bit 1]==1 */
183 run_cpuid( 7, 0, abcd );
184 - if ( (abcd[2] & avx512vbmi_mask) != avx512vbmi_mask )
185 + if ( (abcd[2] & avx512vbmi_mask) != avx512vbmi_mask )
186 return 0;
187
188 return 1;
189 @@ -311,3 +365,17 @@
190 return 0;
191 }
192
193 +#else
194 +
195 +/* non-x86, non-ARM, non-PPC */
196 +
197 +int parasail_can_use_avx512vbmi() { return 0; }
198 +int parasail_can_use_avx512bw() { return 0; }
199 +int parasail_can_use_avx512f() { return 0; }
200 +int parasail_can_use_avx2() { return 0; }
201 +int parasail_can_use_sse41() { return 0; }
202 +int parasail_can_use_sse2() { return 0; }
203 +int parasail_can_use_altivec() { return 0; }
204 +int parasail_can_use_neon() { return 0; }
205 +
206 +#endif