Repository navigation
t27b: f32 @floor, @ceil, @round, @trunc and @rem from libm.t27 (compiler_rt floorf, ceilf, roundf, truncf, fmodf) #7819
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 second PR of #7746's split, after #7791.
What gf16.t27 needs
gf16_floor, gf16_ceil, gf16_round, gf16_trunc and gf16_fmod call @floor, @ceil, @round, @trunc and @rem on an f32, and each has direct tests. t27b refuses all five today (ExprCall(@floor) and so on).
What the reference does
Measured on the t27c lab (zig 0.16.0, x86_64 Debug, the CPU has SSE4.1):
@floor,@ceiland@truncof an f32 are not calls. Zig emitsroundss, which is exact and quiets a signalling NaN (0x7F800001 gives 0x7FC00001). On aarch64,frintm,frintpandfrintzdo the same.@roundof an f32 calls compiler_rtroundf: half away from zero, and a NaN comes back as it is (0x7F800001 stays 0x7F800001). aarch64'sfrintaquiets it instead, so@roundof a signalling NaN is the one place the two references differ.@remof an f32 calls compiler_rtfmodf(generic_fmod): exact, and the sign follows the dividend (@rem(-4, 2)is -0.0). Its NaN is(x * y) / (x * y), whose bits are the platform's: 0xFFC00000 on x86_64, 0x7FC00000 on aarch64.
Plan
- Port compiler_rt's
floorf,ceilf,roundf,truncfandfmodfto t27 inspecs/tri/t27b/libm.t27. Forfloorf,ceilfandtruncf, a NaN is quieted, as the instruction does. - Add the five builtins to
specs/tri/t27b/libm_plan.t27:- an f32 calls its routine;
- an f64 is refused, because libm.t27 has no f64 routine for these yet;
@remtakes two operands, and the second takes the first one's type.
- Test each routine against Zig's builtin, bit for bit, over sweeps of bit patterns: signed zeros, subnormals, halves, NaN payloads and the infinities. No NaN bits are asserted where the two references differ.
Acceptance criteria
t27b test --blockers specs/numeric/gf16.t27names none of@floor,@ceil,@round,@truncand@rem.- libm.t27's new tests pass under
t27c test-reportwith 0 vacuous tests, and under t27b. - The lab corpus receipt compare gives IMPROVED_ONLY, EQUIVALENT or NEUTRAL.
User Scenarios
- Given
gf16.t27calls@floor,@ceil,@round,@trunc,@remon f32 values, Whent27bcompilesgf16.t27, Then none of the five builtins are refused and the tests ingf16.t27pass. - Given
libm.t27providesfloorf,ceilf,roundf,truncf,fmodfported from compiler_rt, Whent27c test-reportruns onlibm.t27, Then all new tests pass with 0 vacuous tests and bit-for-bit match Zig's builtins over the specified sweeps. - Given
libm_plan.t27declares the five f32 builtins with correct signatures, Whent27btype-checks a call to@remwith two f32 operands, Then the second operand takes the first's type and f64 calls are refused.
Requirements
- FR-001:
specs/tri/t27b/libm.t27MUST containfloorf,ceilf,roundf,truncf,fmodfroutines ported from compiler_rt for f32. - FR-002:
floorf,ceilf,truncfinlibm.t27MUST quiet a signalling NaN (0x7F800001 → 0x7FC00001) matching x86_64roundss/ aarch64frintm|p|zbehavior. - FR-003:
roundfinlibm.t27MUST implement half-away-from-zero and preserve a signalling NaN payload (0x7F800001 stays 0x7F800001) matching compiler_rtroundf. - FR-004:
fmodfinlibm.t27MUST implement exact remainder with sign following dividend (@rem(-4, 2)= -0.0) and produce platform NaN bits via(x*y)/(x*y)matching compiler_rtgeneric_fmod. - FR-005:
specs/tri/t27b/libm_plan.t27MUST declare@floor,@ceil,@round,@truncas unary f32 builtins calling theirlibm.t27routines and refuse f64. - FR-006:
specs/tri/t27b/libm_plan.t27MUST declare@remas binary f32 builtin where the second operand takes the first's type and refuse f64. - FR-007:
libm.t27MUST include bit-for-bit tests against Zig builtins covering signed zeros, subnormals, halves, NaN payloads, and infinities with no assertions on differing NaN bits between x86_64 and aarch64.
Success Criteria
t27b test --blockers specs/numeric/gf16.t27exits 0 and names none of@floor,@ceil,@round,@trunc,@remas blockers.t27c test-report specs/tri/t27b/libm.t27exits 0 with 0 vacuous tests and all new routine tests passing.t27b test specs/tri/t27b/libm.t27exits 0.- Lab corpus receipt compare yields IMPROVED_ONLY, EQUIVALENT, or NEUTRAL (no REGRESSION).
Boundary
- specs/numeric/gf16.t27
- specs/tri/t27b/libm.t27
- specs/tri/t27b/libm_plan.t27
Reactions are currently unavailable
Activity
Merge master into t27b/gf16-rounding (Closes #7819)
Merge master into t27b/gf16-rounding (Closes #7819)
Merge master into t27b/gf16-rounding (Closes #7819)
t27b: re-seal the libm specs with master's t27c 0.5.1 (Closes #7819)
Merge master into t27b/gf16-rounding (Closes #7819)
Merge master e87e790 into t27b-int-cast-index-7902 (Closes #7902)
Merge master e87e790 into t27b-optional-module-var-7910 (Closes #7910)
Merge master e87e790 into t27b-repeat-local-7909 (Closes #7909)
Merge master into t27b/gf16-pow; no hand-written line under cli/t27b (C…