[FFmpeg-devel] [RFC PATCH] Remove duplicate ATTR_ALIGN macro, use DECLARE_ASM_CONST.

Diego 'Flameeyes' Pettenò flameeyes
Mon Oct 6 17:50:34 CEST 2008


Some CPU-specific assembler optimistions currently duplicate the
alignment macros by creating a ATTR_ALIGN macro that is used to
declare variables as aligned.

While some of the code using this has already been deprecated, there
is still in-use code doing that. This patch is trying to solve the
issue by using DECLARE_ASM_CONST for constant aligned tables.

This is more than a request for comment than anything else since the
DECLARE_ASM_CONST usage might not be the best suited one.
---

 libavcodec/i386/fdct_mmx.c     |   32 ++++++++++++++------------------
 libavcodec/i386/fft_sse.c      |    2 +-
 libavcodec/i386/h264dsp_mmx.c  |    2 +-
 libavcodec/i386/idct_mmx.c     |   35 +++++++++++++++++------------------
 libavcodec/ps2/idct_mmi.c      |    2 +-
 libavcodec/ps2/mmi.h           |    2 --
 libavcodec/sh4/idct_sh4.c      |    4 ++--
 libavcodec/sparc/dsputil_vis.c |   20 +++++++++-----------
 8 files changed, 45 insertions(+), 54 deletions(-)

diff --git a/libavcodec/i386/fdct_mmx.c b/libavcodec/i386/fdct_mmx.c
index 9e017a6..49c8f9b 100644
--- a/libavcodec/i386/fdct_mmx.c
+++ b/libavcodec/i386/fdct_mmx.c
@@ -34,8 +34,6 @@
 #include "libavcodec/dsputil.h"
 #include "mmx.h"
 
-#define ATTR_ALIGN(align) __attribute__ ((__aligned__ (align)))
-
 //////////////////////////////////////////////////////////////////////
 //
 // constants for the forward DCT
@@ -56,30 +54,29 @@
 #define X8(x) x,x,x,x,x,x,x,x
 
 //concatenated table, for forward DCT transformation
