commit 5e29d29416b568f380a2ab753e3e77e96af4b094
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Wed Apr 27 17:26:41 2016 +0200
Commit: Mattias Andrée <maandree_AT_kth.se>
CommitDate: Wed Apr 27 17:26:44 2016 +0200
Error-check implies unlikely branching
Signed-off-by: Mattias Andrée <maandree_AT_kth.se>
diff --git a/src/allocator.c b/src/allocator.c
index 1a2d505..4f81171 100644
--- a/src/allocator.c
+++ b/src/allocator.c
_AT_@ -22,7 +22,7 @@ libzahl_realloc(z_t a, size_t need)
a->chars = new;
} else {
a->chars = realloc(a->chars, new_size * sizeof(zahl_char_t));
- if (check(unlikely(!a->chars)))
+ if (check(!a->chars))
libzahl_memfailure();
}
a->alloced = new_size;
diff --git a/src/internals.h b/src/internals.h
index c59b792..b055dbd 100644
--- a/src/internals.h
+++ b/src/internals.h
_AT_@ -100,7 +100,7 @@ extern void *libzahl_temp_allocation;
#if defined(UNSAFE)
# define check(expr) 0
#else
-# define check(expr) (expr)
+# define check(expr) unlikely(expr)
#endif
#define SET_SIGNUM(a, signum) ZAHL_SET_SIGNUM(a, signum)
_AT_@ -337,7 +337,7 @@ zinit_temp(z_t a)
size_t n = (size_t)(libzahl_temp_stack_end - libzahl_temp_stack);
void* old = libzahl_temp_stack;
libzahl_temp_stack = realloc(old, 2 * n * sizeof(*libzahl_temp_stack));
- if (check(unlikely(!libzahl_temp_stack))) {
+ if (check(!libzahl_temp_stack)) {
libzahl_temp_stack = old;
libzahl_memfailure();
}
diff --git a/src/zdivmod.c b/src/zdivmod.c
index 9cf3611..dae0e02 100644
--- a/src/zdivmod.c
+++ b/src/zdivmod.c
_AT_@ -72,9 +72,9 @@ zdivmod(z_t a, z_t b, z_t c, z_t d)
sign = zsignum(c) * zsignum(d);
if (unlikely(!sign)) {
- if (check(unlikely(!zzero(c)))) {
+ if (check(!zzero(c))) {
libzahl_failure(-ZERROR_DIV_0);
- } else if (check(unlikely(zzero(d)))) {
+ } else if (check(zzero(d))) {
libzahl_failure(-ZERROR_0_DIV_0);
} else {
SET_SIGNUM(a, 0);
diff --git a/src/zmodpow.c b/src/zmodpow.c
index 34e687f..0cec96d 100644
--- a/src/zmodpow.c
+++ b/src/zmodpow.c
_AT_@ -25,7 +25,7 @@ zmodpow(z_t a, z_t b, z_t c, z_t d)
SET_SIGNUM(a, 0);
}
return;
- } else if (check(unlikely(zzero(d)))) {
+ } else if (check(zzero(d))) {
libzahl_failure(-ZERROR_DIV_0);
} else if (unlikely(zzero(b))) {
SET_SIGNUM(a, 0);
diff --git a/src/zmodpowu.c b/src/zmodpowu.c
index 7bb4f2b..72aa96f 100644
--- a/src/zmodpowu.c
+++ b/src/zmodpowu.c
_AT_@ -16,7 +16,7 @@ zmodpowu(z_t a, z_t b, unsigned long long int c, z_t d)
else
zsetu(a, 1);
return;
- } else if (check(unlikely(zzero(d)))) {
+ } else if (check(zzero(d))) {
libzahl_failure(-ZERROR_DIV_0);
} else if (unlikely(zzero(b))) {
SET_SIGNUM(a, 0);
diff --git a/src/zrand.c b/src/zrand.c
index 079520e..020b58c 100644
--- a/src/zrand.c
+++ b/src/zrand.c
_AT_@ -104,7 +104,7 @@ zrand_fd(void *out, size_t n, void *statep)
while (n) {
read_just = read(fd, buf + read_total, n);
- if (check(unlikely(read_just < 0)))
+ if (check(read_just < 0))
libzahl_failure(errno);
read_total += (size_t)read_just;
n -= (size_t)read_just;
_AT_@ -141,7 +141,7 @@ zrand(z_t r, enum zranddev dev, enum zranddist dist, z_t n)
{
#define RANDOM_UNIFORM(RETRY)\
do {\
- if (check(unlikely(znegative(n))))\
+ if (check(znegative(n)))\
libzahl_failure(-ZERROR_NEGATIVE);\
bits = zbits(n);\
do\
_AT_@ -185,7 +185,7 @@ zrand(z_t r, enum zranddev dev, enum zranddist dist, z_t n)
if (pathname) {
fd = open(pathname, O_RDONLY);
- if (check(unlikely(fd < 0)))
+ if (check(fd < 0))
libzahl_failure(errno);
statep = &fd;
}
diff --git a/src/zsets.c b/src/zsets.c
index 1701c6b..b5f9e04 100644
--- a/src/zsets.c
+++ b/src/zsets.c
_AT_@ -17,12 +17,12 @@ zsets(z_t a, const char *str)
str += neg || (*str == '+');
- if (check(unlikely(!*str))) {
+ if (check(!*str)) {
errno = EINVAL;
return -1;
}
for (str_end = str; *str_end; str_end++) {
- if (check(unlikely(!isdigit(*str_end)))) {
+ if (check(!isdigit(*str_end))) {
errno = EINVAL;
return -1;
}
diff --git a/src/zsetup.c b/src/zsetup.c
index df8c0c2..66d94ee 100644
--- a/src/zsetup.c
+++ b/src/zsetup.c
_AT_@ -46,7 +46,7 @@ zsetup(jmp_buf env)
zinit(libzahl_tmp_divmod_ds[i]);
libzahl_temp_stack = malloc(256 * sizeof(*libzahl_temp_stack));
- if (check(unlikely(!libzahl_temp_stack)))
+ if (check(!libzahl_temp_stack))
libzahl_memfailure();
libzahl_temp_stack_head = libzahl_temp_stack;
libzahl_temp_stack_end = libzahl_temp_stack + 256;
Received on Wed Apr 27 2016 - 17:32:12 CEST
This archive was generated by hypermail 2.3.0
: Wed Apr 27 2016 - 17:36:18 CEST