Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test_basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- slothy.targets.aarch64.apple_m1_icestorm_experimental
- slothy.targets.aarch64.aarch64_big_experimental
- slothy.targets.riscv.xuantie_c908
- slothy.targets.x86_64.intel_atom
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-ubuntu
Expand All @@ -41,6 +42,7 @@ jobs:
- slothy.targets.aarch64.apple_m1_icestorm_experimental
- slothy.targets.aarch64.aarch64_big_experimental
- slothy.targets.riscv.xuantie_c908
- slothy.targets.x86_64.intel_atom
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-ubuntu
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ SLOTHY is generic in the target architecture and microarchitecture. This reposit
- Armv8.1-M+Helium: Cortex-M55, Cortex-M85
- AArch64: Cortex-A55, and experimentally Cortex-A72, Cortex-X/Neoverse-V, Apple M1 (Firestorm, Icestorm)
- RISC-V (RV{32,64}IMB): XuanTie C908
- x86_64 (AT&T syntax, Intel syntax via a translator): experimentally Intel Atom (Bonnell)

SLOTHY is discussed in [Fast and Clean: Auditable high-performance assembly via constraint solving](https://eprint.iacr.org/2022/1303).

Expand Down
5 changes: 5 additions & 0 deletions common/OptimizationRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
import slothy.targets.riscv.riscv as RISCV
import slothy.targets.riscv.xuantie_c908 as Target_XuanTieC908

import slothy.targets.x86_64.x86_64 as X86_64
import slothy.targets.x86_64.intel_atom as Target_IntelAtom

target_label_dict = {
Target_CortexA55: "a55",
Target_CortexA72: "a72",
Expand All @@ -59,13 +62,15 @@
Target_AppleM1_icestorm: "m1_icestorm",
Target_AArch64Big: "aarch64_big",
Target_XuanTieC908: "c908",
Target_IntelAtom: "atom",
}

arch_label_dict = {
Arch_Armv7M: "armv7m",
Arch_Armv81M: "armv8m",
AArch64_Neon: "aarch64",
RISCV: "riscv",
X86_64: "x86_64",
}


Expand Down
5 changes: 3 additions & 2 deletions docs/source/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ It is thus independent of and potentially combinable with superoptimizers operat

## Does SLOTHY support x86?

The core of SLOTHY is architecture- and microarchitecture-agnostic and can accommodate x86. As it stands, however,
there is no model of the x86 architecture. Feel free to build one!
Yes, partially. SLOTHY includes an x86_64 model (AT&T syntax natively, with Intel syntax via
`slothy.targets.x86_64.x86_translator`) covering the instructions needed for Keccak, and a uArch model for
Intel Atom (Bonnell). Loop optimization on x86_64 is not yet safe, because flag writes are only partially modelled.

## Does SLOTHY support RISC-V?

Expand Down
1 change: 1 addition & 0 deletions docs/source/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ SLOTHY is generic in the target architecture and microarchitecture. This reposit
- Armv8.1-M+Helium: Cortex-M55, Cortex-M85
- AArch64: Cortex-A55, and experimentally Cortex-A72, Cortex-X/Neoverse-V, Apple M1 (Firestorm, Icestorm)
- RISC-V (RV{32,64}IMB): XuanTie C908
- x86_64 (AT&T syntax, Intel syntax via a translator): experimentally Intel Atom (Bonnell)

SLOTHY is discussed in [Fast and Clean: Auditable high-performance assembly via constraint solving](https://eprint.iacr.org/2022/1303).

Expand Down
13 changes: 13 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

import slothy.targets.riscv.xuantie_c908 as Target_C908

import slothy.targets.x86_64.intel_atom as Target_IntelAtom

##########################################################################################

from examples.naive.aarch64.dilithium._example import (
Expand Down Expand Up @@ -105,6 +107,14 @@
example_instances as example_instances_riscv_keccak,
)

from examples.naive.x86_64.simple._example import (
example_instances as example_instances_x86_64_simple,
)

from examples.naive.x86_64.intel._example import (
example_instances as example_instances_x86_64_intel,
)


def main():
examples = (
Expand All @@ -126,6 +136,8 @@ def main():
+ example_instances_riscv_ntt_kyber
+ example_instances_riscv_kyber_basemul
+ example_instances_riscv_keccak
+ example_instances_x86_64_simple
+ example_instances_x86_64_intel
)

all_example_names = [e.name for e in examples]
Expand Down Expand Up @@ -163,6 +175,7 @@ def main():
Target_AppleM1_icestorm.__name__,
Target_AArch64Big.__name__,
Target_C908.__name__,
Target_IntelAtom.__name__,
],
)
args = parser.parse_args()
Expand Down
57 changes: 57 additions & 0 deletions examples/naive/x86_64/intel/_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#
# Copyright (c) 2026 Maggie Simmons
# Copyright (c) 2026 Hayden Parsons
# SPDX-License-Identifier: MIT
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#

