util/sparse_array: Stash the node level in the node pointer
authorJason Ekstrand <jason@jlekstrand.net>
Wed, 18 Mar 2020 16:48:47 +0000 (11:48 -0500)
committerJason Ekstrand <jason@jlekstrand.net>
Fri, 20 Mar 2020 20:31:10 +0000 (15:31 -0500)
commitaee004a7c8900938d1c17f0ac299d40001b383b0
tree36524dad187a66e25c26ff397315a52740e328c8
parent6be65b077743fc80efe061b1e05cb13b2ff1a6b1
util/sparse_array: Stash the node level in the node pointer

This reworks the data structure a bit and, in my view, simplifies it.
Instead of each node having a header which has the node level in it, we
use the bottom 6 bits of the pointer for that.  This requires us to
allocate with the os_malloc/free_aligned helpers (which call into
posix_memalign on Linux) but cache-line aligning our allocations is
actually probably a good thing given that we're doing atomics on them.

The primary advantages to doing this is that it changes the number of
memory accesses per tree level from 2 to 1 when walking the tree because
we no longer have to look at node->level.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4228>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4228>
src/util/sparse_array.c
src/util/sparse_array.h