2.2 ABI and ISA

ABI (Application Binary Interface) refers to the calling conventions between functions, meaning what registers are used and what sizes the various C data types are. ISA (Instruction Set Architecture) refers to the instructions and registers a CPU has available.

Some 64-bit ISA CPUs have both a 64-bit ABI and a 32-bit ABI defined, the latter for compatibility with older CPUs in the family. GMP supports some CPUs like this in both ABIs. In fact within GMP ‘ABI’ means a combination of chip ABI, plus how GMP chooses to use it. For example in some 32-bit ABIs, GMP may support a limb as either a 32-bit long or a 64-bit long long.

By default GMP chooses the best ABI available for a given system, and this generally gives significantly greater speed. But an ABI can be chosen explicitly to make GMP compatible with other libraries, or particular application requirements. For example,

./configure ABI=32

In all cases it’s vital that all object code used in a given program is compiled for the same ABI.

Usually a limb is implemented as a long. When a long long limb is used this is encoded in the generated gmp.h. This is convenient for applications, but it does mean that gmp.h will vary, and can’t be just copied around. gmp.h remains compiler independent though, since all compilers for a particular ABI will be expected to use the same limb type.

Currently no attempt is made to follow whatever conventions a system has for installing library or header files built for a particular ABI. This will probably only matter when installing multiple builds of GMP, and it might be as simple as configuring with a special ‘libdir’, or it might require more than that. Note that builds for different ABIs need to be done separately, with a fresh ./configure and make each.


AMD64 (‘x86_64’)

On AMD64 systems supporting both 32-bit and 64-bit modes for applications, the following ABI choices are available.

ABI=64

The 64-bit ABI uses 64-bit limbs and pointers and makes full use of the chip architecture. This is the default. Applications will usually not need special compiler flags, but for reference the option is

gcc  -m64
ABI=32

The 32-bit ABI is the usual i386 conventions. This will be slower, and is not recommended except for inter-operating with other code not yet 64-bit capable. Applications must be compiled with

gcc  -m32

(In GCC 2.95 and earlier there’s no ‘-m32’ option, it’s the only mode.)

ABI=x32

The x32 ABI uses 64-bit limbs but 32-bit pointers. Like the 64-bit ABI, it makes full use of the chip’s arithmetic capabilities. This ABI is not supported by all operating systems.

gcc  -mx32

HPPA 2.0 (‘hppa2.0*’, ‘hppa64’)
ABI=2.0w

The 2.0w ABI uses 64-bit limbs and pointers and is available on HP-UX 11 or up. Applications must be compiled with

gcc [built for 2.0w]
cc  +DD64
ABI=2.0n

The 2.0n ABI means the 32-bit HPPA 1.0 ABI and all its normal calling conventions, but with 64-bit instructions permitted within functions. GMP uses a 64-bit long long for a limb. This ABI is available on hppa64 GNU/Linux and on HP-UX 10 or higher. Applications must be compiled with

gcc [built for 2.0n]
cc  +DA2.0 +e

Note that current versions of GCC (e.g. 3.2) don’t generate 64-bit instructions for long long operations and so may be slower than for 2.0w. (The GMP assembly code is the same though.)

ABI=1.0

HPPA 2.0 CPUs can run all HPPA 1.0 and 1.1 code in the 32-bit HPPA 1.0 ABI. No special compiler options are needed for applications.

All three ABIs are available for CPU types ‘hppa2.0w’, ‘hppa2.0’ and ‘hppa64’, but for CPU type ‘hppa2.0n’ only 2.0n or 1.0 are considered.

Note that GCC on HP-UX has no options to choose between 2.0n and 2.0w modes, unlike HP cc. Instead it must be built for one or the other ABI. GMP will detect how it was built, and skip to the corresponding ‘ABI’.


IA-64 under HP-UX (‘ia64*-*-hpux*’, ‘itanium*-*-hpux*’)

HP-UX supports two ABIs for IA-64. GMP performance is the same in both.

ABI=32

In the 32-bit ABI, pointers, ints and longs are 32 bits and GMP uses a 64 bit long long for a limb. Applications can be compiled without any special flags since this ABI is the default in both HP C and GCC, but for reference the flags are

gcc  -milp32
cc   +DD32
ABI=64