import os

from common.OptimizationRunner import OptimizationRunner
import slothy.targets.x86_64.x86_64 as Arch_X86_64
import slothy.targets.x86_64.intel_atom as Target_IntelAtom
from slothy.targets.x86_64.x86_translator import Intel_Code

SUBFOLDER = os.path.basename(os.path.dirname(__file__)) + "/"


class X86_64SimpleIntel(OptimizationRunner):
def __init__(self, var="", arch=Arch_X86_64, target=Target_IntelAtom, timeout=None):
name = "x86_64_simple_intel"
super().__init__(
name,
name,
subfolder=SUBFOLDER,
arch=arch,
target=target,
timeout=timeout,
var=var,
)

def core(self, slothy):
slothy.config.syntax = Intel_Code
slothy.config.variable_size = True
slothy.config.outputs = ["rcx", "r9"]
slothy.optimize(start="start", end="end")


example_instances = [
X86_64SimpleIntel(),
]
17 changes: 17 additions & 0 deletions examples/naive/x86_64/intel/x86_64_simple_intel.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Two independent load/xor/rotate/store chains in Intel syntax
// (config.syntax = Intel_Code); the output stays in Intel syntax.
start:
mov rax, qword ptr [rdi+0]
mov rbx, qword ptr [rdi+8]
xor rax, rbx
rol rax, 1
xor rcx, rax
mov qword ptr [rsi+0], rcx

mov rdx, qword ptr [rdi+16]
mov r8, qword ptr [rdi+24]
xor rdx, r8
rol rdx, 1
xor r9, rdx
mov qword ptr [rsi+8], r9
end:
74 changes: 74 additions & 0 deletions examples/naive/x86_64/simple/_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#
# Copyright (c) 2026 Maggie Simmons
# Copyright (c) 2026 Hayden Parsons
# SPDX-License-Identifier: MIT
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#

import os

from common.OptimizationRunner import OptimizationRunner
import slothy.targets.x86_64.x86_64 as Arch_X86_64
import slothy.targets.x86_64.intel_atom as Target_IntelAtom

SUBFOLDER = os.path.basename(os.path.dirname(__file__)) + "/"


class X86_64Simple(OptimizationRunner):
def __init__(self, var="", arch=Arch_X86_64, target=Target_IntelAtom, timeout=None):
name = "x86_64_simple"
super().__init__(
name,
name,
subfolder=SUBFOLDER,
arch=arch,
target=target,
timeout=timeout,
var=var,
)

def core(self, slothy):
slothy.config.variable_size = True
# Keep input registers (e.g. the rdi/rsi pointers) intact
slothy.config.inputs_are_outputs = True

# Every non-branch instruction form; results end up in memory
slothy.optimize(start="start", end="end")

# 8/16/32-bit register forms
slothy.config.outputs = ["al", "bx", "ecx"]
slothy.optimize(start="start_subregisters", end="end_subregisters")
slothy.config.outputs = []

# Symbolic registers and memory hints (selftest is skipped for symbolic code)
slothy.optimize(start="start_symbolic", end="end_symbolic")

# Split xor-with-memory, then optimize with the opt-in memory constraint
slothy.fusion_region("start_fusion", "end_fusion", ssa=False)
Target_IntelAtom.memory_offset_constraint = True
try:
slothy.optimize(start="start_fusion", end="end_fusion")
finally:
Target_IntelAtom.memory_offset_constraint = False


example_instances = [
X86_64Simple(),
]
81 changes: 81 additions & 0 deletions examples/naive/x86_64/simple/x86_64_simple.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// x86_64 example for the Intel Atom (Bonnell) model, AT&T syntax.
//
// Four regions, optimized separately (see _example.py):
// start / end every non-branch instruction form (selftest runs)
// start_subregisters / ... 8/16/32-bit register forms
// start_symbolic / ... symbolic registers and memory hints
// start_fusion / ... xor-with-memory splitting + opt-in memory constraint
// Branches (jz/jnz) are not included: loop optimization on x86_64 is not yet safe.

// Register aliases (.equ values may contain %) and memory offsets
.equ rState, %rdi
.equ rOut, %rsi
.equ _a, 1*8
.equ _b, 2*8
.equ _c, 3*8
.equ _x, 4*8
.equ _y, 6*8

