linux/compat.h: port lower_32_bits and upper_32_bits from Linux
PATCH v4 1/2 linux/compat.h: port lower_32_bits and upper_32_bits from Linux
[backport from linux commit 204b885e and 218e180e7]
64 bit processors are becomming more and more popular. lower_32_bits and upper_32_bits save our labor doing shifts/manipulations like (u32)(n) and (u32)((n) >> 32). They are good helpers in both little and big endian cases. Port these two functions here from Linux:include/linux/kernel.h, cater the comment message to little/big endian cases. Later on, developers could include linux/compat.h if they want to use these two functions.
---
v4: split v3 into 2 patches.
v3: change the comment message for lower_32_bits() and upper_32_bits()
change the commit message to argue the necessity of this patch.
v2: add git SHA of linux kernel tree.
include/linux/compat.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
include/linux/compat.h +19 -0
@@ -57,4 +57,23 @@ , __FILE__, __LINE__); }#define PAGE_SIZE 4096 + +/** +* upper_32_bits - return MSB bits 32-63 of a number if little endian, or +* return MSB bits 0-31 of a number if big endian. +* @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 LSB bits 0-31 of a number if little endian, or +* return LSB bits 32-63 of a number if big endian. +* @n: the number we're accessing +*/ +#define lower_32_bits (n) ((u32)(n)) +#endif
Signature · 1 line
1.9.3
PATCH v4 1/2 linux/compat.h: port lower_32_bits and upper_32_bits from Linux
Quoted 11 lines · Lijun Pan
[backport from linux commit
204b885eand218e180e7]
64 bit processors are becomming more and more popular.lower_32_bitsandupper_32_bitssave our labor doing shifts/manipulations like (u32)(n) and (u32)((n) >> 32). They are good helpers in both little and big endian cases. Port these two functions here from Linux:include/linux/kernel.h, cater the comment message to little/big endian cases. Later on, developers could includelinux/compat.hif they want to use these two functions.Signed-off-by Lijun Pan <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140722/5a702ddd/attachment.pgp>