what is intrinsics

来源:互联网 发布:网络综艺节目的特点 编辑:程序博客网 时间:2024/06/17 16:56

 

Intrinsic function

From Wikipedia, the free encyclopedia
Jump to: navigation, search
This article needs additional citations for verification.Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. (December 2009)

In compiler theory, an intrinsic function is a function available for use in a givenprogramming language whose implementation is handled specially by the compiler. Typically, it substitutes a sequence of automatically generated instructions for the original function call, similar to aninline function. Unlike an inline function though, the compiler has an intimate knowledge of the intrinsic function and can therefore better integrate it and optimize it for the situation. This is also called builtin function in many languages.

Compilers that implement intrinsic functions generally enable them only when the user has requestedoptimization, falling back to a default implementation provided by the language runtime environment otherwise.

Intrinsic functions are often used to explicitly implement vectorization and parallelization in languages which do not address such constructs. Altivec and OpenMP are examples ofAPIs which use intrinsic functions to declare, respectively, vectorizable andmultiprocessor-aware operations during compilation. The compiler parses the intrinsic functions and converts them into vector math or multiprocessingobject code appropriate for the target platform.

Microsoft[1] and Intel's C/C++ compilers as well asGCC[2] implement intrinsics that map directly to the x86SIMD instructions (MMX,SSE, SSE2, SSE3, SSSE3, SSE4). In the latest version of the Microsoft Visual Studio (VS2010), the Visual C++ compiler does not support inline assembler for X86-64[3] (neither VS2008[4] nor VS2005[5]). To compensate for the lack of inline assembly, new intrinsics have been added that map to standard assembly instructions that are not normally accessible through C/C++ (e.g.: bit scan).

[edit]References

  1. ^MSDN(VS2010). "Compiler Intrinsics". Microsoft. http://msdn.Microsoft.com/en-us/library/26td21ds. Retrieved 2012-06-20.
  2. ^GCC documentation. "Built-in Functions Specific to Particular Target Machines". Free Software Foundation. http://gcc.gnu.org/onlinedocs/gcc/Target-Builtins.html. Retrieved 2012-06-20.
  3. ^MSDN(VS2010). "Intrinsics and Inline Assembly". Microsoft. http://msdn.microsoft.com/en-us/library/wbk4z78b.aspx?ppud=4. Retrieved 2010-04-16.
  4. ^MSDN(VS2008). "Intrinsics and Inline Assembly". Microsoft. http://msdn.microsoft.com/en-us/library/wbk4z78b(v=VS.90).aspx. Retrieved 2011-09-28.
  5. ^MSDN(VS2005). "Intrinsics and Inline Assembly". Microsoft. http://msdn.microsoft.com/en-us/library/wbk4z78b(v=VS.80).aspx. Retrieved 2011-09-28.

Compiler Intrinsics

            Visual Studio 2012               
                        Other Versions                              
          
  • Visual Studio 2010          
  • Visual Studio 2008          
  • Visual Studio 2005          
  • Visual Studio .NET 2003          
            1 out of 5 rated this helpful- Rate this topic                        

Most functions are contained in libraries, but some functions are built in (that is, intrinsic) to the compiler. These are referred to as intrinsic functions or intrinsics.

Remarks              

            

If a function is an intrinsic, the code for that function is usually inserted inline, avoiding the overhead of a function call and allowing highly efficient machine instructions to be emitted for that function. An intrinsic is often faster than the equivalent inline assembly, because the optimizer has a built-in knowledge of how many intrinsics behave, so some optimizations can be available that are not available when inline assembly is used. Also, the optimizer can expand the intrinsic differently, align buffers differently, or make other adjustments depending on the context and arguments of the call.

The use of intrinsics affects the portability of code, because intrinsics that are available in Visual C++ might not be available if the code is compiled with other compilers and some intrinsics that might be available for some target architectures are not available for all architectures. However, intrinsics are usually more portable than inline assembly. The intrinsics are required on 64-bit architectures where inline assembly is not supported.

Some intrinsics, such as __assume and __ReadWriteBarrier, provide information to the compiler, which affects the behavior of the optimizer.

Some intrinsics are available only as intrinsics, and some are available both in function and intrinsic implementations. You can instruct the compiler to use the intrinsic implementation in one of two ways, depending on whether you want to enable only specific functions or you want to enable all intrinsics. The first way is to use #pragma intrinsic(intrinsic-function-name-list). The pragma can be used to specify a single intrinsic or multiple intrinsics separated by commas. The second is to use the/Oi (Generate Intrinsic Functions) compiler option, which makes all intrinsics on a given platform available. Under/Oi, use #pragma function(intrinsic-function-name-list) to force a function call to be used instead of an intrinsic. If the documentation for a specific intrinsic notes that the routine is only available as an intrinsic, then the intrinsic implementation is used regardless of whether/Oi or #pragma intrinsic is specified. In all cases,/Oi or #pragma intrinsic allows, but does not force, the optimizer to use the intrinsic. The optimizer can still call the function.

Some standard C/C++ library functions are available in intrinsic implementations on some architectures. When calling a CRT function, the intrinsic implementation is used if/Oi is specified on the command line.

A header file, Intrin.h, is available that declares prototypes for the intrinsic functions. Additionally, certain Windows headers declare functions that map onto a compiler intrinsic.

The following sections list all intrinsics that are available on various architectures. For more information on how the intrinsics work on your particular target processor, refer to the manufacturer's reference documentation.

  • ARM Intrinsics                

  • x86 Intrinsics                

  • x64 (amd64) Intrinsics                

See Also              

            

Reference

C++ Keywords                          

Other Resources

ARM Assembler Reference                          
Microsoft Macro Assembler Reference                          
C Run-Time Library Reference

 

原创粉丝点击