CompilerEnvironmentMsvc.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #pragma once
  2. #if _MSC_VER < 1900
  3. #error "Baselib requires C++11 support, i.e. MSVC 2015 or newer"
  4. #endif
  5. #define COMPILER_MSVC 1
  6. #ifdef _CPPUNWIND
  7. #define COMPILER_SUPPORTS_EXCEPTIONS _CPPUNWIND
  8. #else
  9. #define COMPILER_SUPPORTS_EXCEPTIONS 0
  10. #endif
  11. #ifdef _CPPRTTI
  12. #define COMPILER_SUPPORTS_RTTI _CPPRTTI
  13. #else
  14. #define COMPILER_SUPPORTS_RTTI 0
  15. #endif
  16. #define COMPILER_SUPPORTS_GENERIC_LAMBDA_EXPRESSIONS 1 // _MSC_VER >= 1900
  17. #define COMPILER_BUILTIN_EXPECT(X_, Y_) (X_)
  18. // Tells the compiler to assume that this statement is never reached.
  19. // (reaching it anyways is undefined behavior!)
  20. #define COMPILER_BUILTIN_UNREACHABLE() __assume(false)
  21. // Tells the compiler to assume that the given expression is true until the expression is modified.
  22. // (it is undefined behavior if the expression is not true after all)
  23. #define COMPILER_BUILTIN_ASSUME(EXPR_) __assume(EXPR_)
  24. #define HAS_CLANG_FEATURE(x) 0
  25. // Warning management
  26. #define COMPILER_PRINT_MESSAGE(MESSAGE_) __pragma(message(__FILE__ "(" PP_STRINGIZE(__LINE__) ") : info: " MESSAGE_))
  27. #define COMPILER_PRINT_WARNING(MESSAGE_) __pragma(message(__FILE__ "(" PP_STRINGIZE(__LINE__) ") : warning: " MESSAGE_))
  28. #define COMPILER_WARNING_UNUSED_VARIABLE 4101
  29. #define COMPILER_WARNING_DEPRECATED 4995 4996
  30. #define COMPILER_WARNINGS_PUSH __pragma(warning(push))
  31. #define COMPILER_WARNINGS_POP __pragma(warning(pop))
  32. #define COMPILER_WARNINGS_DISABLE(Warn) __pragma(warning(disable : Warn))
  33. #define COMPILER_NOINLINE __declspec(noinline)
  34. #define COMPILER_INLINE inline
  35. #define COMPILER_FORCEINLINE __forceinline
  36. #define COMPILER_EMPTYINLINE __forceinline
  37. #define COMPILER_NORETURN __declspec(noreturn)
  38. #define COMPILER_DEPRECATED(msg) __declspec(deprecated(msg))
  39. #define COMPILER_DEPRECATED_ENUM_VALUE(msg) /* no equivalent for this in MSVC */
  40. #define COMPILER_ALIGN_OF(TYPE_) __alignof(TYPE_)
  41. #define COMPILER_ALIGN_AS(ALIGN_) __declspec(align(ALIGN_))
  42. #define COMPILER_C_STATIC_ASSERT(EXPR_, MSG_) typedef char __static_assert_t[(EXPR_) != 0]
  43. #define COMPILER_ATTRIBUTE_UNUSED __pragma(warning(suppress:4100))
  44. #define COMPILER_DEBUG_TRAP() __debugbreak()
  45. // Note that this is best effort, as "/analyze" compiler flag required to make warning appear
  46. #define COMPILER_WARN_UNUSED_RESULT _Check_return_
  47. #if !defined(alloca)
  48. #define alloca _alloca
  49. #endif
  50. #if PLATFORM_SUPPORTS_SSE
  51. #include <xmmintrin.h>
  52. // Prefetches memory for reading from address `address` if supported on the current architecture
  53. #define COMPILER_PREFETCH_READ(address) _mm_prefetch(reinterpret_cast<const char*>(address), _MM_HINT_T0)
  54. // Prefetches memory for writing from address `address` if supported on the current architecture
  55. #define COMPILER_PREFETCH_WRITE(address) _mm_prefetch(reinterpret_cast<const char*>(address), _MM_HINT_ENTA)
  56. #else
  57. // Prefetches memory for reading from address `address` if supported on the current architecture
  58. #define COMPILER_PREFETCH_READ(address)
  59. // Prefetches memory for writing from address `address` if supported on the current architecture
  60. #define COMPILER_PREFETCH_WRITE(address)
  61. #endif