Ylva And Malin
ym_attributes.h
Go to the documentation of this file.
1 #pragma once
2 // Setup checks for builtin features, attributes and extensions.
3 // See: https://clang.llvm.org/docs/LanguageExtensions.html
4 
5 #ifndef __has_builtin
6 #define __has_builtin(x) 0
7 #endif
8 
9 #ifndef __has_feature
10 #define __has_feature(x) 0
11 #endif
12 
13 #ifndef __has_extension
14 #define __has_extension __has_feature
15 #endif
16 
17 #ifndef __has_attribute
18 #define __has_attribute(x) 0
19 #endif
20 
28 #if __has_attribute(always_inline)
29 #define YM_INLINE __attribute__((always_inline)) inline
30 #else
31 #define YM_INLINE
32 #endif
33 
41 #if __has_attribute(noinline)
42 #define YM_NO_INLINE __attribute__((noinline))
43 #else
44 #define YM_NO_INLINE
45 #endif
46 
54 #if __has_attribute(pure)
55 #define YM_PURE __attribute__((pure))
56 #else
57 #define YM_PURE
58 #endif
59 
67 #define YM_RESTRICT restrict
68 
77 #if __has_attribute(unused)
78 #define YM_UNUSED __attribute__((unused))
79 #else
80 #define YM_UNUSED
81 #endif
82 
91 #if __has_attribute(warn_unused_result)
92 #define YM_NO_DISCARD __attribute__((warn_unused_result))
93 #else
94 #define YM_NO_DISCARD
95 #endif
96 
105 // Having issues with this in release on windows.
106 #if __has_builtin(__builtin_expect) && !defined(WIN32)
107 #define YM_LIKELY(x) __builtin_expect(!!(x), 1)
108 #else
109 #define YM_LIKELY(x) (x)
110 #endif
111 
120 // Having issues with this in release on windows.
121 #if __has_builtin(__builtin_expect) && !defined(WIN32)
122 #define YM_UNLIKELY(x) __builtin_expect(!!(x), 0)
123 #else
124 #define YM_UNLIKELY(x) (x)
125 #endif
126