Using runtime check library

The runtime check library provides a library routine that identifies the target hardware model to the application during its execution. Start of changeThis runtime check library also providesEnd of change built-in functions that are associated with individual architectures to check for safety of the arch_section directive during application execution.

If you have code sections that are customized for specific hardware, you can use these built-in functions to perform a fast and efficient safety check before entering the customized sections. For more information about the arch_section directive, see #pragma arch_section in z/OS XL C/C++ User's Guide.

Check the type of CPU

void __builtin_cpu_init (void);
This built-in function runs the CPU detection code to check the type of CPU. This function must be invoked along with the Start of change__builtin_cpu_is and __builtin_cpu_supportsEnd of change built-in functions to check CPU type and features. This function must be run first so that CPU type is available to __builtin_cpu_is and __builtin_cpu_supports.

Check features the CPU supports

int __builtin_cpu_supports(const char* feature); 
This built-in function returns a positive integer if the runtime CPU supports the specified feature; otherwise, it returns 0. The following features are supported:
  • "1" through "11"
  • "dfp"
  • "dfpzoned"
  • "etf3"
  • "htm"
  • "interlocked"
  • "loadstoreoncond"
  • Start of change"loadstoreoncond2"End of change
  • "longdisplacemnt"
  • "popcount"
  • "prefetch"
  • "storeclockfast"
  • "vector128"

Check the CPU model

int __builtin_cpu_is(const char* cpumodel);

This built-in function returns a positive integer if the runtime CPU is of type cpumodel; otherwise, it returns 0. Supported CPU is one of the models associate with "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", and "11".

Example

The following example shows the usage of the runtime check routine and built-in functions:
int main() {
    __builtin_cpu_init();
    if (__builtin_cpu_supports("dfp"))
    #pragma arch_section(7)
    // ....
    return SUCCESS;
}