libzahl

big integer library
git clone git://git.suckless.org/libzahl
Log | Files | Refs | README | LICENSE

commit 659a5a81045af899310dca5f70907da287c56d19
parent 8cfddc81a437ec86fdf3afd2156eac8bd78f88b8
Author: Mattias Andrée <maandree@kth.se>
Date:   Wed, 27 Apr 2016 14:35:13 +0200

Optimise zpowu and zmodpowu

Signed-off-by: Mattias Andrée <maandree@kth.se>

Diffstat:
Msrc/zmodpowu.c | 6++++--
Msrc/zpowu.c | 6++++--
2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/zmodpowu.c b/src/zmodpowu.c @@ -27,9 +27,11 @@ zmodpowu(z_t a, z_t b, unsigned long long int c, z_t d) zset(td, d); zsetu(a, 1); - for (; c; c >>= 1) { + if (c & 1) + zmodmul(a, a, tb, td); + while (c >>= 1) { + zmodsqr(tb, tb, td); if (c & 1) zmodmul(a, a, tb, td); - zmodsqr(tb, tb, td); } } diff --git a/src/zpowu.c b/src/zpowu.c @@ -23,10 +23,12 @@ zpowu(z_t a, z_t b, unsigned long long int c) zabs(tb, b); zsetu(a, 1); - for (; c; c >>= 1) { + if (c & 1) + zmul_impl(a, a, tb); + while (c >>= 1) { + zsqr_impl(tb, tb); if (c & 1) zmul_impl(a, a, tb); - zsqr_impl(tb, tb); } if (neg)