1 // The MIT License (MIT)
2 //
3 // 	Copyright (c) 2015 Sergey Makeev, Vadim Slyusarev
4 //
5 // 	Permission is hereby granted, free of charge, to any person obtaining a copy
6 // 	of this software and associated documentation files (the "Software"), to deal
7 // 	in the Software without restriction, including without limitation the rights
8 // 	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // 	copies of the Software, and to permit persons to whom the Software is
10 // 	furnished to do so, subject to the following conditions:
11 //
12 //  The above copyright notice and this permission notice shall be included in
13 // 	all copies or substantial portions of the Software.
14 //
15 // 	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // 	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // 	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // 	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // 	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // 	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // 	THE SOFTWARE.
22 
23 #pragma once
24 
25 
26 // Target Platform
27 ////////////////////////////////////////////////////////////////////////
28 #if   _WIN32
29 
30 #define MT_PLATFORM_WINDOWS (1)
31 
32 #elif __APPLE_CC__
33 
34 #define MT_PLATFORM_OSX (1)
35 
36 #else
37 
38 #define MT_PLATFORM_POSIX (1)
39 
40 #endif
41 
42 
43 // Compiler support for SSE intrinsics
44 ////////////////////////////////////////////////////////////////////////
45 #if (defined(__SSE__) || defined(_M_IX86) || defined(_M_X64))
46 
47 #define MT_SSE_INTRINSICS_SUPPORTED (1)
48 
49 #endif
50 
51 
52 // Compiler support for C++11
53 ////////////////////////////////////////////////////////////////////////
54 
55 #if __STDC_VERSION__ >= 201112L
56 
57 #define MT_CPP11_SUPPORTED (1)
58 
59 #endif
60 
61 
62 // Compiler family
63 ////////////////////////////////////////////////////////////////////////
64 
65 #ifdef __clang__
66 
67 #define MT_CLANG_COMPILER_FAMILY (1)
68 #define MT_GCC_COMPILER_FAMILY (1)
69 
70 #elif __GNUC__
71 
72 #define MT_GCC_COMPILER_FAMILY (1)
73 
74 #elif defined(_MSC_VER)
75 
76 #define MT_MSVC_COMPILER_FAMILY (1)
77 
78 #endif
79 
80 
81 // Debug / Release
82 ////////////////////////////////////////////////////////////////////////
83 
84 #ifdef _DEBUG
85 
86 #define MT_DEBUG (1)
87 
88 #else
89 
90 #define MT_RELEASE (1)
91 
92 #endif
93 
94 
95 // x64 / x86
96 ////////////////////////////////////////////////////////////////////////
97 #if defined(_M_X64)
98 
99 #define MT_PTR64 (1)
100 
101 #endif
102 
103 
104 
105 //
106 // x86-64 CPU has strong memory model, so we don't need to define acquire/release fences here
107 //
108 
109 //
110 // Acquire semantics is a property which can only apply to operations which read from shared memory,
111 // whether they are read-modify-write operations or plain loads. The operation is then considered a read-acquire.
112 // Acquire semantics prevent memory reordering of the read-acquire with any read or write operation which follows it in program order.
113 //
114 // Acquire fence is a fence which does not permit subsequent memory operations to be advanced before it.
115 //
116 
117 #if MT_MSVC_COMPILER_FAMILY
118 // MSVC compiler barrier
119 #define mt_acquire_fence() _ReadWriteBarrier()
120 #elif MT_GCC_COMPILER_FAMILY
121 // GCC compiler barrier
122 #define mt_acquire_fence() asm volatile("" ::: "memory")
123 #else
124 #error Platform is not supported!
125 #endif
126 
127 
128 
129 //
130 // Release semantics is a property which can only apply to operations which write to shared memory,
131 // whether they are read-modify-write operations or plain stores. The operation is then considered a write-release.
132 // Release semantics prevent memory reordering of the write-release with any read or write operation which precedes it in program order.
133 //
134 // Release fence is a fence which does not permit preceding memory operations to be delayed past it.
135 //
136 
137 #if MT_MSVC_COMPILER_FAMILY
138 // MSVC compiler barrier
139 #define mt_release_fence() _ReadWriteBarrier()
140 #elif MT_GCC_COMPILER_FAMILY
141 // GCC compiler barrier
142 #define mt_release_fence() asm volatile("" ::: "memory")
143 #else
144 #error Platform is not supported!
145 #endif
146 
147