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

@ -34,7 +34,7 @@ Value findmax_fastfloat(std::vector<std::basic_string<CharT>> &s,
#ifdef USING_COUNTERS #ifdef USING_COUNTERS
std::vector<event_count> &aggregate std::vector<event_count> &aggregate
#else #else
std::chrono::nanoseconds& time std::chrono::nanoseconds &time
#endif #endif
) { ) {
Value answer = 0; Value answer = 0;
@ -55,7 +55,7 @@ Value findmax_fastfloat(std::vector<std::basic_string<CharT>> &s,
t2 = std::chrono::high_resolution_clock::now(); t2 = std::chrono::high_resolution_clock::now();
time += t2 - t1; time += t2 - t1;
#endif #endif
if (ec != std::errc{}) { if (ec != std::errc{}) {
throw std::runtime_error("bug in findmax_fastfloat"); throw std::runtime_error("bug in findmax_fastfloat");
} }
@ -71,7 +71,7 @@ time_it_ns(std::vector<std::basic_string<CharT>> &lines, T const &function,
size_t repeat) { size_t repeat) {
std::vector<event_count> aggregate; std::vector<event_count> aggregate;
bool printed_bug = false; bool printed_bug = false;
for (size_t i = 0; i < repeat; i++) { for (size_t i = 0; i < repeat; i++) {
double ts = function(lines, aggregate); double ts = function(lines, aggregate);
if (ts == 0 && !printed_bug) { if (ts == 0 && !printed_bug) {
printf("bug\n"); printf("bug\n");
@ -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,8 +207,9 @@ 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(
time_it_ns(lines16, findmax_fastfloat<char16_t, double>, repeat)); volume, lines.size(), "fastfloat (64)",
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 -
@ -261,7 +257,7 @@ void fileload(std::string filename) {
continue; continue;
} }
} }
// in the real parser this part of code should return end token // in the real parser this part of code should return end token
#else #else
volume += lines.emplace_back(line).size(); volume += lines.emplace_back(line).size();
#endif #endif

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,12 +999,11 @@ 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
adjusted_mantissa const &am, T &value) noexcept { adjusted_mantissa const &am, T &value) noexcept {
using equiv_uint = equiv_uint_t<T>; using equiv_uint = equiv_uint_t<T>;
equiv_uint word = equiv_uint(am.mantissa); equiv_uint word = equiv_uint(am.mantissa);
word = equiv_uint(word | equiv_uint(am.power2) word = equiv_uint(word | equiv_uint(am.power2)