Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/embree/common/sys/platform.h
9912 views
1
// Copyright 2009-2021 Intel Corporation
2
// SPDX-License-Identifier: Apache-2.0
3
4
#pragma once
5
6
#if !defined(_CRT_SECURE_NO_WARNINGS)
7
#define _CRT_SECURE_NO_WARNINGS
8
#endif
9
10
#include <cstddef>
11
#include <cassert>
12
#include <cstdlib>
13
#include <cstdio>
14
#include <memory>
15
#include <stdexcept>
16
#include <iostream>
17
#include <iomanip>
18
#include <fstream>
19
#include <string>
20
#include <cstring>
21
#include <stdint.h>
22
#include <functional>
23
#include <mutex>
24
25
#if defined(EMBREE_SYCL_SUPPORT)
26
27
#define __SYCL_USE_NON_VARIADIC_SPIRV_OCL_PRINTF__
28
29
#pragma clang diagnostic push
30
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
31
#pragma clang diagnostic ignored "-W#pragma-messages"
32
33
#include <sycl/sycl.hpp>
34
35
#pragma clang diagnostic pop
36
37
#include "sycl.h"
38
39
#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__)
40
#define CONSTANT __attribute__((opencl_constant))
41
#else
42
#define CONSTANT
43
#endif
44
45
#endif
46
47
48
////////////////////////////////////////////////////////////////////////////////
49
/// detect platform
50
////////////////////////////////////////////////////////////////////////////////
51
52
/* detect 32 or 64 Intel platform */
53
#if defined(__x86_64__) || defined(__ia64__) || defined(_M_X64)
54
#define __X86_64__
55
#define __X86_ASM__
56
#elif defined(__i386__) || defined(_M_IX86)
57
#define __X86_ASM__
58
#endif
59
60
/* detect 64 bit platform */
61
#if defined(__X86_64__) || defined(__aarch64__)
62
#define __64BIT__
63
#endif
64
65
/* detect Linux platform */
66
#if defined(linux) || defined(__linux__) || defined(__LINUX__)
67
# if !defined(__LINUX__)
68
# define __LINUX__
69
# endif
70
# if !defined(__UNIX__)
71
# define __UNIX__
72
# endif
73
#endif
74
75
/* detect FreeBSD platform */
76
#if defined(__FreeBSD__) || defined(__FREEBSD__)
77
# if !defined(__FREEBSD__)
78
# define __FREEBSD__
79
# endif
80
# if !defined(__UNIX__)
81
# define __UNIX__
82
# endif
83
#endif
84
85
/* detect Windows 95/98/NT/2000/XP/Vista/7/8/10 platform */
86
#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)) && !defined(__CYGWIN__)
87
# if !defined(__WIN32__)
88
# define __WIN32__
89
# endif
90
#endif
91
92
/* detect Cygwin platform */
93
#if defined(__CYGWIN__)
94
# if !defined(__UNIX__)
95
# define __UNIX__
96
# endif
97
#endif
98
99
/* detect MAC OS X platform */
100
#if defined(__APPLE__) || defined(MACOSX) || defined(__MACOSX__)
101
# if !defined(__MACOSX__)
102
# define __MACOSX__
103
# endif
104
# if !defined(__UNIX__)
105
# define __UNIX__
106
# endif
107
#endif
108
109
/* try to detect other Unix systems */
110
#if defined(__unix__) || defined (unix) || defined(__unix) || defined(_unix)
111
# if !defined(__UNIX__)
112
# define __UNIX__
113
# endif
114
#endif
115
116
////////////////////////////////////////////////////////////////////////////////
117
/// Macros
118
////////////////////////////////////////////////////////////////////////////////
119
120
#ifdef __WIN32__
121
# if defined(EMBREE_STATIC_LIB)
122
# define dll_export
123
# define dll_import
124
# else
125
# define dll_export __declspec(dllexport)
126
# define dll_import __declspec(dllimport)
127
# endif
128
#else
129
# define dll_export __attribute__ ((visibility ("default")))
130
# define dll_import
131
#endif
132
133
#if defined(__WIN32__) && !defined(__MINGW32__)
134
#if !defined(__noinline)
135
#define __noinline __declspec(noinline)
136
#endif
137
//#define __forceinline __forceinline
138
//#define __restrict __restrict
139
#if defined(__INTEL_COMPILER)
140
#define __restrict__ __restrict
141
#else
142
#define __restrict__ //__restrict // causes issues with MSVC
143
#endif
144
#if !defined(__thread) && !defined(__INTEL_LLVM_COMPILER)
145
#define __thread __declspec(thread)
146
#endif
147
#if !defined(__aligned)
148
#define __aligned(...) __declspec(align(__VA_ARGS__))
149
#endif
150
//#define __FUNCTION__ __FUNCTION__
151
#define debugbreak() __debugbreak()
152
153
#else
154
#if !defined(__noinline)
155
#define __noinline __attribute__((noinline))
156
#endif
157
#if !defined(__forceinline)
158
#define __forceinline inline __attribute__((always_inline))
159
#endif
160
//#define __restrict __restrict
161
//#define __thread __thread
162
#if !defined(__aligned)
163
#define __aligned(...) __attribute__((aligned(__VA_ARGS__)))
164
#endif
165
#if !defined(__FUNCTION__)
166
#define __FUNCTION__ __PRETTY_FUNCTION__
167
#endif
168
#define debugbreak() asm ("int $3")
169
#endif
170
171
#if defined(__clang__) || defined(__GNUC__)
172
#define MAYBE_UNUSED __attribute__((unused))
173
#else
174
#define MAYBE_UNUSED
175
#endif
176
177
#if !defined(_unused)
178
#define _unused(x) ((void)(x))
179
#endif
180
181
#if defined(_MSC_VER) && (_MSC_VER < 1900) // before VS2015 deleted functions are not supported properly
182
#define DELETED
183
#else
184
#define DELETED = delete
185
#endif
186
187
#if !defined(likely)
188
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) || defined(__SYCL_DEVICE_ONLY__)
189
#define likely(expr) (expr)
190
#define unlikely(expr) (expr)
191
#else
192
#define likely(expr) __builtin_expect((bool)(expr),true )
193
#define unlikely(expr) __builtin_expect((bool)(expr),false)
194
#endif
195
#endif
196
197
////////////////////////////////////////////////////////////////////////////////
198
/// Error handling and debugging
199
////////////////////////////////////////////////////////////////////////////////
200
201
/* debug printing macros */
202
#define STRING(x) #x
203
#define TOSTRING(x) STRING(x)
204
#define PING embree_cout_uniform << __FILE__ << " (" << __LINE__ << "): " << __FUNCTION__ << embree_endl
205
#define PRINT(x) embree_cout << STRING(x) << " = " << (x) << embree_endl
206
#define PRINT2(x,y) embree_cout << STRING(x) << " = " << (x) << ", " << STRING(y) << " = " << (y) << embree_endl
207
#define PRINT3(x,y,z) embree_cout << STRING(x) << " = " << (x) << ", " << STRING(y) << " = " << (y) << ", " << STRING(z) << " = " << (z) << embree_endl
208
#define PRINT4(x,y,z,w) embree_cout << STRING(x) << " = " << (x) << ", " << STRING(y) << " = " << (y) << ", " << STRING(z) << " = " << (z) << ", " << STRING(w) << " = " << (w) << embree_endl
209
210
#define UPRINT(x) embree_cout_uniform << STRING(x) << " = " << (x) << embree_endl
211
#define UPRINT2(x,y) embree_cout_uniform << STRING(x) << " = " << (x) << ", " << STRING(y) << " = " << (y) << embree_endl
212
#define UPRINT3(x,y,z) embree_cout_uniform << STRING(x) << " = " << (x) << ", " << STRING(y) << " = " << (y) << ", " << STRING(z) << " = " << (z) << embree_endl
213
#define UPRINT4(x,y,z,w) embree_cout_uniform << STRING(x) << " = " << (x) << ", " << STRING(y) << " = " << (y) << ", " << STRING(z) << " = " << (z) << ", " << STRING(w) << " = " << (w) << embree_endl
214
215
#if defined(DEBUG) // only report file and line in debug mode
216
#define THROW_RUNTIME_ERROR(str) \
217
printf("%s (%d): %s", __FILE__, __LINE__, std::string(str).c_str()), abort();
218
//throw std::runtime_error(std::string(__FILE__) + " (" + toString(__LINE__) + "): " + std::string(str));
219
#else
220
#define THROW_RUNTIME_ERROR(str) \
221
abort(); //throw std::runtime_error(str);
222
#endif
223
224
#define FATAL(x) THROW_RUNTIME_ERROR(x)
225
#define WARNING(x) { std::cerr << "Warning: " << x << embree_endl << std::flush; }
226
227
#define NOT_IMPLEMENTED FATAL(std::string(__FUNCTION__) + " not implemented")
228
229
////////////////////////////////////////////////////////////////////////////////
230
/// Basic types
231
////////////////////////////////////////////////////////////////////////////////
232
233
/* default floating-point type */
234
namespace embree {
235
typedef float real;
236
}
237
238
/* windows does not have ssize_t */
239
#if defined(__WIN32__)
240
#if defined(__64BIT__)
241
typedef int64_t ssize_t;
242
#else
243
typedef int32_t ssize_t;
244
#endif
245
#endif
246
247
////////////////////////////////////////////////////////////////////////////////
248
/// Basic utility functions
249
////////////////////////////////////////////////////////////////////////////////
250
251
__forceinline std::string toString(long long value) {
252
return std::to_string(value);
253
}
254
255
////////////////////////////////////////////////////////////////////////////////
256
/// Disable some compiler warnings
257
////////////////////////////////////////////////////////////////////////////////
258
259
#if defined(__INTEL_COMPILER)
260
//#pragma warning(disable:265 ) // floating-point operation result is out of range
261
//#pragma warning(disable:383 ) // value copied to temporary, reference to temporary used
262
//#pragma warning(disable:869 ) // parameter was never referenced
263
//#pragma warning(disable:981 ) // operands are evaluated in unspecified order
264
//#pragma warning(disable:1418) // external function definition with no prior declaration
265
//#pragma warning(disable:1419) // external declaration in primary source file
266
//#pragma warning(disable:1572) // floating-point equality and inequality comparisons are unreliable
267
//#pragma warning(disable:94 ) // the size of an array must be greater than zero
268
//#pragma warning(disable:1599) // declaration hides parameter
269
//#pragma warning(disable:424 ) // extra ";" ignored
270
#pragma warning(disable:2196) // routine is both "inline" and "noinline"
271
//#pragma warning(disable:177 ) // label was declared but never referenced
272
//#pragma warning(disable:114 ) // function was referenced but not defined
273
//#pragma warning(disable:819 ) // template nesting depth does not match the previous declaration of function
274
#pragma warning(disable:15335) // was not vectorized: vectorization possible but seems inefficient
275
#endif
276
277
#if defined(_MSC_VER)
278
//#pragma warning(disable:4200) // nonstandard extension used : zero-sized array in struct/union
279
#pragma warning(disable:4800) // forcing value to bool 'true' or 'false' (performance warning)
280
//#pragma warning(disable:4267) // '=' : conversion from 'size_t' to 'unsigned long', possible loss of data
281
#pragma warning(disable:4244) // 'argument' : conversion from 'ssize_t' to 'unsigned int', possible loss of data
282
#pragma warning(disable:4267) // conversion from 'size_t' to 'const int', possible loss of data
283
//#pragma warning(disable:4355) // 'this' : used in base member initializer list
284
//#pragma warning(disable:391 ) // '<=' : signed / unsigned mismatch
285
//#pragma warning(disable:4018) // '<' : signed / unsigned mismatch
286
//#pragma warning(disable:4305) // 'initializing' : truncation from 'double' to 'float'
287
//#pragma warning(disable:4068) // unknown pragma
288
//#pragma warning(disable:4146) // unary minus operator applied to unsigned type, result still unsigned
289
//#pragma warning(disable:4838) // conversion from 'unsigned int' to 'const int' requires a narrowing conversion)
290
//#pragma warning(disable:4227) // anachronism used : qualifiers on reference are ignored
291
#pragma warning(disable:4503) // decorated name length exceeded, name was truncated
292
#pragma warning(disable:4180) // qualifier applied to function type has no meaning; ignored
293
#pragma warning(disable:4258) // definition from the for loop is ignored; the definition from the enclosing scope is used
294
295
# if _MSC_VER < 1910 // prior to Visual studio 2017 (V141)
296
# pragma warning(disable:4101) // warning C4101: 'x': unreferenced local variable // a compiler bug issues wrong warnings
297
# pragma warning(disable:4789) // buffer '' of size 8 bytes will be overrun; 32 bytes will be written starting at offset 0
298
# endif
299
300
#endif
301
302
#if defined(__clang__) && !defined(__INTEL_COMPILER)
303
//#pragma clang diagnostic ignored "-Wunknown-pragmas"
304
//#pragma clang diagnostic ignored "-Wunused-variable"
305
//#pragma clang diagnostic ignored "-Wreorder"
306
//#pragma clang diagnostic ignored "-Wmicrosoft"
307
//#pragma clang diagnostic ignored "-Wunused-private-field"
308
//#pragma clang diagnostic ignored "-Wunused-local-typedef"
309
//#pragma clang diagnostic ignored "-Wunused-function"
310
//#pragma clang diagnostic ignored "-Wnarrowing"
311
//#pragma clang diagnostic ignored "-Wc++11-narrowing"
312
//#pragma clang diagnostic ignored "-Wdeprecated-register"
313
//#pragma clang diagnostic ignored "-Wdeprecated-declarations"
314
#endif
315
316
#if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__)
317
#pragma GCC diagnostic ignored "-Wpragmas"
318
//#pragma GCC diagnostic ignored "-Wnarrowing"
319
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
320
//#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
321
//#pragma GCC diagnostic ignored "-Warray-bounds"
322
#pragma GCC diagnostic ignored "-Wattributes"
323
#pragma GCC diagnostic ignored "-Wmisleading-indentation"
324
#pragma GCC diagnostic ignored "-Wsign-compare"
325
#pragma GCC diagnostic ignored "-Wparentheses"
326
#endif
327
328
#if defined(__clang__) && defined(__WIN32__)
329
#pragma clang diagnostic ignored "-Wunused-parameter"
330
#pragma clang diagnostic ignored "-Wmicrosoft-cast"
331
#pragma clang diagnostic ignored "-Wmicrosoft-enum-value"
332
#pragma clang diagnostic ignored "-Wmicrosoft-include"
333
#pragma clang diagnostic ignored "-Wunused-function"
334
#pragma clang diagnostic ignored "-Wunknown-pragmas"
335
#endif
336
337
/* disabling deprecated warning, please use only where use of deprecated Embree API functions is desired */
338
#if defined(__WIN32__) && defined(__INTEL_COMPILER)
339
#define DISABLE_DEPRECATED_WARNING __pragma(warning (disable: 1478)) // warning: function was declared deprecated
340
#define ENABLE_DEPRECATED_WARNING __pragma(warning (enable: 1478)) // warning: function was declared deprecated
341
#elif defined(__INTEL_COMPILER)
342
#define DISABLE_DEPRECATED_WARNING _Pragma("warning (disable: 1478)") // warning: function was declared deprecated
343
#define ENABLE_DEPRECATED_WARNING _Pragma("warning (enable : 1478)") // warning: function was declared deprecated
344
#elif defined(__clang__)
345
#define DISABLE_DEPRECATED_WARNING _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") // warning: xxx is deprecated
346
#define ENABLE_DEPRECATED_WARNING _Pragma("clang diagnostic warning \"-Wdeprecated-declarations\"") // warning: xxx is deprecated
347
#elif defined(__GNUC__)
348
#define DISABLE_DEPRECATED_WARNING _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") // warning: xxx is deprecated
349
#define ENABLE_DEPRECATED_WARNING _Pragma("GCC diagnostic warning \"-Wdeprecated-declarations\"") // warning: xxx is deprecated
350
#elif defined(_MSC_VER)
351
#define DISABLE_DEPRECATED_WARNING __pragma(warning (disable: 4996)) // warning: function was declared deprecated
352
#define ENABLE_DEPRECATED_WARNING __pragma(warning (enable : 4996)) // warning: function was declared deprecated
353
#endif
354
355
////////////////////////////////////////////////////////////////////////////////
356
/// SYCL specific
357
////////////////////////////////////////////////////////////////////////////////
358
359
360
#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__)
361
362
#define sycl_printf0(format, ...) { \
363
static const CONSTANT char fmt[] = format; \
364
if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true))) \
365
sycl::ext::oneapi::experimental::printf(fmt, __VA_ARGS__ ); \
366
}
367
368
#define sycl_printf0_(format) { \
369
static const CONSTANT char fmt[] = format; \
370
if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true))) \
371
sycl::ext::oneapi::experimental::printf(fmt); \
372
}
373
374
#else
375
376
#define sycl_printf0(format, ...) { \
377
static const CONSTANT char fmt[] = format; \
378
sycl::ext::oneapi::experimental::printf(fmt, __VA_ARGS__ ); \
379
}
380
381
#define sycl_printf0_(format) { \
382
static const CONSTANT char fmt[] = format; \
383
sycl::ext::oneapi::experimental::printf(fmt); \
384
}
385
386
#endif
387
388
#define sycl_printf(format, ...) { \
389
static const CONSTANT char fmt[] = format; \
390
sycl::ext::oneapi::experimental::printf(fmt, __VA_ARGS__ ); \
391
}
392
393
#define sycl_printf_(format) { \
394
static const CONSTANT char fmt[] = format; \
395
sycl::ext::oneapi::experimental::printf(fmt); \
396
}
397
398
#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__)
399
400
namespace embree
401
{
402
struct sycl_ostream_ {
403
sycl_ostream_ (bool uniform) : uniform(uniform) {}
404
bool uniform = false;
405
};
406
struct sycl_endl_ {};
407
408
#define embree_ostream embree::sycl_ostream_
409
#define embree_cout embree::sycl_ostream_(false)
410
#define embree_cout_uniform embree::sycl_ostream_(true)
411
#define embree_endl embree::sycl_endl_()
412
413
inline sycl_ostream_ operator <<(sycl_ostream_ cout, int i)
414
{
415
if (cout.uniform) {
416
if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true)))
417
sycl_printf("%i",i);
418
}
419
else
420
sycl_printf("%i ",i);
421
422
return cout;
423
}
424
425
inline sycl_ostream_ operator <<(sycl_ostream_ cout, unsigned int i)
426
{
427
if (cout.uniform) {
428
if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true)))
429
sycl_printf("%u",i);
430
} else
431
sycl_printf("%u ",i);
432
433
return cout;
434
}
435
436
inline sycl_ostream_ operator <<(sycl_ostream_ cout, float f)
437
{
438
if (cout.uniform) {
439
if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true)))
440
sycl_printf("%f",f);
441
} else
442
sycl_printf("%f ",f);
443
444
return cout;
445
}
446
447
inline sycl_ostream_ operator <<(sycl_ostream_ cout, double d)
448
{
449
if (cout.uniform) {
450
if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true)))
451
sycl_printf("%f",d);
452
} else
453
sycl_printf("%f ",d);
454
455
return cout;
456
}
457
458
inline sycl_ostream_ operator <<(sycl_ostream_ cout, uint64_t l)
459
{
460
if (cout.uniform) {
461
if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true)))
462
sycl_printf("%lu",l);
463
} else
464
sycl_printf("%lu ",l);
465
466
return cout;
467
}
468
469
inline sycl_ostream_ operator <<(sycl_ostream_ cout, long l)
470
{
471
if (cout.uniform) {
472
if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true)))
473
sycl_printf("%l",l);
474
} else
475
sycl_printf("%l ",l);
476
477
return cout;
478
}
479
480
481
inline sycl_ostream_ operator <<(sycl_ostream_ cout, void* p)
482
{
483
if (cout.uniform) {
484
if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true)))
485
sycl_printf("%p",p);
486
} else
487
sycl_printf("%p ",p);
488
489
return cout;
490
}
491
492
inline sycl_ostream_ operator <<(sycl_ostream_ cout, const char* c)
493
{
494
if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true)))
495
sycl_printf("%s",c);
496
return cout;
497
}
498
499
inline sycl_ostream_ operator <<(sycl_ostream_ cout, sycl_endl_)
500
{
501
if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true)))
502
sycl_printf_("\n");
503
return cout;
504
}
505
}
506
507
#else
508
509
#define embree_ostream std::ostream&
510
#define embree_cout std::cout
511
#define embree_cout_uniform std::cout
512
#define embree_endl std::endl
513
514
#endif
515
516
#if defined(EMBREE_SYCL_SUPPORT)
517
518
/* printing out sycle vector types */
519
__forceinline embree_ostream operator<<(embree_ostream out, const sycl::float4& v) {
520
return out << "(" << v.x() << "," << v.y() << "," << v.z() << "," << v.w() << ")";
521
}
522
__forceinline embree_ostream operator<<(embree_ostream out, const sycl::float3& v) {
523
return out << "(" << v.x() << "," << v.y() << "," << v.z() << ")";
524
}
525
__forceinline embree_ostream operator<<(embree_ostream out, const sycl::float2& v) {
526
return out << "(" << v.x() << "," << v.y() << ")";
527
}
528
__forceinline embree_ostream operator<<(embree_ostream out, const sycl::int4& v) {
529
return out << "(" << v.x() << "," << v.y() << "," << v.z() << "," << v.w() << ")";
530
}
531
__forceinline embree_ostream operator<<(embree_ostream out, const sycl::int3& v) {
532
return out << "(" << v.x() << "," << v.y() << "," << v.z() << ")";
533
}
534
__forceinline embree_ostream operator<<(embree_ostream out, const sycl::int2& v) {
535
return out << "(" << v.x() << "," << v.y() << ")";
536
}
537
__forceinline embree_ostream operator<<(embree_ostream out, const sycl::uint4& v) {
538
return out << "(" << v.x() << "," << v.y() << "," << v.z() << "," << v.w() << ")";
539
}
540
__forceinline embree_ostream operator<<(embree_ostream out, const sycl::uint3& v) {
541
return out << "(" << v.x() << "," << v.y() << "," << v.z() << ")";
542
}
543
__forceinline embree_ostream operator<<(embree_ostream out, const sycl::uint2& v) {
544
return out << "(" << v.x() << "," << v.y() << ")";
545
}
546
547
#endif
548
549
inline void tab(std::ostream& cout, int n) {
550
for (int i=0; i<n; i++) cout << " ";
551
}
552
553
inline std::string tab(int depth) {
554
return std::string(2*depth,' ');
555
}
556
557
////////////////////////////////////////////////////////////////////////////////
558
/// Some macros for static profiling
559
////////////////////////////////////////////////////////////////////////////////
560
561
#if defined (__GNUC__)
562
#define IACA_SSC_MARK( MARK_ID ) \
563
__asm__ __volatile__ ( \
564
"\n\t movl $"#MARK_ID", %%ebx" \
565
"\n\t .byte 0x64, 0x67, 0x90" \
566
: : : "memory" );
567
568
#define IACA_UD_BYTES __asm__ __volatile__ ("\n\t .byte 0x0F, 0x0B");
569
570
#else
571
#define IACA_UD_BYTES {__asm _emit 0x0F \
572
__asm _emit 0x0B}
573
574
#define IACA_SSC_MARK(x) {__asm mov ebx, x\
575
__asm _emit 0x64 \
576
__asm _emit 0x67 \
577
__asm _emit 0x90 }
578
579
#define IACA_VC64_START __writegsbyte(111, 111);
580
#define IACA_VC64_END __writegsbyte(222, 222);
581
582
#endif
583
584
#define IACA_START {IACA_UD_BYTES \
585
IACA_SSC_MARK(111)}
586
#define IACA_END {IACA_SSC_MARK(222) \
587
IACA_UD_BYTES}
588
589
namespace embree
590
{
591
template<typename Closure>
592
struct OnScopeExitHelper
593
{
594
OnScopeExitHelper (const Closure f) : active(true), f(f) {}
595
~OnScopeExitHelper() { if (active) f(); }
596
void deactivate() { active = false; }
597
bool active;
598
const Closure f;
599
};
600
601
template <typename Closure>
602
OnScopeExitHelper<Closure> OnScopeExit(const Closure f) {
603
return OnScopeExitHelper<Closure>(f);
604
}
605
606
#define STRING_JOIN2(arg1, arg2) DO_STRING_JOIN2(arg1, arg2)
607
#define DO_STRING_JOIN2(arg1, arg2) arg1 ## arg2
608
#define ON_SCOPE_EXIT(code) \
609
auto STRING_JOIN2(on_scope_exit_, __LINE__) = OnScopeExit([&](){code;})
610
611
template<typename Ty>
612
std::unique_ptr<Ty> make_unique(Ty* ptr) {
613
return std::unique_ptr<Ty>(ptr);
614
}
615
616
}
617
618