1 # host-cpu-c-abi.m4 serial 1
2 dnl Copyright (C) 2002-2011 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.
7 dnl From Bruno Haible and Sam Steingold.
9 dnl Sets the HOST_CPU_C_ABI variable to the canonical name of the CPU with its
10 dnl C language ABI (application binary interface).
11 dnl Also defines __${HOST_CPU_C_ABI}__ as a C macro in config.h.
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.
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
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 * 'arm' and 'armel' are different canonical names, because they use
33 dnl different memory ordering for the C types like 'int', and although
34 dnl the instruction sets of 'arm' and 'armel' are the same.
35 dnl * The same name 'i386' is used for CPUs of type i386, i486, i586
36 dnl (Pentium), AMD K7, Pentium II, Pentium IV, etc., because
37 dnl - Instructions that do not exist on all of these CPUs (cmpxchg,
38 dnl MMX, SSE, SSE2, 3DNow! etc.) are not frequently used. If your
39 dnl assembly language source files use such instructions, you will
40 dnl need to make the distinction.
41 dnl - Speed of execution of the common instruction set is reasonable across
42 dnl the entire family of CPUs. If you have assembly language source files
43 dnl that are optimized for particular CPU types (like GNU gmp has), you
44 dnl will need to make the distinction.
45 dnl See <http://en.wikipedia.org/wiki/X86_instruction_listings>.
46 AC_DEFUN([gl_HOST_CPU_C_ABI],
48 AC_REQUIRE([AC_CANONICAL_HOST])
49 AC_CACHE_CHECK([host CPU and C ABI], [gl_cv_host_cpu_c_abi],
55 gl_cv_host_cpu_c_abi=i386
59 # On x86_64 systems, the C compiler may still be generating
62 [#if defined __LP64__ || defined __x86_64__ || defined __amd64__
65 [gl_cv_host_cpu_c_abi=x86_64],
66 [gl_cv_host_cpu_c_abi=i386])
70 alphaev[4-8] | alphaev56 | alphapca5[67] | alphaev6[78] )
72 gl_cv_host_cpu_c_abi=alpha
77 [#if defined __ARMEL__
80 [gl_cv_host_cpu_c_abi=armel],
81 [gl_cv_host_cpu_c_abi=arm])
84 hppa1.0 | hppa1.1 | hppa2.0* | hppa64 )
85 # TODO: Distinguish hppa and hppa64 correctly.
86 gl_cv_host_cpu_c_abi=hppa
90 # We should also check for (_MIPS_SZPTR == 64), but gcc keeps this
93 [#if defined _MIPS_SZLONG && (_MIPS_SZLONG == 64)
96 [gl_cv_host_cpu_c_abi=mips64],
97 [# Strictly speaking, the MIPS ABI (-32 or -n32) is independent
98 # from the CPU identification (-mips[12] or -mips[34]). But -n32
99 # is commonly used together with -mips3, and it's easier to test
100 # the CPU identification.
105 [gl_cv_host_cpu_c_abi=mipsn32],
106 [gl_cv_host_cpu_c_abi=mips])])
110 # On powerpc64 systems, the C compiler may still be generating
113 [#if defined __powerpc64__ || defined _ARCH_PPC64
116 [gl_cv_host_cpu_c_abi=powerpc64],
117 [gl_cv_host_cpu_c_abi=powerpc])
121 gl_cv_host_cpu_c_abi=powerpc
124 # TODO: Distinguish s390 and s390x correctly.
127 # UltraSPARCs running Linux have `uname -m` = "sparc64", but the
128 # C compiler still generates 32-bit code.
130 [#if defined __sparcv9 || defined __arch64__
133 [gl_cv_host_cpu_c_abi=sparc64],
134 [gl_cv_host_cpu_c_abi=sparc])
138 gl_cv_host_cpu_c_abi="$host_cpu"
143 HOST_CPU_C_ABI="$gl_cv_host_cpu_c_abi"
144 AC_SUBST([HOST_CPU_C_ABI])
146 # This was AC_DEFINE_UNQUOTED([__${gl_cv_host_cpu_c_abi}__]) earlier,
147 # but KAI C++ 3.2d doesn't like this.
148 cat >> confdefs.h <<EOF
149 #ifndef __${gl_cv_host_cpu_c_abi}__
150 #define __${gl_cv_host_cpu_c_abi}__ 1
153 AH_TOP([/* CPU and C ABI indicator */
193 #ifndef __powerpc64__