Skip to content

[recompiler] Emit the A64 SIMD pairwise, across and MUL ops from Sail - #2489

Merged
DraChimeraVee merged 5 commits into
mainfrom
dravee/recompiler/sail-a64-simd-2
Nov 20, 2026
Merged

DraChimeraVee merged 5 commits into
mainfrom
dravee/recompiler/sail-a64-simd-2

Conversation

@DraChimeraVee

@DraChimeraVee DraChimeraVee commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

The A64 SIMD ops #2468 left written by hand, the pairwise ones, the integer reductions across lanes and MUL, come from their Sail, every choice made by the generator and none in the code it emits.

  • sailgen folds the bits of the word that the decode clause fixes: an if on them keeps one branch when sailgen runs. MUL's clause fixes U at 0, so its element loop no longer reaches PMUL's polynomial product loop. The other ops' IR is the same as before (llvm_sail_ir's report, word by word).
  • An element loop that reads elements 2e and 2e + 1 of Vm:Vn (ADDP, SMAXP, SMINP, UMAXP, UMINP) is a shufflevector of the two registers' lanes, its mask made when the recompiler runs, as ir_vec.c's unzip; the 256-bit concatenation is never made.
  • A loop from 1 that folds each element into a local that starts as element 0's value (SMAXV, SMINV, UMAXV, UMINV, SADDLV, UADDLV) is llvm.vector.reduce over every lane; the start is proved to be element 0 on the Sail's tree, else the loop stays a loop.
  • ADDV's Reduce is read from its Sail's recursion, not lowered by name (Liz: "Derived from recursion so runtime doesn't pay cost, only generator"): sailgen reads on the tree that Reduce__1 gives one element as it is and else calls itself on each half of its bits, walks what joins the two results with the op the decode fixed, and their + is the same llvm.vector.reduce.add of the lanes. A floating-point op, whose result depends on the order, and any other function that calls itself are refused with the name and the line.
  • MUL, ADDP, SMAXP, SMINP, UMAXP, UMINP, ADDV, SADDLV, UADDLV, SMAXV, SMINV, UMAXV and UMINV on vectors are generated; their hand-written emitters move to tests/support/ir_vec_reference.c.

