mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-29 13:23:23 +01:00
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]>
58 lines
1.5 KiB
C
58 lines
1.5 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#ifndef _LINUX_WORDPART_H
|
|
#define _LINUX_WORDPART_H
|
|
|
|
/**
|
|
* upper_32_bits - return bits 32-63 of a number
|
|
* @n: the number we're accessing
|
|
*
|
|
* A basic shift-right of a 64- or 32-bit quantity. Use this to suppress
|
|
* the "right shift count >= width of type" warning when that quantity is
|
|
* 32-bits.
|
|
*/
|
|
#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
|
|
|
|
/**
|
|
* lower_32_bits - return bits 0-31 of a number
|
|
* @n: the number we're accessing
|
|
*/
|
|
#define lower_32_bits(n) ((u32)((n) & 0xffffffff))
|
|
|
|
/**
|
|
* upper_16_bits - return bits 16-31 of a number
|
|
* @n: the number we're accessing
|
|
*/
|
|
#define upper_16_bits(n) ((u16)((n) >> 16))
|
|
|
|
/**
|
|
* lower_16_bits - return bits 0-15 of a number
|
|
* @n: the number we're accessing
|
|
*/
|
|
#define lower_16_bits(n) ((u16)((n) & 0xffff))
|
|
|
|
/**
|
|
* REPEAT_BYTE - repeat the value @x multiple times as an unsigned long value
|
|
* @x: value to repeat
|
|
*
|
|
* NOTE: @x is not checked for > 0xff; larger values produce odd results.
|
|
*/
|
|
#define REPEAT_BYTE(x) ((~0ul / 0xff) * (x))
|
|
|
|
/**
|
|
* REPEAT_BYTE_U32 - repeat the value @x multiple times as a u32 value
|
|
* @x: value to repeat
|
|
*
|
|
* NOTE: @x is not checked for > 0xff; larger values produce odd results.
|
|
*/
|
|
#define REPEAT_BYTE_U32(x) lower_32_bits(REPEAT_BYTE(x))
|
|
|
|
/* Set bits in the first 'n' bytes when loaded from memory */
|
|
#ifdef __LITTLE_ENDIAN
|
|
# define aligned_byte_mask(n) ((1UL << 8*(n))-1)
|
|
#else
|
|
# define aligned_byte_mask(n) (~0xffUL << (BITS_PER_LONG - 8 - 8*(n)))
|
|
#endif
|
|
|
|
#endif // _LINUX_WORDPART_H
|