aboutsummaryrefslogtreecommitdiffstats
path: root/src/zpowu.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-04-27 14:35:13 +0200
committerMattias Andrée <maandree@kth.se>2016-04-27 14:35:13 +0200
commit659a5a81045af899310dca5f70907da287c56d19 (patch)
tree833b6e637a4a7ccadaea45567d5ff87f192e1eb3 /src/zpowu.c
parentAdd error checking to tomsfastmath translation and sort includes (diff)
downloadlibzahl-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/zpowu.c')
-rw-r--r--src/zpowu.c6
1 files changed, 4 insertions, 2 deletions
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)