1/*
2 * Copyright 2017, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(DATA61_BSD)
11 */
12
13#pragma once
14
15#include <utils/attribute.h>
16#include <utils/builtin.h>
17#include <utils/stringify.h>
18
19/* This idiom is a way of passing extra information or hints to GCC. It is only
20 * occasionally successful, so don't think of it as a silver optimisation
21 * bullet.
22 */
23#define ASSUME(x) \
24    do { \
25        if (!(x)) { \
26            __builtin_unreachable(); \
27        } \
28    } while (0)
29
30/* Indicate to the compiler that wherever this macro appears is a cold
31 * execution path. That is, it is not performance critical and likely rarely
32 * used. A perfect example is error handling code. This gives the compiler a
33 * light hint to deprioritise optimisation of this path.
34 */
35#define COLD_PATH() \
36    do { \
37        JOIN(cold_path_, __COUNTER__): COLD UNUSED; \
38    } while (0)
39
40/* The opposite of `COLD_PATH`. That is, aggressively optimise this path,
41 * potentially at the expense of others.
42 */
43#define HOT_PATH() \
44    do { \
45        JOIN(hot_path_, __COUNTER__): HOT UNUSED; \
46    } while (0)
47