Skip to content

Commit eb3ba6b

Browse files
committed
multi_scalar.c: fine-tune MSM for small amounts of inputs.
Fixes supranational#235.
1 parent bef14ca commit eb3ba6b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/multi_scalar.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,14 @@ static size_t pippenger_window_size(size_t npoints)
267267

268268
for (wbits=0; npoints>>=1; wbits++) ;
269269

270-
return wbits>12 ? wbits-3 : (wbits>4 ? wbits-2 : (wbits ? 2 : 1));
270+
if (wbits > 12)
271+
return wbits - 3;
272+
else if (wbits > 8)
273+
return wbits - 2;
274+
else if (wbits > 4)
275+
return wbits - 1;
276+
277+
return wbits ? 2 : 1;
271278
}
272279

273280
#define DECLARE_PRIVATE_POINTXYZZ(ptype, bits) \
@@ -402,10 +409,11 @@ void prefix##s_mult_pippenger(ptype *ret, \
402409
{ \
403410
if (npoints == 1) { \
404411
prefix##_from_affine(ret, points[0]); \
405-
prefix##_mult(ret, ret, scalars[0], nbits); \
412+
ptype##_mult_w5(ret, ret, scalars[0], nbits); \
406413
return; \
407414
} \
408-
if ((npoints * sizeof(ptype##_affine) * 8 * 3) <= SCRATCH_LIMIT) { \
415+
if ((npoints * sizeof(ptype##_affine) * 8 * 3) <= SCRATCH_LIMIT && \
416+
npoints < 32) { \
409417
ptype##_affine *table = alloca(npoints * sizeof(ptype##_affine) * 8); \
410418
ptype##s_precompute_wbits(table, 4, points, npoints); \
411419
ptype##s_mult_wbits(ret, table, 4, npoints, scalars, nbits, NULL); \

0 commit comments

Comments
 (0)