xref: /dpdk/lib/eal/include/rte_branch_prediction.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
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 /**
14  * Check if a branch is likely to be taken.
15  *
16  * This compiler builtin allows the developer to indicate if a branch is
17  * likely to be taken. Example:
18  *
19  *   if (likely(x > 1))
20  *      do_stuff();
21  */
22 #ifndef likely
23 #ifdef RTE_TOOLCHAIN_MSVC
24 #define likely(x)	(!!(x))
25 #else
26 #define likely(x)	__builtin_expect(!!(x), 1)
27 #endif
28 #endif /* likely */
29 
30 /**
31  * Check if a branch is unlikely to be taken.
32  *
33  * This compiler builtin allows the developer to indicate if a branch is
34  * unlikely to be taken. Example:
35  *
36  *   if (unlikely(x < 1))
37  *      do_stuff();
38  */
39 #ifndef unlikely
40 #ifdef RTE_TOOLCHAIN_MSVC
41 #define unlikely(x)	(!!(x))
42 #else
43 #define unlikely(x)	__builtin_expect(!!(x), 0)
44 #endif
45 #endif /* unlikely */
46 
47 #endif /* _RTE_BRANCH_PREDICTION_H_ */
48