0
$\begingroup$

I'm trying to understand what a compiler intrinsic function is. I did find a wiki article but I'm still kind of fuzzy on what it is exactly. If someone could provide a few concrete examples that would definitely clarify the issue.

Any help is appreciated.

$\endgroup$
  • 1
    $\begingroup$ What specifically are you fuzzy about? What is your current understanding? What other sources have you checked out? $\endgroup$ – Raphael May 6 '16 at 6:17
  • $\begingroup$ @Raphael Please see a comment I made to an answer that was provided below. $\endgroup$ – flashburn May 6 '16 at 16:23
4
$\begingroup$

One example of compiler intrinsic functions is the floating point math functions that are part of the standard C math library. On CPU architectures with on-chip support for floating point trigonometric functions like sine and cosine, the compiler might replace the function calls with a series of instructions that achieve the same result but using the available CPU instructions instead.

Another example is replacement of calls to C low-level memory copying functions such as memcpy and memmove. These might be implemented directly using SIMD instructions if available, copying the blocks of memory many times faster.

Note that "... an intrinsic function is a function available for use in a given programming language whose implementation is handled specially by the compiler." This is in contrast to operators like addition and subtraction; the compiler would be expected to implement floating point arithmetic operators even without an FPU since the C language specification demands it. Intrinsic functions go further and implement things that are properly part of the C library of hosted implementations.

$\endgroup$
  • $\begingroup$ This makes it a little more clear, but how are intrinsic functions different from regular assembly instructions. Say my CPU has a floating point unit. How would a floating point add assembly instruction differ from an intrinsic function that implements a floating point add? $\endgroup$ – flashburn May 6 '16 at 16:23
  • $\begingroup$ "... an intrinsic function is a function available for use in a given programming language whose implementation is handled specially by the compiler." In C addition is an operator rather than a function; the compiler would be expected to implement floating point math even without an FPU since the langauge specification demands it. Intrinsic functions go further and implement things that are properly part of the C library of hosted implementations. $\endgroup$ – Kyle Jones May 6 '16 at 16:52
1
$\begingroup$

The difference between an intrinsic function and assembler code is that as a software developer, who can use the intrinsic function in exactly the same way as you would use any other function that you have written yourself. Most likely the use is quite portable; the same intrinsic function may be usable on very different processors.

Assembler code requires you to switch to an unportable language that you likely have no experience with. And you have to write it yourself. In assembler code.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.