Skip to content

x86_64 Intel/AT&T syntax translator - #475

Open
magistras42 wants to merge 6 commits into
slothy-optimizer:mainfrom
h2parson:x86_pr2
Open

magistras42 wants to merge 6 commits into
slothy-optimizer:mainfrom
h2parson:x86_pr2

Conversation

@magistras42

Copy link
Copy Markdown

PR 2 of 3, depending on #474.

SLOTHY's x86_64 model is natively AT&T. This PR lets users write Intel-syntax code (or AT&T with size suffixes such as movq) and get the result back in the same syntax.

Usage

from slothy.targets.x86_64.x86_translator import Intel_Code, Atat_Code
slothy = Slothy(arch, target, syntax=Intel_Code)   # Intel in, Intel out
slothy = Slothy(arch, target, syntax=Atat_Code)    # AT&T, size suffixes normalized
slothy = Slothy(arch, target, syntax=x86_translator)  # auto-detect, AT&T out

syntax=None (the default) means the input is already in the architecture's native syntax.

Changes

  • slothy/targets/x86_64/x86_translator.py: parses Intel or AT&T instructions (immediates, registers, labels, memory operands with base/index/scale/displacement) and converts between them. Code.to_native() / from_native() translate lists of SourceLines, keeping indentation, comments and tags; blank lines, labels and directives pass through. Memory operand sizes in Intel output come from the register operand (xmmword, dword, ...).
  • slothy/core/config.py: documented, validated syntax property. Any object with to_native(source) / from_native(source) works, so this isn't x86-specific. Config.copy() leaves syntax out of the deep copy, like arch/target.
  • README.md, docs/source/general.md, docs/source/faq.md: mention Intel syntax via the translator.
  • slothy/core/slothy.py: Slothy(..., syntax=...). optimize, optimize_loop, fusion_region, fusion_loop, get_input_from_output and get_loop_input_output translate to native syntax after macro/alias unfolding and translate results back, so the selftest and llvm-mca see native code and Intel input gives Intel output.

Limitations

  • Immediate-to-memory instructions lose their size (mov qword ptr [rdi], 1 → mov $1, (%rdi), which needs a q suffix); the model has no such instructions yet.
  • Intel input must be lowercase to match the model's patterns.

Tests (commit 2)

  • tests/naive/x86_64/test_translator.py: per-form translation in both directions (assembled with llvm-mc when available), 8 known-good pairs (tests/naive/x86_64/translator/, from our nanoBench benchmarking of Keccak rounds), invalid AT&T operands, syntax detection, metadata preservation, config.syntax validation, Intel-syntax optimization end to end, and the auto-detect module.
  • tests/naive/x86_64/x86_64_intel.s OptimizationRunner test (Intel syntax, incl. XMM memory operands).

Generated code (commit 3)

  • examples/naive/x86_64/intel/x86_64_simple_intel.s → examples/opt/x86_64/intel/x86_64_simple_intel_opt_atom.s

Note for rebasing: config.py gets this PR's syntax property next to main's solver_search_strategy; both are kept.

Commits

  1. x86_64: add Intel/AT&T syntax translator
  2. x86_64: add translator tests
  3. x86_64: add Intel-syntax example and generated code

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

magistras42 and others added 6 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>

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