Gaia-ECS v0.9.3
A simple and powerful entity component system
Loading...
Searching...
No Matches
config_core_end.h
1#pragma once
2#include "gaia/config/config_core.h"
3
4//------------------------------------------------------------------------------
5// DO NOT MODIFY THIS FILE
6//------------------------------------------------------------------------------
7
8//------------------------------------------------------------------------------
9// External code settings
10//------------------------------------------------------------------------------
11
12#ifndef TCB_SPAN_NO_CONTRACT_CHECKING
13// #define TCB_SPAN_NO_CONTRACT_CHECKING
14#endif
15
16//------------------------------------------------------------------------------
17// Debug features
18//------------------------------------------------------------------------------
19
20#if !defined(NDEBUG) || defined(_DEBUG)
21 #define GAIA_DEBUG_BUILD 1
22#else
23 #define GAIA_DEBUG_BUILD 0
24#endif
25
30#if !defined(GAIA_DEBUG)
31 #if GAIA_DEBUG_BUILD || GAIA_FORCE_DEBUG
32 #define GAIA_DEBUG 1
33 #else
34 #define GAIA_DEBUG 0
35 #endif
36#endif
37
38#if GAIA_DISABLE_ASSERTS
39 #ifdef GAIA_ASSERT_ENABLED
40 #undef GAIA_ASSERT_ENABLED
41 #endif
42 #define GAIA_ASSERT_ENABLED 0
43
44 #ifdef GAIA_ASSERT
45 #undef GAIA_ASSERT
46 #endif
47 #define GAIA_ASSERT(cond)
48
49 #ifdef GAIA_ASSERT2
50 #undef GAIA_ASSERT2
51 #endif
52 #define GAIA_ASSERT2(cond, msg)
53#elif !defined(GAIA_ASSERT)
54 #include <cassert>
55 // For Debug builds use system's native assertion capabilities
56 #if GAIA_DEBUG_BUILD
57 #define GAIA_ASSERT_ENABLED 1
58 #define GAIA_ASSERT(cond) \
59 { \
60 GAIA_MSVC_WARNING_PUSH() \
61 GAIA_MSVC_WARNING_DISABLE(4127) \
62 assert((cond)); \
63 GAIA_MSVC_WARNING_POP() \
64 }
65 #define GAIA_ASSERT2(cond, msg) \
66 { \
67 GAIA_MSVC_WARNING_PUSH() \
68 GAIA_MSVC_WARNING_DISABLE(4127) \
69 assert((cond) && (msg)); \
70 GAIA_MSVC_WARNING_POP() \
71 }
72 #else
73 // For non-Debug builds simulate asserts
74 #if GAIA_DEBUG
75 #define GAIA_ASSERT_ENABLED 1
76 #define GAIA_ASSERT(cond) \
77 { \
78 GAIA_MSVC_WARNING_PUSH() \
79 GAIA_MSVC_WARNING_DISABLE(4127) \
80 if GAIA_UNLIKELY (!(cond)) \
81 [] { \
82 GAIA_LOG_E("%s:%d: Assertion failed: '%s'.", __FILE__, __LINE__, #cond); \
83 }(); \
84 GAIA_MSVC_WARNING_POP() \
85 }
86 #define GAIA_ASSERT2(cond, msg) \
87 { \
88 GAIA_MSVC_WARNING_PUSH() \
89 GAIA_MSVC_WARNING_DISABLE(4127) \
90 if GAIA_UNLIKELY (!(cond)) \
91 [] { \
92 GAIA_LOG_E("%s:%d: Assertion failed: '%s'.", __FILE__, __LINE__, (msg)); \
93 }(); \
94 GAIA_MSVC_WARNING_POP() \
95 }
96 #else
97 #define GAIA_ASSERT_ENABLED 0
98 #define GAIA_ASSERT(cond)
99 #define GAIA_ASSERT2(cond, msg)
100 #endif
101 #endif
102#endif
103
104#if !defined(GAIA_ECS_VALIDATE_CHUNKS)
105 #define GAIA_ECS_VALIDATE_CHUNKS (GAIA_DEBUG && GAIA_DEVMODE)
106#endif
107#if !defined(GAIA_ECS_VALIDATE_ENTITY_LIST)
108 #define GAIA_ECS_VALIDATE_ENTITY_LIST (GAIA_DEBUG && GAIA_DEVMODE)
109#endif
110#if !defined(GAIA_ECS_VALIDATE_ARCHETYPE_GRAPH)
111 #define GAIA_ECS_VALIDATE_ARCHETYPE_GRAPH (GAIA_DEBUG && GAIA_DEVMODE)
112#endif
113
114//------------------------------------------------------------------------------
115// Prefetching
116//------------------------------------------------------------------------------
117
118namespace gaia {
119
132
134 GAIA_FORCEINLINE void prefetch(const void* x, int hint) {
135#if GAIA_USE_PREFETCH
136 #if GAIA_COMPILER_CLANG
137 // In the gcc version of prefetch(), hint is only a constant _after_ inlining
138 // (assumed to have been successful). llvm views things differently, and
139 // checks constant-ness _before_ inlining. This leads to compilation errors
140 // with using the other version of this code with llvm.
141 //
142 // One way round this is to use a switch statement to explicitly match
143 // prefetch hint enumerations, and invoke __builtin_prefetch for each valid
144 // value. llvm's optimization removes the switch and unused case statements
145 // after inlining, so that this boils down in the end to the same as for gcc;
146 // that is, a single inlined prefetchX instruction.
147 //
148 // Note that this version of prefetch() cannot verify constant-ness of hint.
149 // If client code calls prefetch() with a variable value for hint, it will
150 // receive the full expansion of the switch below, perhaps also not inlined.
151 // This should however not be a problem in the general case of well behaved
152 // caller code that uses the supplied prefetch hint enumerations.
153 switch (hint) {
154 case PREFETCH_HINT_T1:
155 __builtin_prefetch(x, 0, PREFETCH_HINT_T1);
156 break;
157 case PREFETCH_HINT_T2:
158 __builtin_prefetch(x, 0, PREFETCH_HINT_T2);
159 break;
161 __builtin_prefetch(x, 0, PREFETCH_HINT_NTA);
162 break;
163 default:
164 __builtin_prefetch(x, 0, PREFETCH_HINT_T0);
165 break;
166 }
167 #elif GAIA_COMPILER_GCC
168 #if !defined(__i386) || defined(__SSE__)
169 if (__builtin_constant_p(hint)) {
170 __builtin_prefetch(x, 0, hint);
171 } else {
172 // Defaults to PREFETCH_HINT_T0
173 __builtin_prefetch(x);
174 }
175 #elif !GAIA_HAS_NO_INLINE_ASSEMBLY
176 // We want a __builtin_prefetch, but we build with the default -march=i386
177 // where __builtin_prefetch quietly turns into nothing.
178 // Once we crank up to -march=pentium3 or higher the __SSE__
179 // clause above will kick in with the builtin.
180 if (hint == PREFETCH_HINT_NTA)
181 asm volatile("prefetchnta (%0)" : : "r"(x));
182 #endif
183 #elif GAIA_COMPILER_MSVC && GAIA_ARCH == GAIA_ARCH_X86
184 switch (hint) {
185 case PREFETCH_HINT_T1:
186 _mm_prefetch(static_cast<const char*>(x), _MM_HINT_T1);
187 break;
188 case PREFETCH_HINT_T2:
189 _mm_prefetch(static_cast<const char*>(x), _MM_HINT_T2);
190 break;
192 _mm_prefetch(static_cast<const char*>(x), _MM_HINT_NTA);
193 break;
194 default:
195 _mm_prefetch(static_cast<const char*>(x), _MM_HINT_T0);
196 break;
197 }
198 #else
199 (void)x;
200 (void)hint;
201 // Not implemented. Not critical, so we can stay silent about it.
202 #endif
203#else
204 (void)x;
205 (void)hint;
206 // Not implemented. Not critical, so we can stay silent about it.
207#endif
208 }
209
210} // namespace gaia
Checks if endianess was detected correctly at compile-time.
Definition bitset.h:9
PrefetchHint
Definition config_core_end.h:120
@ PREFETCH_HINT_T2
Temporal data with respect to second level cache misses — prefetch data into L3 cache and higher,...
Definition config_core_end.h:127
@ PREFETCH_HINT_NTA
Non-temporal data with respect to all cache levels — prefetch data into non-temporal cache structure ...
Definition config_core_end.h:130
@ PREFETCH_HINT_T1
Temporal data with respect to first level cache misses — prefetch data into L2 cache and higher.
Definition config_core_end.h:124
@ PREFETCH_HINT_T0
Temporal data — prefetch data into all levels of the cache hierarchy.
Definition config_core_end.h:122
GAIA_FORCEINLINE void prefetch(const void *x, int hint)
Prefetch intrinsic.
Definition config_core_end.h:134