Skip to content

Commit

Permalink
shortcut some tests when mulmod_shoup_threshold is small
Browse files Browse the repository at this point in the history
  • Loading branch information
vneiger committed Sep 4, 2024
1 parent e11f10d commit 21c0ff4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/nmod_mat/scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ nmod_mat_scalar_addmul_ui(nmod_mat_t C, const nmod_mat_t A, const nmod_mat_t B,
nmod_mat_add(C, A, B);
else if (c == A->mod.n - UWORD(1))
nmod_mat_sub(C, A, B);
#if FLINT_MULMOD_SHOUP_THRESHOLD == 0
else if (A->mod.norm > 0)
#else
else if (A->r * A->c > FLINT_MULMOD_SHOUP_THRESHOLD && A->mod.norm > 0)
#endif
{
const ulong c_pr = n_mulmod_precomp_shoup(c, A->mod.n);
_nmod_mat_scalar_addmul_ui_precomp(C, A, B, c, c_pr);
Expand Down Expand Up @@ -104,7 +108,11 @@ nmod_mat_scalar_mul(nmod_mat_t B, const nmod_mat_t A, ulong c)
nmod_mat_set(B, A);
else if (c == A->mod.n - UWORD(1))
nmod_mat_neg(B, A);
#if FLINT_MULMOD_SHOUP_THRESHOLD == 0
else if (A->mod.norm > 0)
#else
else if (A->r * A->c > FLINT_MULMOD_SHOUP_THRESHOLD && A->mod.norm > 0)
#endif
{
const ulong c_pr = n_mulmod_precomp_shoup(c, A->mod.n);
_nmod_mat_scalar_mul_precomp(B, A, c, c_pr);
Expand Down
4 changes: 4 additions & 0 deletions src/nmod_poly/evaluate_nmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,12 @@ nmod_poly_evaluate_nmod(const nmod_poly_t poly, ulong c)

// if degree below the n_mulmod_shoup threshold
// or modulus forbids n_mulmod_shoup usage, use nmod_mul
#if FLINT_MULMOD_SHOUP_THRESHOLD < 2
if (poly->mod.norm == 0) // here poly->length >= threshold
#else
if ((poly->length <= FLINT_MULMOD_SHOUP_THRESHOLD)
|| (poly->mod.norm == 0))
#endif
{
return _nmod_poly_evaluate_nmod(poly->coeffs, poly->length, c, poly->mod);
}
Expand Down
10 changes: 10 additions & 0 deletions src/nmod_vec/scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,15 @@ void _nmod_vec_scalar_addmul_nmod(nn_ptr res, nn_srcptr vec,
_nmod_vec_sub(res, res, vec, len, mod);
else if (NMOD_BITS(mod) == FLINT_BITS)
_nmod_vec_scalar_addmul_nmod_fullword(res, vec, len, c, mod);
#if FLINT_MULMOD_SHOUP_THRESHOLD == 0
else
_nmod_vec_scalar_addmul_nmod_shoup(res, vec, len, c, mod);
#else
else if (len > FLINT_MULMOD_SHOUP_THRESHOLD)
_nmod_vec_scalar_addmul_nmod_shoup(res, vec, len, c, mod);
else
_nmod_vec_scalar_addmul_nmod_generic(res, vec, len, c, mod);
#endif
}

void _nmod_vec_scalar_mul_nmod_fullword(nn_ptr res, nn_srcptr vec,
Expand Down Expand Up @@ -108,8 +113,13 @@ void _nmod_vec_scalar_mul_nmod(nn_ptr res, nn_srcptr vec,
_nmod_vec_neg(res, vec, len, mod);
else if (NMOD_BITS(mod) == FLINT_BITS)
_nmod_vec_scalar_mul_nmod_fullword(res, vec, len, c, mod);
#if FLINT_MULMOD_SHOUP_THRESHOLD == 0
else
_nmod_vec_scalar_mul_nmod_shoup(res, vec, len, c, mod);
#else
else if (len > FLINT_MULMOD_SHOUP_THRESHOLD)
_nmod_vec_scalar_mul_nmod_shoup(res, vec, len, c, mod);
else
_nmod_vec_scalar_mul_nmod_generic(res, vec, len, c, mod);
#endif
}

0 comments on commit 21c0ff4

Please sign in to comment.