Wuffs the Language has no floating point types, but some reference
implementations (notably the brotli encoder) make decisions with double and
float arithmetic and libm's log2. Porting them with byte-identical output
needs bit-exact floating point results.
This package implements f64 and f32 add, sub, mul, div, fma, comparisons,
min/max, integer conversions and f64<->f32 conversions on bit patterns,
with round-to-nearest-even, subnormals, infinities and NaNs, following the
structure of Berkeley SoftFloat 3. It also ports glibc 2.39's x86-64
__log2_fma log2 implementation (the variant selected on CPUs with FMA and
AVX2), following the shipped machine code's fused operations.
Verification: test/c/std/softfloat.c checks every operation against the C
compiler's native arithmetic on edge cases and random operands. The
script/manual-test-softfloat-*.c programs run 10^8 random operations per
operation group and compare log2_u64 against libm for every integer in
[1, 2^32) plus 10^7 larger values; all with zero mismatches.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011NoosQNe7DKWnqDCBeqw1p
The -O3 codegen is the same (https://godbolt.org/z/5ecWrEq77) but this
avoids compound literals, not part of C++11, and can trigger "compound
literals are a C99-specific feature [-Werror,-Wc99-extensions]".
Fixes#181
Prior to 381e186f "std/vp8: swizzle_ycck once, not once per MB row", we
swizzled one row of macroblocks at a time. After 381e186f, we swizzled
the whole image in one pass, but kept the option of, in the future,
amending the swizzle_ycck implementation to allow ((y_min_incl > 0) and
(ycc_upsampling == FANCY_ETC)) at the same time.
However, 381e186f didn't show a performance loss so large that it seems
worth complicating the swizzle_ycck implementation in that way. So we
just drop, in this commit, the option of that amendment.
This prepares us to change std/vp8's YCC upsampling method from "basic"
to "fancy, like libwebp". Wuffs' current implementation of "fancy"
requires the initial Y coordinate to be zero, as fancy upsampling
special cases the top row of the image and it's simpler if the top row
(row zero) is always presented in the upsampling call.
This is not an optimization or pessimization per se, but for the record,
the performance impact is between negligible and a small improvement.
name old speed new speed delta
wuffs_webp_lossy_decode_image_19k_8bpp/clang14 33.7MB/s ± 0% 34.1MB/s ± 0% +1.28% (p=0.008 n=5+5)
wuffs_webp_lossy_decode_image_40k_24bpp/clang14 106MB/s ± 0% 106MB/s ± 0% +0.09% (p=0.008 n=5+5)
wuffs_webp_lossy_decode_image_77k_24bpp/clang14 129MB/s ± 0% 130MB/s ± 0% +0.54% (p=0.008 n=5+5)
wuffs_webp_lossy_decode_image_552k_32bpp/clang14 207MB/s ± 0% 211MB/s ± 0% +1.90% (p=0.008 n=5+5)
wuffs_webp_lossy_decode_image_4002k_24bpp/clang14 137MB/s ± 0% 138MB/s ± 0% +0.40% (p=0.008 n=5+5)
wuffs_webp_lossy_decode_image_19k_8bpp/gcc12 32.9MB/s ± 0% 32.9MB/s ± 0% +0.05% (p=0.008 n=5+5)
wuffs_webp_lossy_decode_image_40k_24bpp/gcc12 98.4MB/s ± 0% 98.8MB/s ± 0% +0.42% (p=0.008 n=5+5)
wuffs_webp_lossy_decode_image_77k_24bpp/gcc12 125MB/s ± 0% 125MB/s ± 0% +0.17% (p=0.008 n=5+5)
wuffs_webp_lossy_decode_image_552k_32bpp/gcc12 211MB/s ± 0% 214MB/s ± 0% +1.21% (p=0.008 n=5+5)
wuffs_webp_lossy_decode_image_4002k_24bpp/gcc12 137MB/s ± 0% 137MB/s ± 0% ~ (p=0.095 n=5+5)
This reverts commit a4ec3f8e, which triggers -Werror=sign-conversion
errors on C code like this:
v_foobar += blah;
instead of the equivalent (as all variables here have u32 type):
v_foobar += ((uint32_t)(0u + blah));
This compiler warning (or compiler error, with -Werror) is arguably a
false postive but it's easier not to fight the C compiler.
"wuffs test -mimic std/webp" now passes.
This commit, part of a series, is inspired by pull request PR #168 by
Damian Kaczmarek (with AI assistance), with some modifications.
Updates PR #168