diff options
| author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-11-07 14:56:58 (GMT) |
|---|---|---|
| committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-11-07 14:56:58 (GMT) |
| commit | 208e4fd87b7123289717f2a292a056da196f3665 (patch) | |
| tree | 007249b8ff790b61ab5bb160ff9a5b0915cac892 | |
| parent | bdf8f9cc31ac1d71dbb46090b4f5d1c69c3cd4bd (diff) | |
| download | tcl-208e4fd87b7123289717f2a292a056da196f3665.zip tcl-208e4fd87b7123289717f2a292a056da196f3665.tar.gz tcl-208e4fd87b7123289717f2a292a056da196f3665.tar.bz2 | |
Make mp_mul(a,a,c) equivalent to mp_sqr(a,c). Optimization backported from libtommath.
| -rw-r--r-- | libtommath/bn_mp_mul.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/libtommath/bn_mp_mul.c b/libtommath/bn_mp_mul.c index 561913a..b00334d 100644 --- a/libtommath/bn_mp_mul.c +++ b/libtommath/bn_mp_mul.c @@ -12,7 +12,9 @@ mp_err mp_mul(const mp_int *a, const mp_int *b, mp_int *c) digs = a->used + b->used + 1; mp_sign neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG; - if (MP_HAS(S_MP_BALANCE_MUL) && + if (a == b) { + return mp_sqr(a,c); + } else if (MP_HAS(S_MP_BALANCE_MUL) && /* Check sizes. The smaller one needs to be larger than the Karatsuba cut-off. * The bigger one needs to be at least about one MP_KARATSUBA_MUL_CUTOFF bigger * to make some sense, but it depends on architecture, OS, position of the |
