aboutsummaryrefslogtreecommitdiffstats
path: root/src/zrsh.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-03-13 23:54:56 +0100
committerMattias Andrée <maandree@kth.se>2016-03-13 23:54:56 +0100
commit5b10b24044b3350a19ab3d3c0b37b5e9c12365b1 (patch)
tree3f6aa8de29becc5d7511fcca50e6d31982c1b64b /src/zrsh.c
parentOptimisations (diff)
downloadlibzahl-5b10b24044b3350a19ab3d3c0b37b5e9c12365b1.tar.gz
libzahl-5b10b24044b3350a19ab3d3c0b37b5e9c12365b1.tar.bz2
libzahl-5b10b24044b3350a19ab3d3c0b37b5e9c12365b1.tar.xz
Multiple changes:
1) Compile test with -O0, it takes too long otherwise. 2) Add error codes: ZERROR_0_POW_0, ZERROR_0_DIV_0, ZERROR_DIV_0, ZERROR_NEGATIVE. 3) Add workaround for a bug in clang (src/allocator.c). 4) Cleanups. 5) Minor optimisations. 6) Add inclusion guard for zahl.h. Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/zrsh.c')
-rw-r--r--src/zrsh.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/zrsh.c b/src/zrsh.c
index cc83ae5..163919d 100644
--- a/src/zrsh.c
+++ b/src/zrsh.c
@@ -7,14 +7,14 @@ zrsh(z_t a, z_t b, size_t bits)
{
size_t i, chars, cbits;
- if (EXPECT(!bits, 0)) {
+ if (unlikely(!bits)) {
SET(a, b);
return;
}
chars = FLOOR_BITS_TO_CHARS(bits);
- if (EXPECT(zzero(b) || chars >= b->used || zbits(b) <= bits, 0)) {
+ if (unlikely(zzero(b) || chars >= b->used || zbits(b) <= bits)) {
SET_SIGNUM(a, 0);
return;
}
@@ -22,16 +22,16 @@ zrsh(z_t a, z_t b, size_t bits)
bits = BITS_IN_LAST_CHAR(bits);
cbits = BITS_PER_CHAR - bits;
- if (EXPECT(chars, 1) && EXPECT(a == b, 1)) {
+ if (likely(chars) && likely(a == b)) {
a->used -= chars;
zmemmove(a->chars, a->chars + chars, a->used);
- } else if (EXPECT(a != b, 0)) {
+ } else if (unlikely(a != b)) {
a->used = b->used - chars;
ENSURE_SIZE(a, a->used);
zmemcpy(a->chars, b->chars + chars, a->used);
}
- if (EXPECT(bits, 0)) { /* This if statement is very important in C. */
+ if (unlikely(bits)) { /* This if statement is very important in C. */
a->chars[0] >>= bits;
for (i = 1; i < a->used; i++) {
a->chars[i - 1] |= a->chars[i] << cbits;