diff --git a/dev/aarch64_clean/src/rej_uniform_asm.S b/dev/aarch64_clean/src/rej_uniform_asm.S index dadde25f3..e8c5b41a8 100644 --- a/dev/aarch64_clean/src/rej_uniform_asm.S +++ b/dev/aarch64_clean/src/rej_uniform_asm.S @@ -404,7 +404,10 @@ rej_uniform_return: .unreq mldsa_q .unreq bits -/* TODO: autogenerate this in autogen */ + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ #undef STACK_SIZE + /* simpasm: footer-start */ #endif /* MLD_ARITH_BACKEND_AARCH64 && !MLD_CONFIG_MULTILEVEL_NO_SHARED */ diff --git a/dev/aarch64_clean/src/rej_uniform_eta2_asm.S b/dev/aarch64_clean/src/rej_uniform_eta2_asm.S index 594d95810..fc64d132a 100644 --- a/dev/aarch64_clean/src/rej_uniform_eta2_asm.S +++ b/dev/aarch64_clean/src/rej_uniform_eta2_asm.S @@ -328,6 +328,9 @@ rej_uniform_eta2_final_copy: .unreq modulus5 .unreq barrett_tmp +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ #undef STACK_SIZE + /* simpasm: footer-start */ #endif /* MLD_ARITH_BACKEND_AARCH64 && !MLD_CONFIG_MULTILEVEL_NO_SHARED */ diff --git a/dev/aarch64_clean/src/rej_uniform_eta4_asm.S b/dev/aarch64_clean/src/rej_uniform_eta4_asm.S index 42e503d01..8be99835f 100644 --- a/dev/aarch64_clean/src/rej_uniform_eta4_asm.S +++ b/dev/aarch64_clean/src/rej_uniform_eta4_asm.S @@ -304,6 +304,9 @@ rej_uniform_eta4_final_copy: .unreq eta_bound .unreq bits +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ #undef STACK_SIZE + /* simpasm: footer-start */ #endif /* MLD_ARITH_BACKEND_AARCH64 && !MLD_CONFIG_MULTILEVEL_NO_SHARED */ diff --git a/dev/x86_64/src/consts.c b/dev/x86_64/src/consts.c index cd4bfde5a..3c7ba4d16 100644 --- a/dev/x86_64/src/consts.c +++ b/dev/x86_64/src/consts.c @@ -64,3 +64,18 @@ MLD_EMPTY_CU(avx2_consts) #endif /* !(MLD_ARITH_BACKEND_X86_64_DEFAULT && \ !MLD_CONFIG_MULTILEVEL_NO_SHARED) */ + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef MLD_AVX2_Q +#undef MLD_AVX2_QINV +#undef MLD_AVX2_MONT +#undef MLD_AVX2_DIV +#undef MLD_AVX2_DIV_QINV +/* Some macros are kept because they are also defined in a header. */ +/* Keep: MLD_AVX2_BACKEND_DATA_OFFSET_8XQ (consts.h) */ +/* Keep: MLD_AVX2_BACKEND_DATA_OFFSET_8XQINV (consts.h) */ +/* Keep: MLD_AVX2_BACKEND_DATA_OFFSET_8XDIV_QINV (consts.h) */ +/* Keep: MLD_AVX2_BACKEND_DATA_OFFSET_8XDIV (consts.h) */ +/* Keep: MLD_AVX2_BACKEND_DATA_OFFSET_ZETAS_QINV (consts.h) */ +/* Keep: MLD_AVX2_BACKEND_DATA_OFFSET_ZETAS (consts.h) */ diff --git a/dev/x86_64/src/poly_decompose_32_avx2.c b/dev/x86_64/src/poly_decompose_32_avx2.c index 58357b31c..b5ebb3762 100644 --- a/dev/x86_64/src/poly_decompose_32_avx2.c +++ b/dev/x86_64/src/poly_decompose_32_avx2.c @@ -150,3 +150,7 @@ MLD_EMPTY_CU(avx2_poly_decompose) #endif /* !(MLD_ARITH_BACKEND_X86_64_DEFAULT && \ !MLD_CONFIG_MULTILEVEL_NO_SHARED) */ + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef _mm256_blendv_epi32 diff --git a/dev/x86_64/src/poly_decompose_88_avx2.c b/dev/x86_64/src/poly_decompose_88_avx2.c index e572b5b22..f19e52b6b 100644 --- a/dev/x86_64/src/poly_decompose_88_avx2.c +++ b/dev/x86_64/src/poly_decompose_88_avx2.c @@ -150,3 +150,7 @@ MLD_EMPTY_CU(avx2_poly_decompose) #endif /* !(MLD_ARITH_BACKEND_X86_64_DEFAULT && \ !MLD_CONFIG_MULTILEVEL_NO_SHARED) */ + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef _mm256_blendv_epi32 diff --git a/dev/x86_64/src/poly_use_hint_32_avx2.c b/dev/x86_64/src/poly_use_hint_32_avx2.c index ebc3ccf04..1e6b7ec3a 100644 --- a/dev/x86_64/src/poly_use_hint_32_avx2.c +++ b/dev/x86_64/src/poly_use_hint_32_avx2.c @@ -95,3 +95,7 @@ MLD_EMPTY_CU(avx2_poly_use_hint) #endif /* !(MLD_ARITH_BACKEND_X86_64_DEFAULT && \ !MLD_CONFIG_MULTILEVEL_NO_SHARED) */ + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef _mm256_blendv_epi32 diff --git a/dev/x86_64/src/poly_use_hint_88_avx2.c b/dev/x86_64/src/poly_use_hint_88_avx2.c index 1e902f28b..37fcfbd4c 100644 --- a/dev/x86_64/src/poly_use_hint_88_avx2.c +++ b/dev/x86_64/src/poly_use_hint_88_avx2.c @@ -97,3 +97,7 @@ MLD_EMPTY_CU(avx2_poly_use_hint) #endif /* !(MLD_ARITH_BACKEND_X86_64_DEFAULT && \ !MLD_CONFIG_MULTILEVEL_NO_SHARED) */ + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef _mm256_blendv_epi32 diff --git a/dev/x86_64/src/rej_uniform_eta2_avx2.c b/dev/x86_64/src/rej_uniform_eta2_avx2.c index 532f92b7c..70c5c42c7 100644 --- a/dev/x86_64/src/rej_uniform_eta2_avx2.c +++ b/dev/x86_64/src/rej_uniform_eta2_avx2.c @@ -149,3 +149,7 @@ MLD_EMPTY_CU(avx2_rej_uniform_eta2) #endif /* !(MLD_ARITH_BACKEND_X86_64_DEFAULT && \ !MLD_CONFIG_MULTILEVEL_NO_SHARED) */ + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef MLD_AVX2_ETA2 diff --git a/dev/x86_64/src/rej_uniform_eta4_avx2.c b/dev/x86_64/src/rej_uniform_eta4_avx2.c index d382beca8..ba00e9125 100644 --- a/dev/x86_64/src/rej_uniform_eta4_avx2.c +++ b/dev/x86_64/src/rej_uniform_eta4_avx2.c @@ -133,3 +133,7 @@ MLD_EMPTY_CU(avx2_rej_uniform_eta4) #endif /* !(MLD_ARITH_BACKEND_X86_64_DEFAULT && \ !MLD_CONFIG_MULTILEVEL_NO_SHARED) */ + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef MLD_AVX2_ETA4 diff --git a/mldsa/src/fips202/fips202.c b/mldsa/src/fips202/fips202.c index ee7f83221..72b15ad36 100644 --- a/mldsa/src/fips202/fips202.c +++ b/mldsa/src/fips202/fips202.c @@ -264,3 +264,7 @@ void mld_shake256(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen) } #endif /* !MLD_CONFIG_MULTILEVEL_NO_SHARED */ + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef NROUNDS diff --git a/mldsa/src/native/x86_64/src/consts.c b/mldsa/src/native/x86_64/src/consts.c index cd4bfde5a..3c7ba4d16 100644 --- a/mldsa/src/native/x86_64/src/consts.c +++ b/mldsa/src/native/x86_64/src/consts.c @@ -64,3 +64,18 @@ MLD_EMPTY_CU(avx2_consts) #endif /* !(MLD_ARITH_BACKEND_X86_64_DEFAULT && \ !MLD_CONFIG_MULTILEVEL_NO_SHARED) */ + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef MLD_AVX2_Q +#undef MLD_AVX2_QINV +#undef MLD_AVX2_MONT +#undef MLD_AVX2_DIV +#undef MLD_AVX2_DIV_QINV +/* Some macros are kept because they are also defined in a header. */ +/* Keep: MLD_AVX2_BACKEND_DATA_OFFSET_8XQ (consts.h) */ +/* Keep: MLD_AVX2_BACKEND_DATA_OFFSET_8XQINV (consts.h) */ +/* Keep: MLD_AVX2_BACKEND_DATA_OFFSET_8XDIV_QINV (consts.h) */ +/* Keep: MLD_AVX2_BACKEND_DATA_OFFSET_8XDIV (consts.h) */ +/* Keep: MLD_AVX2_BACKEND_DATA_OFFSET_ZETAS_QINV (consts.h) */ +/* Keep: MLD_AVX2_BACKEND_DATA_OFFSET_ZETAS (consts.h) */ diff --git a/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c b/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c index 58357b31c..b5ebb3762 100644 --- a/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +++ b/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c @@ -150,3 +150,7 @@ MLD_EMPTY_CU(avx2_poly_decompose) #endif /* !(MLD_ARITH_BACKEND_X86_64_DEFAULT && \ !MLD_CONFIG_MULTILEVEL_NO_SHARED) */ + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef _mm256_blendv_epi32 diff --git a/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c b/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c index e572b5b22..f19e52b6b 100644 --- a/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +++ b/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c @@ -150,3 +150,7 @@ MLD_EMPTY_CU(avx2_poly_decompose) #endif /* !(MLD_ARITH_BACKEND_X86_64_DEFAULT && \ !MLD_CONFIG_MULTILEVEL_NO_SHARED) */ + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef _mm256_blendv_epi32 diff --git a/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c b/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c index ebc3ccf04..1e6b7ec3a 100644 --- a/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +++ b/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c @@ -95,3 +95,7 @@ MLD_EMPTY_CU(avx2_poly_use_hint) #endif /* !(MLD_ARITH_BACKEND_X86_64_DEFAULT && \ !MLD_CONFIG_MULTILEVEL_NO_SHARED) */ + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef _mm256_blendv_epi32 diff --git a/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c b/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c index 1e902f28b..37fcfbd4c 100644 --- a/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +++ b/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c @@ -97,3 +97,7 @@ MLD_EMPTY_CU(avx2_poly_use_hint) #endif /* !(MLD_ARITH_BACKEND_X86_64_DEFAULT && \ !MLD_CONFIG_MULTILEVEL_NO_SHARED) */ + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef _mm256_blendv_epi32 diff --git a/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c b/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c index 532f92b7c..70c5c42c7 100644 --- a/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +++ b/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c @@ -149,3 +149,7 @@ MLD_EMPTY_CU(avx2_rej_uniform_eta2) #endif /* !(MLD_ARITH_BACKEND_X86_64_DEFAULT && \ !MLD_CONFIG_MULTILEVEL_NO_SHARED) */ + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef MLD_AVX2_ETA2 diff --git a/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c b/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c index d382beca8..ba00e9125 100644 --- a/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +++ b/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c @@ -133,3 +133,7 @@ MLD_EMPTY_CU(avx2_rej_uniform_eta4) #endif /* !(MLD_ARITH_BACKEND_X86_64_DEFAULT && \ !MLD_CONFIG_MULTILEVEL_NO_SHARED) */ + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef MLD_AVX2_ETA4 diff --git a/mldsa/src/packing.c b/mldsa/src/packing.c index 136598543..e9cba5008 100644 --- a/mldsa/src/packing.c +++ b/mldsa/src/packing.c @@ -272,3 +272,7 @@ int mld_unpack_sig(uint8_t c[MLDSA_CTILDEBYTES], mld_polyvecl *z, return mld_unpack_hints(h, sig); } + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef mld_unpack_hints diff --git a/mldsa/src/poly.c b/mldsa/src/poly.c index ebc081a45..8f0bab0f9 100644 --- a/mldsa/src/poly.c +++ b/mldsa/src/poly.c @@ -630,3 +630,7 @@ uint32_t mld_poly_chknorm(const mld_poly *a, int32_t B) #else /* !MLD_CONFIG_MULTILEVEL_NO_SHARED */ MLD_EMPTY_CU(mld_poly) #endif /* MLD_CONFIG_MULTILEVEL_NO_SHARED */ + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef POLY_UNIFORM_NBLOCKS diff --git a/mldsa/src/poly_kl.c b/mldsa/src/poly_kl.c index 6908e5420..4acd39bab 100644 --- a/mldsa/src/poly_kl.c +++ b/mldsa/src/poly_kl.c @@ -825,5 +825,10 @@ void mld_polyw1_pack(uint8_t r[MLDSA_POLYW1_PACKEDBYTES], const mld_poly *a) } /* To facilitate single-compilation-unit (SCU) builds, undefine all macros. */ -/* TODO: autogenerate */ + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef mld_rej_eta +#undef POLY_UNIFORM_ETA_NBLOCKS #undef POLY_UNIFORM_ETA_NBLOCKS +#undef POLY_UNIFORM_GAMMA1_NBLOCKS diff --git a/mldsa/src/polyvec.c b/mldsa/src/polyvec.c index 4ed18c31a..b8e692215 100644 --- a/mldsa/src/polyvec.c +++ b/mldsa/src/polyvec.c @@ -853,3 +853,7 @@ void mld_polyveck_unpack_t0(mld_polyveck *p, mld_assert_bound_2d(p->vec, MLDSA_K, MLDSA_N, -(1 << (MLDSA_D - 1)) + 1, (1 << (MLDSA_D - 1)) + 1); } + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef mld_polymat_permute_bitrev_to_custom diff --git a/mldsa/src/prehash.c b/mldsa/src/prehash.c index 1a4a99766..f90e499c1 100644 --- a/mldsa/src/prehash.c +++ b/mldsa/src/prehash.c @@ -121,3 +121,7 @@ size_t mld_format_pre_hash_message( } #endif /* !MLD_CONFIG_MULTILEVEL_NO_SHARED */ + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef MLD_PRE_HASH_OID_LEN diff --git a/mldsa/src/sign.c b/mldsa/src/sign.c index 038806fd0..a0cfcfddf 100644 --- a/mldsa/src/sign.c +++ b/mldsa/src/sign.c @@ -1025,3 +1025,11 @@ int crypto_sign_verify_pre_hash_shake256( mld_zeroize(ph, sizeof(ph)); return result; } + +/* To facilitate single-compilation-unit (SCU) builds, undefine all macros. + * Don't modify by hand -- this is auto-generated by scripts/autogen. */ +#undef mld_check_pct +#undef mld_sample_s1_s2 +#undef mld_H +#undef mld_attempt_signature_generation +#undef NONCE_UB diff --git a/scripts/autogen b/scripts/autogen index 22cfb664f..37d42ba3d 100755 --- a/scripts/autogen +++ b/scripts/autogen @@ -181,6 +181,7 @@ def finalize(dry_run): # It currently covers: # - zeta values for the reference NTT and invNTT # - header guards +# - #undef's for CU-local macros # Standard color definitions GREEN = "\033[32m" @@ -1841,6 +1842,87 @@ def gen_header_guards(): ) +def gen_source_undefs(source_file): + status_update("undefs", source_file) + + # Get list of #define's clauses in this source file (ignore filename) + undef_list = list(map(lambda c: c[1], get_defines_from_file(source_file))) + if not undef_list: + return + + # Get define clauses from header files, as dict + header_defs = {d: c for (c, d) in get_defines()} + + undefs = [] + ignored = [] + for d in undef_list: + if d not in header_defs.keys(): + undefs.append(f"#undef {d}") + else: + ignored.append((d, header_defs[d])) + + if len(ignored) != 0: + undefs.append( + "/* Some macros are kept because they are also defined in a header. */" + ) + for d, c in ignored: + undefs.append(f"/* Keep: {d} ({c.split('/')[-1]}) */") + + content = read_file(source_file).split("\n") + + # Find simpasm footer if present (search from end) + footer_start = None + if source_file.endswith(".S"): + footer_start_marker = "simpasm: footer-start" + for i in range(len(content) - 1, -1, -1): + if footer_start_marker in content[i]: + footer_start = i + break + + if footer_start is not None: + simpasm_footer = content[footer_start:] + content = content[:footer_start] + else: + simpasm_footer = [] + + # Strip trailing undefs and empty lines + while content and ( + content[-1].startswith("#undef") + or content[-1].startswith("/* Keep:") + or content[-1].startswith("/* Some macros") + or content[-1] == "" + ): + content.pop() + + footer = [ + "", + "/* To facilitate single-compilation-unit (SCU) builds, undefine all macros.", + " * Don't modify by hand -- this is auto-generated by scripts/autogen. */", + ] + + # Remove existing footer if present + if len(content) >= len(footer) and content[-len(footer) :] == footer: + content = content[: -len(footer)] + + content.extend(footer) + content.extend(undefs) + content.append("") + + new_content = "\n".join(content + simpasm_footer) + update_file(source_file, new_content) + + +def gen_undefs(): + with ThreadPoolExecutor() as executor: + _ = list( + executor.map( + partial(gen_source_undefs), + get_c_source_files(core_only=True) + + get_asm_source_files(core_only=True), + ) + ) + + def get_markdown_files(): return get_files("**/*.md") @@ -2419,6 +2501,8 @@ def _main(): gen_monolithic_source_file() high_level_status("Generated monolithic source files") + gen_undefs() + high_level_status("Generated undefs") gen_test_configs() high_level_status("Generated test configs")