mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 22:38:05 +02:00
util: add util_bit_swap macro
We will use this to manipulate lookup tables, but it's a common algorithm. Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37200>
This commit is contained in:
parent
055f8ebf96
commit
86a5dd10ac
1 changed files with 11 additions and 0 deletions
|
|
@ -564,4 +564,15 @@ typedef int lock_cap_t;
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Swap bits a and b. From Bithacks
|
||||
* https://graphics.stanford.edu/~seander/bithacks.html#SwappingBitsXOR
|
||||
*/
|
||||
static inline uint32_t
|
||||
util_bit_swap(uint32_t v, unsigned a, unsigned b)
|
||||
{
|
||||
uint32_t x = ((v >> a) ^ (v >> b)) & 1;
|
||||
return v ^ ((x << a) | (x << b));
|
||||
}
|
||||
|
||||
#endif /* UTIL_MACROS_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue