← Back to Pull requests

keccakf_amd64: 1.1x faster BMI2 permutation #38

Closed
unknown closed this pull request without merging on Nov 26, 2026 09:03 UTC
View on GitHub
unknown unknown commented on Nov 25, 2026 21:10 UTC
Author

Improve Keccak performance on x86 with BMI2 further, on top of the 2-round loop from #36, by following the implementation shape of evmone's Keccak and the assembly clang produces for it.

  • Exploit the 2-round loop following the C++ shape: compute the theta column parities in registers while chi stores the round output, so theta does not reload the state. −7.5%.

  • Fine-tune the scheduling following clang's output: emit the chi outputs of each group in the order 2, 3, 4, 1, 0. The instructions are the same, but the order sets the issue priority in the out-of-order core. A sweep over all 120 orders: every order starting with outputs 2 and 3 is equally fast, all others are slower. −1.7%.

  • Small optimization on top: keep lane 24 in a register between rounds. It saves a load and a store per round, and the store-to-load wait at the round boundary. −0.6%. Now slightly faster than evmone's current kernel.
  • These steps make the generator more complex, because these optimizations are not uniform (e.g. theta has 5 D words, but only 3 fit into the available registers, and lane 24 is a special case). The generator grows from 134 to 156 lines of code (including a simplification pass), the generated asm from 464 to 483 lines. I have doubts the generator makes sense at this point. It may be easier to work on the Go asm directly (we point AI at the generator or the asm anyway).

    | | permutation | Sum256 32 B | Sum256 1 KiB |
    |---|---|---|---|
    | master, cycles | 1024 | 1097 | 8417 |
    | this PR, cycles | 925 | 996 | 7640 |
    | speedup | 1.11× | 1.10× | 1.10× |
    | master, retired ops | 4554 | 4747 | 37005 |
    | this PR, retired ops | 4460 | 4655 | 36264 |

    Per step, cycles per permutation: 1024 → 947 → 931 → 925, retired ops: 4554 → 4506 → 4507 → 4460. For reference: evmone's kernel built with clang 23 is 938 (918 with ipsilon/evmone#1839, which applies the chi order there), clang's code translated to Go asm is 928.

    Measured with perf on a Ryzen 9 5950X (Zen 3).

    Diff: 246 lines (+184 / -62) across 3 files Reviewer: chfast Review duration: 712m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.44) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.44 · 246 lines diff across 3 files
    0.44
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.330
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #38"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43.9% (MEDIUM) · Higher = larger blast radius
    43.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.3% · Safe to merge
    17.3%