|
VTK
9.6.20260612
|
Compiler hint macros for assumptions and branch prediction. More...
Go to the source code of this file.
Macros | |
| #define | VTK_ASSUME(cond) |
| Assert a condition to the compiler as always true, aborting in debug builds if violated. | |
| #define | VTK_ASSUME_NO_ASSERT(cond) |
| Same optimizer hint as VTK_ASSUME but without the debug-mode assertion. | |
| #define | VTK_HAS_BUILTIN(x) |
| #define | VTK_ASSUME_IMPL(cond) |
| #define | VTK_EXPECT(cond, expected) |
Low-level branch-prediction hint wrapping __builtin_expect. | |
| #define | VTK_LIKELY(cond) |
Hint that cond is expected to be true most of the time. | |
| #define | VTK_UNLIKELY(cond) |
Hint that cond is expected to be false most of the time. | |
Compiler hint macros for assumptions and branch prediction.
This header provides four families of macros:
VTK_ASSUME(cond) — tells the compiler cond is always true, with a debug-mode assert to catch violations at runtime.VTK_ASSUME_NO_ASSERT(cond) — same optimizer hint, but skips the assert.VTK_EXPECT(cond, expected) / VTK_LIKELY(cond) / VTK_UNLIKELY(cond) — branch-prediction hints that do not invoke undefined behaviour when wrong.A more detailed description and related tools can be found here.
Definition in file vtkAssume.h.
| #define VTK_ASSUME | ( | cond | ) |
Assert a condition to the compiler as always true, aborting in debug builds if violated.
Instructs the compiler that cond will always evaluate to true at this point in the program, enabling additional optimizations that would otherwise be impossible. In debug builds (NDEBUG not defined) a standard assert fires if the condition is false, making violations easy to catch during development.
Warning: if cond is false in a release build the behaviour is undefined. Only use this macro for invariants you are completely certain about.
Common use-case — fixed component count on a typed array:
Use inside vtkArrayDispatch workers:
| cond | A boolean expression that must always be true at this point. |
Definition at line 70 of file vtkAssume.h.
| #define VTK_ASSUME_NO_ASSERT | ( | cond | ) |
Same optimizer hint as VTK_ASSUME but without the debug-mode assertion.
Passes cond to the compiler as an always-true assumption for optimization purposes while deliberately omitting the assert. Use this variant when the condition is provably true by construction and the assertion would be noise, or in performance-critical inner loops where even the assert overhead in debug builds is undesirable.
Like VTK_ASSUME, a false condition in a release build is undefined behaviour.
| cond | A boolean expression that must always be true at this point. |
Definition at line 101 of file vtkAssume.h.
| #define VTK_HAS_BUILTIN | ( | x | ) |
Definition at line 112 of file vtkAssume.h.
| #define VTK_ASSUME_IMPL | ( | cond | ) |
Definition at line 127 of file vtkAssume.h.
| #define VTK_EXPECT | ( | cond, | |
| expected ) |
Low-level branch-prediction hint wrapping __builtin_expect.
Tells the CPU/compiler that cond is expected to equal expected (0 or 1). Unlike VTK_ASSUME, a misprediction is safe — it only affects performance, not correctness. Prefer the higher-level VTK_LIKELY / VTK_UNLIKELY wrappers in most situations.
| cond | The condition to evaluate. |
| expected | The value (0 or 1) the compiler should assume cond takes. |
Definition at line 199 of file vtkAssume.h.
| #define VTK_LIKELY | ( | cond | ) |
Hint that cond is expected to be true most of the time.
Use this to improve branch-prediction on hot code paths where cond is almost always true. Has no effect on correctness.
| cond | The boolean expression expected to be true. |
Definition at line 200 of file vtkAssume.h.
| #define VTK_UNLIKELY | ( | cond | ) |
Hint that cond is expected to be false most of the time.
Use this on error-handling branches or rarely-taken code paths. Has no effect on correctness.
| cond | The boolean expression expected to be false. |
Definition at line 201 of file vtkAssume.h.