Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

329 lines
15KB

  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_ext.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_EXT
  8. #
  9. # DESCRIPTION
  10. #
  11. # Find supported SIMD extensions by requesting cpuid. When a SIMD
  12. # extension is found, the -m"simdextensionname" is added to SIMD_FLAGS if
  13. # compiler supports it. For example, if "sse2" is available then "-msse2"
  14. # is added to SIMD_FLAGS.
  15. #
  16. # Find other supported CPU extensions by requesting cpuid. When a
  17. # processor extension is found, the -m"extensionname" is added to
  18. # CPUEXT_FLAGS if compiler supports it. For example, if "bmi2" is
  19. # available then "-mbmi2" is added to CPUEXT_FLAGS.
  20. #
  21. # This macro calls:
  22. #
  23. # AC_SUBST(SIMD_FLAGS)
  24. # AC_SUBST(CPUEXT_FLAGS)
  25. #
  26. # And defines:
  27. #
  28. # HAVE_RDRND / HAVE_BMI1 / HAVE_BMI2 / HAVE_ADX / HAVE_MPX
  29. # HAVE_PREFETCHWT1 / HAVE_ABM / HAVE_MMX / HAVE_SSE / HAVE_SSE2
  30. # HAVE_SSE3 / HAVE_SSSE3 / HAVE_SSE4_1 / HAVE_SSE4_2 / HAVE_SSE4a
  31. # HAVE_SHA / HAVE_AES / HAVE_AVX / HAVE_FMA3 / HAVE_FMA4 / HAVE_XOP
  32. # HAVE_AVX2 / HAVE_AVX512_F / HAVE_AVX512_CD / HAVE_AVX512_PF
  33. # HAVE_AVX512_ER / HAVE_AVX512_VL / HAVE_AVX512_BW / HAVE_AVX512_DQ
  34. # HAVE_AVX512_IFMA / HAVE_AVX512_VBMI / HAVE_ALTIVEC / HAVE_VSX
  35. #
  36. # LICENSE
  37. #
  38. # Copyright (c) 2007 Christophe Tournayre <turn3r@users.sourceforge.net>
  39. # Copyright (c) 2013,2015 Michael Petch <mpetch@capp-sysware.com>
  40. # Copyright (c) 2017 Rafael de Lucena Valle <rafaeldelucena@gmail.com>
  41. #
  42. # Copying and distribution of this file, with or without modification, are
  43. # permitted in any medium without royalty provided the copyright notice
  44. # and this notice are preserved. This file is offered as-is, without any
  45. # warranty.
  46. #serial 17
  47. AC_DEFUN([AX_EXT],
  48. [
  49. AC_REQUIRE([AC_CANONICAL_HOST])
  50. AC_REQUIRE([AC_PROG_CC])
  51. CPUEXT_FLAGS=""
  52. SIMD_FLAGS=""
  53. case $host_cpu in
  54. powerpc*)
  55. AC_CACHE_CHECK([whether altivec is supported for old distros], [ax_cv_have_altivec_old_ext],
  56. [
  57. if test `/usr/sbin/sysctl -a 2>/dev/null| grep -c hw.optional.altivec` != 0; then
  58. if test `/usr/sbin/sysctl -n hw.optional.altivec` = 1; then
  59. ax_cv_have_altivec_old_ext=yes
  60. fi
  61. fi
  62. ])
  63. if test "$ax_cv_have_altivec_old_ext" = yes; then
  64. AC_DEFINE(HAVE_ALTIVEC,,[Support Altivec instructions])
  65. AX_CHECK_COMPILE_FLAG(-faltivec, SIMD_FLAGS="$SIMD_FLAGS -faltivec", [])
  66. fi
  67. AC_CACHE_CHECK([whether altivec is supported], [ax_cv_have_altivec_ext],
  68. [
  69. if test `LD_SHOW_AUXV=1 /bin/true 2>/dev/null|grep -c altivec` != 0; then
  70. ax_cv_have_altivec_ext=yes
  71. fi
  72. ])
  73. if test "$ax_cv_have_altivec_ext" = yes; then
  74. AC_DEFINE(HAVE_ALTIVEC,,[Support Altivec instructions])
  75. AX_CHECK_COMPILE_FLAG(-maltivec, SIMD_FLAGS="$SIMD_FLAGS -maltivec", [])
  76. fi
  77. AC_CACHE_CHECK([whether vsx is supported], [ax_cv_have_vsx_ext],
  78. [
  79. if test `LD_SHOW_AUXV=1 /bin/true 2>/dev/null|grep -c vsx` != 0; then
  80. ax_cv_have_vsx_ext=yes
  81. fi
  82. ])
  83. if test "$ax_cv_have_vsx_ext" = yes; then
  84. AC_DEFINE(HAVE_VSX,,[Support VSX instructions])
  85. AX_CHECK_COMPILE_FLAG(-mvsx, SIMD_FLAGS="$SIMD_FLAGS -mvsx", [])
  86. fi
  87. ;;
  88. i[[3456]]86*|x86_64*|amd64*)
  89. AC_REQUIRE([AX_GCC_X86_CPUID])
  90. AC_REQUIRE([AX_GCC_X86_CPUID_COUNT])
  91. AC_REQUIRE([AX_GCC_X86_AVX_XGETBV])
  92. eax_cpuid0=0
  93. AX_GCC_X86_CPUID(0x00000000)
  94. if test "$ax_cv_gcc_x86_cpuid_0x00000000" != "unknown";
  95. then
  96. eax_cpuid0=`echo $ax_cv_gcc_x86_cpuid_0x00000000 | cut -d ":" -f 1`
  97. fi
  98. eax_cpuid80000000=0
  99. AX_GCC_X86_CPUID(0x80000000)
  100. if test "$ax_cv_gcc_x86_cpuid_0x80000000" != "unknown";
  101. then
  102. eax_cpuid80000000=`echo $ax_cv_gcc_x86_cpuid_0x80000000 | cut -d ":" -f 1`
  103. fi
  104. ecx_cpuid1=0
  105. edx_cpuid1=0
  106. if test "$((0x$eax_cpuid0))" -ge 1 ; then
  107. AX_GCC_X86_CPUID(0x00000001)
  108. if test "$ax_cv_gcc_x86_cpuid_0x00000001" != "unknown";
  109. then
  110. ecx_cpuid1=`echo $ax_cv_gcc_x86_cpuid_0x00000001 | cut -d ":" -f 3`
  111. edx_cpuid1=`echo $ax_cv_gcc_x86_cpuid_0x00000001 | cut -d ":" -f 4`
  112. fi
  113. fi
  114. ebx_cpuid7=0
  115. ecx_cpuid7=0
  116. if test "$((0x$eax_cpuid0))" -ge 7 ; then
  117. AX_GCC_X86_CPUID_COUNT(0x00000007, 0x00)
  118. if test "$ax_cv_gcc_x86_cpuid_0x00000007" != "unknown";
  119. then
  120. ebx_cpuid7=`echo $ax_cv_gcc_x86_cpuid_0x00000007 | cut -d ":" -f 2`
  121. ecx_cpuid7=`echo $ax_cv_gcc_x86_cpuid_0x00000007 | cut -d ":" -f 3`
  122. fi
  123. fi
  124. ecx_cpuid80000001=0
  125. edx_cpuid80000001=0
  126. if test "$((0x$eax_cpuid80000000))" -ge "$((0x80000001))" ; then
  127. AX_GCC_X86_CPUID(0x80000001)
  128. if test "$ax_cv_gcc_x86_cpuid_0x80000001" != "unknown";
  129. then
  130. ecx_cpuid80000001=`echo $ax_cv_gcc_x86_cpuid_0x80000001 | cut -d ":" -f 3`
  131. edx_cpuid80000001=`echo $ax_cv_gcc_x86_cpuid_0x80000001 | cut -d ":" -f 4`
  132. fi
  133. fi
  134. AC_CACHE_VAL([ax_cv_have_mmx_os_support_ext],
  135. [
  136. ax_cv_have_mmx_os_support_ext=yes
  137. ])
  138. ax_cv_have_none_os_support_ext=yes
  139. AC_CACHE_VAL([ax_cv_have_sse_os_support_ext],
  140. [
  141. ax_cv_have_sse_os_support_ext=no,
  142. if test "$((0x$edx_cpuid1>>25&0x01))" = 1; then
  143. AC_LANG_PUSH([C])
  144. AC_TRY_RUN([
  145. #include <signal.h>
  146. #include <stdlib.h>
  147. /* No way at ring1 to ring3 in protected mode to check the CR0 and CR4
  148. control registers directly. Execute an SSE instruction.
  149. If it raises SIGILL then OS doesn't support SSE based instructions */
  150. void sig_handler(int signum){ exit(1); }
  151. int main(){
  152. signal(SIGILL, sig_handler);
  153. /* SSE instruction xorps %xmm0,%xmm0 */
  154. __asm__ __volatile__ (".byte 0x0f, 0x57, 0xc0");
  155. return 0;
  156. }],
  157. ax_cv_have_sse_os_support_ext=yes,
  158. ax_cv_have_sse_os_support_ext=no,
  159. ax_cv_have_sse_os_support_ext=no)
  160. AC_LANG_POP([C])
  161. fi
  162. ])
  163. xgetbv_eax=0
  164. if test "$((0x$ecx_cpuid1>>28&0x01))" = 1; then
  165. AX_GCC_X86_AVX_XGETBV(0x00000000)
  166. if test x"$ax_cv_gcc_x86_avx_xgetbv_0x00000000" != x"unknown"; then
  167. xgetbv_eax=`echo $ax_cv_gcc_x86_avx_xgetbv_0x00000000 | cut -d ":" -f 1`
  168. fi
  169. AC_CACHE_VAL([ax_cv_have_avx_os_support_ext],
  170. [
  171. ax_cv_have_avx_os_support_ext=no
  172. if test "$((0x$ecx_cpuid1>>27&0x01))" = 1; then
  173. if test "$((0x$xgetbv_eax&0x6))" = 6; then
  174. ax_cv_have_avx_os_support_ext=yes
  175. fi
  176. fi
  177. ])
  178. fi
  179. AC_CACHE_VAL([ax_cv_have_avx512_os_support_ext],
  180. [
  181. ax_cv_have_avx512_os_support_ext=no
  182. if test "$ax_cv_have_avx_os_support_ext" = yes; then
  183. if test "$((0x$xgetbv_eax&0xe6))" = "$((0xe6))"; then
  184. ax_cv_have_avx512_os_support_ext=yes
  185. fi
  186. fi
  187. ])
  188. for ac_instr_info dnl
  189. in "none;rdrnd;RDRND;ecx_cpuid1,30;-mrdrnd;HAVE_RDRND;CPUEXT_FLAGS" dnl
  190. "none;bmi1;BMI1;ebx_cpuid7,3;-mbmi;HAVE_BMI1;CPUEXT_FLAGS" dnl
  191. "none;bmi2;BMI2;ebx_cpuid7,8;-mbmi2;HAVE_BMI2;CPUEXT_FLAGS" dnl
  192. "none;adx;ADX;ebx_cpuid7,19;-madx;HAVE_ADX;CPUEXT_FLAGS" dnl
  193. "none;mpx;MPX;ebx_cpuid7,14;-mmpx;HAVE_MPX;CPUEXT_FLAGS" dnl
  194. "none;prefetchwt1;PREFETCHWT1;ecx_cpuid7,0;-mprefetchwt1;HAVE_PREFETCHWT1;CPUEXT_FLAGS" dnl
  195. "none;abm;ABM;ecx_cpuid80000001,5;-mabm;HAVE_ABM;CPUEXT_FLAGS" dnl
  196. "mmx;mmx;MMX;edx_cpuid1,23;-mmmx;HAVE_MMX;SIMD_FLAGS" dnl
  197. "sse;sse;SSE;edx_cpuid1,25;-msse;HAVE_SSE;SIMD_FLAGS" dnl
  198. "sse;sse2;SSE2;edx_cpuid1,26;-msse2;HAVE_SSE2;SIMD_FLAGS" dnl
  199. "sse;sse3;SSE3;ecx_cpuid1,1;-msse3;HAVE_SSE3;SIMD_FLAGS" dnl
  200. "sse;ssse3;SSSE3;ecx_cpuid1,9;-mssse3;HAVE_SSSE3;SIMD_FLAGS" dnl
  201. "sse;sse41;SSE4.1;ecx_cpuid1,19;-msse4.1;HAVE_SSE4_1;SIMD_FLAGS" dnl
  202. "sse;sse42;SSE4.2;ecx_cpuid1,20;-msse4.2;HAVE_SSE4_2;SIMD_FLAGS" dnl
  203. "sse;sse4a;SSE4a;ecx_cpuid80000001,6;-msse4a;HAVE_SSE4a;SIMD_FLAGS" dnl
  204. "sse;sha;SHA;ebx_cpuid7,29;-msha;HAVE_SHA;SIMD_FLAGS" dnl
  205. "sse;aes;AES;ecx_cpuid1,25;-maes;HAVE_AES;SIMD_FLAGS" dnl
  206. "avx;avx;AVX;ecx_cpuid1,28;-mavx;HAVE_AVX;SIMD_FLAGS" dnl
  207. "avx;fma3;FMA3;ecx_cpuid1,12;-mfma;HAVE_FMA3;SIMD_FLAGS" dnl
  208. "avx;fma4;FMA4;ecx_cpuid80000001,16;-mfma4;HAVE_FMA4;SIMD_FLAGS" dnl
  209. "avx;xop;XOP;ecx_cpuid80000001,11;-mxop;HAVE_XOP;SIMD_FLAGS" dnl
  210. "avx;avx2;AVX2;ebx_cpuid7,5;-mavx2;HAVE_AVX2;SIMD_FLAGS" dnl
  211. "avx512;avx512f;AVX512-F;ebx_cpuid7,16;-mavx512f;HAVE_AVX512_F;SIMD_FLAGS" dnl
  212. "avx512;avx512cd;AVX512-CD;ebx_cpuid7,28;-mavx512cd;HAVE_AVX512_CD;SIMD_FLAGS" dnl
  213. "avx512;avx512pf;AVX512-PF;ebx_cpuid7,26;-mavx512pf;HAVE_AVX512_PF;SIMD_FLAGS" dnl
  214. "avx512;avx512er;AVX512-ER;ebx_cpuid7,27;-mavx512er;HAVE_AVX512_ER;SIMD_FLAGS" dnl
  215. "avx512;avx512vl;AVX512-VL;ebx_cpuid7,31;-mavx512vl;HAVE_AVX512_VL;SIMD_FLAGS" dnl
  216. "avx512;avx512bw;AVX512-BW;ebx_cpuid7,30;-mavx512bw;HAVE_AVX512_BW;SIMD_FLAGS" dnl
  217. "avx512;avx512dq;AVX512-DQ;ebx_cpuid7,17;-mavx512dq;HAVE_AVX512_DQ;SIMD_FLAGS" dnl
  218. "avx512;avx512ifma;AVX512-IFMA;ebx_cpuid7,21;-mavx512ifma;HAVE_AVX512_IFMA;SIMD_FLAGS" dnl
  219. "avx512;avx512vbmi;AVX512-VBMI;ecx_cpuid7,1;-mavx512vbmi;HAVE_AVX512_VBMI;SIMD_FLAGS" dnl
  220. #
  221. do ac_instr_os_support=$(eval echo \$ax_cv_have_$(echo $ac_instr_info | cut -d ";" -f 1)_os_support_ext)
  222. ac_instr_acvar=$(echo $ac_instr_info | cut -d ";" -f 2)
  223. ac_instr_shortname=$(echo $ac_instr_info | cut -d ";" -f 3)
  224. ac_instr_chk_loc=$(echo $ac_instr_info | cut -d ";" -f 4)
  225. ac_instr_chk_reg=0x$(eval echo \$$(echo $ac_instr_chk_loc | cut -d "," -f 1))
  226. ac_instr_chk_bit=$(echo $ac_instr_chk_loc | cut -d "," -f 2)
  227. ac_instr_compiler_flags=$(echo $ac_instr_info | cut -d ";" -f 5)
  228. ac_instr_have_define=$(echo $ac_instr_info | cut -d ";" -f 6)
  229. ac_instr_flag_type=$(echo $ac_instr_info | cut -d ";" -f 7)
  230. AC_CACHE_CHECK([whether ${ac_instr_shortname} is supported by the processor], [ax_cv_have_${ac_instr_acvar}_cpu_ext],
  231. [
  232. eval ax_cv_have_${ac_instr_acvar}_cpu_ext=no
  233. if test "$((${ac_instr_chk_reg}>>${ac_instr_chk_bit}&0x01))" = 1 ; then
  234. eval ax_cv_have_${ac_instr_acvar}_cpu_ext=yes
  235. fi
  236. ])
  237. if test x"$(eval echo \$ax_cv_have_${ac_instr_acvar}_cpu_ext)" = x"yes"; then
  238. AC_CACHE_CHECK([whether ${ac_instr_shortname} is supported by the processor and OS], [ax_cv_have_${ac_instr_acvar}_ext],
  239. [
  240. eval ax_cv_have_${ac_instr_acvar}_ext=no
  241. if test x"${ac_instr_os_support}" = x"yes"; then
  242. eval ax_cv_have_${ac_instr_acvar}_ext=yes
  243. fi
  244. ])
  245. if test "$(eval echo \$ax_cv_have_${ac_instr_acvar}_ext)" = yes; then
  246. AX_CHECK_COMPILE_FLAG(${ac_instr_compiler_flags}, eval ax_cv_support_${ac_instr_acvar}_ext=yes,
  247. eval ax_cv_support_${ac_instr_acvar}_ext=no)
  248. if test x"$(eval echo \$ax_cv_support_${ac_instr_acvar}_ext)" = x"yes"; then
  249. eval ${ac_instr_flag_type}=\"\$${ac_instr_flag_type} ${ac_instr_compiler_flags}\"
  250. AC_DEFINE_UNQUOTED([${ac_instr_have_define}])
  251. else
  252. AC_MSG_WARN([Your processor and OS supports ${ac_instr_shortname} instructions but not your compiler, can you try another compiler?])
  253. fi
  254. else
  255. if test x"${ac_instr_os_support}" = x"no"; then
  256. AC_CACHE_VAL(ax_cv_support_${ac_instr_acvar}_ext, eval ax_cv_support_${ac_instr_acvar}_ext=no)
  257. AC_MSG_WARN([Your processor supports ${ac_instr_shortname}, but your OS doesn't])
  258. fi
  259. fi
  260. else
  261. AC_CACHE_VAL(ax_cv_have_${ac_instr_acvar}_ext, eval ax_cv_have_${ac_instr_acvar}_ext=no)
  262. AC_CACHE_VAL(ax_cv_support_${ac_instr_acvar}_ext, eval ax_cv_support_${ac_instr_acvar}_ext=no)
  263. fi
  264. done
  265. ;;
  266. esac
  267. AH_TEMPLATE([HAVE_RDRND],[Define to 1 to support Digital Random Number Generator])
  268. AH_TEMPLATE([HAVE_BMI1],[Define to 1 to support Bit Manipulation Instruction Set 1])
  269. AH_TEMPLATE([HAVE_BMI2],[Define to 1 to support Bit Manipulation Instruction Set 2])
  270. AH_TEMPLATE([HAVE_ADX],[Define to 1 to support Multi-Precision Add-Carry Instruction Extensions])
  271. AH_TEMPLATE([HAVE_MPX],[Define to 1 to support Memory Protection Extensions])
  272. AH_TEMPLATE([HAVE_PREFETCHWT1],[Define to 1 to support Prefetch Vector Data Into Caches WT1])
  273. AH_TEMPLATE([HAVE_ABM],[Define to 1 to support Advanced Bit Manipulation])
  274. AH_TEMPLATE([HAVE_MMX],[Define to 1 to support Multimedia Extensions])
  275. AH_TEMPLATE([HAVE_SSE],[Define to 1 to support Streaming SIMD Extensions])
  276. AH_TEMPLATE([HAVE_SSE2],[Define to 1 to support Streaming SIMD Extensions])
  277. AH_TEMPLATE([HAVE_SSE3],[Define to 1 to support Streaming SIMD Extensions 3])
  278. AH_TEMPLATE([HAVE_SSSE3],[Define to 1 to support Supplemental Streaming SIMD Extensions 3])
  279. AH_TEMPLATE([HAVE_SSE4_1],[Define to 1 to support Streaming SIMD Extensions 4.1])
  280. AH_TEMPLATE([HAVE_SSE4_2],[Define to 1 to support Streaming SIMD Extensions 4.2])
  281. AH_TEMPLATE([HAVE_SSE4a],[Define to 1 to support AMD Streaming SIMD Extensions 4a])
  282. AH_TEMPLATE([HAVE_SHA],[Define to 1 to support Secure Hash Algorithm Extension])
  283. AH_TEMPLATE([HAVE_AES],[Define to 1 to support Advanced Encryption Standard New Instruction Set (AES-NI)])
  284. AH_TEMPLATE([HAVE_AVX],[Define to 1 to support Advanced Vector Extensions])
  285. AH_TEMPLATE([HAVE_FMA3],[Define to 1 to support Fused Multiply-Add Extensions 3])
  286. AH_TEMPLATE([HAVE_FMA4],[Define to 1 to support Fused Multiply-Add Extensions 4])
  287. AH_TEMPLATE([HAVE_XOP],[Define to 1 to support eXtended Operations Extensions])
  288. AH_TEMPLATE([HAVE_AVX2],[Define to 1 to support Advanced Vector Extensions 2])
  289. AH_TEMPLATE([HAVE_AVX512_F],[Define to 1 to support AVX-512 Foundation Extensions])
  290. AH_TEMPLATE([HAVE_AVX512_CD],[Define to 1 to support AVX-512 Conflict Detection Instructions])
  291. AH_TEMPLATE([HAVE_AVX512_PF],[Define to 1 to support AVX-512 Conflict Prefetch Instructions])
  292. AH_TEMPLATE([HAVE_AVX512_ER],[Define to 1 to support AVX-512 Exponential & Reciprocal Instructions])
  293. AH_TEMPLATE([HAVE_AVX512_VL],[Define to 1 to support AVX-512 Vector Length Extensions])
  294. AH_TEMPLATE([HAVE_AVX512_BW],[Define to 1 to support AVX-512 Byte and Word Instructions])
  295. AH_TEMPLATE([HAVE_AVX512_DQ],[Define to 1 to support AVX-512 Doubleword and Quadword Instructions])
  296. AH_TEMPLATE([HAVE_AVX512_IFMA],[Define to 1 to support AVX-512 Integer Fused Multiply Add Instructions])
  297. AH_TEMPLATE([HAVE_AVX512_VBMI],[Define to 1 to support AVX-512 Vector Byte Manipulation Instructions])
  298. AC_SUBST(SIMD_FLAGS)
  299. AC_SUBST(CPUEXT_FLAGS)
  300. ])