mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-02-17 19:20:30 +01:00
util/sparse_array: Add a node_size_log2 temporary
We use this value several times. It's probably best to encourage the compiler to only read it once. I have no proof that this actually makes any performance improvement whatsoever. Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4228>
This commit is contained in:
parent
7893872a6c
commit
9fcd8bdbfc
1 changed files with 8 additions and 7 deletions
|
|
@ -108,12 +108,13 @@ _util_sparse_array_set_or_free_node(struct util_sparse_array_node **node_ptr,
|
|||
void *
|
||||
util_sparse_array_get(struct util_sparse_array *arr, uint64_t idx)
|
||||
{
|
||||
const unsigned node_size_log2 = arr->node_size_log2;
|
||||
struct util_sparse_array_node *root = p_atomic_read(&arr->root);
|
||||
if (unlikely(root == NULL)) {
|
||||
unsigned root_level = 0;
|
||||
uint64_t idx_iter = idx >> arr->node_size_log2;
|
||||
uint64_t idx_iter = idx >> node_size_log2;
|
||||
while (idx_iter) {
|
||||
idx_iter >>= arr->node_size_log2;
|
||||
idx_iter >>= node_size_log2;
|
||||
root_level++;
|
||||
}
|
||||
struct util_sparse_array_node *new_root =
|
||||
|
|
@ -122,8 +123,8 @@ util_sparse_array_get(struct util_sparse_array *arr, uint64_t idx)
|
|||
}
|
||||
|
||||
while (1) {
|
||||
uint64_t root_idx = idx >> (root->level * arr->node_size_log2);
|
||||
if (likely(root_idx < (1ull << arr->node_size_log2)))
|
||||
uint64_t root_idx = idx >> (root->level * node_size_log2);
|
||||
if (likely(root_idx < (1ull << node_size_log2)))
|
||||
break;
|
||||
|
||||
/* In this case, we have a root but its level is low enough that the
|
||||
|
|
@ -147,8 +148,8 @@ util_sparse_array_get(struct util_sparse_array *arr, uint64_t idx)
|
|||
|
||||
struct util_sparse_array_node *node = root;
|
||||
while (node->level > 0) {
|
||||
uint64_t child_idx = (idx >> (node->level * arr->node_size_log2)) &
|
||||
((1ull << arr->node_size_log2) - 1);
|
||||
uint64_t child_idx = (idx >> (node->level * node_size_log2)) &
|
||||
((1ull << node_size_log2) - 1);
|
||||
|
||||
struct util_sparse_array_node **children =
|
||||
_util_sparse_array_node_data(node);
|
||||
|
|
@ -164,7 +165,7 @@ util_sparse_array_get(struct util_sparse_array *arr, uint64_t idx)
|
|||
node = child;
|
||||
}
|
||||
|
||||
uint64_t elem_idx = idx & ((1ull << arr->node_size_log2) - 1);
|
||||
uint64_t elem_idx = idx & ((1ull << node_size_log2) - 1);
|
||||
return (void *)((char *)_util_sparse_array_node_data(node) +
|
||||
(elem_idx * arr->elem_size));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue