[PATCH 5/6 V2] [pcm_dmix assembly] refactor the PIC mode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Frédéric Recoules <frederic.recoules@xxxxxxxxx>

Note: newer versions of GCC accept that ebx is declared
      in the clobber list.

Signed-off-by: Frédéric Recoules <frederic.recoules@xxxxxxxxx>
---
 src/pcm/pcm_dmix_i386.h   | 93 ++++++++++++++++++++++++++++++---------
 src/pcm/pcm_dmix_x86_64.h | 59 ++++++++++++++++++++-----
 2 files changed, 120 insertions(+), 32 deletions(-)

diff --git a/src/pcm/pcm_dmix_i386.h b/src/pcm/pcm_dmix_i386.h
index d9bf8f50..b28ae787 100644
--- a/src/pcm/pcm_dmix_i386.h
+++ b/src/pcm/pcm_dmix_i386.h
@@ -26,6 +26,10 @@
  *
  */

+#if defined(__GNUC__) && __GNUC__ < 5 && defined(__PIC__)
+#  define BOUNDED_EBX
+#endif
+
 /*
  *  for plain i386
  */
@@ -34,8 +38,9 @@ static void MIX_AREAS_16(unsigned int size,
 			 volatile signed int *sum, size_t dst_step,
 			 size_t src_step, size_t sum_step)
 {
+#     ifdef BOUNDED_EBX
 	unsigned int old_ebx;
-
+#     endif
 	/*
 	 *  ESI - src
 	 *  EDI - dst
@@ -46,8 +51,9 @@ static void MIX_AREAS_16(unsigned int size,
 	 */
 	__asm__ __volatile__ (
 		"\n"
-
+#            ifdef BOUNDED_EBX
 		"\tmovl %%ebx, %[old_ebx]\n"	/* ebx is GOT pointer (-fPIC) */
+#            endif
 		/*
 		 *  initialization, load ESI, EDI, EBX registers
 		 */
@@ -140,13 +146,20 @@ static void MIX_AREAS_16(unsigned int size,
 		"\tjnz 1b\n"

 		"7:"
+#            ifdef BOUNDED_EBX
 		"\tmovl %[old_ebx], %%ebx\n"	/* ebx is GOT pointer (-fPIC) */
-
-		: [size] "+m" (size), [old_ebx] "=m" (old_ebx)
+#            endif
+		: [size] "+m" (size)
+#               ifdef BOUNDED_EBX
+		  , [old_ebx] "=m" (old_ebx)
+#               endif
 		: [dst] "m" (dst), [src] "m" (src), [sum] "m" (sum),
 		  [dst_step] "m" (dst_step),  [src_step] "m" (src_step),
 		  [sum_step] "m" (sum_step)
 		: "esi", "edi", "edx", "ecx", "eax", "memory", "cc"
+#               ifndef BOUNDED_EBX
+		  , "ebx"
+#               endif
 	);
 }

@@ -158,8 +171,9 @@ static void MIX_AREAS_16_MMX(unsigned int size,
 			     volatile signed int *sum, size_t dst_step,
 			     size_t src_step, size_t sum_step)
 {
+#     ifdef BOUNDED_EBX
 	unsigned int old_ebx;
-
+#     endif
 	/*
 	 *  ESI - src
 	 *  EDI - dst
@@ -170,8 +184,9 @@ static void MIX_AREAS_16_MMX(unsigned int size,
 	 */
 	__asm__ __volatile__ (
 		"\n"
-
+#            ifdef BOUNDED_EBX
 		"\tmovl %%ebx, %[old_ebx]\n"	/* ebx is GOT pointer (-fPIC) */
+#            endif
 		/*
 		 *  initialization, load ESI, EDI, EBX registers and clear MM1
 		 */
@@ -231,13 +246,20 @@ static void MIX_AREAS_16_MMX(unsigned int size,
 		"\tjnz 1b\n"
 		"\temms\n"
                 "5:"
+#            ifdef BOUNDED_EBX
 		"\tmovl %[old_ebx], %%ebx\n"	/* ebx is GOT pointer (-fPIC) */
-
-	        : [size] "+m" (size), [old_ebx] "=m" (old_ebx)
+#            endif
+		: [size] "+m" (size)
+#               ifdef BOUNDED_EBX
+		  , [old_ebx] "=m" (old_ebx)
+#               endif
 		: [dst] "m" (dst), [src] "m" (src), [sum] "m" (sum),
 		  [dst_step] "m" (dst_step),  [src_step] "m" (src_step),
 		  [sum_step] "m" (sum_step)
 		: "esi", "edi", "edx", "ecx", "eax", "memory", "cc"
+#               ifndef BOUNDED_EBX
+		  , "ebx"
+#               endif
 #               ifdef HAVE_MMX
 		  , "mm0", "mm1"
 #               else
@@ -255,8 +277,9 @@ static void MIX_AREAS_32(unsigned int size,
 			 volatile signed int *sum, size_t dst_step,
 			 size_t src_step, size_t sum_step)
 {
+#     ifdef BOUNDED_EBX
 	unsigned int old_ebx;
-
+#     endif
 	/*
 	 *  ESI - src
 	 *  EDI - dst
@@ -267,8 +290,9 @@ static void MIX_AREAS_32(unsigned int size,
 	 */
 	__asm__ __volatile__ (
 		"\n"
-
+#            ifdef BOUNDED_EBX
 		"\tmovl %%ebx, %[old_ebx]\n"	/* ebx is GOT pointer (-fPIC) */
+#            endif
 		/*
 		 *  initialization, load ESI, EDI, EBX registers
 		 */
@@ -350,13 +374,20 @@ static void MIX_AREAS_32(unsigned int size,
 		"\tjmp 1b\n"

 		"6:"
+#            ifdef BOUNDED_EBX
 		"\tmovl %[old_ebx], %%ebx\n"	/* ebx is GOT pointer (-fPIC) */
-
-		: [size] "+m" (size), [old_ebx] "=m" (old_ebx)
+#            endif
+		: [size] "+m" (size)
+#               ifdef BOUNDED_EBX
+		  , [old_ebx] "=m" (old_ebx)
+#               endif
 		: [dst] "m" (dst), [src] "m" (src), [sum] "m" (sum),
 		  [dst_step] "m" (dst_step),  [src_step] "m" (src_step),
 		  [sum_step] "m" (sum_step)
 		: "esi", "edi", "edx", "ecx", "eax", "memory", "cc"
+#               ifndef BOUNDED_EBX
+		  , "ebx"
+#               endif
 	);
 }

@@ -368,8 +399,9 @@ static void MIX_AREAS_24(unsigned int size,
 			 volatile signed int *sum, size_t dst_step,
 			 size_t src_step, size_t sum_step)
 {
+#     ifdef BOUNDED_EBX
 	unsigned int old_ebx;
-
+#     endif
 	/*
 	 *  ESI - src
 	 *  EDI - dst
@@ -380,8 +412,9 @@ static void MIX_AREAS_24(unsigned int size,
 	 */
 	__asm__ __volatile__ (
 		"\n"
-
+#            ifdef BOUNDED_EBX
 		"\tmovl %%ebx, %[old_ebx]\n"	/* ebx is GOT pointer (-fPIC) */
+#            endif
 		/*
 		 *  initialization, load ESI, EDI, EBX registers
 		 */
@@ -456,13 +489,20 @@ static void MIX_AREAS_24(unsigned int size,
 		"\tjmp 1b\n"

 		"6:"
+#            ifdef BOUNDED_EBX
 		"\tmovl %[old_ebx], %%ebx\n"	/* ebx is GOT pointer (-fPIC) */
-
-	        : [size] "+m" (size), [old_ebx] "=m" (old_ebx)
+#            endif
+		: [size] "+m" (size)
+#               ifdef BOUNDED_EBX
+		  , [old_ebx] "=m" (old_ebx)
+#               endif
 		: [dst] "m" (dst), [src] "m" (src), [sum] "m" (sum),
 		  [dst_step] "m" (dst_step),  [src_step] "m" (src_step),
 		  [sum_step] "m" (sum_step)
 		: "esi", "edi", "edx", "ecx", "eax", "memory", "cc"
+#               ifndef BOUNDED_EBX
+		  , "ebx"
+#               endif
 	);
 }

@@ -474,8 +514,9 @@ static void MIX_AREAS_24_CMOV(unsigned int size,
 			      volatile signed int *sum, size_t dst_step,
 			      size_t src_step, size_t sum_step)
 {
+#     ifdef BOUNDED_EBX
 	unsigned int old_ebx;
-
+#     endif
 	/*
 	 *  ESI - src
 	 *  EDI - dst
@@ -486,8 +527,9 @@ static void MIX_AREAS_24_CMOV(unsigned int size,
 	 */
 	__asm__ __volatile__ (
 		"\n"
-
+#            ifdef BOUNDED_EBX
 		"\tmovl %%ebx, %[old_ebx]\n"	/* ebx is GOT pointer (-fPIC) */
+#            endif
 		/*
 		 *  initialization, load ESI, EDI, EBX registers
 		 */
@@ -555,12 +597,23 @@ static void MIX_AREAS_24_CMOV(unsigned int size,
 		"\tjnz 1b\n"

 		"6:"
+#            ifdef BOUNDED_EBX
 		"\tmovl %[old_ebx], %%ebx\n"	/* ebx is GOT pointer (-fPIC) */
-
-	        : [size] "+m" (size), [old_ebx] "=m" (old_ebx)
+#            endif
+		: [size] "+m" (size)
+#               ifdef BOUNDED_EBX
+		  , [old_ebx] "=m" (old_ebx)
+#               endif
 		: [dst] "m" (dst), [src] "m" (src), [sum] "m" (sum),
 		  [dst_step] "m" (dst_step),  [src_step] "m" (src_step),
 		  [sum_step] "m" (sum_step)
 		: "esi", "edi", "edx", "ecx", "eax", "memory", "cc"
+#               ifndef BOUNDED_EBX
+		  , "ebx"
+#               endif
 	);
 }
+
+#ifdef BOUNDED_EBX
+#  undef BOUNDED_EBX
+#endif
diff --git a/src/pcm/pcm_dmix_x86_64.h b/src/pcm/pcm_dmix_x86_64.h
index 8ad1b2a0..f543a134 100644
--- a/src/pcm/pcm_dmix_x86_64.h
+++ b/src/pcm/pcm_dmix_x86_64.h
@@ -27,6 +27,10 @@
  *
  */

+#if defined(__GNUC__) && __GNUC__ < 5 && defined(__PIC__)
+#  define BOUNDED_RBX
+#endif
+
 /*
  *  MMX optimized
  */
@@ -35,8 +39,9 @@ static void MIX_AREAS_16(unsigned int size,
 			 volatile signed int *sum, size_t dst_step,
 			 size_t src_step, size_t sum_step)
 {
+#     ifdef BOUNDED_RBX
 	unsigned long long old_rbx;
-
+#     endif
 	/*
 	 *  RSI - src
 	 *  RDI - dst
@@ -47,8 +52,9 @@ static void MIX_AREAS_16(unsigned int size,
 	 */
 	__asm__ __volatile__ (
 		"\n"
-
+#            ifdef BOUNDED_RBX
 		"\tmovq %%rbx, %[old_rbx]\n"
+#            endif
 		/*
 		 *  initialization, load RSI, RDI, RBX registers and clear MM1
 		 */
@@ -113,13 +119,20 @@ static void MIX_AREAS_16(unsigned int size,
 		"6:"

 		"\temms\n"
+#            ifdef BOUNDED_RBX
 		"\tmovq %[old_rbx], %%rbx\n"
-
-		: [size] "+m" (size), [old_rbx] "=m" (old_rbx)
+#            endif
+		: [size] "+m" (size)
+#               ifdef BOUNDED_RBX
+		  , [old_rbx] "=m" (old_rbx)
+#               endif
 	        : [dst] "m" (dst), [src] "m" (src), [sum] "m" (sum),
 		  [dst_step] "m" (dst_step),  [src_step] "m" (src_step),
 		  [sum_step] "m" (sum_step)
 		: "rsi", "rdi", "edx", "ecx", "eax", "memory", "cc"
+#               ifndef BOUNDED_RBX
+		  , "rbx"
+#               endif
 #               ifdef HAVE_MMX
 		  , "mm0", "mm1"
 #               else
@@ -137,8 +150,9 @@ static void MIX_AREAS_32(unsigned int size,
 			 volatile signed int *sum, size_t dst_step,
 			 size_t src_step, size_t sum_step)
 {
+#     ifdef BOUNDED_RBX
 	unsigned long long old_rbx;
-
+#     endif
 	/*
 	 *  RSI - src
 	 *  RDI - dst
@@ -149,8 +163,9 @@ static void MIX_AREAS_32(unsigned int size,
 	 */
 	__asm__ __volatile__ (
 		"\n"
-
+#            ifdef BOUNDED_RBX
 		"\tmovq %%rbx, %[old_rbx]\n"
+#            endif
 		/*
 		 *  initialization, load RSI, RDI, RBX registers
 		 */
@@ -234,13 +249,20 @@ static void MIX_AREAS_32(unsigned int size,
 		"\tjnz 1b\n"

 		"6:"
+#            ifdef BOUNDED_RBX
 		"\tmovq %[old_rbx], %%rbx\n"
-
-		: [size] "+m" (size), [old_rbx] "=m" (old_rbx)
+#            endif
+		: [size] "+m" (size)
+#               ifdef BOUNDED_RBX
+		  , [old_rbx] "=m" (old_rbx)
+#               endif
 	        : [dst] "m" (dst), [src] "m" (src), [sum] "m" (sum),
 		  [dst_step] "m" (dst_step),  [src_step] "m" (src_step),
 		  [sum_step] "m" (sum_step)
 		: "rsi", "rdi", "edx", "ecx", "eax", "memory", "cc"
+#               ifndef BOUNDED_RBX
+		  , "rbx"
+#               endif
 	);
 }

@@ -252,8 +274,9 @@ static void MIX_AREAS_24(unsigned int size,
 			 volatile signed int *sum, size_t dst_step,
 			 size_t src_step, size_t sum_step)
 {
+#     ifdef BOUNDED_RBX
 	unsigned long long old_rbx;
-
+#     endif
 	/*
 	 *  RSI - src
 	 *  RDI - dst
@@ -264,8 +287,9 @@ static void MIX_AREAS_24(unsigned int size,
 	 */
 	__asm__ __volatile__ (
 		"\n"
-
+#            ifdef BOUNDED_RBX
 		"\tmovq %%rbx, %[old_rbx]\n"
+#            endif
 		/*
 		 *  initialization, load RSI, RDI, RBX registers
 		 */
@@ -337,12 +361,23 @@ static void MIX_AREAS_24(unsigned int size,
 		"\tjnz 1b\n"

 		"6:"
+#            ifdef BOUNDED_RBX
 		"\tmovq %[old_rbx], %%rbx\n"
-
-		: [size] "+m" (size), [old_rbx] "=m" (old_rbx)
+#            endif
+		: [size] "+m" (size)
+#               ifdef BOUNDED_RBX
+		  , [old_rbx] "=m" (old_rbx)
+#               endif
 	        : [dst] "m" (dst), [src] "m" (src), [sum] "m" (sum),
 		  [dst_step] "m" (dst_step),  [src_step] "m" (src_step),
 		  [sum_step] "m" (sum_step)
 		: "rsi", "rdi", "edx", "ecx", "eax", "memory", "cc"
+#               ifndef BOUNDED_RBX
+		  , "rbx"
+#               endif
 	);
 }
+
+#ifdef BOUNDED_RBX
+#  undef BOUNDED_RBX
+#endif
--
2.17.1

Note: it has not been tested but I can not figure out it could break
something because the compiler is now aware that ebx is clobbered.
Curiously, it seems it significantly reduces the size of the code.



[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux