Added FASTFLOAT_ASSUME for support attribute [[assume]] is declared in P1774

This commit is contained in:
IRainman 2025-03-09 03:41:27 +03:00
parent f496321570
commit c2daa8a614
4 changed files with 14 additions and 5 deletions

View File

@ -291,7 +291,7 @@ parse_number_string(UC const *p, UC const *pend,
parsed_number_string_t<UC> answer; parsed_number_string_t<UC> answer;
answer.valid = false; answer.valid = false;
answer.too_many_digits = false; answer.too_many_digits = false;
[[assume(p < pend)]]; // assume p < pend, so dereference without checks; FASTFLOAT_ASSUME(p < pend); // assume p < pend, so dereference without checks;
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
answer.negative = (*p == UC('-')); answer.negative = (*p == UC('-'));
// C++17 20.19.3.(7.1) explicitly forbids '+' sign here // C++17 20.19.3.(7.1) explicitly forbids '+' sign here

View File

@ -46,4 +46,13 @@
#define FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE 1 #define FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE 1
#endif #endif
// For support attribute [[assume]] is declared in P1774
#if defined(__clang__)
#define FASTFLOAT_ASSUME(expr) __builtin_assume(expr)
#elif defined(__GNUC__) && !defined(__ICC)
#define ASSUME(expr) __attribute__((expr)))
#elif defined(_MSC_VER) || defined(__ICC)
#define FASTFLOAT_ASSUME(expr) __assume(expr)
#endif
#endif // FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H #endif // FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H

View File

@ -342,7 +342,7 @@ leading_zeroes_generic(uint64_t input_num, int last_bit = 0) {
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 int fastfloat_really_inline FASTFLOAT_CONSTEXPR20 int
leading_zeroes(uint64_t input_num) noexcept { leading_zeroes(uint64_t input_num) noexcept {
assert(input_num > 0); assert(input_num > 0);
[[assume(input_num > 0)]]; FASTFLOAT_ASSUME(input_num > 0);
if (cpp20_and_in_constexpr()) { if (cpp20_and_in_constexpr()) {
return leading_zeroes_generic(input_num); return leading_zeroes_generic(input_num);
} }

View File

@ -27,7 +27,7 @@ from_chars_result_t<UC>
from_chars_result_t<UC> answer{}; from_chars_result_t<UC> answer{};
answer.ptr = first; answer.ptr = first;
answer.ec = std::errc(); // be optimistic answer.ec = std::errc(); // be optimistic
[[assume(first < last)]]; // so dereference without checks FASTFLOAT_ASSUME(first < last); // so dereference without checks
bool const minusSign = (*first == UC('-')); bool const minusSign = (*first == UC('-'));
// C++17 20.19.3.(7.1) explicitly forbids '+' sign here // C++17 20.19.3.(7.1) explicitly forbids '+' sign here
@ -321,7 +321,7 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value,
} }
#else #else
// We are in parser code with external loop that checks bounds. // We are in parser code with external loop that checks bounds.
[[assume((first < last))]]; FASTFLOAT_ASSUME(first < last);
#endif #endif
parsed_number_string_t<UC> const pns = parsed_number_string_t<UC> const pns =
parse_number_string<UC>(first, last, options); parse_number_string<UC>(first, last, options);
@ -374,7 +374,7 @@ from_chars_int_advanced(UC const *first, UC const *last, T &value,
} }
#else #else
// We are in parser code with external loop that checks bounds. // We are in parser code with external loop that checks bounds.
[[assume((first < last))]]; FASTFLOAT_ASSUME(first < last);
#endif #endif
if ( if (
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN