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 2012 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) 71 #if _MSC_VER == 1800 && WINVER < 0x0603 72 # pragma message(__FILE__ ": Please update your Windows SDK") 75 #if _MSC_VER == 1700 && WINVER < 0x0602 76 # pragma message(__FILE__ ": Please update your Windows SDK") 79 #if (!defined(_M_IX86_FP) || _M_IX86_FP < 2) && !defined(_M_X64) && !defined(_M_AMD64) 80 # error /arch:SSE2 or higher must be set 92 #if (_MSC_VER >= 1800) 93 # define NLIB_HAS_STDHEADER_INTTYPES 94 # include <inttypes.h> 98 # define __func__ __FUNCTION__ 102 #ifndef NLIB_HAS_STDHEADER_INTTYPES 103 # include "nn/nlib/IntTypes.h" 111 # define va_copy(dest, src) (dest = src) 113 #define NLIB_ALWAYS_INLINE __forceinline 114 #define NLIB_NEVER_INLINE __declspec(noinline) 115 #define NLIB_LIKELY(x) (x) 116 #define NLIB_UNLIKELY(x) (x) 117 #define NLIB_EXPECT(var, exp_value) (var) 118 #define NLIB_CHECK_RESULT 119 #define NLIB_NORETURN 121 #define NLIB_NONNULL_1 122 #define NLIB_NONNULL_2 123 #define NLIB_NONNULL_3 124 #define NLIB_NONNULL_4 125 #define NLIB_NONNULL_5 126 #define NLIB_ATTRIBUTE_MALLOC 127 #define NLIB_ATTRIBUTE_PURE 128 #define NLIB_ATTRIBUTE_CONST 129 #define NLIB_ATTRIBUTE_ALLOC_SIZE1(n) 130 #define NLIB_ATTRIBUTE_ALLOC_SIZE2(n0, n1) 131 #define NLIB_ATTRIBUTE_ALLOC_ALIGN(algn) 132 #define NLIB_ATTRIBUTE_ASSUME_ALIGNED(n) 133 #ifndef NLIB_DEPRECATED 134 #define NLIB_DEPRECATED __declspec(deprecated) 136 #ifndef NLIB_DEPRECATED_MSG 137 #define NLIB_DEPRECATED_MSG(msg) __declspec(deprecated(msg)) 139 #define NLIB_WEAKSYMBOL 140 #define NLIB_VIS_HIDDEN 142 # define NLIB_EXPIMP_TEMPLATE_(x) template class NLIB_VIS_PUBLIC x 143 # define NLIB_WINEXPORT __declspec(dllexport) 144 # define NLIB_WINIMPORT __declspec(dllimport) 145 # define NLIB_VIS_PUBLIC NLIB_WINIMPORT 146 # define NLIB_EXPIMP_TEMPLATE(x) extern NLIB_EXPIMP_TEMPLATE_(x) 148 # define NLIB_VIS_PUBLIC 149 # define NLIB_EXPIMP_TEMPLATE(x) 152 #if defined(n_EXPORTS) 153 # undef NLIB_VIS_PUBLIC 154 # define NLIB_VIS_PUBLIC NLIB_WINEXPORT 155 #elif defined(nx_misc_EXPORTS) 156 # undef NLIB_EXPIMP_TEMPLATE 157 # define NLIB_EXPIMP_TEMPLATE(x) NLIB_EXPIMP_TEMPLATE_(x) 160 #define NLIB_VIS_PUBLIC_ALT 162 #define NLIB_LITTLE_ENDIAN 171 #define NLIB_MEMORY_ORDER_RELEASE \ 172 __pragma(warning(push)) \ 173 __pragma(warning(disable:4127)) \ 174 do { _WriteBarrier(); _mm_sfence(); } while (0) \ 175 __pragma(warning(pop)) 176 #define NLIB_MEMORY_ORDER_ACQUIRE \ 177 __pragma(warning(push)) \ 178 __pragma(warning(disable:4127)) \ 179 do { _ReadBarrier(); _mm_lfence(); } while (0) \ 180 __pragma(warning(pop)) 181 #define NLIB_MEMORY_ORDER_ACQ_REL \ 182 __pragma(warning(push)) \ 183 __pragma(warning(disable:4127)) \ 184 do { _ReadWriteBarrier(); _mm_mfence(); } while (0) \ 185 __pragma(warning(pop)) 186 #define NLIB_MEMORY_ORDER_SEQ_CST NLIB_MEMORY_ORDER_ACQ_REL 190 # define __PRIS_PREFIX "ll" 192 # define __PRIS_PREFIX 194 #define NLIB_WARN__(x) #x 195 #define NLIB_WARN_(x) NLIB_WARN__(x) 196 #define NLIB_WARN(exp) (__FILE__ "(" NLIB_WARN_(__LINE__) ") : WARNING: " exp) 201 #define NLIB_TIMESPEC_HAS_NATIVE 204 #pragma pack(push, 8) 205 typedef struct nlib_mutex_ {
214 #define NLIB_MUTEX_INITIALIZER { 0x6768696AU, 0 } 215 #define NLIB_RECURSIVE_MUTEX_INITIALIZER { 0x6768696AU, 1 } 216 #define NLIB_RECURSIVE_TIMED_MUTEX_INITIALIZER { 0x6768696AU, 2 } 220 typedef struct nlib_cond_ {
221 CONDITION_VARIABLE cond;
224 #define NLIB_COND_INITIALIZER { 0, NLIB_MUTEX_INITIALIZER } 228 #define NLIB_ATTRIBUTE_PRINTF(x, y) 230 #define NLIB_ASSUME(cond) __assume(cond) 232 #define NLIB_RWLOCK_HAS_NATIVE 233 #ifdef NLIB_RWLOCK_HAS_NATIVE 235 #define NLIB_RWLOCK_INITIALIZER SRWLOCK_INIT 237 #define NLIB_TIMER_HAS_NATIVE 241 #define NLIB_LIBC_nlib_memcmp 242 #define NLIB_LIBC_nlib_strlen 243 #define NLIB_LIBC_nlib_strnlen 244 #define NLIB_LIBC_nlib_wcslen 245 #define NLIB_LIBC_nlib_wcsnlen 246 #define NLIB_LIBC_nlib_strcpy 247 #define NLIB_LIBC_nlib_strncpy 248 #define NLIB_LIBC_nlib_wcscpy 249 #define NLIB_LIBC_nlib_wcsncpy 250 #define NLIB_LIBC_nlib_strchr 251 #define NLIB_LIBC_nlib_strrchr 253 #if !defined(__INTELLISENSE__) 254 #define NLIB_ATOMIC_RELAXED (0) 255 #define NLIB_ATOMIC_ACQUIRE (1) 256 #define NLIB_ATOMIC_RELEASE (2) 257 #define NLIB_ATOMIC_ACQ_REL (3) 258 #define NLIB_ATOMIC_SEQ_CST (7) 283 _InterlockedExchange((
volatile long*)ptr, val);
293 result = (int32_t)_InterlockedExchange((
volatile long*)ptr, val);
299 int32_t desired,
int weak,
300 int success_memorder,
int failure_memorder) {
303 result = _InterlockedCompareExchange((
volatile long*)ptr, desired, *expected);
306 (void)success_memorder;
307 (void)failure_memorder;
308 if (result == *expected) {
321 result = _InterlockedExchangeAdd((
volatile long*)ptr, val) + val;
331 result = _InterlockedExchangeAdd((
volatile long*)ptr, -val) - val;
341 result = _InterlockedAnd((
volatile long*)ptr, val) & val;
351 result = _InterlockedXor((
volatile long*)ptr, val) ^ val;
361 result = _InterlockedOr((
volatile long*)ptr, val) | val;
371 result = _InterlockedExchangeAdd((
volatile long*)ptr, val);
381 result = _InterlockedExchangeAdd((
volatile long*)ptr, -val);
391 result = _InterlockedAnd((
volatile long*)ptr, val);
401 result = _InterlockedXor((
volatile long*)ptr, val);
411 result = _InterlockedOr((
volatile long*)ptr, val);
435 InterlockedExchange64((
volatile long long*)ptr, val);
437 _InterlockedExchange64((
volatile long long*)ptr, val);
449 result = (int64_t)InterlockedExchange64((
volatile long long*)ptr, val);
451 result = (int64_t)_InterlockedExchange64((
volatile long long*)ptr, val);
466 int64_t desired,
int weak,
467 int success_memorder,
int failure_memorder) {
471 result = InterlockedCompareExchange64((
volatile long long*)ptr, desired, *expected);
473 result = _InterlockedCompareExchange64((
volatile long long*)ptr, desired, *expected);
477 (void)success_memorder;
478 (void)failure_memorder;
479 if (result == *expected) {
493 result = InterlockedExchangeAdd64((
volatile long long*)ptr, val) + val;
495 result = _InterlockedExchangeAdd64((
volatile long long*)ptr, val) + val;
507 result = InterlockedExchangeAdd64((
volatile long long*)ptr, -val) - val;
509 result = _InterlockedExchangeAdd64((
volatile long long*)ptr, -val) - val;
521 result = InterlockedAnd64((
volatile long long*)ptr, val) & val;
523 result = _InterlockedAnd64((
volatile long long*)ptr, val) & val;
535 result = InterlockedXor64((
volatile long long*)ptr, val) ^ val;
537 result = _InterlockedXor64((
volatile long long*)ptr, val) ^ val;
549 result = InterlockedOr64((
volatile long long*)ptr, val) | val;
551 result = _InterlockedOr64((
volatile long long*)ptr, val) | val;
563 result = InterlockedExchangeAdd64((
volatile long long*)ptr, val);
565 result = _InterlockedExchangeAdd64((
volatile long long*)ptr, val);
577 result = InterlockedExchangeAdd64((
volatile long long*)ptr, -val);
579 result = _InterlockedExchangeAdd64((
volatile long long*)ptr, -val);
591 result = InterlockedAnd64((
volatile long long*)ptr, val);
593 result = _InterlockedAnd64((
volatile long long*)ptr, val);
605 result = InterlockedXor64((
volatile long long*)ptr, val);
607 result = _InterlockedXor64((
volatile long long*)ptr, val);
619 result = InterlockedOr64((
volatile long long*)ptr, val);
621 result = _InterlockedOr64((
volatile long long*)ptr, val);
645 #if _MSC_VER < 1800 || (_MSC_VER == 1800 && !defined(NLIB_64BIT)) 646 InterlockedExchangePointer((
void*
volatile*)ptr, val);
648 _InterlockedExchangePointer((
void*
volatile*)ptr, val);
655 void* desired,
int weak,
656 int success_memorder,
int failure_memorder) {
660 result = InterlockedCompareExchangePointer((
void*
volatile *)ptr, desired, *expected);
662 result = _InterlockedCompareExchangePointer((
void*
volatile *)ptr, desired, *expected);
666 (void)success_memorder;
667 (void)failure_memorder;
668 if (result == *expected) {
698 #define NLIB_ALTNAME(func1, func2) \ 699 __pragma(comment(linker, "/alternatename:_" NLIB_STRINGIFY(func1) "=_" NLIB_STRINGIFY(func2))) 701 #define NLIB_ALTNAME(func1, func2) \ 702 __pragma(comment(linker, "/alternatename:" NLIB_STRINGIFY(func1) "=" NLIB_STRINGIFY(func2))) 711 #if defined(NLIB_SIMD) 712 # ifndef NLIB_LIBC_nlib_strlen 715 # ifndef NLIB_LIBC_nlib_strlen 718 NLIB_ALTNAME(nlib_utf16len_, nlib_utf16len_simd)
719 NLIB_ALTNAME(nlib_utf16nlen_, nlib_utf16nlen_simd)
720 NLIB_ALTNAME(nlib_utf32len_, nlib_utf32len_generic)
721 NLIB_ALTNAME(nlib_utf32nlen_, nlib_utf32nlen_generic)
722 NLIB_ALTNAME(nlib_utf16cplen_ex_, nlib_utf16cplen_ex_simd)
739 # ifndef NLIB_LIBC_nlib_strlen 742 # ifndef NLIB_LIBC_nlib_strlen 745 NLIB_ALTNAME(nlib_utf16len_, nlib_utf16len_generic)
746 NLIB_ALTNAME(nlib_utf16nlen_, nlib_utf16nlen_generic)
747 NLIB_ALTNAME(nlib_utf32len_, nlib_utf32len_generic)
748 NLIB_ALTNAME(nlib_utf32nlen_, nlib_utf32nlen_generic)
749 NLIB_ALTNAME(nlib_utf16cplen_ex_, nlib_utf16cplen_ex_generic)
750 NLIB_ALTNAME(nlib_strchr, nlib_strchr_generic)
751 NLIB_ALTNAME(nlib_strrchr, nlib_strrchr_generic)
752 NLIB_ALTNAME(nlib_strchr_mb, nlib_strchr_mb_generic)
753 NLIB_ALTNAME(nlib_memcmp, nlib_memcmp_generic)
754 NLIB_ALTNAME(nlib_memchr, nlib_memchr_generic)
755 NLIB_ALTNAME(nlib_memrchr, nlib_memrchr_generic)
756 NLIB_ALTNAME(nlib_memchr_not, nlib_memchr_not_generic)
757 NLIB_ALTNAME(nlib_memchr_range_not, nlib_memchr_range_not_generic)
758 NLIB_ALTNAME(nlib_memchr_lt, nlib_memchr_lt_generic)
759 NLIB_ALTNAME(nlib_memchr_gt, nlib_memchr_gt_generic)
760 NLIB_ALTNAME(nlib_memchr_mb, nlib_memchr_mb_generic)
761 NLIB_ALTNAME(nlib_skipws, nlib_skipws_generic)
762 NLIB_ALTNAME(nlib_swapendian_16, nlib_swapendian_16_generic)
763 NLIB_ALTNAME(nlib_swapendian_32, nlib_swapendian_32_generic)
764 NLIB_ALTNAME(nlib_swapendian_64, nlib_swapendian_64_generic)
768 #endif // INCLUDE_NN_NLIB_PLATFORM_WIN32_H_