16 #ifndef INCLUDE_NN_NLIB_PLATFORM_WIN32_H_ 17 #define INCLUDE_NN_NLIB_PLATFORM_WIN32_H_ 18 #ifndef INCLUDE_NN_NLIB_PLATFORM_H_ 19 # error do not include directly 24 #if !defined(_M_IX86) && !defined(_M_X64) && !defined(_M_AMD64) 25 #error Sorry, not supported 29 # error Use Visual Studio 2013 or later 32 #ifndef WIN32_LEAN_AND_MEAN 33 # pragma message(__FILE__ ": WIN32_LEAN_AND_MEAN not defined, compile may fail") 34 # define WIN32_LEAN_AND_MEAN 38 # pragma message(__FILE__ ": NOMINMAX not defined, compile may fail") 42 #ifndef _USE_MATH_DEFINES 43 # pragma message(__FILE__ ": _USE_MATH_DEFINES not defined, compile may fail") 44 # define _USE_MATH_DEFINES 53 #pragma intrinsic(_BitScanReverse) 54 #pragma intrinsic(_BitScanForward) 56 # pragma intrinsic(_BitScanReverse64) 57 # pragma intrinsic(_BitScanForward64) 72 # pragma message(__FILE__ ": Please update your Windows SDK") 75 #if (!defined(_M_IX86_FP) || _M_IX86_FP < 2) && !defined(_M_X64) && !defined(_M_AMD64) 76 # error /arch:SSE2 or higher must be set 88 #define NLIB_CXX11_SWAPHEADER 89 #define NLIB_CXX11_STATIC_ASSERTIONS 90 #define NLIB_CXX11_NULL_POINTER_CONSTANT 91 #define NLIB_CXX11_RVALUE_REFERENCES 92 #define NLIB_CXX11_LAMBDAS 93 #define NLIB_CXX11_UNIQUEPTR 94 #define NLIB_CXX11_EXPLICIT_VIRTUAL_OVERRIDES 95 #define NLIB_CXX11_RANGE_BASED_FOR 96 #define NLIB_CXX11_STDLIB_CHRONO 97 #define NLIB_CXX11_STDLIB_ATOMIC 98 #define NLIB_CXX11_STDLIB_ARRAY 99 #define NLIB_CXX11_STDLIB_UNORDERED 100 #define NLIB_CXX11_STDLIB_TUPLE 102 #define NLIB_HAS_NATIVE_TYPETRAITS 104 #define NLIB_CXX11_EXPLICIT_CONVERSION_OPERATORS 105 #define NLIB_CXX11_TEMPLATE_ALIAS 106 #define NLIB_CXX11_VARIADIC_TEMPLATES 107 #define NLIB_CXX11_DELEGATING_CONSTRUCTORS 108 #define NLIB_CXX11_STDLIB_RANDOM 109 #define NLIB_CXX11_DEFAULT_TEMPLATE_ARGUMENT_FOR_FUNCTION_TEMPLATES 111 # define NLIB_CXX11_CONSTEXPR 112 # define NLIB_CXX11_NOEXCEPT 113 # define NLIB_CXX11_NEW_CHARACTER_TYPES 114 # define NLIB_CXX11_ALIGNMENT_SUPPORT 115 # define NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS 120 #include <inttypes.h> 121 #if (_MSC_VER < 1900) 123 # define __func__ __FUNCTION__ 132 # define va_copy(dest, src) (dest = src) 134 #define NLIB_ALWAYS_INLINE __forceinline 135 #define NLIB_NEVER_INLINE __declspec(noinline) 136 #define NLIB_LIKELY(x) (x) 137 #define NLIB_UNLIKELY(x) (x) 138 #define NLIB_EXPECT(var, exp_value) (var) 139 #define NLIB_CHECK_RESULT 140 #define NLIB_NORETURN 142 #define NLIB_NONNULL_1 143 #define NLIB_NONNULL_2 144 #define NLIB_NONNULL_3 145 #define NLIB_NONNULL_4 146 #define NLIB_NONNULL_5 147 #define NLIB_ATTRIBUTE_MALLOC 148 #define NLIB_ATTRIBUTE_PURE 149 #define NLIB_ATTRIBUTE_CONST 150 #define NLIB_ATTRIBUTE_ALLOC_SIZE1(n) 151 #define NLIB_ATTRIBUTE_ALLOC_SIZE2(n0, n1) 152 #define NLIB_ATTRIBUTE_ALLOC_ALIGN(algn) 153 #define NLIB_ATTRIBUTE_ASSUME_ALIGNED(n) 154 #ifndef NLIB_DEPRECATED 155 #define NLIB_DEPRECATED __declspec(deprecated) 157 #ifndef NLIB_DEPRECATED_MSG 158 #define NLIB_DEPRECATED_MSG(msg) __declspec(deprecated(msg)) 160 #define NLIB_WEAKSYMBOL 161 #define NLIB_VIS_HIDDEN 163 # define NLIB_EXPIMP_TEMPLATE_(x) template class NLIB_VIS_PUBLIC x 164 # define NLIB_WINEXPORT __declspec(dllexport) 165 # define NLIB_WINIMPORT __declspec(dllimport) 166 # define NLIB_VIS_PUBLIC NLIB_WINIMPORT 167 # define NLIB_EXPIMP_TEMPLATE(x) extern NLIB_EXPIMP_TEMPLATE_(x) 169 # define NLIB_VIS_PUBLIC 170 # define NLIB_EXPIMP_TEMPLATE(x) 173 #if defined(n_EXPORTS) 174 # undef NLIB_VIS_PUBLIC 175 # define NLIB_VIS_PUBLIC NLIB_WINEXPORT 176 #elif defined(nx_misc_EXPORTS) 177 # undef NLIB_EXPIMP_TEMPLATE 178 # define NLIB_EXPIMP_TEMPLATE(x) NLIB_EXPIMP_TEMPLATE_(x) 181 #define NLIB_VIS_PUBLIC_ALT 183 #define NLIB_LITTLE_ENDIAN 192 #define NLIB_MEMORY_ORDER_RELEASE \ 193 __pragma(warning(push)) \ 194 __pragma(warning(disable:4127)) \ 195 do { _WriteBarrier(); _mm_sfence(); } while (0) \ 196 __pragma(warning(pop)) 197 #define NLIB_MEMORY_ORDER_ACQUIRE \ 198 __pragma(warning(push)) \ 199 __pragma(warning(disable:4127)) \ 200 do { _ReadBarrier(); _mm_lfence(); } while (0) \ 201 __pragma(warning(pop)) 202 #define NLIB_MEMORY_ORDER_ACQ_REL \ 203 __pragma(warning(push)) \ 204 __pragma(warning(disable:4127)) \ 205 do { _ReadWriteBarrier(); _mm_mfence(); } while (0) \ 206 __pragma(warning(pop)) 207 #define NLIB_MEMORY_ORDER_SEQ_CST NLIB_MEMORY_ORDER_ACQ_REL 211 # define __PRIS_PREFIX "ll" 213 # define __PRIS_PREFIX 215 #define NLIB_WARN__(x) #x 216 #define NLIB_WARN_(x) NLIB_WARN__(x) 217 #define NLIB_WARN(exp) (__FILE__ "(" NLIB_WARN_(__LINE__) ") : WARNING: " exp) 222 #define NLIB_TIMESPEC_HAS_NATIVE 225 #pragma pack(push, 8) 226 typedef struct nlib_mutex_ {
235 #define NLIB_MUTEX_INITIALIZER { 0x6768696AU, 0 } 236 #define NLIB_RECURSIVE_MUTEX_INITIALIZER { 0x6768696AU, 1 } 237 #define NLIB_RECURSIVE_TIMED_MUTEX_INITIALIZER { 0x6768696AU, 2 } 241 typedef struct nlib_cond_ {
242 CONDITION_VARIABLE cond;
245 #define NLIB_COND_INITIALIZER { 0, NLIB_MUTEX_INITIALIZER } 249 #define NLIB_ATTRIBUTE_PRINTF(x, y) 251 #define NLIB_ASSUME(cond) __assume(cond) 253 #define NLIB_RWLOCK_HAS_NATIVE 254 #ifdef NLIB_RWLOCK_HAS_NATIVE 256 #define NLIB_RWLOCK_INITIALIZER SRWLOCK_INIT 258 #define NLIB_TIMER_HAS_NATIVE 259 #define NLIB_ONCE_HAS_NATIVE 263 #define NLIB_LIBC_nlib_memcmp 264 #define NLIB_LIBC_nlib_strlen 265 #define NLIB_LIBC_nlib_strnlen 266 #define NLIB_LIBC_nlib_wcslen 267 #define NLIB_LIBC_nlib_wcsnlen 268 #define NLIB_LIBC_nlib_strcpy 269 #define NLIB_LIBC_nlib_strncpy 270 #define NLIB_LIBC_nlib_wcscpy 271 #define NLIB_LIBC_nlib_wcsncpy 272 #define NLIB_LIBC_nlib_strchr 273 #define NLIB_LIBC_nlib_strrchr 275 #if !defined(__INTELLISENSE__) 276 #define NLIB_ATOMIC_RELAXED (0) 277 #define NLIB_ATOMIC_ACQUIRE (1) 278 #define NLIB_ATOMIC_RELEASE (2) 279 #define NLIB_ATOMIC_ACQ_REL (3) 280 #define NLIB_ATOMIC_SEQ_CST (7) 305 _InterlockedExchange((
volatile long*)ptr, val);
315 result = (int32_t)_InterlockedExchange((
volatile long*)ptr, val);
321 int32_t desired,
int weak,
322 int success_memorder,
int failure_memorder) {
325 result = _InterlockedCompareExchange((
volatile long*)ptr, desired, *expected);
328 (void)success_memorder;
329 (void)failure_memorder;
330 if (result == *expected) {
343 result = _InterlockedExchangeAdd((
volatile long*)ptr, val) + val;
353 result = _InterlockedExchangeAdd((
volatile long*)ptr, -val) - val;
363 result = _InterlockedAnd((
volatile long*)ptr, val) & val;
373 result = _InterlockedXor((
volatile long*)ptr, val) ^ val;
383 result = _InterlockedOr((
volatile long*)ptr, val) | val;
393 result = _InterlockedExchangeAdd((
volatile long*)ptr, val);
403 result = _InterlockedExchangeAdd((
volatile long*)ptr, -val);
413 result = _InterlockedAnd((
volatile long*)ptr, val);
423 result = _InterlockedXor((
volatile long*)ptr, val);
433 result = _InterlockedOr((
volatile long*)ptr, val);
457 InterlockedExchange64((
volatile long long*)ptr, val);
459 _InterlockedExchange64((
volatile long long*)ptr, val);
471 result = (int64_t)InterlockedExchange64((
volatile long long*)ptr, val);
473 result = (int64_t)_InterlockedExchange64((
volatile long long*)ptr, val);
488 int64_t desired,
int weak,
489 int success_memorder,
int failure_memorder) {
493 result = InterlockedCompareExchange64((
volatile long long*)ptr, desired, *expected);
495 result = _InterlockedCompareExchange64((
volatile long long*)ptr, desired, *expected);
499 (void)success_memorder;
500 (void)failure_memorder;
501 if (result == *expected) {
515 result = InterlockedExchangeAdd64((
volatile long long*)ptr, val) + val;
517 result = _InterlockedExchangeAdd64((
volatile long long*)ptr, val) + val;
529 result = InterlockedExchangeAdd64((
volatile long long*)ptr, -val) - val;
531 result = _InterlockedExchangeAdd64((
volatile long long*)ptr, -val) - val;
543 result = InterlockedAnd64((
volatile long long*)ptr, val) & val;
545 result = _InterlockedAnd64((
volatile long long*)ptr, val) & val;
557 result = InterlockedXor64((
volatile long long*)ptr, val) ^ val;
559 result = _InterlockedXor64((
volatile long long*)ptr, val) ^ val;
571 result = InterlockedOr64((
volatile long long*)ptr, val) | val;
573 result = _InterlockedOr64((
volatile long long*)ptr, val) | val;
585 result = InterlockedExchangeAdd64((
volatile long long*)ptr, val);
587 result = _InterlockedExchangeAdd64((
volatile long long*)ptr, val);
599 result = InterlockedExchangeAdd64((
volatile long long*)ptr, -val);
601 result = _InterlockedExchangeAdd64((
volatile long long*)ptr, -val);
613 result = InterlockedAnd64((
volatile long long*)ptr, val);
615 result = _InterlockedAnd64((
volatile long long*)ptr, val);
627 result = InterlockedXor64((
volatile long long*)ptr, val);
629 result = _InterlockedXor64((
volatile long long*)ptr, val);
641 result = InterlockedOr64((
volatile long long*)ptr, val);
643 result = _InterlockedOr64((
volatile long long*)ptr, val);
667 #if (_MSC_VER == 1800 && !defined(NLIB_64BIT)) 668 InterlockedExchangePointer((
void*
volatile*)ptr, val);
670 _InterlockedExchangePointer((
void*
volatile*)ptr, val);
677 void* desired,
int weak,
678 int success_memorder,
int failure_memorder) {
681 result = _InterlockedCompareExchangePointer((
void*
volatile *)ptr, desired, *expected);
684 (void)success_memorder;
685 (void)failure_memorder;
686 if (result == *expected) {
716 #define NLIB_ALTNAME(func1, func2) \ 717 __pragma(comment(linker, "/alternatename:_" NLIB_STRINGIFY(func1) "=_" NLIB_STRINGIFY(func2))) 719 #define NLIB_ALTNAME(func1, func2) \ 720 __pragma(comment(linker, "/alternatename:" NLIB_STRINGIFY(func1) "=" NLIB_STRINGIFY(func2))) 729 #if defined(NLIB_SIMD) 730 # ifndef NLIB_LIBC_nlib_strlen 733 # ifndef NLIB_LIBC_nlib_strlen 736 NLIB_ALTNAME(nlib_utf16len_, nlib_utf16len_simd)
737 NLIB_ALTNAME(nlib_utf16nlen_, nlib_utf16nlen_simd)
738 NLIB_ALTNAME(nlib_utf32len_, nlib_utf32len_generic)
739 NLIB_ALTNAME(nlib_utf32nlen_, nlib_utf32nlen_generic)
740 NLIB_ALTNAME(nlib_utf16cplen_ex_, nlib_utf16cplen_ex_simd)
743 NLIB_ALTNAME(nlib_strchr_mb, nlib_strchr_mb_simd)
757 # ifndef NLIB_LIBC_nlib_strlen 760 # ifndef NLIB_LIBC_nlib_strlen 763 NLIB_ALTNAME(nlib_utf16len_, nlib_utf16len_generic)
764 NLIB_ALTNAME(nlib_utf16nlen_, nlib_utf16nlen_generic)
765 NLIB_ALTNAME(nlib_utf32len_, nlib_utf32len_generic)
766 NLIB_ALTNAME(nlib_utf32nlen_, nlib_utf32nlen_generic)
767 NLIB_ALTNAME(nlib_utf16cplen_ex_, nlib_utf16cplen_ex_generic)
770 NLIB_ALTNAME(nlib_strchr_mb, nlib_strchr_mb_generic)
786 #endif // INCLUDE_NN_NLIB_PLATFORM_WIN32_H_