Skip to content

Commit d76c701

Browse files
committed
Clean up macros and make runtime assertions consistent across debug and release
1 parent 2b2ccc8 commit d76c701

3 files changed

Lines changed: 60 additions & 26 deletions

File tree

Fastor/config/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This file is part of the FASTOR library. {{{
2-
Copyright (c) 2016 Roman Poya
2+
Copyright (c) 2020 Roman Poya
33
44
Permission is hereby granted, free of charge, to any person obtaining a copy
55
of this software and associated documentation files (the "Software"), to deal

Fastor/config/cpuid.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/* This file is part of the FASTOR library. {{{
2+
Copyright (c) 2020 Roman Poya
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
SOFTWARE.
21+
22+
}}}*/
23+
124
#ifndef CPUID_H
225
#define CPUID_H
326

Fastor/config/macros.h

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This file is part of the FASTOR library. {{{
2-
Copyright (c) 2016 Roman Poya
2+
Copyright (c) 2020 Roman Poya
33
44
Permission is hereby granted, free of charge, to any person obtaining a copy
55
of this software and associated documentation files (the "Software"), to deal
@@ -74,11 +74,17 @@ SOFTWARE.
7474
#endif
7575
//------------------------------------------------------------------------------------------------//
7676

77+
78+
// Aliasing
79+
//------------------------------------------------------------------------------------------------//
7780
#ifndef FASTOR_NO_ALIAS
7881
#define FASTOR_NO_ALIAS 0
7982
#endif
83+
//------------------------------------------------------------------------------------------------//
8084

81-
// this changes the behaviour of all expression templates (apart from views)
85+
86+
// Macros used throughout Fastor
87+
//------------------------------------------------------------------------------------------------//
8288
//#define FASTOR_COPY_EXPR
8389
//#define FASTOR_DONT_VECTORISE
8490
//#define FASTOR_DONT_PERFORM_OP_MIN
@@ -101,11 +107,14 @@ SOFTWARE.
101107
#define FASTOR_BLAS_SWITCH_MATRIX_SIZE 16
102108
#endif
103109

104-
110+
// FASTOR_NIL
111+
//------------------------------------------------------------------------------------------------//
105112
#define FASTOR_NIL 0
106113
//------------------------------------------------------------------------------------------------//
107114

108115

116+
// Bit sizes
117+
//------------------------------------------------------------------------------------------------//
109118
#define FASTOR_AVX512_BITSIZE 512
110119
#define FASTOR_AVX_BITSIZE 256
111120
#define FASTOR_SSE_BITSIZE 128
@@ -114,6 +123,7 @@ SOFTWARE.
114123
#ifndef FASTOR_SCALAR_BITSIZE
115124
#define FASTOR_SCALAR_BITSIZE FASTOR_DOUBLE_BITSIZE
116125
#endif
126+
//------------------------------------------------------------------------------------------------//
117127

118128

119129
// Alignment
@@ -144,46 +154,38 @@ SOFTWARE.
144154

145155
#define FASTOR_ISALIGNED(POINTER, BYTE_COUNT) \
146156
(((uintptr_t)(const void *)(POINTER)) % (BYTE_COUNT) == 0)
157+
//------------------------------------------------------------------------------------------------//
147158

148159

149-
// Asserts and warnings
160+
// Assertions
150161
//------------------------------------------------------------------------------------------------//
151162
namespace Fastor {
152-
153-
// Strong assert under debug and release
163+
// Strong unconditional assert
154164
FASTOR_INLINE void FASTOR_EXIT_ASSERT(bool cond, const std::string &msg="") {
155165
if (cond==false) {
156166
throw std::runtime_error(msg);
157167
}
158168
}
159169

160-
#if !FASTOR_ENABLE_RUNTIME_CHECKS
161-
// Standard assert - by default only turned on under debug
162-
#ifndef NDEBUG
163-
#define FASTOR_ASSERT(COND, MESSAGE) assert(COND && MESSAGE)
170+
#if !defined(NDEBUG) || FASTOR_ENABLE_RUNTIME_CHECKS
171+
#define FASTOR_ASSERT(COND, MESSAGE) FASTOR_EXIT_ASSERT(COND, MESSAGE)
164172
#else
165173
#define FASTOR_ASSERT(COND, MESSAGE)
166174
#endif
167-
#else
168-
// Otherwise if asked by the user turned on unconditionally
169-
#define FASTOR_ASSERT(COND, MESSAGE) FASTOR_EXIT_ASSERT(COND, MESSAGE)
170-
#endif
171175

176+
// Warn
172177
FASTOR_INLINE void FASTOR_WARN(bool cond, const std::string &x) {
173-
if (cond==true) {
174-
return;
175-
}
176-
else {
178+
if (cond==false) {
177179
std::cout << x << std::endl;
178180
}
179181
}
180-
181182
} // end of namespace Fastor
182-
183-
#define FASTOR_TOSTRING_(X) #X
184-
#define FASTOR_TOSTRING(X) FASTOR_TOSTRING_(X)
183+
//------------------------------------------------------------------------------------------------//
185184

186185

186+
// Warnings
187+
//------------------------------------------------------------------------------------------------//
188+
// Static warn
187189
#ifndef FASTOR_NO_STATIC_WARNING
188190
#if defined(__GNUC__)
189191
#define FASTOR_DEPRECATE(foo, msg) foo __attribute__((deprecated(msg)))
@@ -215,13 +217,24 @@ struct FASTOR_CAT(static_warning,__LINE__) { \
215217

216218
} // end of namespace Fastor
217219
#endif // FASTOR_NO_STATIC_WARNING
220+
//------------------------------------------------------------------------------------------------//
218221

219222

223+
// Token to string
224+
//------------------------------------------------------------------------------------------------//
225+
#define FASTOR_TOSTRING_(X) #X
226+
#define FASTOR_TOSTRING(X) FASTOR_TOSTRING_(X)
227+
//------------------------------------------------------------------------------------------------//
228+
220229
// asm comment
230+
//------------------------------------------------------------------------------------------------//
221231
#define FASTOR_ASM(STR) asm(STR ::)
232+
//------------------------------------------------------------------------------------------------//
222233

234+
// unused
235+
//------------------------------------------------------------------------------------------------//
223236
namespace Fastor {
224-
//clobber
237+
// clobber
225238
template <typename T> void unused(T &&x) {
226239
#ifndef _WIN32
227240
asm("" ::"m"(x));
@@ -230,7 +243,6 @@ template <typename T> void unused(T &&x) {
230243
template <typename T, typename ... U> void unused(T&& x, U&& ...y) { unused(x); unused(y...); }
231244
} // end of namespace Fastor
232245
//------------------------------------------------------------------------------------------------//
233-
//------------------------------------------------------------------------------------------------//
234246

235247

236248
// SIMD round-down
@@ -275,7 +287,6 @@ constexpr int NoDepthFirst = -201;
275287
constexpr double PRECI_TOL = 1e-14;
276288

277289
}
278-
279290
//------------------------------------------------------------------------------------------------//
280291

281292
#endif // FASTOR_MACROS_H

0 commit comments

Comments
 (0)