All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
hints.h File Reference

Compiler hints. More...

+ Include dependency graph for hints.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ARCH_LIKELY(x)   (x)
 
#define ARCH_UNLIKELY(x)   (x)
 
#define ARCH_GUARANTEE_TO_COMPILER(x)
 ARCH_GUARANTEE_TO_COMPILER(bool-expr) informs the compiler about value constraints to help it make better optimizations.
 

Detailed Description

Compiler hints.

ARCH_LIKELY(bool-expr) and ARCH_UNLIKELY(bool-expr) will evaluate to the value of bool-expr but will also emit compiler intrinsics providing hints for branch prediction if the compiler has such intrinsics. It is advised that you only use these in cases where you empirically know the outcome of bool-expr to a very high degree of certainty. For example, fatal-error cases, invariants, first-time initializations, etc.

Definition in file hints.h.

Macro Definition Documentation

◆ ARCH_GUARANTEE_TO_COMPILER

#define ARCH_GUARANTEE_TO_COMPILER (   x)

ARCH_GUARANTEE_TO_COMPILER(bool-expr) informs the compiler about value constraints to help it make better optimizations.

It is of critical importance that the guarantee is in fact always 100% true, otherwise the compiler may generate invalid code.

This can be useful, for example, when an out-of-line function call could potentially change a value previously known to compiler, but does not, based on code invariants.

This hint is best used after investigating generated assembly code and seeing useless/unreachable code being generated that can be prevented with this hint. This hint is often times not necessary, and should never be inserted on a whim. The compiler will run with the promises we make it to the ends of the earth, and this can lead to surprising results (e.g. undefined behavior) if we are not careful.

Definition at line 63 of file hints.h.

◆ ARCH_LIKELY

#define ARCH_LIKELY (   x)    (x)

Definition at line 29 of file hints.h.

◆ ARCH_UNLIKELY

#define ARCH_UNLIKELY (   x)    (x)

Definition at line 30 of file hints.h.