Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are intrinsics?

Tags:

c++

c

intrinsics

Can anyone explain what they are and why I would need them? What kind of applications am I building if I need to use intrinsics?

like image 979
Scott J Avatar asked Feb 15 '10 20:02

Scott J


People also ask

What are intrinsics in computing?

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.

What are Intel intrinsics?

intel-intrinsics is the SIMD library for D. intel-intrinsics lets you use SIMD in D with support for LDC / DMD / GDC with a single syntax and API: the x86 Intel Intrinsics API that is also used within the C, C++, and Rust communities.

What is intrinsics in Java?

A native method is a method that is declared as native in the Java source code of the class. An "intrinsic" method is one that the JVM runtime (specifically the JIT compiler) performs special optimization on. One of the things that "intrinsic" means is that the call sequence is not a JNI call.


1 Answers

An intrinsic function is a function which the compiler implements directly when possible, rather than linking to a library-provided implementation of the function.

A common example is strncpy().

For short strings, making a function call to strncpy(), which involves setting up a 'stack frame' with a return address, will consume more time than the actual copying of bytes does. Worse, the effect on CPU pre-fetch buffers will stall the CPU execution for several clock cycles.

Instead, the intrinsic function is implemented by the compiler in lieu of a function call. In the example of strncpy(), the byte-copying code is emitted directly at the place where strncpy() is invoked.

Similar to this strncpy() example, every intrinsic function is implemented directly as in-line code if required constraints are met.

A non-intrinsic copy of the intrinsic function usually still exists in the standard library, in case the address of the function is needed.

As compared to inline functions, the intrinsic function is provided by the compiler. There isn't a place in the source code of a C program where the intrinsic function is written, nor is there a library implementation that must be linked to. An inline function is different in that the compiler reads the source code for the inline function, but is similar in that later it may emit a compiled translation of the inline function directly into the object code, omitting the overhead of a function call.

In short, the practical difference between an intrinsic funciton and an inline function is that intrinsic functions are "present" even if you have not #include the needed header file which contains the function declaration. For an inline function, the header file with the function declaration must be #include'd (or otherwise declared) first.

like image 130
Heath Hunnicutt Avatar answered Oct 03 '22 03:10

Heath Hunnicutt