This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Intrinsic function" – news ·newspapers ·books ·scholar ·JSTOR(December 2009) (Learn how and when to remove this message) |
Incomputer software, incompiler theory, anintrinsic function, also calledbuilt-in function orbuiltin function, is a function (subroutine) available for use in a givenprogramming language whose implementation is handled specially by thecompiler. Typically, it may substitute a sequence of automatically generatedinstructions for the original function call, similar to aninline function.[1] Unlike an inline function, the compiler has an intimate knowledge of an intrinsic function and can thus better integrate and optimize it for a given situation.
Compilers that implement intrinsic functions may enable them only when a program requestsoptimization, otherwise falling back to a default implementation provided by the languageruntime system (environment).
Intrinsic functions are often used to explicitly implementvectorization andparallelization in languages which do not address such constructs. Someapplication programming interfaces (API), for example,AltiVec andOpenMP, use intrinsic functions to declare, respectively, vectorizable andmultiprocessing-aware operations during compiling. The compiler parses the intrinsic functions and converts them into vector math or multiprocessingobject code appropriate for the targetplatform.Some intrinsics are used to provide additional constraints to the optimizer, such as values a variable cannot assume.[2]
Compilers forC andC++, of Microsoft,[3]Intel,[1] and theGNU Compiler Collection (GCC)[4]implement intrinsics that map directly to thex86single instruction, multiple data (SIMD) instructions (MMX,Streaming SIMD Extensions (SSE),SSE2,SSE3,SSSE3,SSE4,AVX,AVX2,AVX512,FMA, ...). Intrinsics allow mapping to standard assembly instructions that are not normally accessible through C/C++; e.g. bit scan and parallel operations on128 bits and256 bits.
Some C and C++ compilers provide non-portable platform-specific intrinsics. Other intrinsics (such asGNU built-ins) are slightly more abstracted, approximating the abilities of several contemporary platforms, with portablefall back implementations on platforms with no appropriate instructions.[5] It is common for C++ libraries, such asglm orSony'svector maths libraries,[6] to achieve portability viaconditional compilation (based on platform specific compiler flags), providing fully portable high-level primitives (e.g., a four-element floating-point vector type) mapped onto the appropriatelow level programming language implementations, while still benefiting from the C++ type system and inlining; hence the advantage over linking to hand-written assembly object files, using the Capplication binary interface (ABI).
The following are examples of signatures of intrinsic functions from Intel's set of intrinsic functions.
uint64_t__rdtsc();// return internal CPU clock counteruint64_t__popcnt64(uint64_tn);// count of bits set in nuint64_t_umul128(uint64_tFactor1,uint64_tFactor2,uint64_t*HighProduct);// 64 bit * 64 bit => 128 bit multiplication__m512_mm512_add_ps(__m512a,__m512b);// calculates a + b for two vectors of 16 floats__m512_mm512_fmadd_ps(__m512a,__m512b,__m512c);// calculates a*b + c for three vectors of 16 floats
Intrinsic function Module forCOBOL was introduced in ANSI INCITS X3.23a-1989 and ISO 1989:1985/Amd 1:1992.
TheHotSpotJava virtual machine's (JVM)just-in-time compiler also has intrinsics for specific Java APIs.[8] Hotspot intrinsics are standard Java APIs which may have one or more optimized implementation on some platforms.
ANSI/ISOPL/I defines nearly 90 builtin functions.[9] These are conventionally grouped as follows:[10]: 337–338
Individual compilers have added additional builtins specific to a machine architecture or operating system.
A builtin function is identified by leaving its name undeclared and allowing it to default, or by declaring itBUILTIN. A user-supplied function of the same name can be substituted by declaring it asENTRY.
Builtin Functions
{{cite book}}: CS1 maint: numeric names: authors list (link)