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) 71 # pragma message(__FILE__ ": Please update your Windows SDK") 74 #if (!defined(_M_IX86_FP) || _M_IX86_FP < 2) && !defined(_M_X64) && !defined(_M_AMD64) 75 # error /arch:SSE2 or higher must be set 91 #define NLIB_CXX11_SWAPHEADER 92 #define NLIB_CXX11_STDLIB_CHRONO 93 #define NLIB_CXX11_STDLIB_ATOMIC 94 #define NLIB_CXX11_STDLIB_ARRAY 95 #define NLIB_CXX11_STDLIB_UNORDERED 96 #define NLIB_CXX11_STDLIB_TUPLE 97 #define NLIB_HAS_NATIVE_TYPETRAITS 98 #define NLIB_CXX11_UNIQUEPTR 99 #define NLIB_CXX11_EXPLICIT_VIRTUAL_OVERRIDES 100 #define NLIB_CXX11_EXPLICIT_CONVERSION_OPERATORS 101 #define NLIB_CXX11_STDLIB_RANDOM 102 #define NLIB_CXX11_DEFAULT_TEMPLATE_ARGUMENT_FOR_FUNCTION_TEMPLATES 103 #define NLIB_CXX11_NULL_POINTER_CONSTANT 105 #define NLIB_CXX11_STATIC_ASSERTIONS 106 #ifndef __cpp_static_assert 107 #define __cpp_static_assert 200410L // N1720 110 #define NLIB_CXX11_RVALUE_REFERENCES 111 #ifndef __cpp_rvalue_references 112 #define __cpp_rvalue_references 200610L // N2118 115 #define NLIB_CXX11_LAMBDAS 116 #ifndef __cpp_lambdas 117 #define __cpp_lambdas 200907L // N2927 120 #define NLIB_CXX11_RANGE_BASED_FOR 121 #ifndef __cpp_range_based_for 122 #define __cpp_range_based_for 200907L // N2930 125 #define NLIB_CXX11_TEMPLATE_ALIAS 126 #ifndef __cpp_alias_templates 127 #define __cpp_alias_templates 200704L // N2258 130 #define NLIB_CXX11_VARIADIC_TEMPLATES 131 #ifndef __cpp_variadic_templates 132 #define __cpp_variadic_templates 200704L // N2242 135 #define NLIB_CXX11_DELEGATING_CONSTRUCTORS 136 #ifndef __cpp_delegating_constructors 137 #define __cpp_delegating_constructors 200604L // N1986 140 #ifndef __cpp_lib_make_unique 141 #define __cpp_lib_make_unique 201304L // N3656 143 #ifndef __cpp_lib_transparent_operators 144 #define __cpp_lib_transparent_operators 201210L // N3421 146 #ifndef __cpp_lib_transformation_trait_aliases 147 #define __cpp_lib_transformation_trait_aliases 201304L // N3655 149 #ifndef __cpp_lib_incomplete_container_elements 150 #define __cpp_lib_incomplete_container_elements 201505L // N4510 154 #define NLIB_CXX11_NOEXCEPT 155 #define NLIB_CXX11_ALIGNMENT_SUPPORT 156 #define NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS 158 #define NLIB_CXX11_CONSTEXPR 159 #ifndef __cpp_constexpr 160 #define __cpp_constexpr 200704 // N2235 163 #define NLIB_CXX11_NEW_CHARACTER_TYPES 164 #ifndef __cpp_unicode_characters 165 #define __cpp_unicode_characters 200704L // N2249 169 #ifndef __cpp_raw_strings 170 #define __cpp_raw_strings 200710L // N2442 172 #ifndef __cpp_unicode_literals 173 #define __cpp_unicode_literals 200710L // N2442 175 #ifndef __cpp_user_defined_literals 176 #define __cpp_user_defined_literals 200809L // N2765 178 #ifndef __cpp_decltype 179 #define __cpp_decltype 200707L // N2343 181 #ifndef __cpp_attributes 182 #define __cpp_attributes 200809L // N2761 184 #ifndef __cpp_initializer_lists 185 #define __cpp_initializer_lists 200806L // N2672 188 #define __cpp_nsdmi 200809L // N2756 190 #ifndef __cpp_inheriting_constructors 191 #define __cpp_inheriting_constructors 200802L // N2540 193 #ifndef __cpp_ref_qualifiers 194 #define __cpp_ref_qualifiers 200710L // N2439 198 #ifndef __cpp_binary_literals 199 #define __cpp_binary_literals 201304L // N3472 201 #ifndef __cpp_init_captures 202 #define __cpp_init_captures 201304L // N3648 204 #ifndef __cpp_generic_lambdas 205 #define __cpp_generic_lambdas 201304L // N3649 207 #ifndef __cpp_sized_deallocation 208 #define __cpp_sized_deallocation 201309L // N3778 210 #ifndef __cpp_decltype_auto 211 #define __cpp_decltype_auto 201304L // N3638 213 #ifndef __cpp_return_type_deduction 214 #define __cpp_return_type_deduction 201304L // N3638 216 #ifndef __cpp_variable_templates 217 #define __cpp_variable_templates 201304L // N3651 219 #ifndef __cpp_lib_is_null_pointer 220 #define __cpp_lib_is_null_pointer 201309L // LWG2247 222 #ifndef __cpp_lib_integer_sequence 223 #define __cpp_lib_integer_sequence 201304L // N3658 225 #ifndef __cpp_lib_exchange_function 226 #define __cpp_lib_exchange_function 201304L // N3668 228 #ifndef __cpp_lib_tuples_by_type 229 #define __cpp_lib_tuples_by_type 201304L // N3670 231 #ifndef __cpp_lib_tuple_element_t 232 #define __cpp_lib_tuple_element_t 201402L // N3887 234 #ifndef __cpp_lib_integral_constant_callable 235 #define __cpp_lib_integral_constant_callable 201304L // N3545 237 #ifndef __cpp_lib_result_of_sfinae 238 #define __cpp_lib_result_of_sfinae 201210L // N3642 240 #ifndef __cpp_lib_is_final 241 #define __cpp_lib_is_final 201402L // LWG2112 243 #ifndef __cpp_lib_chrono_udls 244 #define __cpp_lib_chrono_udls 201304L // N3642 246 #ifndef __cpp_lib_string_udls 247 #define __cpp_lib_string_udls 201304L // N3642 249 #ifndef __cpp_lib_generic_associative_lookup 250 #define __cpp_lib_generic_associative_lookup 201304L // N3657 252 #ifndef __cpp_lib_null_iterators 253 #define __cpp_lib_null_iterators 201304L // N3644 255 #ifndef __cpp_lib_make_reverse_iterator 256 #define __cpp_lib_make_reverse_iterator 201402L // LWG2285 258 #ifndef __cpp_lib_robust_nonmodifying_seq_ops 259 #define __cpp_lib_robust_nonmodifying_seq_ops 201304L // N3671 261 #ifndef __cpp_lib_complex_udls 262 #define __cpp_lib_complex_udls 201309L // N3779 264 #ifndef __cpp_lib_quoted_string_io 265 #define __cpp_lib_quoted_string_io 201304L // N3654 267 #ifndef __cpp_lib_shared_timed_mutex 268 #define __cpp_lib_shared_timed_mutex 201402L // N3891 270 #if _MSVC_LANG > 201402L 271 #ifndef __cpp_namespace_attributes 272 #define __cpp_namespace_attributes 201411L // N4266 274 #ifndef __cpp_enumerator_attributes 275 #define __cpp_enumerator_attributes 201411L // N4266 277 #ifndef __cpp_lib_type_trait_variable_templates 278 #define __cpp_lib_type_trait_variable_templates // P0006R0 280 #ifndef __cpp_lib_logical_traits 281 #define __cpp_lib_logical_traits 201510 // P0013R1 283 #ifndef __cpp_lib_as_const 284 #define __cpp_lib_as_const 201510 // P0007R1 286 #ifndef __cpp_lib_transparent_operators 287 #define __cpp_lib_transparent_operators 201510L // P0074R0 289 #ifndef __cpp_lib_chrono 290 #define __cpp_lib_chrono 201510 // P0092R1 292 #ifndef __cpp_lib_lock_guard_variadic 293 #define __cpp_lib_lock_guard_variadic 201510L // P0156R0 295 #ifndef __cpp_lib_uncaught_exceptions 296 #define __cpp_lib_uncaught_exceptions 201411L // N4259 298 #ifndef __cpp_lib_shared_mutex 299 #define __cpp_lib_shared_mutex 201505L // N4508 305 #define NLIB_CXX14_CONSTEXPR 306 #undef __cpp_constexpr 307 #define __cpp_constexpr 201304L // N3652 308 #ifndef __cpp_aggregate_nsdmi 309 #define __cpp_aggregate_nsdmi 201304L // N3653 311 #if _MSVC_LANG > 201402L 320 #undef __cpp_range_based_for 321 #define __cpp_range_based_for 201603L // P0184R0 322 #undef __cpp_static_assert 323 #define __cpp_static_assert 201411L // N3928 324 #ifndef __cpp_nested_namespace_definitions 325 #define __cpp_nested_namespace_definitions 201411L // N4230 337 #include <inttypes.h> 338 #if (_MSC_VER < 1900) 340 # define __func__ __FUNCTION__ 349 # define va_copy(dest, src) (dest = src) 351 #define NLIB_ALWAYS_INLINE __forceinline 352 #define NLIB_NEVER_INLINE __declspec(noinline) 353 #define NLIB_LIKELY(x) (x) 354 #define NLIB_UNLIKELY(x) (x) 355 #define NLIB_EXPECT(var, exp_value) (var) 356 #define NLIB_CHECK_RESULT 357 #if defined(__cplusplus) && _MSC_VER >= 1900 358 #define NLIB_NORETURN [[noreturn]] // NOLINT 360 #define NLIB_NORETURN 362 #if defined(__cplusplus) && _MSC_VER >= 1910 && _MSVC_LANG > 201402L 363 #define NLIB_FALLTHROUGH [[fallthrough]] // NOLINT 365 #define NLIB_FALLTHROUGH 368 #define NLIB_NONNULL_1 369 #define NLIB_NONNULL_2 370 #define NLIB_NONNULL_3 371 #define NLIB_NONNULL_4 372 #define NLIB_NONNULL_5 373 #define NLIB_ATTRIBUTE_MALLOC 374 #define NLIB_ATTRIBUTE_PURE 375 #define NLIB_ATTRIBUTE_CONST 376 #define NLIB_ATTRIBUTE_ALLOC_SIZE1(n) 377 #define NLIB_ATTRIBUTE_ALLOC_SIZE2(n0, n1) 378 #define NLIB_ATTRIBUTE_ALLOC_ALIGN(algn) 379 #define NLIB_ATTRIBUTE_ASSUME_ALIGNED(n) 380 #ifndef NLIB_DEPRECATED 381 #if defined(__cplusplus) && _MSC_VER >= 1910 382 #define NLIB_DEPRECATED [[deprecated]] // NOLINT 384 #define NLIB_DEPRECATED __declspec(deprecated) 387 #ifndef NLIB_DEPRECATED_MSG 388 #if defined(__cplusplus) && _MSC_VER >= 1910 389 #define NLIB_DEPRECATED_MSG(msg) [[deprecated(msg)]] // NOLINT 391 #define NLIB_DEPRECATED_MSG(msg) __declspec(deprecated(msg)) 394 #define NLIB_WEAKSYMBOL 395 #define NLIB_VIS_HIDDEN 397 # define NLIB_EXPIMP_TEMPLATE_(x) template class NLIB_VIS_PUBLIC x 398 # define NLIB_WINEXPORT __declspec(dllexport) 399 # define NLIB_WINIMPORT __declspec(dllimport) 400 # define NLIB_VIS_PUBLIC NLIB_WINIMPORT 401 # define NLIB_EXPIMP_TEMPLATE(x) extern NLIB_EXPIMP_TEMPLATE_(x) 403 # define NLIB_VIS_PUBLIC 404 # define NLIB_EXPIMP_TEMPLATE(x) 407 #if defined(n_EXPORTS) 408 # undef NLIB_VIS_PUBLIC 409 # define NLIB_VIS_PUBLIC NLIB_WINEXPORT 410 #elif defined(nx_misc_EXPORTS) 411 # undef NLIB_EXPIMP_TEMPLATE 412 # define NLIB_EXPIMP_TEMPLATE(x) NLIB_EXPIMP_TEMPLATE_(x) 415 #define NLIB_VIS_PUBLIC_ALT 417 #define NLIB_LITTLE_ENDIAN 426 #define NLIB_MEMORY_ORDER_RELEASE \ 427 __pragma(warning(push)) \ 428 __pragma(warning(disable:4127)) \ 429 do { _WriteBarrier(); _mm_sfence(); } while (0) \ 430 __pragma(warning(pop)) 431 #define NLIB_MEMORY_ORDER_ACQUIRE \ 432 __pragma(warning(push)) \ 433 __pragma(warning(disable:4127)) \ 434 do { _ReadBarrier(); _mm_lfence(); } while (0) \ 435 __pragma(warning(pop)) 436 #define NLIB_MEMORY_ORDER_ACQ_REL \ 437 __pragma(warning(push)) \ 438 __pragma(warning(disable:4127)) \ 439 do { _ReadWriteBarrier(); _mm_mfence(); } while (0) \ 440 __pragma(warning(pop)) 441 #define NLIB_MEMORY_ORDER_SEQ_CST NLIB_MEMORY_ORDER_ACQ_REL 445 # define __PRIS_PREFIX "ll" 447 # define __PRIS_PREFIX 449 #define NLIB_WARN__(x) #x 450 #define NLIB_WARN_(x) NLIB_WARN__(x) 451 #define NLIB_WARN(exp) (__FILE__ "(" NLIB_WARN_(__LINE__) ") : WARNING: " exp) 456 #define NLIB_TIMESPEC_HAS_NATIVE 459 #pragma pack(push, 8) 460 typedef struct nlib_mutex_ {
469 #define NLIB_MUTEX_INITIALIZER { 0x6768696AU, 0 } 470 #define NLIB_RECURSIVE_MUTEX_INITIALIZER { 0x6768696AU, 1 } 471 #define NLIB_RECURSIVE_TIMED_MUTEX_INITIALIZER { 0x6768696AU, 2 } 475 typedef struct nlib_cond_ {
476 CONDITION_VARIABLE cond;
479 #define NLIB_COND_INITIALIZER { 0, NLIB_MUTEX_INITIALIZER } 483 #define NLIB_ATTRIBUTE_PRINTF(x, y) 485 #define NLIB_ASSUME(cond) __assume(cond) 487 #define NLIB_RWLOCK_HAS_NATIVE 488 #ifdef NLIB_RWLOCK_HAS_NATIVE 490 #define NLIB_RWLOCK_INITIALIZER SRWLOCK_INIT 492 #define NLIB_TIMER_HAS_NATIVE 493 #define NLIB_ONCE_HAS_NATIVE 497 #define NLIB_LIBC_nlib_memcmp 498 #define NLIB_LIBC_nlib_strlen 499 #define NLIB_LIBC_nlib_strnlen 500 #define NLIB_LIBC_nlib_wcslen 501 #define NLIB_LIBC_nlib_wcsnlen 502 #define NLIB_LIBC_nlib_strcpy 503 #define NLIB_LIBC_nlib_strncpy 504 #define NLIB_LIBC_nlib_wcscpy 505 #define NLIB_LIBC_nlib_wcsncpy 506 #define NLIB_LIBC_nlib_strchr 507 #define NLIB_LIBC_nlib_strrchr 509 #if !defined(__INTELLISENSE__) 510 #define NLIB_ATOMIC_RELAXED (0) 511 #define NLIB_ATOMIC_ACQUIRE (1) 512 #define NLIB_ATOMIC_RELEASE (2) 513 #define NLIB_ATOMIC_ACQ_REL (3) 514 #define NLIB_ATOMIC_SEQ_CST (7) 539 _InterlockedExchange((
volatile long*)ptr, val);
549 result = (int32_t)_InterlockedExchange((
volatile long*)ptr, val);
555 int32_t desired,
int weak,
556 int success_memorder,
int failure_memorder) {
559 result = _InterlockedCompareExchange((
volatile long*)ptr, desired, *expected);
562 (void)success_memorder;
563 (void)failure_memorder;
564 if (result == *expected) {
577 result = _InterlockedExchangeAdd((
volatile long*)ptr, val) + val;
587 result = _InterlockedExchangeAdd((
volatile long*)ptr, -val) - val;
597 result = _InterlockedAnd((
volatile long*)ptr, val) & val;
607 result = _InterlockedXor((
volatile long*)ptr, val) ^ val;
617 result = _InterlockedOr((
volatile long*)ptr, val) | val;
627 result = _InterlockedExchangeAdd((
volatile long*)ptr, val);
637 result = _InterlockedExchangeAdd((
volatile long*)ptr, -val);
647 result = _InterlockedAnd((
volatile long*)ptr, val);
657 result = _InterlockedXor((
volatile long*)ptr, val);
667 result = _InterlockedOr((
volatile long*)ptr, val);
691 InterlockedExchange64((
volatile long long*)ptr, val);
693 _InterlockedExchange64((
volatile long long*)ptr, val);
705 result = (int64_t)InterlockedExchange64((
volatile long long*)ptr, val);
707 result = (int64_t)_InterlockedExchange64((
volatile long long*)ptr, val);
722 int64_t desired,
int weak,
723 int success_memorder,
int failure_memorder) {
727 result = InterlockedCompareExchange64((
volatile long long*)ptr, desired, *expected);
729 result = _InterlockedCompareExchange64((
volatile long long*)ptr, desired, *expected);
733 (void)success_memorder;
734 (void)failure_memorder;
735 if (result == *expected) {
749 result = InterlockedExchangeAdd64((
volatile long long*)ptr, val) + val;
751 result = _InterlockedExchangeAdd64((
volatile long long*)ptr, val) + val;
763 result = InterlockedExchangeAdd64((
volatile long long*)ptr, -val) - val;
765 result = _InterlockedExchangeAdd64((
volatile long long*)ptr, -val) - val;
777 result = InterlockedAnd64((
volatile long long*)ptr, val) & val;
779 result = _InterlockedAnd64((
volatile long long*)ptr, val) & val;
791 result = InterlockedXor64((
volatile long long*)ptr, val) ^ val;
793 result = _InterlockedXor64((
volatile long long*)ptr, val) ^ val;
805 result = InterlockedOr64((
volatile long long*)ptr, val) | val;
807 result = _InterlockedOr64((
volatile long long*)ptr, val) | val;
819 result = InterlockedExchangeAdd64((
volatile long long*)ptr, val);
821 result = _InterlockedExchangeAdd64((
volatile long long*)ptr, val);
833 result = InterlockedExchangeAdd64((
volatile long long*)ptr, -val);
835 result = _InterlockedExchangeAdd64((
volatile long long*)ptr, -val);
847 result = InterlockedAnd64((
volatile long long*)ptr, val);
849 result = _InterlockedAnd64((
volatile long long*)ptr, val);
861 result = InterlockedXor64((
volatile long long*)ptr, val);
863 result = _InterlockedXor64((
volatile long long*)ptr, val);
875 result = InterlockedOr64((
volatile long long*)ptr, val);
877 result = _InterlockedOr64((
volatile long long*)ptr, val);
901 #if (_MSC_VER == 1800 && !defined(NLIB_64BIT)) 902 InterlockedExchangePointer((
void*
volatile*)ptr, val);
904 _InterlockedExchangePointer((
void*
volatile*)ptr, val);
911 void* desired,
int weak,
912 int success_memorder,
int failure_memorder) {
915 result = _InterlockedCompareExchangePointer((
void*
volatile *)ptr, desired, *expected);
918 (void)success_memorder;
919 (void)failure_memorder;
920 if (result == *expected) {
950 #define NLIB_ALTNAME(func1, func2) \ 951 __pragma(comment(linker, "/alternatename:_" NLIB_STRINGIFY(func1) "=_" NLIB_STRINGIFY(func2))) 953 #define NLIB_ALTNAME(func1, func2) \ 954 __pragma(comment(linker, "/alternatename:" NLIB_STRINGIFY(func1) "=" NLIB_STRINGIFY(func2))) 963 #if defined(NLIB_SIMD) 964 # ifndef NLIB_LIBC_nlib_strlen 967 # ifndef NLIB_LIBC_nlib_strlen 970 NLIB_ALTNAME(nlib_utf16len_, nlib_utf16len_simd)
971 NLIB_ALTNAME(nlib_utf16nlen_, nlib_utf16nlen_simd)
972 NLIB_ALTNAME(nlib_utf32len_, nlib_utf32len_generic)
973 NLIB_ALTNAME(nlib_utf32nlen_, nlib_utf32nlen_generic)
974 NLIB_ALTNAME(nlib_utf16cplen_ex_, nlib_utf16cplen_ex_simd)
977 NLIB_ALTNAME(nlib_strchr_mb, nlib_strchr_mb_simd)
991 # ifndef NLIB_LIBC_nlib_strlen 994 # ifndef NLIB_LIBC_nlib_strlen 997 NLIB_ALTNAME(nlib_utf16len_, nlib_utf16len_generic)
998 NLIB_ALTNAME(nlib_utf16nlen_, nlib_utf16nlen_generic)
999 NLIB_ALTNAME(nlib_utf32len_, nlib_utf32len_generic)
1000 NLIB_ALTNAME(nlib_utf32nlen_, nlib_utf32nlen_generic)
1001 NLIB_ALTNAME(nlib_utf16cplen_ex_, nlib_utf16cplen_ex_generic)
1004 NLIB_ALTNAME(nlib_strchr_mb, nlib_strchr_mb_generic)
1020 #endif // INCLUDE_NN_NLIB_PLATFORM_WIN32_H_