Repository navigation
x86_64 architecture model and Intel Atom (Bonnell) microarchitecture model - #474
Open
magistras42 wants to merge 3 commits into
Open
magistras42 wants to merge 3 commits into
magistras42 wants to merge 3 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the first of three stacked PRs adding x86_64 support to SLOTHY:
The series doesn't change SLOTHY's core (
core.py,dataflow.py,heuristics.pyare untouched).Each PR has three commits: code, tests, generated code. We'd like to merge them without squashing; please let us know if that doesn't work for you, and whether force-pushes to update an open PR are OK.
Part 1a: x86_64 architecture model (
slothy/targets/x86_64/)x86_64_base_instructions.py,x86_64_sse_instructions.py,x86_64_avx_instructions.py) on a pattern-based core (x86_64_instruction_core.py,instruction_core.py). This covers the forms needed for Keccak: GPR ALU ops, moves, rotates/shifts,test,xchg,push/pop,jz/jnz, memory forms with a base register and optional immediate offset, and SSEmovdqu/pxor.a,di,8, ...) and a size check against the size tag in the pattern (HW/SW/DW/QWfor 8/16/32/64-bit GPRs,XMM,YMM). Symbolic registers use the same tags, e.g.%QW<state>.addr, following SLOTHY's convention.push/popalso read and writersp, so they stay ordered against stack accesses.SF,ZF,PF) is its own register. Flags are added only as instructions need them (see Known limitations).reads=/writes=) work as on AArch64.xorwith a memory operand has a fusion callback that splits it into a load and a registerxor.SP/BPregisters are reserved by default.Part 1b: Intel Atom / Bonnell model (
slothy/targets/x86_64/intel_atom.py)issue_rate = 2), unitsALU0,ALU1,MUL,DIV,MEM,FP0,FP1.test_atom_model.py).xorusesALU0+MEM(measured; Agner Fog lists either ALU).pxorusesFP0+MEM. It needs the MEM unit and either FP unit, but a choice between unit groups ([[FP0, MEM], [FP1, MEM]]) isn't supported by SLOTHY's unit model, so the model fixes FP0.push,popandxchg(microcoded, measured inverse throughput 6) occupy every execution unit.llvm_mca_target = "atom".intel_atom.memory_offset_constraint = Truekeeps accesses with the same immediate offset but different base registers at least 8 cycles apart. It is off by default because it is a simplification of behaviour we don't fully understand yet.Bonnell measurements
The Atom model was checked against these nanoBench measurements, taken one instruction form at a time on a Bonnell machine with
thrpt_lat.py(added in PR 3). Every value is in cycles, and "–" means the latency wasn't measured.test_atom_model.pyembeds the values and lists the known deviations from the model.add %rbx, %raxadd $1, %raxmov %rbx, %raxmov $1, %raxmov (%rdi), %raxmov %rax, (%rdi)movq $1, (%rdi)mov 8(%rdi), %raxmov %rax, 8(%rdi)movq $1, 8(%rdi)not %raxor %rbx, %raxpop %raxpush %raxrol $1, %raxrol %raxshr $1, %raxsub $1, %raxxchg %rax, %rbxxor $1, %raxxor %rbx, %raxxor 8(%rdi), %raxxor %rax, 8(%rdi)xorq $1, 8(%rdi)Changes to shared code
slothy/helper.py:.equvalues may contain%(.equ rState, %rdi).slothy/targets/query.py,common/OptimizationRunner.py,test.py,example.py: register x86_64 / Intel Atom..github/workflows/test_basic.yaml:slothy.targets.x86_64.intel_atomadded to both target matrices.README.md,docs/source/general.md: x86_64 / Intel Atom added to the list of supported targets;docs/source/faq.md: "Does SLOTHY support x86?" updated.Known limitation: loops
Loop optimization on x86_64 (
optimize_loop,BranchLoop) is currently unsafe and is being fixed. Flag writes are only partially modelled:testwrites SF/ZF/PF andjz/jnzread ZF, butadd/sub/and/or/xor/shrdon't declare their flag writes. SLOTHY can therefore schedule a flag-writing instruction betweentestand the branch, which overwrites ZF on hardware. The selftest doesn't compare flags, so it doesn't catch this. Straight-line code that doesn't read flags, including all Keccak examples in this series, is not affected. The code carries the same warning (BranchLoopdocstring). The fix (declaring the flag writes, non-renameable flags, the branch flag as a loop-body output, selftest support for flag bits) will follow in a separate PR.Other limitations
addrholds the full register name, so(%rax)and(%eax)count as different addresses (fine when one register size is used, as in Keccak).al/ax/eax/raxare separate registers; overlap is not modelled.movdqu/pxor/xorfrom memory need an explicit offset (0(%rsi)); offset-free forms give a parse error.vpunpcklqdq) is in the architecture model but not in the Atom model (Bonnell has no AVX).config.selftest = False.Tests (commit 2)
tests/naive/x86_64/test_instruction_model.py: parsing and write-back of every instruction form, operand roles, size checks, symbolic registers, memory operands,push/popandrsp, memory hints, optimizing symbolic-input code with the selftest off, register-ID round trip, thexorfusion callback, branches, and importing the architecture without a target.tests/naive/x86_64/test_atom_model.py: unit assignments (memory-source forms, instructions that use every unit), model against nanoBench measurements, scheduling on the shared MEM unit, the opt-in memory constraint, the llvm-mca CPU name.tests/naive/x86_64/_test.py:instructions.s(every non-branch form, with selftest),instructions_subregisters.s,x86_64_equ.s, plus the two unit-test modules; registered intest.py.python3 -W error test.pypasses on top ofmain, andexample.py --dry-run --only-target=slothy.targets.x86_64.intel_atompasses.Generated code (commit 3)
examples/naive/x86_64/simple/x86_64_simple.s→examples/opt/x86_64/simple/x86_64_simple_opt_atom.s, covering this PR's changes:.equregister aliases (%), memory forms,push/pop(implicitrsp),xchg(every unit) and memory-sourcepxor(FP0+MEM); the selftest runsreads=/writes=memory hints (the selftest is skipped, following other architectures' examples)xor-with-memory fusion callback, then the opt-in memory constraint (memory_offset_constraint)Commits
Co-authored by Hayden Parsons (@h2parson) and Maggie Simmons.