Testing, on 422774c (c0aea3d before the rebase, the same patches and generated emitters):

  • ctest of the recompiler and sailgen, 82 tests: sailgen_lanes pairs=lanes fold=lanes start=loop fixed=lanes free=loop besides [recompiler] Emit the A64 SIMD integer ops from the Sail as vectors #2468's three, sailgen_halves sum=reduce, and the six sailgen_refused_halves_*: the halves joined by another op, a value that is not their sum or is it under a condition alone, the same half twice, a base that is not the element, a register written where they are joined.
  • llvm_sail_ir: 13561 words on the three paths, none longer, the same results from 8 states. The 13 new ops: ADDV and the six other across ops the same IR, the pairwise ops and MUL the same instructions reordered. The other ops' 6843 listed words have the same verdict and IR sizes as on main.
  • With ADDV from the recursion, sailgen's output is the one before it byte for byte but for ADDV's emitter, which makes the same back end call on the same value, and the lines of a64.sail its messages name; llvm_sail_ir's three reports are the same files.
  • ucas proves the tree of halves joined by + equal to the lanes' sum in lane order, modulo the element's size, for every shape up to 128 bits: by SAT on the slices of 64 bits and of 128 by 32, as a ring identity on the lanes for 16 of 8 bits and 8 of 16.
  • Fourteen mutants fail a test: llvm_sail_ir names the op for the concatenation's sides swapped and the mask taken as the lane's own (ADDP_v), Min and Max folded unsigned (SMAXV), the sum folded at a lane's width (SADDLV), the sum of Reduce's halves folded exact (ADDV, longer) and the word's fixed bits inverted (every op); sailgen_lanes fails when an accumulator's start is not checked; and seven of the reading of the recursion each fail their sailgen_halves or sailgen_refused_halves_* test.
  • Measured on df1a75a, whose emitted IR this head's is: emitting and optimizing the corpus +0.7% (each round, both arms in one process: +0.7%, +2.0%, -1.0%), emitting alone +25%, as for [recompiler] Emit the A64 SIMD integer ops from the Sail as vectors #2468. llvm_bench (12 kernels, 5 interleaved rounds against main 0348b59, twice): none apart in either set. The runs far from their median were repeated alone, 15 rounds each: calls-live (one run at 1.78 times its median on the branch's side in the first set) -0.77%, fp (the branch's first three runs slow in the second set, +3.99% there) -0.04%, neither apart; neither kernel holds an op this changes. edenprobe's cpu area is the same as main's (737 pass, 2 skip in both).

A field the clause pins is known when sailgen runs, so an if on it keeps one branch: MUL's
clause fixes U at 0, and its element loop no longer holds PMUL's polynomial product.

Change-Id: I7d2db64d0eb722a0747c7c75d9335c62e948cc4b
Signed-off-by: AO55 <AO55@reden-emu.dev>
Elements 2e and 2e + 1 of Vm:Vn are lanes of both registers picked by a mask made when the
recompiler runs, as ir_vec.c's unzip does; the 256-bit concatenation is never made.

Change-Id: I178d68c5c2f7da921419c0b883ab13c6ca213d18
Signed-off-by: AO55 <AO55@reden-emu.dev>
A loop from 1 that folds each element into a local starting at element 0 is
llvm.vector.reduce of every lane, and Reduce of ReduceOp_ADD the same, as ir_vec.c's
across() builds them.

Change-Id: If22bcfb3afa11b6b8a1365366de6c804e50184a9
Signed-off-by: AO55 <AO55@reden-emu.dev>
MUL, ADDP, SMAXP, SMINP, UMAXP, UMINP, ADDV, SADDLV, UADDLV, SMAXV, SMINV, UMAXV and UMINV
on vectors come from their Sail, with the IR ir_vec.c built for them.

Change-Id: I7a179c16687550523a14f0cf3d0ec27ac748416f
Signed-off-by: AO55 <AO55@reden-emu.dev>
@DraChimeraVee DraChimeraVee added kind: enhancement New feature or improvement priority: high Next in line preview-effort: medium A focused change across a few files area: recompiler labels Nov 18, 2026
@DraChimeraVee DraChimeraVee changed the title [wip] [recompiler] Emit the A64 SIMD pairwise, across and MUL ops from Sail [recompiler] Emit the A64 SIMD pairwise, across and MUL ops from Sail Nov 19, 2026
@DraChimeraVee DraChimeraVee changed the title [recompiler] Emit the A64 SIMD pairwise, across and MUL ops from Sail [donotmerge waiting Liz] [recompiler] Emit the A64 SIMD pairwise, across and MUL ops from Sail Nov 19, 2026
@DraChimeraVee

Copy link
Copy Markdown
Contributor Author

From Aogo:
Measured and proven (body above); one design call waits for Liz: ADDV comes from Reduce(ReduceOp_ADD), lowered by name to llvm.vector.reduce.add as CountLeadingZeroBits already is, while the other across ops are recognized from their loops. By name, or derived from the Sail's recursion? Kept donotmerge until she answers.

Reduce is not lowered by name: sailgen reads that Reduce__1 gives one element as it is and
else adds what it gives for each half, the elements' sum, and emits the same
llvm.vector.reduce.add. Any other function that calls itself is refused.

Change-Id: I0d0035d0c90e6c2de9861c77d7288b10855d56d2
Signed-off-by: AF52 <AF52@reden-emu.dev>
@DraChimeraVee
DraChimeraVee force-pushed the dravee/recompiler/sail-a64-simd-2 branch from c0aea3d to 422774c Compare November 20, 2026 10:18
@DraChimeraVee DraChimeraVee changed the title [donotmerge waiting Liz] [recompiler] Emit the A64 SIMD pairwise, across and MUL ops from Sail [recompiler] Emit the A64 SIMD pairwise, across and MUL ops from Sail Nov 20, 2026
@DraChimeraVee
DraChimeraVee marked this pull request as ready for review November 20, 2026 12:16
@DraChimeraVee
DraChimeraVee merged commit c7739cb into main Nov 20, 2026
18 of 19 checks passed
@DraChimeraVee
DraChimeraVee deleted the dravee/recompiler/sail-a64-simd-2 branch November 20, 2026 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: recompiler kind: enhancement New feature or improvement preview-effort: medium A focused change across a few files priority: high Next in line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants