Remove declarations after statements from vertClassify_altivec
[libav.git] / libpostproc / postprocess_altivec_template.c
index c87ada5..5f73950 100644 (file)
@@ -62,7 +62,13 @@ static inline int vertClassify_altivec(uint8_t src[], int stride, PPContext *c)
     vector by assuming (stride % 16) == 0, unfortunately
     this is not always true.
     */
-    DECLARE_ALIGNED(16, short, data[8]);
+    DECLARE_ALIGNED(16, short, data[8]) =
+                    {
+                        ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1,
+                        data[0] * 2 + 1,
+                        c->QP * 2,
+                        c->QP * 4
+                    };
     int numEq;
     uint8_t *src2 = src;
     vector signed short v_dcOffset;
@@ -75,12 +81,21 @@ static inline int vertClassify_altivec(uint8_t src[], int stride, PPContext *c)
     const vector signed int zero = vec_splat_s32(0);
     const vector signed short mask = vec_splat_s16(1);
     vector signed int v_numEq = vec_splat_s32(0);
-
-    data[0] = ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1;
-    data[1] = data[0] * 2 + 1;
-    data[2] = c->QP * 2;
-    data[3] = c->QP * 4;
     vector signed short v_data = vec_ld(0, data);
+    vector signed short v_srcAss0, v_srcAss1, v_srcAss2, v_srcAss3,
+                        v_srcAss4, v_srcAss5, v_srcAss6, v_srcAss7;
+//FIXME avoid this mess if possible
+    register int j0 = 0,
+                 j1 = stride,
+                 j2 = 2 * stride,
+                 j3 = 3 * stride,
+                 j4 = 4 * stride,
+                 j5 = 5 * stride,
+                 j6 = 6 * stride,
+                 j7 = 7 * stride;
+    vector unsigned char v_srcA0, v_srcA1, v_srcA2, v_srcA3,
+                         v_srcA4, v_srcA5, v_srcA6, v_srcA7;
+
     v_dcOffset = vec_splat(v_data, 0);
     v_dcThreshold = (vector unsigned short)vec_splat(v_data, 1);
     v2QP = vec_splat(v_data, 2);
@@ -88,24 +103,22 @@ static inline int vertClassify_altivec(uint8_t src[], int stride, PPContext *c)
 
     src2 += stride * 4;
 
-    vector signed short v_srcAss0, v_srcAss1, v_srcAss2, v_srcAss3, v_srcAss4, v_srcAss5, v_srcAss6, v_srcAss7;
 
 #define LOAD_LINE(i)                                                    \
