xref: /dpdk/lib/eal/include/rte_branch_prediction.h (revision 2df20a1d345a5fc0a1b6dc0317d11fc7b1fda7e7)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4 
5 /**
6  * @file
7  * Branch Prediction Helpers in RTE
8  */
9 
10 #ifndef _RTE_BRANCH_PREDICTION_H_
11 #define _RTE_BRANCH_PREDICTION_H_
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 /**
18  * Check if a branch is likely to be taken.
19  *
20  * This compiler builtin allows the developer to indicate if a branch is
21  * likely to be taken. Example:
22  *
23  *   if (likely(x > 1))
24  *      do_stuff();
25  */
26 #ifndef likely
27 #ifdef RTE_TOOLCHAIN_MSVC
28 #define likely(x)	(!!(x))
29 #else
30 #define likely(x)	__builtin_expect(!!(x), 1)
31 #endif
32 #endif /* likely */
33 
34 /**
35  * Check if a branch is unlikely to be taken.
36  *
37  * This compiler builtin allows the developer to indicate if a branch is
38  * unlikely to be taken. Example:
39  *
40  *   if (unlikely(x < 1))
41  *      do_stuff();
42  */
43 #ifndef unlikely
44 #ifdef RTE_TOOLCHAIN_MSVC
45 #define unlikely(x)	(!!(x))
46 #else
47 #define unlikely(x)	__builtin_expect(!!(x), 0)
48 #endif
49 #endif /* unlikely */
50 
51 #ifdef __cplusplus
52 }
53 #endif
54 
55 #endif /* _RTE_BRANCH_PREDICTION_H_ */
56