2 * Copyright 2012-present Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #define FOLLY_DETAIL_BUILTIN_EXPECT(b, t) (__builtin_expect(b, t))
22 #define FOLLY_DETAIL_BUILTIN_EXPECT(b, t) b
25 // Likeliness annotations
27 // Useful when the author has better knowledge than the compiler of whether
28 // the branch condition is overwhelmingly likely to take a specific value.
30 // Useful when the author has better knowledge than the compiler of which code
31 // paths are designed as the fast path and which are designed as the slow path,
32 // and to force the compiler to optimize for the fast path, even when it is not
33 // overwhelmingly likely.
35 #define FOLLY_LIKELY(x) FOLLY_DETAIL_BUILTIN_EXPECT((x), 1)
36 #define FOLLY_UNLIKELY(x) FOLLY_DETAIL_BUILTIN_EXPECT((x), 0)
38 // Un-namespaced annotations
44 #define LIKELY(x) (__builtin_expect((x), 1))
45 #define UNLIKELY(x) (__builtin_expect((x), 0))
48 #define UNLIKELY(x) (x)