In the 64-bit ABI, longs and pointers are 64 bits and GMP uses a long for a limb. Applications must be compiled with

gcc  -mlp64
cc   +DD64

On other IA-64 systems, GNU/Linux for instance, ‘ABI=64’ is the only choice.


MIPS under IRIX 6 (‘mips*-*-irix[6789]’)

IRIX 6 always has a 64-bit MIPS 3 or better CPU, and supports ABIs o32, n32, and 64. n32 or 64 are recommended, and GMP performance will be the same in each. The default is n32.

ABI=o32

The o32 ABI is 32-bit pointers and integers, and no 64-bit operations. GMP will be slower than in n32 or 64, this option only exists to support old compilers, e.g. GCC 2.7.2. Applications can be compiled with no special flags on an old compiler, or on a newer compiler with

gcc  -mabi=32
cc   -32
ABI=n32

The n32 ABI is 32-bit pointers and integers, but with a 64-bit limb using a long long. Applications must be compiled with

gcc  -mabi=n32
cc   -n32
ABI=64

The 64-bit ABI is 64-bit pointers and integers. Applications must be compiled with

gcc  -mabi=64
cc   -64

Note that MIPS GNU/Linux, as of kernel version 2.2, doesn’t have the necessary support for n32 or 64 and so only gets a 32-bit limb and the MIPS 2 code.


PowerPC 64 (‘powerpc64’, ‘powerpc620’, ‘powerpc630’, ‘powerpc970’, ‘power4’, ‘power5’)
ABI=mode64

The AIX 64 ABI uses 64-bit limbs and pointers and is the default on PowerPC 64 ‘*-*-aix*’ systems. Applications must be compiled with

gcc  -maix64
xlc  -q64

On 64-bit GNU/Linux, BSD, and Mac OS X/Darwin systems, the applications must be compiled with

gcc  -m64
ABI=mode32

The ‘mode32’ ABI uses a 64-bit long long limb but with the chip still in 32-bit mode and using 32-bit calling conventions. This is the default for systems where the true 64-bit ABI is unavailable. No special compiler options are typically needed for applications. This ABI is not available under AIX.

ABI=32

This is the basic 32-bit PowerPC ABI, with a 32-bit limb. No special compiler options are needed for applications.

GMP’s speed is greatest for the ‘mode64’ ABI, the ‘mode32’ ABI is 2nd best. In ‘ABI=32’ only the 32-bit ISA is used and this doesn’t make full use of a 64-bit chip.


Sparc V9 (‘sparc64’, ‘sparcv9’, ‘ultrasparc*’)
ABI=64

The 64-bit V9 ABI is available on the various BSD sparc64 ports, recent versions of Sparc64 GNU/Linux, and Solaris 2.7 and up (when the kernel is in 64-bit mode). GCC 3.2 or higher, or Sun cc is required. On GNU/Linux, depending on the default gcc mode, applications must be compiled with

gcc  -m64

On Solaris applications must be compiled with

gcc  -m64 -mptr64 -Wa,-xarch=v9 -mcpu=v9
cc   -xarch=v9

On the BSD sparc64 systems no special options are required, since 64-bits is the only ABI available.

ABI=32

For the basic 32-bit ABI, GMP still uses as much of the V9 ISA as it can. In the Sun documentation this combination is known as “v8plus”. On GNU/Linux, depending on the default gcc mode, applications may need to be compiled with

gcc  -m32

On Solaris, no special compiler options are required for applications, though using something like the following is recommended. (gcc 2.8 and earlier only support ‘-mv8’ though.)

gcc  -mv8plus
cc   -xarch=v8plus

GMP speed is greatest in ‘ABI=64’, so it’s the default where available. The speed is partly because there are extra registers available and partly because 64-bits is considered the more important case and has therefore had better code written for it.

Don’t be confused by the names of the ‘-m’ and ‘-x’ compiler options, they’re called ‘arch’ but effectively control both ABI and ISA.

On Solaris 2.6 and earlier, only ‘ABI=32’ is available since the kernel doesn’t save all registers.

On Solaris 2.7 with the kernel in 32-bit mode, a normal native build will reject ‘ABI=64’ because the resulting executables won’t run. ‘ABI=64’ can still be built if desired by making it look like a cross-compile, for example

./configure --build=none --host=sparcv9-sun-solaris2.7 ABI=64