commit b8f7e263d28edb721f18f64d3553947710ff9fce
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Wed May 4 17:04:27 2016 +0200
Commit: Mattias Andrée <maandree_AT_kth.se>
CommitDate: Wed May 4 17:04:27 2016 +0200
Optimise znot
Signed-off-by: Mattias Andrée <maandree_AT_kth.se>
diff --git a/src/internals.h b/src/internals.h
index f1a2f78..a475ada 100644
--- a/src/internals.h
+++ b/src/internals.h
_AT_@ -344,7 +344,7 @@ zfree_temp(z_t a)
/* } */
-#define ZMEM_OP(a, b, c, n, OP) \
+#define ZMEM_2OP(a, b, c, n, OP) \
do { \
zahl_char_t *a__ = (a); \
const zahl_char_t *b__ = (b); \
_AT_@ -371,3 +371,30 @@ zfree_temp(z_t a)
a__[i__] = b__[i__] OP c__[i__]; \
} \
} while (0)
+
+#define ZMEM_1OP(a, b, n, OP) \
+ do { \
+ zahl_char_t *a__ = (a); \
+ const zahl_char_t *b__ = (b); \
+ size_t i__, n__ = (n); \
+ if (n__ <= 4) { \
+ if (n__ >= 1) \
+ a__[0] = OP(b__[0]); \
+ if (n__ >= 2) \
+ a__[1] = OP(b__[1]); \
+ if (n__ >= 3) \
+ a__[2] = OP(b__[2]); \
+ if (n__ >= 4) \
+ a__[3] = OP(b__[3]); \
+ } else { \
+ for (i__ = 0; (i__ += 4) < n__;) { \
+ a__[i__ - 1] = OP(b__[i__ - 1]); \
+ a__[i__ - 2] = OP(b__[i__ - 2]); \
+ a__[i__ - 3] = OP(b__[i__ - 3]); \
+ a__[i__ - 4] = OP(b__[i__ - 4]); \
+ } \
+ if (i__ > n__) \
+ for (i__ -= 4; i__ < n__; i__++) \
+ a__[i__] = OP(b__[i__]); \
+ } \
+ } while (0)
diff --git a/src/zand.c b/src/zand.c
index 45d1ed5..362515c 100644
--- a/src/zand.c
+++ b/src/zand.c
_AT_@ -17,12 +17,12 @@ zand(z_t a, z_t b, z_t c)
a->used = MIN(b->used, c->used);
if (a == b) {
- ZMEM_OP(a->chars, a->chars, c->chars, a->used, &);
+ ZMEM_2OP(a->chars, a->chars, c->chars, a->used, &);
} else if (unlikely(a == c)) {
- ZMEM_OP(a->chars, a->chars, b->chars, a->used, &);
+ ZMEM_2OP(a->chars, a->chars, b->chars, a->used, &);
} else {
ENSURE_SIZE(a, a->used);
- ZMEM_OP(a->chars, b->chars, c->chars, a->used, &);
+ ZMEM_2OP(a->chars, b->chars, c->chars, a->used, &);
}
TRIM_AND_SIGN(a, zpositive1(b, c) * 2 - 1);
diff --git a/src/znot.c b/src/znot.c
index bebc55b..e076cda 100644
--- a/src/znot.c
+++ b/src/znot.c
_AT_@ -5,7 +5,7 @@
void
znot(z_t a, z_t b)
{
- size_t bits, i;
+ size_t bits;
if (unlikely(zzero(b))) {
SET_SIGNUM(a, 0);
_AT_@ -16,8 +16,7 @@ znot(z_t a, z_t b)
a->used = b->used;
SET_SIGNUM(a, -zsignum(b));
- for (i = 0; i < a->used; i++)
- a->chars[i] = ~(b->chars[i]);
+ ZMEM_1OP(a->chars, b->chars, a->used, ~);
bits = BITS_IN_LAST_CHAR(bits);
if (bits)
a->chars[a->used - 1] &= ((zahl_char_t)1 << bits) - 1;
diff --git a/src/zor.c b/src/zor.c
index ed952ca..9b45620 100644
--- a/src/zor.c
+++ b/src/zor.c
_AT_@ -19,18 +19,18 @@ zor(z_t a, z_t b, z_t c)
ENSURE_SIZE(a, m);
if (a == b) {
- ZMEM_OP(a->chars, a->chars, c->chars, n, |);
+ ZMEM_2OP(a->chars, a->chars, c->chars, n, |);
if (a->used < c->used)
zmemcpy_range(a->chars, c->chars, n, m);
} else if (unlikely(a == c)) {
- ZMEM_OP(a->chars, a->chars, b->chars, n, |);
+ ZMEM_2OP(a->chars, a->chars, b->chars, n, |);
if (a->used < b->used)
zmemcpy_range(a->chars, b->chars, n, m);
} else if (m == b->used) {
- ZMEM_OP(a->chars, c->chars, b->chars, n, |);
+ ZMEM_2OP(a->chars, c->chars, b->chars, n, |);
zmemcpy_range(a->chars, b->chars, n, m);
} else {
- ZMEM_OP(a->chars, b->chars, c->chars, n, |);
+ ZMEM_2OP(a->chars, b->chars, c->chars, n, |);
zmemcpy_range(a->chars, c->chars, n, m);
}
diff --git a/src/zxor.c b/src/zxor.c
index 3f2ca5c..fe6b4cd 100644
--- a/src/zxor.c
+++ b/src/zxor.c
_AT_@ -26,18 +26,18 @@ zxor(z_t a, z_t b, z_t c)
ENSURE_SIZE(a, m);
if (a == b) {
- ZMEM_OP(a->chars, a->chars, cc, n, ^);
+ ZMEM_2OP(a->chars, a->chars, cc, n, ^);
if (a->used < cn)
zmemcpy_range(a->chars, cc, n, m);
} else if (unlikely(a == c)) {
- ZMEM_OP(a->chars, b->chars, cc, n, ^);
+ ZMEM_2OP(a->chars, b->chars, cc, n, ^);
if (a->used < bn)
zmemcpy_range(a->chars, bc, n, m);
} else if (m == bn) {
- ZMEM_OP(a->chars, c->chars, b->chars, n, ^);
+ ZMEM_2OP(a->chars, c->chars, b->chars, n, ^);
zmemcpy_range(a->chars, b->chars, n, m);
} else {
- ZMEM_OP(a->chars, b->chars, c->chars, n, ^);
+ ZMEM_2OP(a->chars, b->chars, c->chars, n, ^);
zmemcpy_range(a->chars, c->chars, n, m);
}
Received on Wed May 04 2016 - 17:17:01 CEST
This archive was generated by hypermail 2.3.0
: Wed May 04 2016 - 17:24:13 CEST