Skip to content

Commit e111144

Browse files
committed
Port: use consistent architecture identifier
This commit ports the change from pq-code-package/mlkem-native#1456 to mldsa-native. Currently, mldsa-native already uses x86_64 as the architecture identifier for x86 in its existing HOL-Light proofs, and no changes are required in that regard. This commit simply aligns the surrounding scripts and infrastructure to consistently use x86_64 as the architecture name. - Adds the related scripts to support dual architectures by introducing an explicit arch parameter in the autogen process. - Replaces the arm_or_x86 flag with a unified arch flag in test scripts. Signed-off-by: willieyz <[email protected]>
1 parent f87d623 commit e111144

File tree

2 files changed

+44
-22
lines changed

2 files changed

+44
-22
lines changed

scripts/autogen

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ montgomery_factor = pow(2, 32, modulus)
2727
_RE_DEFINED = re.compile(r"defined\(([^)]+)\)")
2828
_RE_MARKDOWN_CITE = re.compile(r"\[\^(?P<id>\w+)\]")
2929
_RE_C_CITE = re.compile(r"@\[(?P<id>\w+)")
30-
_RE_BYTECODE_START = re.compile(r"=== bytecode start: mldsa/([^/\s]+?)\.o")
30+
_RE_BYTECODE_START = re.compile(
31+
r"=== bytecode start: (?:aarch64|x86_64)/mldsa/([^/\s]+?)\.o"
32+
)
3133
_RE_FUNC_SYMBOL = re.compile(r"MLD_ASM_FN_SYMBOL\((.*)\)")
3234
_RE_MACRO_CHECK = re.compile(r"[^_]((?:MLD_|MLDSA_)\w+)(.*)$", re.M)
3335
_RE_DEFINE = re.compile(r"^\s*#define\s+(\w+)")
@@ -2121,28 +2123,30 @@ def update_via_simpasm(
21212123

21222124

21232125
def gen_hol_light_asm_file(job):
2124-
infile, outfile, indir, cflags = job
2126+
infile, outfile, indir, cflags, arch = job
21252127
update_via_simpasm(
21262128
f"{indir}/{infile}",
2127-
"proofs/hol_light/x86_64/mldsa",
2129+
"proofs/hol_light/" + arch + "/mldsa",
21282130
outfile=outfile,
21292131
cflags=cflags,
21302132
preserve_header=False,
21312133
)
21322134

21332135

21342136
def gen_hol_light_asm():
2135-
joblist = [
2137+
x86_64_flags = "-mavx2 -mbmi2 -msse4 -fcf-protection=full"
2138+
joblist_x86_64 = [
21362139
(
21372140
"ntt.S",
21382141
"mldsa_ntt.S",
21392142
"dev/x86_64/src",
2140-
"-Imldsa/src/native/x86_64/src/ -mavx2 -mbmi2 -msse4 -fcf-protection=full",
2143+
f"-Imldsa/src/native/x86_64/src -Imldsa/src/common.h {x86_64_flags}",
2144+
"x86_64",
21412145
),
21422146
]
21432147

21442148
with ThreadPoolExecutor() as executor:
2145-
_ = list(executor.map(partial(gen_hol_light_asm_file), joblist))
2149+
_ = list(executor.map(partial(gen_hol_light_asm_file), joblist_x86_64))
21462150

21472151

21482152
def update_via_copy(infile_full, outfile_full, transform=None):
@@ -2911,16 +2915,30 @@ def update_bytecode_in_proof_script(filepath, bytecode):
29112915
update_file(filepath, updated_content)
29122916

29132917

2914-
def update_hol_light_bytecode():
2915-
"""Update HOL Light proof files with bytecode from make dump_bytecode."""
2918+
def update_hol_light_bytecode_for_arch(arch, force_cross=False):
29162919
status_update(
2917-
"HOL Light bytecode",
2918-
"Running make dump_bytecode ... (this may take a few minutes)",
2920+
f"HOL Light bytecode ({arch})",
2921+
f"Running make dump_bytecode ({arch})... (this may take a few minutes)",
29192922
)
29202923

2924+
source_arch = arch
2925+
if platform.machine().lower() in ["arm64", "aarch64"]:
2926+
native_arch = "aarch64"
2927+
else:
2928+
native_arch = "x86_64"
2929+
2930+
if native_arch != source_arch:
2931+
cross_prefix = f"{source_arch}-unknown-linux-gnu-"
2932+
cross_gcc = cross_prefix + "gcc"
2933+
# Check if cross-compiler is present
2934+
if shutil.which(cross_gcc) is None:
2935+
if force_cross is False:
2936+
return
2937+
raise Exception(f"Could not find cross toolchain {cross_prefix}")
2938+
29212939
# Run make to get bytecode output
29222940
result = subprocess.run(
2923-
["make", "-C", "proofs/hol_light/x86_64", "dump_bytecode"],
2941+
["make", "-C", "proofs/hol_light/" + arch, "dump_bytecode"],
29242942
capture_output=True,
29252943
text=True,
29262944
check=True,
@@ -2932,10 +2950,14 @@ def update_hol_light_bytecode():
29322950

29332951
# Update each .ml file
29342952
for obj_name, bytecode in bytecode_dict.items():
2935-
ml_file = "proofs/hol_light/x86_64/proofs/" + obj_name + ".ml"
2953+
ml_file = "proofs/hol_light/" + arch + "/proofs/" + obj_name + ".ml"
29362954
update_bytecode_in_proof_script(ml_file, bytecode)
29372955

29382956

2957+
def update_hol_light_bytecode(force_cross=False):
2958+
"""Update HOL Light proof files with bytecode from make dump_bytecode."""
2959+
update_hol_light_bytecode_for_arch("x86_64", force_cross=force_cross)
2960+
29392961
def gen_test_config(config_path, config_spec, default_config_content):
29402962
"""Generate a config file by modifying the default config."""
29412963
status_update("test configs", config_path)

scripts/tests

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,33 +1000,33 @@ class Tests:
10001000

10011001
if platform.machine().lower() in ["arm64", "aarch64"]:
10021002
# TODO: Skip HOL-Light proofs on arm64/aarch64 until the first proof is added
1003-
# arm_or_x86 = "arm"
1003+
# arch = "aarch64"
10041004
return
10051005
elif platform.machine().lower() in ["x86_64"]:
1006-
arm_or_x86 = "x86_64"
1006+
arch = "x86_64"
10071007
else:
10081008
return
10091009

1010-
def list_proofs(arm_or_x86):
1011-
cmd_str = ["./proofs/hol_light/" + arm_or_x86 + "/list_proofs.sh"]
1010+
def list_proofs(arch):
1011+
cmd_str = ["./proofs/hol_light/" + arch + "/list_proofs.sh"]
10121012
p = subprocess.run(cmd_str, capture_output=True, universal_newlines=False)
10131013
proofs = filter(lambda s: s.strip() != "", p.stdout.decode().split("\n"))
10141014
return list(proofs)
10151015

10161016
if self.args.list_functions:
1017-
for p in list_proofs(arm_or_x86):
1017+
for p in list_proofs(arch):
10181018
print(p)
10191019
exit(0)
10201020

1021-
def run_hol_light_single_step(proofs, arm_or_x86):
1021+
def run_hol_light_single_step(proofs, arch):
10221022
num_proofs = len(proofs)
10231023
for i, func in enumerate(proofs):
10241024
log = logger(f"HOL_LIGHT ({i+1}/{num_proofs})", None, None, None)
10251025
log.info(f"Starting HOL-Light proof for {func}")
10261026
start = time.time()
10271027
proof_bin = f"mldsa/{func}.native"
10281028
proof_target = f"mldsa/{func}.correct"
1029-
proof_dir = "proofs/hol_light/" + arm_or_x86
1029+
proof_dir = "proofs/hol_light/" + arch
10301030
# Remove intermediate proof files to force-rerun
10311031
try:
10321032
os.remove(os.path.join(proof_dir, proof_bin))
@@ -1039,7 +1039,7 @@ class Tests:
10391039
f"mldsa/{func}.correct",
10401040
]
10411041
+ self.make_j(),
1042-
cwd="proofs/hol_light/" + arm_or_x86,
1042+
cwd="proofs/hol_light/" + arch,
10431043
env=os.environ.copy(),
10441044
capture_output=(self.args.verbose is False),
10451045
)
@@ -1054,11 +1054,11 @@ class Tests:
10541054
else:
10551055
log.info(f" SUCCESS (after {dur}s)")
10561056

1057-
proofs = list_proofs(arm_or_x86)
1057+
proofs = list_proofs(arch)
10581058
if self.args.proof is not None:
10591059
proofs = self.args.proof
10601060

1061-
run_hol_light_single_step(proofs, arm_or_x86)
1061+
run_hol_light_single_step(proofs, arch)
10621062
self.check_fail()
10631063

10641064

0 commit comments

Comments
 (0)