xref: /freebsd/sys/contrib/dpdk_rte_lpm/rte_branch_prediction.h (revision ebacd8013fe5f7fdf9f6a5b286f6680dd2891036)
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  */
23 #ifndef likely
24 #define likely(x)	__builtin_expect(!!(x), 1)
25 #endif /* likely */
26 
27 /**
28  * Check if a branch is unlikely to be taken.
29  *
30  * This compiler builtin allows the developer to indicate if a branch is
31  * unlikely to be taken. Example:
32  *
33  *   if (unlikely(x < 1))
34  *      do_stuff();
35  *
36  */
37 #ifndef unlikely
38 #define unlikely(x)	__builtin_expect(!!(x), 0)
39 #endif /* unlikely */
40 
41 #endif /* _RTE_BRANCH_PREDICTION_H_ */
42