-
Notifications
You must be signed in to change notification settings - Fork 37
Description
Context: The idea of auto.mk
is to optimize the build for the platform on which mlkem-native is built. This is done by automatically adding various AVX2 feature flags.
Issues: There are issues at multiple levels.
- On x86_64,
auto.mk
makes two assumptions about the compilation host:
i. It assumes that the host compiler supports various feature flags:-mavx2 -mbmi2 -mpopcnt -maes
ii. It assumes that the host CPU supports the aforementioned AVX2 features. - On AArch64,
auto.mk
does not deal with the Armv8.4-a+SHA3 extension required for parts of the FIPS202 backend. However, the analogous way of dealing with this, by adding-march=armv8.4-a+sha3
toCFLAGS
, would suffer from the same issues as in point 1.
Task:
-
Add a new
test/mk/compiler.mk
which detects whether the architectural features used by mlkem-native are supported by the host compiler.
i. For x86_64, detect whether the compiler supports AVX2, SSE2, and BMI2.
ii. For AArch64, detect whether the compiler supports the SHA3 extension.The detected compiler support should be captured in Makefile variables MLK_COMPILER_SUPPORTS_XXX. It should not be reflected in any CFLAGS. This is to avoid creating a dependency of the mlkem-native sources on our own build system.
The feature detection for the compiler should be done by try-compilation.
-
Extend
test/mk/auto.mk
to check whether the host CPU (the CPU on which mlkem-native is compiled) supports the aforementioned features. This should at least support any combination of {x86_64, AArch64} x {MacOS, Linux}. The results should be captured in MLK_HOST_SUPPORTS_XXX, following the same naming as MLK_COMPILER_SUPPORTS_XXX. Then, if for any given feature XXX, both MLK_COMPILER_SUPPORTS_XXX and MLK_HOST_SUPPORTS_XXX are set, the CFLAGS should be amended with the appropriate architecture flag. The setting ofMLK_FORCE_XXX
directives should be kept. For platforms other than the ones listed above, the CFLAGS should not be further amended -- for those, one relies on the default compiler configuration being tailored to the target CPU. -
Add a
make host_info
target to the mainMakefile
which summarizes the host-compiler/CPU feature support. This will require unconditionally importingauto.mk
(unguarded by AUTO=0/1), but instead guarding the extension of the CFLAGS byAUTO=1
.