xref: /freebsd/sys/contrib/openzfs/config/toolchain-simd.m4 (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1dnl #
2dnl # Checks if host toolchain supports SIMD instructions
3dnl #
4AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_TOOLCHAIN_SIMD], [
5	case "$host_cpu" in
6		amd64 | x86_64 | x86 | i686)
7			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSE
8			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSE2
9			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSE3
10			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSSE3
11			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSE4_1
12			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSE4_2
13			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX
14			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX2
15			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512F
16			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512CD
17			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512DQ
18			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512BW
19			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512IFMA
20			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512VBMI
21			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512PF
22			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512ER
23			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512VL
24			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AES
25			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_PCLMULQDQ
26			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_MOVBE
27			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_XSAVE
28			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_XSAVEOPT
29			ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_XSAVES
30			;;
31	esac
32])
33
34dnl #
35dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSE
36dnl #
37AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSE], [
38	AC_MSG_CHECKING([whether host toolchain supports SSE])
39
40	AC_LINK_IFELSE([AC_LANG_SOURCE([[
41		void main()
42		{
43			__asm__ __volatile__("xorps %xmm0, %xmm1");
44		}
45	]])], [
46		AC_DEFINE([HAVE_SSE], 1, [Define if host toolchain supports SSE])
47		AC_MSG_RESULT([yes])
48	], [
49		AC_MSG_RESULT([no])
50	])
51])
52
53dnl #
54dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSE2
55dnl #
56AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSE2], [
57	AC_MSG_CHECKING([whether host toolchain supports SSE2])
58
59	AC_LINK_IFELSE([AC_LANG_SOURCE([[
60		void main()
61		{
62			__asm__ __volatile__("pxor %xmm0, %xmm1");
63		}
64	]])], [
65		AC_DEFINE([HAVE_SSE2], 1, [Define if host toolchain supports SSE2])
66		AC_MSG_RESULT([yes])
67	], [
68		AC_MSG_RESULT([no])
69	])
70])
71
72dnl #
73dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSE3
74dnl #
75AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSE3], [
76	AC_MSG_CHECKING([whether host toolchain supports SSE3])
77
78	AC_LINK_IFELSE([AC_LANG_SOURCE([[
79		void main()
80		{
81			char v[16];
82			__asm__ __volatile__("lddqu %0,%%xmm0" :: "m"(v[0]));
83		}
84	]])], [
85		AC_DEFINE([HAVE_SSE3], 1, [Define if host toolchain supports SSE3])
86		AC_MSG_RESULT([yes])
87	], [
88		AC_MSG_RESULT([no])
89	])
90])
91
92dnl #
93dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSSE3
94dnl #
95AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSSE3], [
96	AC_MSG_CHECKING([whether host toolchain supports SSSE3])
97
98	AC_LINK_IFELSE([AC_LANG_SOURCE([[
99		void main()
100		{
101			__asm__ __volatile__("pshufb %xmm0,%xmm1");
102		}
103	]])], [
104		AC_DEFINE([HAVE_SSSE3], 1, [Define if host toolchain supports SSSE3])
105		AC_MSG_RESULT([yes])
106	], [
107		AC_MSG_RESULT([no])
108	])
109])
110
111dnl #
112dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSE4_1
113dnl #
114AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSE4_1], [
115	AC_MSG_CHECKING([whether host toolchain supports SSE4.1])
116
117	AC_LINK_IFELSE([AC_LANG_SOURCE([[
118		void main()
119		{
120			__asm__ __volatile__("pmaxsb %xmm0,%xmm1");
121		}
122	]])], [
123		AC_DEFINE([HAVE_SSE4_1], 1, [Define if host toolchain supports SSE4.1])
124		AC_MSG_RESULT([yes])
125	], [
126		AC_MSG_RESULT([no])
127	])
128])
129
130dnl #
131dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSE4_2
132dnl #
133AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSE4_2], [
134	AC_MSG_CHECKING([whether host toolchain supports SSE4.2])
135
136	AC_LINK_IFELSE([AC_LANG_SOURCE([[
137		void main()
138		{
139			__asm__ __volatile__("pcmpgtq %xmm0, %xmm1");
140		}
141	]])], [
142		AC_DEFINE([HAVE_SSE4_2], 1, [Define if host toolchain supports SSE4.2])
143		AC_MSG_RESULT([yes])
144	], [
145		AC_MSG_RESULT([no])
146	])
147])
148
149dnl #
150dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX
151dnl #
152AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX], [
153	AC_MSG_CHECKING([whether host toolchain supports AVX])
154
155	AC_LINK_IFELSE([AC_LANG_SOURCE([[
156		void main()
157		{
158			char v[32];
159			__asm__ __volatile__("vmovdqa %0,%%ymm0" :: "m"(v[0]));
160		}
161	]])], [
162		AC_MSG_RESULT([yes])
163		AC_DEFINE([HAVE_AVX], 1, [Define if host toolchain supports AVX])
164	], [
165		AC_MSG_RESULT([no])
166	])
167])
168
169dnl #
170dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX2
171dnl #
172AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX2], [
173	AC_MSG_CHECKING([whether host toolchain supports AVX2])
174
175	AC_LINK_IFELSE([AC_LANG_SOURCE([
176	[
177		void main()
178		{
179			__asm__ __volatile__("vpshufb %ymm0,%ymm1,%ymm2");
180		}
181	]])], [
182		AC_MSG_RESULT([yes])
183		AC_DEFINE([HAVE_AVX2], 1, [Define if host toolchain supports AVX2])
184	], [
185		AC_MSG_RESULT([no])
186	])
187])
188
189dnl #
190dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512F
191dnl #
192AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512F], [
193	AC_MSG_CHECKING([whether host toolchain supports AVX512F])
194
195	AC_LINK_IFELSE([AC_LANG_SOURCE([
196	[
197		void main()
198		{
199			__asm__ __volatile__("vpandd %zmm0,%zmm1,%zmm2");
200		}
201	]])], [
202		AC_MSG_RESULT([yes])
203		AC_DEFINE([HAVE_AVX512F], 1, [Define if host toolchain supports AVX512F])
204	], [
205		AC_MSG_RESULT([no])
206	])
207])
208
209dnl #
210dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512CD
211dnl #
212AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512CD], [
213	AC_MSG_CHECKING([whether host toolchain supports AVX512CD])
214
215	AC_LINK_IFELSE([AC_LANG_SOURCE([
216	[
217		void main()
218		{
219			__asm__ __volatile__("vplzcntd %zmm0,%zmm1");
220		}
221	]])], [
222		AC_MSG_RESULT([yes])
223		AC_DEFINE([HAVE_AVX512CD], 1, [Define if host toolchain supports AVX512CD])
224	], [
225		AC_MSG_RESULT([no])
226	])
227])
228
229dnl #
230dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512DQ
231dnl #
232AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512DQ], [
233	AC_MSG_CHECKING([whether host toolchain supports AVX512DQ])
234
235	AC_LINK_IFELSE([AC_LANG_SOURCE([
236	[
237		void main()
238		{
239			__asm__ __volatile__("vandpd %zmm0,%zmm1,%zmm2");
240		}
241	]])], [
242		AC_MSG_RESULT([yes])
243		AC_DEFINE([HAVE_AVX512DQ], 1, [Define if host toolchain supports AVX512DQ])
244	], [
245		AC_MSG_RESULT([no])
246	])
247])
248
249dnl #
250dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512BW
251dnl #
252AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512BW], [
253	AC_MSG_CHECKING([whether host toolchain supports AVX512BW])
254
255	AC_LINK_IFELSE([AC_LANG_SOURCE([
256	[
257		void main()
258		{
259			__asm__ __volatile__("vpshufb %zmm0,%zmm1,%zmm2");
260		}
261	]])], [
262		AC_MSG_RESULT([yes])
263		AC_DEFINE([HAVE_AVX512BW], 1, [Define if host toolchain supports AVX512BW])
264	], [
265		AC_MSG_RESULT([no])
266	])
267])
268
269dnl #
270dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512IFMA
271dnl #
272AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512IFMA], [
273	AC_MSG_CHECKING([whether host toolchain supports AVX512IFMA])
274
275	AC_LINK_IFELSE([AC_LANG_SOURCE([
276	[
277		void main()
278		{
279			__asm__ __volatile__("vpmadd52luq %zmm0,%zmm1,%zmm2");
280		}
281	]])], [
282		AC_MSG_RESULT([yes])
283		AC_DEFINE([HAVE_AVX512IFMA], 1, [Define if host toolchain supports AVX512IFMA])
284	], [
285		AC_MSG_RESULT([no])
286	])
287])
288
289dnl #
290dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512VBMI
291dnl #
292AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512VBMI], [
293	AC_MSG_CHECKING([whether host toolchain supports AVX512VBMI])
294
295	AC_LINK_IFELSE([AC_LANG_SOURCE([
296	[
297		void main()
298		{
299			__asm__ __volatile__("vpermb %zmm0,%zmm1,%zmm2");
300		}
301	]])], [
302		AC_MSG_RESULT([yes])
303		AC_DEFINE([HAVE_AVX512VBMI], 1, [Define if host toolchain supports AVX512VBMI])
304	], [
305		AC_MSG_RESULT([no])
306	])
307])
308
309dnl #
310dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512PF
311dnl #
312AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512PF], [
313	AC_MSG_CHECKING([whether host toolchain supports AVX512PF])
314
315	AC_LINK_IFELSE([AC_LANG_SOURCE([
316	[
317		void main()
318		{
319			__asm__ __volatile__("vgatherpf0dps (%rsi,%zmm0,4){%k1}");
320		}
321	]])], [
322		AC_MSG_RESULT([yes])
323		AC_DEFINE([HAVE_AVX512PF], 1, [Define if host toolchain supports AVX512PF])
324	], [
325		AC_MSG_RESULT([no])
326	])
327])
328
329dnl #
330dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512ER
331dnl #
332AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512ER], [
333	AC_MSG_CHECKING([whether host toolchain supports AVX512ER])
334
335	AC_LINK_IFELSE([AC_LANG_SOURCE([
336	[
337		void main()
338		{
339			__asm__ __volatile__("vexp2pd %zmm0,%zmm1");
340		}
341	]])], [
342		AC_MSG_RESULT([yes])
343		AC_DEFINE([HAVE_AVX512ER], 1, [Define if host toolchain supports AVX512ER])
344	], [
345		AC_MSG_RESULT([no])
346	])
347])
348
349dnl #
350dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512VL
351dnl #
352AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AVX512VL], [
353	AC_MSG_CHECKING([whether host toolchain supports AVX512VL])
354
355	AC_LINK_IFELSE([AC_LANG_SOURCE([
356	[
357		void main()
358		{
359			__asm__ __volatile__("vpabsq %zmm0,%zmm1");
360		}
361	]])], [
362		AC_MSG_RESULT([yes])
363		AC_DEFINE([HAVE_AVX512VL], 1, [Define if host toolchain supports AVX512VL])
364	], [
365		AC_MSG_RESULT([no])
366	])
367])
368
369dnl #
370dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AES
371dnl #
372AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_AES], [
373	AC_MSG_CHECKING([whether host toolchain supports AES])
374
375	AC_LINK_IFELSE([AC_LANG_SOURCE([
376	[
377		void main()
378		{
379			__asm__ __volatile__("aesenc %xmm0, %xmm1");
380		}
381	]])], [
382		AC_MSG_RESULT([yes])
383		AC_DEFINE([HAVE_AES], 1, [Define if host toolchain supports AES])
384	], [
385		AC_MSG_RESULT([no])
386	])
387])
388
389dnl #
390dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_PCLMULQDQ
391dnl #
392AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_PCLMULQDQ], [
393	AC_MSG_CHECKING([whether host toolchain supports PCLMULQDQ])
394
395	AC_LINK_IFELSE([AC_LANG_SOURCE([
396	[
397		void main()
398		{
399			__asm__ __volatile__("pclmulqdq %0, %%xmm0, %%xmm1" :: "i"(0));
400		}
401	]])], [
402		AC_MSG_RESULT([yes])
403		AC_DEFINE([HAVE_PCLMULQDQ], 1, [Define if host toolchain supports PCLMULQDQ])
404	], [
405		AC_MSG_RESULT([no])
406	])
407])
408
409dnl #
410dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_MOVBE
411dnl #
412AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_MOVBE], [
413	AC_MSG_CHECKING([whether host toolchain supports MOVBE])
414
415	AC_LINK_IFELSE([AC_LANG_SOURCE([
416	[
417		void main()
418		{
419			__asm__ __volatile__("movbe 0(%eax), %eax");
420		}
421	]])], [
422		AC_MSG_RESULT([yes])
423		AC_DEFINE([HAVE_MOVBE], 1, [Define if host toolchain supports MOVBE])
424	], [
425		AC_MSG_RESULT([no])
426	])
427])
428
429dnl #
430dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_XSAVE
431dnl #
432AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_XSAVE], [
433	AC_MSG_CHECKING([whether host toolchain supports XSAVE])
434
435	AC_LINK_IFELSE([AC_LANG_SOURCE([
436	[
437		void main()
438		{
439		  char b[4096] __attribute__ ((aligned (64)));
440		  __asm__ __volatile__("xsave %[b]\n" : : [b] "m" (*b) : "memory");
441		}
442	]])], [
443		AC_MSG_RESULT([yes])
444		AC_DEFINE([HAVE_XSAVE], 1, [Define if host toolchain supports XSAVE])
445	], [
446		AC_MSG_RESULT([no])
447	])
448])
449
450dnl #
451dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_XSAVEOPT
452dnl #
453AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_XSAVEOPT], [
454	AC_MSG_CHECKING([whether host toolchain supports XSAVEOPT])
455
456	AC_LINK_IFELSE([AC_LANG_SOURCE([
457	[
458		void main()
459		{
460		  char b[4096] __attribute__ ((aligned (64)));
461		  __asm__ __volatile__("xsaveopt %[b]\n" : : [b] "m" (*b) : "memory");
462		}
463	]])], [
464		AC_MSG_RESULT([yes])
465		AC_DEFINE([HAVE_XSAVEOPT], 1, [Define if host toolchain supports XSAVEOPT])
466	], [
467		AC_MSG_RESULT([no])
468	])
469])
470
471dnl #
472dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_XSAVES
473dnl #
474AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_XSAVES], [
475	AC_MSG_CHECKING([whether host toolchain supports XSAVES])
476
477	AC_LINK_IFELSE([AC_LANG_SOURCE([
478	[
479		void main()
480		{
481		  char b[4096] __attribute__ ((aligned (64)));
482		  __asm__ __volatile__("xsaves %[b]\n" : : [b] "m" (*b) : "memory");
483		}
484	]])], [
485		AC_MSG_RESULT([yes])
486		AC_DEFINE([HAVE_XSAVES], 1, [Define if host toolchain supports XSAVES])
487	], [
488		AC_MSG_RESULT([no])
489	])
490])
491