forked from ColinIanKing/stress-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core-attribute.h
183 lines (164 loc) · 5.4 KB
/
core-attribute.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
* Copyright (C) 2023 Colin Ian King
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef CORE_ATTRIBUTE_H
#define CORE_ATTRIBUTE_H
/* warn unused attribute */
#if defined(HAVE_ATTRIBUTE_WARN_UNUSED_RESULT) && \
((defined(HAVE_COMPILER_GCC_OR_MUSL) && NEED_GNUC(4, 2, 0)) || \
(defined(HAVE_COMPILER_CLANG) && NEED_CLANG(3, 0, 0)))
#define WARN_UNUSED __attribute__((warn_unused_result))
#else
#define WARN_UNUSED
#endif
#if defined(HAVE_ATTRIBUTE_FAST_MATH) && \
!defined(HAVE_COMPILER_ICC) && \
defined(HAVE_COMPILER_GCC_OR_MUSL) && \
NEED_GNUC(10, 0, 0)
#define OPTIMIZE_FAST_MATH __attribute__((optimize("fast-math")))
#else
#define OPTIMIZE_FAST_MATH
#endif
/* no return hint */
#if defined(HAVE_ATTRIBUTE_NORETURN) && \
((defined(HAVE_COMPILER_GCC_OR_MUSL) && NEED_GNUC(2, 5, 0)) || \
(defined(HAVE_COMPILER_CLANG) && NEED_CLANG(3, 0, 0)))
#define NORETURN __attribute__((noreturn))
#else
#define NORETURN
#endif
/* weak attribute */
#if defined(HAVE_ATTRIBUTE_WEAK) && \
((defined(HAVE_COMPILER_GCC_OR_MUSL) && NEED_GNUC(4, 0, 0)) || \
(defined(HAVE_COMPILER_CLANG) && NEED_CLANG(3, 4, 0)))
#define WEAK __attribute__((weak))
#define HAVE_WEAK_ATTRIBUTE
#else
#define WEAK
#endif
#if defined(ALWAYS_INLINE)
#undef ALWAYS_INLINE
#endif
/* force inlining hint */
#if defined(HAVE_ATTRIBUTE_ALWAYS_INLINE) && \
((defined(HAVE_COMPILER_GCC_OR_MUSL) && NEED_GNUC(3, 4, 0) \
&& ((!defined(__s390__) && !defined(__s390x__)) || NEED_GNUC(6, 0, 1))) || \
(defined(HAVE_COMPILER_CLANG) && NEED_CLANG(3, 0, 0)))
#define ALWAYS_INLINE __attribute__((always_inline))
#else
#define ALWAYS_INLINE
#endif
/* force no inlining hint */
#if defined(HAVE_ATTRIBUTE_NOINLINE) && \
((defined(HAVE_COMPILER_GCC_OR_MUSL) && NEED_GNUC(3, 4, 0)) || \
(defined(HAVE_COMPILER_CLANG) && NEED_CLANG(3, 0, 0)))
#define NOINLINE __attribute__((noinline))
#else
#define NOINLINE
#endif
/* -O3 attribute support */
#if defined(HAVE_COMPILER_GCC_OR_MUSL) && \
!defined(HAVE_COMPILER_CLANG) && \
!defined(HAVE_COMPILER_ICC) && \
NEED_GNUC(4, 6, 0)
#define OPTIMIZE3 __attribute__((optimize("-O3")))
#else
#define OPTIMIZE3
#endif
/* -O2 attribute support */
#if defined(HAVE_COMPILER_GCC_OR_MUSL) && \
!defined(HAVE_COMPILER_CLANG) && \
!defined(HAVE_COMPILER_ICC) && \
NEED_GNUC(4, 6, 0)
#define OPTIMIZE2 __attribute__((optimize("-O2")))
#else
#define OPTIMIZE2
#endif
/* -O1 attribute support */
#if defined(HAVE_COMPILER_GCC_OR_MUSL) && \
!defined(HAVE_COMPILER_CLANG) && \
!defined(HAVE_COMPILER_ICC) && \
NEED_GNUC(4, 6, 0)
#define OPTIMIZE1 __attribute__((optimize("-O1")))
#else
#define OPTIMIZE1
#endif
/* -O0 attribute support */
#if defined(HAVE_COMPILER_GCC_OR_MUSL) && \
!defined(HAVE_COMPILER_ICC) && \
NEED_GNUC(4, 6, 0)
#define OPTIMIZE0 __attribute__((optimize("-O0")))
#elif (defined(HAVE_COMPILER_CLANG) && NEED_CLANG(10, 0, 0))
#define OPTIMIZE0 __attribute__((optnone))
#else
#define OPTIMIZE0
#endif
#if ((defined(HAVE_COMPILER_GCC_OR_MUSL) && NEED_GNUC(3, 3, 0)) || \
(defined(HAVE_COMPILER_CLANG) && NEED_CLANG(3, 0, 0)) || \
(defined(HAVE_COMPILER_ICC) && NEED_ICC(2021, 0, 0))) && \
!defined(HAVE_COMPILER_PCC) && \
!defined(__minix__)
#define ALIGNED(a) __attribute__((aligned(a)))
#else
#define ALIGNED(a)
#endif
/* Force alignment macros */
#define ALIGN128 ALIGNED(128)
#define ALIGN64 ALIGNED(64)
#if (defined(HAVE_COMPILER_GCC_OR_MUSL) && NEED_GNUC(4, 6, 0)) || \
(defined(HAVE_COMPILER_CLANG) && NEED_CLANG(3, 0, 0))
#if (defined(__APPLE__) && defined(__MACH__))
#define SECTION(s) __attribute__((__section__(# s "," # s)))
#else
#define SECTION(s) __attribute__((__section__(# s)))
#endif
#else
#define SECTION(s)
#endif
/* GCC hot attribute */
#if defined(HAVE_ATTRIBUTE_HOT) && \
((defined(HAVE_COMPILER_GCC_OR_MUSL) && NEED_GNUC(4, 6, 0)) || \
(defined(HAVE_COMPILER_CLANG) && NEED_CLANG(3, 3, 0)))
#define HOT __attribute__((hot))
#else
#define HOT
#endif
#if defined(HAVE_ATTRIBUTE_PURE)
#define PURE __attribute__((pure))
#else
#define PURE
#endif
/* GCC mlocked data and data section attribute */
#if ((defined(HAVE_COMPILER_GCC_OR_MUSL) && NEED_GNUC(4, 6, 0) || \
(defined(HAVE_COMPILER_CLANG) && NEED_CLANG(3, 0, 0)))) && \
!defined(__sun__) && \
!defined(__APPLE__) && \
!defined(BUILD_STATIC)
#define MLOCKED_TEXT __attribute__((__section__("mlocked_text")))
#define MLOCKED_SECTION (1)
#else
#define MLOCKED_TEXT
#endif
/* print format attribute */
#if ((defined(HAVE_COMPILER_GCC_OR_MUSL) && NEED_GNUC(3, 2, 0)) || \
(defined(HAVE_COMPILER_CLANG) && NEED_CLANG(3, 0, 0)))
#define FORMAT(func, a, b) __attribute__((format(func, a, b)))
#else
#define FORMAT(func, a, b)
#endif
#endif