diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-03-13 01:04:48 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-03-13 01:05:00 +0100 |
| commit | 58baaf9eaa1a0519766b9f5aabb510e1e6969d6c (patch) | |
| tree | d0ee04f49deebd2f4940e24dafa1b7d77e273aeb | |
| parent | Add possibility to compare against libgmp (diff) | |
| download | libzahl-58baaf9eaa1a0519766b9f5aabb510e1e6969d6c.tar.gz libzahl-58baaf9eaa1a0519766b9f5aabb510e1e6969d6c.tar.bz2 libzahl-58baaf9eaa1a0519766b9f5aabb510e1e6969d6c.tar.xz | |
Make zabs, zneg and zswap inline
Signed-off-by: Mattias Andrée <maandree@kth.se>
| -rw-r--r-- | Makefile | 8 | ||||
| -rw-r--r-- | src/zabs.c | 10 | ||||
| -rw-r--r-- | src/zneg.c | 10 | ||||
| -rw-r--r-- | src/zswap.c | 12 | ||||
| -rw-r--r-- | zahl.h | 20 |
5 files changed, 14 insertions, 46 deletions
@@ -5,7 +5,6 @@ HDR =\ src/internals.h FUN =\ - zabs\ zadd\ zand\ zbits\ @@ -29,7 +28,6 @@ FUN =\ zmodpowu\ zmodsqr\ zmul\ - zneg\ znot\ zor\ zperror\ @@ -49,19 +47,21 @@ FUN =\ zstr\ zstr_length\ zsub\ - zswap\ ztrunc\ zunsetup\ zxor INLINE_FUN =\ zinit\ + zswap\ zeven\ zodd\ zeven_nonzero\ zodd_nonzero\ zzero\ - zsignum + zsignum\ + zabs\ + zneg OBJ = $(FUN:=.o) allocator.o MAN3 = $(FUN:=.3) $(INLINE_FUN:=.3) diff --git a/src/zabs.c b/src/zabs.c deleted file mode 100644 index d4de6c4..0000000 --- a/src/zabs.c +++ /dev/null @@ -1,10 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#include "internals.h" - - -void -zabs(z_t a, z_t b) -{ - SET(a, b); - SET_SIGNUM(a, !zzero(a)); -} diff --git a/src/zneg.c b/src/zneg.c deleted file mode 100644 index 484d610..0000000 --- a/src/zneg.c +++ /dev/null @@ -1,10 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#include "internals.h" - - -void -zneg(z_t a, z_t b) -{ - SET(a, b); - SET_SIGNUM(a, -zsignum(a)); -} diff --git a/src/zswap.c b/src/zswap.c deleted file mode 100644 index 452d712..0000000 --- a/src/zswap.c +++ /dev/null @@ -1,12 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#include "internals.h" - - -void -zswap(z_t a, z_t b) -{ - z_t t; - *t = *a; - *a = *b; - *b = *t; -} @@ -44,7 +44,6 @@ void zunsetup(void); /* Free resources used by libzahl */ /* Memory functions. */ void zfree(z_t); /* Free resources in a. */ -void zswap(z_t, z_t); /* (a, b) := (b, a) */ size_t zsave(z_t, void *); /* Store a into b (if !!b), and return number of written bytes. */ size_t zload(z_t, const void *); /* Restore a from b, and return number of read bytes. */ @@ -78,8 +77,6 @@ void zdivmod(z_t, z_t, z_t, z_t); /* a := c / d, b = c % d */ void zmod(z_t, z_t, z_t); /* a := b % c */ void zsqr(z_t, z_t); /* a := b² */ void zmodsqr(z_t, z_t, z_t); /* a := b² % c */ -void zneg(z_t, z_t); /* a := -b */ -void zabs(z_t, z_t); /* a := |b| */ void zpow(z_t, z_t, z_t); /* a := b ↑ c */ void zmodpow(z_t, z_t, z_t, z_t); /* a := (b ↑ c) % d */ void zpowu(z_t, z_t, unsigned long long int); @@ -140,10 +137,13 @@ void zperror(const char *); /* Identical to perror(3p) except it supp /* Inline functions. */ -static inline void zinit(z_t a) { a->alloced = 0; a->chars = 0; } /* Prepare a for use. */ -static inline int zeven(z_t a) { return !a->sign || !(a->chars[0] & 1); } /* Is a even? */ -static inline int zodd(z_t a) { return a->sign && (a->chars[0] & 1); } /* Is a odd? */ -static inline int zeven_nonzero(z_t a) { return !(a->chars[0] & 1); } /* Is a even? Assumes a ≠ 0. */ -static inline int zodd_nonzero(z_t a) { return (a->chars[0] & 1); } /* Is a odd? Assumes a ≠ 0. */ -static inline int zzero(z_t a) { return !a->sign; } /* Is a zero? */ -static inline int zsignum(z_t a) { return a->sign; } /* a/|a|, 0 if a is zero. */ +static inline void zinit(z_t a) { a->alloced = 0; a->chars = 0; } /* Prepare a for use. */ +static inline void zswap(z_t a, z_t b) { z_t t; *t = *a; *a = *b; *b = *t; } /* (a, b) := (b, a) */ +static inline int zeven(z_t a) { return !a->sign || !(a->chars[0] & 1); } /* Is a even? */ +static inline int zodd(z_t a) { return a->sign && (a->chars[0] & 1); } /* Is a odd? */ +static inline int zeven_nonzero(z_t a) { return !(a->chars[0] & 1); } /* Is a even? Assumes a ≠ 0. */ +static inline int zodd_nonzero(z_t a) { return (a->chars[0] & 1); } /* Is a odd? Assumes a ≠ 0. */ +static inline int zzero(z_t a) { return !a->sign; } /* Is a zero? */ +static inline int zsignum(z_t a) { return a->sign; } /* a/|a|, 0 if a is zero. */ +static inline void zabs(z_t a, z_t b) { if (a != b) zset(a, b); a->sign = !!a->sign; } /* a := |b| */ +static inline void zneg(z_t a, z_t b) { if (a != b) zset(a, b); a->sign = -a->sign; } /* a := -b */ |
