Commit Graph
5 Commits
Author SHA1 Message Date
Claude 4dff581dd0 script: check the softfloat comparisons in manual-test-softfloat-sweep.c
Add f32_compare and f64_compare, which run the cmp, eq, ne, lt, le, gt,
ge, min and max functions on every pair of 594 structured values
against the hardware's comparison operators.
2026-10-27 10:43:02 +00:00
Claude 44a9ca086c std/softfloat: compare non-negative, non-NaN operands directly
The f64 and f32 comparison, min and max functions now compare the bit
patterns directly when neither operand is negative or a NaN, and call
the unchanged general code (now f64_cmp_slow and f32_cmp_slow)
otherwise. Results are unchanged: the ops harness and the old-vs-new
differential test report zero mismatches.
2026-10-27 10:30:04 +00:00
Claude ab5930ffbb std/softfloat: return early for zero operands, merge the f64 add/sub fast paths and add a faster f32_from_u32
f64_add and f64_sub now share one fast path for normal operands
(f64_add_normal) and both return early when one operand is zero. The f32
add and sub do the same, and f32_from_u32 converts values below 2^24
directly. All results are unchanged: the sweep, the old-vs-new
differential test and the ops harness report zero mismatches.
2026-10-27 10:18:57 +00:00
Claude 1d1c338981 std/softfloat: add fast paths for f32 and f64 add, sub and mul
f32_add, f32_sub and f32_mul now compute the result directly in binary32
when both operands are normal and the result is normal (or overflows),
instead of always going through f64. f64_add and f64_sub get a similar
fast path for normal operands. Every other case takes the previous code
path, so results (including NaN payloads) are unchanged.

Add script/manual-test-softfloat-sweep.c, which checks the f32 and f64
add, sub, mul and div operations over every pair of operand exponents
with many mantissa patterns, and the f32 conversions, against the
hardware and (bit-for-bit, NaNs included) the via-f64 definitions.
2026-10-27 09:26:09 +00:00
Claude f33e9f3377 std/softfloat: add bit-exact IEEE 754 binary64/binary32 arithmetic
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
2026-10-26 22:46:32 +00:00