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 #ifndef __cpp_static_assert 106 #define __cpp_static_assert 200410L // N1720 109 #ifndef __cpp_rvalue_references 110 #define __cpp_rvalue_references 200610L // N2118 113 #ifndef __cpp_lambdas 114 #define __cpp_lambdas 200907L // N2927 117 #ifndef __cpp_range_based_for 118 #define __cpp_range_based_for 200907L // N2930 121 #ifndef __cpp_alias_templates 122 #define __cpp_alias_templates 200704L // N2258 125 #ifndef __cpp_variadic_templates 126 #define __cpp_variadic_templates 200704L // N2242 129 #ifndef __cpp_delegating_constructors 130 #define __cpp_delegating_constructors 200604L // N1986 133 #ifndef __cpp_lib_make_unique 134 #define __cpp_lib_make_unique 201304L // N3656 136 #ifndef __cpp_lib_transparent_operators 137 #define __cpp_lib_transparent_operators 201210L // N3421 139 #ifndef __cpp_lib_transformation_trait_aliases 140 #define __cpp_lib_transformation_trait_aliases 201304L // N3655 142 #ifndef __cpp_lib_incomplete_container_elements 143 #define __cpp_lib_incomplete_container_elements 201505L // N4510 147 #define NLIB_CXX11_NOEXCEPT 148 #define NLIB_CXX11_ALIGNMENT_SUPPORT 149 #define NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS 151 #ifndef __cpp_constexpr 152 #define __cpp_constexpr 200704 // N2235 155 #ifndef __cpp_unicode_characters 156 #define __cpp_unicode_characters 200704L // N2249 160 #ifndef __cpp_raw_strings 161 #define __cpp_raw_strings 200710L // N2442 163 #ifndef __cpp_unicode_literals 164 #define __cpp_unicode_literals 200710L // N2442 166 #ifndef __cpp_user_defined_literals 167 #define __cpp_user_defined_literals 200809L // N2765 169 #ifndef __cpp_decltype 170 #define __cpp_decltype 200707L // N2343 172 #ifndef __cpp_attributes 173 #define __cpp_attributes 200809L // N2761 175 #ifndef __cpp_initializer_lists 176 #define __cpp_initializer_lists 200806L // N2672 179 #define __cpp_nsdmi 200809L // N2756 181 #ifndef __cpp_inheriting_constructors 182 #define __cpp_inheriting_constructors 200802L // N2540 184 #ifndef __cpp_ref_qualifiers 185 #define __cpp_ref_qualifiers 200710L // N2439 189 #ifndef __cpp_binary_literals 190 #define __cpp_binary_literals 201304L // N3472 192 #ifndef __cpp_init_captures 193 #define __cpp_init_captures 201304L // N3648 195 #ifndef __cpp_generic_lambdas 196 #define __cpp_generic_lambdas 201304L // N3649 198 #ifndef __cpp_sized_deallocation 199 #define __cpp_sized_deallocation 201309L // N3778 201 #ifndef __cpp_decltype_auto 202 #define __cpp_decltype_auto 201304L // N3638 204 #ifndef __cpp_return_type_deduction 205 #define __cpp_return_type_deduction 201304L // N3638 207 #ifndef __cpp_variable_templates 208 #define __cpp_variable_templates 201304L // N3651 210 #ifndef __cpp_lib_is_null_pointer 211 #define __cpp_lib_is_null_pointer 201309L // LWG2247 213 #ifndef __cpp_lib_integer_sequence 214 #define __cpp_lib_integer_sequence 201304L // N3658 216 #ifndef __cpp_lib_exchange_function 217 #define __cpp_lib_exchange_function 201304L // N3668 219 #ifndef __cpp_lib_tuples_by_type 220 #define __cpp_lib_tuples_by_type 201304L // N3670 222 #ifndef __cpp_lib_tuple_element_t 223 #define __cpp_lib_tuple_element_t 201402L // N3887 225 #ifndef __cpp_lib_integral_constant_callable 226 #define __cpp_lib_integral_constant_callable 201304L // N3545 228 #ifndef __cpp_lib_result_of_sfinae 229 #define __cpp_lib_result_of_sfinae 201210L // N3642 231 #ifndef __cpp_lib_is_final 232 #define __cpp_lib_is_final 201402L // LWG2112 234 #ifndef __cpp_lib_chrono_udls 235 #define __cpp_lib_chrono_udls 201304L // N3642 237 #ifndef __cpp_lib_string_udls 238 #define __cpp_lib_string_udls 201304L // N3642 240 #ifndef __cpp_lib_generic_associative_lookup 241 #define __cpp_lib_generic_associative_lookup 201304L // N3657 243 #ifndef __cpp_lib_null_iterators 244 #define __cpp_lib_null_iterators 201304L // N3644 246 #ifndef __cpp_lib_make_reverse_iterator 247 #define __cpp_lib_make_reverse_iterator 201402L // LWG2285 249 #ifndef __cpp_lib_robust_nonmodifying_seq_ops 250 #define __cpp_lib_robust_nonmodifying_seq_ops 201304L // N3671 252 #ifndef __cpp_lib_complex_udls 253 #define __cpp_lib_complex_udls 201309L // N3779 255 #ifndef __cpp_lib_quoted_string_io 256 #define __cpp_lib_quoted_string_io 201304L // N3654 258 #ifndef __cpp_lib_shared_timed_mutex 259 #define __cpp_lib_shared_timed_mutex 201402L // N3891 261 #if _MSVC_LANG > 201402L 262 #ifndef __cpp_namespace_attributes 263 #define __cpp_namespace_attributes 201411L // N4266 265 #ifndef __cpp_enumerator_attributes 266 #define __cpp_enumerator_attributes 201411L // N4266 268 #ifndef __cpp_lib_type_trait_variable_templates 269 #define __cpp_lib_type_trait_variable_templates // P0006R0 271 #ifndef __cpp_lib_logical_traits 272 #define __cpp_lib_logical_traits 201510 // P0013R1 274 #ifndef __cpp_lib_as_const 275 #define __cpp_lib_as_const 201510 // P0007R1 277 #ifndef __cpp_lib_transparent_operators 278 #define __cpp_lib_transparent_operators 201510L // P0074R0 280 #ifndef __cpp_lib_chrono 281 #define __cpp_lib_chrono 201510 // P0092R1 283 #ifndef __cpp_lib_lock_guard_variadic 284 #define __cpp_lib_lock_guard_variadic 201510L // P0156R0 286 #ifndef __cpp_lib_uncaught_exceptions 287 #define __cpp_lib_uncaught_exceptions 201411L // N4259 289 #ifndef __cpp_lib_shared_mutex 290 #define __cpp_lib_shared_mutex 201505L // N4508 296 #undef __cpp_constexpr 297 #define __cpp_constexpr 201304L // N3652 298 #ifndef __cpp_aggregate_nsdmi 299 #define __cpp_aggregate_nsdmi 201304L // N3653 301 #if _MSVC_LANG > 201402L 310 #undef __cpp_range_based_for 311 #define __cpp_range_based_for 201603L // P0184R0 312 #undef __cpp_static_assert 313 #define __cpp_static_assert 201411L // N3928 314 #ifndef __cpp_nested_namespace_definitions 315 #define __cpp_nested_namespace_definitions 201411L // N4230 327 #include <inttypes.h> 328 #if (_MSC_VER < 1900) 330 #define __func__ __FUNCTION__ 339 #define va_copy(dest, src) (dest = src) 341 #define NLIB_ALWAYS_INLINE __forceinline 342 #define NLIB_NEVER_INLINE __declspec(noinline) 343 #define NLIB_LIKELY(x) (x) 344 #define NLIB_UNLIKELY(x) (x) 345 #define NLIB_EXPECT(var, exp_value) (var) 346 #define NLIB_CHECK_RESULT 347 #if defined(__cplusplus) && _MSC_VER >= 1900 348 #define NLIB_NORETURN [[noreturn]] 350 #define NLIB_NORETURN 352 #if defined(__cplusplus) && _MSC_VER >= 1910 && _MSVC_LANG > 201402L 353 #define NLIB_FALLTHROUGH [[fallthrough]] 355 #define NLIB_FALLTHROUGH 358 #define NLIB_NONNULL_1 359 #define NLIB_NONNULL_2 360 #define NLIB_NONNULL_3 361 #define NLIB_NONNULL_4 362 #define NLIB_NONNULL_5 363 #define NLIB_ATTRIBUTE_MALLOC 364 #define NLIB_ATTRIBUTE_PURE 365 #define NLIB_ATTRIBUTE_CONST 366 #define NLIB_ATTRIBUTE_ALLOC_SIZE1(n) 367 #define NLIB_ATTRIBUTE_ALLOC_SIZE2(n0, n1) 368 #define NLIB_ATTRIBUTE_ALLOC_ALIGN(algn) 369 #define NLIB_ATTRIBUTE_ASSUME_ALIGNED(n) 370 #ifndef NLIB_DEPRECATED 371 #if defined(__cplusplus) && _MSC_VER >= 1910 372 #define NLIB_DEPRECATED [[deprecated]] 374 #define NLIB_DEPRECATED __declspec(deprecated) 377 #ifndef NLIB_DEPRECATED_MSG 378 #if defined(__cplusplus) && _MSC_VER >= 1910 379 #define NLIB_DEPRECATED_MSG(msg) [[deprecated(msg)]] 381 #define NLIB_DEPRECATED_MSG(msg) __declspec(deprecated(msg)) 384 #define NLIB_WEAKSYMBOL 385 #define NLIB_VIS_HIDDEN 387 #define NLIB_EXPIMP_TEMPLATE_(x) template class NLIB_VIS_PUBLIC x 388 #define NLIB_WINEXPORT __declspec(dllexport) 389 #define NLIB_WINIMPORT __declspec(dllimport) 390 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT 391 #define NLIB_EXPIMP_TEMPLATE(x) extern NLIB_EXPIMP_TEMPLATE_(x) 393 #define NLIB_VIS_PUBLIC 394 #define NLIB_EXPIMP_TEMPLATE(x) 397 #if defined(n_EXPORTS) 398 #undef NLIB_VIS_PUBLIC 399 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT 400 #elif defined(nx_misc_EXPORTS) 401 #undef NLIB_EXPIMP_TEMPLATE 402 #define NLIB_EXPIMP_TEMPLATE(x) NLIB_EXPIMP_TEMPLATE_(x) 405 #define NLIB_VIS_PUBLIC_ALT 407 #define NLIB_LITTLE_ENDIAN 416 #define NLIB_MEMORY_ORDER_RELEASE \ 417 __pragma(warning(push)) __pragma(warning(disable : 4127)) do { \ 421 while (0) __pragma(warning(pop)) 422 #define NLIB_MEMORY_ORDER_ACQUIRE \ 423 __pragma(warning(push)) __pragma(warning(disable : 4127)) do { \ 427 while (0) __pragma(warning(pop)) 428 #define NLIB_MEMORY_ORDER_ACQ_REL \ 429 __pragma(warning(push)) __pragma(warning(disable : 4127)) do { \ 430 _ReadWriteBarrier(); \ 433 while (0) __pragma(warning(pop)) 434 #define NLIB_MEMORY_ORDER_SEQ_CST NLIB_MEMORY_ORDER_ACQ_REL 438 #define __PRIS_PREFIX "ll" 440 #define __PRIS_PREFIX 442 #define NLIB_WARN__(x) #x 443 #define NLIB_WARN_(x) NLIB_WARN__(x) 444 #define NLIB_WARN(exp) (__FILE__ "(" NLIB_WARN_(__LINE__) ") : WARNING: " exp) 449 #define NLIB_TIMESPEC_HAS_NATIVE 452 #pragma pack(push, 8) 453 typedef struct nlib_mutex_ {
462 #define NLIB_MUTEX_INITIALIZER \ 464 #define NLIB_RECURSIVE_MUTEX_INITIALIZER \ 466 #define NLIB_RECURSIVE_TIMED_MUTEX_INITIALIZER \ 471 typedef struct nlib_cond_ {
472 CONDITION_VARIABLE cond;
475 #define NLIB_COND_INITIALIZER \ 476 { 0, NLIB_MUTEX_INITIALIZER } 480 #define NLIB_ATTRIBUTE_PRINTF(x, y) 482 #define NLIB_ASSUME(cond) __assume(cond) 484 #define NLIB_RWLOCK_HAS_NATIVE 485 #ifdef NLIB_RWLOCK_HAS_NATIVE 487 #define NLIB_RWLOCK_INITIALIZER SRWLOCK_INIT 489 #define NLIB_TIMER_HAS_NATIVE 490 #define NLIB_ONCE_HAS_NATIVE 494 #define NLIB_LIBC_nlib_memcmp 495 #define NLIB_LIBC_nlib_strlen 496 #define NLIB_LIBC_nlib_strnlen 497 #define NLIB_LIBC_nlib_wcslen 498 #define NLIB_LIBC_nlib_wcsnlen 499 #define NLIB_LIBC_nlib_strcpy 500 #define NLIB_LIBC_nlib_strncpy 501 #define NLIB_LIBC_nlib_wcscpy 502 #define NLIB_LIBC_nlib_wcsncpy 503 #define NLIB_LIBC_nlib_strchr 504 #define NLIB_LIBC_nlib_strrchr 506 #if !defined(__INTELLISENSE__) 507 #define NLIB_ATOMIC_RELAXED (0) 508 #define NLIB_ATOMIC_ACQUIRE (1) 509 #define NLIB_ATOMIC_RELEASE (2) 510 #define NLIB_ATOMIC_ACQ_REL (3) 511 #define NLIB_ATOMIC_SEQ_CST (7) 536 _InterlockedExchange((
volatile long*)ptr, val);
545 result = (int32_t)_InterlockedExchange((
volatile long*)ptr, val);
552 int success_memorder,
int failure_memorder) {
555 result = _InterlockedCompareExchange((
volatile long*)ptr, desired, *expected);
558 (void)success_memorder;
559 (void)failure_memorder;
560 if (result == *expected) {
572 result = _InterlockedExchangeAdd((
volatile long*)ptr, val) + val;
581 result = _InterlockedExchangeAdd((
volatile long*)ptr, -val) - val;
590 result = _InterlockedAnd((
volatile long*)ptr, val) & val;
599 result = _InterlockedXor((
volatile long*)ptr, val) ^ val;
608 result = _InterlockedOr((
volatile long*)ptr, val) | val;
617 result = _InterlockedExchangeAdd((
volatile long*)ptr, val);
626 result = _InterlockedExchangeAdd((
volatile long*)ptr, -val);
635 result = _InterlockedAnd((
volatile long*)ptr, val);
644 result = _InterlockedXor((
volatile long*)ptr, val);
653 result = _InterlockedOr((
volatile long*)ptr, val);
677 InterlockedExchange64((
volatile long long*)ptr, val);
679 _InterlockedExchange64((
volatile long long*)ptr, val);
690 result = (int64_t)InterlockedExchange64((
volatile long long*)ptr, val);
692 result = (int64_t)_InterlockedExchange64((
volatile long long*)ptr, val);
708 int success_memorder,
int failure_memorder) {
712 result = InterlockedCompareExchange64((
volatile long long*)ptr, desired, *expected);
714 result = _InterlockedCompareExchange64((
volatile long long*)ptr, desired, *expected);
718 (void)success_memorder;
719 (void)failure_memorder;
720 if (result == *expected) {
733 result = InterlockedExchangeAdd64((
volatile long long*)ptr, val) + val;
735 result = _InterlockedExchangeAdd64((
volatile long long*)ptr, val) + val;
746 result = InterlockedExchangeAdd64((
volatile long long*)ptr, -val) - val;
748 result = _InterlockedExchangeAdd64((
volatile long long*)ptr, -val) - val;
759 result = InterlockedAnd64((
volatile long long*)ptr, val) & val;
761 result = _InterlockedAnd64((
volatile long long*)ptr, val) & val;
772 result = InterlockedXor64((
volatile long long*)ptr, val) ^ val;
774 result = _InterlockedXor64((
volatile long long*)ptr, val) ^ val;
785 result = InterlockedOr64((
volatile long long*)ptr, val) | val;
787 result = _InterlockedOr64((
volatile long long*)ptr, val) | val;
798 result = InterlockedExchangeAdd64((
volatile long long*)ptr, val);
800 result = _InterlockedExchangeAdd64((
volatile long long*)ptr, val);
811 result = InterlockedExchangeAdd64((
volatile long long*)ptr, -val);
813 result = _InterlockedExchangeAdd64((
volatile long long*)ptr, -val);
824 result = InterlockedAnd64((
volatile long long*)ptr, val);
826 result = _InterlockedAnd64((
volatile long long*)ptr, val);
837 result = InterlockedXor64((
volatile long long*)ptr, val);
839 result = _InterlockedXor64((
volatile long long*)ptr, val);
850 result = InterlockedOr64((
volatile long long*)ptr, val);
852 result = _InterlockedOr64((
volatile long long*)ptr, val);
876 #if (_MSC_VER == 1800 && !defined(NLIB_64BIT)) 877 InterlockedExchangePointer((
void*
volatile*)ptr, val);
879 _InterlockedExchangePointer((
void*
volatile*)ptr, val);
887 int success_memorder,
int failure_memorder) {
890 result = _InterlockedCompareExchangePointer((
void*
volatile*)ptr, desired, *expected);
893 (void)success_memorder;
894 (void)failure_memorder;
895 if (result == *expected) {
925 #define NLIB_ALTNAME(func1, func2) \ 926 __pragma(comment(linker, "/alternatename:_" NLIB_STRINGIFY(func1) "=_" NLIB_STRINGIFY(func2))) 928 #define NLIB_ALTNAME(func1, func2) \ 929 __pragma(comment(linker, "/alternatename:" NLIB_STRINGIFY(func1) "=" NLIB_STRINGIFY(func2))) 938 #if defined(NLIB_SIMD) 939 #ifndef NLIB_LIBC_nlib_strlen 942 #ifndef NLIB_LIBC_nlib_strlen 945 NLIB_ALTNAME(nlib_utf16len_, nlib_utf16len_simd)
946 NLIB_ALTNAME(nlib_utf16nlen_, nlib_utf16nlen_simd)
947 NLIB_ALTNAME(nlib_utf32len_, nlib_utf32len_generic)
948 NLIB_ALTNAME(nlib_utf32nlen_, nlib_utf32nlen_generic)
949 NLIB_ALTNAME(nlib_utf16cplen_ex_, nlib_utf16cplen_ex_simd)
952 NLIB_ALTNAME(nlib_strchr_mb, nlib_strchr_mb_simd)
966 #ifndef NLIB_LIBC_nlib_strlen 969 #ifndef NLIB_LIBC_nlib_strlen 972 NLIB_ALTNAME(nlib_utf16len_, nlib_utf16len_generic)
973 NLIB_ALTNAME(nlib_utf16nlen_, nlib_utf16nlen_generic)
974 NLIB_ALTNAME(nlib_utf32len_, nlib_utf32len_generic)
975 NLIB_ALTNAME(nlib_utf32nlen_, nlib_utf32nlen_generic)
976 NLIB_ALTNAME(nlib_utf16cplen_ex_, nlib_utf16cplen_ex_generic)
979 NLIB_ALTNAME(nlib_strchr_mb, nlib_strchr_mb_generic)
995 #endif // INCLUDE_NN_NLIB_PLATFORM_WIN32_H_