W3cubDocs

/GCC 7

6.60.21 PowerPC Built-in Functions

The following built-in functions are always available and can be used to check the PowerPC target platform type:

Built-in Function: 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.

Built-in Function: 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.

Built-in Function: 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 __builtin_cpu_is function requires GLIBC 2.23 or newer which exports the hardware capability bits. GCC defines the macro __BUILTIN_CPU_SUPPORTS__ if the __builtin_cpu_supports built-in function is fully supported.

If GCC was configured to use a GLIBC before 2.23, the built-in function __builtin_cpu_is always returns a 0 and the compiler issues a warning.

The following CPU names can be detected:

power9

IBM POWER9 Server CPU.

power8

IBM POWER8 Server CPU.

power7

IBM POWER7 Server CPU.

power6x

IBM POWER6 Server CPU (RAW mode).

power6

IBM POWER6 Server CPU (Architected mode).

power5+

IBM POWER5+ Server CPU.

power5

IBM POWER5 Server CPU.

ppc970

IBM 970 Server CPU (ie, Apple G5).

power4

IBM POWER4 Server CPU.

ppca2

IBM A2 64-bit Embedded CPU

ppc476

IBM PowerPC 476FP 32-bit Embedded CPU.

ppc464

IBM PowerPC 464 32-bit Embedded CPU.

ppc440

PowerPC 440 32-bit Embedded CPU.

ppc405

PowerPC 405 32-bit Embedded CPU.

ppc-cell-be

IBM PowerPC Cell Broadband Engine Architecture CPU.

Here is an example:

#ifdef __BUILTIN_CPU_SUPPORTS__
  if (__builtin_cpu_is ("power8"))
    {
       do_power8 (); // POWER8 specific implementation.
    }
  else
#endif
    {
       do_generic (); // Generic implementation.
    }
Built-in Function: 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 __builtin_cpu_supports function requires GLIBC 2.23 or newer which exports the hardware capability bits. GCC defines the macro __BUILTIN_CPU_SUPPORTS__ if the __builtin_cpu_supports built-in function is fully supported.

If GCC was configured to use a GLIBC before 2.23, the built-in function __builtin_cpu_suports always returns a 0 and the compiler issues a warning.

The following features can be detected:

4xxmac

4xx CPU has a Multiply Accumulator.

altivec

CPU has a SIMD/Vector Unit.

arch_2_05

CPU supports ISA 2.05 (eg, POWER6)

arch_2_06

CPU supports ISA 2.06 (eg, POWER7)

arch_2_07

CPU supports ISA 2.07 (eg, POWER8)

arch_3_00

CPU supports ISA 3.0 (eg, POWER9)

archpmu

CPU supports the set of compatible performance monitoring events.

booke

CPU supports the Embedded ISA category.

cellbe

CPU has a CELL broadband engine.

dfp

CPU has a decimal floating point unit.

dscr

CPU supports the data stream control register.

ebb

CPU supports event base branching.

efpdouble

CPU has a SPE double precision floating point unit.

efpsingle

CPU has a SPE single precision floating point unit.

fpu

CPU has a floating point unit.

htm

CPU has hardware transaction memory instructions.

htm-nosc

Kernel aborts hardware transactions when a syscall is made.

ic_snoop

CPU supports icache snooping capabilities.

ieee128

CPU supports 128-bit IEEE binary floating point instructions.

isel

CPU supports the integer select instruction.

mmu

CPU has a memory management unit.

notb

CPU does not have a timebase (eg, 601 and 403gx).

pa6t

CPU supports the PA Semi 6T CORE ISA.

power4

CPU supports ISA 2.00 (eg, POWER4)

power5

CPU supports ISA 2.02 (eg, POWER5)

power5+

CPU supports ISA 2.03 (eg, POWER5+)

power6x

CPU supports ISA 2.05 (eg, POWER6) extended opcodes mffgpr and mftgpr.

