libzahl

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

commit cf5f82f17769ad3f6729dc1344acc5431ae5344d
parent d2ec8006ca45753b6a404cd7ccbf7092d876c660
Author: Mattias Andrée <maandree@kth.se>
Date:   Wed, 27 Apr 2016 02:27:52 +0200

Functions in the translation layers should static inline. Probably not always fair...

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

Diffstat:
Mbench/libgmp.h | 20++++++++++----------
Mbench/libhebimath.h | 36+++++++++++++++++++-----------------
Mbench/libtfm.h | 32++++++++++++++++----------------
Mbench/libtommath.h | 18+++++++++---------
4 files changed, 54 insertions(+), 52 deletions(-)

diff --git a/bench/libgmp.h b/bench/libgmp.h @@ -14,7 +14,7 @@ static z_t _0, _1, _a, _b; static FILE *_fbuf; static gmp_randstate_t _randstate; -static void +static inline void zsetup(jmp_buf env) { static char buf[1000]; @@ -27,7 +27,7 @@ zsetup(jmp_buf env) gmp_randinit_mt(_randstate); } -static void +static inline void zunsetup(void) { mpz_clear(_0); @@ -97,7 +97,7 @@ zunsetup(void) #define zmod mpz_tdiv_r #define zdivmod mpz_tdiv_qr -static void +static inline void zsetu(z_t r, unsigned long long int val) { uint32_t high = (uint32_t)(val >> 32); @@ -114,7 +114,7 @@ zsetu(z_t r, unsigned long long int val) } -static void +static inline void zseti(z_t r, long long int val) { if (val >= 0) { @@ -125,7 +125,7 @@ zseti(z_t r, long long int val) } } -static void +static inline void znot(z_t r, z_t a) { size_t bits = zbits(a); @@ -136,7 +136,7 @@ znot(z_t r, z_t a) zneg(r, r); } -static void +static inline void zsplit(z_t high, z_t low, z_t a, size_t brk) { if (low == a) { @@ -148,7 +148,7 @@ zsplit(z_t high, z_t low, z_t a, size_t brk) } } -static void +static inline void zbset(z_t r, z_t a, size_t bit, int mode) { if (r != a) @@ -161,7 +161,7 @@ zbset(z_t r, z_t a, size_t bit, int mode) mpz_combit(r, bit); } -static size_t +static inline size_t zsave(z_t a, void *buffer) { size_t n = mpz_out_raw(_fbuf, a); @@ -170,7 +170,7 @@ zsave(z_t a, void *buffer) return n; } -static size_t +static inline size_t zload(z_t a, const void *buffer) { size_t n = mpz_inp_raw(a, _fbuf); @@ -179,7 +179,7 @@ zload(z_t a, const void *buffer) return n; } -static void +static inline void zrand(z_t r, int dev, int dist, z_t n) { size_t bits; diff --git a/bench/libhebimath.h b/bench/libhebimath.h @@ -12,7 +12,7 @@ typedef hebi_int z_t[1]; static z_t _0, _1, _a, _b, _m; -static void +static inline void zsetup(jmp_buf env) { (void) env; @@ -23,7 +23,7 @@ zsetup(jmp_buf env) hebi_init(_m); } -static void +static inline void zunsetup(void) { hebi_destroy(_0); @@ -86,7 +86,7 @@ zunsetup(void) #define zsave(a, s) zstr(a, s, sizeof(s) - 1) #define zload(a, s) zsets(a, s) -static size_t +static inline size_t zbits(z_t a) { hebi_uword x = x; @@ -106,7 +106,7 @@ zbits(z_t a) return rc; } -static size_t +static inline size_t zlsb(z_t a) { hebi_uword x; @@ -125,7 +125,7 @@ zlsb(z_t a) return rc; } -static void +static inline void zptest(z_t w, z_t a, int t) { static int gave_up = 0; @@ -138,7 +138,7 @@ zptest(z_t w, z_t a, int t) (void) t; } -static void +static inline void zpowu(z_t r, z_t a, unsigned long long int b) { int neg = zsignum(a) < 0; @@ -153,7 +153,7 @@ zpowu(z_t r, z_t a, unsigned long long int b) zneg(r, r); } -static void +static inline void zmodpowu(z_t r, z_t a, unsigned long long int b, z_t m) { int neg = zsignum(a) < 0; @@ -169,7 +169,7 @@ zmodpowu(z_t r, z_t a, unsigned long long int b, z_t m) zneg(r, r); } -static size_t +static inline size_t zstr_length(z_t a, unsigned long long int radix) { size_t size_total = 1, size_temp; @@ -190,7 +190,7 @@ zstr_length(z_t a, unsigned long long int radix) return size_total + (zsignum(a) < 0); } -static void +static inline void zsplit(z_t high, z_t low, z_t a, size_t brk) { if (low == a) { @@ -202,7 +202,7 @@ zsplit(z_t high, z_t low, z_t a, size_t brk) } } -static void +static inline void zbset(z_t r, z_t a, size_t bit, int mode) { zrsh(_a, a, bit); @@ -217,7 +217,7 @@ zbset(z_t r, z_t a, size_t bit, int mode) } } -static void +static inline void zrand(z_t r, int dev, int dist, z_t n) { static int gave_up[] = {0, 0, 0}; @@ -230,7 +230,7 @@ zrand(z_t r, int dev, int dist, z_t n) (void) n; } -static void +static inline void zand(z_t r, z_t a, z_t b) { int neg = hebi_sign(a) < 0 && hebi_sign(b) < 0; @@ -251,7 +251,7 @@ zand(z_t r, z_t a, z_t b) zneg(r, r); } -static void +static inline void zor(z_t r, z_t a, z_t b) { int neg = hebi_sign(a) < 0 || hebi_sign(b) < 0; @@ -272,7 +272,7 @@ zor(z_t r, z_t a, z_t b) zneg(r, r); } -static void +static inline void zxor(z_t r, z_t a, z_t b) { int neg = (hebi_sign(a) < 0) ^ (hebi_sign(b) < 0); @@ -293,7 +293,7 @@ zxor(z_t r, z_t a, z_t b) zneg(r, r); } -void +static inline void zgcd(z_t r, z_t a, z_t b) { size_t shifts, a_lsb, b_lsb; @@ -333,7 +333,7 @@ zgcd(z_t r, z_t a, z_t b) zneg(r, r); } -static void +static inline void znot(z_t r, z_t a) { size_t bits = zbits(a); @@ -346,7 +346,9 @@ znot(z_t r, z_t a) zneg(r, r); } -int +/* Prototype declared, but implementation missing, in hebimath */ + +staint hebi_shl(hebi_int *r, const hebi_int *a, unsigned int b) { zsetu(_a, 2); diff --git a/bench/libtfm.h b/bench/libtfm.h @@ -12,7 +12,7 @@ typedef fp_int z_t[1]; static z_t _0, _1, _a, _b; static int _tmp; -static void +static inline void fp_set_int(z_t a, uint32_t d) { a->dp[0] = d; @@ -20,7 +20,7 @@ fp_set_int(z_t a, uint32_t d) a->sign = 0; } -static void +static inline void zsetup(jmp_buf env) { (void) env; @@ -32,7 +32,7 @@ zsetup(jmp_buf env) fp_set_int(_1, 1); } -static void +static inline void zunsetup(void) { /* Do nothing */ @@ -102,7 +102,7 @@ zabs(z_t r, z_t a) fp_abs(a, r); } -static void +static inline void zswap(z_t a, z_t b) { z_t t; @@ -111,7 +111,7 @@ zswap(z_t a, z_t b) fp_copy(t, b); } -static void +static inline void zand(z_t r, z_t a, z_t b) { int i; @@ -123,7 +123,7 @@ zand(z_t r, z_t a, z_t b) r->sign = a->sign & b->sign; } -static void +static inline void zor(z_t r, z_t a, z_t b) { int i; @@ -137,7 +137,7 @@ zor(z_t r, z_t a, z_t b) r->sign = a->sign | b->sign; } -static void +static inline void zxor(z_t r, z_t a, z_t b) { int i; @@ -153,14 +153,14 @@ zxor(z_t r, z_t a, z_t b) r->sign = a->sign ^ b->sign; } -static int +static inline int zsave(z_t a, char *buf) { _tmp = buf ? fp_signed_bin_size(a) : (fp_to_signed_bin(a, (unsigned char *)buf), 0); return _tmp; } -static void +static inline void zsetu(z_t r, unsigned long long int val) { uint32_t high = (uint32_t)(val >> 32); @@ -177,7 +177,7 @@ zsetu(z_t r, unsigned long long int val) } -static void +static inline void zseti(z_t r, long long int val) { if (val >= 0) { @@ -188,7 +188,7 @@ zseti(z_t r, long long int val) } } -static void +static inline void zsplit(z_t high, z_t low, z_t a, size_t brk) { if (low == a) { @@ -200,7 +200,7 @@ zsplit(z_t high, z_t low, z_t a, size_t brk) } } -static void +static inline void znot(z_t r, z_t a) { fp_2expt(_a, (int)zbits(a)); @@ -209,7 +209,7 @@ znot(z_t r, z_t a) zneg(r, r); } -static int +static inline int zbtest(z_t a, size_t bit) { fp_2expt(_b, (int)bit); @@ -217,7 +217,7 @@ zbtest(z_t a, size_t bit) return !zzero(_b); } -static void +static inline void zbset(z_t r, z_t a, size_t bit, int mode) { if (mode > 0) { @@ -229,7 +229,7 @@ zbset(z_t r, z_t a, size_t bit, int mode) } } -static void +static inline void zrand(z_t r, int dev, int dist, z_t n) { static int gave_up = 0; @@ -272,7 +272,7 @@ zrand(z_t r, int dev, int dist, z_t n) } } -static void +static inline void zpowu(z_t r, z_t a, unsigned long long int b) { int neg = zsignum(a) < 0; diff --git a/bench/libtommath.h b/bench/libtommath.h @@ -30,7 +30,7 @@ static jmp_buf jbuf; # define try(expr) do if ((error = (expr))) longjmp(jbuf, 1); while (0) #endif -static void +static inline void zsetup(jmp_buf env) { *jbuf = *env; @@ -40,7 +40,7 @@ zsetup(jmp_buf env) try(mp_init(_b)); } -static void +static inline void zunsetup(void) { mp_clear(_0); @@ -176,7 +176,7 @@ zxor(z_t r, z_t a, z_t b) try(mp_xor(a, b, r)); } -static void +static inline void znot(z_t r, z_t a) { try(mp_2expt(_a, (int)zbits(a))); @@ -185,7 +185,7 @@ znot(z_t r, z_t a) zneg(r, r); } -static int +static inline int zbtest(z_t a, size_t bit) { try(mp_2expt(_b, (int)bit)); @@ -193,7 +193,7 @@ zbtest(z_t a, size_t bit) return !zzero(_b); } -static void +static inline void zbset(z_t r, z_t a, size_t bit, int mode) { if (mode > 0) { @@ -229,7 +229,7 @@ ztrunc(z_t r, z_t a, size_t b) try(mp_mod_2d(a, (int)b, r)); } -static void +static inline void zsplit(z_t high, z_t low, z_t a, size_t brk) { if (low == a) { @@ -241,13 +241,13 @@ zsplit(z_t high, z_t low, z_t a, size_t brk) } } -static void +static inline void zsetu(z_t r, unsigned long long int val) { try(mp_set_long_long(r, val)); } -static void +static inline void zseti(z_t r, long long int val) { if (val >= 0) { @@ -405,7 +405,7 @@ zdivmod(z_t q, z_t r, z_t a, z_t b) try(mp_div(a, b, q, r)); } -static void +static inline void zrand(z_t r, int dev, int dist, z_t n) { static int gave_up = 0;