Skip to content

Commit 14b32ec

Browse files
committed
Benchmarks: Add component benchmarks for native functions
- poly_pointwise_montgomery - poly_caddq - poly_chknorm - poly_decompose - poly_use_hint - polyz_unpack Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
1 parent 734e659 commit 14b32ec

1 file changed

Lines changed: 27 additions & 9 deletions

File tree

test/bench_components_mldsa.c

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <string.h>
1111
#include "../mldsa/src/ntt.h"
1212
#include "../mldsa/src/poly.h"
13+
#include "../mldsa/src/poly_kl.h"
1314
#include "../mldsa/src/polyvec.h"
1415
#include "../mldsa/src/randombytes.h"
1516
#include "hal.h"
@@ -23,14 +24,17 @@ static int cmp_uint64_t(const void *a, const void *b)
2324
return (int)((*((const uint64_t *)a)) - (*((const uint64_t *)b)));
2425
}
2526

26-
#define BENCH(txt, code) \
27-
for (i = 0; i < NTESTS; i++) \
28-
{ \
29-
mld_randombytes((uint8_t *)data0, sizeof(data0)); \
30-
mld_randombytes((uint8_t *)&polyvecl_a, sizeof(polyvecl_a)); \
31-
mld_randombytes((uint8_t *)&polyvecl_b, sizeof(polyvecl_b)); \
32-
mld_randombytes((uint8_t *)&polymat, sizeof(polymat)); \
33-
for (j = 0; j < NWARMUP; j++) \
27+
#define BENCH(txt, code) \
28+
for (i = 0; i < NTESTS; i++) \
29+
{ \
30+
mld_randombytes((uint8_t *)data0, sizeof(data0)); \
31+
mld_randombytes((uint8_t *)&poly_out, sizeof(poly_out)); \
32+
mld_randombytes((uint8_t *)&poly_hint, sizeof(poly_hint)); \
33+
mld_randombytes((uint8_t *)&polyvecl_a, sizeof(polyvecl_a)); \
34+
mld_randombytes((uint8_t *)&polyvecl_b, sizeof(polyvecl_b)); \
35+
mld_randombytes((uint8_t *)&polymat, sizeof(polymat)); \
36+
mld_randombytes((uint8_t *)polyz_packed, sizeof(polyz_packed)); \
37+
for (j = 0; j < NWARMUP; j++) \
3438
{ \
3539
code; \
3640
} \
@@ -49,10 +53,11 @@ static int cmp_uint64_t(const void *a, const void *b)
4953
static int bench(void)
5054
{
5155
MLD_ALIGN int32_t data0[256];
52-
MLD_ALIGN mld_poly poly_out;
56+
MLD_ALIGN mld_poly poly_out, poly_a1, poly_a0, poly_hint;
5357
MLD_ALIGN mld_polyvecl polyvecl_a, polyvecl_b;
5458
MLD_ALIGN mld_polyveck polyveck_out;
5559
MLD_ALIGN mld_polymat polymat;
60+
MLD_ALIGN uint8_t polyz_packed[MLDSA_POLYZ_PACKEDBYTES];
5661
uint64_t cyc[NTESTS];
5762
unsigned i, j;
5863
uint64_t t0, t1;
@@ -62,13 +67,26 @@ static int bench(void)
6267
BENCH("poly_invntt_tomont", mld_poly_invntt_tomont((mld_poly *)data0))
6368

6469
/* pointwise */
70+
BENCH("poly_pointwise_montgomery",
71+
mld_poly_pointwise_montgomery(&poly_out, &polyvecl_a.vec[0],
72+
&polyvecl_b.vec[0]))
6573
BENCH("polyvecl_pointwise_acc_montgomery",
6674
mld_polyvecl_pointwise_acc_montgomery(&poly_out, &polyvecl_a,
6775
&polyvecl_b))
6876
BENCH("polyvec_matrix_pointwise_montgomery",
6977
mld_polyvec_matrix_pointwise_montgomery(&polyveck_out, &polymat,
7078
&polyvecl_b))
7179

80+
/* poly arithmetic */
81+
BENCH("poly_caddq", mld_poly_caddq(&poly_out))
82+
BENCH("poly_chknorm", mld_poly_chknorm(&poly_out, MLDSA_GAMMA1 - 1))
83+
BENCH("poly_decompose", mld_poly_decompose(&poly_a1, &poly_a0, &poly_out))
84+
BENCH("poly_use_hint",
85+
mld_poly_use_hint(&poly_out, &polyvecl_a.vec[0], &poly_hint))
86+
87+
/* packing */
88+
BENCH("polyz_unpack", mld_polyz_unpack(&poly_out, polyz_packed))
89+
7290
return 0;
7391
}
7492

0 commit comments

Comments
 (0)