2
0

ac_gcc_archflag.m4 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. AC_DEFUN([AX_GCC_ARCHFLAG],
  2. [AC_REQUIRE([AC_PROG_CC])
  3. AC_ARG_WITH(gcc-arch, [AC_HELP_STRING([--with-gcc-arch=<arch>], [use architecture <arch> for gcc -march/-mtune, instead of guessing])],
  4. ax_gcc_arch=$withval, ax_gcc_arch=yes)
  5. AC_MSG_CHECKING([for gcc architecture flag])
  6. AC_MSG_RESULT([])
  7. AC_CACHE_VAL(ax_cv_gcc_archflag,
  8. [
  9. ax_cv_gcc_archflag="unknown"
  10. if test "$GCC" = yes; then
  11. if test "x$ax_gcc_arch" = xyes; then
  12. ax_gcc_arch=""
  13. if test "$cross_compiling" = no; then
  14. case $host_cpu in
  15. i[[3456]]86*|x86_64*) # use cpuid codes, in part from x86info-1.7 by D. Jones
  16. AX_GCC_X86_CPUID(0)
  17. AX_GCC_X86_CPUID(1)
  18. case $ax_cv_gcc_x86_cpuid_0 in
  19. *:756e6547:*:*) # Intel
  20. case $ax_cv_gcc_x86_cpuid_1 in
  21. *5[[48]]?:*:*:*) ax_gcc_arch="pentium-mmx pentium" ;;
  22. *5??:*:*:*) ax_gcc_arch=pentium ;;
  23. *6[[3456]]?:*:*:*) ax_gcc_arch="pentium2 pentiumpro" ;;
  24. *6a?:*[[01]]:*:*) ax_gcc_arch="pentium2 pentiumpro" ;;
  25. *6a?:*[[234]]:*:*) ax_gcc_arch="pentium3 pentiumpro" ;;
  26. *6[[9d]]?:*:*:*) ax_gcc_arch="pentium-m pentium3 pentiumpro" ;;
  27. *6[[78b]]?:*:*:*) ax_gcc_arch="pentium3 pentiumpro" ;;
  28. *6??:*:*:*) ax_gcc_arch=pentiumpro ;;
  29. *f3[[347]]:*:*:*|*f4[1347]:*:*:*)
  30. case $host_cpu in
  31. x86_64*) ax_gcc_arch="nocona pentium4 pentiumpro" ;;
  32. *) ax_gcc_arch="prescott pentium4 pentiumpro" ;;
  33. esac ;;
  34. *f??:*:*:*) ax_gcc_arch="pentium4 pentiumpro";;
  35. esac ;;
  36. *:68747541:*:*) # AMD
  37. case $ax_cv_gcc_x86_cpuid_1 in
  38. *5[[67]]?:*:*:*) ax_gcc_arch=k6 ;;
  39. *5[[8d]]?:*:*:*) ax_gcc_arch="k6-2 k6" ;;
  40. *5[[9]]?:*:*:*) ax_gcc_arch="k6-3 k6" ;;
  41. *60?:*:*:*) ax_gcc_arch=k7 ;;
  42. *6[[12]]?:*:*:*) ax_gcc_arch="athlon k7" ;;
  43. *6[[34]]?:*:*:*) ax_gcc_arch="athlon-tbird k7" ;;
  44. *67?:*:*:*) ax_gcc_arch="athlon-4 athlon k7" ;;
  45. *6[[68a]]?:*:*:*)
  46. AX_GCC_X86_CPUID(0x80000006) # L2 cache size
  47. case $ax_cv_gcc_x86_cpuid_0x80000006 in
  48. *:*:*[[1-9a-f]]??????:*) # (L2 = ecx >> 16) >= 256
  49. ax_gcc_arch="athlon-xp athlon-4 athlon k7" ;;
  50. *) ax_gcc_arch="athlon-4 athlon k7" ;;
  51. esac ;;
  52. *f[[4cef8b]]?:*:*:*) ax_gcc_arch="athlon64 k8" ;;
  53. *f5?:*:*:*) ax_gcc_arch="opteron k8" ;;
  54. *f7?:*:*:*) ax_gcc_arch="athlon-fx opteron k8" ;;
  55. *f??:*:*:*) ax_gcc_arch="k8" ;;
  56. esac ;;
  57. *:746e6543:*:*) # IDT
  58. case $ax_cv_gcc_x86_cpuid_1 in
  59. *54?:*:*:*) ax_gcc_arch=winchip-c6 ;;
  60. *58?:*:*:*) ax_gcc_arch=winchip2 ;;
  61. *6[[78]]?:*:*:*) ax_gcc_arch=c3 ;;
  62. *69?:*:*:*) ax_gcc_arch="c3-2 c3" ;;
  63. esac ;;
  64. esac
  65. if test x"$ax_gcc_arch" = x; then # fallback
  66. case $host_cpu in
  67. i586*) ax_gcc_arch=pentium ;;
  68. i686*) ax_gcc_arch=pentiumpro ;;
  69. esac
  70. fi
  71. ;;
  72. sparc*)
  73. AC_PATH_PROG([PRTDIAG], [prtdiag], [prtdiag], [$PATH:/usr/platform/`uname -i`/sbin/:/usr/platform/`uname -m`/sbin/])
  74. cputype=`(((grep cpu /proc/cpuinfo | cut -d: -f2) ; ($PRTDIAG -v |grep -i sparc) ; grep -i cpu /var/run/dmesg.boot ) | head -n 1) 2> /dev/null`
  75. cputype=`echo "$cputype" | tr -d ' -' |tr $as_cr_LETTERS $as_cr_letters`
  76. case $cputype in
  77. *ultrasparciv*) ax_gcc_arch="ultrasparc4 ultrasparc3 ultrasparc v9" ;;
  78. *ultrasparciii*) ax_gcc_arch="ultrasparc3 ultrasparc v9" ;;
  79. *ultrasparc*) ax_gcc_arch="ultrasparc v9" ;;
  80. *supersparc*|*tms390z5[[05]]*) ax_gcc_arch="supersparc v8" ;;
  81. *hypersparc*|*rt62[[056]]*) ax_gcc_arch="hypersparc v8" ;;
  82. *cypress*) ax_gcc_arch=cypress ;;
  83. esac ;;
  84. alphaev5) ax_gcc_arch=ev5 ;;
  85. alphaev56) ax_gcc_arch=ev56 ;;
  86. alphapca56) ax_gcc_arch="pca56 ev56" ;;
  87. alphapca57) ax_gcc_arch="pca57 pca56 ev56" ;;
  88. alphaev6) ax_gcc_arch=ev6 ;;
  89. alphaev67) ax_gcc_arch=ev67 ;;
  90. alphaev68) ax_gcc_arch="ev68 ev67" ;;
  91. alphaev69) ax_gcc_arch="ev69 ev68 ev67" ;;
  92. alphaev7) ax_gcc_arch="ev7 ev69 ev68 ev67" ;;
  93. alphaev79) ax_gcc_arch="ev79 ev7 ev69 ev68 ev67" ;;
  94. powerpc*)
  95. cputype=`((grep cpu /proc/cpuinfo | head -n 1 | cut -d: -f2 | cut -d, -f1 | sed 's/ //g') ; /usr/bin/machine ; /bin/machine; grep CPU /var/run/dmesg.boot | head -n 1 | cut -d" " -f2) 2> /dev/null`
  96. cputype=`echo $cputype | sed -e 's/ppc//g;s/ *//g'`
  97. case $cputype in
  98. *750*) ax_gcc_arch="750 G3" ;;
  99. *740[[0-9]]*) ax_gcc_arch="$cputype 7400 G4" ;;
  100. *74[[4-5]][[0-9]]*) ax_gcc_arch="$cputype 7450 G4" ;;
  101. *74[[0-9]][[0-9]]*) ax_gcc_arch="$cputype G4" ;;
  102. *970*) ax_gcc_arch="970 G5 power4";;
  103. *POWER4*|*power4*|*gq*) ax_gcc_arch="power4 970";;
  104. *POWER5*|*power5*|*gr*|*gs*) ax_gcc_arch="power5 power4 970";;
  105. 603ev|8240) ax_gcc_arch="$cputype 603e 603";;
  106. *) ax_gcc_arch=$cputype ;;
  107. esac
  108. ax_gcc_arch="$ax_gcc_arch powerpc"
  109. ;;
  110. esac
  111. fi # not cross-compiling
  112. fi # guess arch
  113. if test "x$ax_gcc_arch" != x -a "x$ax_gcc_arch" != xno; then
  114. for arch in $ax_gcc_arch; do
  115. if test "x[]m4_default([$1],yes)" = xyes; then # if we require portable code
  116. flags="-mtune=$arch"
  117. # -mcpu=$arch and m$arch generate nonportable code on every arch except
  118. # x86. And some other arches (e.g. Alpha) don't accept -mtune. Grrr.
  119. case $host_cpu in i*86|x86_64*) flags="$flags -mcpu=$arch -m$arch";; esac
  120. else
  121. flags="-march=$arch -mcpu=$arch -m$arch"
  122. fi
  123. for flag in $flags; do
  124. AX_CHECK_COMPILER_FLAGS($flag, [ax_cv_gcc_archflag=$flag; break])
  125. done
  126. test "x$ax_cv_gcc_archflag" = xunknown || break
  127. done
  128. fi
  129. fi # $GCC=yes
  130. ])
  131. AC_MSG_CHECKING([for gcc architecture flag])
  132. AC_MSG_RESULT($ax_cv_gcc_archflag)
  133. if test "x$ax_cv_gcc_archflag" = xunknown; then
  134. m4_default([$3],:)
  135. else
  136. m4_default([$2], [CFLAGS="$CFLAGS $ax_cv_gcc_archflag"])
  137. fi
  138. ])