[PATCH] ASM-optimized byteswap functions
Diego Biurrun <[email protected]> Thu, 19 Jan 2006 00:57:31 +0100
| Newsgroups | gmane.comp.video.ogle.devel |
|---|---|
| Message-ID | <[email protected]> |
--TYecfFk8j8mZq+dy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Hi,
this stuff has been sitting in the MPlayer tree forever.
Please review / apply.
Diego
--TYecfFk8j8mZq+dy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="libdvdread_asm.patch"
Index: dvdread/bswap.h
===================================================================
RCS file: /cvsroot/ogle/libdvdread/dvdread/bswap.h,v
retrieving revision 1.13
diff -u -r1.13 bswap.h
--- dvdread/bswap.h 19 Sep 2005 14:14:34 -0000 1.13
+++ dvdread/bswap.h 18 Jan 2006 23:54:49 -0000
@@ -76,6 +76,44 @@
#define B2N_32(x) x = be32toh(x)
#define B2N_64(x) x = be64toh(x)
+#elif defined(ARCH_X86)
+inline static unsigned short bswap_16(unsigned short x)
+{
+ __asm("xchgb %b0,%h0" :
+ "=q" (x) :
+ "0" (x));
+ return x;
+}
+#define B2N_16(x) x = bswap_16(x)
+
+inline static unsigned int bswap_32(unsigned int x)
+{
+ __asm(
+#if __CPU__ > 386
+ "bswap %0":
+ "=r" (x) :
+#else
+ "xchgb %b0,%h0\n"
+ " rorl $16,%0\n"
+ " xchgb %b0,%h0":
+ "=q" (x) :
+#endif
+ "0" (x));
+ return x;
+}
+#define B2N_32(x) x = bswap_32(x)
+
+inline static unsigned long long int bswap_64(unsigned long long int x)
+{
+ 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((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32))));
+ return __x.__ll;
+}
+#define B2N_64(x) x = bswap_64(x)
+
/* This is a slow but portable implementation, it has multiple evaluation
* problems so beware.
* Old FreeBSD's and Solaris don't have <byteswap.h> or any other such
--TYecfFk8j8mZq+dy--