Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Keccak #65

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
167 changes: 156 additions & 11 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Example():

def __init__(self, infile, name=None, funcname=None, suffix="opt",
rename=False, outfile="", arch=Arch_Armv81M, target=Target_CortexM55r1,
timeout=None, **kwargs):
timeout=None, outfile_full=False, **kwargs):
if name is None:
name = infile

Expand All @@ -67,17 +67,23 @@ def __init__(self, infile, name=None, funcname=None, suffix="opt",
self.funcname = funcname
self.infile = infile
self.suffix = suffix
if outfile == "":
self.outfile = f"{infile}_{self.suffix}_{target_label_dict[self.target]}"
if outfile_full is True:
self.outfile = outfile
else:
self.outfile = f"{outfile}_{self.suffix}_{target_label_dict[self.target]}"
if outfile == "":
self.outfile = f"{infile}_{self.suffix}_{target_label_dict[self.target]}"
else:
self.outfile = f"{outfile}_{self.suffix}_{target_label_dict[self.target]}"
if funcname is None:
self.funcname = self.infile
subfolder = ""
if self.arch == AArch64_Neon:
subfolder = "aarch64/"
self.infile_full = f"examples/naive/{subfolder}{self.infile}.s"
self.outfile_full = f"examples/opt/{subfolder}{self.outfile}.s"
if outfile_full is False:
self.outfile_full = f"examples/opt/{subfolder}{self.outfile}.s"
else:
self.outfile_full = self.outfile
self.name = name
self.rename = rename
self.timeout = timeout
Expand Down Expand Up @@ -155,9 +161,12 @@ def run(self, debug=False, log_model=False, log_model_dir="models", dry_run=Fals

self.core(slothy, *self.extra_args)

if self.rename:
slothy.rename_function(
self.funcname, f"{self.funcname}_{self.suffix}_{target_label_dict[self.target]}")
if self.rename is not False:
if self.rename is True:
slothy.rename_function(
self.funcname, f"{self.funcname}_{self.suffix}_{target_label_dict[self.target]}")
elif isinstance(self.rename, str):
slothy.rename_function(self.funcname, self.rename)

if dry_run is False:
slothy.write_source_to_file(self.outfile_full)
Expand Down Expand Up @@ -1088,7 +1097,7 @@ def core(self, slothy):
slothy.config.constraints.stalls_first_attempt = 110
slothy.optimize_loop("layer123_start")




class ntt_dilithium_123(Example):
Expand Down Expand Up @@ -1211,7 +1220,7 @@ def core(self, slothy):
slothy.optimize_loop("layer5678_start")

slothy.config = conf.copy()

if self.timeout is not None:
slothy.config.timeout = self.timeout // 12

Expand All @@ -1228,7 +1237,7 @@ def core(self, slothy):
slothy.config.split_heuristic_stepsize = 0.1
slothy.config.constraints.stalls_first_attempt = 14
slothy.optimize_loop("layer1234_start")


class ntt_dilithium_1234(Example):
def __init__(self, var="", arch=AArch64_Neon, target=Target_CortexA72):
Expand Down Expand Up @@ -1355,6 +1364,133 @@ def core(self, slothy):
slothy.config.sw_pipelining.optimize_postamble = False
slothy.optimize_loop("flt_radix4_fft_loop_start")

class neon_keccak_x1_no_symbolic(Example):
def __init__(self, var="", arch=AArch64_Neon, target=Target_CortexA55):
name = "keccak_f1600_x1_scalar_slothy_no_symbolic"
infile = "keccak_f1600_x1_scalar_slothy"
outfile = "keccak_f1600_x1_scalar_no_symbolic"

super().__init__(infile, name, outfile=outfile, rename=True, arch=arch, target=target)

def core(self, slothy):
slothy.config.reserved_regs = ["x18", "sp"]

slothy.config.inputs_are_outputs = True
slothy.config.variable_size = True
slothy.config.visualize_expected_performance = False
slothy.config.timeout = 10800

slothy.config.selfcheck_failure_logfile = "selfcheck_fail.log"

slothy.config.outputs = ["flags"]
slothy.config.constraints.stalls_first_attempt = 64
slothy.config.constraints.minimize_spills = True
slothy.config.constraints.allow_reordering = True
slothy.config.constraints.allow_spills = True
slothy.config.constraints.minimize_spills = True
slothy.config.visualize_expected_performance = True
slothy.optimize(start="loop", end="end_loop")

slothy.config.outputs = ["hint_STACK_OFFSET_COUNT"]
slothy.optimize(start="initial_round_start", end="initial_round_end")

class neon_keccak_x1_scalar_opt(Example):
def __init__(self, var="", arch=AArch64_Neon, target=Target_CortexA55):
name = "keccak_f1600_x1_scalar_opt"
infile = "keccak_f1600_x1_scalar_pre_opt"
outfile = "keccak_f1600_x1_scalar"

super().__init__(infile, name, outfile=outfile, rename=True, arch=arch, target=target)

def core(self, slothy):
slothy.config.reserved_regs = ["x18", "sp"]

slothy.config.inputs_are_outputs = True
slothy.config.variable_size = True
slothy.config.timeout = 10800

slothy.config.selfcheck_failure_logfile = "selfcheck_fail.log"

slothy.config.outputs = ["flags"]
slothy.config.constraints.stalls_first_attempt = 32
slothy.config.visualize_expected_performance = True
slothy.config.split_heuristic = True
slothy.config.split_heuristic_factor = 1.5
slothy.config.split_heuristic_stepsize = 0.3
slothy.config.split_heuristic_repeat = 1
slothy.config.split_heuristic_optimize_seam = 5

slothy.optimize(start="loop", end="end_loop")

slothy.config.outputs = ["hint_STACK_OFFSET_COUNT"]
slothy.optimize(start="initial_round_start", end="initial_round_end")

class neon_keccak_x4_hybrid_no_symbolic(Example):
def __init__(self, var="v84a", arch=AArch64_Neon, target=Target_CortexA55):
name = f"keccak_f1600_x4_{var}_hybrid_slothy_no_symbolic"
infile = f"keccak_f1600_x4_{var}_hybrid_slothy_symbolic"
outfile = f"examples/naive/aarch64/keccak_f1600_x4_{var}_hybrid_slothy_clean.s"

super().__init__(infile, name, outfile=outfile, rename=f"keccak_f1600_x4_{var}_hybrid_no_symbolic", arch=arch, target=target)

def core(self, slothy):
slothy.config.reserved_regs = ["x18", "sp"]

slothy.config.inputs_are_outputs = True
slothy.config.variable_size = True
slothy.config.visualize_expected_performance = False
slothy.config.timeout = 10800

slothy.config.selfcheck_failure_logfile = "selfcheck_fail.log"

slothy.config.outputs = ["flags"]
slothy.config.constraints.stalls_first_attempt = 64
slothy.config.ignore_objective = True
slothy.config.constraints.functional_only = True
slothy.config.constraints.allow_reordering = False
slothy.config.constraints.allow_spills = True
slothy.config.visualize_expected_performance = True

slothy.optimize(start="loop", end="loop_end")
slothy.config.outputs = ["hint_STACK_OFFSET_COUNT"]
slothy.optimize(start="initial", end="loop")

class neon_keccak_x4_hybrid_interleave(Example):
def __init__(self, var="v84a", arch=AArch64_Neon, target=Target_CortexA55):
name = f"keccak_f1600_x4_{var}_hybrid_slothy_interleave"
infile = f"keccak_f1600_x4_{var}_hybrid_slothy_clean"
outfile = f"examples/naive/aarch64/keccak_f1600_x4_{var}_hybrid_slothy_interleaved.s"

super().__init__(infile, name, outfile=outfile, rename=f"keccak_f1600_x4_{var}_hybrid_slothy_interleaved",
arch=arch, target=target, outfile_full=True)

def core(self, slothy):
slothy.config.reserved_regs = ["x18", "sp"]

slothy.config.inputs_are_outputs = True
slothy.config.variable_size = True
slothy.config.visualize_expected_performance = False
slothy.config.timeout = 10800

slothy.config.selfcheck_failure_logfile = "selfcheck_fail.log"

slothy.config.outputs = ["flags", "hint_STACK_OFFSET_COUNT"]
slothy.config.constraints.stalls_first_attempt = 64
slothy.config.ignore_objective = True
slothy.config.constraints.functional_only = True
slothy.config.constraints.allow_reordering = False
slothy.config.constraints.allow_spills = True
slothy.config.visualize_expected_performance = True

slothy.config.split_heuristic = True
slothy.config.split_heuristic_repeat = 0
slothy.config.split_heuristic_preprocess_naive_interleaving = True
slothy.config.split_heuristic_preprocess_naive_interleaving_strategy = "alternate"
slothy.config.split_heuristic_estimate_performance = False
slothy.config.absorb_spills = False

slothy.optimize(start="loop", end="loop_end")

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


Expand Down Expand Up @@ -1497,6 +1633,15 @@ def main():
fft_floatingpoint_radix4(),
# Fixed point
fft_fixedpoint_radix4(),
# Keccak
neon_keccak_x1_no_symbolic(),
neon_keccak_x1_scalar_opt(),
neon_keccak_x4_hybrid_no_symbolic(var="v84a"),
neon_keccak_x4_hybrid_interleave(var="v84a"),
neon_keccak_x4_hybrid_no_symbolic(var="v8a"),
neon_keccak_x4_hybrid_interleave(var="v8a"),
neon_keccak_x4_hybrid_no_symbolic(var="v8a_v84a"),
neon_keccak_x4_hybrid_interleave(var="v8a_v84a"),
]

all_example_names = [e.name for e in examples]
Expand Down
Loading
Loading