Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions BIBLIOGRAPHY.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ source code and documentation.
- [examples/basic_deterministic/mlkem_native/custom_no_randomized_config.h](examples/basic_deterministic/mlkem_native/custom_no_randomized_config.h)
- [integration/liboqs/config_aarch64.h](integration/liboqs/config_aarch64.h)
- [integration/liboqs/config_c.h](integration/liboqs/config_c.h)
- [integration/liboqs/config_ppc64le.h](integration/liboqs/config_ppc64le.h)
- [integration/liboqs/config_x86_64.h](integration/liboqs/config_x86_64.h)
- [mlkem/src/config.h](mlkem/src/config.h)
- [mlkem/src/kem.c](mlkem/src/kem.c)
Expand Down
6 changes: 6 additions & 0 deletions dev/ppc64le/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[//]: # (SPDX-License-Identifier: CC-BY-4.0)

# ppc64le backend (little endian)

This directory contains a native backend for little endian POWER 8 (ppc64le) and above systems.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed before, I couldn't yet run the code with power8 emulation, and I think you mentioned you only tested power9 and power10. Are you sure it works on power8?


53 changes: 53 additions & 0 deletions dev/ppc64le/meta.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) The mlkem-native project authors
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
*/

#ifndef MLK_DEV_PPC64LE_META_H
#define MLK_DEV_PPC64LE_META_H

/* Identifier for this backend so that source and assembly files
* in the build can be appropriately guarded. */
#define MLK_ARITH_BACKEND_PPC64LE_DEFAULT

#define MLK_ARITH_BACKEND_NAME PPC64LE_DEFAULT

/* Set of primitives that this backend replaces */
#define MLK_USE_NATIVE_NTT
#define MLK_USE_NATIVE_INTT
#define MLK_USE_NATIVE_POLY_REDUCE
#define MLK_USE_NATIVE_POLY_TOMONT

#if !defined(__ASSEMBLER__)
#include <string.h>
#include "../../common.h"
#include "../../params.h"
#include "../api.h"
#include "src/arith_native_ppc64le.h"

static MLK_INLINE int mlk_ntt_native(int16_t data[MLKEM_N])
{
mlk_ntt_ppc(data, mlk_ppc_qdata);
return MLK_NATIVE_FUNC_SUCCESS;
}

static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N])
{
mlk_intt_ppc(data, mlk_ppc_qdata);
return MLK_NATIVE_FUNC_SUCCESS;
}

static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N])
{
mlk_reduce_ppc(data, mlk_ppc_qdata);
return MLK_NATIVE_FUNC_SUCCESS;
}

static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N])
{
mlk_poly_tomont_ppc(data, mlk_ppc_qdata);
return MLK_NATIVE_FUNC_SUCCESS;
}
#endif /* !__ASSEMBLER__ */

#endif /* !MLK_DEV_PPC64LE_META_H */
24 changes: 24 additions & 0 deletions dev/ppc64le/src/arith_native_ppc64le.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2024-2025 The mlkem-native project authors
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef MLK_DEV_PPC64LE_SRC_ARITH_NATIVE_PPC64LE_H
#define MLK_DEV_PPC64LE_SRC_ARITH_NATIVE_PPC64LE_H

#include <stdint.h>
#include "../../../common.h"
#include "consts.h"

#define mlk_ntt_ppc MLK_NAMESPACE(ntt_ppc)
void mlk_ntt_ppc(int16_t *, const int16_t *);

#define mlk_intt_ppc MLK_NAMESPACE(intt_ppc)
void mlk_intt_ppc(int16_t *, const int16_t *);

#define mlk_reduce_ppc MLK_NAMESPACE(reduce_ppc)
void mlk_reduce_ppc(int16_t *r, const int16_t *);

#define mlk_poly_tomont_ppc MLK_NAMESPACE(poly_tomont_ppc)
void mlk_poly_tomont_ppc(int16_t *, const int16_t *);

#endif /* !MLK_DEV_PPC64LE_SRC_ARITH_NATIVE_PPC64LE_H */
132 changes: 132 additions & 0 deletions dev/ppc64le/src/consts.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright (c) The mlkem-native project authors
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
*/

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "../../../common.h"

#if defined(MLK_ARITH_BACKEND_PPC64LE_DEFAULT) && \
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)

#include "consts.h"

MLK_ALIGN const int16_t mlk_ppc_qdata[1072] = {
/* -Q */
-3329, -3329, -3329, -3329, -3329, -3329, -3329, -3329,
/* QINV */
-3327, -3327, -3327, -3327, -3327, -3327, -3327, -3327,
/* Q */
3329, 3329, 3329, 3329, 3329, 3329, 3329, 3329,
/* const 20159 for reduce.S and intt */
20159, 20159, 20159, 20159, 20159, 20159, 20159, 20159,
/* const 1441 for intt */
1441, 1441, 1441, 1441, 1441, 1441, 1441, 1441,
/* for poly_tomont.S */
1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353,
/* zetas */
/* For ntt Len=128, offset 96 */
-758, -758, -758, -758, -758, -758, -758, -758, -359, -359, -359, -359,
-359, -359, -359, -359, -1517, -1517, -1517, -1517, -1517, -1517, -1517,
-1517, 1493, 1493, 1493, 1493, 1493, 1493, 1493, 1493, 1422, 1422, 1422,
1422, 1422, 1422, 1422, 1422, 287, 287, 287, 287, 287, 287, 287, 287, 202,
202, 202, 202, 202, 202, 202, 202, -171, -171, -171, -171, -171, -171, -171,
-171, 622, 622, 622, 622, 622, 622, 622, 622, 1577, 1577, 1577, 1577, 1577,
1577, 1577, 1577, 182, 182, 182, 182, 182, 182, 182, 182, 962, 962, 962,
962, 962, 962, 962, 962, -1202, -1202, -1202, -1202, -1202, -1202, -1202,
-1202, -1474, -1474, -1474, -1474, -1474, -1474, -1474, -1474, 1468, 1468,
1468, 1468, 1468, 1468, 1468, 1468, 573, 573, 573, 573, 573, 573, 573, 573,
-1325, -1325, -1325, -1325, -1325, -1325, -1325, -1325, 264, 264, 264, 264,
264, 264, 264, 264, 383, 383, 383, 383, 383, 383, 383, 383, -829, -829,
-829, -829, -829, -829, -829, -829, 1458, 1458, 1458, 1458, 1458, 1458,
1458, 1458, -1602, -1602, -1602, -1602, -1602, -1602, -1602, -1602, -130,
-130, -130, -130, -130, -130, -130, -130, -681, -681, -681, -681, -681,
-681, -681, -681, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 732, 732,
732, 732, 732, 732, 732, 732, 608, 608, 608, 608, 608, 608, 608, 608, -1542,
-1542, -1542, -1542, -1542, -1542, -1542, -1542, 411, 411, 411, 411, 411,
411, 411, 411, -205, -205, -205, -205, -205, -205, -205, -205, -1571, -1571,
-1571, -1571, -1571, -1571, -1571, -1571,
/* For Len=4 */
1223, 1223, 1223, 1223, 652, 652, 652, 652, -552, -552, -552, -552, 1015,
1015, 1015, 1015, -1293, -1293, -1293, -1293, 1491, 1491, 1491, 1491, -282,
-282, -282, -282, -1544, -1544, -1544, -1544, 516, 516, 516, 516, -8, -8,
-8, -8, -320, -320, -320, -320, -666, -666, -666, -666, -1618, -1618, -1618,
-1618, -1162, -1162, -1162, -1162, 126, 126, 126, 126, 1469, 1469, 1469,
1469, -853, -853, -853, -853, -90, -90, -90, -90, -271, -271, -271, -271,
830, 830, 830, 830, 107, 107, 107, 107, -1421, -1421, -1421, -1421, -247,
-247, -247, -247, -951, -951, -951, -951, -398, -398, -398, -398, 961, 961,
961, 961, -1508, -1508, -1508, -1508, -725, -725, -725, -725, 448, 448, 448,
448, -1065, -1065, -1065, -1065, 677, 677, 677, 677, -1275, -1275, -1275,
-1275,
/*
* For ntt Len=2
* reorder zeta array, (1, 2, 3, 4) -> (3, 1, 4, 2)
* Transpose z[0], z[1], z[2], z[3]
* -> z[3], z[3], z[1], z[1], z[4], z[4], z[2], z[2]
*/
555, 555, -1103, -1103, 843, 843, 430, 430, 1550, 1550, -1251, -1251, 105,
105, 871, 871, 177, 177, 422, 422, -235, -235, 587, 587, 1574, 1574, -291,
-291, 1653, 1653, -460, -460, 1159, 1159, -246, -246, -147, -147, 778, 778,
-602, -602, -777, -777, 1119, 1119, 1483, 1483, -872, -872, -1590, -1590,
349, 349, 644, 644, -156, -156, 418, 418, -75, -75, 329, 329, 603, 603, 817,
817, 610, 610, 1097, 1097, -1465, -1465, 1322, 1322, 384, 384, -1285, -1285,
1218, 1218, -1215, -1215, -1335, -1335, -136, -136, -1187, -1187, -874,
-874, -1659, -1659, 220, 220, -1278, -1278, -1185, -1185, 794, 794, -1530,
-1530, -870, -870, -1510, -1510, 478, 478, -854, -854, 996, 996, -108, -108,
991, 991, -308, -308, 1522, 1522, 958, 958, 1628, 1628, -1460, -1460,
/*
* For intt Len=2, offset IZETA_NTT_OFFSET127
* reorder zeta array, (1, 2, 3, 4) -> (3, 1, 4, 2)
* Transpose z[0], z[1], z[2], z[3]
* -> z[3], z[3], z[1], z[1], z[4], z[4], z[2], z[2]
*/
-1460, -1460, 1628, 1628, 958, 958, 1522, 1522, -308, -308, 991, 991, -108,
-108, 996, 996, -854, -854, 478, 478, -1510, -1510, -870, -870, -1530,
-1530, 794, 794, -1185, -1185, -1278, -1278, 220, 220, -1659, -1659, -874,
-874, -1187, -1187, -136, -136, -1335, -1335, -1215, -1215, 1218, 1218,
-1285, -1285, 384, 384, 1322, 1322, -1465, -1465, 1097, 1097, 610, 610, 817,
817, 603, 603, 329, 329, -75, -75, 418, 418, -156, -156, 644, 644, 349, 349,
-1590, -1590, -872, -872, 1483, 1483, 1119, 1119, -777, -777, -602, -602,
778, 778, -147, -147, -246, -246, 1159, 1159, -460, -460, 1653, 1653, -291,
-291, 1574, 1574, 587, 587, -235, -235, 422, 422, 177, 177, 871, 871, 105,
105, -1251, -1251, 1550, 1550, 430, 430, 843, 843, -1103, -1103, 555, 555,
/* For intt Len=4 */
-1275, -1275, -1275, -1275, 677, 677, 677, 677, -1065, -1065, -1065, -1065,
448, 448, 448, 448, -725, -725, -725, -725, -1508, -1508, -1508, -1508, 961,
961, 961, 961, -398, -398, -398, -398, -951, -951, -951, -951, -247, -247,
-247, -247, -1421, -1421, -1421, -1421, 107, 107, 107, 107, 830, 830, 830,
830, -271, -271, -271, -271, -90, -90, -90, -90, -853, -853, -853, -853,
1469, 1469, 1469, 1469, 126, 126, 126, 126, -1162, -1162, -1162, -1162,
-1618, -1618, -1618, -1618, -666, -666, -666, -666, -320, -320, -320, -320,
-8, -8, -8, -8, 516, 516, 516, 516, -1544, -1544, -1544, -1544, -282, -282,
-282, -282, 1491, 1491, 1491, 1491, -1293, -1293, -1293, -1293, 1015, 1015,
1015, 1015, -552, -552, -552, -552, 652, 652, 652, 652, 1223, 1223, 1223,
1223,
/* For intt Len=8 and others */
-1571, -1571, -1571, -1571, -1571, -1571, -1571, -1571, -205, -205, -205,
-205, -205, -205, -205, -205, 411, 411, 411, 411, 411, 411, 411, 411, -1542,
-1542, -1542, -1542, -1542, -1542, -1542, -1542, 608, 608, 608, 608, 608,
608, 608, 608, 732, 732, 732, 732, 732, 732, 732, 732, 1017, 1017, 1017,
1017, 1017, 1017, 1017, 1017, -681, -681, -681, -681, -681, -681, -681,
-681, -130, -130, -130, -130, -130, -130, -130, -130, -1602, -1602, -1602,
-1602, -1602, -1602, -1602, -1602, 1458, 1458, 1458, 1458, 1458, 1458, 1458,
1458, -829, -829, -829, -829, -829, -829, -829, -829, 383, 383, 383, 383,
383, 383, 383, 383, 264, 264, 264, 264, 264, 264, 264, 264, -1325, -1325,
-1325, -1325, -1325, -1325, -1325, -1325, 573, 573, 573, 573, 573, 573, 573,
573, 1468, 1468, 1468, 1468, 1468, 1468, 1468, 1468, -1474, -1474, -1474,
-1474, -1474, -1474, -1474, -1474, -1202, -1202, -1202, -1202, -1202, -1202,
-1202, -1202, 962, 962, 962, 962, 962, 962, 962, 962, 182, 182, 182, 182,
182, 182, 182, 182, 1577, 1577, 1577, 1577, 1577, 1577, 1577, 1577, 622,
622, 622, 622, 622, 622, 622, 622, -171, -171, -171, -171, -171, -171, -171,
-171, 202, 202, 202, 202, 202, 202, 202, 202, 287, 287, 287, 287, 287, 287,
287, 287, 1422, 1422, 1422, 1422, 1422, 1422, 1422, 1422, 1493, 1493, 1493,
1493, 1493, 1493, 1493, 1493, -1517, -1517, -1517, -1517, -1517, -1517,
-1517, -1517, -359, -359, -359, -359, -359, -359, -359, -359, -758, -758,
-758, -758, -758, -758, -758, -758};

#endif /* MLK_ARITH_BACKEND_PPC64LE_DEFAULT && \
!MLK_CONFIG_MULTILEVEL_NO_SHARED */
24 changes: 24 additions & 0 deletions dev/ppc64le/src/consts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) The mlkem-native project authors
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
*/

#ifndef MLK_DEV_PPC64LE_SRC_CONSTS_H
#define MLK_DEV_PPC64LE_SRC_CONSTS_H
#include "../../../common.h"

#define NQ_OFFSET 0
#define QINV_OFFSET 16
#define Q_OFFSET 32
#define C20159_OFFSET 48
#define C1441_OFFSET 64
#define C1353_OFFSET 80
#define ZETA_NTT_OFFSET 96
#define ZETA_INTT_OFFSET 1104

#ifndef __ASSEMBLER__
#define mlk_ppc_qdata MLK_NAMESPACE(ppc_qdata)
extern const int16_t mlk_ppc_qdata[];
#endif

#endif /* !MLK_DEV_PPC64LE_SRC_CONSTS_H */
Loading