Skip to content

Commit 207069e

Browse files
committed
FASTFLOAT_ASSUME and Clang related crutches cleanup.
1 parent bc13169 commit 207069e

4 files changed

Lines changed: 51 additions & 24 deletions

File tree

include/fast_float/bigint.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -618,11 +618,20 @@ struct bigint : pow5_tables<> {
618618
exp -= small_step;
619619
}
620620
if (exp != 0) {
621-
// Work around clang bug https://godbolt.org/z/zedh7rrhc
622-
// This is similar to https://github.com/llvm/llvm-project/issues/47746,
623-
// except the workaround described there don't work here
624-
FASTFLOAT_TRY(small_mul(vec, limb((static_cast<void>(small_power_of_5[0]),
625-
small_power_of_5[exp]))));
621+
FASTFLOAT_TRY(small_mul(
622+
vec,
623+
limb(
624+
#if defined(__clang__)
625+
// Work around clang bug https://godbolt.org/z/zedh7rrhc
626+
// This is similar to
627+
// https://github.com/llvm/llvm-project/issues/47746, except
628+
// the workaround described there don't work here
629+
(static_cast<void>(small_power_of_5[0]), small_power_of_5[exp])
630+
#else
631+
small_power_of_5[exp]
632+
#endif
633+
634+
)));
626635
}
627636

628637
return true;

include/fast_float/constexpr_feature_detect.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
#define FASTFLOAT_INLINE_VARIABLE static constexpr
5555
#endif
5656

57-
// Before C++17, constexpr variables may need an out-of-class definition.
57+
// Before C++17 constexpr variables may need an out-of-class definition.
5858
#if __cplusplus >= 201703L || (defined(_MSC_VER) && _MSVC_LANG >= 201703L)
5959
#define FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE 0
6060
#else
@@ -98,13 +98,15 @@
9898
#define FASTFLOAT_HAS_BUILTIN(x) false
9999
#endif
100100

101-
#if defined(FASTFLOAT_ASSUME)
102-
// user provided solution
103-
#elif defined(__cpp_attrubute_assume)
104-
// For support attribute [[assume]] is declared in P1774
105-
#define FASTFLOAT_ASSUME(expr) [[assume(expr)]]
106-
#else
107-
#define FASTFLOAT_ASSUME(expr)
108-
#endif
101+
// #if defined(FASTFLOAT_ASSUME)
102+
// user provided solution
103+
// #elif defined(__cpp_attrubute_assume)
104+
// For support attribute [[assume]] is declared in P1774
105+
#define FASTFLOAT_ASSUME(expr) \
106+
assert(expr); \
107+
[[assume(expr)]]
108+
// #else
109+
// #define FASTFLOAT_ASSUME(expr)
110+
// #endif
109111

110112
#endif // FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H

include/fast_float/float_common.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -944,8 +944,12 @@ constexpr uint16_t
944944
template <>
945945
inline constexpr std::float16_t
946946
binary_format<std::float16_t>::exact_power_of_ten(am_pow_t power) {
947+
#if defined(__clang__)
947948
// Work around clang bug https://godbolt.org/z/zedh7rrhc
948-
return (void)powers_of_ten[0], powers_of_ten[power];
949+
return (void)max_mantissa[0], max_mantissa[power];
950+
#else
951+
return max_mantissa[power];
952+
#endif
949953
}
950954

951955
template <>
@@ -989,9 +993,12 @@ inline constexpr am_mant_t
989993
binary_format<std::float16_t>::max_mantissa_fast_path(am_pow_t power) {
990994
// caller is responsible to ensure that
991995
FASTFLOAT_ASSUME(power >= 0 && power <= 4);
992-
//
996+
#if defined(__clang__)
993997
// Work around clang bug https://godbolt.org/z/zedh7rrhc
994998
return (void)max_mantissa[0], max_mantissa[power];
999+
#else
1000+
return max_mantissa[power];
1001+
#endif
9951002
}
9961003