ppc32

CPU supports 32-bit mode execution.

ppc601

CPU supports the old POWER ISA (eg, 601)

ppc64

CPU supports 64-bit mode execution.

ppcle

CPU supports a little-endian mode that uses address swizzling.

smt

CPU support simultaneous multi-threading.

spe

CPU has a signal processing extension unit.

tar

CPU supports the target address register.

true_le

CPU supports true little-endian mode.

ucache

CPU has unified I/D cache.

vcrypto

CPU supports the vector cryptography instructions.

vsx

CPU supports the vector-scalar extension.

Here is an example:

#ifdef __BUILTIN_CPU_SUPPORTS__
  if (__builtin_cpu_supports ("fpu"))
    {
       asm("fadd %0,%1,%2" : "=d"(dst) : "d"(src1), "d"(src2));
    }
  else
#endif
    {
       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);

unsigned int scalar_extract_exp (double source);
unsigned long long int scalar_extract_sig (double source);

double
scalar_insert_exp (unsigned long long int significand, unsigned long long int exponent);
double
scalar_insert_exp (double significand, unsigned long long int exponent);

int scalar_cmp_exp_gt (double arg1, double arg2);
int scalar_cmp_exp_lt (double arg1, double arg2);
int scalar_cmp_exp_eq (double arg1, double arg2);
int scalar_cmp_exp_unordered (double arg1, double arg2);

bool scalar_test_data_class (float source, const int condition);
bool scalar_test_data_class (double source, const int condition);

bool scalar_test_neg (float source);
bool scalar_test_neg (double source);

int __builtin_byte_in_set (unsigned char u, unsigned long long set);
int __builtin_byte_in_range (unsigned char u, unsigned int range);
int __builtin_byte_in_either_range (unsigned char u, unsigned int ranges);

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 scalar_extract_exp and scalar_extract_sig functions require a 64-bit environment supporting ISA 3.0 or later. The scalar_extract_exp and scalar_extract_sig built-in functions return the significand and the biased exponent value respectively of their source arguments. Within the result returned by scalar_extract_sig, the 0x10000000000000 bit is set if the function’s source argument is in normalized form. Otherwise, this bit is set to 0. Note that the sign of the significand is not represented in the result returned from the scalar_extract_sig function. Use the scalar_test_neg function to test the sign of its double argument.

The scalar_insert_exp function requires a 64-bit environment supporting ISA 3.0 or later. The scalar_insert_exp built-in function returns a double-precision floating point value that is constructed by assembling the values of its significand and exponent arguments. The sign of the result is copied from the most significant bit of the significand argument. The significand and exponent components of the result are composed of the least significant 11 bits of the exponent argument and the least significant 52 bits of the significand argument.

The scalar_cmp_exp_gt, scalar_cmp_exp_lt, scalar_cmp_exp_eq, and scalar_cmp_exp_unordered built-in functions return a non-zero value if arg1 is greater than, less than, equal to, or not comparable to arg2 respectively. The arguments are not comparable if one or the other equals NaN (not a number).

The scalar_test_data_class built-in function returns 1 if any of the condition tests enabled by the value of the condition variable are true, and 0 otherwise. The condition argument must be a compile-time constant integer with value not exceeding 127. The condition argument is encoded as a bitmask with each bit enabling the testing of a different condition, as characterized by the following:

0x40    Test for NaN
0x20    Test for +Infinity
0x10    Test for -Infinity
0x08    Test for +Zero
0x04    Test for -Zero
0x02    Test for +Denormal
0x01    Test for -Denormal

The scalar_test_neg built-in function returns 1 if its source argument holds a negative value, 0 otherwise.

The __builtin_byte_in_set function requires a 64-bit environment supporting ISA 3.0 or later. This function returns a non-zero value if and only if its u argument exactly equals one of the eight bytes contained within its 64-bit set argument.

