Skip to content

Latest commit

 

History

History
131 lines (109 loc) · 6.56 KB

intrinsic.md

File metadata and controls

131 lines (109 loc) · 6.56 KB
title description ms.date f1_keywords helpviewer_keywords ms.assetid
intrinsic pragma
The MSVC intrinsic pragma is used to specify the supported intrinsic functions to use as intrinsics.
07/08/2020
intrinsic_CPP
vc-pragma.intrinsic
intrinsic pragma
pragmas, intrinsic
25c86ac7-ef40-47b7-a2c0-fada9c5dc3c5

intrinsic pragma

Specifies that calls to functions specified in the pragma's argument list are intrinsic.

Syntax

#pragma intrinsic( function1 [, function2 ... ] )

Remarks

The intrinsic pragma tells the compiler that a function has known behavior. The compiler may call the function and not replace the function call with inline instructions, if it will result in better performance.

The library functions with intrinsic forms are listed below. Once an intrinsic pragma is seen, it takes effect at the first function definition containing a specified intrinsic function. The effect continues to the end of the source file or to the appearance of a function pragma specifying the same intrinsic function. The intrinsic pragma can be used only outside of a function definition, at the global level.

The following functions have intrinsic forms, and the intrinsic forms are used when you specify /Oi:

:::row::: :::column span=""::: abs
_disable
_enable
fabs
_inp
_inpw
:::column-end::: :::column span=""::: labs
_lrotl
_lrotr
memcmp
memcpy
:::column-end::: :::column span=""::: memset
_outp
_outpw
_rotl
_rotr
:::column-end::: :::column span=""::: strcat
strcmp
strcpy
strlen
_strset
:::column-end::: :::row-end:::

Programs that use intrinsic functions are faster because they don't have the overhead of function calls. However, they may be larger because of the additional code generated.

x86-specific example

The _disable and _enable intrinsics generate kernel-mode instructions to disable or enable interrupts, and could be useful in kernel-mode drivers.

Compile the following code from the command line with cl -c -FAs sample.c and look at sample.asm to see that they turn into x86 instructions CLI and STI:

// pragma_directive_intrinsic.cpp
// processor: x86
#include <dos.h>   // definitions for _disable, _enable
#pragma intrinsic(_disable)
#pragma intrinsic(_enable)
void f1(void) {
   _disable();
   // do some work here that should not be interrupted
   _enable();
}
int main() {
}

Intrinsic floating-point functions

These floating-point functions don't have true intrinsic forms. Instead, they have versions that pass arguments directly to the floating-point chip, rather than pushing them on the stack:

:::row::: :::column span=""::: acos
asin
:::column-end::: :::column span=""::: cosh
fmod
:::column-end::: :::column span=""::: pow
sinh
:::column-end::: :::column span=""::: tanh
:::column-end::: :::row-end:::

These floating-point functions have true intrinsic forms when you specify /Oi and /fp:fast (or any option that includes /Oi: /Ox, /O1, and /O2):

:::row::: :::column span=""::: atan
atan2
cos
:::column-end::: :::column span=""::: exp
log
:::column-end::: :::column span=""::: log10
sin
:::column-end::: :::column span=""::: sqrt
tan
:::column-end::: :::row-end:::

You can use /fp:strict or /Za to override generation of true intrinsic floating-point options. In this case, the functions are generated as library routines that pass arguments directly to the floating-point chip instead of pushing them onto the program stack.

See #pragma function for information and an example on how to enable and disable intrinsics for a block of source text.

See also

Pragma directives and the __pragma keyword
Compiler intrinsics