/root/doris/be/src/common/compiler_util.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | // Compiler hint that this branch is likely or unlikely to |
21 | | // be taken. Take from the "What all programmers should know |
22 | | // about memory" paper. |
23 | | // example: if (LIKELY(size > 0)) { ... } |
24 | | // example: if (UNLIKELY(!status.ok())) { ... } |
25 | | #define CACHE_LINE_SIZE 64 |
26 | | |
27 | | #ifdef LIKELY |
28 | | #undef LIKELY |
29 | | #endif |
30 | | |
31 | | #ifdef UNLIKELY |
32 | | #undef UNLIKELY |
33 | | #endif |
34 | | |
35 | 1.24M | #define LIKELY(expr) __builtin_expect(!!(expr), 1) |
36 | 27.2M | #define UNLIKELY(expr) __builtin_expect(!!(expr), 0) |
37 | | |
38 | | #define PREFETCH(addr) __builtin_prefetch(addr) |
39 | | |
40 | | /// Force inlining. The 'inline' keyword is treated by most compilers as a hint, |
41 | | /// not a command. This should be used sparingly for cases when either the function |
42 | | /// needs to be inlined for a specific reason or the compiler's heuristics make a bad |
43 | | /// decision, e.g. not inlining a small function on a hot path. |
44 | | #ifdef ALWAYS_INLINE |
45 | | #undef ALWAYS_INLINE |
46 | | #endif |
47 | | #define ALWAYS_INLINE __attribute__((always_inline)) |
48 | | #define NO_INLINE __attribute__((__noinline__)) |
49 | | #define MAY_ALIAS __attribute__((__may_alias__)) |
50 | | |
51 | | #define ALIGN_CACHE_LINE __attribute__((aligned(CACHE_LINE_SIZE))) |
52 | | |
53 | | #define PURE __attribute__((pure)) |