#pragma arch_section (IBM extension)

Category

Object code control

Purpose

Overrides the architecture of a statement in the source file. This pragma directive enables your program to leverage specific hardware features like using newer and faster instructions through built-ins or compiler generated instructions based on the architecture sections within the source file. You do not need to maintain code customized for a specific hardware model in separate source files. This pragma directive reduces the overhead of the call to an external routine and permits code for different machine architectures to coexist in one source file.

Syntax

Read syntax diagramSkip visual syntax diagram#pragmaarch_section ( architecture level )statement

Defaults

Not applicable.

Parameters

architecture level
Specifies the hardware architecture level for the code section that follows the directive. Valid architecture levels are 5 and above, which are described under the ARCHITECTURE option in z/OS XL C/C++ User's Guide.
statement
A single statement or a compound statement that is enclosed by curly braces.

Usage

Upon encountering the #pragma arch_section directive in the source, the compiler replaces the architecture level specified by compiler option ARCH or a parent scope #pragma options(architecture(n)) until the end of the statement.

The #pragma arch_section directive can be nested. When nesting, the outer sections should be lower than the inner sections, as the older hardware features are a subset of the newer ones.

The TUNE compiler option should be equal or greater than the highest architecture level specified in any #pragma arch_section directive.

Options that enable language extensions associated with a hardware feature should be specified on compiler command line invocation. For example, DFP to enable _Decimal{32, 64, 128} type, and VECTOR to enable the vector types.

Specifying the following options on the compiler command line invocation does not enable the hardware features associated with them for the statements following the #pragma arch_section directive. These options and their associated hardware features are as follows:
  • RTCHECK for #pragma arch_section(8) or higher
  • HGPR for #pragma arch_section(5) or higher
  • FLOAT(HEX,MAF),OPTIMIZE for #pragma arch_section(9) or higher

When using #pragma arch_section in the source, check the hardware model to ensure that the specified functionality is available at execution time. You can use one of the compiler supported built-ins functions, which are documented in z/OS XL C/C++ Programming Guide.

Examples

The following example shows that architecture levels must be specified in an increasing order. Suppose that you have the following program with name nest.c:
#include <builtins.h>

extern unsigned int c, a, b, d;
int countzero();

int main(void){
  unsigned long zero=0ul;
  __builtin_cpu_init();
  if (__builtin_cpu_supports("popcount"))
    #pragma arch_section(11)
    {
      c = a + b;
    #pragma arch_section(9)
      d = __popcnt(zero);
    }
  return 55;
}
If you compile this program with the following command:
xlc -c -qlanglvl=extended nest.c
The following warning message will be issued:
The value "9" specified on pragma "arch_section" is lower than the effective 
architecture value "11". The pragma is ignored.
The following example shows that you cannot use decimal floating-point in sections of the source when effective architecture level is lower than 7. Suppose that you have the following program with name dfp.c:
#include <stdio.h>
#include <builtins.h>

_Decimal64 dec_n=-1.0;

int main(){
  __builtin_cpu_init();
  if(__builtin_cpu_supports("dfp"))
    #pragma arch_section(7)
    {
       dec_n=-6.4;
       dec_n = __d64_abs(dec_n);
       printf("%f\n", dec_n);
    }
    return 55;
}
If you compile this program with the following command:
xlC -c dfp.c -qphsinfo -qarch=5 -qDFP
The following error message will be issued:
The use of decimal floating-point is invalid for architecture level "5".

Related information