arch.m4 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. dnl This Source Code Form is subject to the terms of the Mozilla Public
  2. dnl License, v. 2.0. If a copy of the MPL was not distributed with this
  3. dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. AC_DEFUN([MOZ_ARCH_OPTS],
  5. [
  6. dnl ========================================================
  7. dnl = ARM toolchain tweaks
  8. dnl ========================================================
  9. MOZ_THUMB=toolchain-default
  10. MOZ_THUMB_INTERWORK=toolchain-default
  11. MOZ_FPU=toolchain-default
  12. MOZ_FLOAT_ABI=toolchain-default
  13. MOZ_SOFT_FLOAT=toolchain-default
  14. MOZ_ALIGN=toolchain-default
  15. MOZ_ARG_WITH_STRING(arch,
  16. [ --with-arch=[[type|toolchain-default]]
  17. Use specific CPU features (-march=type). Resets
  18. thumb, fpu, float-abi, etc. defaults when set],
  19. if test -z "$GNU_CC"; then
  20. AC_MSG_ERROR([--with-arch is not supported on non-GNU toolchains])
  21. fi
  22. MOZ_ARCH=$withval)
  23. if test -z "$MOZ_ARCH"; then
  24. dnl Defaults
  25. case "${CPU_ARCH}-${OS_TARGET}" in
  26. arm-Android)
  27. MOZ_THUMB=yes
  28. MOZ_ARCH=armv7-a
  29. MOZ_FPU=vfp
  30. MOZ_FLOAT_ABI=softfp
  31. MOZ_ALIGN=no
  32. ;;
  33. arm-Darwin)
  34. MOZ_ARCH=toolchain-default
  35. ;;
  36. esac
  37. fi
  38. if test "$MOZ_ARCH" = "armv6" -a "$OS_TARGET" = "Android"; then
  39. MOZ_FPU=vfp
  40. MOZ_FLOAT_ABI=softfp
  41. fi
  42. MOZ_ARG_WITH_STRING(thumb,
  43. [ --with-thumb[[=yes|no|toolchain-default]]]
  44. [ Use Thumb instruction set (-mthumb)],
  45. if test -z "$GNU_CC"; then
  46. AC_MSG_ERROR([--with-thumb is not supported on non-GNU toolchains])
  47. fi
  48. MOZ_THUMB=$withval)
  49. MOZ_ARG_WITH_STRING(thumb-interwork,
  50. [ --with-thumb-interwork[[=yes|no|toolchain-default]]
  51. Use Thumb/ARM instuctions interwork (-mthumb-interwork)],
  52. if test -z "$GNU_CC"; then
  53. AC_MSG_ERROR([--with-thumb-interwork is not supported on non-GNU toolchains])
  54. fi
  55. MOZ_THUMB_INTERWORK=$withval)
  56. MOZ_ARG_WITH_STRING(fpu,
  57. [ --with-fpu=[[type|toolchain-default]]
  58. Use specific FPU type (-mfpu=type)],
  59. if test -z "$GNU_CC"; then
  60. AC_MSG_ERROR([--with-fpu is not supported on non-GNU toolchains])
  61. fi
  62. MOZ_FPU=$withval)
  63. MOZ_ARG_WITH_STRING(float-abi,
  64. [ --with-float-abi=[[type|toolchain-default]]
  65. Use specific arm float ABI (-mfloat-abi=type)],
  66. if test -z "$GNU_CC"; then
  67. AC_MSG_ERROR([--with-float-abi is not supported on non-GNU toolchains])
  68. fi
  69. MOZ_FLOAT_ABI=$withval)
  70. MOZ_ARG_WITH_STRING(soft-float,
  71. [ --with-soft-float[[=yes|no|toolchain-default]]
  72. Use soft float library (-msoft-float)],
  73. if test -z "$GNU_CC"; then
  74. AC_MSG_ERROR([--with-soft-float is not supported on non-GNU toolchains])
  75. fi
  76. MOZ_SOFT_FLOAT=$withval)
  77. case "$MOZ_ARCH" in
  78. toolchain-default|"")
  79. arch_flag=""
  80. ;;
  81. *)
  82. arch_flag="-march=$MOZ_ARCH"
  83. ;;
  84. esac
  85. case "$MOZ_THUMB" in
  86. yes)
  87. MOZ_THUMB2=1
  88. thumb_flag="-mthumb"
  89. ;;
  90. no)
  91. MOZ_THUMB2=
  92. thumb_flag="-marm"
  93. ;;
  94. *)
  95. _SAVE_CFLAGS="$CFLAGS"
  96. CFLAGS="$arch_flag"
  97. AC_TRY_COMPILE([],[return sizeof(__thumb2__);],
  98. MOZ_THUMB2=1,
  99. MOZ_THUMB2=)
  100. CFLAGS="$_SAVE_CFLAGS"
  101. thumb_flag=""
  102. ;;
  103. esac
  104. if test "$MOZ_THUMB2" = 1; then
  105. AC_DEFINE(MOZ_THUMB2)
  106. fi
  107. case "$MOZ_THUMB_INTERWORK" in
  108. yes)
  109. thumb_interwork_flag="-mthumb-interwork"
  110. ;;
  111. no)
  112. thumb_interwork_flag="-mno-thumb-interwork"
  113. ;;
  114. *) # toolchain-default
  115. thumb_interwork_flag=""
  116. ;;
  117. esac
  118. case "$MOZ_FPU" in
  119. toolchain-default|"")
  120. fpu_flag=""
  121. ;;
  122. *)
  123. fpu_flag="-mfpu=$MOZ_FPU"
  124. ;;
  125. esac
  126. case "$MOZ_FLOAT_ABI" in
  127. toolchain-default|"")
  128. float_abi_flag=""
  129. ;;
  130. *)
  131. float_abi_flag="-mfloat-abi=$MOZ_FLOAT_ABI"
  132. ;;
  133. esac
  134. case "$MOZ_SOFT_FLOAT" in
  135. yes)
  136. soft_float_flag="-msoft-float"
  137. ;;
  138. no)
  139. soft_float_flag="-mno-soft-float"
  140. ;;
  141. *) # toolchain-default
  142. soft_float_flag=""
  143. ;;
  144. esac
  145. case "$MOZ_ALIGN" in
  146. no)
  147. align_flag="-mno-unaligned-access"
  148. ;;
  149. yes)
  150. align_flag="-munaligned-access"
  151. ;;
  152. *)
  153. align_flag=""
  154. ;;
  155. esac
  156. if test -n "$align_flag"; then
  157. _SAVE_CFLAGS="$CFLAGS"
  158. CFLAGS="$CFLAGS $align_flag"
  159. AC_MSG_CHECKING(whether alignment flag ($align_flag) is supported)
  160. AC_TRY_COMPILE([],[],,align_flag="")
  161. CFLAGS="$_SAVE_CFLAGS"
  162. fi
  163. dnl Use echo to avoid accumulating space characters
  164. all_flags=`echo $arch_flag $thumb_flag $thumb_interwork_flag $fpu_flag $float_abi_flag $soft_float_flag $align_flag`
  165. if test -n "$all_flags"; then
  166. _SAVE_CFLAGS="$CFLAGS"
  167. CFLAGS="$all_flags"
  168. AC_MSG_CHECKING(whether the chosen combination of compiler flags ($all_flags) works)
  169. AC_TRY_COMPILE([],[return 0;],
  170. AC_MSG_RESULT([yes]),
  171. AC_MSG_ERROR([no]))
  172. CFLAGS="$_SAVE_CFLAGS $all_flags"
  173. CXXFLAGS="$CXXFLAGS $all_flags"
  174. ASFLAGS="$ASFLAGS $all_flags"
  175. if test -n "$thumb_flag"; then
  176. LDFLAGS="$LDFLAGS $thumb_flag"
  177. fi
  178. fi
  179. AC_SUBST(MOZ_THUMB2)
  180. if test "$CPU_ARCH" = "arm"; then
  181. NEON_FLAGS="-mfpu=neon"
  182. AC_MSG_CHECKING(for ARM SIMD support in compiler)
  183. # We try to link so that this also fails when
  184. # building with LTO.
  185. AC_TRY_LINK([],
  186. [asm("uqadd8 r1, r1, r2");],
  187. result="yes", result="no")
  188. AC_MSG_RESULT("$result")
  189. if test "$result" = "yes"; then
  190. AC_DEFINE(HAVE_ARM_SIMD)
  191. HAVE_ARM_SIMD=1
  192. fi
  193. AC_MSG_CHECKING(ARM version support in compiler)
  194. dnl Determine the target ARM architecture (5 for ARMv5, v5T, v5E, etc.; 6 for ARMv6, v6K, etc.)
  195. ARM_ARCH=`${CC-cc} ${CFLAGS} -dM -E - < /dev/null | sed -n 's/.*__ARM_ARCH_\([[0-9]][[0-9]]*\).*/\1/p'`
  196. AC_MSG_RESULT("$ARM_ARCH")
  197. AC_MSG_CHECKING(for ARM NEON support in compiler)
  198. # We try to link so that this also fails when
  199. # building with LTO.
  200. AC_TRY_LINK([],
  201. [asm(".fpu neon\n vadd.i8 d0, d0, d0");],
  202. result="yes", result="no")
  203. AC_MSG_RESULT("$result")
  204. if test "$result" = "yes"; then
  205. AC_DEFINE(HAVE_ARM_NEON)
  206. HAVE_ARM_NEON=1
  207. dnl We don't need to build NEON support if we're targetting a non-NEON device.
  208. dnl This matches media/webrtc/trunk/webrtc/build/common.gypi.
  209. if test -n "$ARM_ARCH"; then
  210. if test "$ARM_ARCH" -lt 7; then
  211. BUILD_ARM_NEON=
  212. else
  213. AC_DEFINE(BUILD_ARM_NEON)
  214. BUILD_ARM_NEON=1
  215. fi
  216. fi
  217. fi
  218. fi # CPU_ARCH = arm
  219. AC_SUBST(HAVE_ARM_SIMD)
  220. AC_SUBST(HAVE_ARM_NEON)
  221. AC_SUBST(BUILD_ARM_NEON)
  222. AC_SUBST(ARM_ARCH)
  223. AC_SUBST_LIST(NEON_FLAGS)
  224. ])