host-cpu-c-abi.m4 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. # host-cpu-c-abi.m4 serial 15
  2. dnl Copyright (C) 2002-2022 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. dnl From Bruno Haible and Sam Steingold.
  7. dnl Sets the HOST_CPU variable to the canonical name of the CPU.
  8. dnl Sets the HOST_CPU_C_ABI variable to the canonical name of the CPU with its
  9. dnl C language ABI (application binary interface).
  10. dnl Also defines __${HOST_CPU}__ and __${HOST_CPU_C_ABI}__ as C macros in
  11. dnl config.h.
  12. dnl
  13. dnl This canonical name can be used to select a particular assembly language
  14. dnl source file that will interoperate with C code on the given host.
  15. dnl
  16. dnl For example:
  17. dnl * 'i386' and 'sparc' are different canonical names, because code for i386
  18. dnl will not run on SPARC CPUs and vice versa. They have different
  19. dnl instruction sets.
  20. dnl * 'sparc' and 'sparc64' are different canonical names, because code for
  21. dnl 'sparc' and code for 'sparc64' cannot be linked together: 'sparc' code
  22. dnl contains 32-bit instructions, whereas 'sparc64' code contains 64-bit
  23. dnl instructions. A process on a SPARC CPU can be in 32-bit mode or in 64-bit
  24. dnl mode, but not both.
  25. dnl * 'mips' and 'mipsn32' are different canonical names, because they use
  26. dnl different argument passing and return conventions for C functions, and
  27. dnl although the instruction set of 'mips' is a large subset of the
  28. dnl instruction set of 'mipsn32'.
  29. dnl * 'mipsn32' and 'mips64' are different canonical names, because they use
  30. dnl different sizes for the C types like 'int' and 'void *', and although
  31. dnl the instruction sets of 'mipsn32' and 'mips64' are the same.
  32. dnl * The same canonical name is used for different endiannesses. You can
  33. dnl determine the endianness through preprocessor symbols:
  34. dnl - 'arm': test __ARMEL__.
  35. dnl - 'mips', 'mipsn32', 'mips64': test _MIPSEB vs. _MIPSEL.
  36. dnl - 'powerpc64': test _BIG_ENDIAN vs. _LITTLE_ENDIAN.
  37. dnl * The same name 'i386' is used for CPUs of type i386, i486, i586
  38. dnl (Pentium), AMD K7, Pentium II, Pentium IV, etc., because
  39. dnl - Instructions that do not exist on all of these CPUs (cmpxchg,
  40. dnl MMX, SSE, SSE2, 3DNow! etc.) are not frequently used. If your
  41. dnl assembly language source files use such instructions, you will
  42. dnl need to make the distinction.
  43. dnl - Speed of execution of the common instruction set is reasonable across
  44. dnl the entire family of CPUs. If you have assembly language source files
  45. dnl that are optimized for particular CPU types (like GNU gmp has), you
  46. dnl will need to make the distinction.
  47. dnl See <https://en.wikipedia.org/wiki/X86_instruction_listings>.
  48. AC_DEFUN([gl_HOST_CPU_C_ABI],
  49. [
  50. AC_REQUIRE([AC_CANONICAL_HOST])
  51. AC_REQUIRE([gl_C_ASM])
  52. AC_CACHE_CHECK([host CPU and C ABI], [gl_cv_host_cpu_c_abi],
  53. [case "$host_cpu" in
  54. changequote(,)dnl
  55. i[34567]86 )
  56. changequote([,])dnl
  57. gl_cv_host_cpu_c_abi=i386
  58. ;;
  59. x86_64 )
  60. # On x86_64 systems, the C compiler may be generating code in one of
  61. # these ABIs:
  62. # - 64-bit instruction set, 64-bit pointers, 64-bit 'long': x86_64.
  63. # - 64-bit instruction set, 64-bit pointers, 32-bit 'long': x86_64
  64. # with native Windows (mingw, MSVC).
  65. # - 64-bit instruction set, 32-bit pointers, 32-bit 'long': x86_64-x32.
  66. # - 32-bit instruction set, 32-bit pointers, 32-bit 'long': i386.
  67. AC_COMPILE_IFELSE(
  68. [AC_LANG_SOURCE(
  69. [[#if (defined __x86_64__ || defined __amd64__ \
  70. || defined _M_X64 || defined _M_AMD64)
  71. int ok;
  72. #else
  73. error fail
  74. #endif
  75. ]])],
  76. [AC_COMPILE_IFELSE(
  77. [AC_LANG_SOURCE(
  78. [[#if defined __ILP32__ || defined _ILP32
  79. int ok;
  80. #else
  81. error fail
  82. #endif
  83. ]])],
  84. [gl_cv_host_cpu_c_abi=x86_64-x32],
  85. [gl_cv_host_cpu_c_abi=x86_64])],
  86. [gl_cv_host_cpu_c_abi=i386])
  87. ;;
  88. changequote(,)dnl
  89. alphaev[4-8] | alphaev56 | alphapca5[67] | alphaev6[78] )
  90. changequote([,])dnl
  91. gl_cv_host_cpu_c_abi=alpha
  92. ;;
  93. arm* | aarch64 )
  94. # Assume arm with EABI.
  95. # On arm64 systems, the C compiler may be generating code in one of
  96. # these ABIs:
  97. # - aarch64 instruction set, 64-bit pointers, 64-bit 'long': arm64.
  98. # - aarch64 instruction set, 32-bit pointers, 32-bit 'long': arm64-ilp32.
  99. # - 32-bit instruction set, 32-bit pointers, 32-bit 'long': arm or armhf.
  100. AC_COMPILE_IFELSE(
  101. [AC_LANG_SOURCE(
  102. [[#ifdef __aarch64__
  103. int ok;
  104. #else
  105. error fail
  106. #endif
  107. ]])],
  108. [AC_COMPILE_IFELSE(
  109. [AC_LANG_SOURCE(
  110. [[#if defined __ILP32__ || defined _ILP32
  111. int ok;
  112. #else
  113. error fail
  114. #endif
  115. ]])],
  116. [gl_cv_host_cpu_c_abi=arm64-ilp32],
  117. [gl_cv_host_cpu_c_abi=arm64])],
  118. [# Don't distinguish little-endian and big-endian arm, since they
  119. # don't require different machine code for simple operations and
  120. # since the user can distinguish them through the preprocessor
  121. # defines __ARMEL__ vs. __ARMEB__.
  122. # But distinguish arm which passes floating-point arguments and
  123. # return values in integer registers (r0, r1, ...) - this is
  124. # gcc -mfloat-abi=soft or gcc -mfloat-abi=softfp - from arm which
  125. # passes them in float registers (s0, s1, ...) and double registers
  126. # (d0, d1, ...) - this is gcc -mfloat-abi=hard. GCC 4.6 or newer
  127. # sets the preprocessor defines __ARM_PCS (for the first case) and
  128. # __ARM_PCS_VFP (for the second case), but older GCC does not.
  129. echo 'double ddd; void func (double dd) { ddd = dd; }' > conftest.c
  130. # Look for a reference to the register d0 in the .s file.
  131. AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS $gl_c_asm_opt conftest.c) >/dev/null 2>&1
  132. if LC_ALL=C grep 'd0,' conftest.$gl_asmext >/dev/null; then
  133. gl_cv_host_cpu_c_abi=armhf
  134. else
  135. gl_cv_host_cpu_c_abi=arm
  136. fi
  137. rm -f conftest*
  138. ])
  139. ;;
  140. hppa1.0 | hppa1.1 | hppa2.0* | hppa64 )
  141. # On hppa, the C compiler may be generating 32-bit code or 64-bit
  142. # code. In the latter case, it defines _LP64 and __LP64__.
  143. AC_COMPILE_IFELSE(
  144. [AC_LANG_SOURCE(
  145. [[#ifdef __LP64__
  146. int ok;
  147. #else
  148. error fail
  149. #endif
  150. ]])],
  151. [gl_cv_host_cpu_c_abi=hppa64],
  152. [gl_cv_host_cpu_c_abi=hppa])
  153. ;;
  154. ia64* )
  155. # On ia64 on HP-UX, the C compiler may be generating 64-bit code or
  156. # 32-bit code. In the latter case, it defines _ILP32.
  157. AC_COMPILE_IFELSE(
  158. [AC_LANG_SOURCE(
  159. [[#ifdef _ILP32
  160. int ok;
  161. #else
  162. error fail
  163. #endif
  164. ]])],
  165. [gl_cv_host_cpu_c_abi=ia64-ilp32],
  166. [gl_cv_host_cpu_c_abi=ia64])
  167. ;;
  168. mips* )
  169. # We should also check for (_MIPS_SZPTR == 64), but gcc keeps this
  170. # at 32.
  171. AC_COMPILE_IFELSE(
  172. [AC_LANG_SOURCE(
  173. [[#if defined _MIPS_SZLONG && (_MIPS_SZLONG == 64)
  174. int ok;
  175. #else
  176. error fail
  177. #endif
  178. ]])],
  179. [gl_cv_host_cpu_c_abi=mips64],
  180. [# In the n32 ABI, _ABIN32 is defined, _ABIO32 is not defined (but
  181. # may later get defined by <sgidefs.h>), and _MIPS_SIM == _ABIN32.
  182. # In the 32 ABI, _ABIO32 is defined, _ABIN32 is not defined (but
  183. # may later get defined by <sgidefs.h>), and _MIPS_SIM == _ABIO32.
  184. AC_COMPILE_IFELSE(
  185. [AC_LANG_SOURCE(
  186. [[#if (_MIPS_SIM == _ABIN32)
  187. int ok;
  188. #else
  189. error fail
  190. #endif
  191. ]])],
  192. [gl_cv_host_cpu_c_abi=mipsn32],
  193. [gl_cv_host_cpu_c_abi=mips])])
  194. ;;
  195. powerpc* )
  196. # Different ABIs are in use on AIX vs. Mac OS X vs. Linux,*BSD.
  197. # No need to distinguish them here; the caller may distinguish
  198. # them based on the OS.
  199. # On powerpc64 systems, the C compiler may still be generating
  200. # 32-bit code. And on powerpc-ibm-aix systems, the C compiler may
  201. # be generating 64-bit code.
  202. AC_COMPILE_IFELSE(
  203. [AC_LANG_SOURCE(
  204. [[#if defined __powerpc64__ || defined __LP64__
  205. int ok;
  206. #else
  207. error fail
  208. #endif
  209. ]])],
  210. [# On powerpc64, there are two ABIs on Linux: The AIX compatible
  211. # one and the ELFv2 one. The latter defines _CALL_ELF=2.
  212. AC_COMPILE_IFELSE(
  213. [AC_LANG_SOURCE(
  214. [[#if defined _CALL_ELF && _CALL_ELF == 2
  215. int ok;
  216. #else
  217. error fail
  218. #endif
  219. ]])],
  220. [gl_cv_host_cpu_c_abi=powerpc64-elfv2],
  221. [gl_cv_host_cpu_c_abi=powerpc64])
  222. ],
  223. [gl_cv_host_cpu_c_abi=powerpc])
  224. ;;
  225. rs6000 )
  226. gl_cv_host_cpu_c_abi=powerpc
  227. ;;
  228. riscv32 | riscv64 )
  229. # There are 2 architectures (with variants): rv32* and rv64*.
  230. AC_COMPILE_IFELSE(
  231. [AC_LANG_SOURCE(
  232. [[#if __riscv_xlen == 64
  233. int ok;
  234. #else
  235. error fail
  236. #endif
  237. ]])],
  238. [cpu=riscv64],
  239. [cpu=riscv32])
  240. # There are 6 ABIs: ilp32, ilp32f, ilp32d, lp64, lp64f, lp64d.
  241. # Size of 'long' and 'void *':
  242. AC_COMPILE_IFELSE(
  243. [AC_LANG_SOURCE(
  244. [[#if defined __LP64__
  245. int ok;
  246. #else
  247. error fail
  248. #endif
  249. ]])],
  250. [main_abi=lp64],
  251. [main_abi=ilp32])
  252. # Float ABIs:
  253. # __riscv_float_abi_double:
  254. # 'float' and 'double' are passed in floating-point registers.
  255. # __riscv_float_abi_single:
  256. # 'float' are passed in floating-point registers.
  257. # __riscv_float_abi_soft:
  258. # No values are passed in floating-point registers.
  259. AC_COMPILE_IFELSE(
  260. [AC_LANG_SOURCE(
  261. [[#if defined __riscv_float_abi_double
  262. int ok;
  263. #else
  264. error fail
  265. #endif
  266. ]])],
  267. [float_abi=d],
  268. [AC_COMPILE_IFELSE(
  269. [AC_LANG_SOURCE(
  270. [[#if defined __riscv_float_abi_single
  271. int ok;
  272. #else
  273. error fail
  274. #endif
  275. ]])],
  276. [float_abi=f],
  277. [float_abi=''])
  278. ])
  279. gl_cv_host_cpu_c_abi="${cpu}-${main_abi}${float_abi}"
  280. ;;
  281. s390* )
  282. # On s390x, the C compiler may be generating 64-bit (= s390x) code
  283. # or 31-bit (= s390) code.
  284. AC_COMPILE_IFELSE(
  285. [AC_LANG_SOURCE(
  286. [[#if defined __LP64__ || defined __s390x__
  287. int ok;
  288. #else
  289. error fail
  290. #endif
  291. ]])],
  292. [gl_cv_host_cpu_c_abi=s390x],
  293. [gl_cv_host_cpu_c_abi=s390])
  294. ;;
  295. sparc | sparc64 )
  296. # UltraSPARCs running Linux have `uname -m` = "sparc64", but the
  297. # C compiler still generates 32-bit code.
  298. AC_COMPILE_IFELSE(
  299. [AC_LANG_SOURCE(
  300. [[#if defined __sparcv9 || defined __arch64__
  301. int ok;
  302. #else
  303. error fail
  304. #endif
  305. ]])],
  306. [gl_cv_host_cpu_c_abi=sparc64],
  307. [gl_cv_host_cpu_c_abi=sparc])
  308. ;;
  309. *)
  310. gl_cv_host_cpu_c_abi="$host_cpu"
  311. ;;
  312. esac
  313. ])
  314. dnl In most cases, $HOST_CPU and $HOST_CPU_C_ABI are the same.
  315. HOST_CPU=`echo "$gl_cv_host_cpu_c_abi" | sed -e 's/-.*//'`
  316. HOST_CPU_C_ABI="$gl_cv_host_cpu_c_abi"
  317. AC_SUBST([HOST_CPU])
  318. AC_SUBST([HOST_CPU_C_ABI])
  319. # This was
  320. # AC_DEFINE_UNQUOTED([__${HOST_CPU}__])
  321. # AC_DEFINE_UNQUOTED([__${HOST_CPU_C_ABI}__])
  322. # earlier, but KAI C++ 3.2d doesn't like this.
  323. sed -e 's/-/_/g' >> confdefs.h <<EOF
  324. #ifndef __${HOST_CPU}__
  325. #define __${HOST_CPU}__ 1
  326. #endif
  327. #ifndef __${HOST_CPU_C_ABI}__
  328. #define __${HOST_CPU_C_ABI}__ 1
  329. #endif
  330. EOF
  331. AH_TOP([/* CPU and C ABI indicator */
  332. #ifndef __i386__
  333. #undef __i386__
  334. #endif
  335. #ifndef __x86_64_x32__
  336. #undef __x86_64_x32__
  337. #endif
  338. #ifndef __x86_64__
  339. #undef __x86_64__
  340. #endif
  341. #ifndef __alpha__
  342. #undef __alpha__
  343. #endif
  344. #ifndef __arm__
  345. #undef __arm__
  346. #endif
  347. #ifndef __armhf__
  348. #undef __armhf__
  349. #endif
  350. #ifndef __arm64_ilp32__
  351. #undef __arm64_ilp32__
  352. #endif
  353. #ifndef __arm64__
  354. #undef __arm64__
  355. #endif
  356. #ifndef __hppa__
  357. #undef __hppa__
  358. #endif
  359. #ifndef __hppa64__
  360. #undef __hppa64__
  361. #endif
  362. #ifndef __ia64_ilp32__
  363. #undef __ia64_ilp32__
  364. #endif
  365. #ifndef __ia64__
  366. #undef __ia64__
  367. #endif
  368. #ifndef __loongarch64__
  369. #undef __loongarch64__
  370. #endif
  371. #ifndef __m68k__
  372. #undef __m68k__
  373. #endif
  374. #ifndef __mips__
  375. #undef __mips__
  376. #endif
  377. #ifndef __mipsn32__
  378. #undef __mipsn32__
  379. #endif
  380. #ifndef __mips64__
  381. #undef __mips64__
  382. #endif
  383. #ifndef __powerpc__
  384. #undef __powerpc__
  385. #endif
  386. #ifndef __powerpc64__
  387. #undef __powerpc64__
  388. #endif
  389. #ifndef __powerpc64_elfv2__
  390. #undef __powerpc64_elfv2__
  391. #endif
  392. #ifndef __riscv32__
  393. #undef __riscv32__
  394. #endif
  395. #ifndef __riscv64__
  396. #undef __riscv64__
  397. #endif
  398. #ifndef __riscv32_ilp32__
  399. #undef __riscv32_ilp32__
  400. #endif
  401. #ifndef __riscv32_ilp32f__
  402. #undef __riscv32_ilp32f__
  403. #endif
  404. #ifndef __riscv32_ilp32d__
  405. #undef __riscv32_ilp32d__
  406. #endif
  407. #ifndef __riscv64_ilp32__
  408. #undef __riscv64_ilp32__
  409. #endif
  410. #ifndef __riscv64_ilp32f__
  411. #undef __riscv64_ilp32f__
  412. #endif
  413. #ifndef __riscv64_ilp32d__
  414. #undef __riscv64_ilp32d__
  415. #endif
  416. #ifndef __riscv64_lp64__
  417. #undef __riscv64_lp64__
  418. #endif
  419. #ifndef __riscv64_lp64f__
  420. #undef __riscv64_lp64f__
  421. #endif
  422. #ifndef __riscv64_lp64d__
  423. #undef __riscv64_lp64d__
  424. #endif
  425. #ifndef __s390__
  426. #undef __s390__
  427. #endif
  428. #ifndef __s390x__
  429. #undef __s390x__
  430. #endif
  431. #ifndef __sh__
  432. #undef __sh__
  433. #endif
  434. #ifndef __sparc__
  435. #undef __sparc__
  436. #endif
  437. #ifndef __sparc64__
  438. #undef __sparc64__
  439. #endif
  440. ])
  441. ])
  442. dnl Sets the HOST_CPU_C_ABI_32BIT variable to 'yes' if the C language ABI
  443. dnl (application binary interface) is a 32-bit one, to 'no' if it is a 64-bit
  444. dnl one, or to 'unknown' if unknown.
  445. dnl This is a simplified variant of gl_HOST_CPU_C_ABI.
  446. AC_DEFUN([gl_HOST_CPU_C_ABI_32BIT],
  447. [
  448. AC_REQUIRE([AC_CANONICAL_HOST])
  449. AC_CACHE_CHECK([32-bit host C ABI], [gl_cv_host_cpu_c_abi_32bit],
  450. [if test -n "$gl_cv_host_cpu_c_abi"; then
  451. case "$gl_cv_host_cpu_c_abi" in
  452. i386 | x86_64-x32 | arm | armhf | arm64-ilp32 | hppa | ia64-ilp32 | mips | mipsn32 | powerpc | riscv*-ilp32* | s390 | sparc)
  453. gl_cv_host_cpu_c_abi_32bit=yes ;;
  454. x86_64 | alpha | arm64 | hppa64 | ia64 | mips64 | powerpc64 | powerpc64-elfv2 | riscv*-lp64* | s390x | sparc64 )
  455. gl_cv_host_cpu_c_abi_32bit=no ;;
  456. *)
  457. gl_cv_host_cpu_c_abi_32bit=unknown ;;
  458. esac
  459. else
  460. case "$host_cpu" in
  461. # CPUs that only support a 32-bit ABI.
  462. arc \
  463. | bfin \
  464. | cris* \
  465. | csky \
  466. | epiphany \
  467. | ft32 \
  468. | h8300 \
  469. | m68k \
  470. | microblaze | microblazeel \
  471. | nds32 | nds32le | nds32be \
  472. | nios2 | nios2eb | nios2el \
  473. | or1k* \
  474. | or32 \
  475. | sh | sh[1234] | sh[1234]e[lb] \
  476. | tic6x \
  477. | xtensa* )
  478. gl_cv_host_cpu_c_abi_32bit=yes
  479. ;;
  480. # CPUs that only support a 64-bit ABI.
  481. changequote(,)dnl
  482. alpha | alphaev[4-8] | alphaev56 | alphapca5[67] | alphaev6[78] \
  483. | mmix )
  484. changequote([,])dnl
  485. gl_cv_host_cpu_c_abi_32bit=no
  486. ;;
  487. changequote(,)dnl
  488. i[34567]86 )
  489. changequote([,])dnl
  490. gl_cv_host_cpu_c_abi_32bit=yes
  491. ;;
  492. x86_64 )
  493. # On x86_64 systems, the C compiler may be generating code in one of
  494. # these ABIs:
  495. # - 64-bit instruction set, 64-bit pointers, 64-bit 'long': x86_64.
  496. # - 64-bit instruction set, 64-bit pointers, 32-bit 'long': x86_64
  497. # with native Windows (mingw, MSVC).
  498. # - 64-bit instruction set, 32-bit pointers, 32-bit 'long': x86_64-x32.
  499. # - 32-bit instruction set, 32-bit pointers, 32-bit 'long': i386.
  500. AC_COMPILE_IFELSE(
  501. [AC_LANG_SOURCE(
  502. [[#if (defined __x86_64__ || defined __amd64__ \
  503. || defined _M_X64 || defined _M_AMD64) \
  504. && !(defined __ILP32__ || defined _ILP32)
  505. int ok;
  506. #else
  507. error fail
  508. #endif
  509. ]])],
  510. [gl_cv_host_cpu_c_abi_32bit=no],
  511. [gl_cv_host_cpu_c_abi_32bit=yes])
  512. ;;
  513. arm* | aarch64 )
  514. # Assume arm with EABI.
  515. # On arm64 systems, the C compiler may be generating code in one of
  516. # these ABIs:
  517. # - aarch64 instruction set, 64-bit pointers, 64-bit 'long': arm64.
  518. # - aarch64 instruction set, 32-bit pointers, 32-bit 'long': arm64-ilp32.
  519. # - 32-bit instruction set, 32-bit pointers, 32-bit 'long': arm or armhf.
  520. AC_COMPILE_IFELSE(
  521. [AC_LANG_SOURCE(
  522. [[#if defined __aarch64__ && !(defined __ILP32__ || defined _ILP32)
  523. int ok;
  524. #else
  525. error fail
  526. #endif
  527. ]])],
  528. [gl_cv_host_cpu_c_abi_32bit=no],
  529. [gl_cv_host_cpu_c_abi_32bit=yes])
  530. ;;
  531. hppa1.0 | hppa1.1 | hppa2.0* | hppa64 )
  532. # On hppa, the C compiler may be generating 32-bit code or 64-bit
  533. # code. In the latter case, it defines _LP64 and __LP64__.
  534. AC_COMPILE_IFELSE(
  535. [AC_LANG_SOURCE(
  536. [[#ifdef __LP64__
  537. int ok;
  538. #else
  539. error fail
  540. #endif
  541. ]])],
  542. [gl_cv_host_cpu_c_abi_32bit=no],
  543. [gl_cv_host_cpu_c_abi_32bit=yes])
  544. ;;
  545. ia64* )
  546. # On ia64 on HP-UX, the C compiler may be generating 64-bit code or
  547. # 32-bit code. In the latter case, it defines _ILP32.
  548. AC_COMPILE_IFELSE(
  549. [AC_LANG_SOURCE(
  550. [[#ifdef _ILP32
  551. int ok;
  552. #else
  553. error fail
  554. #endif
  555. ]])],
  556. [gl_cv_host_cpu_c_abi_32bit=yes],
  557. [gl_cv_host_cpu_c_abi_32bit=no])
  558. ;;
  559. mips* )
  560. # We should also check for (_MIPS_SZPTR == 64), but gcc keeps this
  561. # at 32.
  562. AC_COMPILE_IFELSE(
  563. [AC_LANG_SOURCE(
  564. [[#if defined _MIPS_SZLONG && (_MIPS_SZLONG == 64)
  565. int ok;
  566. #else
  567. error fail
  568. #endif
  569. ]])],
  570. [gl_cv_host_cpu_c_abi_32bit=no],
  571. [gl_cv_host_cpu_c_abi_32bit=yes])
  572. ;;
  573. powerpc* )
  574. # Different ABIs are in use on AIX vs. Mac OS X vs. Linux,*BSD.
  575. # No need to distinguish them here; the caller may distinguish
  576. # them based on the OS.
  577. # On powerpc64 systems, the C compiler may still be generating
  578. # 32-bit code. And on powerpc-ibm-aix systems, the C compiler may
  579. # be generating 64-bit code.
  580. AC_COMPILE_IFELSE(
  581. [AC_LANG_SOURCE(
  582. [[#if defined __powerpc64__ || defined __LP64__
  583. int ok;
  584. #else
  585. error fail
  586. #endif
  587. ]])],
  588. [gl_cv_host_cpu_c_abi_32bit=no],
  589. [gl_cv_host_cpu_c_abi_32bit=yes])
  590. ;;
  591. rs6000 )
  592. gl_cv_host_cpu_c_abi_32bit=yes
  593. ;;
  594. riscv32 | riscv64 )
  595. # There are 6 ABIs: ilp32, ilp32f, ilp32d, lp64, lp64f, lp64d.
  596. # Size of 'long' and 'void *':
  597. AC_COMPILE_IFELSE(
  598. [AC_LANG_SOURCE(
  599. [[#if defined __LP64__
  600. int ok;
  601. #else
  602. error fail
  603. #endif
  604. ]])],
  605. [gl_cv_host_cpu_c_abi_32bit=no],
  606. [gl_cv_host_cpu_c_abi_32bit=yes])
  607. ;;
  608. s390* )
  609. # On s390x, the C compiler may be generating 64-bit (= s390x) code
  610. # or 31-bit (= s390) code.
  611. AC_COMPILE_IFELSE(
  612. [AC_LANG_SOURCE(
  613. [[#if defined __LP64__ || defined __s390x__
  614. int ok;
  615. #else
  616. error fail
  617. #endif
  618. ]])],
  619. [gl_cv_host_cpu_c_abi_32bit=no],
  620. [gl_cv_host_cpu_c_abi_32bit=yes])
  621. ;;
  622. sparc | sparc64 )
  623. # UltraSPARCs running Linux have `uname -m` = "sparc64", but the
  624. # C compiler still generates 32-bit code.
  625. AC_COMPILE_IFELSE(
  626. [AC_LANG_SOURCE(
  627. [[#if defined __sparcv9 || defined __arch64__
  628. int ok;
  629. #else
  630. error fail
  631. #endif
  632. ]])],
  633. [gl_cv_host_cpu_c_abi_32bit=no],
  634. [gl_cv_host_cpu_c_abi_32bit=yes])
  635. ;;
  636. *)
  637. gl_cv_host_cpu_c_abi_32bit=unknown
  638. ;;
  639. esac
  640. fi
  641. ])
  642. HOST_CPU_C_ABI_32BIT="$gl_cv_host_cpu_c_abi_32bit"
  643. ])