xref: /aosp_15_r20/external/zstd/contrib/pzstd/utils/Likely.h (revision 01826a4963a0d8a59bc3812d29bdf0fb76416722)
1*01826a49SYabin Cui /*
2*01826a49SYabin Cui  * Copyright (c) Meta Platforms, Inc. and affiliates.
3*01826a49SYabin Cui  * All rights reserved.
4*01826a49SYabin Cui  *
5*01826a49SYabin Cui  * This source code is licensed under both the BSD-style license (found in the
6*01826a49SYabin Cui  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7*01826a49SYabin Cui  * in the COPYING file in the root directory of this source tree).
8*01826a49SYabin Cui  */
9*01826a49SYabin Cui 
10*01826a49SYabin Cui /**
11*01826a49SYabin Cui  * Compiler hints to indicate the fast path of an "if" branch: whether
12*01826a49SYabin Cui  * the if condition is likely to be true or false.
13*01826a49SYabin Cui  *
14*01826a49SYabin Cui  * @author Tudor Bosman ([email protected])
15*01826a49SYabin Cui  */
16*01826a49SYabin Cui 
17*01826a49SYabin Cui #pragma once
18*01826a49SYabin Cui 
19*01826a49SYabin Cui #undef LIKELY
20*01826a49SYabin Cui #undef UNLIKELY
21*01826a49SYabin Cui 
22*01826a49SYabin Cui #if defined(__GNUC__) && __GNUC__ >= 4
23*01826a49SYabin Cui #define LIKELY(x) (__builtin_expect((x), 1))
24*01826a49SYabin Cui #define UNLIKELY(x) (__builtin_expect((x), 0))
25*01826a49SYabin Cui #else
26*01826a49SYabin Cui #define LIKELY(x) (x)
27*01826a49SYabin Cui #define UNLIKELY(x) (x)
28*01826a49SYabin Cui #endif
29