The __builtin_byte_in_range and __builtin_byte_in_either_range require an environment supporting ISA 3.0 or later. For these two functions, the range argument is encoded as 4 bytes, organized as hi_1:lo_1:hi_2:lo_2. The __builtin_byte_in_range function returns a non-zero value if and only if its u argument is within the range bounded between lo_2 and hi_2 inclusive. The __builtin_byte_in_either_range function returns non-zero if and only if its u argument is within either the range bounded between lo_1 and hi_1 inclusive or the range bounded between lo_2 and hi_2 inclusive.

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 also available for the PowerPC family of processors, starting with ISA 3.0 or later (-mcpu=power9). These string functions are described separately in order to group the descriptions closer to the function prototypes:

int vec_all_nez (vector signed char, vector signed char);
int vec_all_nez (vector unsigned char, vector unsigned char);
int vec_all_nez (vector signed short, vector signed short);
int vec_all_nez (vector unsigned short, vector unsigned short);
int vec_all_nez (vector signed int, vector signed int);
int vec_all_nez (vector unsigned int, vector unsigned int);

int vec_any_eqz (vector signed char, vector signed char);
int vec_any_eqz (vector unsigned char, vector unsigned char);
int vec_any_eqz (vector signed short, vector signed short);
int vec_any_eqz (vector unsigned short, vector unsigned short);
int vec_any_eqz (vector signed int, vector signed int);
int vec_any_eqz (vector unsigned int, vector unsigned int);

vector bool char vec_cmpnez (vector signed char arg1, vector signed char arg2);
vector bool char vec_cmpnez (vector unsigned char arg1, vector unsigned char arg2);
vector bool short vec_cmpnez (vector signed short arg1, vector signed short arg2);
vector bool short vec_cmpnez (vector unsigned short arg1, vector unsigned short arg2);
vector bool int vec_cmpnez (vector signed int arg1, vector signed int arg2);
vector bool int vec_cmpnez (vector unsigned int, vector unsigned int);

signed int vec_cntlz_lsbb (vector signed char);
signed int vec_cntlz_lsbb (vector unsigned char);

signed int vec_cnttz_lsbb (vector signed char);
signed int vec_cnttz_lsbb (vector unsigned char);

vector signed char vec_xl_len (signed char *addr, size_t len);
vector unsigned char vec_xl_len (unsigned char *addr, size_t len);
vector signed int vec_xl_len (signed int *addr, size_t len);
vector unsigned int vec_xl_len (unsigned int *addr, size_t len);
vector signed __int128 vec_xl_len (signed __int128 *addr, size_t len);
vector unsigned __int128 vec_xl_len (unsigned __int128 *addr, size_t len);
vector signed long long vec_xl_len (signed long long *addr, size_t len);
vector unsigned long long vec_xl_len (unsigned long long *addr, size_t len);
vector signed short vec_xl_len (signed short *addr, size_t len);
vector unsigned short vec_xl_len (unsigned short *addr, size_t len);
vector double vec_xl_len (double *addr, size_t len);
vector float vec_xl_len (float *addr, size_t len);

void vec_xst_len (vector signed char data, signed char *addr, size_t len);
void vec_xst_len (vector unsigned char data, unsigned char *addr, size_t len);
void vec_xst_len (vector signed int data, signed int *addr, size_t len);
void vec_xst_len (vector unsigned int data, unsigned int *addr, size_t len);
void vec_xst_len (vector unsigned __int128 data, unsigned __int128 *addr, size_t len);
void vec_xst_len (vector signed long long data, signed long long *addr, size_t len);
void vec_xst_len (vector unsigned long long data, unsigned long long *addr, size_t len);
void vec_xst_len (vector signed short data, signed short *addr, size_t len);
void vec_xst_len (vector unsigned short data, unsigned short *addr, size_t len);
void vec_xst_len (vector signed __int128 data, signed __int128 *addr, size_t len);
void vec_xst_len (vector double data, double *addr, size_t len);
void vec_xst_len (vector float data, float *addr, size_t len);

