Repository navigation
t27b: f32 @log, @log2 and @log10 from libm.t27 (compiler_rt logf, log2f, log10f) #7822
Copy link
Copy link
Closed
Labels
Description
Part of #7746 (t27b passes specs/numeric/gf16.t27), which is part of #6063 (t27b coverage), item C10 of #6488. This is the third PR of #7746's split, after #7791 and #7819.
What needs it
- gf16.t27.
gf16_log,gf16_log2andgf16_log10call@log,@log2and@log10on an f32, and tests such asgf16_log2_eightandgf16_log10_tenreach them.std.math.pow(f32, ..), the last PR of t27b: specs/numeric/gf16.t27 after the type mismatch family -- @bitCast, f32 rounding and libm, std.math, @setEvalBranchQuota #7746, calls@logand@expof an f32 too. specs/ml/loss/kl_divergence.t27is blocked only on its f32@log.- t27b today. It refuses an f32
@log(libm.t27 has no f32 routine for it), and@log2and@log10of any type.
What the reference does
Measured on the t27c lab (zig 0.16.0, x86_64 Debug, no libc):
- A run-time
@log,@log2or@log10of an f32 is a call of compiler_rtlogf,log2forlog10f(log.zig,log2.zig,log10.zig). These are musl's fdlibm-style routines on the bits, not the table-driven f64logthat libm.t27 already holds. - None is correctly rounded, so t27b must return their bits.
compiler_rt.want_float_exceptionsis true on x86_64 and aarch64, so:- a zero gives
-1 / (x * x)(-inf); - a negative gives
(x - x) / 0.0, a NaN whose bits are the platform's; - +inf and NaN come back as they are, a signalling NaN included.
- a zero gives
- A typed f32 operand Zig knows at compile time folds to the same bits as the run-time call. Measured on 24000 points per builtin: the whole bit range, and densely near 1. 0 differ.
Plan
- Port
logf,log2fandlog10fto t27 inspecs/tri/t27b/libm.t27, step for step, with the same constants (as exact decimals of their f32 values) and the same operation order. - In
specs/tri/t27b/libm_plan.t27:- an f32
@logcallslogf; - an f32
@log2and@log10calllog2fandlog10f; - an f64
@log2and@log10are refused, because compiler_rt's f64log2andlog10are not ported.
- an f32
- Hold each port to Zig's builtin bit for bit in a spec of its own, over sweeps of bit patterns. Then search for inputs where one ulp of a constant shows, as t27b: @log of an f64 calls compiler_rt's log written in t27, from the libm plan (Closes #7217) #7648 did for
log.
Acceptance criteria
t27b test --blockers specs/numeric/gf16.t27names no@log,@log2or@log10.specs/ml/loss/kl_divergence.t27no longer stops atExprCall(@log).- The new tests pass under
t27c test-reportwith 0 vacuous tests, and under t27b. Mutants of the ports' constants are killed. - The lab corpus receipt compare gives IMPROVED_ONLY, EQUIVALENT or NEUTRAL.
User Scenarios
- Given gf16.t27 calls
@log,@log2,@log10on f32 values, When t27b compiles gf16.t27, Then the build succeeds without "libm.t27 has no f32 routine for it" errors. - Given kl_divergence.t27 uses f32
@log, When t27b compiles kl_divergence.t27, Then compilation proceeds past theExprCall(@log)that currently stops it. - Given a t27 spec exercising f32
@log/@log2/@log10over bit-pattern sweeps, When t27c test-report runs it, Then all tests pass with 0 vacuous tests and mutant constants are killed.
Requirements
- FR-001: specs/tri/t27b/libm.t27 MUST contain f32
logf,log2f,log10fports matching compiler_rt step-for-step with identical constants (as exact decimals of their f32 values) and operation order. - FR-002: specs/tri/t27b/libm_plan.t27 MUST map f32
@log→logf, f32@log2→log2f, f32@log10→log10f, and MUST refuse f64@log2and@log10. - FR-003: New spec files for each port MUST verify bit-for-bit agreement with Zig's builtin
@log,@log2,@log10on f32 over full bit-range sweeps and dense sampling near 1. - FR-004: The ports MUST reproduce compiler_rt exception behavior: zero → -inf, negative → NaN (platform bits), +inf/NaN → unchanged (including signalling NaN).
- FR-005:
t27b test --blockers specs/numeric/gf16.t27MUST report zero blockers for@log,@log2,@log10.
Boundary
- specs/tri/t27b/libm.t27
- specs/tri/t27b/libm_plan.t27
- specs/numeric/gf16.t27
- specs/ml/loss/kl_divergence.t27
- scripts/tri_loop/t27b.py
Reactions are currently unavailable
Activity
Merge master into t27b/gf16-logf (Closes #7822)
Merge master into t27b/gf16-logf (Closes #7822)
Merge master into t27b/gf16-logf (Closes #7822)
Merge master into t27b/gf16-logf (Closes #7822)
Merge master into t27b/gf16-logf (Closes #7822)
Merge master into t27b/gf16-logf (Closes #7822)
Merge master into t27b/gf16-logf (Closes #7822)
Merge master into t27b-libm-std-math-7923 (Closes #7923)
Merge master 12ee225 into t27b-repeat-local-7909 (Closes #7909)
Merge master 12ee225 into t27b-optional-module-var-7910 (Closes #7910)
Merge master 12ee225 into t27b-int-cast-index-7902 (Closes #7902)