commit 58baaf9eaa1a0519766b9f5aabb510e1e6969d6c
parent b2584fb5a9851bdf3c23036e6cea9cd301135df0
Author: Mattias Andrée <maandree@kth.se>
Date: Sun, 13 Mar 2016 01:04:48 +0100
Make zabs, zneg and zswap inline
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat:
5 files changed, 14 insertions(+), 46 deletions(-)
diff --git a/Makefile b/Makefile
@@ -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
@@ -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
@@ -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
@@ -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;
-}
diff --git a/zahl.h b/zahl.h
@@ -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 */