Skip to content

Commit 39ac88f

Browse files
committed
x86_64: Add ABI checker
Extend the ABI checker to cover all x86_64 assembly in mlkem-native. The x86_64 System V ABI requires preservation of rbx, rbp, and r12-r15. Unlike AArch64, no SIMD registers are callee-saved. Changes: - Add YAML metadata to all 21 dev x86_64 assembly files (20 arith + 1 keccak), propagated to mlkem/ via simpasm - Add x86_64_callstub.S implementing the register state capture/restore for x86_64 System V - Extend abicheckutil.c/h with x86_64_register_state struct and compliance check - Generalize autogen gen_abicheck() to handle both architectures via an arch_configs table; output filenames are now suffixed with the architecture (e.g. check_ntt_asm_aarch64.c) - Extend components.mk with x86_64 build rules including constant data files (consts.c, compress_consts.c, etc.) Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
1 parent 9354ac8 commit 39ac88f

109 files changed

Lines changed: 3759 additions & 336 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ run_size: \
252252
run_size_1024
253253

254254
ifeq ($(OPT),1)
255+
# ABI checker is not supported on Windows (calling convention mismatch)
256+
ifeq ($(findstring MINGW,$(HOST_PLATFORM))$(findstring Windows,$(HOST_PLATFORM)),)
255257
abicheck: $(ABICHECK_DIR)/bin/abicheck
256258

257259
run_abicheck: abicheck
@@ -260,6 +262,10 @@ else
260262
abicheck:
261263
run_abicheck:
262264
endif
265+
else
266+
abicheck:
267+
run_abicheck:
268+
endif
263269

264270
# Display host and compiler feature detection information
265271
# Shows which architectural features are supported by both the compiler and host CPU

dev/fips202/x86_64/src/keccak_f1600_x4_avx2.S

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,37 @@
66

77
#if defined(MLK_FIPS202_X86_64_NEED_X4_AVX2) && \
88
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
9+
/*yaml
10+
Name: keccak_f1600_x4_avx2
11+
Description: x86_64 AVX2 Keccak-f[1600] permutation for four states
12+
Signature: void mlk_keccak_f1600_x4_avx2(uint64_t states[100], const uint64_t rc[24], const uint64_t rho8[4], const uint64_t rho56[4])
13+
ABI:
14+
rdi:
15+
type: buffer
16+
size_bytes: 800
17+
permissions: read/write
18+
c_parameter: uint64_t states[100]
19+
description: Four sequential Keccak states (4 x 25 x uint64_t)
20+
rsi:
21+
type: buffer
22+
size_bytes: 192
23+
permissions: read-only
24+
c_parameter: const uint64_t rc[24]
25+
description: Round constants (24 x uint64_t)
26+
rdx:
27+
type: buffer
28+
size_bytes: 32
29+
permissions: read-only
30+
c_parameter: const uint64_t rho8[4]
31+
description: Rotation constant rho8 (4 x uint64_t)
32+
rcx:
33+
type: buffer
34+
size_bytes: 32
35+
permissions: read-only
36+
c_parameter: const uint64_t rho56[4]
37+
description: Rotation constant rho56 (4 x uint64_t)
38+
*/
39+
940
/* simpasm: header-end */
1041

1142
.text

dev/x86_64/src/intt.S

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@
3131
#include "../../../common.h"
3232
#if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \
3333
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
34+
/*yaml
35+
Name: invntt_avx2
36+
Description: x86_64 AVX2 inverse NTT
37+
Signature: void mlk_invntt_avx2(int16_t *r, const int16_t *qdata)
38+
ABI:
39+
rdi:
40+
type: buffer
41+
size_bytes: 512
42+
permissions: read/write
43+
c_parameter: int16_t *r
44+
description: Input/output polynomial (256 x int16_t)
45+
rsi:
46+
type: buffer
47+
size_bytes: 1248
48+
permissions: read-only
49+
c_parameter: const int16_t *qdata
50+
description: Precomputed constants (624 x int16_t)
51+
*/
52+
3453
/* simpasm: header-end */
3554

3655
#include "consts.h"

dev/x86_64/src/mulcache_compute.S

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,31 @@
66
#include "../../../common.h"
77
#if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \
88
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
9+
/*yaml
10+
Name: poly_mulcache_compute_avx2
11+
Description: x86_64 AVX2 mulcache computation
12+
Signature: void mlk_poly_mulcache_compute_avx2(int16_t *out, const int16_t *in, const int16_t *qdata)
13+
ABI:
14+
rdi:
15+
type: buffer
16+
size_bytes: 256
17+
permissions: write-only
18+
c_parameter: int16_t *out
19+
description: Output mulcache (128 x int16_t)
20+
rsi:
21+
type: buffer
22+
size_bytes: 512
23+
permissions: read-only
24+
c_parameter: const int16_t *in
25+
description: Input polynomial (256 x int16_t)
26+
rdx:
27+
type: buffer
28+
size_bytes: 1248
29+
permissions: read-only
30+
c_parameter: const int16_t *qdata
31+
description: Precomputed constants (624 x int16_t)
32+
*/
33+
934
/* simpasm: header-end */
1035

1136
#include "consts.h"

