Pixar Arch
Loading...
Searching...
No Matches
hints.h
Go to the documentation of this file.
1// Copyright 2016 Pixar
2//
3// Licensed under the terms set forth in the LICENSE.txt file available at
4// https://openusd.org/license.
5//
6// Modified by Jeremy Retailleau.
7
8#ifndef PXR_ARCH_HINTS_H
9#define PXR_ARCH_HINTS_H
10
11#include "./defines.h"
12
22
23#if defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
24
25#define ARCH_LIKELY(x) (__builtin_expect((bool)(x), true))
26#define ARCH_UNLIKELY(x) (__builtin_expect((bool)(x), false))
27
28#else
29
30#define ARCH_LIKELY(x) (x)
31#define ARCH_UNLIKELY(x) (x)
32
33#endif
34
50
51#if defined(ARCH_COMPILER_GCC) || \
52 defined(ARCH_COMPILER_CLANG) || \
53 defined(ARCH_COMPILER_ICC)
54
55// Intentionally using __builtin_unreachable on clang for consistency, since
56// __builtin_assume does not evaluate the expression, and our only option on gcc
57// is the __builtin_unreachable branch.
58
59#define ARCH_GUARANTEE_TO_COMPILER(x) \
60 if (static_cast<bool>(x)) { } else { __builtin_unreachable(); }
61
62#else
63
64#define ARCH_GUARANTEE_TO_COMPILER(x)
65
66#endif
67
68
69#endif // PXR_ARCH_HINTS_H