Developer Guide and Reference

Contents

Processor Targeting

The manual processor dispatch feature allows you to target processors manually. There are several ways to control processor dispatching:
  • Use the
    cpu_specific
    and
    cpu_dispatch
    keywords—attributes in Linux* or __declspecs in Windows*—to write one or more versions of a function that executes only on specified types of Intel® processors as well as a generic version that executes on other Intel or non-Intel processors. The Intel processor type is detected at run-time, and the corresponding function version is executed. This feature is available only for Intel processors based on IA-32 or Intel® 64 architecture. It is not available for non-Intel processors. Applications built using the manual processor dispatch feature may be more highly optimized for Intel processors than for non-Intel processors.
    For more information see below.
  • Use the
    optimization_parameter
    pragma.
    For more information see below.
  • On Linux*, in addition to the Intel-defined attributes
    cpu_specific
    and
    cpu_dispatch
    , C++ compilations with GNU Compiler Collection (GCC*) compatibility 4.8 or higher support creation of multiple function versions using the
    target
    attribute.
    For more information see the GCC documentation on "Function Multiversioning".

Using
cpu_dispatch
for Manual Processor Dispatch Programming

Use the
__declspec(cpu_dispatch(cpuid, cpuid,...))
syntax in your code to provide a list of targeted processors along with an empty function body/function stub. Use the
__declspec(cpu_specific(cpuid))
in your code to declare each function version targeted at particular type[s] of processors.
For a list of the values for
cpuid
, see the list on cpu_dispatch, cpu_specific.
If no other matching Intel processor type is detected, the
generic
version of the function is executed. If you want the program to execute on non-Intel processors, a
generic
function version must be provided. You can control the degree of optimization of the
generic
function version and the processor features that it assumes.
The
cpuid
attributes are not case sensitive. The body of a function declared with
__declspec(cpu_dispatch)
must be empty, and is referred to as a stub (an empty-bodied function).
The following example illustrates how the
cpu_dispatch
and
cpu_specific
keywords can be used to create function versions for the 2nd generation Intel® Core™ processor family with support of Intel® Adanced Vector Extensions (Intel® AVX), for the Intel® Core™ processor family, for the Intel® Core™2 Duo processor family, and for other Intel and compatible, non-Intel processors. Each processor-specific function body might contain processor-specific intrinsic functions, or it might be placed in a separate source file and compiled with a processor-specific compiler option.
Example