Project
Loading...
Searching...
No Matches
CompilerBuiltins.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12// Compatibility layer for a few common builtins found in different compilers.
13// These are trivial and the goal is to make sure we can compile on non GCC /
14// clang compilers if requested.
15#ifndef O2_FRAMEWORK_COMPILER_BUILTINS_H_
16#define O2_FRAMEWORK_COMPILER_BUILTINS_H_
17#if __GNUC__
18#define O2_BUILTIN_UNREACHABLE __builtin_unreachable
19#elif __clang__
20#define O2_BUILTIN_UNREACHABLE __builtin_unreachable
21#else
22#define O2_BUILTIN_UNREACHABLE
23#endif
24
25#if __GNUC__
26#define O2_BUILTIN_LIKELY(x) __builtin_expect((x), 1)
27#define O2_BUILTIN_UNLIKELY(x) __builtin_expect((x), 0)
28#elif __clang__
29#define O2_BUILTIN_LIKELY(x) __builtin_expect((x), 1)
30#define O2_BUILTIN_UNLIKELY(x) __builtin_expect((x), 0)
31#else
32#define O2_BUILTIN_LIKELY(x) (x)
33#define O2_BUILTIN_UNLIKELY(x) (x)
34#endif
35
36#if __GNUC__
37#define O2_BUILTIN_PREFETCH(x, ...) __builtin_prefetch((x), __VA_ARGS__)
38#elif __clang__
39#define O2_BUILTIN_PREFETCH(x, ...) __builtin_prefetch((x), __VA_ARGS__)
40#else
41#define O2_BUILTIN_PREFETCH(x, ...)
42#endif
43
44#if __GNUC__
45#define O2_VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
46#elif __clang__
47#define O2_VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
48#else
49#define O2_VISIBILITY_HIDDEN
50#endif
51
52#endif // O2_FRAMEWORK_COMPILER_BUILTINS_H_