From c8c64252eb57241a73b1c9e4e332d82580220fde Mon Sep 17 00:00:00 2001 From: Stewart Smith Date: Tue, 15 Dec 2015 16:59:35 +1100 Subject: remove likely/unlikely: nothing is *that* perf critical Signed-off-by: Stewart Smith --- clib/builtin.h | 16 ---------------- clib/src/slab.c | 24 ++++++++++++------------ clib/src/tree.c | 16 ++++++++-------- ffs/src/libffs.c | 8 ++++---- 4 files changed, 24 insertions(+), 40 deletions(-) diff --git a/clib/builtin.h b/clib/builtin.h index 5a7ac08..a6dc820 100644 --- a/clib/builtin.h +++ b/clib/builtin.h @@ -32,22 +32,6 @@ #ifndef __BUILTIN_H__ #define __BUILTIN_H__ -/*! - * @def likely(x) - * @hideinitializer - * @brief Indicate an expression is likely to occur - * @param x [in] Expression - */ -#define likely(x) __builtin_expect(!!(x), 1) - -/*! - * @def unlikely(x) - * @hideinitializer - * @brief Indicate an expression is unlikely to occur - * @param x [in] Expression - */ -#define unlikely(x) __builtin_expect(!!(x), 0) - /*! * @def parity(x) * @hideinitializer diff --git a/clib/src/slab.c b/clib/src/slab.c index 9ee4353..8ddfca3 100644 --- a/clib/src/slab.c +++ b/clib/src/slab.c @@ -127,7 +127,7 @@ int slab_init5(slab_t * self, const char *name, uint32_t alloc_size, { assert(self != NULL); - if (unlikely(MAGIC_CHECK(self->hdr.id, SLAB_MAGIC) == false)) + if (MAGIC_CHECK(self->hdr.id, SLAB_MAGIC) == false) slab_delete(self); alloc_size = align(alloc_size, sizeof(void *)); @@ -189,10 +189,10 @@ int slab_init5(slab_t * self, const char *name, uint32_t alloc_size, int slab_delete(slab_t * self) { - if (unlikely(self == NULL)) + if (self == NULL) return 0; - if (unlikely(MAGIC_CHECK(self->hdr.id, SLAB_MAGIC))) { + if (MAGIC_CHECK(self->hdr.id, SLAB_MAGIC)) { UNEXPECTED("'%s' invalid or corrupt slab object", self->hdr.name); return -1; @@ -234,7 +234,7 @@ void *slab_alloc(slab_t * self) if (0 < node->free) break; - if (unlikely(tree_iter_elem(&it) == NULL)) + if (tree_iter_elem(&it) == NULL) node = __slab_grow(self); assert(node != NULL); @@ -247,11 +247,11 @@ void *slab_alloc(slab_t * self) if (node->bitmap[map_pos] != UINT32_MAX) break; - if (unlikely(node->bitmap[map_pos] == UINT32_MAX)) { + if (node->bitmap[map_pos] == UINT32_MAX) { UNEXPECTED("'%s' cache is corrupted", self->hdr.name); return NULL; } - if (unlikely(self->hdr.bitmap_size <= map_pos)) { + if (self->hdr.bitmap_size <= map_pos) { UNEXPECTED("'%s' cache is corrupted", self->hdr.name); return NULL; } @@ -259,7 +259,7 @@ void *slab_alloc(slab_t * self) uint32_t bit = clzl(~node->bitmap[map_pos]); uint32_t mask = 0x80000000 >> bit; - if (unlikely((node->bitmap[map_pos] & mask) == mask)) { + if ((node->bitmap[map_pos] & mask) == mask) { UNEXPECTED("'%s' cache is corrupted", self->hdr.name); return NULL; } @@ -278,14 +278,14 @@ int slab_free(slab_t * self, void *ptr) assert(self != NULL); assert(!MAGIC_CHECK(self->hdr.id, SLAB_MAGIC)); - if (unlikely(ptr == NULL)) + if (ptr == NULL) return 0; slab_node_t *node = (slab_node_t *) ((uintptr_t) ptr & ~(self->hdr.page_size - 1)); assert(node != NULL); - if (unlikely(SLAB_NODE_MAGIC_CHECK(node->magic))) { + if (SLAB_NODE_MAGIC_CHECK(node->magic)) { int64_t hash = int64_hash1((int64_t) node); if (splay_find(&self->tree, (const void *)hash) == NULL) { UNEXPECTED("'%s' invalid slab_node pointer, %p", @@ -297,7 +297,7 @@ int slab_free(slab_t * self, void *ptr) void *data = (void *)node->bitmap + self->hdr.bitmap_size; assert(data != NULL); - if (unlikely(ptr < data)) { + if (ptr < data) { UNEXPECTED("'%s' pointer out-of-range, %p", self->hdr.name, ptr); return -1; @@ -307,7 +307,7 @@ int slab_free(slab_t * self, void *ptr) uint32_t mask = 0x80000000 >> slot; size_t map_pos = slot / INT32_BIT; - if (unlikely((node->bitmap[map_pos] & mask) != mask)) { + if ((node->bitmap[map_pos] & mask) != mask) { UNEXPECTED("'%s' double free detected, %p", self->hdr.name, ptr); return -1; @@ -362,7 +362,7 @@ void slab_dump(slab_t * self, FILE * out) out = stdout; if (self != NULL) { - if (unlikely(MAGIC_CHECK(self->hdr.id, SLAB_MAGIC))) { + if (MAGIC_CHECK(self->hdr.id, SLAB_MAGIC)) { UNEXPECTED("'%s' invalid or corrupt slab object", self->hdr.name); return; diff --git a/clib/src/tree.c b/clib/src/tree.c index e7230a4..45a18e3 100644 --- a/clib/src/tree.c +++ b/clib/src/tree.c @@ -136,9 +136,9 @@ __tree_new_root(tree_t * self, tree_node_t * node, tree_node_t * left, node->right = right; node->parent = NULL; - if (unlikely(right != NULL)) + if (right != NULL) right->parent = node; - if (unlikely(left != NULL)) + if (left != NULL) left->parent = node; self->root = node; @@ -152,7 +152,7 @@ int tree_insert(tree_t * self, tree_node_t * node) __tree_new_min(self, node); __tree_new_max(self, node); - if (unlikely(self->root == NULL)) { + if (self->root == NULL) { __tree_new_root(self, node, NULL, NULL); self->size++; } else { @@ -223,7 +223,7 @@ int tree_remove(tree_t * self, tree_node_t * node) assert(self != NULL); assert(node != NULL); - if (unlikely(self->root == NULL) || unlikely(node == NULL)) + if (self->root == NULL || node == NULL) return 0; /* =========================== */ @@ -365,7 +365,7 @@ int tree_walk(tree_t * self, tree_walk_f walk_func) int __tree_walk(tree_node_t * root) { int rc = 0; - if (likely(root != NULL)) { + if (root != NULL) { __tree_walk(root->left); rc = walk_func(root); __tree_walk(root->right); @@ -406,7 +406,7 @@ void tree_node_dump(tree_node_t * node, FILE * out) return; void __tree_node_dump(tree_node_t * root, int level) { - if (likely(root != NULL)) { + if (root != NULL) { if (0 < level) { for (int i = 0; i < level; i++) fprintf(out, " "); @@ -528,7 +528,7 @@ int splay_insert(tree_t * self, tree_node_t * node) __tree_new_min(self, node); __tree_new_max(self, node); - if (unlikely(self->root == NULL)) { + if (self->root == NULL) { node->left = node->right = node->parent = NULL; self->root = node; self->size = 1; @@ -569,7 +569,7 @@ int splay_remove(tree_t * self, tree_node_t * node) assert(self != NULL); assert(node != NULL); - if (unlikely(self->root == NULL) || unlikely(node == NULL)) + if (self->root == NULL || node == NULL) return 0; if (node == self->min) diff --git a/ffs/src/libffs.c b/ffs/src/libffs.c index e8f1933..03359d8 100644 --- a/ffs/src/libffs.c +++ b/ffs/src/libffs.c @@ -268,7 +268,7 @@ static int __entries_read(ffs_hdr_t * hdr, FILE * file, off_t offset) #if 0 static void __entries_write(ffs_hdr_t * hdr, FILE * file, off_t offset) { - if (unlikely(hdr == NULL)) + if (hdr == NULL) ffs_throw(UNEX, 10400, "NULL hdr pointer"); if (hdr->magic != FFS_MAGIC) ffs_throw(UNEX, 10401, "magic number mismatch '%x' != " @@ -740,7 +740,7 @@ int __ffs_fclose(ffs_t * self) int __ffs_close(ffs_t * self) { - if (unlikely(self == NULL)) + if (self == NULL) return 0; if (self->dirty == true) @@ -1325,7 +1325,7 @@ ssize_t __ffs_entry_copy(ffs_t *self, ffs_t *in, const char *path) assert(in != NULL); assert(path != NULL); - if (unlikely(*path == '\0')) + if (*path == '\0') return 0; ffs_entry_t *src = __find_entry(in->hdr, path); @@ -1405,7 +1405,7 @@ ssize_t __ffs_entry_compare(ffs_t * self, ffs_t * in, const char *path) assert(in != NULL); assert(path != NULL); - if (unlikely(*path == '\0')) + if (*path == '\0') return 0; ffs_entry_t *src = __find_entry(in->hdr, path); -- cgit v1.2.1