Skip to content

Commit afdb0b5

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 052ee8d commit afdb0b5

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

scripts/autogen

Lines changed: 35 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+)")
@@ -2124,28 +2126,30 @@ def update_via_simpasm(
21242126

21252127

21262128
def gen_hol_light_asm_file(job):
2127-
infile, outfile, indir, cflags = job
2129+
infile, outfile, indir, cflags, arch = job
21282130
update_via_simpasm(
21292131
f"{indir}/{infile}",
2130-
"proofs/hol_light/x86_64/mldsa",
2132+
"proofs/hol_light/" + arch + "/mldsa",
21312133
outfile=outfile,
21322134
cflags=cflags,
21332135
preserve_header=False,
21342136
)
21352137

21362138

21372139
def gen_hol_light_asm():
2138-
joblist = [
2140+
x86_64_flags = "-mavx2 -mbmi2 -msse4 -fcf-protection=full"
2141+
joblist_x86_64 = [
21392142
(
21402143
"ntt.S",
21412144
"mldsa_ntt.S",
21422145
"dev/x86_64/src",
2143-
"-Imldsa/src/native/x86_64/src/ -mavx2 -mbmi2 -msse4 -fcf-protection=full",
2146+
f"-Imldsa/src/native/x86_64/src -Imldsa/src/common.h {x86_64_flags}",
2147+
"x86_64",
21442148
),
21452149
]
21462150

21472151
with ThreadPoolExecutor() as executor:
2148-
_ = list(executor.map(partial(gen_hol_light_asm_file), joblist))
2152+
_ = list(executor.map(partial(gen_hol_light_asm_file), joblist_x86_64))
21492153

21502154

21512155
def update_via_copy(infile_full, outfile_full, transform=None):
@@ -2914,16 +2918,30 @@ def update_bytecode_in_proof_script(filepath, bytecode):
29142918
update_file(filepath, updated_content)
29152919

29162920

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

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

29362954
# Update each .ml file
29372955
for obj_name, bytecode in bytecode_dict.items():
2938-
ml_file = "proofs/hol_light/x86_64/proofs/" + obj_name + ".ml"
2956+
ml_file = "proofs/hol_light/" + arch + "/proofs/" + obj_name + ".ml"
29392957
update_bytecode_in_proof_script(ml_file, bytecode)
29402958

29412959

2960+
def update_hol_light_bytecode(force_cross=False):
2961+
"""Update HOL Light proof files with bytecode from make dump_bytecode."""
2962+
update_hol_light_bytecode_for_arch("x86_64", force_cross=force_cross)
2963+
2964+
29422965
def gen_test_config(config_path, config_spec, default_config_content):
29432966
"""Generate a config file by modifying the default config."""
29442967
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)