From 92be5631d8e319babf5cca49f53ea5e692c54793 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 15 Mar 2016 00:20:00 +0100 Subject: Optimisations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/zlsh.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'src/zlsh.c') diff --git a/src/zlsh.c b/src/zlsh.c index 42894e0..1c9fd8f 100644 --- a/src/zlsh.c +++ b/src/zlsh.c @@ -6,22 +6,18 @@ void zlsh(z_t a, z_t b, size_t bits) { size_t i, chars, cbits; - zahl_char_t carry[] = {0, 0}; + zahl_char_t carry = 0, tcarry; if (unlikely(zzero(b))) { SET_SIGNUM(a, 0); return; } - if (unlikely(!bits)) { - SET(a, b); - return; - } chars = FLOOR_BITS_TO_CHARS(bits); bits = BITS_IN_LAST_CHAR(bits); cbits = BITS_PER_CHAR - bits; - ENSURE_SIZE(a, b->used + chars); + ENSURE_SIZE(a, b->used + chars + 1); if (likely(a == b)) zmemmove(a->chars + chars, b->chars, b->used); else @@ -31,15 +27,13 @@ zlsh(z_t a, z_t b, size_t bits) if (likely(bits)) { /* This if statement is very important in C. */ for (i = chars; i < a->used; i++) { - carry[~i & 1] = a->chars[i] >> cbits; + tcarry = a->chars[i] >> cbits; a->chars[i] <<= bits; - a->chars[i] |= carry[i & 1]; - } - if (carry[i & 1]) { - ENSURE_SIZE(a, a->used + 1); - a->chars[i] = carry[i & 1]; - a->used++; + a->chars[i] |= carry; + carry = tcarry; } + if (carry) + a->chars[a->used++] = carry; } SET_SIGNUM(a, zsignum(b)); -- cgit v1.2.3-70-g09d2