fiber
Loading...
Searching...
No Matches
definitions.hpp
Go to the documentation of this file.
1#pragma once
2
9
10
11 // compiler independent assume
12#if (defined(__clang__) || defined(__GNUC__))
13 #define FIBER_ASSUME(cond) __builtin_assume(cond)
14#elif defined(_MSC_VER)
15 #define FIBER_ASSUME(cond) __assume(cond)
16#else
17 #define FIBER_ASSUME(cond)
18#endif
19
20// compiler independent prettiest name to get a string of the function signature
21#if defined(__clang__) || defined(__GNUC__)
22 #define FIBER_FUNCTION_SIGNATURE __PRETTY_FUNCTION__
23#elif defined(_MSC_VER)
24 #define FIBER_FUNCTION_SIGNATURE __FUNCSIG__
25#else // defined(__func__)
26 #define FIBER_FUNCTION_SIGNATURE __func__
27#endif
28
29
30#if __cplusplus >= 202002L
31 // Use standard C++20 attributes
32 #define FIBER_IF_LIKELY(condition) if(condition) [[likely]]
33 #define FIBER_IF_UNLIKELY(condition) if(condition) [[unlikely]]
34#elif defined(__clang__) || defined(__GNUC__)
35 // Use compiler builtins
36 #define FIBER_IF_LIKELY(condition) if(__builtin_expect(condition, 1))
37 #define FIBER_IF_UNLIKELY(condition) if(__builtin_expect(condition, 0))
38#else
39 // No-op fallback
40 #define FIBER_LIKELY if(condition)
41 #define FIBER_UNLIKELY if(condition)
42#endif
43
44#define FIBER_USE_UNUSED(value) ((void)sizeof(value))
45
46#if defined(__GNUC__) || defined(__clang__)
47 // Covers GCC, Clang, ARM-GCC, ARMCLANG (Keil 6)
48 #define FIBER_WEAK __attribute__((weak))
49#elif defined(__CC_ARM)
50 // ARM Compiler 5 (Keil <=5.x), old ARMCC
51 #define FIBER_WEAK __weak
52#elif defined(_MSC_VER)
53 // Microsoft Visual Studio (limited to inline-style weak symbols)
54 #define FIBER_WEAK __declspec(selectany)
55#else
56 #define FIBER_WEAK
57 #warning "FIBER_WEAK not defined for this compiler. Please file an issue at the repository, state the compiler you use and how one defines weak symbols for it."
58#endif