Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,18 @@ own logarithm and exponential and calls only `sqrt`, `fabs` and `scalbn`. `sinh`
(`VFdlibm.sinh`, from `e_sinh.c`, computing through `expm1`'s common path below 22 and finishing
the rest per lane), and so is `cosh` (`VFdlibm.cosh`, from `e_cosh.c`, through `exp`'s common path
and expm1's `k == 0` lines, with two arms for its small range: the default arm is the slice arm,
provisionally, until a benchmark host times them). `asin` is done too (`VFdlibm.asin`, from
`e_asin.c`, with `sqrt` as the Vector API's `SQRT`, one arm, and the lanes of `|x| >= 1` finished
per lane), and so is `atan` (`VFdlibm.atan`, from `s_atan.c`, five ranges through one division on
blended operands, the lanes from `2^66` up finished per lane), and so is `acos`
(`VFdlibm.acos`, from `e_acos.c`, built as asin is), and so is `atan2` (`VFdlibm.atan2`, from
`e_atan2.c`, the first function of two arguments: the special lanes blended over the general path,
which calls `atan`'s core, no lane finished per lane, and two arms, the blended one and the guarded
one `VFdlibm` calls, provisionally). `log`, `log10` and
`log1p` are done too (`VFdlibm.log`, from `e_log.c`, `VFdlibm.log10`, from `e_log10.c`, which
computes through log's common path, and `VFdlibm.log1p`, from `s_log1p.c`), and so is `expm1`
(`VFdlibm.expm1`, from `s_expm1.c`, whose reduction is exp's).
provisionally, the host files of 21 November timing both and deciding neither). `asin` is done
too (`VFdlibm.asin`, from `e_asin.c`, with `sqrt` as the Vector API's `SQRT`, one arm, and the
lanes of `|x| >= 1` finished per lane), and so is `atan` (`VFdlibm.atan`, from `s_atan.c`, five
ranges through one division on blended operands, the lanes from `2^66` up finished per lane), and
so is `acos` (`VFdlibm.acos`, from `e_acos.c`, built as asin is), and so is `atan2`
(`VFdlibm.atan2`, from `e_atan2.c`, the first function of two arguments: the special lanes blended
over the general path, which calls `atan`'s core, no lane finished per lane, and two arms, the
blended one and the guarded one `VFdlibm` calls, provisionally: the host files of 22 November time
both and give them no direction). `log`, `log10` and `log1p` are done too (`VFdlibm.log`, from
`e_log.c`, `VFdlibm.log10`, from `e_log10.c`, which computes through log's common path, and
`VFdlibm.log1p`, from `s_log1p.c`), and so is `expm1` (`VFdlibm.expm1`, from `s_expm1.c`, whose
reduction is exp's).

`tan`, `tanh` and `cbrt` are fdlibm on aarch64 but Intel LIBM stubs on x86, so a port of them
matches the JVM only on Arm. `sin` and `cos` are HotSpot's own stubs on both architectures, so
Expand Down Expand Up @@ -137,8 +138,10 @@ five are a later, optional set; the large-argument reduction of the trigonometri
but for the rows of that pair.
Which arm each function keeps stays provisional until the 8573C has a second run, the other
AVX-512 hosts a first, and a pair exists, and the rules for a tie within 1.3x and for hosts that
disagree are set (issue #30); meanwhile `VFdlibm` calls the finish arm of `exp`, `log` and `log10`
and the guarded arm of `expm1` and `log1p` (`HARDWARE.md`).
disagree are set (issue #30); meanwhile `VFdlibm` calls the finish arm of `exp`, `log` and
`log10`, the guarded arm of `expm1`, `log1p` and `atan2` and the slice arm of `cosh`
(`bench/results/cosh-*-2026-11-21.txt` and `atan2-*-2026-11-22.txt` give the arms of `cosh`
and `atan2` no direction, and each wants a re-run on the EPYC 7763 too).

## 6. Rules

Expand Down Expand Up @@ -179,8 +182,11 @@ five are a later, optional set; the large-argument reduction of the trigonometri
finish of `exp`, `expm1`, `log`, `log10` and `log1p` boxed there on mixed data until its first
eight lanes were written out (`bench/results/max-finish-laptop-2026-11-20.txt`, then
`bench/results/max-finish-alloc-free-laptop-2026-11-21.txt`, a laptop reading of allocation only);
no file reads the earlier finish of `sinh` or `cosh`, and none has an `asin`, `atan`, `acos` or
`atan2` row, whose finishes were written in the new shape from the start. `ExpKindsBench` runs
no file reads the earlier finish of `sinh` or `cosh`, whose current rows the host files of 21
November read (`bench/results/sinh-xeon8573c-2026-11-21.txt` and the like). `asin`, `atan` and
`acos` were written with the new finish from the start, and `atan2` finishes no lane per lane;
the host files of 22 November read their rows (`bench/results/asin-xeon8573c-2026-11-22.txt`
and the like). `ExpKindsBench` runs
exp's two arms on one kind of rare input at a time (a NaN, an overflow, an underflow, a subnormal
result), to find which kind costs an arm its time on mixed data (#41); it is named apart so that
a run of
Expand Down
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,18 @@ are unchanged, and each lane still meets the contract below.
allocates differs. The allocation check (`bench/alloc-check.py`, run by CI) covers 256 bits, the
preferred species and `SPECIES_MAX` (up to eight lanes) on x86, and the preferred species, 128
bits, on GitHub's Arm runner. The files under `bench/results/` read as allocating, and the check
does not cover: `exp` and `log` at 128 bits on x86, and every function at 512 bits on an AVX2
host. `SPECIES_MAX` was read on a laptop only (`max-finish-alloc-free-laptop-2026-11-21.txt`); the
host files that have a `*Max` row (the Xeon's of 21 November for all five functions, the EPYC's of
20 November for `exp` and `log10`, and `exp-onediv-xeon8573c-2026-11-03.txt`) read the old finish.
The Javadoc of `VFdlibm` gives each reading with its file, and lists what is not measured: the
speed of 512 bits against 256 on the EPYC 9V74 draws that have AVX-512, and any port's speed on
Arm.
does not cover: `exp` and `log` at 128 bits on x86, and every function but `atan2`, which has no
512-bit row, at 512 bits on an AVX2 host. `SPECIES_MAX` of today's `exp`, `expm1`, `log`, `log10`
and `log1p` was read on a laptop (`max-finish-alloc-free-laptop-2026-11-21.txt`), and on a host
only for `exp` and `log10`, at 256 bits, by the EPYC 7763 pair
(`exp-log10-pair-epyc7763-2026-11-21.txt` and its re-run); the other host files that have a
`*Max` row of those five (the Xeon's of 21 November for all five, the EPYC's of
20 November for `exp` and `log10` and of 21 November for all five, and
`exp-onediv-xeon8573c-2026-11-03.txt`) read the old finish. The host files of 21 November for
`sinh` and `cosh` and of 22 November for `asin`, `atan`, `acos` and `atan2` (`bench/results/`)
read their `*Max` rows as they are now, under 0.05 bytes per op. The Javadoc of `VFdlibm` gives
each reading with its file, and lists what is not measured: the speed of 512 bits against 256 on
the EPYC 9V74 draws that have AVX-512, and any port's speed on Arm.

## Supported JDKs

Expand Down Expand Up @@ -173,13 +178,14 @@ fdlibm's own sequence of operations, lane by lane. That is this library.
- **Rare paths, exact too.** Lanes on a rare path (huge arguments, subnormals, special cases) are
either computed in the vector, every branch blended (in every vector, or only in a vector that
holds a rare lane), or finished by `StrictMath` per lane; the result is exact either way. The
choice is made per function from benchmarks, and stays provisional. `exp`, `expm1`, `log`, `log10`
and `log1p` each have files from the Xeon Platinum 8573C and the EPYC 7763 (`bench/results/`), and
each file's reading is in `SKILLS.md`; where two arms are within 1.3x of each other no direction
is read, and where the hosts disagree the files say so. The decision waits for a second run of the
8573C and a first of the other AVX-512 hosts (`HARDWARE.md`, the EPYC 9V45 when drawn), a pair,
and the rules for a tie and for hosts that disagree (issue #30). The laptop's numbers do not agree
at every width.
choice is made per function from benchmarks, and stays provisional. The functions with more than
one arm, `exp`, `expm1`, `log`, `log10`, `log1p`, `cosh` and `atan2`, each have files from the
Xeon Platinum 8573C and the EPYC 7763 (`bench/results/`), and each file's reading is in
`SKILLS.md`; where two arms are within 1.3x of each other no direction is read, and where the
hosts disagree the files say so. The decision waits for a second run of the 8573C and a first of
the other AVX-512 hosts (`HARDWARE.md`, the EPYC 9V45 when drawn), for `cosh` and `atan2` a
second run of the EPYC 7763 too, a pair, and the rules for a tie and for hosts that disagree
(issue #30). The laptop's numbers do not agree at every width.

## Testing

Expand Down
42 changes: 30 additions & 12 deletions SKILLS.md
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,8 @@ stops the next port re-trying a settled question.
hand on this version).
- **What a pass over a function of two arguments costs** (laptop, 21 November 2026,
`bench/results/pair-sweep-laptop-2026-11-21.txt`; it was taken before `atan2` was ported, so it is
two stand-ins run through `PairCostProbe`, not the port, and no timing of `atan2` exists). A
two stand-ins run through `PairCostProbe`, not the port, which it does not time; the port's
timings are `bench/results/atan2-xeon8573c-2026-11-22.txt` and `atan2-epyc7763-2026-11-22.txt`). A
stripe of 2^24 high words at 256 bits took 0.9 s for the harness alone (`toy2`) and 1.8 s for an
arm that calls `StrictMath.atan2` lane by lane, against 2.9 s and 3.6 s for the unary sweeps of
exp and log1p, at 4 threads on 4 CPUs. Scaled to a whole pass (256 stripes), the x86 sweep jobs of
Expand Down Expand Up @@ -984,9 +985,16 @@ stops the next port re-trying a settled question.
only on `|x| < 0.5*ln2`, so their cost follows the share of that range, which is 3.5% in
Varka's baseline benchmark and 17% in Spark's unit tests (issue #32): at 8 lanes a vector
holds one in 27% and 82% of the cases. `CoshKindsBench` has those two shares, and
`CoshBenchmark`'s common data 0.6% of them. No timing of the two arms exists yet: a laptop
run under load read no direction and was not kept. So the default is the plan's baseline
design, not a measurement, and a benchmark host's run of both classes decides it.
`CoshBenchmark`'s common data 0.6% of them. A laptop run under load read no direction and was
not kept. Each host has since run both classes once
(`bench/results/cosh-xeon8573c-2026-11-21.txt`, `cosh-epyc7763-2026-11-21.txt`,
`cosh-kinds-xeon8573c-2026-11-21.txt` and `cosh-kinds-epyc7763-2026-11-21.txt`), and no file
decides the arm: on `CoshBenchmark` the ratios between the arms are near 1.3x, waiting for a
re-run before a direction is written, or inside it, with no direction; on `CoshKindsBench` the
finish arm reads lower by more than 1.3x only on data with no small lane, and the arms read
within 1.3x of each other, with no direction, at 3.5% and 17% of small lanes, Varka's and
Spark's shares. So the default is still the plan's baseline design, not a measurement, and
stays provisional until a re-run and issue #30's rules decide it.
- **Which exp faults reach cosh.** `exp.dropCorrection` and `exp.constantOffByOneUlp`, which
change `expCore`'s lanes of `|x| >= 0.5 ln2`. `exp.thresholdMoved` moves the subnormal
scale-back, which `expCore` leaves out, and `exp.dropKForcing` the lanes of the word of 0.5
Expand Down Expand Up @@ -1015,6 +1023,10 @@ stops the next port re-trying a settled question.
- **One finish arm.** The rare lanes (`|x| >= 2^66`, the infinities and the NaNs) have results
that are a constant or `x+x`, so a guarded arm that blends them is possible; none is built,
because the tie-break rule of #30 sends a tie to the finish arm and no timing says otherwise.
The host files of 22 November (`bench/results/atan-xeon8573c-2026-11-22.txt` and
`atan-epyc7763-2026-11-22.txt`, one run each) time the one arm against the scalar loop, and
read every vector row at 0.02 B/op or less, but for the EPYC's 512-bit rows, which run in Java
there.
- **Sizes of its faults, each of 2^22 uniform draws from its own interval.** `atan.dropLo`:
855028 changed of 2^22 draws from `(-5, 5)`, none of those below 7/16. `atan.splitMoved`
(19/16 moved to 2): 431802 changed of 2^22 draws from `[19/16, 2)`, none from the ranges
Expand Down Expand Up @@ -1061,9 +1073,11 @@ stops the next port re-trying a settled question.
`bench/alloc-check.py` passed on `AsinBenchmark`'s rows (`finish256`, `finishPreferred` and
`finishMax`, common and mixed data) and on `SqrtBenchmark`'s (`sqrtMax` has no row: the class
has no `SPECIES_MAX` arm), at this laptop's flags and as an AVX2 host (`-XX:UseAVX=2
-XX:MaxVectorSize=32`); CI runs it. The readings are not committed as results
files, so no figure of them is quoted. That says nothing of 128 bits or of the masked form's
lowering; no timing is committed either, so the port claims no speed.
-XX:MaxVectorSize=32`); CI runs it. Those local readings are not committed, so no figure of
them is quoted. The host files of 22 November (`bench/results/asin-xeon8573c-2026-11-22.txt`
and `asin-epyc7763-2026-11-22.txt`, one run each) read every vector row at 0.02 B/op or less,
but for the EPYC's 512-bit rows, which run in Java there, and time the arm against the scalar
loop. None of it says anything of 128 bits or of the masked form's lowering.
- **One arm, no tie to break.** The three ranges below 1 share `t`'s polynomials and the one
division `p/q`, and the split range's second division is computed on every lane; the rare lanes
(`|x| >= 1`, NaN) are finished per lane. There is no second body to compare, so the arm needs
Expand Down Expand Up @@ -1107,8 +1121,10 @@ stops the next port re-trying a settled question.
midpoint, so most are not hard to round; the file keeps every line. All are positive, between
0.0143 and 0.999999999999999.
- **Allocation.** CI runs `bench/alloc-check.py` on `AcosBenchmark`'s rows (`finish256`,
`finishPreferred`, `finishMax`, common and mixed data). No reading of them is committed and no
timing exists, so nothing is claimed of either.
`finishPreferred`, `finishMax`, common and mixed data). The host files of 22 November
(`bench/results/acos-xeon8573c-2026-11-22.txt` and `acos-epyc7763-2026-11-22.txt`, one run
each) read every vector row at 0.02 B/op or less, but for the EPYC's 512-bit rows, which run
in Java there, and time the arm against the scalar loop.

