Saturday, 6 September 2025

Compiler Intrinsics - Basics, Pros and Cons

In Microsoft C++, many functions come from libraries, whilst some are built in to the compiler. The latter functions are known as compiler intrinsics.

PROS

An intrinsic function is usually inserted inline, avoiding overhead of a function call. Hence, compiler intrinsics are efficient!

They can be even jiffier than inline functions, as the optimizer in the compiler has knowledge of them and can optimise usage!

POTENTIAL CONS

A potential downside of using intrinsic functions is reduced portability of the code - other compilers may not support these functions. Also, some intrinsics may be available for some target architectures and not others.

COMMON INTRINSICS

Microsoft make some intrinsics available on all target architectures. Here's an example!

_AddressOfReturnAddress

signature: void * _AddressOfReturnAddress();

<intrin.h>

This function provides the address of the memory location that holds the return address of the current function.

No comments: