Skip to content

Commit b15ba6b

Browse files
dannytsenhanno-becker
authored andcommitted
Added optimized ppc64le support functions for ML-KEM.
The supported native functions include: 1. MLK_USE_NATIVE_NTT (ntt_ppc.S) 2. MLK_USE_NATIVE_INTT (intt_ppc.S) 3. MLK_USE_NATIVE_POLY_REDUCE (reduce.S) 4. MLK_USE_NATIVE_POLY_TOMONT (poly_tomont.S) And other interface functions and headers. Signed-off-by: Danny Tsen <[email protected]>
1 parent 9683251 commit b15ba6b

27 files changed

+4227
-0
lines changed

BIBLIOGRAPHY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ source code and documentation.
2929
- [examples/basic_deterministic/mlkem_native/custom_no_randomized_config.h](examples/basic_deterministic/mlkem_native/custom_no_randomized_config.h)
3030
- [integration/liboqs/config_aarch64.h](integration/liboqs/config_aarch64.h)
3131
- [integration/liboqs/config_c.h](integration/liboqs/config_c.h)
32+
- [integration/liboqs/config_ppc64le.h](integration/liboqs/config_ppc64le.h)
3233
- [integration/liboqs/config_x86_64.h](integration/liboqs/config_x86_64.h)
3334
- [mlkem/src/config.h](mlkem/src/config.h)
3435
- [mlkem/src/kem.c](mlkem/src/kem.c)

dev/ppc64le/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[//]: # (SPDX-License-Identifier: CC-BY-4.0)
2+
3+
# ppc64le backend (little endian)
4+
5+
This directory contains a native backend for little endian POWER 8 (ppc64le) and above systems.
6+

dev/ppc64le/meta.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) The mlkem-native project authors
3+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4+
*/
5+
6+
#ifndef MLK_DEV_PPC64LE_META_H
7+
#define MLK_DEV_PPC64LE_META_H
8+
9+
/* Identifier for this backend so that source and assembly files
10+
* in the build can be appropriately guarded. */
11+
#define MLK_ARITH_BACKEND_PPC64LE_DEFAULT
12+
13+
#define MLK_ARITH_BACKEND_NAME PPC64LE_DEFAULT
14+
15+
/* Set of primitives that this backend replaces */
16+
#define MLK_USE_NATIVE_NTT
17+
#define MLK_USE_NATIVE_INTT
18+
#define MLK_USE_NATIVE_POLY_REDUCE
19+
#define MLK_USE_NATIVE_POLY_TOMONT
20+
21+
#if !defined(__ASSEMBLER__)
22+
#include <string.h>
23+
#include "../../common.h"
24+
#include "../../params.h"
25+
#include "../api.h"
26+
#include "src/arith_native_ppc64le.h"
27+
28+
static MLK_INLINE int mlk_ntt_native(int16_t data[MLKEM_N])
29+
{
30+
mlk_ntt_ppc(data, mlk_ppc_qdata);
31+
return MLK_NATIVE_FUNC_SUCCESS;
32+
}
33+
34+
static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N])
35+
{
36+
mlk_intt_ppc(data, mlk_ppc_qdata);
37+
return MLK_NATIVE_FUNC_SUCCESS;
38+
}
39+
40+
static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N])
41+
{
42+
mlk_reduce_ppc(data, mlk_ppc_qdata);
43+
return MLK_NATIVE_FUNC_SUCCESS;
44+
}
45+
46+
static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N])
47+
{
48+
mlk_poly_tomont_ppc(data, mlk_ppc_qdata);
49+
return MLK_NATIVE_FUNC_SUCCESS;
50+
}
51+
#endif /* !__ASSEMBLER__ */
52+
53+
#endif /* !MLK_DEV_PPC64LE_META_H */
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2024-2025 The mlkem-native project authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
#ifndef MLK_DEV_PPC64LE_SRC_ARITH_NATIVE_PPC64LE_H
6+
#define MLK_DEV_PPC64LE_SRC_ARITH_NATIVE_PPC64LE_H
7+
8+
#include <stdint.h>
9+
#include "../../../common.h"
10+
#include "consts.h"
11+
12+
#define mlk_ntt_ppc MLK_NAMESPACE(ntt_ppc)
13+
void mlk_ntt_ppc(int16_t *, const int16_t *);
14+
15+
#define mlk_intt_ppc MLK_NAMESPACE(intt_ppc)
16+
void mlk_intt_ppc(int16_t *, const int16_t *);
17+
18+
#define mlk_reduce_ppc MLK_NAMESPACE(reduce_ppc)
19+
void mlk_reduce_ppc(int16_t *r, const int16_t *);
20+
21+
#define mlk_poly_tomont_ppc MLK_NAMESPACE(poly_tomont_ppc)
22+
void mlk_poly_tomont_ppc(int16_t *, const int16_t *);
23+
24+
#endif /* !MLK_DEV_PPC64LE_SRC_ARITH_NATIVE_PPC64LE_H */

dev/ppc64le/src/consts.c

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
* Copyright (c) The mlkem-native project authors
3+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4+
*/
5+
6+
#include "../../../common.h"
7+
8+
#if defined(MLK_ARITH_BACKEND_PPC64LE_DEFAULT) && \
9+
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
10+
11+
#include "consts.h"
12+
13+
MLK_ALIGN const int16_t mlk_ppc_qdata[1568] = {
14+
/* -Q */
15+
-3329, -3329, -3329, -3329, -3329, -3329, -3329, -3329,
16+
/* QINV */
17+
-3327, -3327, -3327, -3327, -3327, -3327, -3327, -3327,
18+
/* Q */
19+
3329, 3329, 3329, 3329, 3329, 3329, 3329, 3329,
20+
/* const 20159 for reduce.S and intt */
21+
20159, 20159, 20159, 20159, 20159, 20159, 20159, 20159,
22+
/* const 1441 for intt */
23+
1441, 1441, 1441, 1441, 1441, 1441, 1441, 1441,
24+
/* for poly_tomont.S */
25+
1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353,
26+
/* zetas */
27+
/* For ntt Len=128, offset 96 */
28+
-758, -758, -758, -758, -758, -758, -758, -758, -359, -359, -359, -359,
29+
-359, -359, -359, -359, -1517, -1517, -1517, -1517, -1517, -1517, -1517,
30+
-1517, 1493, 1493, 1493, 1493, 1493, 1493, 1493, 1493, 1422, 1422, 1422,
31+
1422, 1422, 1422, 1422, 1422, 287, 287, 287, 287, 287, 287, 287, 287, 202,
32+
202, 202, 202, 202, 202, 202, 202, -171, -171, -171, -171, -171, -171, -171,
33+
-171, 622, 622, 622, 622, 622, 622, 622, 622, 1577, 1577, 1577, 1577, 1577,
34+
1577, 1577, 1577, 182, 182, 182, 182, 182, 182, 182, 182, 962, 962, 962,
35+
962, 962, 962, 962, 962, -1202, -1202, -1202, -1202, -1202, -1202, -1202,
36+
-1202, -1474, -1474, -1474, -1474, -1474, -1474, -1474, -1474, 1468, 1468,
37+
1468, 1468, 1468, 1468, 1468, 1468, 573, 573, 573, 573, 573, 573, 573, 573,
38+
-1325, -1325, -1325, -1325, -1325, -1325, -1325, -1325, 264, 264, 264, 264,
39+
264, 264, 264, 264, 383, 383, 383, 383, 383, 383, 383, 383, -829, -829,
40+
-829, -829, -829, -829, -829, -829, 1458, 1458, 1458, 1458, 1458, 1458,
41+
1458, 1458, -1602, -1602, -1602, -1602, -1602, -1602, -1602, -1602, -130,
42+
-130, -130, -130, -130, -130, -130, -130, -681, -681, -681, -681, -681,
43+
-681, -681, -681, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 732, 732,
44+
732, 732, 732, 732, 732, 732, 608, 608, 608, 608, 608, 608, 608, 608, -1542,
45+
-1542, -1542, -1542, -1542, -1542, -1542, -1542, 411, 411, 411, 411, 411,
46+
411, 411, 411, -205, -205, -205, -205, -205, -205, -205, -205, -1571, -1571,
47+
-1571, -1571, -1571, -1571, -1571, -1571, 1223, 1223, 1223, 1223, 1223,
48+
1223, 1223, 1223, 652, 652, 652, 652, 652, 652, 652, 652, -552, -552, -552,
49+
-552, -552, -552, -552, -552, 1015, 1015, 1015, 1015, 1015, 1015, 1015,
50+
1015, -1293, -1293, -1293, -1293, -1293, -1293, -1293, -1293, 1491, 1491,
51+
1491, 1491, 1491, 1491, 1491, 1491, -282, -282, -282, -282, -282, -282,
52+
-282, -282, -1544, -1544, -1544, -1544, -1544, -1544, -1544, -1544, 516,
53+
516, 516, 516, 516, 516, 516, 516, -8, -8, -8, -8, -8, -8, -8, -8, -320,
54+
-320, -320, -320, -320, -320, -320, -320, -666, -666, -666, -666, -666,
55+
-666, -666, -666, -1618, -1618, -1618, -1618, -1618, -1618, -1618, -1618,
56+
-1162, -1162, -1162, -1162, -1162, -1162, -1162, -1162, 126, 126, 126, 126,
57+
126, 126, 126, 126, 1469, 1469, 1469, 1469, 1469, 1469, 1469, 1469, -853,
58+
-853, -853, -853, -853, -853, -853, -853, -90, -90, -90, -90, -90, -90, -90,
59+
-90, -271, -271, -271, -271, -271, -271, -271, -271, 830, 830, 830, 830,
60+
830, 830, 830, 830, 107, 107, 107, 107, 107, 107, 107, 107, -1421, -1421,
61+
-1421, -1421, -1421, -1421, -1421, -1421, -247, -247, -247, -247, -247,
62+
-247, -247, -247, -951, -951, -951, -951, -951, -951, -951, -951, -398,
63+
-398, -398, -398, -398, -398, -398, -398, 961, 961, 961, 961, 961, 961, 961,
64+
961, -1508, -1508, -1508, -1508, -1508, -1508, -1508, -1508, -725, -725,
65+
-725, -725, -725, -725, -725, -725, 448, 448, 448, 448, 448, 448, 448, 448,
66+
-1065, -1065, -1065, -1065, -1065, -1065, -1065, -1065, 677, 677, 677, 677,
67+
677, 677, 677, 677, -1275, -1275, -1275, -1275, -1275, -1275, -1275, -1275,
68+
/* For intt Len=2, offset IZETA_NTT_OFFSET64 */
69+
-1103, -1103, -1103, -1103, 430, 430, 430, 430, 555, 555, 555, 555, 843,
70+
843, 843, 843, -1251, -1251, -1251, -1251, 871, 871, 871, 871, 1550, 1550,
71+
1550, 1550, 105, 105, 105, 105, 422, 422, 422, 422, 587, 587, 587, 587, 177,
72+
177, 177, 177, -235, -235, -235, -235, -291, -291, -291, -291, -460, -460,
73+
-460, -460, 1574, 1574, 1574, 1574, 1653, 1653, 1653, 1653, -246, -246,
74+
-246, -246, 778, 778, 778, 778, 1159, 1159, 1159, 1159, -147, -147, -147,
75+
-147, -777, -777, -777, -777, 1483, 1483, 1483, 1483, -602, -602, -602,
76+
-602, 1119, 1119, 1119, 1119, -1590, -1590, -1590, -1590, 644, 644, 644,
77+
644, -872, -872, -872, -872, 349, 349, 349, 349, 418, 418, 418, 418, 329,
78+
329, 329, 329, -156, -156, -156, -156, -75, -75, -75, -75, 817, 817, 817,
79+
817, 1097, 1097, 1097, 1097, 603, 603, 603, 603, 610, 610, 610, 610, 1322,
80+
1322, 1322, 1322, -1285, -1285, -1285, -1285, -1465, -1465, -1465, -1465,
81+
384, 384, 384, 384, -1215, -1215, -1215, -1215, -136, -136, -136, -136,
82+
1218, 1218, 1218, 1218, -1335, -1335, -1335, -1335, -874, -874, -874, -874,
83+
220, 220, 220, 220, -1187, -1187, -1187, -1187, -1659, -1659, -1659, -1659,
84+
-1185, -1185, -1185, -1185, -1530, -1530, -1530, -1530, -1278, -1278, -1278,
85+
-1278, 794, 794, 794, 794, -1510, -1510, -1510, -1510, -854, -854, -854,
86+
-854, -870, -870, -870, -870, 478, 478, 478, 478, -108, -108, -108, -108,
87+
-308, -308, -308, -308, 996, 996, 996, 996, 991, 991, 991, 991, 958, 958,
88+
958, 958, -1460, -1460, -1460, -1460, 1522, 1522, 1522, 1522, 1628, 1628,
89+
1628, 1628,
90+
/* For intt Len=2, offset IZETA_NTT_OFFSET127 */
91+
1628, 1628, 1628, 1628, 1522, 1522, 1522, 1522, -1460, -1460, -1460, -1460,
92+
958, 958, 958, 958, 991, 991, 991, 991, 996, 996, 996, 996, -308, -308,
93+
-308, -308, -108, -108, -108, -108, 478, 478, 478, 478, -870, -870, -870,
94+
-870, -854, -854, -854, -854, -1510, -1510, -1510, -1510, 794, 794, 794,
95+
794, -1278, -1278, -1278, -1278, -1530, -1530, -1530, -1530, -1185, -1185,
96+
-1185, -1185, -1659, -1659, -1659, -1659, -1187, -1187, -1187, -1187, 220,
97+
220, 220, 220, -874, -874, -874, -874, -1335, -1335, -1335, -1335, 1218,
98+
1218, 1218, 1218, -136, -136, -136, -136, -1215, -1215, -1215, -1215, 384,
99+
384, 384, 384, -1465, -1465, -1465, -1465, -1285, -1285, -1285, -1285, 1322,
100+
1322, 1322, 1322, 610, 610, 610, 610, 603, 603, 603, 603, 1097, 1097, 1097,
101+
1097, 817, 817, 817, 817, -75, -75, -75, -75, -156, -156, -156, -156, 329,
102+
329, 329, 329, 418, 418, 418, 418, 349, 349, 349, 349, -872, -872, -872,
103+
-872, 644, 644, 644, 644, -1590, -1590, -1590, -1590, 1119, 1119, 1119,
104+
1119, -602, -602, -602, -602, 1483, 1483, 1483, 1483, -777, -777, -777,
105+
-777, -147, -147, -147, -147, 1159, 1159, 1159, 1159, 778, 778, 778, 778,
106+
-246, -246, -246, -246, 1653, 1653, 1653, 1653, 1574, 1574, 1574, 1574,
107+
-460, -460, -460, -460, -291, -291, -291, -291, -235, -235, -235, -235, 177,
108+
177, 177, 177, 587, 587, 587, 587, 422, 422, 422, 422, 105, 105, 105, 105,
109+
1550, 1550, 1550, 1550, 871, 871, 871, 871, -1251, -1251, -1251, -1251, 843,
110+
843, 843, 843, 555, 555, 555, 555, 430, 430, 430, 430, -1103, -1103, -1103,
111+
-1103,
112+
/* For intt Len=4 and others, offset IZETA_NTT_OFFSET63 */
113+
-1275, -1275, -1275, -1275, -1275, -1275, -1275, -1275, 677, 677, 677, 677,
114+
677, 677, 677, 677, -1065, -1065, -1065, -1065, -1065, -1065, -1065, -1065,
115+
448, 448, 448, 448, 448, 448, 448, 448, -725, -725, -725, -725, -725, -725,
116+
-725, -725, -1508, -1508, -1508, -1508, -1508, -1508, -1508, -1508, 961,
117+
961, 961, 961, 961, 961, 961, 961, -398, -398, -398, -398, -398, -398, -398,
118+
-398, -951, -951, -951, -951, -951, -951, -951, -951, -247, -247, -247,
119+
-247, -247, -247, -247, -247, -1421, -1421, -1421, -1421, -1421, -1421,
120+
-1421, -1421, 107, 107, 107, 107, 107, 107, 107, 107, 830, 830, 830, 830,
121+
830, 830, 830, 830, -271, -271, -271, -271, -271, -271, -271, -271, -90,
122+
-90, -90, -90, -90, -90, -90, -90, -853, -853, -853, -853, -853, -853, -853,
123+
-853, 1469, 1469, 1469, 1469, 1469, 1469, 1469, 1469, 126, 126, 126, 126,
124+
126, 126, 126, 126, -1162, -1162, -1162, -1162, -1162, -1162, -1162, -1162,
125+
-1618, -1618, -1618, -1618, -1618, -1618, -1618, -1618, -666, -666, -666,
126+
-666, -666, -666, -666, -666, -320, -320, -320, -320, -320, -320, -320,
127+
-320, -8, -8, -8, -8, -8, -8, -8, -8, 516, 516, 516, 516, 516, 516, 516,
128+
516, -1544, -1544, -1544, -1544, -1544, -1544, -1544, -1544, -282, -282,
129+
-282, -282, -282, -282, -282, -282, 1491, 1491, 1491, 1491, 1491, 1491,
130+
1491, 1491, -1293, -1293, -1293, -1293, -1293, -1293, -1293, -1293, 1015,
131+
1015, 1015, 1015, 1015, 1015, 1015, 1015, -552, -552, -552, -552, -552,
132+
-552, -552, -552, 652, 652, 652, 652, 652, 652, 652, 652, 1223, 1223, 1223,
133+
1223, 1223, 1223, 1223, 1223, -1571, -1571, -1571, -1571, -1571, -1571,
134+
-1571, -1571, -205, -205, -205, -205, -205, -205, -205, -205, 411, 411, 411,
135+
411, 411, 411, 411, 411, -1542, -1542, -1542, -1542, -1542, -1542, -1542,
136+
-1542, 608, 608, 608, 608, 608, 608, 608, 608, 732, 732, 732, 732, 732, 732,
137+
732, 732, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, -681, -681, -681,
138+
-681, -681, -681, -681, -681, -130, -130, -130, -130, -130, -130, -130,
139+
-130, -1602, -1602, -1602, -1602, -1602, -1602, -1602, -1602, 1458, 1458,
140+
1458, 1458, 1458, 1458, 1458, 1458, -829, -829, -829, -829, -829, -829,
141+
-829, -829, 383, 383, 383, 383, 383, 383, 383, 383, 264, 264, 264, 264, 264,
142+
264, 264, 264, -1325, -1325, -1325, -1325, -1325, -1325, -1325, -1325, 573,
143+
573, 573, 573, 573, 573, 573, 573, 1468, 1468, 1468, 1468, 1468, 1468, 1468,
144+
1468, -1474, -1474, -1474, -1474, -1474, -1474, -1474, -1474, -1202, -1202,
145+
-1202, -1202, -1202, -1202, -1202, -1202, 962, 962, 962, 962, 962, 962, 962,
146+
962, 182, 182, 182, 182, 182, 182, 182, 182, 1577, 1577, 1577, 1577, 1577,
147+
1577, 1577, 1577, 622, 622, 622, 622, 622, 622, 622, 622, -171, -171, -171,
148+
-171, -171, -171, -171, -171, 202, 202, 202, 202, 202, 202, 202, 202, 287,
149+
287, 287, 287, 287, 287, 287, 287, 1422, 1422, 1422, 1422, 1422, 1422, 1422,
150+
1422, 1493, 1493, 1493, 1493, 1493, 1493, 1493, 1493, -1517, -1517, -1517,
151+
-1517, -1517, -1517, -1517, -1517, -359, -359, -359, -359, -359, -359, -359,
152+
-359, -758, -758, -758, -758, -758, -758, -758, -758};
153+
154+
#endif /* MLK_ARITH_BACKEND_PPC64LE_DEFAULT && \
155+
!MLK_CONFIG_MULTILEVEL_NO_SHARED */

dev/ppc64le/src/consts.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) The mlkem-native project authors
3+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4+
*/
5+
6+
#ifndef MLK_DEV_PPC64LE_SRC_CONSTS_H
7+
#define MLK_DEV_PPC64LE_SRC_CONSTS_H
8+
#include "../../../common.h"
9+
10+
#define NQ_OFFSET 0
11+
#define QINV_OFFSET 16
12+
#define Q_OFFSET 32
13+
#define C20159_OFFSET 48
14+
#define C1441_OFFSET 64
15+
#define C1353_OFFSET 80
16+
#define ZETA_NTT_OFFSET 96
17+
#define ZETA_NTT_OFFSET64 1104
18+
#define IZETA_NTT_OFFSET127 1616
19+
#define IZETA_NTT_OFFSET63 2128
20+
21+
#ifndef __ASSEMBLER__
22+
#define mlk_ppc_qdata MLK_NAMESPACE(ppc_qdata)
23+
extern const int16_t mlk_ppc_qdata[];
24+
#endif
25+
26+
#endif /* !MLK_DEV_PPC64LE_SRC_CONSTS_H */

0 commit comments

Comments
 (0)