ax_ext.m4 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. # ===========================================================================
  2. # http://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 an SIMD
  12. # extension is found, the -m"simdextensionname" is added to SIMD_FLAGS if
  13. # compilator supports it. For example, if "sse2" is available, then
  14. # "-msse2" is added to SIMD_FLAGS.
  15. #
  16. # This macro calls:
  17. #
  18. # AC_SUBST(SIMD_FLAGS)
  19. #
  20. # And defines:
  21. #
  22. # HAVE_MMX / HAVE_SSE / HAVE_SSE2 / HAVE_SSE3 / HAVE_SSSE3 / HAVE_SSE4.1 / HAVE_SSE4.2 / HAVE_AVX
  23. #
  24. # LICENSE
  25. #
  26. # Copyright (c) 2007 Christophe Tournayre <[email protected]>
  27. #
  28. # Copying and distribution of this file, with or without modification, are
  29. # permitted in any medium without royalty provided the copyright notice
  30. # and this notice are preserved. This file is offered as-is, without any
  31. # warranty.
  32. #serial 10
  33. AC_DEFUN([AX_EXT],
  34. [
  35. AC_REQUIRE([AC_CANONICAL_HOST])
  36. case $host_cpu in
  37. powerpc*)
  38. AC_CACHE_CHECK([whether altivec is supported], [ax_cv_have_altivec_ext],
  39. [
  40. if test `/usr/sbin/sysctl -a 2>/dev/null| grep -c hw.optional.altivec` != 0; then
  41. if test `/usr/sbin/sysctl -n hw.optional.altivec` = 1; then
  42. ax_cv_have_altivec_ext=yes
  43. fi
  44. fi
  45. ])
  46. if test "$ax_cv_have_altivec_ext" = yes; then
  47. AC_DEFINE(HAVE_ALTIVEC,,[Support Altivec instructions])
  48. AX_CHECK_COMPILE_FLAG(-faltivec, SIMD_FLAGS="$SIMD_FLAGS -faltivec", [])
  49. fi
  50. ;;
  51. i[[3456]]86*|x86_64*)
  52. AC_REQUIRE([AX_GCC_X86_CPUID])
  53. AX_GCC_X86_CPUID(0x00000001)
  54. ecx=`echo $ax_cv_gcc_x86_cpuid_0x00000001 | cut -d ":" -f 3`
  55. edx=`echo $ax_cv_gcc_x86_cpuid_0x00000001 | cut -d ":" -f 4`
  56. AC_CACHE_CHECK([whether mmx is supported], [ax_cv_have_mmx_ext],
  57. [
  58. ax_cv_have_mmx_ext=no
  59. if test "$((0x$edx>>23&0x01))" = 1; then
  60. ax_cv_have_mmx_ext=yes
  61. fi
  62. ])
  63. AC_CACHE_CHECK([whether sse is supported], [ax_cv_have_sse_ext],
  64. [
  65. ax_cv_have_sse_ext=no
  66. if test "$((0x$edx>>25&0x01))" = 1; then
  67. ax_cv_have_sse_ext=yes
  68. fi
  69. ])
  70. AC_CACHE_CHECK([whether sse2 is supported], [ax_cv_have_sse2_ext],
  71. [
  72. ax_cv_have_sse2_ext=no
  73. if test "$((0x$edx>>26&0x01))" = 1; then
  74. ax_cv_have_sse2_ext=yes
  75. fi
  76. ])
  77. AC_CACHE_CHECK([whether sse3 is supported], [ax_cv_have_sse3_ext],
  78. [
  79. ax_cv_have_sse3_ext=no
  80. if test "$((0x$ecx&0x01))" = 1; then
  81. ax_cv_have_sse3_ext=yes
  82. fi
  83. ])
  84. AC_CACHE_CHECK([whether ssse3 is supported], [ax_cv_have_ssse3_ext],
  85. [
  86. ax_cv_have_ssse3_ext=no
  87. if test "$((0x$ecx>>9&0x01))" = 1; then
  88. ax_cv_have_ssse3_ext=yes
  89. fi
  90. ])
  91. AC_CACHE_CHECK([whether sse4.1 is supported], [ax_cv_have_sse41_ext],
  92. [
  93. ax_cv_have_sse41_ext=no
  94. if test "$((0x$ecx>>19&0x01))" = 1; then
  95. ax_cv_have_sse41_ext=yes
  96. fi
  97. ])
  98. AC_CACHE_CHECK([whether sse4.2 is supported], [ax_cv_have_sse42_ext],
  99. [
  100. ax_cv_have_sse42_ext=no
  101. if test "$((0x$ecx>>20&0x01))" = 1; then
  102. ax_cv_have_sse42_ext=yes
  103. fi
  104. ])
  105. AC_CACHE_CHECK([whether avx is supported], [ax_cv_have_avx_ext],
  106. [
  107. ax_cv_have_avx_ext=no
  108. if test "$((0x$ecx>>28&0x01))" = 1; then
  109. ax_cv_have_avx_ext=yes
  110. fi
  111. ])
  112. if test "$ax_cv_have_mmx_ext" = yes; then
  113. AX_CHECK_COMPILE_FLAG(-mmmx, ax_cv_support_mmx_ext=yes, [])
  114. if test x"$ax_cv_support_mmx_ext" = x"yes"; then
  115. SIMD_FLAGS="$SIMD_FLAGS -mmmx"
  116. AC_DEFINE(HAVE_MMX,,[Support mmx instructions])
  117. else
  118. AC_MSG_WARN([Your processor supports mmx instructions but not your compiler, can you try another compiler?])
  119. fi
  120. fi
  121. if test "$ax_cv_have_sse_ext" = yes; then
  122. AX_CHECK_COMPILE_FLAG(-msse, ax_cv_support_sse_ext=yes, [])
  123. if test x"$ax_cv_support_sse_ext" = x"yes"; then
  124. SIMD_FLAGS="$SIMD_FLAGS -msse"
  125. AC_DEFINE(HAVE_SSE,,[Support SSE (Streaming SIMD Extensions) instructions])
  126. else
  127. AC_MSG_WARN([Your processor supports sse instructions but not your compiler, can you try another compiler?])
  128. fi
  129. fi
  130. if test "$ax_cv_have_sse2_ext" = yes; then
  131. AX_CHECK_COMPILE_FLAG(-msse2, ax_cv_support_sse2_ext=yes, [])
  132. if test x"$ax_cv_support_sse2_ext" = x"yes"; then
  133. SIMD_FLAGS="$SIMD_FLAGS -msse2"
  134. AC_DEFINE(HAVE_SSE2,,[Support SSE2 (Streaming SIMD Extensions 2) instructions])
  135. else
  136. AC_MSG_WARN([Your processor supports sse2 instructions but not your compiler, can you try another compiler?])
  137. fi
  138. fi
  139. if test "$ax_cv_have_sse3_ext" = yes; then
  140. AX_CHECK_COMPILE_FLAG(-msse3, ax_cv_support_sse3_ext=yes, [])
  141. if test x"$ax_cv_support_sse3_ext" = x"yes"; then
  142. SIMD_FLAGS="$SIMD_FLAGS -msse3"
  143. AC_DEFINE(HAVE_SSE3,,[Support SSE3 (Streaming SIMD Extensions 3) instructions])
  144. else
  145. AC_MSG_WARN([Your processor supports sse3 instructions but not your compiler, can you try another compiler?])
  146. fi
  147. fi
  148. if test "$ax_cv_have_ssse3_ext" = yes; then
  149. AX_CHECK_COMPILE_FLAG(-mssse3, ax_cv_support_ssse3_ext=yes, [])
  150. if test x"$ax_cv_support_ssse3_ext" = x"yes"; then
  151. SIMD_FLAGS="$SIMD_FLAGS -mssse3"
  152. AC_DEFINE(HAVE_SSSE3,,[Support SSSE3 (Supplemental Streaming SIMD Extensions 3) instructions])
  153. else
  154. AC_MSG_WARN([Your processor supports ssse3 instructions but not your compiler, can you try another compiler?])
  155. fi
  156. fi
  157. if test "$ax_cv_have_sse41_ext" = yes; then
  158. AX_CHECK_COMPILE_FLAG(-msse4.1, ax_cv_support_sse41_ext=yes, [])
  159. if test x"$ax_cv_support_sse41_ext" = x"yes"; then
  160. SIMD_FLAGS="$SIMD_FLAGS -msse4.1"
  161. AC_DEFINE(HAVE_SSE4_1,,[Support SSSE4.1 (Streaming SIMD Extensions 4.1) instructions])
  162. else
  163. AC_MSG_WARN([Your processor supports sse4.1 instructions but not your compiler, can you try another compiler?])
  164. fi
  165. fi
  166. if test "$ax_cv_have_sse42_ext" = yes; then
  167. AX_CHECK_COMPILE_FLAG(-msse4.2, ax_cv_support_sse42_ext=yes, [])
  168. if test x"$ax_cv_support_sse42_ext" = x"yes"; then
  169. SIMD_FLAGS="$SIMD_FLAGS -msse4.2"
  170. AC_DEFINE(HAVE_SSE4_2,,[Support SSSE4.2 (Streaming SIMD Extensions 4.2) instructions])
  171. else
  172. AC_MSG_WARN([Your processor supports sse4.2 instructions but not your compiler, can you try another compiler?])
  173. fi
  174. fi
  175. if test "$ax_cv_have_avx_ext" = yes; then
  176. AX_CHECK_COMPILE_FLAG(-mavx, ax_cv_support_avx_ext=yes, [])
  177. if test x"$ax_cv_support_avx_ext" = x"yes"; then
  178. SIMD_FLAGS="$SIMD_FLAGS -mavx"
  179. AC_DEFINE(HAVE_AVX,,[Support AVX (Advanced Vector Extensions) instructions])
  180. else
  181. AC_MSG_WARN([Your processor supports avx instructions but not your compiler, can you try another compiler?])
  182. fi
  183. fi
  184. ;;
  185. esac
  186. AC_SUBST(SIMD_FLAGS)
  187. ])