想必很多学C++的都没听说过内在函数,我也是初次听见。什么是内在函数?英文是Intrinsic Function。这是一种编译器特殊函数,它的行为类似与C++的内联函数,但是由于它是编译器提供的,所以编译器对其更加了解更利于优化。比如说memcpy等就是内在函数。如果编译器有选择/Optimization,那么编译器在生成代码的时候将直接插入运行代码而不是调用该函数,这和内联函数差不多,但是如上所说,由于编译器对其的了解,这个优化会更好。
在vc++中,AbnormalTermination也是一个内在函数。
下面是维基百科的一些介绍:
This article is about compiler intrinsic functions. For X toolkit, see Intrinsics.
In compiler theory, an intrinsic function is a function available in a given 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 an inline 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 requested optimization, 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 of APIs which use intrinsic functions to declare, respectively, vectorizable and multiprocessor-aware operations during compilation. The compiler parses the intrinsic functions and converts them into vector math or multiprocessing object code appropriate for the target platform.
Microsoft and Intel's C/C++ compilers as well as GCC implement intrinsics that map directly to the x86 SIMD instructions (MMX, SSE, SSE2, SSE3, SSSE3, SSE4). In the latest version of the Microsoft compiler (VC2005 as well as VC2008) inline assembly is not available when compiling for 64 bit Windows, therefore intrinsics are necessary. 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).
什么是C++的内在函数
最新推荐文章于 2023-06-29 09:15:37 发布