Using runtime check library

The runtime check library provides a library routine that identifies the target hardware model to the application during its execution. This runtime check library also provides 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++ Language Reference.

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 __builtin_cpu_is and __builtin_cpu_supports 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:
  • "5" through "12"
  • "dfp"
  • "dfpzoned"
  • "etf3"
  • "htm"
  • "interlocked"
  • "loadstoreoncond"
  • "loadstoreoncond2"
  • "longdisplacemnt"
  • "miscinsnfacility2"
  • "popcount"
  • "prefetch"
  • "storeclockfast"
  • "vector128"
  • "vectorenhfacility1"
  • "vectorpacked"

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 that are associated with "5", "6", "7", "8", "9", "10", "11", and "12", which correspond to the ARCH levels.


The following example shows the usage of the runtime check routine and built-in functions:

int main() {
    if (__builtin_cpu_supports("dfp"))
    #pragma arch_section(7)
    // ....
    return SUCCESS;