diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/system/compiler.h | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/system/compiler.h')
-rw-r--r-- | util/system/compiler.h | 498 |
1 files changed, 249 insertions, 249 deletions
diff --git a/util/system/compiler.h b/util/system/compiler.h index b373edcc46..4b70b8f452 100644 --- a/util/system/compiler.h +++ b/util/system/compiler.h @@ -1,11 +1,11 @@ -#pragma once - +#pragma once + #if defined(_MSC_VER) - #include <intrin.h> + #include <intrin.h> #endif -// useful cross-platfrom definitions for compilers - +// useful cross-platfrom definitions for compilers + /** * @def Y_FUNC_SIGNATURE * @@ -29,29 +29,29 @@ * @endcode */ #if defined(__GNUC__) - #define Y_FUNC_SIGNATURE __PRETTY_FUNCTION__ + #define Y_FUNC_SIGNATURE __PRETTY_FUNCTION__ #elif defined(_MSC_VER) - #define Y_FUNC_SIGNATURE __FUNCSIG__ + #define Y_FUNC_SIGNATURE __FUNCSIG__ #else - #define Y_FUNC_SIGNATURE "" -#endif - -#ifdef __GNUC__ - #define Y_PRINTF_FORMAT(n, m) __attribute__((__format__(__printf__, n, m))) -#endif - -#ifndef Y_PRINTF_FORMAT - #define Y_PRINTF_FORMAT(n, m) -#endif - -#if defined(__clang__) - #define Y_NO_SANITIZE(...) __attribute__((no_sanitize(__VA_ARGS__))) -#endif - -#if !defined(Y_NO_SANITIZE) - #define Y_NO_SANITIZE(...) -#endif - + #define Y_FUNC_SIGNATURE "" +#endif + +#ifdef __GNUC__ + #define Y_PRINTF_FORMAT(n, m) __attribute__((__format__(__printf__, n, m))) +#endif + +#ifndef Y_PRINTF_FORMAT + #define Y_PRINTF_FORMAT(n, m) +#endif + +#if defined(__clang__) + #define Y_NO_SANITIZE(...) __attribute__((no_sanitize(__VA_ARGS__))) +#endif + +#if !defined(Y_NO_SANITIZE) + #define Y_NO_SANITIZE(...) +#endif + /** * @def Y_DECLARE_UNUSED * @@ -68,21 +68,21 @@ * } * @endcode */ -#ifdef __GNUC__ - #define Y_DECLARE_UNUSED __attribute__((unused)) -#endif - +#ifdef __GNUC__ + #define Y_DECLARE_UNUSED __attribute__((unused)) +#endif + #ifndef Y_DECLARE_UNUSED - #define Y_DECLARE_UNUSED -#endif - + #define Y_DECLARE_UNUSED +#endif + #if defined(__GNUC__) - #define Y_LIKELY(Cond) __builtin_expect(!!(Cond), 1) - #define Y_UNLIKELY(Cond) __builtin_expect(!!(Cond), 0) - #define Y_PREFETCH_READ(Pointer, Priority) __builtin_prefetch((const void*)(Pointer), 0, Priority) - #define Y_PREFETCH_WRITE(Pointer, Priority) __builtin_prefetch((const void*)(Pointer), 1, Priority) -#endif - + #define Y_LIKELY(Cond) __builtin_expect(!!(Cond), 1) + #define Y_UNLIKELY(Cond) __builtin_expect(!!(Cond), 0) + #define Y_PREFETCH_READ(Pointer, Priority) __builtin_prefetch((const void*)(Pointer), 0, Priority) + #define Y_PREFETCH_WRITE(Pointer, Priority) __builtin_prefetch((const void*)(Pointer), 1, Priority) +#endif + /** * @def Y_FORCE_INLINE * @@ -90,113 +90,113 @@ * it to be inlined. */ #if !defined(Y_FORCE_INLINE) - #if defined(CLANG_COVERAGE) - #/* excessive __always_inline__ might significantly slow down compilation of an instrumented unit */ - #define Y_FORCE_INLINE inline - #elif defined(_MSC_VER) - #define Y_FORCE_INLINE __forceinline - #elif defined(__GNUC__) - #/* Clang also defines __GNUC__ (as 4) */ - #define Y_FORCE_INLINE inline __attribute__((__always_inline__)) - #else - #define Y_FORCE_INLINE inline - #endif + #if defined(CLANG_COVERAGE) + #/* excessive __always_inline__ might significantly slow down compilation of an instrumented unit */ + #define Y_FORCE_INLINE inline + #elif defined(_MSC_VER) + #define Y_FORCE_INLINE __forceinline + #elif defined(__GNUC__) + #/* Clang also defines __GNUC__ (as 4) */ + #define Y_FORCE_INLINE inline __attribute__((__always_inline__)) + #else + #define Y_FORCE_INLINE inline + #endif #endif /** - * @def Y_NO_INLINE + * @def Y_NO_INLINE * * Macro to use in place of 'inline' in function declaration/definition to * prevent it from being inlined. */ -#if !defined(Y_NO_INLINE) - #if defined(_MSC_VER) - #define Y_NO_INLINE __declspec(noinline) - #elif defined(__GNUC__) || defined(__INTEL_COMPILER) - #/* Clang also defines __GNUC__ (as 4) */ - #define Y_NO_INLINE __attribute__((__noinline__)) - #else - #define Y_NO_INLINE - #endif -#endif - -//to cheat compiler about strict aliasing or similar problems -#if defined(__GNUC__) - #define Y_FAKE_READ(X) \ - do { \ - __asm__ __volatile__("" \ - : \ - : "m"(X)); \ - } while (0) - - #define Y_FAKE_WRITE(X) \ - do { \ - __asm__ __volatile__("" \ - : "=m"(X)); \ - } while (0) -#endif - -#if !defined(Y_FAKE_READ) - #define Y_FAKE_READ(X) -#endif - -#if !defined(Y_FAKE_WRITE) - #define Y_FAKE_WRITE(X) -#endif - -#ifndef Y_PREFETCH_READ - #define Y_PREFETCH_READ(Pointer, Priority) (void)(const void*)(Pointer), (void)Priority -#endif - -#ifndef Y_PREFETCH_WRITE - #define Y_PREFETCH_WRITE(Pointer, Priority) (void)(const void*)(Pointer), (void)Priority -#endif - +#if !defined(Y_NO_INLINE) + #if defined(_MSC_VER) + #define Y_NO_INLINE __declspec(noinline) + #elif defined(__GNUC__) || defined(__INTEL_COMPILER) + #/* Clang also defines __GNUC__ (as 4) */ + #define Y_NO_INLINE __attribute__((__noinline__)) + #else + #define Y_NO_INLINE + #endif +#endif + +//to cheat compiler about strict aliasing or similar problems +#if defined(__GNUC__) + #define Y_FAKE_READ(X) \ + do { \ + __asm__ __volatile__("" \ + : \ + : "m"(X)); \ + } while (0) + + #define Y_FAKE_WRITE(X) \ + do { \ + __asm__ __volatile__("" \ + : "=m"(X)); \ + } while (0) +#endif + +#if !defined(Y_FAKE_READ) + #define Y_FAKE_READ(X) +#endif + +#if !defined(Y_FAKE_WRITE) + #define Y_FAKE_WRITE(X) +#endif + +#ifndef Y_PREFETCH_READ + #define Y_PREFETCH_READ(Pointer, Priority) (void)(const void*)(Pointer), (void)Priority +#endif + +#ifndef Y_PREFETCH_WRITE + #define Y_PREFETCH_WRITE(Pointer, Priority) (void)(const void*)(Pointer), (void)Priority +#endif + #ifndef Y_LIKELY - #define Y_LIKELY(Cond) (Cond) - #define Y_UNLIKELY(Cond) (Cond) -#endif - -#ifdef __GNUC__ + #define Y_LIKELY(Cond) (Cond) + #define Y_UNLIKELY(Cond) (Cond) +#endif + +#ifdef __GNUC__ #define Y_PACKED __attribute__((packed)) -#else +#else #define Y_PACKED -#endif - +#endif + #if defined(__GNUC__) - #define Y_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -#endif - -#ifndef Y_WARN_UNUSED_RESULT - #define Y_WARN_UNUSED_RESULT -#endif - + #define Y_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +#endif + +#ifndef Y_WARN_UNUSED_RESULT + #define Y_WARN_UNUSED_RESULT +#endif + +#if defined(__GNUC__) + #define Y_HIDDEN __attribute__((visibility("hidden"))) +#endif + +#if !defined(Y_HIDDEN) + #define Y_HIDDEN +#endif + #if defined(__GNUC__) - #define Y_HIDDEN __attribute__((visibility("hidden"))) -#endif - -#if !defined(Y_HIDDEN) - #define Y_HIDDEN -#endif - -#if defined(__GNUC__) - #define Y_PUBLIC __attribute__((visibility("default"))) + #define Y_PUBLIC __attribute__((visibility("default"))) #endif #if !defined(Y_PUBLIC) - #define Y_PUBLIC + #define Y_PUBLIC #endif #if !defined(Y_UNUSED) && !defined(__cplusplus) - #define Y_UNUSED(var) (void)(var) -#endif + #define Y_UNUSED(var) (void)(var) +#endif #if !defined(Y_UNUSED) && defined(__cplusplus) -template <class... Types> -constexpr Y_FORCE_INLINE int Y_UNUSED(Types&&...) { - return 0; -}; +template <class... Types> +constexpr Y_FORCE_INLINE int Y_UNUSED(Types&&...) { + return 0; +}; #endif - + /** * @def Y_ASSUME * @@ -230,18 +230,18 @@ constexpr Y_FORCE_INLINE int Y_UNUSED(Types&&...) { * @endcode */ #if defined(__GNUC__) - #define Y_ASSUME(condition) ((condition) ? (void)0 : __builtin_unreachable()) + #define Y_ASSUME(condition) ((condition) ? (void)0 : __builtin_unreachable()) #elif defined(_MSC_VER) - #define Y_ASSUME(condition) __assume(condition) + #define Y_ASSUME(condition) __assume(condition) #else - #define Y_ASSUME(condition) Y_UNUSED(condition) + #define Y_ASSUME(condition) Y_UNUSED(condition) #endif #ifdef __cplusplus [[noreturn]] #endif -Y_HIDDEN void -_YandexAbort(); +Y_HIDDEN void +_YandexAbort(); /** * @def Y_UNREACHABLE @@ -263,78 +263,78 @@ _YandexAbort(); * @endcode */ #if defined(__GNUC__) - #define Y_UNREACHABLE() __builtin_unreachable() -#elif defined(_MSC_VER) - #define Y_UNREACHABLE() __assume(false) + #define Y_UNREACHABLE() __builtin_unreachable() +#elif defined(_MSC_VER) + #define Y_UNREACHABLE() __assume(false) #else - #define Y_UNREACHABLE() _YandexAbort() + #define Y_UNREACHABLE() _YandexAbort() #endif -#if defined(undefined_sanitizer_enabled) - #define _ubsan_enabled_ -#endif +#if defined(undefined_sanitizer_enabled) + #define _ubsan_enabled_ +#endif #ifdef __clang__ - #if __has_feature(thread_sanitizer) - #define _tsan_enabled_ - #endif - #if __has_feature(memory_sanitizer) - #define _msan_enabled_ - #endif - #if __has_feature(address_sanitizer) - #define _asan_enabled_ - #endif - + #if __has_feature(thread_sanitizer) + #define _tsan_enabled_ + #endif + #if __has_feature(memory_sanitizer) + #define _msan_enabled_ + #endif + #if __has_feature(address_sanitizer) + #define _asan_enabled_ + #endif + #else - #if defined(thread_sanitizer_enabled) || defined(__SANITIZE_THREAD__) - #define _tsan_enabled_ - #endif - #if defined(memory_sanitizer_enabled) - #define _msan_enabled_ - #endif - #if defined(address_sanitizer_enabled) || defined(__SANITIZE_ADDRESS__) - #define _asan_enabled_ - #endif - -#endif - -#if defined(_asan_enabled_) || defined(_msan_enabled_) || defined(_tsan_enabled_) || defined(_ubsan_enabled_) - #define _san_enabled_ -#endif - -#if defined(_MSC_VER) - #define __PRETTY_FUNCTION__ __FUNCSIG__ -#endif + #if defined(thread_sanitizer_enabled) || defined(__SANITIZE_THREAD__) + #define _tsan_enabled_ + #endif + #if defined(memory_sanitizer_enabled) + #define _msan_enabled_ + #endif + #if defined(address_sanitizer_enabled) || defined(__SANITIZE_ADDRESS__) + #define _asan_enabled_ + #endif + +#endif + +#if defined(_asan_enabled_) || defined(_msan_enabled_) || defined(_tsan_enabled_) || defined(_ubsan_enabled_) + #define _san_enabled_ +#endif + +#if defined(_MSC_VER) + #define __PRETTY_FUNCTION__ __FUNCSIG__ +#endif #if defined(__GNUC__) - #define Y_WEAK __attribute__((weak)) + #define Y_WEAK __attribute__((weak)) #else - #define Y_WEAK + #define Y_WEAK #endif #if defined(__CUDACC_VER_MAJOR__) - #define Y_CUDA_AT_LEAST(x, y) (__CUDACC_VER_MAJOR__ > x || (__CUDACC_VER_MAJOR__ == x && __CUDACC_VER_MINOR__ >= y)) + #define Y_CUDA_AT_LEAST(x, y) (__CUDACC_VER_MAJOR__ > x || (__CUDACC_VER_MAJOR__ == x && __CUDACC_VER_MINOR__ >= y)) #else - #define Y_CUDA_AT_LEAST(x, y) 0 + #define Y_CUDA_AT_LEAST(x, y) 0 #endif // NVidia CUDA C++ Compiler did not know about noexcept keyword until version 9.0 #if !Y_CUDA_AT_LEAST(9, 0) - #if defined(__CUDACC__) && !defined(noexcept) - #define noexcept throw() - #endif + #if defined(__CUDACC__) && !defined(noexcept) + #define noexcept throw() + #endif #endif #if defined(__GNUC__) - #define Y_COLD __attribute__((cold)) - #define Y_LEAF __attribute__((leaf)) - #define Y_WRAPPER __attribute__((artificial)) + #define Y_COLD __attribute__((cold)) + #define Y_LEAF __attribute__((leaf)) + #define Y_WRAPPER __attribute__((artificial)) #else - #define Y_COLD - #define Y_LEAF - #define Y_WRAPPER + #define Y_COLD + #define Y_LEAF + #define Y_WRAPPER #endif /** @@ -356,11 +356,11 @@ _YandexAbort(); * @endcode */ #if defined(__clang__) || defined(__GNUC__) - #define Y_PRAGMA(x) _Pragma(x) -#elif defined(_MSC_VER) - #define Y_PRAGMA(x) __pragma(x) + #define Y_PRAGMA(x) _Pragma(x) +#elif defined(_MSC_VER) + #define Y_PRAGMA(x) __pragma(x) #else - #define Y_PRAGMA(x) + #define Y_PRAGMA(x) #endif /** @@ -378,13 +378,13 @@ _YandexAbort(); * @endcode */ #if defined(__clang__) || defined(__GNUC__) - #define Y_PRAGMA_DIAGNOSTIC_PUSH \ - Y_PRAGMA("GCC diagnostic push") + #define Y_PRAGMA_DIAGNOSTIC_PUSH \ + Y_PRAGMA("GCC diagnostic push") #elif defined(_MSC_VER) - #define Y_PRAGMA_DIAGNOSTIC_PUSH \ - Y_PRAGMA(warning(push)) + #define Y_PRAGMA_DIAGNOSTIC_PUSH \ + Y_PRAGMA(warning(push)) #else - #define Y_PRAGMA_DIAGNOSTIC_PUSH + #define Y_PRAGMA_DIAGNOSTIC_PUSH #endif /** @@ -402,13 +402,13 @@ _YandexAbort(); * @endcode */ #if defined(__clang__) || defined(__GNUC__) - #define Y_PRAGMA_DIAGNOSTIC_POP \ - Y_PRAGMA("GCC diagnostic pop") + #define Y_PRAGMA_DIAGNOSTIC_POP \ + Y_PRAGMA("GCC diagnostic pop") #elif defined(_MSC_VER) - #define Y_PRAGMA_DIAGNOSTIC_POP \ - Y_PRAGMA(warning(pop)) + #define Y_PRAGMA_DIAGNOSTIC_POP \ + Y_PRAGMA(warning(pop)) #else - #define Y_PRAGMA_DIAGNOSTIC_POP + #define Y_PRAGMA_DIAGNOSTIC_POP #endif /** @@ -434,13 +434,13 @@ _YandexAbort(); * @endcode */ #if defined(__clang__) || defined(__GNUC__) - #define Y_PRAGMA_NO_WSHADOW \ - Y_PRAGMA("GCC diagnostic ignored \"-Wshadow\"") + #define Y_PRAGMA_NO_WSHADOW \ + Y_PRAGMA("GCC diagnostic ignored \"-Wshadow\"") #elif defined(_MSC_VER) - #define Y_PRAGMA_NO_WSHADOW \ - Y_PRAGMA(warning(disable : 4456 4457)) + #define Y_PRAGMA_NO_WSHADOW \ + Y_PRAGMA(warning(disable : 4456 4457)) #else - #define Y_PRAGMA_NO_WSHADOW + #define Y_PRAGMA_NO_WSHADOW #endif /** @@ -470,12 +470,12 @@ _YandexAbort(); * @endcode */ #if defined(__clang__) || defined(__GNUC__) - #define Y_PRAGMA_NO_UNUSED_FUNCTION \ - Y_PRAGMA("GCC diagnostic ignored \"-Wunused-function\"") + #define Y_PRAGMA_NO_UNUSED_FUNCTION \ + Y_PRAGMA("GCC diagnostic ignored \"-Wunused-function\"") #else - #define Y_PRAGMA_NO_UNUSED_FUNCTION + #define Y_PRAGMA_NO_UNUSED_FUNCTION #endif - + /** * @ def Y_PRAGMA_NO_UNUSED_PARAMETER * @@ -504,14 +504,14 @@ _YandexAbort(); * Y_PRAGMA_DIAGNOSTIC_POP * @endcode */ -#if defined(__clang__) || defined(__GNUC__) - #define Y_PRAGMA_NO_UNUSED_PARAMETER \ - Y_PRAGMA("GCC diagnostic ignored \"-Wunused-parameter\"") +#if defined(__clang__) || defined(__GNUC__) + #define Y_PRAGMA_NO_UNUSED_PARAMETER \ + Y_PRAGMA("GCC diagnostic ignored \"-Wunused-parameter\"") #elif defined(_MSC_VER) - #define Y_PRAGMA_NO_UNUSED_PARAMETER \ - Y_PRAGMA(warning(disable : 4100)) + #define Y_PRAGMA_NO_UNUSED_PARAMETER \ + Y_PRAGMA(warning(disable : 4100)) #else - #define Y_PRAGMA_NO_UNUSED_PARAMETER + #define Y_PRAGMA_NO_UNUSED_PARAMETER #endif /** @@ -541,18 +541,18 @@ _YandexAbort(); * @endcode */ #if defined(__clang__) || defined(__GNUC__) - #define Y_PRAGMA_NO_DEPRECATED \ - Y_PRAGMA("GCC diagnostic ignored \"-Wdeprecated\"") + #define Y_PRAGMA_NO_DEPRECATED \ + Y_PRAGMA("GCC diagnostic ignored \"-Wdeprecated\"") #elif defined(_MSC_VER) - #define Y_PRAGMA_NO_DEPRECATED \ - Y_PRAGMA(warning(disable : 4996)) + #define Y_PRAGMA_NO_DEPRECATED \ + Y_PRAGMA(warning(disable : 4996)) #else - #define Y_PRAGMA_NO_DEPRECATED + #define Y_PRAGMA_NO_DEPRECATED #endif // Memory sanitizer sometimes doesn't correctly set parameter shadow of constant functions. #if (defined(__clang__) || defined(__GNUC__)) && !defined(_msan_enabled_) - /** + /** * @def Y_CONST_FUNCTION methods and functions, marked with this method are promised to: 1. do not have side effects @@ -562,15 +562,15 @@ _YandexAbort(); NOTE: in common case this attribute can't be set if method have pointer-arguments NOTE: as result there no any reason to discard result of such method */ - #define Y_CONST_FUNCTION [[gnu::const]] -#endif - -#if !defined(Y_CONST_FUNCTION) - #define Y_CONST_FUNCTION -#endif - -#if defined(__clang__) || defined(__GNUC__) - /** + #define Y_CONST_FUNCTION [[gnu::const]] +#endif + +#if !defined(Y_CONST_FUNCTION) + #define Y_CONST_FUNCTION +#endif + +#if defined(__clang__) || defined(__GNUC__) + /** * @def Y_PURE_FUNCTION methods and functions, marked with this method are promised to: 1. do not have side effects @@ -578,12 +578,12 @@ _YandexAbort(); this allow compilers to do hard optimization of that functions NOTE: as result there no any reason to discard result of such method */ - #define Y_PURE_FUNCTION [[gnu::pure]] -#endif - -#if !defined(Y_PURE_FUNCTION) - #define Y_PURE_FUNCTION -#endif + #define Y_PURE_FUNCTION [[gnu::pure]] +#endif + +#if !defined(Y_PURE_FUNCTION) + #define Y_PURE_FUNCTION +#endif /** * @ def Y_HAVE_INT128 @@ -599,7 +599,7 @@ _YandexAbort(); * @endcode */ #if defined(__SIZEOF_INT128__) - #define Y_HAVE_INT128 1 + #define Y_HAVE_INT128 1 #endif /** @@ -609,19 +609,19 @@ _YandexAbort(); * for compilers that doesn't support XRay. */ #if defined(XRAY) && defined(__cplusplus) - #include <xray/xray_interface.h> - #define Y_XRAY_ALWAYS_INSTRUMENT [[clang::xray_always_instrument]] - #define Y_XRAY_NEVER_INSTRUMENT [[clang::xray_never_instrument]] - #define Y_XRAY_CUSTOM_EVENT(__string, __length) \ - do { \ - __xray_customevent(__string, __length); \ - } while (0) + #include <xray/xray_interface.h> + #define Y_XRAY_ALWAYS_INSTRUMENT [[clang::xray_always_instrument]] + #define Y_XRAY_NEVER_INSTRUMENT [[clang::xray_never_instrument]] + #define Y_XRAY_CUSTOM_EVENT(__string, __length) \ + do { \ + __xray_customevent(__string, __length); \ + } while (0) #else - #define Y_XRAY_ALWAYS_INSTRUMENT - #define Y_XRAY_NEVER_INSTRUMENT - #define Y_XRAY_CUSTOM_EVENT(__string, __length) \ - do { \ - } while (0) + #define Y_XRAY_ALWAYS_INSTRUMENT + #define Y_XRAY_NEVER_INSTRUMENT + #define Y_XRAY_CUSTOM_EVENT(__string, __length) \ + do { \ + } while (0) #endif #ifdef __cplusplus @@ -630,21 +630,21 @@ void UseCharPointerImpl(volatile const char*); template <typename T> Y_FORCE_INLINE void DoNotOptimizeAway(T&& datum) { - #if defined(_MSC_VER) + #if defined(_MSC_VER) UseCharPointerImpl(&reinterpret_cast<volatile const char&>(datum)); _ReadWriteBarrier(); - #elif defined(__GNUC__) && defined(_x86_) + #elif defined(__GNUC__) && defined(_x86_) asm volatile("" : : "X"(datum)); - #else + #else Y_FAKE_READ(datum); - #endif + #endif } - /** + /** * Use this macro to prevent unused variables elimination. */ - #define Y_DO_NOT_OPTIMIZE_AWAY(X) ::DoNotOptimizeAway(X) + #define Y_DO_NOT_OPTIMIZE_AWAY(X) ::DoNotOptimizeAway(X) #endif |