-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathTSPlatform.h
237 lines (161 loc) · 4.51 KB
/
TSPlatform.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
//
// This file is part of the Terathon Common Library, by Eric Lengyel.
// Copyright 1999-2024, Terathon Software LLC
//
// This software is distributed under the MIT License.
// Separate proprietary licenses are available from Terathon Software.
//
#ifndef TSPlatform_h
#define TSPlatform_h
#if defined(TERATHON_EXPORT)
#if defined(_MSC_VER)
#define TERATHON_API __declspec(dllexport)
#elif defined(__GNUC__)
#define TERATHON_API __attribute__((visibility("default")))
#else
#define TERATHON_API
#endif
#elif defined(TERATHON_IMPORT)
#if defined(_MSC_VER)
#define TERATHON_API __declspec(dllimport)
#else
#define TERATHON_API
#endif
#else
#define TERATHON_API
#endif
#ifdef TERATHON_NO_SYSTEM
void *__cdecl operator new(size_t);
void *__cdecl operator new[](size_t);
void __cdecl operator delete(void *);
void __cdecl operator delete[](void *);
inline void *__cdecl operator new(size_t, void *ptr)
{
return (ptr);
}
inline void *__cdecl operator new[](size_t, void *ptr)
{
return (ptr);
}
inline void __cdecl operator delete(void *, void *)
{
}
inline void __cdecl operator delete[](void *, void *)
{
}
extern "C"
{
void *__cdecl memcpy(void *, const void *, size_t);
#pragma intrinsic(memcpy)
void *__cdecl memset(void *, int, size_t);
#pragma intrinsic(memset)
}
#else
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4530) // C++ exception handler used, but unwind semantics are not enabled
#pragma warning(disable: 4577) // 'noexcept' used with no exception handling mode specified
#endif
#include <new>
#include <string.h>
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
#endif
namespace Terathon
{
#if defined(_MSC_VER)
typedef signed char int8;
typedef short int16;
typedef int int32;
typedef __int64 int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned __int64 uint64;
#if defined(_M_X64) || defined(_M_ARM64)
typedef __int64 machine;
typedef unsigned __int64 umachine;
typedef unsigned __int64 machine_address;
#else
typedef int machine;
typedef unsigned int umachine;
typedef unsigned int machine_address;
#endif
#define restrict __restrict
#pragma warning(disable: 4100) // unreferenced formal parameter
#pragma warning(disable: 4244) // conversion, possible loss of data
#pragma warning(disable: 4324) // structure was padded due to alignment specifier
#pragma warning(disable: 4458) // declaration hides class member
#pragma warning(disable: 4522) // multiple assignment operators specified
#elif defined(__ORBIS__) || defined(__PROSPERO__)
typedef signed char int8;
typedef short int16;
typedef int int32;
typedef long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long uint64;
typedef long machine;
typedef unsigned long umachine;
typedef unsigned long machine_address;
#elif defined(__GNUC__)
typedef signed char int8;
typedef short int16;
typedef int int32;
typedef long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
#if defined(__LP64__) || defined(_WIN64)
typedef long long machine;
typedef unsigned long long umachine;
typedef unsigned long long machine_address;
#else
typedef int machine;
typedef unsigned int umachine;
typedef unsigned int machine_address;
#endif
#if !defined(restrict)
#define restrict __restrict__
#endif
#endif
inline machine_address GetPointerAddress(const volatile void *ptr)
{
return (reinterpret_cast<machine_address>(ptr));
}
inline const float& asfloat(const int32& i)
{
return (reinterpret_cast<const float&>(i));
}
inline const float& asfloat(const uint32& i)
{
return (reinterpret_cast<const float&>(i));
}
inline const int32& asint(const float& f)
{
return (reinterpret_cast<const int32&>(f));
}
inline const uint32& asuint(const float& f)
{
return (reinterpret_cast<const uint32&>(f));
}
#undef CopyMemory
#undef FillMemory
#undef ClearMemory
inline void CopyMemory(const void *source, void *dest, uint32 size)
{
memcpy(dest, source, size);
}
inline void FillMemory(void *ptr, uint32 size, uint8 value)
{
memset(ptr, value, size);
}
inline void ClearMemory(void *ptr, uint32 size)
{
memset(ptr, 0, size);
}
}
#endif