Skip to content

Commit 118d777

Browse files
mrutland-armctmarinas
authored andcommitted
wordpart.h: Add REPEAT_BYTE_U32()
In some cases it's necessary to replicate a byte across a u32 value, for which REPEAT_BYTE() would be helpful. Currently this requires explicit masking of the result to avoid sparse warnings, as e.g. (u32)REPEAT_BYTE(0xa0)) ... will result in a warning: cast truncates bits from constant value (a0a0a0a0a0a0a0a0 becomes a0a0a0a0) Add a new REPEAT_BYTE_U32() which does the necessary masking internally, so that we don't need to duplicate this for every usage. Signed-off-by: Mark Rutland <[email protected]> Cc: Alexandru Elisei <[email protected]> Cc: Marc Zyngier <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]> Acked-by: Thomas Gleixner <[email protected]>
1 parent 83a7eef commit 118d777

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

include/linux/wordpart.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@
3939
*/
4040
#define REPEAT_BYTE(x) ((~0ul / 0xff) * (x))
4141

42+
/**
43+
* REPEAT_BYTE_U32 - repeat the value @x multiple times as a u32 value
44+
* @x: value to repeat
45+
*
46+
* NOTE: @x is not checked for > 0xff; larger values produce odd results.
47+
*/
48+
#define REPEAT_BYTE_U32(x) lower_32_bits(REPEAT_BYTE(x))
49+
4250
/* Set bits in the first 'n' bytes when loaded from memory */
4351
#ifdef __LITTLE_ENDIAN
4452
# define aligned_byte_mask(n) ((1UL << 8*(n))-1)

0 commit comments

Comments
 (0)