Skip to content

Keccak-f[1600] on Intel Atom: utility scripts, round example and permutation sweep - #476

Draft
magistras42 wants to merge 9 commits into
slothy-optimizer:mainfrom
h2parson:x86_pr3
Draft

magistras42 wants to merge 9 commits into
slothy-optimizer:mainfrom
h2parson:x86_pr3

Conversation

@magistras42

Copy link
Copy Markdown

PR 3 of 3, depending on #475.

These are the scripts we used to explore SLOTHY's split heuristic on Keccak-f[1600] for Intel Atom and to benchmark the results on hardware, plus one optimized round as an example. Following the project structure:

  • the scripts are in examples/misc/x86_64/, next to examples/misc/gen_roots.py;
  • the templates and the example input are naive code in examples/naive/x86_64/keccak/;
  • the generated code is in examples/opt/x86_64/keccak/.

This PR changes no SLOTHY code.

Changes (commit 1)

  • examples/naive/x86_64/keccak/x86_mKeccakRound_template.s: one Keccak round, with {iState}, {oState}, {rc}, {lastRound} parameters. It is taken from the SUPERCOP x86_64 implementation by Ronny Van Keer (CC0).
  • examples/naive/x86_64/keccak/x86_mKeccakPermutation_template.s: the full 24-round permutation, reusing the round macro unchanged (CC0, SUPERCOP).
  • examples/misc/x86_64/keccak_round_ex_opts.py: sweeps macro parameters × split-heuristic settings. For each combination it optimizes the round, reruns SLOTHY in fixed order to count stalls, and writes the count at the top of the output file.
    • The stall count is read from SLOTHY's log ("Minimum number of stalls: N") by a small logging.Handler (StallCounter), so no SLOTHY API change is needed.
    • All three Keccak scripts take --memory-offset-constraint, which turns on PR 1's opt-in Atom constraint (intel_atom.memory_offset_constraint).
  • examples/misc/x86_64/keccak_permutation_ex_opts.py: the same sweep over the full permutation. Its options are --rounds (for partial permutations), --max-configs and --output-dir. The per-round split settings are scaled by the number of rounds.
  • examples/misc/x86_64/keccak_splitting.py: a single fixed pipeline: register allocation, then the split heuristic, then the stall count.
  • examples/misc/x86_64/nanobench.py: runs code under nanoBench and parses its counters.
    • to_nanobench_asm() uses the PR 2 translator to turn AT&T code (such as SLOTHY's x86_64 output) into the ;-separated Intel string that nanoBench takes, so any SLOTHY output can be measured on hardware.
  • examples/misc/x86_64/thrpt_lat.py: measures the inverse throughput and latency of each instruction form. The Bonnell results are in the "Bonnell measurements" table of #PR1's description; the Atom model was checked against them, and test_atom_model.py embeds them.

nanoBench needs root and a real CPU, so only its output parsing is tested. Our Keccak benchmarking drivers and raw results stay in our fork. There's no script yet that compares SLOTHY's predicted stalls with measured cycles, but we will create the comparison script and add it in a follow-up PR, if desired.

Results and open questions

  • Single rounds optimized by SLOTHY ran faster than the original on Bonnell. For example, the setting used in the example gave about 108 cycles per non-final round, in a batch optimized with the memory constraint on.
  • When the optimized rounds were substituted back into the permutation, the gain held for up to about 9 rounds but not for the whole file.
  • The whole-file result looks dominated by an instruction-fetch effect, which we haven't confirmed yet.
    • In our measurements, one extra instruction at ~2,000 instructions added over 130 cycles in both versions.
    • That is roughly where nanoBench's unrolled code reaches the 32 KB L1 instruction cache.
  • Some stalls that SLOTHY didn't predict follow a store to x(%rdi) and a load from x(%rsp) within 8 cycles. The opt-in Atom constraint from PR 1 models this crudely.

Tests (commit 2)

  • tests/naive/x86_64/test_keccak_utilities.py: covers template rendering (including a missing parameter and the full round template), nanoBench output parsing, the nanoBench command line, translation for nanoBench, and the stall counter.
  • tests/naive/x86_64/test_keccak_permutation.py: checks that there are 24 rounds with the right constants, the buffer alternation, the last-round flag and partial permutations, and that the round macro is identical to the round template.
  • The Keccak example runs in the example.py --dry-run CI matrix entry for slothy.targets.x86_64.intel_atom.

Generated code (commit 3)

  • examples/naive/x86_64/keccak/keccak_round_rdi_rsp.s and _example.py produce examples/opt/x86_64/keccak/keccak_round_rdi_rsp_opt_atom.s. This is one Keccak round (state in rdi, output to the stack), optimized for Atom with the split heuristic (factor 3, step 1/6, one repetition) and with the opt-in memory constraint on. These are the conditions of the sweep batch in which this setting measured fastest for non-final rounds; without the constraint it was among the slower settings.

Commits

  1. x86_64: add Keccak utility scripts, templates and permutation sweep
  2. x86_64: add Keccak utility and permutation tests
  3. x86_64: add Keccak-round Atom example and generated code

Co-authored by Hayden Parsons (@h2parson) and Maggie Simmons.

magistras42 and others added 9 commits November 2, 2026 23:50
Co-authored-by: h2parson <haydenfparsons@icloud.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: h2parson <haydenfparsons@icloud.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: h2parson <haydenfparsons@icloud.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: h2parson <haydenfparsons@icloud.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: h2parson <haydenfparsons@icloud.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: h2parson <haydenfparsons@icloud.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: h2parson <haydenfparsons@icloud.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: h2parson <haydenfparsons@icloud.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: h2parson <haydenfparsons@icloud.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant