byteorder: add get/put endian helpers for the aligned case
PATCH 1/1 byteorder: add get/put endian helpers for the aligned case
Create helpers when working with aligned loads/stores, same functionality as get_unaligned_* and put_unaligned_*
Signed-off-by Harvey Harrison <[email protected]>
--- include/linux/byteorder.h | 84 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 84 insertions(+), 0 deletions(-)
include/linux/byteorder.h +84 -0
@@ -278,6 +278,90 @@ static inline __be64 __cpu_to_be64p(const __u64 *p)# define htons (x) ___htons(x)# define ntohs (x) ___ntohs(x) +static inline u16 get_le16 (const __le16 *p) +{ +#ifdef __LITTLE_ENDIAN +return (__force u16)*p; +#else +return swab16p ((__force u16 *)p); +#endif +} + +static inline u32 get_le32 (const __le32 *p) +{ +#ifdef __LITTLE_ENDIAN +return (__force u32)*p; +#else +return swab32p ((__force u32 *)p); +#endif +} + +static inline u64 get_le64 (const __le64 *p) +{ +#ifdef __LITTLE_ENDIAN +return (__force u64)*p; +#else +return __swab64p ((__force u64 *)p); +#endif +} + +static inline u16 get_be16 (const __be16 *p) +{ +#ifdef __BIG_ENDIAN +return (__force u16)*p; +#else +return swab16p ((__force u16 *)p); +#endif +} + +static inline u32 get_be32 (const __be32 *p) +{ +#ifdef __BIG_ENDIAN +return (__force u32)*p; +#else +return swab32p ((__force u32 *)p); +#endif +} + +static inline u64 get_be64 (const __be64 *p) +{ +#ifdef __BIG_ENDIAN +return (__force u64)*p; +#else +return __swab64p ((__force u64 *)p); +#endif +} + +static inline void put_le16 (u16 val,__le16 *p) +{ + *p =cpu_to_le16 (val); +} + +static inline void put_le32 (u32 val,__le32 *p) +{ + *p =cpu_to_le32 (val); +} + +static inline void put_le64 (u64 val,__le64 *p) +{ + *p =cpu_to_le64 (val); +} + +static inline void put_be16 (u16 val,__be16 *p) +{ + *p =cpu_to_be16 (val); +} + +static inline void put_be32 (u32 val,__be32 *p) +{ + *p =cpu_to_be32 (val); +} + +static inline void put_be64 (u64 val,__be64 *p) +{ + *p =cpu_to_be64 (val); +} +static inline void le16_add_cpu (__le16 *var,u16 val) { *var =cpu_to_le16 (le16_to_cpup (var) + val);
Signature · 1 line
1.5.5.1.579.g4e43