From 870fc1a72069f8cd26359221a5d9deb4328e4c58 Mon Sep 17 00:00:00 2001 From: HedgehogInTheCPP Date: Tue, 25 Aug 2026 22:54:57 +0300 Subject: [PATCH] Improvements detection of features, part 15, added FASTFLOAT_NO_UNIQUE_ADDRESS and improves more. --- include/fast_float/ascii_number.h | 21 +++--- include/fast_float/constexpr_feature_detect.h | 67 +++++++++++++------ include/fast_float/float_common.h | 4 +- 3 files changed, 59 insertions(+), 33 deletions(-) diff --git a/include/fast_float/ascii_number.h b/include/fast_float/ascii_number.h index a3de75d..c768c93 100644 --- a/include/fast_float/ascii_number.h +++ b/include/fast_float/ascii_number.h @@ -473,19 +473,19 @@ enum class parse_error : uint_fast8_t { }; template struct parsed_number_string_t { - am_mant_t mantissa; - am_pow_t exponent; - UC const *lastmatch; + FASTFLOAT_NO_UNIQUE_ADDRESS am_mant_t mantissa; + FASTFLOAT_NO_UNIQUE_ADDRESS am_pow_t exponent; + FASTFLOAT_NO_UNIQUE_ADDRESS UC const *lastmatch; #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN - bool negative; + FASTFLOAT_NO_UNIQUE_ADDRESS bool negative; #endif - bool invalid; - bool too_many_digits; - parse_error error; + FASTFLOAT_NO_UNIQUE_ADDRESS bool invalid; + FASTFLOAT_NO_UNIQUE_ADDRESS bool too_many_digits; + FASTFLOAT_NO_UNIQUE_ADDRESS parse_error error; // contains the range of the significant digits - span integer; // non-nullable - span fraction; // nullable + FASTFLOAT_NO_UNIQUE_ADDRESS span integer; // non-nullable + FASTFLOAT_NO_UNIQUE_ADDRESS span fraction; // nullable }; using byte_span = span; @@ -774,9 +774,8 @@ parse_int_string(UC const *p, UC const *pend, T &value, FASTFLOAT_ASSUME(p < pend); // so dereference without checks from_chars_result_t answer; - auto const *const first = p; - #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN + auto const *const first = p; // Read sign auto const negative = (*p == UC('-')); #ifdef FASTFLOAT_VISUAL_STUDIO diff --git a/include/fast_float/constexpr_feature_detect.h b/include/fast_float/constexpr_feature_detect.h index 657b068..11ef4e5 100644 --- a/include/fast_float/constexpr_feature_detect.h +++ b/include/fast_float/constexpr_feature_detect.h @@ -1,16 +1,42 @@ #ifndef FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H #define FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H -#ifdef __has_include -#if __has_include() -#include +#ifdef _MSVC_LANG +#define FASTFLOAT_CPLUSPLUS _MSVC_LANG +#else +#define FASTFLOAT_CPLUSPLUS __cplusplus #endif + +// Detect __has_*. +#ifdef __has_feature +#define FASTFLOAT_HAS_FEATURE(x) __has_feature(x) +#else +#define FASTFLOAT_HAS_FEATURE(x) 0 +#endif +#ifdef __has_include +#define FASTFLOAT_HAS_INCLUDE(x) __has_include(x) +#else +#define FASTFLOAT_HAS_INCLUDE(x) 0 +#endif +#ifdef __has_builtin +#define FASTFLOAT_HAS_BUILTIN(x) __has_builtin(x) +#else +#define FASTFLOAT_HAS_BUILTIN(x) 0 +#endif +#ifdef __has_cpp_attribute +#define FASTFLOAT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) +#else +#define FASTFLOAT_HAS_CPP_ATTRIBUTE(x) 0 +#endif + +#if FASTFLOAT_HAS_INCLUDE() +#include #endif // C++14 constexpr #if defined(__cpp_constexpr) && __cpp_constexpr >= 201304L #define FASTFLOAT_CONSTEXPR14 constexpr -#elif __cplusplus >= 201402L +#elif FASTFLOAT_CPLUSPLUS >= 201402L #define FASTFLOAT_CONSTEXPR14 constexpr #elif defined(_MSC_VER) && _MSC_VER >= 1910 && _MSVC_LANG >= 201402L #define FASTFLOAT_CONSTEXPR14 constexpr @@ -21,10 +47,7 @@ // C++14 variable templates #if defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304L #define FASTFLOAT_HAS_VARIABLE_TEMPLATES 1 -#elif __cplusplus >= 201402L -#define FASTFLOAT_HAS_VARIABLE_TEMPLATES 1 -#elif defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023918L && \ - defined(_MSC_VER) && _MSVC_LANG >= 201402L +#elif FASTFLOAT_CPLUSPLUS >= 201402L #define FASTFLOAT_HAS_VARIABLE_TEMPLATES 1 #else #define FASTFLOAT_HAS_VARIABLE_TEMPLATES 0 @@ -35,9 +58,7 @@ #define FASTFLOAT_CONSTEXPR17 constexpr #elif defined(__cpp_constexpr) && __cpp_constexpr >= 201603L #define FASTFLOAT_CONSTEXPR17 constexpr -#elif __cplusplus >= 201703L -#define FASTFLOAT_CONSTEXPR17 constexpr -#elif defined(_MSC_VER) && _MSC_VER >= 1911 && _MSVC_LANG >= 201703L +#elif FASTFLOAT_CPLUSPLUS >= 201703L #define FASTFLOAT_CONSTEXPR17 constexpr #else #define FASTFLOAT_CONSTEXPR17 @@ -55,7 +76,7 @@ #endif // Before C++17 constexpr variables may need an out-of-class definition. -#if __cplusplus >= 201703L || (defined(_MSC_VER) && _MSVC_LANG >= 201703L) +#if FASTFLOAT_CPLUSPLUS >= 201703L #define FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE 0 #else #define FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE 1 @@ -92,17 +113,23 @@ #define FASTFLOAT_HAS_BYTESWAP 0 #endif -#if defined(__has_builtin) -#define FASTFLOAT_HAS_BUILTIN(x) __has_builtin(x) -#else -#define FASTFLOAT_HAS_BUILTIN(x) false -#endif - -#if defined(__cpp_attrubute_assume) -// For support attribute [[assume]] is declared in P1774 +#ifdef FASTFLOAT_ASSUME +// Use the provided definition. +#elif FASTFLOAT_HAS_CPP_ATTRIBUTE(assume) #define FASTFLOAT_ASSUME(expr) [[assume(expr)]] #else #define FASTFLOAT_ASSUME(expr) #endif +#ifdef FASTFLOAT_NO_UNIQUE_ADDRESS +// Use the provided definition. +#elif FASTFLOAT_CPLUSPLUS < 202002L +// Not supported. +#elif FASTFLOAT_HAS_CPP_ATTRIBUTE(no_unique_address) +#define FASTFLOAT_NO_UNIQUE_ADDRESS [[no_unique_address]] +// VS2019 v16.10 and later except clang-cl (https://reviews.llvm.org/D110485). +#elif defined(_MSC_VER) && _MSC_VER >= 1929 && !defined(__clang__) +#define FASTFLOAT_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] +#endif + #endif // FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index cab9fd6..10cc861 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -687,8 +687,8 @@ full_multiplication(uint64_t a, uint64_t b) noexcept { /* alignas(16) - better data cache usage without align */ struct adjusted_mantissa { - am_mant_t mantissa; - am_pow_t power2; + FASTFLOAT_NO_UNIQUE_ADDRESS am_mant_t mantissa; + FASTFLOAT_NO_UNIQUE_ADDRESS am_pow_t power2; constexpr adjusted_mantissa() noexcept : mantissa(0), power2(0) {}