FASTFLOAT_ASSUME and Clang related crutches cleanup.

This commit is contained in:
HedgehogInTheCPP 2026-08-22 22:14:00 +03:00
parent bc1316970c
commit 207069edcd
4 changed files with 51 additions and 24 deletions

View File

@ -618,11 +618,20 @@ struct bigint : pow5_tables<> {
exp -= small_step; exp -= small_step;
} }
if (exp != 0) { if (exp != 0) {
// Work around clang bug https://godbolt.org/z/zedh7rrhc FASTFLOAT_TRY(small_mul(
// This is similar to https://github.com/llvm/llvm-project/issues/47746, vec,
// except the workaround described there don't work here limb(
FASTFLOAT_TRY(small_mul(vec, limb((static_cast<void>(small_power_of_5[0]), #if defined(__clang__)
small_power_of_5[exp])))); // Work around clang bug https://godbolt.org/z/zedh7rrhc
// This is similar to
// https://github.com/llvm/llvm-project/issues/47746, except
// the workaround described there don't work here
(static_cast<void>(small_power_of_5[0]), small_power_of_5[exp])
#else
small_power_of_5[exp]
#endif
)));
} }
return true; return true;

View File

@ -54,7 +54,7 @@
#define FASTFLOAT_INLINE_VARIABLE static constexpr #define FASTFLOAT_INLINE_VARIABLE static constexpr
#endif #endif
// Before C++17, constexpr variables may need an out-of-class definition. // Before C++17 constexpr variables may need an out-of-class definition.
#if __cplusplus >= 201703L || (defined(_MSC_VER) && _MSVC_LANG >= 201703L) #if __cplusplus >= 201703L || (defined(_MSC_VER) && _MSVC_LANG >= 201703L)
#define FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE 0 #define FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE 0
#else #else
@ -98,13 +98,15 @@
#define FASTFLOAT_HAS_BUILTIN(x) false #define FASTFLOAT_HAS_BUILTIN(x) false
#endif #endif
#if defined(FASTFLOAT_ASSUME) // #if defined(FASTFLOAT_ASSUME)
// user provided solution // user provided solution
#elif defined(__cpp_attrubute_assume) // #elif defined(__cpp_attrubute_assume)
// For support attribute [[assume]] is declared in P1774 // For support attribute [[assume]] is declared in P1774
#define FASTFLOAT_ASSUME(expr) [[assume(expr)]] #define FASTFLOAT_ASSUME(expr) \
#else assert(expr); \
#define FASTFLOAT_ASSUME(expr) [[assume(expr)]]
#endif // #else
// #define FASTFLOAT_ASSUME(expr)
// #endif
#endif // FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H #endif // FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H

View File

