changeset 2660:e26dc8cf7069 libavcodec

optimization
author michael
date Tue, 10 May 2005 19:54:38 +0000
parents 4023235edd2e
children b2846918585c
files bswap.h
diffstat 1 files changed, 18 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/bswap.h	Tue May 10 10:05:44 2005 +0000
+++ b/bswap.h	Tue May 10 19:54:38 2005 +0000
@@ -19,7 +19,7 @@
 #if defined(ARCH_X86) || defined(ARCH_X86_64)
 static always_inline uint16_t bswap_16(uint16_t x)
 {
-  __asm("xchgb %b0,%h0"	:
+  __asm("rorw $8, %0"	:
         LEGACY_REGS (x)	:
         "0" (x));
     return x;
@@ -48,12 +48,15 @@
         "0" (x));
   return x;
 #else
-  register union { __extension__ uint64_t __ll;
-          uint32_t __l[2]; } __x;
-  asm("xchgl	%0,%1":
-      "=r"(__x.__l[0]),"=r"(__x.__l[1]):
-      "0"(bswap_32((uint32_t)x)),"1"(bswap_32((uint32_t)(x>>32))));
-  return __x.__ll;
+    union { 
+        uint64_t ll;
+        struct {
+           uint32_t l,h;
+        } l;
+    } r;
+    r.l.l = bswap_32 (x);
+    r.l.h = bswap_32 (x>>32);
+    return r.ll;
 #endif
 }
 
@@ -92,11 +95,17 @@
 }
 
 static always_inline uint32_t bswap_32(uint32_t x){
-    return (x >> 24) | ((x & 0x00ff0000) >>  8) | ((x & 0x0000ff00) <<  8) | (x << 24);
+    x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
+    return (x>>16) | (x<<16);
 }
 
 static inline uint64_t bswap_64(uint64_t x)
 {
+#if 0
+    x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);
+    x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL);
+    return (x>>32) | (x<<32);
+#else
     union { 
         uint64_t ll;
         uint32_t l[2]; 
@@ -105,6 +114,7 @@
     r.l[0] = bswap_32 (w.l[1]);
     r.l[1] = bswap_32 (w.l[0]);
     return r.ll;
+#endif
 }
 #endif	/* !ARCH_X86 */