diff options
author | Stewart Smith <stewart@linux.vnet.ibm.com> | 2015-12-15 16:59:35 +1100 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2015-12-15 16:59:35 +1100 |
commit | c8c64252eb57241a73b1c9e4e332d82580220fde (patch) | |
tree | 5f45d14720433e864ea5cd3694d79841445b6981 /clib | |
parent | 67c96c6d2e76a8cce19988839f2ebcc1793445e2 (diff) | |
download | ffs-c8c64252eb57241a73b1c9e4e332d82580220fde.tar.gz ffs-c8c64252eb57241a73b1c9e4e332d82580220fde.zip |
remove likely/unlikely: nothing is *that* perf critical
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'clib')
-rw-r--r-- | clib/builtin.h | 16 | ||||
-rw-r--r-- | clib/src/slab.c | 24 | ||||
-rw-r--r-- | clib/src/tree.c | 16 |
3 files changed, 20 insertions, 36 deletions
diff --git a/clib/builtin.h b/clib/builtin.h index 5a7ac08..a6dc820 100644 --- a/clib/builtin.h +++ b/clib/builtin.h @@ -33,22 +33,6 @@ #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 * @brief Return parity of the input 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) |