start:
mov (rState), %rbx // mov_from_mem
mov _a(rState), %rax // mov_from_mem_offset
mov $3, %rcx // mov_qi
movq $5, %rdx // movq_i
add $1, %rax // add_qi
add %rbx, %rax // add_qq
and %rcx, %rax // and_qq
or %rdx, %rbx // or_qq
xor $7, %rbx // xor_qi
xor %rax, %rbx // xor_qq
not %rcx // not_q
rol $3, %rcx // rol_qi
rol %rdx // rol1
shr $2, %rdx // shr_qi
sub $4, %rdx // sub_qi
xchg %rcx, %rdx // xchg_q: microcoded, uses every unit
mov %rcx, %r8 // mov_qq
movq %rdx, %r9 // movq
xor _b(rState), %r8 // xor_from_mem_offset: ALU0 + MEM
push %r9 // push: implicit rsp, uses every unit
pop %r10 // pop
mov %rax, (rOut) // mov_to_mem
mov %rbx, _a(rOut) // mov_to_mem_offset
xor %r8, _b(rOut) // xor_to_mem_offset
mov %r10, _c(rOut)
movdqu _x(rState), %xmm0 // movdqu_x_from_mem_offset
pxor _y(rState), %xmm0 // pxor_x_from_mem_offset: FP0 + MEM
pxor %xmm1, %xmm0 // pxor_xx
movdqu %xmm0, _x(rOut) // movdqu_x_to_mem_offset
end:

// Sub-register forms on their own: overlap between e.g. al and rax is not modelled
start_subregisters:
add $1, %al // add_hi
add $1, %bx // add_si
add $1, %ecx // add_di
add %dl, %al // add_hh
add %si, %bx // add_ss
add %edi, %ecx // add_dd
end_subregisters:

// Symbolic registers (allocated by SLOTHY) and a memory dependency declared by tags
start_symbolic:
mov _a(rState), %QW<x>
mov _b(rState), %QW<y>
xor %QW<y>, %QW<x>
rol $1, %QW<x>
mov %QW<x>, _a(rOut) // @slothy:writes=out
mov _a(rOut), %QW<z> // @slothy:reads=out
add %QW<z>, %QW<x>
mov %QW<x>, _b(rOut)
end_symbolic:

// xor with a memory operand is split into a load and a register xor (fusion), then
// optimized with the opt-in Bonnell constraint: the load from _a(rState) and the
// store to _a(rOut) (same offset, different base register) stay 8 cycles apart
start_fusion:
xor _a(rState), %rax
xor _b(rState), %rbx
mov %rax, _a(rOut)
mov %rbx, _b(rOut)
end_fusion:
47 changes: 47 additions & 0 deletions examples/opt/x86_64/intel/x86_64_simple_intel_opt_atom.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Two independent load/xor/rotate/store chains in Intel syntax
// (config.syntax = Intel_Code); the output stays in Intel syntax.
start:
// Instructions: 12
// Expected cycles: 8
// Expected IPC: 1.50
//
// Cycle bound: 8.0
// IPC bound: 1.50
//
// Wall time: 0.02s
// User time: 0.02s
//
// ----- cycle (expected) ------>
// 0 25
// |------------------------|----
mov r14, qword ptr [rdi+0]// *.............................
mov r10, qword ptr [rdi+8]// .*............................
xor r14, r10 // ..*...........................
mov r13, qword ptr [rdi+16]// ..*...........................
mov r10, qword ptr [rdi+24]// ...*..........................
rol r14, 1 // ....*.........................
xor r13, r10 // ....*.........................
xor rcx, r14 // .....*........................
rol r13, 1 // .....*........................
mov qword ptr [rsi+0], rcx// ......*.......................
xor r9, r13 // ......*.......................
mov qword ptr [rsi+8], r9 // .......*......................

// ------ cycle (expected) ------>
// 0 25
// |------------------------|-----
// mov 0(%rdi), %rax // *..............................
// mov 8(%rdi), %rbx // .*.............................
// xor %rbx, %rax // ..*............................
// rol $1, %rax // ....*..........................
// xor %rax, %rcx // .....*.........................
// mov %rcx, 0(%rsi) // ......*........................
// mov 16(%rdi), %rdx // ..*............................
// mov 24(%rdi), %r8 // ...*...........................
// xor %r8, %rdx // ....*..........................
// rol $1, %rdx // .....*.........................
// xor %rdx, %r9 // ......*........................
// mov %r9, 8(%rsi) // .......*.......................

end:

Loading
Loading