From f59f73c4dac05e115e186a3b5a4401bd808c5781 Mon Sep 17 00:00:00 2001 From: Maya Warrier Date: Sat, 1 Apr 2023 04:09:00 -0400 Subject: [PATCH] Disable simd-related warnings --- include/fast_float/ascii_number.h | 24 +++++++++++------------- include/fast_float/fast_float.h | 7 ++----- include/fast_float/float_common.h | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/include/fast_float/ascii_number.h b/include/fast_float/ascii_number.h index 2676182..9c2ed8a 100644 --- a/include/fast_float/ascii_number.h +++ b/include/fast_float/ascii_number.h @@ -9,8 +9,6 @@ #include "float_common.h" -#define FASTFLOAT_SSE2 1 - #if FASTFLOAT_SSE2 #include #endif @@ -44,25 +42,26 @@ uint64_t fast_read_u64(const char* chars) return val; } +// https://quick-bench.com/q/fk6Y07KDGu8XZ9iUtQD8QJTc3Hg fastfloat_really_inline uint64_t fast_read_u64(const char16_t* chars) { #if FASTFLOAT_SSE2 - const unsigned char* const p = reinterpret_cast(chars); - +FASTFLOAT_SIMD_DISABLE_WARNINGS static const char16_t masks[] = {0xff, 0xff, 0xff, 0xff}; const __m128i m_masks = _mm_loadu_si128(reinterpret_cast(masks)); - // mask hi bytes + + // mask hi bytes and pack + const char* const p = reinterpret_cast(chars); __m128i i1 = _mm_and_si128(_mm_loadu_si64(p), m_masks); __m128i i2 = _mm_and_si128(_mm_loadu_si64(p + 8), m_masks); - - // pack into chars __m128i packed = _mm_packus_epi16(i1, i2); // extract uint64_t val; _mm_storeu_si64(&val, _mm_shuffle_epi32(packed, 0x8)); return val; +FASTFLOAT_SIMD_RESTORE_WARNINGS #else alignas(8) unsigned char bytes[8]; for (int i = 0; i < 8; ++i) @@ -143,7 +142,7 @@ bool is_made_of_eight_digits_fast(const CharT *chars) noexcept { typedef span byte_span; -template +template struct parsed_number_string { int64_t exponent{0}; uint64_t mantissa{0}; @@ -161,10 +160,9 @@ struct parsed_number_string { // parse an ASCII string. template fastfloat_really_inline FASTFLOAT_CONSTEXPR20 -parsed_number_string parse_number_string(const CharT *p, const CharT *pend, parse_options options) noexcept { +parsed_number_string parse_number_string(const CharT *p, const CharT *pend, parse_options options, const bool parse_ints = false) noexcept { const chars_format fmt = options.format; const parse_rules rules = options.rules; - const bool parse_ints = options.parse_ints; const CharT decimal_point = static_cast(options.decimal_point); parsed_number_string answer; @@ -279,9 +277,9 @@ parsed_number_string parse_number_string(const CharT *p, const CharT *pen start++; } constexpr uint64_t minimal_twenty_digit_integer{10000000000000000000ULL}; - // maya: A 64-bit number may have up to 20 digits, not 19! - // If we're parsing ints, preserve accuracy up to 20 digits instead - // of converting them to the closest floating point value. + // maya: A 64-bit number may have up to 20 digits! + // If we're parsing ints, preserve accuracy up to 20 digits + // instead of rounding them to a floating point value. answer.too_many_digits = rules == parse_rules::json_rules && parse_ints && answer.is_64bit_int ? (digit_count > 20 || i < minimal_twenty_digit_integer) : digit_count > 19; diff --git a/include/fast_float/fast_float.h b/include/fast_float/fast_float.h index d4648e6..91870a7 100644 --- a/include/fast_float/fast_float.h +++ b/include/fast_float/fast_float.h @@ -27,16 +27,13 @@ struct from_chars_result { struct parse_options { constexpr explicit parse_options( chars_format fmt = chars_format::general, - parse_rules rules = parse_rules::std_rules, - bool parse_ints = false, char dot = '.') - : format(fmt), rules(rules), parse_ints(parse_ints), decimal_point(dot) {} + parse_rules rules = parse_rules::std_rules, char dot = '.') + : format(fmt), rules(rules), decimal_point(dot) {} /** Which number formats are accepted */ chars_format format; /** Which parsing rules to use */ parse_rules rules; - /* Whether to parse integers too, only applicable with json_rules */ - bool parse_ints; /** The character used as decimal point */ char decimal_point; }; diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index eaa6e73..7ca3284 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -78,6 +78,24 @@ #endif #endif + +#if defined(__GNUC__) +#define FASTFLOAT_SIMD_DISABLE_WARNINGS \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wcast-align=strict\"") +#else +#define FASTFLOAT_SIMD_DISABLE_WARNINGS +#endif + +#if defined(__GNUC__) +#define FASTFLOAT_SIMD_RESTORE_WARNINGS \ + _Pragma("GCC diagnostic pop") +#else +#define FASTFLOAT_SIMD_RESTORE_WARNINGS +#endif + + + #ifdef FASTFLOAT_VISUAL_STUDIO #define fastfloat_really_inline __forceinline #else