The following built-in functions are always available and can be used to check the PowerPC target platform type:
void
__builtin_cpu_init (void)
¶This function is a nop
on the PowerPC platform and is included solely
to maintain API compatibility with the x86 builtins.
int
__builtin_cpu_is (const char *cpuname)
¶This function returns a value of 1
if the run-time CPU is of type
cpuname and returns 0
otherwise. The following CPU names can be
detected:
IBM POWER9 Server CPU.
IBM POWER8 Server CPU.
IBM POWER7 Server CPU.
IBM POWER6 Server CPU (RAW mode).
IBM POWER6 Server CPU (Architected mode).
IBM POWER5+ Server CPU.
IBM POWER5 Server CPU.
IBM 970 Server CPU (ie, Apple G5).
IBM POWER4 Server CPU.
IBM A2 64-bit Embedded CPU
IBM PowerPC 476FP 32-bit Embedded CPU.
IBM PowerPC 464 32-bit Embedded CPU.
PowerPC 440 32-bit Embedded CPU.
PowerPC 405 32-bit Embedded CPU.
IBM PowerPC Cell Broadband Engine Architecture CPU.
Here is an example:
if (__builtin_cpu_is ("power8")) { do_power8 (); // POWER8 specific implementation. } else { do_generic (); // Generic implementation. }
int
__builtin_cpu_supports (const char *feature)
¶This function returns a value of 1
if the run-time CPU supports the HWCAP
feature feature and returns 0
otherwise. The following features can be
detected:
4xx CPU has a Multiply Accumulator.
CPU has a SIMD/Vector Unit.
CPU supports ISA 2.05 (eg, POWER6)
CPU supports ISA 2.06 (eg, POWER7)
CPU supports ISA 2.07 (eg, POWER8)
CPU supports ISA 3.00 (eg, POWER9)
CPU supports the set of compatible performance monitoring events.
CPU supports the Embedded ISA category.
CPU has a CELL broadband engine.
CPU has a decimal floating point unit.
CPU supports the data stream control register.
CPU supports event base branching.
CPU has a SPE double precision floating point unit.
CPU has a SPE single precision floating point unit.
CPU has a floating point unit.
CPU has hardware transaction memory instructions.
Kernel aborts hardware transactions when a syscall is made.
CPU supports icache snooping capabilities.
CPU supports 128-bit IEEE binary floating point instructions.
CPU supports the integer select instruction.
CPU has a memory management unit.
CPU does not have a timebase (eg, 601 and 403gx).
CPU supports the PA Semi 6T CORE ISA.
CPU supports ISA 2.00 (eg, POWER4)
CPU supports ISA 2.02 (eg, POWER5)
CPU supports ISA 2.03 (eg, POWER5+)
CPU supports ISA 2.05 (eg, POWER6) extended opcodes mffgpr and mftgpr.
CPU supports 32-bit mode execution.
CPU supports the old POWER ISA (eg, 601)
CPU supports 64-bit mode execution.
CPU supports a little-endian mode that uses address swizzling.
CPU support simultaneous multi-threading.
CPU has a signal processing extension unit.
CPU supports the target address register.
CPU supports true little-endian mode.
CPU has unified I/D cache.
CPU supports the vector cryptography instructions.
CPU supports the vector-scalar extension.
Here is an example:
if (__builtin_cpu_supports ("fpu")) { asm("fadd %0,%1,%2" : "=d"(dst) : "d"(src1), "d"(src2)); } else { dst = __fadd (src1, src2); // Software FP addition function. }
These built-in functions are available for the PowerPC family of processors:
float __builtin_recipdivf (float, float); float __builtin_rsqrtf (float); double __builtin_recipdiv (double, double); double __builtin_rsqrt (double); uint64_t __builtin_ppc_get_timebase (); unsigned long __builtin_ppc_mftb (); double __builtin_unpack_longdouble (long double, int); long double __builtin_pack_longdouble (double, double);
The vec_rsqrt
, __builtin_rsqrt
, and
__builtin_rsqrtf
functions generate multiple instructions to
implement the reciprocal sqrt functionality using reciprocal sqrt
estimate instructions.
The __builtin_recipdiv
, and __builtin_recipdivf
functions generate multiple instructions to implement division using
the reciprocal estimate instructions.
The __builtin_ppc_get_timebase
and __builtin_ppc_mftb
functions generate instructions to read the Time Base Register. The
__builtin_ppc_get_timebase
function may generate multiple
instructions and always returns the 64 bits of the Time Base Register.
The __builtin_ppc_mftb
function always generates one instruction and
returns the Time Base Register value as an unsigned long, throwing away
the most significant word on 32-bit environments.
Additional built-in functions are available for the 64-bit PowerPC
family of processors, for efficient use of 128-bit floating point
(__float128
) values.
The following floating-point built-in functions are available with
-mfloat128
and Altivec support. All of them implement the
function that is part of the name.
__float128 __builtin_fabsq (__float128) __float128 __builtin_copysignq (__float128, __float128)
The following built-in functions are available with -mfloat128
and Altivec support.
__float128 __builtin_infq (void)
Similar to __builtin_inf
, except the return type is __float128
.
__float128 __builtin_huge_valq (void)
Similar to __builtin_huge_val
, except the return type is __float128
.
__float128 __builtin_nanq (void)
Similar to __builtin_nan
, except the return type is __float128
.
__float128 __builtin_nansq (void)
Similar to __builtin_nans
, except the return type is __float128
.
The following built-in functions are available for the PowerPC family of processors, starting with ISA 2.06 or later (-mcpu=power7 or -mpopcntd):
long __builtin_bpermd (long, long); int __builtin_divwe (int, int); int __builtin_divweo (int, int); unsigned int __builtin_divweu (unsigned int, unsigned int); unsigned int __builtin_divweuo (unsigned int, unsigned int); long __builtin_divde (long, long); long __builtin_divdeo (long, long); unsigned long __builtin_divdeu (unsigned long, unsigned long); unsigned long __builtin_divdeuo (unsigned long, unsigned long); unsigned int cdtbcd (unsigned int); unsigned int cbcdtd (unsigned int); unsigned int addg6s (unsigned int, unsigned int);
The __builtin_divde
, __builtin_divdeo
,
__builtin_divdeu
, __builtin_divdeou
functions require a
64-bit environment support ISA 2.06 or later.
The following built-in functions are available for the PowerPC family of processors, starting with ISA 3.0 or later (-mcpu=power9):
long long __builtin_darn (void); long long __builtin_darn_raw (void); int __builtin_darn_32 (void); int __builtin_dfp_dtstsfi_lt (unsigned int comparison, _Decimal64 value); int __builtin_dfp_dtstsfi_lt (unsigned int comparison, _Decimal128 value); int __builtin_dfp_dtstsfi_lt_dd (unsigned int comparison, _Decimal64 value); int __builtin_dfp_dtstsfi_lt_td (unsigned int comparison, _Decimal128 value); int __builtin_dfp_dtstsfi_gt (unsigned int comparison, _Decimal64 value); int __builtin_dfp_dtstsfi_gt (unsigned int comparison, _Decimal128 value); int __builtin_dfp_dtstsfi_gt_dd (unsigned int comparison, _Decimal64 value); int __builtin_dfp_dtstsfi_gt_td (unsigned int comparison, _Decimal128 value); int __builtin_dfp_dtstsfi_eq (unsigned int comparison, _Decimal64 value); int __builtin_dfp_dtstsfi_eq (unsigned int comparison, _Decimal128 value); int __builtin_dfp_dtstsfi_eq_dd (unsigned int comparison, _Decimal64 value); int __builtin_dfp_dtstsfi_eq_td (unsigned int comparison, _Decimal128 value); int __builtin_dfp_dtstsfi_ov (unsigned int comparison, _Decimal64 value); int __builtin_dfp_dtstsfi_ov (unsigned int comparison, _Decimal128 value); int __builtin_dfp_dtstsfi_ov_dd (unsigned int comparison, _Decimal64 value); int __builtin_dfp_dtstsfi_ov_td (unsigned int comparison, _Decimal128 value);
The __builtin_darn
and __builtin_darn_raw
functions require a
64-bit environment supporting ISA 3.0 or later.
The __builtin_darn
function provides a 64-bit conditioned
random number. The __builtin_darn_raw
function provides a
64-bit raw random number. The __builtin_darn_32
function
provides a 32-bit random number.
The __builtin_dfp_dtstsfi_lt
function returns a non-zero value
if and only if the number of signficant digits of its value
argument
is less than its comparison
argument. The
__builtin_dfp_dtstsfi_lt_dd
and
__builtin_dfp_dtstsfi_lt_td
functions behave similarly, but
require that the type of the value
argument be
__Decimal64
and __Decimal128
respectively.
The __builtin_dfp_dtstsfi_gt
function returns a non-zero value
if and only if the number of signficant digits of its value
argument
is greater than its comparison
argument. The
__builtin_dfp_dtstsfi_gt_dd
and
__builtin_dfp_dtstsfi_gt_td
functions behave similarly, but
require that the type of the value
argument be
__Decimal64
and __Decimal128
respectively.
The __builtin_dfp_dtstsfi_eq
function returns a non-zero value
if and only if the number of signficant digits of its value
argument
equals its comparison
argument. The
__builtin_dfp_dtstsfi_eq_dd
and
__builtin_dfp_dtstsfi_eq_td
functions behave similarly, but
require that the type of the value
argument be
__Decimal64
and __Decimal128
respectively.
The __builtin_dfp_dtstsfi_ov
function returns a non-zero value
if and only if its value
argument has an undefined number of
significant digits, such as when value
is an encoding of NaN
.
The __builtin_dfp_dtstsfi_ov_dd
and
__builtin_dfp_dtstsfi_ov_td
functions behave similarly, but
require that the type of the value
argument be
__Decimal64
and __Decimal128
respectively.
The following built-in functions are available for the PowerPC family of processors when hardware decimal floating point (-mhard-dfp) is available:
_Decimal64 __builtin_dxex (_Decimal64); _Decimal128 __builtin_dxexq (_Decimal128); _Decimal64 __builtin_ddedpd (int, _Decimal64); _Decimal128 __builtin_ddedpdq (int, _Decimal128); _Decimal64 __builtin_denbcd (int, _Decimal64); _Decimal128 __builtin_denbcdq (int, _Decimal128); _Decimal64 __builtin_diex (_Decimal64, _Decimal64); _Decimal128 _builtin_diexq (_Decimal128, _Decimal128); _Decimal64 __builtin_dscli (_Decimal64, int); _Decimal128 __builtin_dscliq (_Decimal128, int); _Decimal64 __builtin_dscri (_Decimal64, int); _Decimal128 __builtin_dscriq (_Decimal128, int); unsigned long long __builtin_unpack_dec128 (_Decimal128, int); _Decimal128 __builtin_pack_dec128 (unsigned long long, unsigned long long);
The following built-in functions are available for the PowerPC family of processors when the Vector Scalar (vsx) instruction set is available:
unsigned long long __builtin_unpack_vector_int128 (vector __int128_t, int); vector __int128_t __builtin_pack_vector_int128 (unsigned long long, unsigned long long);