34 Commits
Author SHA1 Message Date
Nigel Tao 32a23a9bb5 base: backport parse_number_{u64,f64} fixes
This backports commits 9d41525a2f and
c99f5af9fe from the main branch (working
on an unstable v0.4) to the v0.3 branch.
2026-10-20 14:17:58 +11:00
Nigel Tao 00d5e35865 floatconv: optimize parse_number_f64 fallback
The time taken running script/manual-test-parse-number-f64.cc on the
parse-number-fxx-test-data suite falls from 3.565s to 2.491s (a 1.43x
ratio; the inverse is 0.70 = 100% - 30%).

Fixes #113
2023-04-08 14:56:32 +10:00
Nigel Tao 4d4c3c4c3c floatconv: tweak Simple Decimal Conversion
This tweaks the code and comments added in commit 36d7748e "Merge pull
request #90 from sarastro-nl/improvement/optimize-SDC" and commit
d46220ca "optimize SDC". Both of those two commit messages are short but
see the discussion re algorithmic changes on PR 87 (yes, 87, not 90):
https://github.com/google/wuffs/pull/87

Also run clang-format.

Also update doc/changelog.md

Compared to before commit d46220ca "optimize SDC", when running
script/manual-test-parse-number-f64.cc and disabling both the
etc__parse_number_f64_eisel_lemire function and the "If both man and
(10 ** exp10) are exactly representable by a double" fast path, the
tests still pass but the number of etc__high_prec_dec__small_lshift and
etc__high_prec_dec__small_rshift calls drop:

Function    Before      After       Ratio
lshift      31174584    25762258    82.64% = 100% - 17.36%
rshift      21592604    20982502    97.17% = 100% -  2.83%

The time taken drops from 15.984s to 13.710s (85.77% = 100% - 14.23%).

To repeat, these are the improvements after disabling the Eisel-Lemire
and other fast paths. Simple Decimal Conversion is the rarely invoked
fallback parse_number_f64 algorithm. The practical improvement (with
Eisel-Lemire etc enabled) is smaller.
2023-02-04 14:48:25 +11:00
sarastro-nl d46220ca00 optimize SDC 2022-11-21 22:10:19 +01:00
Nigel Tao f148f5c5b3 Make "// - etc" bullet point comments consistent 2021-11-05 16:50:38 +11:00
Nigel Tao 1d19157668 Remove After editing... run "go generate" lines 2021-08-22 12:57:39 +10:00
Nigel Tao a1c22caa15 Rename load and store to peek and poke 2021-01-17 22:44:39 +11:00
Nigel Tao ce685a647d Fix hpd__small_rshift clobbering the negative bit
Also link to the Simple Decimal Conversion blog post.
2020-11-03 15:24:02 +11:00
Nigel Tao 1d8d18f400 Add link to Eisel-Lemire blog post 2020-10-07 22:13:51 +11:00
Nigel Tao ba3818cb6b Add more parse_number_f64 test cases 2020-09-28 12:51:45 +10:00
Nigel Tao 4f1d24c070 Add names to "typedef struct { ... } foo" types 2020-09-23 22:02:53 +10:00
Nigel Tao afe7f27ab7 Trim Eisel-Lemire powers-of-10 tables
This tracks the upstream github.com/lemire/fast_double_parser

On a mid-range x86_64 laptop, processing the 181 MiB citylots.json file
from github.com/zemirco/sf-city-lots-json:

$ g++ -O3 script/process-json-numbers.c
$ time ./a.out -parse-number-f64 < citylots.json
Before/After:
real    0m1.035s
real    0m1.003s

Binary size, before:
29544 gen/lib/c/clang-9-dynamic/wuffs-base-floatconv.lo
29648 gen/lib/c/clang-9-static/wuffs-base-floatconv.o
31192 gen/lib/c/gcc-dynamic/wuffs-base-floatconv.lo
31160 gen/lib/c/gcc-static/wuffs-base-floatconv.o

After:
27160 gen/lib/c/clang-9-dynamic/wuffs-base-floatconv.lo
27264 gen/lib/c/clang-9-static/wuffs-base-floatconv.o
28760 gen/lib/c/gcc-dynamic/wuffs-base-floatconv.lo
28760 gen/lib/c/gcc-static/wuffs-base-floatconv.o
2020-09-23 16:18:27 +10:00
Nigel Tao b6d855210c Use a formula to calculate Eisel-Lemire power-of-2
On a mid-range x86_64 laptop, processing the 181 MiB citylots.json file
from github.com/zemirco/sf-city-lots-json:

