102d170cfSs.makeev_local // The MIT License (MIT) 202d170cfSs.makeev_local // 302d170cfSs.makeev_local // Copyright (c) 2015 Sergey Makeev, Vadim Slyusarev 402d170cfSs.makeev_local // 502d170cfSs.makeev_local // Permission is hereby granted, free of charge, to any person obtaining a copy 602d170cfSs.makeev_local // of this software and associated documentation files (the "Software"), to deal 702d170cfSs.makeev_local // in the Software without restriction, including without limitation the rights 802d170cfSs.makeev_local // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 902d170cfSs.makeev_local // copies of the Software, and to permit persons to whom the Software is 1002d170cfSs.makeev_local // furnished to do so, subject to the following conditions: 1102d170cfSs.makeev_local // 1202d170cfSs.makeev_local // The above copyright notice and this permission notice shall be included in 1302d170cfSs.makeev_local // all copies or substantial portions of the Software. 1402d170cfSs.makeev_local // 1502d170cfSs.makeev_local // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1602d170cfSs.makeev_local // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1702d170cfSs.makeev_local // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1802d170cfSs.makeev_local // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1902d170cfSs.makeev_local // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 2002d170cfSs.makeev_local // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 2102d170cfSs.makeev_local // THE SOFTWARE. 2202d170cfSs.makeev_local 2302d170cfSs.makeev_local #pragma once 2402d170cfSs.makeev_local 2502d170cfSs.makeev_local 2602d170cfSs.makeev_local // Target Platform 2702d170cfSs.makeev_local //////////////////////////////////////////////////////////////////////// 2802d170cfSs.makeev_local #if _WIN32 2902d170cfSs.makeev_local 3002d170cfSs.makeev_local #define MT_PLATFORM_WINDOWS (1) 3102d170cfSs.makeev_local 3202d170cfSs.makeev_local #elif __APPLE_CC__ 3302d170cfSs.makeev_local 3402d170cfSs.makeev_local #define MT_PLATFORM_OSX (1) 3502d170cfSs.makeev_local 3602d170cfSs.makeev_local #else 3702d170cfSs.makeev_local 3802d170cfSs.makeev_local #define MT_PLATFORM_POSIX (1) 3902d170cfSs.makeev_local 4002d170cfSs.makeev_local #endif 4102d170cfSs.makeev_local 4202d170cfSs.makeev_local 4302d170cfSs.makeev_local // Compiler support for SSE intrinsics 4402d170cfSs.makeev_local //////////////////////////////////////////////////////////////////////// 4502d170cfSs.makeev_local #if (defined(__SSE__) || defined(_M_IX86) || defined(_M_X64)) 4602d170cfSs.makeev_local 4702d170cfSs.makeev_local #define MT_SSE_INTRINSICS_SUPPORTED (1) 4802d170cfSs.makeev_local 4902d170cfSs.makeev_local #endif 5002d170cfSs.makeev_local 5102d170cfSs.makeev_local 5202d170cfSs.makeev_local // Compiler support for C++11 5302d170cfSs.makeev_local //////////////////////////////////////////////////////////////////////// 5402d170cfSs.makeev_local 5502d170cfSs.makeev_local #if __STDC_VERSION__ >= 201112L 5602d170cfSs.makeev_local 5702d170cfSs.makeev_local #define MT_CPP11_SUPPORTED (1) 5802d170cfSs.makeev_local 5902d170cfSs.makeev_local #endif 6002d170cfSs.makeev_local 6102d170cfSs.makeev_local 6202d170cfSs.makeev_local // Compiler family 6302d170cfSs.makeev_local //////////////////////////////////////////////////////////////////////// 6402d170cfSs.makeev_local 6502d170cfSs.makeev_local #ifdef __clang__ 6602d170cfSs.makeev_local 6702d170cfSs.makeev_local #define MT_CLANG_COMPILER_FAMILY (1) 6802d170cfSs.makeev_local #define MT_GCC_COMPILER_FAMILY (1) 6902d170cfSs.makeev_local 7002d170cfSs.makeev_local #elif __GNUC__ 7102d170cfSs.makeev_local 7202d170cfSs.makeev_local #define MT_GCC_COMPILER_FAMILY (1) 7302d170cfSs.makeev_local 7402d170cfSs.makeev_local #elif defined(_MSC_VER) 7502d170cfSs.makeev_local 7602d170cfSs.makeev_local #define MT_MSVC_COMPILER_FAMILY (1) 7702d170cfSs.makeev_local 7802d170cfSs.makeev_local #endif 7902d170cfSs.makeev_local 8002d170cfSs.makeev_local 8102d170cfSs.makeev_local // Debug / Release 8202d170cfSs.makeev_local //////////////////////////////////////////////////////////////////////// 8302d170cfSs.makeev_local 84012b0cafSSergey Makeev #if defined(_DEBUG) || defined(DEBUG) 8502d170cfSs.makeev_local 8602d170cfSs.makeev_local #define MT_DEBUG (1) 8702d170cfSs.makeev_local 8802d170cfSs.makeev_local #else 8902d170cfSs.makeev_local 9002d170cfSs.makeev_local #define MT_RELEASE (1) 9102d170cfSs.makeev_local 9202d170cfSs.makeev_local #endif 931e78cb24Ss.makeev_local 941e78cb24Ss.makeev_local 951e78cb24Ss.makeev_local // x64 / x86 961e78cb24Ss.makeev_local //////////////////////////////////////////////////////////////////////// 971e78cb24Ss.makeev_local #if defined(_M_X64) 981e78cb24Ss.makeev_local 991e78cb24Ss.makeev_local #define MT_PTR64 (1) 1001e78cb24Ss.makeev_local 1011e78cb24Ss.makeev_local #endif 102721f8c0bSs.makeev_local 1039c716f68Ss.makeev_local 1049c716f68Ss.makeev_local 105721f8c0bSs.makeev_local // 106721f8c0bSs.makeev_local // x86-64 CPU has strong memory model, so we don't need to define acquire/release fences here 107721f8c0bSs.makeev_local // 108721f8c0bSs.makeev_local 109721f8c0bSs.makeev_local // 110721f8c0bSs.makeev_local // Acquire semantics is a property which can only apply to operations which read from shared memory, 111721f8c0bSs.makeev_local // whether they are read-modify-write operations or plain loads. The operation is then considered a read-acquire. 112721f8c0bSs.makeev_local // Acquire semantics prevent memory reordering of the read-acquire with any read or write operation which follows it in program order. 113721f8c0bSs.makeev_local // 114721f8c0bSs.makeev_local // Acquire fence is a fence which does not permit subsequent memory operations to be advanced before it. 115721f8c0bSs.makeev_local // 1169c716f68Ss.makeev_local 1179c716f68Ss.makeev_local #if MT_MSVC_COMPILER_FAMILY 1189c716f68Ss.makeev_local // MSVC compiler barrier 1199c716f68Ss.makeev_local #define mt_acquire_fence() _ReadWriteBarrier() 1209c716f68Ss.makeev_local #elif MT_GCC_COMPILER_FAMILY 1219c716f68Ss.makeev_local // GCC compiler barrier 1229c716f68Ss.makeev_local #define mt_acquire_fence() asm volatile("" ::: "memory") 1239c716f68Ss.makeev_local #else 1249c716f68Ss.makeev_local #error Platform is not supported! 1259c716f68Ss.makeev_local #endif 126721f8c0bSs.makeev_local 127721f8c0bSs.makeev_local 128721f8c0bSs.makeev_local 129721f8c0bSs.makeev_local // 130721f8c0bSs.makeev_local // Release semantics is a property which can only apply to operations which write to shared memory, 131721f8c0bSs.makeev_local // whether they are read-modify-write operations or plain stores. The operation is then considered a write-release. 132721f8c0bSs.makeev_local // Release semantics prevent memory reordering of the write-release with any read or write operation which precedes it in program order. 133721f8c0bSs.makeev_local // 134721f8c0bSs.makeev_local // Release fence is a fence which does not permit preceding memory operations to be delayed past it. 135721f8c0bSs.makeev_local // 1369c716f68Ss.makeev_local 1379c716f68Ss.makeev_local #if MT_MSVC_COMPILER_FAMILY 1389c716f68Ss.makeev_local // MSVC compiler barrier 1399c716f68Ss.makeev_local #define mt_release_fence() _ReadWriteBarrier() 1409c716f68Ss.makeev_local #elif MT_GCC_COMPILER_FAMILY 1419c716f68Ss.makeev_local // GCC compiler barrier 1429c716f68Ss.makeev_local #define mt_release_fence() asm volatile("" ::: "memory") 1439c716f68Ss.makeev_local #else 1449c716f68Ss.makeev_local #error Platform is not supported! 1459c716f68Ss.makeev_local #endif 146721f8c0bSs.makeev_local 147b2d53818Ss.makeev_local 148b2d53818Ss.makeev_local 149b2d53818Ss.makeev_local // 150b2d53818Ss.makeev_local // mt_forceinline 151b2d53818Ss.makeev_local // 152b2d53818Ss.makeev_local #if MT_MSVC_COMPILER_FAMILY 153b2d53818Ss.makeev_local #define mt_forceinline __forceinline 154b2d53818Ss.makeev_local #elif MT_GCC_COMPILER_FAMILY 155b2d53818Ss.makeev_local #define mt_forceinline __attribute__((always_inline)) inline 156b2d53818Ss.makeev_local #else 15711946a49SSergey Makeev #error Can not define mt_forceinline. Unknown platform. 158b2d53818Ss.makeev_local #endif 159b2d53818Ss.makeev_local 160436acff3Ss.makeev_local 161*01616bcfSs.makeev_local // Enable Windows XP support (disable conditional variables) 162436acff3Ss.makeev_local //#if !MT_PTR64 && MT_PLATFORM_WINDOWS 163436acff3Ss.makeev_local //#define MT_ENABLE_LEGACY_WINDOWSXP_SUPPORT (1) 164436acff3Ss.makeev_local //#endif 165436acff3Ss.makeev_local 166