dev/x86_64/src/ntt.S

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@
2727
#include "../../../common.h"
2828
#if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \
2929
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
30+
/*yaml
31+
Name: ntt_avx2
32+
Description: x86_64 AVX2 forward NTT
33+
Signature: void mlk_ntt_avx2(int16_t *r, const int16_t *qdata)
34+
ABI:
35+
rdi:
36+
type: buffer
37+
size_bytes: 512
38+
permissions: read/write
39+
c_parameter: int16_t *r
40+
description: Input/output polynomial (256 x int16_t)
41+
rsi:
42+
type: buffer
43+
size_bytes: 1248
44+
permissions: read-only
45+
c_parameter: const int16_t *qdata
46+
description: Precomputed constants (624 x int16_t)
47+
*/
48+
3049
/* simpasm: header-end */
3150

3251
#include "consts.h"

dev/x86_64/src/nttfrombytes.S

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,25 @@
2121

2222
#if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \
2323
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
24+
/*yaml
25+
Name: nttfrombytes_avx2
26+
Description: x86_64 AVX2 polynomial deserialization in NTT domain
27+
Signature: void mlk_nttfrombytes_avx2(int16_t *r, const uint8_t *a)
28+
ABI:
29+
rdi:
30+
type: buffer
31+
size_bytes: 512
32+
permissions: write-only
33+
c_parameter: int16_t *r
34+
description: Output polynomial (256 x int16_t)
35+
rsi:
36+
type: buffer
37+
size_bytes: 384
38+
permissions: read-only
39+
c_parameter: const uint8_t *a
40+
description: Input byte array (MLKEM_POLYBYTES = 384)
41+
*/
42+
2443
/* simpasm: header-end */
2544

2645
#include "consts.h"

dev/x86_64/src/ntttobytes.S

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,25 @@
2121

2222
#if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \
2323
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
24+
/*yaml
25+
Name: ntttobytes_avx2
26+
Description: x86_64 AVX2 polynomial serialization in NTT domain
27+
Signature: void mlk_ntttobytes_avx2(uint8_t *r, const int16_t *a)
28+
ABI:
29+
rdi:
30+
type: buffer
31+
size_bytes: 384
32+
permissions: write-only
33+
c_parameter: uint8_t *r
34+
description: Output byte array (MLKEM_POLYBYTES = 384)
35+
rsi:
36+
type: buffer
37+
size_bytes: 512
38+
permissions: read-only
39+
c_parameter: const int16_t *a
40+
description: Input polynomial (256 x int16_t)
41+
*/
42+
2443
/* simpasm: header-end */
2544

2645
#include "consts.h"

dev/x86_64/src/nttunpack.S

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@
2121

2222
#if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \
2323
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
24+
/*yaml
25+
Name: nttunpack_avx2
26+
Description: x86_64 AVX2 NTT unpack from custom to bitreversed order
27+
Signature: void mlk_nttunpack_avx2(int16_t *r)
28+
ABI:
29+
rdi:
30+
type: buffer
31+
size_bytes: 512
32+
permissions: read/write
33+
c_parameter: int16_t *r
34+
description: Input/output polynomial (256 x int16_t)
35+
*/
36+
2437
/* simpasm: header-end */
2538

2639
#include "consts.h"

dev/x86_64/src/poly_compress_d10.S

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,31 @@
3232
#if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \
3333
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \
3434
(defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 2 || MLKEM_K == 3)
35+
/*yaml
36+
Name: poly_compress_d10_avx2
37+
Description: x86_64 AVX2 polynomial compression (d=10)
38+
Signature: void mlk_poly_compress_d10_avx2(uint8_t *r, const int16_t *a, const uint8_t *data)
39+
ABI:
40+
rdi:
41+
type: buffer
42+
size_bytes: 320
43+
permissions: write-only
44+
c_parameter: uint8_t *r
45+
description: Output compressed polynomial
46+
rsi:
47+
type: buffer
48+
size_bytes: 512
49+
permissions: read-only
50+
c_parameter: const int16_t *a
51+
description: Input polynomial (256 x int16_t)
52+
rdx:
53+
type: buffer
54+
size_bytes: 32
55+
permissions: read-only
56+
c_parameter: const uint8_t *data
57+
description: Precomputed compression constants
58+
*/
59+
3560
/* simpasm: header-end */
3661

3762
.text

dev/x86_64/src/poly_compress_d11.S

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,31 @@
3434
#if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \
3535
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \
3636
(defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4)
37+
/*yaml
38+
Name: poly_compress_d11_avx2
39+
Description: x86_64 AVX2 polynomial compression (d=11)
40+
Signature: void mlk_poly_compress_d11_avx2(uint8_t *r, const int16_t *a, const uint8_t *data)
41+
ABI:
42+
rdi:
43+
type: buffer
44+
size_bytes: 352
45+
permissions: write-only
46+
c_parameter: uint8_t *r
47+
description: Output compressed polynomial
48+
rsi:
49+
type: buffer
50+
size_bytes: 512
51+
permissions: read-only
52+
c_parameter: const int16_t *a
53+
description: Input polynomial (256 x int16_t)
54+
rdx:
55+
type: buffer
56+
size_bytes: 64
57+
permissions: read-only
58+
c_parameter: const uint8_t *data
59+
description: Precomputed compression constants
60+
*/
61+
3762
/* simpasm: header-end */
3863

3964
.text

0 commit comments

Comments
 (0)