From 4bba6e7176632b4d760ba9362a1515552471d741 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 29 Apr 2016 21:54:39 +0200 Subject: Some optimisations, fix refsheet, and disable const/pure attributes in gmp in benchmark MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- zahl-internals.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'zahl-internals.h') diff --git a/zahl-internals.h b/zahl-internals.h index 9d6df24..4adbdfe 100644 --- a/zahl-internals.h +++ b/zahl-internals.h @@ -32,10 +32,12 @@ #define ZAHL_SET_SIGNUM(a, signum) ((a)->sign = (signum)) #define ZAHL_SET(a, b) do { if ((a) != (b)) zset(a, b); } while (0) +#define ZAHL_ENSURE_SIZE(a, n) do { if ((a)->alloced < (n)) libzahl_realloc(a, (n)); } while (0) #define ZAHL_TRIM(a) for (; (a)->used && !(a)->chars[(a)->used - 1]; (a)->used--) #define ZAHL_TRIM_NONZERO(a) for (; !(a)->chars[(a)->used - 1]; (a)->used--) #define ZAHL_TRIM_AND_ZERO(a) do { ZAHL_TRIM(a); if (!(a)->used) ZAHL_SET_SIGNUM(a, 0); } while (0) #define ZAHL_TRIM_AND_SIGN(a, s) do { ZAHL_TRIM(a); ZAHL_SET_SIGNUM(a, (a)->used ? (s) : 0); } while (0) +#define ZAHL_SWAP(a, b, t, m) ((t)->m = (a)->m, (a)->m = (b)->m, (b)->m = (t)->m) #if defined(__GNUC__) || defined(__clang__) @@ -72,3 +74,20 @@ struct zahl { size_t alloced; zahl_char_t *chars; }; + + +void libzahl_realloc(struct zahl *, size_t); + +static inline void +libzahl_memcpy(zahl_char_t *restrict d, const zahl_char_t *restrict s, register size_t n) +{ + while (n--) + d[n] = s[n]; +} + +static inline void +libzahl_memset(zahl_char_t *a, register zahl_char_t v, register size_t n) +{ + while (n--) + a[n] = v; +} -- cgit v1.2.3-70-g09d2