[FFmpeg-devel] [PATCH 7/9] sbrdsp: unroll and use integer operations

Christophe Gisquet christophe.gisquet at gmail.com
Thu Apr 4 21:45:51 CEST 2013


This patch can be controversial, by assuming floats are IEEE-754 and
particular behaviour of the FPU will get in the way.
Timing on Arrandale and Win32 (thus, x87 FPU is used in the reference).

sbr_qmf_pre_shuffle_c: 115 to 76
sbr_neg_odd_64_c: 84 to 55
sbr_qmf_post_shuffle_c: 112 to 83
---
 libavcodec/sbrdsp.c | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/libavcodec/sbrdsp.c b/libavcodec/sbrdsp.c
index e2280cc..49c2107 100644
--- a/libavcodec/sbrdsp.c
+++ b/libavcodec/sbrdsp.c
@@ -51,28 +51,41 @@ static float sbr_sum_square_c(float (*x)[2], int n)
 
 static void sbr_neg_odd_64_c(float *x)
 {
+    uint32_t *xi = (uint32_t*)x;
     int i;
-    for (i = 1; i < 64; i += 2)
-        x[i] = -x[i];
+    for (i = 1; i < 64; i += 4)
+    {
+        xi[i+0] ^= 1U<<31;
+        xi[i+2] ^= 1U<<31;
+    }
 }
 
 static void sbr_qmf_pre_shuffle_c(float *z)
 {
+    uint32_t *zi = (uint32_t*)z;
     int k;
-    z[64] = z[0];
-    z[65] = z[1];
-    for (k = 1; k < 32; k++) {
-        z[64+2*k  ] = -z[64 - k];
-        z[64+2*k+1] =  z[ k + 1];
+    zi[64] = zi[0];
+    zi[65] = zi[1];
+    for (k = 1; k < 31; k+=2) {
+        zi[64+2*k+0] = zi[64 - k] ^ (1U<<31);
+        zi[64+2*k+1] = zi[ k + 1];
+        zi[64+2*k+2] = zi[63 - k] ^ (1U<<31);
+        zi[64+2*k+3] = zi[ k + 2];
     }
+    zi[64+2*31+0] = zi[64 - 31] ^ (1U<<31);
+    zi[64+2*31+1] = zi[31 + 1];
 }
 
 static void sbr_qmf_post_shuffle_c(float W[32][2], const float *z)
 {
+    const uint32_t *zi = (const uint32_t*)z;
+    uint32_t *Wi = (uint32_t*)W;
     int k;
-    for (k = 0; k < 32; k++) {
-        W[k][0] = -z[63-k];
-        W[k][1] = z[k];
+    for (k = 0; k < 32; k+=2) {
+        Wi[2*k+0] = zi[63-k] ^ (1U<<31);
+        Wi[2*k+1] = zi[k+0];
+        Wi[2*k+2] = zi[62-k] ^ (1U<<31);
+        Wi[2*k+3] = zi[k+1];
     }
 }
 
-- 
1.8.0.msysgit.0



More information about the ffmpeg-devel mailing list