@ -944,8 +944,12 @@ constexpr uint16_t
template <> template <>
inline constexpr std::float16_t inline constexpr std::float16_t
binary_format<std::float16_t>::exact_power_of_ten(am_pow_t power) { binary_format<std::float16_t>::exact_power_of_ten(am_pow_t power) {
#if defined(__clang__)
// Work around clang bug https://godbolt.org/z/zedh7rrhc // Work around clang bug https://godbolt.org/z/zedh7rrhc
return (void)powers_of_ten[0], powers_of_ten[power]; return (void)max_mantissa[0], max_mantissa[power];
#else
return max_mantissa[power];
#endif
} }
template <> template <>
@ -989,9 +993,12 @@ inline constexpr am_mant_t
binary_format<std::float16_t>::max_mantissa_fast_path(am_pow_t power) { binary_format<std::float16_t>::max_mantissa_fast_path(am_pow_t power) {
// caller is responsible to ensure that // caller is responsible to ensure that
FASTFLOAT_ASSUME(power >= 0 && power <= 4); FASTFLOAT_ASSUME(power >= 0 && power <= 4);
// #if defined(__clang__)
// Work around clang bug https://godbolt.org/z/zedh7rrhc // Work around clang bug https://godbolt.org/z/zedh7rrhc
return (void)max_mantissa[0], max_mantissa[power]; return (void)max_mantissa[0], max_mantissa[power];
#else
return max_mantissa[power];
#endif
} }
template <> template <>
@ -1077,8 +1084,12 @@ constexpr uint16_t
template <> template <>
inline constexpr std::bfloat16_t inline constexpr std::bfloat16_t
binary_format<std::bfloat16_t>::exact_power_of_ten(am_pow_t power) { binary_format<std::bfloat16_t>::exact_power_of_ten(am_pow_t power) {
#if defined(__clang__)
// Work around clang bug https://godbolt.org/z/zedh7rrhc // Work around clang bug https://godbolt.org/z/zedh7rrhc
return (void)powers_of_ten[0], powers_of_ten[power]; return (void)max_mantissa[0], max_mantissa[power];
#else
return max_mantissa[power];
#endif
} }
template <> template <>
@ -1122,9 +1133,12 @@ inline constexpr am_mant_t
binary_format<std::bfloat16_t>::max_mantissa_fast_path(am_pow_t power) { binary_format<std::bfloat16_t>::max_mantissa_fast_path(am_pow_t power) {
// caller is responsible to ensure that // caller is responsible to ensure that
FASTFLOAT_ASSUME(power >= 0 && power <= 3); FASTFLOAT_ASSUME(power >= 0 && power <= 3);
// #if defined(__clang__)
// Work around clang bug https://godbolt.org/z/zedh7rrhc // Work around clang bug https://godbolt.org/z/zedh7rrhc
return (void)max_mantissa[0], max_mantissa[power]; return (void)max_mantissa[0], max_mantissa[power];
#else
return max_mantissa[power];
#endif
} }
template <> template <>
@ -1186,7 +1200,7 @@ template <>
inline constexpr am_mant_t inline constexpr am_mant_t
binary_format<double>::max_mantissa_fast_path(am_pow_t power) { binary_format<double>::max_mantissa_fast_path(am_pow_t power) {
// caller is responsible to ensure that // caller is responsible to ensure that
// FASTFLOAT_ASSUME(power >= 0 && power <= 22); FASTFLOAT_ASSUME(power >= 0 && power <= 22);
#if defined(__clang__) #if defined(__clang__)
// Work around clang bug https://godbolt.org/z/zedh7rrhc // Work around clang bug https://godbolt.org/z/zedh7rrhc
return (void)max_mantissa[0], max_mantissa[power]; return (void)max_mantissa[0], max_mantissa[power];
@ -1199,7 +1213,7 @@ template <>
inline constexpr am_mant_t inline constexpr am_mant_t
binary_format<float>::max_mantissa_fast_path(am_pow_t power) { binary_format<float>::max_mantissa_fast_path(am_pow_t power) {
// caller is responsible to ensure that // caller is responsible to ensure that
// FASTFLOAT_ASSUME(power >= 0 && power <= 10); FASTFLOAT_ASSUME(power >= 0 && power <= 10);
#if defined(__clang__) #if defined(__clang__)
// Work around clang bug https://godbolt.org/z/zedh7rrhc // Work around clang bug https://godbolt.org/z/zedh7rrhc
return (void)max_mantissa[0], max_mantissa[power]; return (void)max_mantissa[0], max_mantissa[power];
@ -1212,7 +1226,7 @@ template <>
inline constexpr double inline constexpr double
binary_format<double>::exact_power_of_ten(am_pow_t power) { binary_format<double>::exact_power_of_ten(am_pow_t power) {
// caller is responsible to ensure that // caller is responsible to ensure that
// FASTFLOAT_ASSUME(power >= 0 && power <= 22); FASTFLOAT_ASSUME(power >= 0 && power <= 22);
#if defined(__clang__) #if defined(__clang__)
// Work around clang bug https://godbolt.org/z/zedh7rrhc // Work around clang bug https://godbolt.org/z/zedh7rrhc
return (void)powers_of_ten[0], powers_of_ten[power]; return (void)powers_of_ten[0], powers_of_ten[power];
@ -1225,7 +1239,7 @@ template <>
inline constexpr float inline constexpr float
binary_format<float>::exact_power_of_ten(am_pow_t power) { binary_format<float>::exact_power_of_ten(am_pow_t power) {
// caller is responsible to ensure that // caller is responsible to ensure that
// FASTFLOAT_ASSUME(power >= 0 && power <= 10); FASTFLOAT_ASSUME(power >= 0 && power <= 10);
#if defined(__clang__) #if defined(__clang__)
// Work around clang bug https://godbolt.org/z/zedh7rrhc // Work around clang bug https://godbolt.org/z/zedh7rrhc
return (void)powers_of_ten[0], powers_of_ten[power]; return (void)powers_of_ten[0], powers_of_ten[power];

View File

@ -218,9 +218,11 @@ clinger_fast_path_impl(am_mant_t const mantissa, am_pow_t const exponent,
// We could check it first (before the previous branch), but // We could check it first (before the previous branch), but
// there might be performance advantages at having the check // there might be performance advantages at having the check
// be last. // be last.
if (!is_constant_evaluated()
#ifndef FASTFLOAT_ONLY_ROUNDS_TO_NEAREST_SUPPORTED #ifndef FASTFLOAT_ONLY_ROUNDS_TO_NEAREST_SUPPORTED
if (detail::rounds_to_nearest()) { && detail::rounds_to_nearest()
#endif #endif
) {
// We have that fegetround() == FE_TONEAREST. // We have that fegetround() == FE_TONEAREST.
// Next is Clinger's fast path. // Next is Clinger's fast path.
if (mantissa <= binary_format<T>::max_mantissa_fast_path()) { if (mantissa <= binary_format<T>::max_mantissa_fast_path()) {
@ -263,8 +265,8 @@ clinger_fast_path_impl(am_mant_t const mantissa, am_pow_t const exponent,
} }
#endif #endif
return true; return true;
}
#endif #endif
}
} }
} }
return false; return false;