Intrinsic function
This article needs additional citations for verification. (December 2009) |
In
Compilers that implement intrinsic functions may enable them only when a program requests optimization, otherwise falling back to a default implementation provided by the language runtime system (environment).
Vectorization and parallelization
Intrinsic functions are often used to explicitly implement
By programming language
C and C++
Compilers for C and C++, of Microsoft,[3] Intel,[1] and the GNU Compiler Collection (GCC)[4] implement intrinsics that map directly to the
To compensate for this, new intrinsics have been added that map to standard assembly instructions that are not normally accessible through C/C++, e.g., bit scan.Some C and C++ compilers provide non-portable platform-specific intrinsics. Other intrinsics (such as
Examples
uint64_t __rdtsc (); // return internal CPU clock counter
uint64_t __popcnt64 (uint64_t n); // count of bits set in n
uint64_t _umul128 (uint64_t Factor1, uint64_t Factor2, uint64_t* HighProduct); // 64 bit * 64 bit => 128 bit multiplication
__m512 _mm512_add_ps (__m512 a, __m512 b); // calculates a + b for two vectors of 16 floats
__m512 _mm512_fmadd_ps(__m512 a, __m512 b, __m512 c); // calculates a*b + c for three vectors of 16 floats
Java
The HotSpot Java virtual machine's (JVM) just-in-time compiler also has intrinsics for specific Java APIs.[12] Hotspot intrinsics are standard Java APIs which may have one or more optimized implementation on some platforms.
PL/I
ANSI/ISO PL/I defines nearly 90 builtin functions.[13] These are conventionally grouped as follows:[14]: 337–338
- String-handling builtin functions such as INDEX, LENGTH
- Arithmetic builtin functions such as ABS, CEIL, ROUND
- Mathematical builtin functions like SIN, COS, LOG, ERF
- Array-handling builtin functions, for example ANY, ALL, PROD
- Condition-handling builtin functions like ONCODE, ONFILE
- Storage Control builtin functions, for example ADDR, POINTER
- Input-Output builtins: LINENO
- Miscellaneous builtin functions like DATE and TIME
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 it BUILTIN
. A user-supplied function of the same name can be substituted by declaring it as ENTRY
.
References
- ^ a b "Intel® C++ Compiler 19.1 Developer Guide and Reference". Intel® C++ Compiler Documentation. 16 December 2019. Retrieved 2020-01-17.
- ^ The Clang Team (2020). "Clang Language Extensions". Clang 11 documentation. Retrieved 2020-01-17.
Builtin Functions
- ^ MSDN. "Compiler Intrinsics". Microsoft. Retrieved 2012-06-20.
- ^ GCC documentation. "Built-in Functions Specific to Particular Target Machines". Free Software Foundation. Retrieved 2012-06-20.
- ^ MSDN. "Intrinsics and Inline Assembly". Microsoft. Archived from the original on 2018-01-02. Retrieved 2010-04-16.
- ^ MSDN. "Intrinsics and Inline Assembly". Microsoft. Retrieved 2011-09-28.
- ^ MSDN. "Intrinsics and Inline Assembly". Microsoft. Retrieved 2011-09-28.
- ^ MSDN. "Intrinsics and Inline Assembly". Microsoft. Retrieved 2011-09-28.
- ^ "Vector Extensions". Using the GNU Compiler Collection (GCC). Retrieved 2020-01-16.
- ^ "Sony open sources Vector Math and SIMD math libraries (Cell PPU/SPU/other platforms)". Beyond3D Forum. Retrieved 2020-01-17.
- ^ Intel Intrinsics
- ^ Mok, Kris (25 February 2013). "Intrinsic Methods in HotSpot VM". Slideshare. Retrieved 2014-12-20.
- ^ ANSI X3 Committee (1976). American National Standard programming language PL/I.
{{cite book}}
: CS1 maint: numeric names: authors list (link) - ^ IBM Corporation (1995). IBM PL/I for MVS & VM Language Reference.
External links
- Intel Intrinsics Guide
- Using milicode routines, IBM AIX 6.1 documentation