## What the atan2 port taught

Expand All @@ -1127,9 +1143,11 @@ stops the next port re-trying a settled question.
and the special blends follow inline (no second call), and the body then allocates nothing:
`bench/alloc-check.py` passes on the `Atan2Benchmark` rows (`blended` and `guarded`, at 256 bits,
the preferred species and `SPECIES_MAX`, common and mixed data) at this laptop's flags and as an
AVX2 host, and CI runs it. The readings are not committed as results files, so no figure of them
is quoted. No timing of `atan2` exists, so the two arms are not compared and the guarded one
is the default provisionally.
AVX2 host, and CI runs it. Those local readings are not committed, so no figure of them is
quoted. Each host has timed both arms once (`bench/results/atan2-xeon8573c-2026-11-22.txt` and
`atan2-epyc7763-2026-11-22.txt`): on the Xeon they read within 1.3x of each other at every
width, and on the EPYC 7763 near 1.3x or inside it, so neither file gives them a direction, and
the guarded one stays the default provisionally until a re-run and issue #30's rules decide it.
- **A lane the core must not see.** A NaN, an infinity or a huge `t` in a lane the special blends
overwrite would send the vector to atan's per-lane finish. The mask `t < 2^66` keeps them out
(a NaN compares false), and a vector with no special lane never reaches the finish.
Expand Down
5 changes: 3 additions & 2 deletions src/jmh/java/io/github/vecbricks/vfdlibm/AcosBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
*
* <p>{@code bench/alloc-check.py} runs the vector benchmarks named {@code *256}, {@code
* *Preferred} and {@code *Max} on {@code common} and {@code mixed} inputs and fails if any
* allocates, which means the body boxed. No reading of these rows is committed. acos has one arm,
* so there is no comparison to make between arms.
* allocates, which means the body boxed. bench/results/acos-xeon8573c-2026-11-22.txt and
* acos-epyc7763-2026-11-22.txt read these rows, one run on each host. acos has one arm, so there
* is no comparison to make between arms.
*/
@State(Scope.Thread)
@BenchmarkMode(Mode.AverageTime)
Expand Down
5 changes: 3 additions & 2 deletions src/jmh/java/io/github/vecbricks/vfdlibm/AsinBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
* *Preferred} and {@code *Max} on {@code common} and {@code mixed} inputs and fails if any
* allocates, which means the body boxed. The {@code *Max} row is at {@code
* DoubleVector.SPECIES_MAX}; {@link Asin#asin}'s finish writes out its first eight lanes with
* constant indices, as the other ports' do since #100. No reading of these rows is committed.
* asin has one arm, so there is no comparison to make between arms.
* constant indices, as the other ports' do since #100. bench/results/asin-xeon8573c-2026-11-22.txt
* and asin-epyc7763-2026-11-22.txt read these rows, one run on each host. asin has one arm, so
* there is no comparison to make between arms.
*/
@State(Scope.Thread)
@BenchmarkMode(Mode.AverageTime)
Expand Down
7 changes: 4 additions & 3 deletions src/jmh/java/io/github/vecbricks/vfdlibm/Atan2Benchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
* StrictMath.atan2} loop and the two arms of {@link Atan2}, {@code blended} (the special lanes'
* blends in every vector) and {@code guarded} (behind one test; {@code VFdlibm.atan2} runs it),
* at 256 bits, at the host's preferred species and at {@code SPECIES_MAX}. 128 bits is left out:
* on x86 C2 lowers no mask at two 64-bit lanes, so every 128-bit arm boxes (SKILLS.md). No
* timing of {@code atan2} exists: the benchmark is read by {@code bench/alloc-check.py} for what
* the bodies allocate, and the arms are not yet compared on a host.
* on x86 C2 lowers no mask at two 64-bit lanes, so every 128-bit arm boxes (SKILLS.md). {@code
* bench/alloc-check.py} reads it for what the bodies allocate, and
* bench/results/atan2-xeon8573c-2026-11-22.txt and atan2-epyc7763-2026-11-22.txt time it, one
* run on each host, which gives the two arms no direction.
*
* <p>{@code inputs} picks the data: {@code common} draws {@code y} and {@code x} from {@code
* (-4, 4)}, where no lane is special (NaN, zero, infinite), none has {@code x = 1.0} and none
Expand Down
2 changes: 2 additions & 0 deletions src/jmh/java/io/github/vecbricks/vfdlibm/AtanBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
* DoubleVector.SPECIES_MAX}, where the finish walked the set bits of the rare mask, a variable
* lane index that boxes there, until it wrote out its first eight lanes with constant indices
* (bench/results/max-finish-alloc-free-laptop-2026-11-21.txt).
* bench/results/atan-xeon8573c-2026-11-22.txt and atan-epyc7763-2026-11-22.txt read these rows,
* one run on each host.
*/
@State(Scope.Thread)
@BenchmarkMode(Mode.AverageTime)
Expand Down
4 changes: 3 additions & 1 deletion src/jmh/java/io/github/vecbricks/vfdlibm/CoshBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
* DoubleVector.SPECIES_MAX}, where the finish writes out its first eight lanes with constant
* indices and a loop takes any past eight; the rows read under 0.1 B/op in the laptop reading of
* bench/results/max-finish-alloc-free-laptop-2026-11-21.txt (allocation only, no timing). No
* file reads the finish they replaced.
* file reads the finish they replaced. bench/results/cosh-xeon8573c-2026-11-21.txt and
* cosh-epyc7763-2026-11-21.txt read these rows, one run on each host, and give the two arms no
* direction.
*/
@State(Scope.Thread)
@BenchmarkMode(Mode.AverageTime)
Expand Down
3 changes: 3 additions & 0 deletions src/jmh/java/io/github/vecbricks/vfdlibm/CoshKindsBench.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
* are to be quoted come from {@code bench/dispatch-bench.sh}, which applies the fixed method
* (AGENTS.md); by hand that is {@code -f 2 -wi 3 -w 2s -i 5 -r 2s -prof gc -jvmArgsAppend
* -XX:CompileCommand=inline,io.github.vecbricks.vfdlibm.*::*}.
*
* <p>bench/results/cosh-kinds-xeon8573c-2026-11-21.txt and cosh-kinds-epyc7763-2026-11-21.txt
* read these rows, one run on each host, and decide no arm.
*/
@State(Scope.Thread)
@BenchmarkMode(Mode.AverageTime)
Expand Down
3 changes: 2 additions & 1 deletion src/jmh/java/io/github/vecbricks/vfdlibm/SinhBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
* DoubleVector.SPECIES_MAX}, where the finish writes out its first eight lanes with constant
* indices and a loop takes any past eight; the row reads under 0.1 B/op in the laptop reading of
* bench/results/max-finish-alloc-free-laptop-2026-11-21.txt (allocation only, no timing). No
* file reads the finish it replaced.
* file reads the finish it replaced. bench/results/sinh-xeon8573c-2026-11-21.txt and
* sinh-epyc7763-2026-11-21.txt read these rows, one run on each host.
*/
@State(Scope.Thread)
@BenchmarkMode(Mode.AverageTime)
Expand Down
Loading