From eeeda9a11637c8093a0efaa5cdf9675c0b6da3b9 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Wed, 26 Feb 2020 16:00:51 -0500 Subject: [PATCH] misc: Use GCC builtins for byteswapping. (On most CPUs this translates to single-cycle operations. 1.2% binary size shrink on x86_64, for example) --- backend_common.h | 40 +++++------------------------ lib6145/libS6145ImageReProcess.c | 41 +++++------------------------- lib70x/libMitsuD70ImageReProcess.c | 41 +++++------------------------- 3 files changed, 18 insertions(+), 104 deletions(-) diff --git a/backend_common.h b/backend_common.h index fc88b06..221d23d 100644 --- a/backend_common.h +++ b/backend_common.h @@ -59,41 +59,13 @@ #define le64_to_cpu(__x) __x #define le32_to_cpu(__x) __x #define le16_to_cpu(__x) __x -#define be16_to_cpu(__x) ((uint16_t)( \ - (((uint16_t)(__x) & (uint16_t)0x00ff) << 8) | \ - (((uint16_t)(__x) & (uint16_t)0xff00) >> 8) )) -#define be32_to_cpu(__x) ((uint32_t)( \ - (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \ - (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \ - (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \ - (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )) -#define be64_to_cpu(__x) ((uint64_t)( \ - (((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \ - (((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \ - (((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \ - (((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) << 8) | \ - (((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \ - (((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \ - (((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \ - (((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56) )) +#define be16_to_cpu(__x) __builtin_bswap16(__x) +#define be32_to_cpu(__x) __builtin_bswap32(__x) +#define be64_to_cpu(__x) __builtin_bswap64(__x) #else -#define le16_to_cpu(__x) ((uint16_t)( \ - (((uint16_t)(__x) & (uint16_t)0x00ff) << 8) | \ - (((uint16_t)(__x) & (uint16_t)0xff00) >> 8) )) -#define le32_to_cpu(__x) ((uint32_t)( \ - (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \ - (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \ - (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \ - (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )) -#define le64_to_cpu(__x) ((uint64_t)( \ - (((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \ - (((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \ - (((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \ - (((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) << 8) | \ - (((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \ - (((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \ - (((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \ - (((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56))) +#define le16_to_cpu(__x) __builtin_bswap16(__x) +#define le32_to_cpu(__x) __builtin_bswap32(__x) +#define le64_to_cpu(__x) __builtin_bswap64(__x) #define be64_to_cpu(__x) __x #define be32_to_cpu(__x) __x #define be16_to_cpu(__x) __x diff --git a/lib6145/libS6145ImageReProcess.c b/lib6145/libS6145ImageReProcess.c index 2428ab6..2bb9c73 100644 --- a/lib6145/libS6145ImageReProcess.c +++ b/lib6145/libS6145ImageReProcess.c @@ -224,46 +224,17 @@ static void LeadEdgeCorrection(void); //------------------------------------------------------------------------- // Endian Manipulation macros - #if (__BYTE_ORDER == __LITTLE_ENDIAN) #define le64_to_cpu(__x) __x #define le32_to_cpu(__x) __x #define le16_to_cpu(__x) __x -#define be16_to_cpu(__x) ((uint16_t)( \ - (((uint16_t)(__x) & (uint16_t)0x00ff) << 8) | \ - (((uint16_t)(__x) & (uint16_t)0xff00) >> 8) )) -#define be32_to_cpu(__x) ((uint32_t)( \ - (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \ - (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \ - (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \ - (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )) -#define be64_to_cpu(__x) ((uint64_t)( \ - (((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \ - (((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \ - (((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \ - (((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) << 8) | \ - (((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \ - (((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \ - (((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \ - (((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56) )) +#define be16_to_cpu(__x) __builtin_bswap16(__x) +#define be32_to_cpu(__x) __builtin_bswap32(__x) +#define be64_to_cpu(__x) __builtin_bswap64(__x) #else -#define le16_to_cpu(__x) ((uint16_t)( \ - (((uint16_t)(__x) & (uint16_t)0x00ff) << 8) | \ - (((uint16_t)(__x) & (uint16_t)0xff00) >> 8) )) -#define le32_to_cpu(__x) ((uint32_t)( \ - (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \ - (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \ - (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \ - (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )) -#define le64_to_cpu(__x) ((uint64_t)( \ - (((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \ - (((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \ - (((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \ - (((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) << 8) | \ - (((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \ - (((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \ - (((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \ - (((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56))) +#define le16_to_cpu(__x) __builtin_bswap16(__x) +#define le32_to_cpu(__x) __builtin_bswap32(__x) +#define le64_to_cpu(__x) __builtin_bswap64(__x) #define be64_to_cpu(__x) __x #define be32_to_cpu(__x) __x #define be16_to_cpu(__x) __x diff --git a/lib70x/libMitsuD70ImageReProcess.c b/lib70x/libMitsuD70ImageReProcess.c index fba91aa..2acc214 100644 --- a/lib70x/libMitsuD70ImageReProcess.c +++ b/lib70x/libMitsuD70ImageReProcess.c @@ -65,46 +65,17 @@ //------------------------------------------------------------------------- // Endian Manipulation macros - #if (__BYTE_ORDER == __LITTLE_ENDIAN) #define le64_to_cpu(__x) __x #define le32_to_cpu(__x) __x #define le16_to_cpu(__x) __x -#define be16_to_cpu(__x) ((uint16_t)( \ - (((uint16_t)(__x) & (uint16_t)0x00ff) << 8) | \ - (((uint16_t)(__x) & (uint16_t)0xff00) >> 8) )) -#define be32_to_cpu(__x) ((uint32_t)( \ - (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \ - (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \ - (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \ - (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )) -#define be64_to_cpu(__x) ((uint64_t)( \ - (((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \ - (((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \ - (((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \ - (((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) << 8) | \ - (((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \ - (((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \ - (((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \ - (((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56) )) +#define be16_to_cpu(__x) __builtin_bswap16(__x) +#define be32_to_cpu(__x) __builtin_bswap32(__x) +#define be64_to_cpu(__x) __builtin_bswap64(__x) #else -#define le16_to_cpu(__x) ((uint16_t)( \ - (((uint16_t)(__x) & (uint16_t)0x00ff) << 8) | \ - (((uint16_t)(__x) & (uint16_t)0xff00) >> 8) )) -#define le32_to_cpu(__x) ((uint32_t)( \ - (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \ - (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \ - (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \ - (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )) -#define le64_to_cpu(__x) ((uint64_t)( \ - (((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \ - (((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \ - (((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \ - (((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) << 8) | \ - (((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \ - (((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \ - (((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \ - (((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56))) +#define le16_to_cpu(__x) __builtin_bswap16(__x) +#define le32_to_cpu(__x) __builtin_bswap32(__x) +#define le64_to_cpu(__x) __builtin_bswap64(__x) #define be64_to_cpu(__x) __x #define be32_to_cpu(__x) __x #define be16_to_cpu(__x) __x