mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 20:28:04 +02:00
util: Add util_widen_mask function.
Widens the given bit mask by a multiplier, meaning that it will replicate each bit by that amount. For example: 0b101 widened by 2 will become: 0b110011 This is typically used in shader I/O to transform a 64-bit writemask to a 32-bit writemask. Moving this function here because it is used in multiple places. Signed-off-by: Timur Kristóf <timur.kristof@gmail.com> Reviewed-by: Rhys Perry <pendingchaos02@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14005>
This commit is contained in:
parent
7e66da89f8
commit
6cde424945
1 changed files with 19 additions and 0 deletions
|
|
@ -349,6 +349,25 @@ util_bitcount64(uint64_t n)
|
|||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Widens the given bit mask by a multiplier, meaning that it will
|
||||
* replicate each bit by that amount.
|
||||
*
|
||||
* For example:
|
||||
* 0b101 widened by 2 will become: 0b110011
|
||||
*
|
||||
* This is typically used in shader I/O to transform a 64-bit
|
||||
* writemask to a 32-bit writemask.
|
||||
*/
|
||||
static inline uint32_t
|
||||
util_widen_mask(uint32_t mask, unsigned multiplier)
|
||||
{
|
||||
uint32_t new_mask = 0;
|
||||
u_foreach_bit(i, mask)
|
||||
new_mask |= ((1u << multiplier) - 1u) << (i * multiplier);
|
||||
return new_mask;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue