/* #define MPMONT_DISABLE */
+#define MPMONT_KTHRESH (16*MPK_THRESH)
+
/*----- Low-level implementation ------------------------------------------*/
#ifndef MPMONT_DISABLE
MAYBE_REDC4(x86_sse2)
#endif
+#if CPUFAM_AMD64
+ MAYBE_REDC4(amd64_sse2)
+#endif
+
static redccore__functype *pick_redccore(void)
{
#if CPUFAM_X86
DISPATCH_PICK_COND(mpmont_reduce, maybe_redc4_x86_sse2,
cpu_feature_p(CPUFEAT_X86_SSE2));
#endif
+#if CPUFAM_AMD64
+ DISPATCH_PICK_COND(mpmont_reduce, maybe_redc4_amd64_sse2,
+ cpu_feature_p(CPUFEAT_X86_SSE2));
+#endif
DISPATCH_PICK_FALLBACK(mpmont_reduce, simple_redccore);
}
MAYBE_MUL4(x86_sse2)
#endif
+#if CPUFAM_AMD64
+ MAYBE_MUL4(amd64_sse2)
+#endif
+
static mulcore__functype *pick_mulcore(void)
{
#if CPUFAM_X86
DISPATCH_PICK_COND(mpmont_mul, maybe_mul4_x86_sse2,
cpu_feature_p(CPUFEAT_X86_SSE2));
#endif
+#if CPUFAM_AMD64
+ DISPATCH_PICK_COND(mpmont_mul, maybe_mul4_amd64_sse2,
+ cpu_feature_p(CPUFEAT_X86_SSE2));
+#endif
DISPATCH_PICK_FALLBACK(mpmont_mul, simple_mulcore);
}
/* --- @finish@ --- *
*
- * Arguments: @mpmont *mm@ = pointer to a Montgomery reduction context
+ * Arguments: @const mpmont *mm@ = pointer to a Montgomery reduction
+ * context
* *mp *d@ = pointer to mostly-reduced operand
*
* Returns: ---
* need to do an additional subtraction if %$d$% is negative.
*/
-static void finish(mpmont *mm, mp *d)
+static void finish(const mpmont *mm, mp *d)
{
mpw *dv = d->v, *dvl = d->vl;
size_t n = mm->n;
/* --- @mpmont_reduce@ --- *
*
- * Arguments: @mpmont *mm@ = pointer to Montgomery reduction context
+ * Arguments: @const mpmont *mm@ = pointer to Montgomery reduction context
* @mp *d@ = destination
* @mp *a@ = source, assumed positive
*
#ifdef MPMONT_DISABLE
-mp *mpmont_reduce(mpmont *mm, mp *d, mp *a)
+mp *mpmont_reduce(const mpmont *mm, mp *d, mp *a)
{
mp_div(0, &d, a, mm->m);
return (d);
#else
-mp *mpmont_reduce(mpmont *mm, mp *d, mp *a)
+mp *mpmont_reduce(const mpmont *mm, mp *d, mp *a)
{
size_t n = mm->n;
/* --- Check for serious Karatsuba reduction --- */
- if (n > MPK_THRESH * 3) {
+ if (n > MPMONT_KTHRESH) {
mp al;
mpw *vl;
mp *u;
/* --- @mpmont_mul@ --- *
*
- * Arguments: @mpmont *mm@ = pointer to Montgomery reduction context
+ * Arguments: @const mpmont *mm@ = pointer to Montgomery reduction context
* @mp *d@ = destination
* @mp *a, *b@ = sources, assumed positive
*
#ifdef MPMONT_DISABLE
-mp *mpmont_mul(mpmont *mm, mp *d, mp *a, mp *b)
+mp *mpmont_mul(const mpmont *mm, mp *d, mp *a, mp *b)
{
d = mp_mul(d, a, b);
mp_div(0, &d, d, mm->m);
#else
-mp *mpmont_mul(mpmont *mm, mp *d, mp *a, mp *b)
+mp *mpmont_mul(const mpmont *mm, mp *d, mp *a, mp *b)
{
size_t n = mm->n;
- if (n > MPK_THRESH * 3) {
+ if (n > MPMONT_KTHRESH) {
d = mp_mul(d, a, b);
d = mpmont_reduce(mm, d, d);
} else {