[PATCH 7/8] Use lswap{l,s} in cpswap{l,s}
Matt Turner
mattst88 at gmail.com
Tue Aug 16 19:58:26 PDT 2011
Should be safe since cpswap isn't used on pointers.
text data bss dec hex filename
before: 1875588 52136 78040 2005764 1e9b04 hw/xfree86/Xorg
after: 1872820 52136 78040 2002996 1e9034 hw/xfree86/Xorg
bswap instructions: 5 -> 131 (used in lswapl)
rol instructions: 811 -> 943 (used in lswaps)
Signed-off-by: Matt Turner <mattst88 at gmail.com>
---
include/misc.h | 14 ++++++--------
1 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/include/misc.h b/include/misc.h
index 46b83ef..cfe734f 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -304,20 +304,18 @@ static inline void swap_uint16(uint16_t *x)
} while (0)
/* copy 32-bit value from src to dst byteswapping on the way */
-#define cpswapl(src, dst) { \
+#define cpswapl(src, dst) do { \
if (sizeof((src)) != 4 || sizeof((dst)) != 4) \
wrong_size(); \
- ((char *)&(dst))[0] = ((char *) &(src))[3];\
- ((char *)&(dst))[1] = ((char *) &(src))[2];\
- ((char *)&(dst))[2] = ((char *) &(src))[1];\
- ((char *)&(dst))[3] = ((char *) &(src))[0]; }
+ (dst) = lswapl((src)); \
+ } while (0)
/* copy short from src to dst byteswapping on the way */
-#define cpswaps(src, dst) { \
+#define cpswaps(src, dst) do { \
if (sizeof((src)) != 2 || sizeof((dst)) != 2) \
wrong_size(); \
- ((char *) &(dst))[0] = ((char *) &(src))[1];\
- ((char *) &(dst))[1] = ((char *) &(src))[0]; }
+ (dst) = lswaps((src)); \
+ } while (0)
extern _X_EXPORT void SwapLongs(
CARD32 *list,
--
1.7.3.4
More information about the xorg-devel
mailing list