From 3c1b33b7d57ad8b8aeeab8babd48625b86532e0b Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 7 Jun 2018 15:18:51 +0200 Subject: [PATCH] utils: add const_* byteswapping functions Some gcc versions have issues with the __builtin_choose_expr construct which attempts to automatically use the const versions of those functions. Make it possible to explicitly use const_* versions to avoid that. Signed-off-by: Felix Fietkau --- utils.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/utils.h b/utils.h index 019d817..27f81e5 100644 --- a/utils.h +++ b/utils.h @@ -142,6 +142,22 @@ int clock_gettime(int type, struct timespec *tv); #if __BYTE_ORDER == __LITTLE_ENDIAN +#define const_cpu_to_be64(x) __constant_swap64(x) +#define const_cpu_to_be32(x) __constant_swap32(x) +#define const_cpu_to_be16(x) __constant_swap16(x) + +#define const_be64_to_cpu(x) __constant_swap64(x) +#define const_be32_to_cpu(x) __constant_swap32(x) +#define const_be16_to_cpu(x) __constant_swap16(x) + +#define const_cpu_to_le64(x) (x) +#define const_cpu_to_le32(x) (x) +#define const_cpu_to_le16(x) (x) + +#define const_le64_to_cpu(x) (x) +#define const_le32_to_cpu(x) (x) +#define const_le16_to_cpu(x) (x) + #define cpu_to_be64(x) __eval_safe(__constant_swap64, x) #define cpu_to_be32(x) __eval_safe(__constant_swap32, x) #define cpu_to_be16(x) __eval_safe(__constant_swap16, x) @@ -160,6 +176,22 @@ int clock_gettime(int type, struct timespec *tv); #else /* __BYTE_ORDER == __LITTLE_ENDIAN */ +#define const_cpu_to_le64(x) __constant_swap64(x) +#define const_cpu_to_le32(x) __constant_swap32(x) +#define const_cpu_to_le16(x) __constant_swap16(x) + +#define const_le64_to_cpu(x) __constant_swap64(x) +#define const_le32_to_cpu(x) __constant_swap32(x) +#define const_le16_to_cpu(x) __constant_swap16(x) + +#define const_cpu_to_be64(x) (x) +#define const_cpu_to_be32(x) (x) +#define const_cpu_to_be16(x) (x) + +#define const_be64_to_cpu(x) (x) +#define const_be32_to_cpu(x) (x) +#define const_be16_to_cpu(x) (x) + #define cpu_to_le64(x) __eval_safe(__constant_swap64, x) #define cpu_to_le32(x) __eval_safe(__constant_swap32, x) #define cpu_to_le16(x) __eval_safe(__constant_swap16, x) -- 2.30.2