Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion dev/aarch64_clean/src/rej_uniform_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
3 changes: 3 additions & 0 deletions dev/aarch64_clean/src/rej_uniform_eta2_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
3 changes: 3 additions & 0 deletions dev/aarch64_clean/src/rej_uniform_eta4_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
15 changes: 15 additions & 0 deletions dev/x86_64/src/consts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
4 changes: 4 additions & 0 deletions dev/x86_64/src/poly_decompose_32_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions dev/x86_64/src/poly_decompose_88_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions dev/x86_64/src/poly_use_hint_32_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions dev/x86_64/src/poly_use_hint_88_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions dev/x86_64/src/rej_uniform_eta2_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions dev/x86_64/src/rej_uniform_eta4_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions mldsa/src/fips202/fips202.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions mldsa/src/native/x86_64/src/consts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
4 changes: 4 additions & 0 deletions mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions mldsa/src/packing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions mldsa/src/poly.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion mldsa/src/poly_kl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions mldsa/src/polyvec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions mldsa/src/prehash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions mldsa/src/sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
84 changes: 84 additions & 0 deletions scripts/autogen
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")
Expand Down