signed char vec_xlx (unsigned int index, vector signed char data);
unsigned char vec_xlx (unsigned int index, vector unsigned char data);
signed short vec_xlx (unsigned int index, vector signed short data);
unsigned short vec_xlx (unsigned int index, vector unsigned short data);
signed int vec_xlx (unsigned int index, vector signed int data);
unsigned int vec_xlx (unsigned int index, vector unsigned int data);
float vec_xlx (unsigned int index, vector float data);

signed char vec_xrx (unsigned int index, vector signed char data);
unsigned char vec_xrx (unsigned int index, vector unsigned char data);
signed short vec_xrx (unsigned int index, vector signed short data);
unsigned short vec_xrx (unsigned int index, vector unsigned short data);
signed int vec_xrx (unsigned int index, vector signed int data);
unsigned int vec_xrx (unsigned int index, vector unsigned int data);
float vec_xrx (unsigned int index, vector float data);

The vec_all_nez, vec_any_eqz, and vec_cmpnez perform pairwise comparisons between the elements at the same positions within their two vector arguments. The vec_all_nez function returns a non-zero value if and only if all pairwise comparisons are not equal and no element of either vector argument contains a zero. The vec_any_eqz function returns a non-zero value if and only if at least one pairwise comparison is equal or if at least one element of either vector argument contains a zero. The vec_cmpnez function returns a vector of the same type as its two arguments, within which each element consists of all ones to denote that either the corresponding elements of the incoming arguments are not equal or that at least one of the corresponding elements contains zero. Otherwise, the element of the returned vector contains all zeros.

The vec_cntlz_lsbb function returns the count of the number of consecutive leading byte elements (starting from position 0 within the supplied vector argument) for which the least-significant bit equals zero. The vec_cnttz_lsbb function returns the count of the number of consecutive trailing byte elements (starting from position 15 and counting backwards within the supplied vector argument) for which the least-significant bit equals zero.

The vec_xl_len and vec_xst_len functions require a 64-bit environment supporting ISA 3.0 or later. The vec_xl_len function loads a variable length vector from memory. The vec_xst_len function stores a variable length vector to memory. With both the vec_xl_len and vec_xst_len functions, the addr argument represents the memory address to or from which data will be transferred, and the len argument represents the number of bytes to be transferred, as computed by the C expression min((len & 0xff), 16). If this expression’s value is not a multiple of the vector element’s size, the behavior of this function is undefined. In the case that the underlying computer is configured to run in big-endian mode, the data transfer moves bytes 0 to (len - 1) of the corresponding vector. In little-endian mode, the data transfer moves bytes (16 - len) to 15 of the corresponding vector. For the load function, any bytes of the result vector that are not loaded from memory are set to zero. The value of the addr argument need not be aligned on a multiple of the vector’s element size.

The vec_xlx and vec_xrx functions extract the single element selected by the index argument from the vector represented by the data argument. The index argument always specifies a byte offset, regardless of the size of the vector element. With vec_xlx, index is the offset of the first byte of the element to be extracted. With vec_xrx, index represents the last byte of the element to be extracted, measured from the right end of the vector. In other words, the last byte of the element to be extracted is found at position (15 - index). There is no requirement that index be a multiple of the vector element size. However, if the size of the vector element added to index is greater than 15, the content of the returned value is undefined.

The following built-in functions are available for the PowerPC family of processors when hardware decimal floating point (-mhard-dfp) is available:

long long __builtin_dxex (_Decimal64);
long long __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 (long long, _Decimal64);
_Decimal128 _builtin_diexq (long long, _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);

Next: , Previous: , Up: Target Builtins [Contents][Index]

© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
https://gcc.gnu.org/onlinedocs/gcc-7.3.0/gcc/PowerPC-Built_002din-Functions.html