$ g++ -O3 script/process-json-numbers.c
$ time ./a.out -parse-number-f64 < citylots.json
Before/After:
real    0m0.992s
real    0m1.035s
2020-09-23 15:23:12 +10:00
Nigel Tao 0987296352 Fix parse_number_f64_eisel_lemire comment typos 2020-09-15 22:25:33 +10:00
Nigel Tao f2be4dd7cf Trim private_implementation__powers_of_10 array
Binary size, before:
30344 gen/lib/c/clang-9-dynamic/wuffs-base-floatconv.lo
30488 gen/lib/c/clang-9-static/wuffs-base-floatconv.o
31992 gen/lib/c/gcc-dynamic/wuffs-base-floatconv.lo
31992 gen/lib/c/gcc-static/wuffs-base-floatconv.o

After:
29512 gen/lib/c/clang-9-dynamic/wuffs-base-floatconv.lo
29656 gen/lib/c/clang-9-static/wuffs-base-floatconv.o
31160 gen/lib/c/gcc-dynamic/wuffs-base-floatconv.lo
31160 gen/lib/c/gcc-static/wuffs-base-floatconv.o
2020-09-15 22:14:30 +10:00
Nigel Tao 8b45db0120 Narrow parse_number_f64_eisel_lemire's exp10 arg
On a mid-range x86_64 laptop, processing the 181 MiB citylots.json file
from github.com/zemirco/sf-city-lots-json:

$ g++ -O3 script/process-json-numbers.c
$ time ./a.out -parse-number-f64 < citylots.json
Before/After:
real    0m0.995s
real    0m0.968s
2020-09-15 21:58:57 +10:00
Nigel Tao 339119a5c1 Simplify parse_number_f64's use of __uint128_t 2020-09-14 12:43:29 +10:00
Nigel Tao 9f22b5ebf7 Fix wuffs_base__parse_number_f64 fast path comment 2020-09-11 09:10:08 +10:00
Nigel Tao 57d47c633c Fix etc__high_prec_dec__to_f64 shift amount
Shifting 0.299 left by 2 doesn't put us in [½ .. 1].
2020-09-08 16:43:31 +10:00
Nigel Tao a4f2bbb249 Update cgen/base run "go generate" comment 2020-07-28 14:15:24 +10:00
Nigel Tao c4fa8e27c0 Rename the "Eisel" algorithm to "Eisel-Lemire" 2020-07-18 17:35:13 +10:00
Nigel Tao 56d9096f81 Fix -Werror=conversion in from_f64_to_u{16,32} 2020-07-12 21:11:49 +10:00
Nigel Tao a3931d5215 Rename IEEE 754 from_f64_to_u{16,32} functions 2020-07-12 21:06:44 +10:00
Nigel Tao 7bf7cf28b9 Add IEEE 754 from_f64_to_u{16,32} functions 2020-07-12 17:01:14 +10:00
Nigel Tao 4d449dc663 Rename ieee_754_bit_representation functions 2020-07-12 11:00:47 +10:00
Nigel Tao c5c9885db4 Add PARSE_NUMBER_XXX__ALLOW_UNDERSCORES 2020-07-11 13:10:14 +10:00
Nigel Tao e82bc8ec7b Add PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_Z... 2020-07-11 12:57:25 +10:00
Nigel Tao 4d61a056e0 Add PARSE_NUMBER_FXX__REJECT_INF_AND_NAN 2020-07-11 12:34:40 +10:00
Nigel Tao e0c5de9d8d Add PARSE_NUMBER_FXX__DECIMAL_SEPARATOR_IS_A_COMMA 2020-07-11 12:14:39 +10:00
Nigel Tao e722bb095c Fix #ifdef guarding the use of __uint128_t 2020-07-10 20:33:09 +10:00
Nigel Tao bff01d7ea8 Add comment linking to previous commit's numbers 2020-07-10 12:15:09 +10:00
Nigel Tao 18449ad75d Optimize 128-bit muls in parse_number_f64_eisel
Processing citylots.json from github.com/zemirco/sf-city-lots-json
$ cc -O3 script/process-json-numbers.c
$ time ./a.out --parse-number-f64 < citylots.json

gcc   9.3 Before/After
real    0m0.638s
real    0m0.609s

clang 9.0 Before/After
real    0m0.692s
real    0m0.685s

x86_64 Broadwell desktop CPU.
2020-07-10 12:11:26 +10:00
Nigel Tao 74d4af66e4 Refactor 128-bit muls in parse_number_f64_eisel 2020-07-10 11:27:17 +10:00
Nigel Tao ca55cdbef0 Rename {f64,i64}conv to {float,int}conv 2020-07-09 21:15:36 +10:00