Intrinsic function

In computer software, in compiler theory, an intrinsic function (or builtin function) is a function (subroutine) available for use in a given programming language which 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. 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.

C and C++

Compilers for C and C++, of Microsoft,[1] Intel, and the GNU Compiler Collection (GCC)[2] implement intrinsics that map directly to the x86 single instruction, multiple data (SIMD) instructions (MMX, Streaming SIMD Extensions (SSE), SSE2, SSE3, SSSE3, SSE4). The Microsoft Visual C++ compiler of Microsoft Visual Studio does not support inline assembly for x86-64.[3][4][5][6] 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. It is common for C++ libraries, such as glm or Sony's vector maths libraries,[7] 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).

Java

The HotSpot Java 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.

References

  1. MSDN (VS2010). "Compiler Intrinsics". Microsoft. Retrieved 2012-06-20.
  2. GCC documentation. "Built-in Functions Specific to Particular Target Machines". Free Software Foundation. Retrieved 2012-06-20.
  3. MSDN (VS2012). "Intrinsics and Inline Assembly". Microsoft. Retrieved 2010-04-16.
  4. MSDN (VS2010). "Intrinsics and Inline Assembly". Microsoft. Retrieved 2011-09-28.
  5. MSDN (VS2008). "Intrinsics and Inline Assembly". Microsoft. Retrieved 2011-09-28.
  6. MSDN (VS2005). "Intrinsics and Inline Assembly". Microsoft. Retrieved 2011-09-28.
  7. "sony open sources vector math simd libraries".
  8. Mok, Kris (25 February 2013). "Intrinsic Methods in HotSpot VM". Slideshare. Retrieved 20 December 2014.
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.