pq-code-package / mlkem-c-embedded

MLKEM implementation optimized for embedded microcontrollers
Apache License 2.0
14 stars 6 forks source link

Add STM32F207ZG (Cortex-M3) support #16

Closed mkannwischer closed 4 months ago

mkannwischer commented 6 months ago

e.g., https://www.st.com/en/evaluation-tools/nucleo-f207zg.html STM32F207ZG

mkannwischer commented 5 months ago

This won't work with #31. You'll get the following errors:

/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x1034): undefined reference to `__smlabb'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x103e): undefined reference to `__smlatt'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x1048): undefined reference to `__smlabb'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x1058): undefined reference to `__smlatb'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x1064): undefined reference to `__smuadx'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x1074): undefined reference to `__smlatb'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x1098): undefined reference to `__smlawt'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x10a4): undefined reference to `__smlabb'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x10ae): undefined reference to `__smlatt'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x10b8): undefined reference to `__smlabb'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x10c8): undefined reference to `__smlatb'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x10d4): undefined reference to `__smuadx'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x10e4): undefined reference to `__smlatb'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x1170): undefined reference to `__smlawt'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x117c): undefined reference to `__smlabb'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x118a): undefined reference to `__smlatt'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x1194): undefined reference to `__smlabb'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x11a4): undefined reference to `__smlatb'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x11b0): undefined reference to `__smuadx'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x11c0): undefined reference to `__smlatb'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x11d4): undefined reference to `__uadd16'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x11ec): undefined reference to `__smlawt'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x11f8): undefined reference to `__smlabb'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x1202): undefined reference to `__smlatt'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x120c): undefined reference to `__smlabb'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x121c): undefined reference to `__smlatb'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x1228): undefined reference to `__smuadx'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x1238): undefined reference to `__smlatb'
/nix/store/iwqdz0yhwvxbjx3dqyyhpwhxlg35z90p-gcc-arm-embedded-13.2.rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: ntt.c:(.text+0x124a): undefined reference to `__uadd16'

These instructions don't exist on the Cortex-M3, so that is expected. I think what we want is to re-add the arithmetic that works on the Cortex-M3 as well from a previous commit https://github.com/pq-code-package/mlkem-c-embedded/blob/4d271a9f8a9a407d1062f5251286fb7c8e49cb68/mlkem/ntt.c and then hide the faster Plantard one behind a flag.

Please also implement some kind of check in CI that makes sure that no instruction of umull/umlal/smull/smlal/udiv/sdiv appears in any of the object files when compiled with any optimization flags (-O{0,1,2,3,s,z,fast})