An intrinsic function is a function available for use in a given programming language whose implementation is handled specially by the compiler. Typically, it substitutes a sequence of automatically generated instructions for the original function call, similar to an inline function. Unlike an inline function though, the compiler has an intimate knowledge of the intrinsic function and can therefore better integrate it and optimize it for the situation. This is also called builtin function in many languages.
A code snippet is written to check the code generation when intrinsic is enabled or not:
Only printf() is in code. No abs() nor memcpy(). Since they are intrinsic, as listed here in gcc’s online document.
Intrinsic can be explicitly disabled. For instance, CRT intrinsic must be disabled for kernel development. Add -fno-builtin flag to gcc, or remove /Oi switch in MSVC. Only paste the generated code in gcc case here:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $32, %esp
movl 8(%ebp), %eax
movl %eax, (%esp)
call abs
movl %eax, 28(%esp)
movl c, %eax
movl %eax, %edx
movl $c2, %eax
movl $12, 8(%esp)
movl %edx, 4(%esp)
movl %eax, (%esp)
call memcpy
movl $.LC1, %eax
movl $c2, 8(%esp)
movl 28(%esp), %edx
movl %edx, 4(%esp)
movl %eax, (%esp)
call printf
movl $0, %eax
leave
ret
There _are_ abs() and memcpy() now. General MSVC intrinsic can be found here.
Intrinsic is easier than inline assembly. It is used to increase performance in most cases. Both gcc and MSVC provide intrinsic support for Intel’s MMX, SSE and SSE2 instrument set. Code snippet to use MMX:
You see MMX registers and instruments this time. -mmmx flag is required to build for gcc. MSVC also generate similar code. Reference for these instrument set is available on Intel’s website.