diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-04-27 14:35:13 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-04-27 14:35:13 +0200 |
| commit | 659a5a81045af899310dca5f70907da287c56d19 (patch) | |
| tree | 833b6e637a4a7ccadaea45567d5ff87f192e1eb3 /src | |
| parent | Add error checking to tomsfastmath translation and sort includes (diff) | |
| download | libzahl-659a5a81045af899310dca5f70907da287c56d19.tar.gz libzahl-659a5a81045af899310dca5f70907da287c56d19.tar.bz2 libzahl-659a5a81045af899310dca5f70907da287c56d19.tar.xz | |
Optimise zpowu and zmodpowu
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src')
| -rw-r--r-- | src/zmodpowu.c | 6 | ||||
| -rw-r--r-- | src/zpowu.c | 6 |
2 files changed, 8 insertions, 4 deletions
diff --git a/src/zmodpowu.c b/src/zmodpowu.c index c9c8af5..fd5e925 100644 --- 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 index 9618010..3d58aa4 100644 --- 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) |
