From 8c2ad212d78184d59e4181993c195b35c4cde166 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 27 Apr 2016 13:30:47 +0200 Subject: Improve library translations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- bench/libtfm.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'bench/libtfm.h') diff --git a/bench/libtfm.h b/bench/libtfm.h index c4cc02b..5b872e1 100644 --- a/bench/libtfm.h +++ b/bench/libtfm.h @@ -10,7 +10,8 @@ typedef fp_int z_t[1]; static z_t _0, _1, _a, _b; -static int _tmp; +static int _tmp, error; +static jmp_buf jbuf; static inline void fp_set_int(z_t a, uint32_t d) @@ -23,7 +24,7 @@ fp_set_int(z_t a, uint32_t d) static inline void zsetup(jmp_buf env) { - (void) env; + *jbuf = *env; fp_init(_0); fp_init(_1); fp_init(_a); @@ -275,7 +276,14 @@ zrand(z_t r, int dev, int dist, z_t n) static inline void zpowu(z_t r, z_t a, unsigned long long int b) { - int neg = zsignum(a) < 0; + if (!b) { + if (zzero(a)) { + error = FP_VAL; + longjmp(jbuf, 1); + } + zsetu(r, 1); + return; + } zset(_a, a); zsetu(r, 1); for (; b; b >>= 1) { @@ -283,6 +291,4 @@ zpowu(z_t r, z_t a, unsigned long long int b) zmul(r, r, _a); zsqr(_a, _a); } - if (neg) - zneg(r, r); } -- cgit v1.2.3-70-g09d2