9971004
template <>
@@ -1077,8 +1084,12 @@ constexpr uint16_t
10771084
template <>
10781085
inline constexpr std::bfloat16_t
10791086
binary_format<std::bfloat16_t>::exact_power_of_ten(am_pow_t power) {
1087+
#if defined(__clang__)
10801088
// Work around clang bug https://godbolt.org/z/zedh7rrhc
1081-
return (void)powers_of_ten[0], powers_of_ten[power];
1089+
return (void)max_mantissa[0], max_mantissa[power];
1090+
#else
1091+
return max_mantissa[power];
1092+
#endif
10821093
}
10831094

10841095
template <>
@@ -1122,9 +1133,12 @@ inline constexpr am_mant_t
11221133
binary_format<std::bfloat16_t>::max_mantissa_fast_path(am_pow_t power) {
11231134
// caller is responsible to ensure that
11241135
FASTFLOAT_ASSUME(power >= 0 && power <= 3);
1125-
//
1136+
#if defined(__clang__)
11261137
// Work around clang bug https://godbolt.org/z/zedh7rrhc
11271138
return (void)max_mantissa[0], max_mantissa[power];
1139+
#else
1140+
return max_mantissa[power];
1141+
#endif
11281142
}
11291143

11301144
template <>
@@ -1186,7 +1200,7 @@ template <>
11861200
inline constexpr am_mant_t
11871201
binary_format<double>::max_mantissa_fast_path(am_pow_t power) {
11881202
// caller is responsible to ensure that
1189-
// FASTFLOAT_ASSUME(power >= 0 && power <= 22);
1203+
FASTFLOAT_ASSUME(power >= 0 && power <= 22);
11901204
#if defined(__clang__)
11911205
// Work around clang bug https://godbolt.org/z/zedh7rrhc
11921206
return (void)max_mantissa[0], max_mantissa[power];
@@ -1199,7 +1213,7 @@ template <>
11991213
inline constexpr am_mant_t
12001214
binary_format<float>::max_mantissa_fast_path(am_pow_t power) {
12011215
// caller is responsible to ensure that
1202-
// FASTFLOAT_ASSUME(power >= 0 && power <= 10);
1216+
FASTFLOAT_ASSUME(power >= 0 && power <= 10);
12031217
#if defined(__clang__)
12041218
// Work around clang bug https://godbolt.org/z/zedh7rrhc
12051219
return (void)max_mantissa[0], max_mantissa[power];
@@ -1212,7 +1226,7 @@ template <>
12121226
inline constexpr double
12131227
binary_format<double>::exact_power_of_ten(am_pow_t power) {
12141228
// caller is responsible to ensure that
1215-
// FASTFLOAT_ASSUME(power >= 0 && power <= 22);
1229+
FASTFLOAT_ASSUME(power >= 0 && power <= 22);
12161230
#if defined(__clang__)
12171231
// Work around clang bug https://godbolt.org/z/zedh7rrhc
12181232
return (void)powers_of_ten[0], powers_of_ten[power];
@@ -1225,7 +1239,7 @@ template <>
12251239
inline constexpr float
12261240
binary_format<float>::exact_power_of_ten(am_pow_t power) {
12271241
// caller is responsible to ensure that
1228-
// FASTFLOAT_ASSUME(power >= 0 && power <= 10);
1242+
FASTFLOAT_ASSUME(power >= 0 && power <= 10);
12291243
#if defined(__clang__)
12301244
// Work around clang bug https://godbolt.org/z/zedh7rrhc
12311245
return (void)powers_of_ten[0], powers_of_ten[power];

include/fast_float/parse_number.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,11 @@ clinger_fast_path_impl(am_mant_t const mantissa, am_pow_t const exponent,
218218
// We could check it first (before the previous branch), but
219219
// there might be performance advantages at having the check
220220
// be last.
221+
if (!is_constant_evaluated()
221222
#ifndef FASTFLOAT_ONLY_ROUNDS_TO_NEAREST_SUPPORTED
222-
if (detail::rounds_to_nearest()) {
223+
&& detail::rounds_to_nearest()
223224
#endif
225+
) {
224226
// We have that fegetround() == FE_TONEAREST.
225227
// Next is Clinger's fast path.
226228
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,
263265
}
264266
#endif
265267
return true;
266-
}
267268
#endif
269+
}
268270
}
269271
}
270272
return false;

0 commit comments

Comments
 (0)