fbpx
Wikipedia

Intrinsic function

In computer software, in compiler theory, an intrinsic function (or built-in function) is a function (subroutine) available for use in a given programming language whose implementation is handled specially by the compiler. Typically, it may substitute a sequence of automatically generated instructions for the original function call, similar to an inline 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 generally enable them only when a program requests optimization, otherwise falling back to a default implementation provided by the language runtime system (environment).

Intrinsic functions are often used to explicitly implement vectorization and parallelization in languages which do not address such constructs. Some application programming interfaces (API), for example, AltiVec and OpenMP, use intrinsic functions to declare, respectively, vectorizable and multiprocessing-aware operations during compiling. The compiler parses the intrinsic functions and converts them into vector math or multiprocessing object code appropriate for the target platform. Some intrinsics are used to provide additional constraints to the optimizer, such as values a variable cannot assume.[2]

C and C++ edit

Compilers for C and C++, of Microsoft,[3] Intel,[1] and the GNU Compiler Collection (GCC)[4] implement intrinsics that map directly to the x86 single instruction, multiple data (SIMD) instructions (MMX, Streaming SIMD Extensions (SSE), SSE2, SSE3, SSSE3, SSE4, AVX, AVX2, AVX512, FMA, ...). The Microsoft Visual C++ compiler of Microsoft Visual Studio does not support inline assembly for x86-64.[5][6][7][8] 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 GNU built-ins) are slightly more abstracted, approximating the abilities of several contemporary platforms, with portable fall back implementations on platforms with no appropriate instructions.[9] It is common for C++ libraries, such as glm or Sony's vector maths libraries,[10] to achieve portability via conditional 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 appropriate low 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 C application binary interface (ABI).

Examples edit

 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 
Links
  • Intel Intrinsics

Java edit

The HotSpot Java virtual machine's (JVM) just-in-time compiler also has intrinsics for specific Java APIs.[11] Hotspot intrinsics are standard Java APIs which may have one or more optimized implementation on some platforms.

References edit

  1. ^ a b "Intel® C++ Compiler 19.1 Developer Guide and Reference". Intel® C++ Compiler Documentation. 16 December 2019. Retrieved 2020-01-17.
  2. ^ The Clang Team (2020). "Clang Language Extensions". Clang 11 documentation. Retrieved 2020-01-17. Builtin Functions
  3. ^ MSDN. "Compiler Intrinsics". Microsoft. Retrieved 2012-06-20.
  4. ^ GCC documentation. "Built-in Functions Specific to Particular Target Machines". Free Software Foundation. Retrieved 2012-06-20.
  5. ^ MSDN. . Microsoft. Archived from the original on 2018-01-02. Retrieved 2010-04-16.
  6. ^ MSDN. "Intrinsics and Inline Assembly". Microsoft. Retrieved 2011-09-28.
  7. ^ MSDN. "Intrinsics and Inline Assembly". Microsoft. Retrieved 2011-09-28.
  8. ^ MSDN. "Intrinsics and Inline Assembly". Microsoft. Retrieved 2011-09-28.
  9. ^ "Vector Extensions". Using the GNU Compiler Collection (GCC). Retrieved 2020-01-16.
  10. ^ "Sony open sources Vector Math and SIMD math libraries (Cell PPU/SPU/other platforms)". Beyond3D Forum. Retrieved 2020-01-17.
  11. ^ Mok, Kris (25 February 2013). "Intrinsic Methods in HotSpot VM". Slideshare. Retrieved 2014-12-20.

External links edit

  • Intel Intrinsics Guide
  • Using milicode routines, IBM AIX 6.1 documentation

intrinsic, function, this, article, about, compiler, intrinsic, functions, toolkit, toolkit, intrinsics, this, article, needs, additional, citations, verification, please, help, improve, this, article, adding, citations, reliable, sources, unsourced, material,. This article is about compiler intrinsic functions For X toolkit see X Toolkit Intrinsics 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 Find sources Intrinsic function news newspapers books scholar JSTOR December 2009 Learn how and when to remove this template message In computer software in compiler theory an intrinsic function or built in function is a function subroutine available for use in a given programming language whose implementation is handled specially by the compiler Typically it may substitute a sequence of automatically generated instructions for the original function call similar to an inline 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 generally enable them only when a program requests optimization otherwise falling back to a default implementation provided by the language runtime system environment Intrinsic functions are often used to explicitly implement vectorization and parallelization in languages which do not address such constructs Some application programming interfaces API for example AltiVec and OpenMP use intrinsic functions to declare respectively vectorizable and multiprocessing aware operations during compiling The compiler parses the intrinsic functions and converts them into vector math or multiprocessing object code appropriate for the target platform Some intrinsics are used to provide additional constraints to the optimizer such as values a variable cannot assume 2 Contents 1 C and C 1 1 Examples 2 Java 3 References 4 External linksC and C editCompilers for C and C of Microsoft 3 Intel 1 and the GNU Compiler Collection GCC 4 implement intrinsics that map directly to the x86 single instruction multiple data SIMD instructions MMX Streaming SIMD Extensions SSE SSE2 SSE3 SSSE3 SSE4 AVX AVX2 AVX512 FMA The Microsoft Visual C compiler of Microsoft Visual Studio does not support inline assembly for x86 64 5 6 7 8 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 GNU built ins are slightly more abstracted approximating the abilities of several contemporary platforms with portable fall back implementations on platforms with no appropriate instructions 9 It is common for C libraries such as glm or Sony s vector maths libraries 10 to achieve portability via conditional 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 appropriate low 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 C application binary interface ABI Examples edit 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 gt 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 LinksIntel IntrinsicsJava editThe HotSpot Java virtual machine s JVM just in time compiler also has intrinsics for specific Java APIs 11 Hotspot intrinsics are standard Java APIs which may have one or more optimized implementation on some platforms References edit 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 Mok Kris 25 February 2013 Intrinsic Methods in HotSpot VM Slideshare Retrieved 2014 12 20 External links editIntel Intrinsics Guide Using milicode routines IBM AIX 6 1 documentation Retrieved from https en wikipedia org w index php title Intrinsic function amp oldid 1097917698, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.