[PATCH 4/5] Use lswapl() in cpswapl macro

Matt Turner mattst88 at gmail.com
Thu Aug 4 15:06:35 PDT 2011


Small reduction in text size:
   text   data    bss      dec     hex  filename
1866284  52136  78040  1996460  1e76ac  ./hw/xfree86/Xorg
1863788  52136  78040  1993964  1e6cec  ./hw/xfree86/Xorg

and the number of bswap instructions increases from 5 to 131.

lswaps is not used in cpswaps because it actually increases the code size.

Signed-off-by: Matt Turner <mattst88 at gmail.com>
---
 include/misc.h |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/include/misc.h b/include/misc.h
index ebfbc1a..d2b5e11 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -282,18 +282,21 @@ void __attribute__((error("wrong sized variable passed to swap"))) wrong_size(vo
 	} while (0)
 
 /* copy 32-bit value from src to dst byteswapping on the way */
-#define cpswapl(src, dst) { \
-                  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]; }
+#define cpswapl(src, dst)				\
+    do {						\
+	if (sizeof((src)) != 4 || sizeof((dst)) != 4)	\
+	    wrong_size();				\
+	(dst) = lswapl((src));				\
+    } while (0)
 
 /* copy short from src to dst byteswapping on the way */
-#define cpswaps(src, dst) { \
-		 if (sizeof((src)) != 2 || sizeof((dst)) != 2) wrong_size();\
-		 ((char *) &(dst))[0] = ((char *) &(src))[1];\
-		 ((char *) &(dst))[1] = ((char *) &(src))[0]; }
+#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];	\
+    } while (0)
 
 extern _X_EXPORT void SwapLongs(
     CARD32 *list,
-- 
1.7.3.4



More information about the xorg-devel mailing list