mirror of
https://github.com/fastfloat/fast_float.git
synced 2026-11-09 14:49:59 +08:00
FASTFLOAT_ASSUME and Clang related crutches cleanup.
This commit is contained in:
parent
bc1316970c
commit
207069edcd
@ -618,11 +618,20 @@ struct bigint : pow5_tables<> {
|
||||
exp -= small_step;
|
||||
}
|
||||
if (exp != 0) {
|
||||
// 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
|
||||
FASTFLOAT_TRY(small_mul(vec, limb((static_cast<void>(small_power_of_5[0]),
|
||||
small_power_of_5[exp]))));
|
||||
FASTFLOAT_TRY(small_mul(
|
||||
vec,
|
||||
limb(
|
||||
#if defined(__clang__)
|
||||
// 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;
|
||||
|
||||
@ -54,7 +54,7 @@
|
||||
#define FASTFLOAT_INLINE_VARIABLE static constexpr
|
||||
#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)
|
||||
#define FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE 0
|
||||
#else
|
||||
@ -98,13 +98,15 @@
|
||||
#define FASTFLOAT_HAS_BUILTIN(x) false
|
||||
#endif
|
||||
|
||||
#if defined(FASTFLOAT_ASSUME)
|
||||
// user provided solution
|
||||
#elif defined(__cpp_attrubute_assume)
|
||||
// For support attribute [[assume]] is declared in P1774
|
||||
#define FASTFLOAT_ASSUME(expr) [[assume(expr)]]
|
||||
#else
|
||||
#define FASTFLOAT_ASSUME(expr)
|
||||
#endif
|
||||
// #if defined(FASTFLOAT_ASSUME)
|
||||
// user provided solution
|
||||
// #elif defined(__cpp_attrubute_assume)
|
||||
// For support attribute [[assume]] is declared in P1774
|
||||
#define FASTFLOAT_ASSUME(expr) \
|
||||
assert(expr); \
|
||||
[[assume(expr)]]
|
||||
// #else
|
||||
// #define FASTFLOAT_ASSUME(expr)
|
||||
// #endif
|
||||
|
||||
#endif // FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H
|
||||
|
||||
@ -944,8 +944,12 @@ constexpr uint16_t
|
||||
template <>
|
||||
inline constexpr std::float16_t
|
||||
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
|
||||
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 <>
|
||||
@ -989,9 +993,12 @@ inline constexpr am_mant_t
|
||||
binary_format<std::float16_t>::max_mantissa_fast_path(am_pow_t power) {
|
||||
// caller is responsible to ensure that
|
||||
FASTFLOAT_ASSUME(power >= 0 && power <= 4);
|
||||
//
|
||||
#if defined(__clang__)
|
||||
// Work around clang bug https://godbolt.org/z/zedh7rrhc
|
||||
return (void)max_mantissa[0], max_mantissa[power];
|
||||
#else
|
||||
return max_mantissa[power];
|
||||
#endif
|
||||
}
|
||||
|
||||
template <>
|
||||
@ -1077,8 +1084,12 @@ constexpr uint16_t
|
||||
template <>
|
||||
inline constexpr std::bfloat16_t
|
||||
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
|
||||
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 <>
|
||||
@ -1122,9 +1133,12 @@ inline constexpr am_mant_t
|
||||
binary_format<std::bfloat16_t>::max_mantissa_fast_path(am_pow_t power) {
|
||||
// caller is responsible to ensure that
|
||||
FASTFLOAT_ASSUME(power >= 0 && power <= 3);
|
||||
//
|
||||
#if defined(__clang__)
|
||||
// Work around clang bug https://godbolt.org/z/zedh7rrhc
|
||||
return (void)max_mantissa[0], max_mantissa[power];
|
||||
#else
|
||||
return max_mantissa[power];
|
||||
#endif
|
||||
}
|
||||
|
||||
template <>
|
||||
@ -1186,7 +1200,7 @@ template <>
|
||||
inline constexpr am_mant_t
|
||||
binary_format<double>::max_mantissa_fast_path(am_pow_t power) {
|
||||
// caller is responsible to ensure that
|
||||
// FASTFLOAT_ASSUME(power >= 0 && power <= 22);
|
||||
FASTFLOAT_ASSUME(power >= 0 && power <= 22);
|
||||
#if defined(__clang__)
|
||||
// Work around clang bug https://godbolt.org/z/zedh7rrhc
|
||||
return (void)max_mantissa[0], max_mantissa[power];
|
||||
@ -1199,7 +1213,7 @@ template <>
|
||||
inline constexpr am_mant_t
|
||||
binary_format<float>::max_mantissa_fast_path(am_pow_t power) {
|
||||
// caller is responsible to ensure that
|
||||
// FASTFLOAT_ASSUME(power >= 0 && power <= 10);
|
||||
FASTFLOAT_ASSUME(power >= 0 && power <= 10);
|
||||
#if defined(__clang__)
|
||||
// Work around clang bug https://godbolt.org/z/zedh7rrhc
|
||||
return (void)max_mantissa[0], max_mantissa[power];
|
||||
@ -1212,7 +1226,7 @@ template <>
|
||||
inline constexpr double
|
||||
binary_format<double>::exact_power_of_ten(am_pow_t power) {
|
||||
// caller is responsible to ensure that
|
||||
// FASTFLOAT_ASSUME(power >= 0 && power <= 22);
|
||||
FASTFLOAT_ASSUME(power >= 0 && power <= 22);
|
||||
#if defined(__clang__)
|
||||
// Work around clang bug https://godbolt.org/z/zedh7rrhc
|
||||
return (void)powers_of_ten[0], powers_of_ten[power];
|
||||
@ -1225,7 +1239,7 @@ template <>
|
||||
inline constexpr float
|
||||
binary_format<float>::exact_power_of_ten(am_pow_t power) {
|
||||
// caller is responsible to ensure that
|
||||
// FASTFLOAT_ASSUME(power >= 0 && power <= 10);
|
||||
FASTFLOAT_ASSUME(power >= 0 && power <= 10);
|
||||
#if defined(__clang__)
|
||||
// Work around clang bug https://godbolt.org/z/zedh7rrhc
|
||||
return (void)powers_of_ten[0], powers_of_ten[power];
|
||||
|
||||
@ -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
|
||||
// there might be performance advantages at having the check
|
||||
// be last.
|
||||
if (!is_constant_evaluated()
|
||||
#ifndef FASTFLOAT_ONLY_ROUNDS_TO_NEAREST_SUPPORTED
|
||||
if (detail::rounds_to_nearest()) {
|
||||
&& detail::rounds_to_nearest()
|
||||
#endif
|
||||
) {
|
||||
// We have that fegetround() == FE_TONEAREST.
|
||||
// Next is Clinger's 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
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user