This commit is contained in:
IRainman 2025-03-12 20:11:11 +03:00
parent 07ab87ca2b
commit 3dd3712782
3 changed files with 34 additions and 31 deletions

View File

@ -155,7 +155,8 @@ time_it_ns(std::vector<std::basic_string<CharT>> &lines, T const &function,
printf("bug\n"); printf("bug\n");
printed_bug = true; printed_bug = true;
} }
double dif = std::chrono::duration_cast<std::chrono::nanoseconds>(time).count(); double dif =
std::chrono::duration_cast<std::chrono::nanoseconds>(time).count();
average += dif; average += dif;
min_value = min_value < dif ? min_value : dif; min_value = min_value < dif ? min_value : dif;
} }
@ -206,7 +207,8 @@ void process(std::vector<std::string> &lines, size_t volume) {
volume = 2 * volume; volume = 2 * volume;
volumeMB = volume / (1024. * 1024.); volumeMB = volume / (1024. * 1024.);
std::cout << "UTF-16 volume = " << volumeMB << " MB " << std::endl; std::cout << "UTF-16 volume = " << volumeMB << " MB " << std::endl;
pretty_print(volume, lines.size(), "fastfloat (64)", pretty_print(
volume, lines.size(), "fastfloat (64)",
time_it_ns(lines16, findmax_fastfloat<char16_t, double>, repeat)); time_it_ns(lines16, findmax_fastfloat<char16_t, double>, repeat));
pretty_print(volume, lines.size(), "fastfloat (32)", pretty_print(volume, lines.size(), "fastfloat (32)",
time_it_ns(lines16, findmax_fastfloat<char16_t, float>, repeat)); time_it_ns(lines16, findmax_fastfloat<char16_t, float>, repeat));
@ -229,29 +231,23 @@ void fileload(std::string filename) {
#ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN #ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
/* This code is a simple parser emulator */ /* This code is a simple parser emulator */
for (size_t n = 0; n < line.size(); ++n) { for (size_t n = 0; n < line.size(); ++n) {
if ((line[n] >= '0' && line[n] <= '9')) if ((line[n] >= '0' && line[n] <= '9')) {
{
/* in the real parser we don't check anything else /* in the real parser we don't check anything else
and call the from_chars function immediately */ and call the from_chars function immediately */
const auto s = n; const auto s = n;
for (++n; n < line.size() && for (++n; n < line.size() &&
((line[n] >= '0' && line[n] <= '9') || ((line[n] >= '0' && line[n] <= '9') || line[n] == 'e' ||
line[n] == 'e' || line[n] == 'E' || line[n] == 'E' || line[n] == '.' || line[n] == '-' ||
line[n] == '.' || line[n] == '+'
line[n] == '-' || line[n] == '+'
/* last line for exponent sign*/ /* last line for exponent sign*/
); );
++n) ++n) {
{
} }
/*~ in the real parser we don't check anything else /*~ in the real parser we don't check anything else
and call the from_chars function immediately */ and call the from_chars function immediately */
volume += lines.emplace_back(line.substr(s, n)).size(); volume += lines.emplace_back(line.substr(s, n)).size();
} } else {
else
{
/* for the test we simplify skipped all other symbols, /* for the test we simplify skipped all other symbols,
in real application this should be a full parser, in real application this should be a full parser,
that parse also any mathematical operations like + and - that parse also any mathematical operations like + and -

View File

@ -62,7 +62,11 @@
#if defined(__clang__) // needs testing #if defined(__clang__) // needs testing
#define FASTFLOAT_ASSUME(expr) __builtin_assume(expr) #define FASTFLOAT_ASSUME(expr) __builtin_assume(expr)
#elif defined(__GNUC__) && !defined(__ICC) // needs testing #elif defined(__GNUC__) && !defined(__ICC) // needs testing
#define FASTFLOAT_ASSUME(expr) if (expr) {} else { __builtin_unreachable(); } #define FASTFLOAT_ASSUME(expr) \
if (expr) { \
} else { \
__builtin_unreachable(); \
}
#elif defined(__ICC) // needs testing #elif defined(__ICC) // needs testing
#define FASTFLOAT_ASSUME(expr) __assume(expr) #define FASTFLOAT_ASSUME(expr) __assume(expr)
#elif defined(_MSC_VER) #elif defined(_MSC_VER)

View File

@ -67,8 +67,9 @@ template <typename UC> struct from_chars_result_t {
using from_chars_result = from_chars_result_t<char>; using from_chars_result = from_chars_result_t<char>;
template <typename UC> struct parse_options_t { template <typename UC> struct parse_options_t {
FASTFLOAT_CONSTEXPR20 explicit parse_options_t(chars_format fmt = chars_format::general, FASTFLOAT_CONSTEXPR20 explicit parse_options_t(
UC dot = UC('.'), const int b = 10) noexcept chars_format fmt = chars_format::general, UC dot = UC('.'),
const int b = 10) noexcept
: format(fmt), decimal_point(dot), base(static_cast<uint8_t>(b)) {} : format(fmt), decimal_point(dot), base(static_cast<uint8_t>(b)) {}
/** Which number formats are accepted */ /** Which number formats are accepted */
@ -216,7 +217,8 @@ using parse_options = parse_options_t<char>;
namespace fast_float { namespace fast_float {
fastfloat_really_inline FASTFLOAT_CONSTEVAL20 bool cpp20_and_in_constexpr() noexcept { fastfloat_really_inline FASTFLOAT_CONSTEVAL20 bool
cpp20_and_in_constexpr() noexcept {
#if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED #if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED
return std::is_constant_evaluated(); return std::is_constant_evaluated();
#else #else
@ -304,7 +306,8 @@ struct value128 {
uint64_t low; uint64_t low;
uint64_t high; uint64_t high;
constexpr value128(uint64_t _low, uint64_t _high) noexcept : low(_low), high(_high) {} constexpr value128(uint64_t _low, uint64_t _high) noexcept
: low(_low), high(_high) {}
constexpr value128() noexcept : low(0), high(0) {} constexpr value128() noexcept : low(0), high(0) {}
}; };
@ -362,7 +365,8 @@ leading_zeroes(uint64_t input_num) noexcept {
} }
// slow emulation routine for 32-bit // slow emulation routine for 32-bit
fastfloat_really_inline constexpr uint64_t emulu(uint32_t x, uint32_t y) noexcept { fastfloat_really_inline constexpr uint64_t emulu(uint32_t x,
uint32_t y) noexcept {
return x * (uint64_t)y; return x * (uint64_t)y;
} }
@ -995,8 +999,7 @@ binary_format<double>::hidden_bit_mask() {
} }
template <typename T> template <typename T>
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void to_float(
to_float(
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
bool const negative, bool const negative,
#endif #endif