@@ -1431,6 +1431,10 @@ def gen_monolithic_source_file(dry_run=False):
14311431 for c in filter (native_arith_x86_64 , c_sources ):
14321432 yield f'#include "{ c } "'
14331433 yield "#endif"
1434+ yield "#if defined(MLK_SYS_PPC64LE)"
1435+ for c in filter (native_arith_ppc64le , c_sources ):
1436+ yield f'#include "{ c } "'
1437+ yield "#endif"
14341438 yield "#endif"
14351439 yield ""
14361440 yield "#if defined(MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202)"
@@ -1766,6 +1770,10 @@ def update_via_simpasm(
17661770 source_arch = "aarch64"
17671771 elif "x86_64" in infile_full :
17681772 source_arch = "x86_64"
1773+ elif "ppc64le" in infile_full :
1774+ source_arch = "ppc64le"
1775+ elif "riscv64" in infile_full :
1776+ source_arch = "riscv64"
17691777 else :
17701778 raise Exception (f"Could not detect architecture of source file { infile_full } ." )
17711779 # Check native architecture
@@ -1775,7 +1783,14 @@ def update_via_simpasm(
17751783 native_arch = "x86_64"
17761784
17771785 if native_arch != source_arch :
1778- cross_prefix = f"{ source_arch } -unknown-linux-gnu-"
1786+ arch_to_cross_prefix = {
1787+ "aarch64" : "aarch64-unknown-linux-gnu-" ,
1788+ "x86_64" : "x86_64-unknown-linux-gnu-" ,
1789+ "ppc64le" : "powerpc64le-unknown-linux-gnu-" ,
1790+ "riscv64" : "riscv64-unknown-linux-gnu-" ,
1791+ }
1792+
1793+ cross_prefix = arch_to_cross_prefix [source_arch ]
17791794 cross_gcc = cross_prefix + "gcc"
17801795 # Check if cross-compiler is present
17811796 if shutil .which (cross_gcc ) is None :
@@ -1788,13 +1803,12 @@ def update_via_simpasm(
17881803 with tempfile .NamedTemporaryFile (suffix = ".S" ) as tmp :
17891804 try :
17901805 # Determine architecture from filename
1791- arch = "aarch64" if "aarch64" in infile_full else "x86_64"
17921806
17931807 cmd = [
17941808 "./scripts/simpasm" ,
17951809 "--objdump=llvm-objdump" ,
17961810 "--cfify" ,
1797- "--arch=" + arch ,
1811+ "--arch=" + source_arch ,
17981812 "-i" ,
17991813 infile_full ,
18001814 "-o" ,
@@ -2058,49 +2072,55 @@ def synchronize_backends(
20582072 ),
20592073 )
20602074
2061- synchronize_backend (
2062- f"dev/aarch64_{ ty } /src" ,
2063- "mlkem/src/native/aarch64/src" ,
2064- dry_run = dry_run ,
2065- delete = delete ,
2066- force_cross = force_cross ,
2067- no_simplify = no_simplify ,
2068- cflags = "-Imlkem/src/native/aarch64/src" ,
2069- )
2070- synchronize_backend (
2071- "dev/fips202/aarch64/src" ,
2072- "mlkem/src/fips202/native/aarch64/src" ,
2073- dry_run = dry_run ,
2074- delete = delete ,
2075- force_cross = force_cross ,
2076- no_simplify = no_simplify ,
2077- cflags = "-Imlkem/src/fips202/native/aarch64/src -march=armv8.4-a+sha3" ,
2078- )
2079- synchronize_backend (
2080- "dev/fips202/aarch64" ,
2081- "mlkem/src/fips202/native/aarch64" ,
2082- dry_run = dry_run ,
2083- delete = delete ,
2084- force_cross = force_cross ,
2085- no_simplify = no_simplify ,
2086- cflags = "-Imlkem/src/fips202/native/aarch64 -march=armv8.4-a+sha3" ,
2087- )
2088- synchronize_backend (
2089- "dev/x86_64/src" ,
2090- "mlkem/src/native/x86_64/src" ,
2091- dry_run = dry_run ,
2092- delete = delete ,
2093- force_cross = force_cross ,
2094- no_simplify = no_simplify ,
2095- # Turn off control-flow protection (CET) explicitly. Newer versions of
2096- # clang turn it on by default and insert endbr64 instructions at every
2097- # global symbol.
2098- # We insert endbr64 instruction manually via the MLK_ASM_FN_SYMBOL
2099- # macro.
2100- # This leads to duplicate endbr64 instructions causing a failure when
2101- # comparing the object code before and after simplification.
2102- cflags = "-Imlkem/src/native/x86_64/src/ -mavx2 -mbmi2 -msse4 -fcf-protection=none" ,
2103- )
2075+ # Triples of
2076+ # - input backend directory under dev/
2077+ # - output backend directory under mlkem/
2078+ # - cflags
2079+ worklist = [
2080+ (
2081+ f"dev/aarch64_{ ty } /src" ,
2082+ "mlkem/src/native/aarch64/src" ,
2083+ "-Imlkem/src/native/aarch64/src" ,
2084+ ),
2085+ (
2086+ "dev/fips202/aarch64/src" ,
2087+ "mlkem/src/fips202/native/aarch64/src" ,
2088+ "-Imlkem/src/fips202/native/aarch64/src -march=armv8.4-a+sha3" ,
2089+ ),
2090+ (
2091+ "dev/fips202/aarch64" ,
2092+ "mlkem/src/fips202/native/aarch64" ,
2093+ "-Imlkem/src/fips202/native/aarch64 -march=armv8.4-a+sha3" ,
2094+ ),
2095+ (
2096+ "dev/x86_64/src" ,
2097+ "mlkem/src/native/x86_64/src" ,
2098+ # Turn off control-flow protection (CET) explicitly. Newer versions of
2099+ # clang turn it on by default and insert endbr64 instructions at every
2100+ # global symbol.
2101+ # We insert endbr64 instruction manually via the MLK_ASM_FN_SYMBOL
2102+ # macro.
2103+ # This leads to duplicate endbr64 instructions causing a failure when
2104+ # comparing the object code before and after simplification.
2105+ "-Imlkem/src/native/x86_64/src/ -mavx2 -mbmi2 -msse4 -fcf-protection=none" ,
2106+ ),
2107+ (
2108+ "dev/ppc64le/src" ,
2109+ "mlkem/src/native/ppc64le/src" ,
2110+ "-Imlkem/src/native/ppc64le/src -mvsx" ,
2111+ ),
2112+ ]
2113+
2114+ for in_dir , out_dir , cflags in worklist :
2115+ synchronize_backend (
2116+ in_dir ,
2117+ out_dir ,
2118+ dry_run = dry_run ,
2119+ delete = delete ,
2120+ force_cross = force_cross ,
2121+ no_simplify = no_simplify ,
2122+ cflags = cflags ,
2123+ )
21042124
21052125
21062126def adjust_header_guard_for_filename (content , header_file ):
0 commit comments