-static const int16_t fdct_tg_all_16[24] ATTR_ALIGN(16) = {
+DECLARE_ASM_CONST(16, int16_t, fdct_tg_all_16[24]) = {
     X8(13036),  // tg * (2<<16) + 0.5
     X8(27146),  // tg * (2<<16) + 0.5
     X8(-21746)  // tg * (2<<16) + 0.5
 };
 
-static const int16_t ocos_4_16[8] ATTR_ALIGN(16) = {
+DECLARE_ASM_CONST(16, int16_t, ocos_4_16[8]) = {
     X8(23170)   //cos * (2<<15) + 0.5
 };
 
-static const int16_t fdct_one_corr[8] ATTR_ALIGN(16) = { X8(1) };
+DECLARE_ASM_CONST(16, int16_t, fdct_one_corr[8]) = { X8(1) };
 
-static const int32_t fdct_r_row[2] ATTR_ALIGN(8) = {RND_FRW_ROW, RND_FRW_ROW };
+DECLARE_ASM_CONST(8, int32_t, fdct_r_row[2]) = {RND_FRW_ROW, RND_FRW_ROW };
 
-static struct
-{
- const int32_t fdct_r_row_sse2[4] ATTR_ALIGN(16);
-} fdct_r_row_sse2 ATTR_ALIGN(16)=
+DECLARE_ASM_CONST(16, struct {
+  int32_t fdct_r_row_sse2[4];
+}, fdct_r_row_sse2) = 
 {{
  RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW
 }};
 //static const long fdct_r_row_sse2[4] ATTR_ALIGN(16) = {RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW};
 
-static const int16_t tab_frw_01234567[] ATTR_ALIGN(8) = {  // forward_dct coeff table
+DECLARE_ASM_CONST(8, int16_t, tab_frw_01234567[]) = { // forward_dct coeff table
   16384,   16384,   22725,   19266,
   16384,   16384,   12873,    4520,
   21407,    8867,   19266,   -4520,
@@ -153,10 +150,9 @@ static const int16_t tab_frw_01234567[] ATTR_ALIGN(8) = {  // forward_dct coeff
   29692,  -12299,   26722,  -31521,
 };
 
-static struct
-{
- const int16_t tab_frw_01234567_sse2[256] ATTR_ALIGN(16);
-} tab_frw_01234567_sse2 ATTR_ALIGN(16) =
+DECLARE_ASM_CONST(16, struct {
+  int16_t tab_frw_01234567_sse2[256];
+}, tab_frw_01234567_sse2) = 
 {{
 //static const int16_t tab_frw_01234567_sse2[] ATTR_ALIGN(16) = {  // forward_dct coeff table
 #define TABLE_SSE2 C4,  C4,  C1,  C3, -C6, -C2, -C1, -C5, \
@@ -524,7 +520,7 @@ static av_always_inline void fdct_row_mmx(const int16_t *in, int16_t *out, const
 
 void ff_fdct_mmx(int16_t *block)
 {
-    int64_t align_tmp[16] ATTR_ALIGN(8);
+    DECLARE_ALIGNED(8, int64_t, align_tmp[16]);
     int16_t * block1= (int16_t*)align_tmp;
     const int16_t *table= tab_frw_01234567;
     int i;
@@ -542,7 +538,7 @@ void ff_fdct_mmx(int16_t *block)
 
 void ff_fdct_mmx2(int16_t *block)
 {
-    int64_t align_tmp[16] ATTR_ALIGN(8);
+    DECLARE_ALIGNED(8, int64_t, align_tmp[16]);
     int16_t *block1= (int16_t*)align_tmp;
     const int16_t *table= tab_frw_01234567;
     int i;
@@ -560,7 +556,7 @@ void ff_fdct_mmx2(int16_t *block)
 
 void ff_fdct_sse2(int16_t *block)
 {
-    int64_t align_tmp[16] ATTR_ALIGN(16);
+    DECLARE_ALIGNED(8, int64_t, align_tmp[16]);
     int16_t * const block1= (int16_t*)align_tmp;
 
     fdct_col_sse2(block, block1, 0);
diff --git a/libavcodec/i386/fft_sse.c b/libavcodec/i386/fft_sse.c
index 9246770..5f9c4de 100644
--- a/libavcodec/i386/fft_sse.c
+++ b/libavcodec/i386/fft_sse.c
@@ -22,7 +22,7 @@
 #include "libavutil/x86_cpu.h"
 #include "libavcodec/dsputil.h"
 
-static const int m1m1m1m1[4] __attribute__((aligned(16))) =
+DECLARE_ASM_CONST(16, int, m1m1m1m1[4]) =
     { 1 << 31, 1 << 31, 1 << 31, 1 << 31 };
 
 void ff_fft_dispatch_sse(FFTComplex *z, int nbits);
diff --git a/libavcodec/i386/h264dsp_mmx.c b/libavcodec/i386/h264dsp_mmx.c
index f94f708..717193a 100644
--- a/libavcodec/i386/h264dsp_mmx.c
+++ b/libavcodec/i386/h264dsp_mmx.c
@@ -157,7 +157,7 @@ static inline void h264_idct8_1d(int16_t *block)
 static void ff_h264_idct8_add_mmx(uint8_t *dst, int16_t *block, int stride)
 {
     int i;
-    int16_t __attribute__ ((aligned(8))) b2[64];
+    DECLARE_ALIGNED(8, int16_t, b2[64]);
 
     block[0] += 32;
 
diff --git a/libavcodec/i386/idct_mmx.c b/libavcodec/i386/idct_mmx.c
index d860c7e..24411ea 100644
--- a/libavcodec/i386/idct_mmx.c
+++ b/libavcodec/i386/idct_mmx.c
@@ -24,8 +24,6 @@
 
 #include "mmx.h"
 
-#define ATTR_ALIGN(align) __attribute__ ((__aligned__ (align)))
-
 #define ROW_SHIFT 11
 #define COL_SHIFT 6
 
@@ -392,10 +390,10 @@ static inline void idct_col (int16_t * col, int offset)
 #define T3 43790
 #define C4 23170
 
-    static const short t1_vector[] ATTR_ALIGN(8) = {T1,T1,T1,T1};
-    static const short t2_vector[] ATTR_ALIGN(8) = {T2,T2,T2,T2};
-    static const short t3_vector[] ATTR_ALIGN(8) = {T3,T3,T3,T3};
-    static const short c4_vector[] ATTR_ALIGN(8) = {C4,C4,C4,C4};
+    DECLARE_ASM_CONST(8, short, t1_vector[]) = {T1,T1,T1,T1};
+    DECLARE_ASM_CONST(8, short, t2_vector[]) = {T2,T2,T2,T2};
+    DECLARE_ASM_CONST(8, short, t3_vector[]) = {T3,T3,T3,T3};
+    DECLARE_ASM_CONST(8, short, c4_vector[]) = {C4,C4,C4,C4};
 
     /* column code adapted from Peter Gubanov */
     /* http://www.elecard.com/peter/idct.shtml */
@@ -533,20 +531,21 @@ static inline void idct_col (int16_t * col, int offset)
 #undef C4
 }
 
-static const int32_t rounder0[] ATTR_ALIGN(8) =
+DECLARE_ASM_CONST(8, int32_t, rounder0[]) = 
     rounder ((1 << (COL_SHIFT - 1)) - 0.5);
-static const int32_t rounder4[] ATTR_ALIGN(8) = rounder (0);
-static const int32_t rounder1[] ATTR_ALIGN(8) =
+DECLARE_ASM_CONST(8, int32_t, rounder4[]) = 
+    rounder (0);
+DECLARE_ASM_CONST(8, int32_t, rounder1[]) = 
     rounder (1.25683487303);        /* C1*(C1/C4+C1+C7)/2 */
-static const int32_t rounder7[] ATTR_ALIGN(8) =
+DECLARE_ASM_CONST(8, int32_t, rounder7[]) =
     rounder (-0.25);                /* C1*(C7/C4+C7-C1)/2 */
-static const int32_t rounder2[] ATTR_ALIGN(8) =
+DECLARE_ASM_CONST(8, int32_t, rounder2[]) =
     rounder (0.60355339059);        /* C2 * (C6+C2)/2 */
-static const int32_t rounder6[] ATTR_ALIGN(8) =
+DECLARE_ASM_CONST(8, int32_t, rounder6[]) =
     rounder (-0.25);                /* C2 * (C6-C2)/2 */
-static const int32_t rounder3[] ATTR_ALIGN(8) =
+DECLARE_ASM_CONST(8, int32_t, rounder3[]) =
     rounder (0.087788325588);       /* C3*(-C3/C4+C3+C5)/2 */
-static const int32_t rounder5[] ATTR_ALIGN(8) =
+DECLARE_ASM_CONST(8, int32_t, rounder5[]) =
     rounder (-0.441341716183);      /* C3*(-C5/C4+C5-C3)/2 */
 
 #undef COL_SHIFT
@@ -555,13 +554,13 @@ static const int32_t rounder5[] ATTR_ALIGN(8) =
 #define declare_idct(idct,table,idct_row_head,idct_row,idct_row_tail,idct_row_mid) \
 void idct (int16_t * block)                                             \
 {                                                                       \
-    static const int16_t table04[] ATTR_ALIGN(16) =                     \
+    DECLARE_ASM_CONST(16, int16_t, table04[]) =                     \
         table (22725, 21407, 19266, 16384, 12873,  8867, 4520);         \
-    static const int16_t table17[] ATTR_ALIGN(16) =                     \
+    DECLARE_ASM_CONST(16, int16_t, table17[]) =                     \
         table (31521, 29692, 26722, 22725, 17855, 12299, 6270);         \
-    static const int16_t table26[] ATTR_ALIGN(16) =                     \
+    DECLARE_ASM_CONST(16, int16_t, table26[]) =                     \
         table (29692, 27969, 25172, 21407, 16819, 11585, 5906);         \
-    static const int16_t table35[] ATTR_ALIGN(16) =                     \
+    DECLARE_ASM_CONST(16, int16_t, table35[]) =                     \
         table (26722, 25172, 22654, 19266, 15137, 10426, 5315);         \
                                                                         \
     idct_row_head (block, 0*8, table04);                                \
diff --git a/libavcodec/ps2/idct_mmi.c b/libavcodec/ps2/idct_mmi.c
index 8fac74f..61b7138 100644
--- a/libavcodec/ps2/idct_mmi.c
+++ b/libavcodec/ps2/idct_mmi.c
@@ -53,7 +53,7 @@
 
 #define CLIPMAX         (32+256+64+0)
 
-static short consttable[] align16 = {
+DECLARE_ASM_CONST(16, short, consttable[]) = {
 /* rounder 0*/  // assume SHIFT_INV_ROW == 11
  0x3ff, 1, 0x3ff, 1, 0x3ff, 1, 0x3ff, 1,
 /* rounder 1*/
diff --git a/libavcodec/ps2/mmi.h b/libavcodec/ps2/mmi.h
index 81905e0..2037e5c 100644
--- a/libavcodec/ps2/mmi.h
+++ b/libavcodec/ps2/mmi.h
@@ -21,8 +21,6 @@
 #ifndef AVCODEC_PS2_MMI_H
 #define AVCODEC_PS2_MMI_H
 
-#define align16 __attribute__ ((aligned (16)))
-
 /*
 #define r0 $zero
 #define r1 $at          //assembler!
diff --git a/libavcodec/sh4/idct_sh4.c b/libavcodec/sh4/idct_sh4.c
index b31943f..abb680b 100644
--- a/libavcodec/sh4/idct_sh4.c
+++ b/libavcodec/sh4/idct_sh4.c
@@ -29,14 +29,14 @@
 #define c6      0.54119610014619712324  /* sqrt(2)*cos(6*pi/16) */
 #define c7      0.27589937928294311353  /* sqrt(2)*cos(7*pi/16) */
 
-static const float even_table[] __attribute__ ((aligned(8))) = {
+DECLARE_ASM_CONST(8, float, even_table[]) = {
         c4, c4, c4, c4,
         c2, c6,-c6,-c2,
         c4,-c4,-c4, c4,
         c6,-c2, c2,-c6
 };
 
-static const float odd_table[] __attribute__ ((aligned(8))) = {
+DECLARE_ASM_CONST(8, float, odd_table[]) = {
         c1, c3, c5, c7,
         c3,-c7,-c1,-c5,
         c5,-c1, c7, c3,
diff --git a/libavcodec/sparc/dsputil_vis.c b/libavcodec/sparc/dsputil_vis.c
index a01eea3..50a95bc 100644
--- a/libavcodec/sparc/dsputil_vis.c
+++ b/libavcodec/sparc/dsputil_vis.c
@@ -55,20 +55,18 @@ extern void ff_simple_idct_vis(DCTELEM *data);
  *      fpsub16         f12, f10, f10
  */
 
-#define ATTR_ALIGN(alignd) __attribute__ ((aligned(alignd)))
-
 #define DUP4(x) {x, x, x, x}
 #define DUP8(x) {x, x, x, x, x, x, x, x}
-static const int16_t constants1[] ATTR_ALIGN(8) = DUP4 (1);
-static const int16_t constants2[] ATTR_ALIGN(8) = DUP4 (2);
-static const int16_t constants3[] ATTR_ALIGN(8) = DUP4 (3);
-static const int16_t constants6[] ATTR_ALIGN(8) = DUP4 (6);
-static const int8_t constants_fe[] ATTR_ALIGN(8) = DUP8 (0xfe);
-static const int8_t constants_7f[] ATTR_ALIGN(8) = DUP8 (0x7f);
-static const int8_t constants128[] ATTR_ALIGN(8) = DUP8 (128);
-static const int16_t constants256_512[] ATTR_ALIGN(8) =
+DECLARE_ASM_CONST(8, int16_t, constants1[]) = DUP4(1);
+DECLARE_ASM_CONST(8, int16_t, constants2[]) = DUP4(2);
+DECLARE_ASM_CONST(8, int16_t, constants3[]) = DUP4(3);
+DECLARE_ASM_CONST(8, int16_t, constants6[]) = DUP4(6);
+DECLARE_ASM_CONST(8, int8_t, constants_fe[]) = DUP8(0xfe);
+DECLARE_ASM_CONST(8, int8_t, constants_7f[]) = DUP8(0x7f);
+DECLARE_ASM_CONST(8, int8_t, constants_128[]) = DUP8(128);
+DECLARE_ASM_CONST(8, int16_t, constants256_512[]) =
         {256, 512, 256, 512};
-static const int16_t constants256_1024[] ATTR_ALIGN(8) =
+DECLARE_ASM_CONST(8, int16_t, constants256_1024[]) =
         {256, 1024, 256, 1024};
 
 #define REF_0           0





More information about the ffmpeg-devel mailing list