-    register int j##i = i * stride;                                     \
+    {                                                                   \
     vector unsigned char perm##i = vec_lvsl(j##i, src2);                \
-    const vector unsigned char v_srcA1##i = vec_ld(j##i, src2);         \
     vector unsigned char v_srcA2##i;                                    \
+    vector unsigned char v_srcA1##i = vec_ld(j##i, src2);               \
     if (two_vectors)                                                    \
         v_srcA2##i = vec_ld(j##i + 16, src2);                           \
-    const vector unsigned char v_srcA##i =                              \
+    v_srcA##i =                                                         \
         vec_perm(v_srcA1##i, v_srcA2##i, perm##i);                      \
     v_srcAss##i =                                                       \
         (vector signed short)vec_mergeh((vector signed char)zero,       \
-                                        (vector signed char)v_srcA##i)
+                                        (vector signed char)v_srcA##i); }
 
 #define LOAD_LINE_ALIGNED(i)                                            \
-    register int j##i = i * stride;                                     \
-    const vector unsigned char v_srcA##i = vec_ld(j##i, src2);          \
+    v_srcA##i = vec_ld(j##i, src2);                                     \
     v_srcAss##i =                                                       \
         (vector signed short)vec_mergeh((vector signed char)zero,       \
                                         (vector signed char)v_srcA##i)
@@ -143,16 +156,26 @@ static inline int vertClassify_altivec(uint8_t src[], int stride, PPContext *c)
     const vector signed short v_comp##i =                               \
         (vector signed short)vec_cmplt((vector unsigned short)v_sum##i, \
                                        v_dcThreshold);                  \
-    const vector signed short v_part##i = vec_and(mask, v_comp##i);     \
-    v_numEq = vec_sum4s(v_part##i, v_numEq);
-
-    ITER(0, 1);
-    ITER(1, 2);
-    ITER(2, 3);
-    ITER(3, 4);
-    ITER(4, 5);
-    ITER(5, 6);
-    ITER(6, 7);
+    const vector signed short v_part##i = vec_and(mask, v_comp##i);
+
+{
+    ITER(0, 1)
+    ITER(1, 2)
+    ITER(2, 3)
+    ITER(3, 4)
+    ITER(4, 5)
+    ITER(5, 6)
+    ITER(6, 7)
+
+    v_numEq = vec_sum4s(v_part0, v_numEq);
+    v_numEq = vec_sum4s(v_part1, v_numEq);
+    v_numEq = vec_sum4s(v_part2, v_numEq);
+    v_numEq = vec_sum4s(v_part3, v_numEq);
+    v_numEq = vec_sum4s(v_part4, v_numEq);
+    v_numEq = vec_sum4s(v_part5, v_numEq);
+    v_numEq = vec_sum4s(v_part6, v_numEq);
+}
+
 #undef ITER
 
     v_numEq = vec_sums(v_numEq, zero);
@@ -800,7 +823,7 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) {
 #define do_a_deblock_altivec(a...) do_a_deblock_C(a)
 
 static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride,
-                                            uint8_t *tempBlured, uint32_t *tempBluredPast, int *maxNoise)
+                                            uint8_t *tempBlurred, uint32_t *tempBlurredPast, int *maxNoise)
 {
     const vector signed int zero = vec_splat_s32(0);
     const vector signed short vsint16_1 = vec_splat_s16(1);
@@ -808,9 +831,9 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride,
     vector signed int v_sysdp = zero;
     int d, sysd, i;
 
-    tempBluredPast[127]= maxNoise[0];
-    tempBluredPast[128]= maxNoise[1];
-    tempBluredPast[129]= maxNoise[2];
+    tempBlurredPast[127]= maxNoise[0];
+    tempBlurredPast[128]= maxNoise[1];
+    tempBlurredPast[129]= maxNoise[2];
 
 #define LOAD_LINE(src, i)                                               \
     register int j##src##i = i * stride;                                \
@@ -832,18 +855,18 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride,
     LOAD_LINE(src, 6);
     LOAD_LINE(src, 7);
 
-    LOAD_LINE(tempBlured, 0);
-    LOAD_LINE(tempBlured, 1);
-    LOAD_LINE(tempBlured, 2);
-    LOAD_LINE(tempBlured, 3);
-    LOAD_LINE(tempBlured, 4);
-    LOAD_LINE(tempBlured, 5);
-    LOAD_LINE(tempBlured, 6);
-    LOAD_LINE(tempBlured, 7);
+    LOAD_LINE(tempBlurred, 0);
+    LOAD_LINE(tempBlurred, 1);
+    LOAD_LINE(tempBlurred, 2);
+    LOAD_LINE(tempBlurred, 3);
+    LOAD_LINE(tempBlurred, 4);
+    LOAD_LINE(tempBlurred, 5);
+    LOAD_LINE(tempBlurred, 6);
+    LOAD_LINE(tempBlurred, 7);
 #undef LOAD_LINE
 
 #define ACCUMULATE_DIFFS(i)                                     \
-    vector signed short v_d##i = vec_sub(v_tempBluredAss##i,    \
+    vector signed short v_d##i = vec_sub(v_tempBlurredAss##i,    \
                                          v_srcAss##i);          \
     v_dp = vec_msums(v_d##i, v_d##i, v_dp);                     \
     v_sysdp = vec_msums(v_d##i, vsint16_1, v_sysdp)
@@ -869,16 +892,16 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride,
 
     i = d;
     d = (4*d
-         +(*(tempBluredPast-256))
-         +(*(tempBluredPast-1))+ (*(tempBluredPast+1))
-         +(*(tempBluredPast+256))
+         +(*(tempBlurredPast-256))
+         +(*(tempBlurredPast-1))+ (*(tempBlurredPast+1))
+         +(*(tempBlurredPast+256))
          +4)>>3;
 
-    *tempBluredPast=i;
+    *tempBlurredPast=i;
 
     if (d > maxNoise[1]) {
         if (d < maxNoise[2]) {
-#define OP(i) v_tempBluredAss##i = vec_avg(v_tempBluredAss##i, v_srcAss##i);
+#define OP(i) v_tempBlurredAss##i = vec_avg(v_tempBlurredAss##i, v_srcAss##i);
 
             OP(0);
             OP(1);
@@ -890,7 +913,7 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride,
             OP(7);
 #undef OP
         } else {
-#define OP(i) v_tempBluredAss##i = v_srcAss##i;
+#define OP(i) v_tempBlurredAss##i = v_srcAss##i;
 
             OP(0);
             OP(1);
@@ -910,11 +933,11 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride,
 
 #define OP(i)                                                   \
             const vector signed short v_temp##i =               \
-                vec_mladd(v_tempBluredAss##i,                   \
+                vec_mladd(v_tempBlurredAss##i,                   \
                           vsint16_7, v_srcAss##i);              \
             const vector signed short v_temp2##i =              \
                 vec_add(v_temp##i, vsint16_4);                  \
-            v_tempBluredAss##i = vec_sr(v_temp2##i, vuint16_3)
+            v_tempBlurredAss##i = vec_sr(v_temp2##i, vuint16_3)
 
             OP(0);
             OP(1);
@@ -931,11 +954,11 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride,
 
 #define OP(i)                                                   \
             const vector signed short v_temp##i =               \
-                vec_mladd(v_tempBluredAss##i,                   \
+                vec_mladd(v_tempBlurredAss##i,                   \
                           vsint16_3, v_srcAss##i);              \
             const vector signed short v_temp2##i =              \
                 vec_add(v_temp##i, vsint16_2);                  \
-            v_tempBluredAss##i = vec_sr(v_temp2##i, (vector unsigned short)vsint16_2)
+            v_tempBlurredAss##i = vec_sr(v_temp2##i, (vector unsigned short)vsint16_2)
 
             OP(0);
             OP(1);
@@ -957,7 +980,7 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride,
     const vector unsigned char perms##src##i =                  \
         vec_lvsr(i * stride, src);                              \
     const vector unsigned char vf##src##i =                     \
-        vec_packsu(v_tempBluredAss##i, (vector signed short)zero); \
+        vec_packsu(v_tempBlurredAss##i, (vector signed short)zero); \
     const vector unsigned char vg##src##i =                     \
         vec_perm(vf##src##i, v_##src##A##i, permHH);            \
     const vector unsigned char mask##src##i =                   \
@@ -979,14 +1002,14 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride,
     PACK_AND_STORE(src, 5);
     PACK_AND_STORE(src, 6);
     PACK_AND_STORE(src, 7);
-    PACK_AND_STORE(tempBlured, 0);
-    PACK_AND_STORE(tempBlured, 1);
-    PACK_AND_STORE(tempBlured, 2);
-    PACK_AND_STORE(tempBlured, 3);
-    PACK_AND_STORE(tempBlured, 4);
-    PACK_AND_STORE(tempBlured, 5);
-    PACK_AND_STORE(tempBlured, 6);
-    PACK_AND_STORE(tempBlured, 7);
+    PACK_AND_STORE(tempBlurred, 0);
+    PACK_AND_STORE(tempBlurred, 1);
+    PACK_AND_STORE(tempBlurred, 2);
+    PACK_AND_STORE(tempBlurred, 3);
+    PACK_AND_STORE(tempBlurred, 4);
+    PACK_AND_STORE(tempBlurred, 5);
+    PACK_AND_STORE(tempBlurred, 6);
+    PACK_AND_STORE(tempBlurred, 7);
 #undef PACK_AND_STORE
 }