6 #include "common/common.h"
8 #include "common/i386/pixel.h"
9 #include "common/i386/dct.h"
10 #include "common/i386/mc.h"
13 #include "common/ppc/pixel.h"
16 /* buf1, buf2: initialised to randome data and shouldn't write into them */
17 uint8_t * buf1, * buf2;
18 /* buf3, buf4: used to store output */
19 uint8_t * buf3, * buf4;
21 static int check_pixel()
23 x264_pixel_function_t pixel_c = {{0},{0},{0}};
24 x264_pixel_function_t pixel_asm = {{0}, {0},{0}};
28 memset( &pixel_asm, 0, sizeof( x264_pixel_function_t ) );
29 x264_pixel_init( 0, &pixel_c );
31 x264_pixel_init( X264_CPU_MMX|X264_CPU_MMXEXT, &pixel_asm );
34 x264_pixel_altivec_init( &pixel_asm );
37 for( i = 0, ok = 1; i < 7; i++ )
40 if( pixel_asm.sad[i] )
42 res_c = pixel_c.sad[i]( buf1, 32, buf2, 32 );
43 res_asm = pixel_asm.sad[i]( buf1, 32, buf2, 32 );
44 if( res_c != res_asm )
47 fprintf( stderr, "sad[%d]: %d != %d [FAILED]\n", i, res_c, res_asm );
52 fprintf( stderr, " - pixel sad : [OK]\n" );
55 fprintf( stderr, " - pixel sat : [FAILED]\n" );
58 for( i = 0, ok = 1; i < 7; i++ )
61 if( pixel_asm.satd[i] )
63 res_c = pixel_c.satd[i]( buf1, 32, buf2, 32 );
64 res_asm = pixel_asm.satd[i]( buf1, 32, buf2, 32 );
65 if( res_c != res_asm )
68 fprintf( stderr, "satd[%d]: %d != %d [FAILED]\n", i, res_c, res_asm );
74 fprintf( stderr, " - pixel satd : [OK]\n" );
77 fprintf( stderr, " - pixel satd : [FAILED]\n" );
80 for( i = 0, ok = 1; i < 7; i++ )
82 if( pixel_asm.avg[i] )
84 memcpy( buf3, buf1, 32*32 );
85 memcpy( buf4, buf1, 32*32 );
86 pixel_c.satd[i]( buf3, 32, buf2, 32 );
87 pixel_asm.satd[i]( buf4, 32, buf2, 32 );
88 if( memcmp( buf3, buf4, 32*32 ) )
91 fprintf( stderr, "avg[%d]: [FAILED]\n", i );
97 fprintf( stderr, " - pixel avg : [OK]\n" );
100 fprintf( stderr, " - pixel avg : [FAILED]\n" );
106 static int check_dct()
108 x264_dct_function_t dct_c;
109 x264_dct_function_t dct_asm;
111 int16_t dct1[16][4][4] __attribute((aligned(16)));
112 int16_t dct2[16][4][4] __attribute((aligned(16)));
114 memset( &dct_asm, 0, sizeof( dct_asm ) );
115 x264_dct_init( 0, &dct_c );
117 x264_dct_init( X264_CPU_MMX|X264_CPU_MMXEXT, &dct_asm );
119 #define TEST_DCT( name, t1, t2, size ) \
122 dct_c.name( t1, buf1, 32, buf2, 32 ); \
123 dct_asm.name( t2, buf1, 32, buf2, 32 ); \
124 if( memcmp( t1, t2, size ) ) \
127 fprintf( stderr, #name " [FAILED]\n" ); \
131 TEST_DCT( sub4x4_dct, dct1[0], dct2[0], 16*2 );
132 TEST_DCT( sub8x8_dct, dct1, dct2, 16*2*4 );
133 TEST_DCT( sub16x16_dct, dct1, dct2, 16*2*16 );
135 fprintf( stderr, " - sub_dctXxX : [OK]\n" );
138 fprintf( stderr, " - sub_dctXxX : [FAILED]\n" );
142 #define TEST_IDCT( name, t ) \
145 memcpy( buf3, buf1, 32*32 ); \
146 memcpy( buf4, buf1, 32*32 ); \
147 dct_c.name( buf3, 32, t ); \
148 dct_asm.name( buf4, 32, t ); \
149 if( memcmp( buf3, buf4, 32*32 ) ) \
152 fprintf( stderr, #name " [FAILED]\n" ); \
156 TEST_IDCT( add4x4_idct, dct1[0] );
157 TEST_IDCT( add8x8_idct, dct1 );
158 TEST_IDCT( add16x16_idct, dct1 );
160 fprintf( stderr, " - add_idctXxX : [OK]\n" );
163 fprintf( stderr, " - add_idctXxX : [FAILED]\n" );
168 if( dct_asm.dct4x4dc )
170 int16_t dct1[4][4] __attribute((aligned(16))) = { {-12, 42, 23, 67},{2, 90, 89,56}, {67,43,-76,91},{56,-78,-54,1}};
171 int16_t dct2[4][4] __attribute((aligned(16))) = { {-12, 42, 23, 67},{2, 90, 89,56}, {67,43,-76,91},{56,-78,-54,1}};
173 dct_c.dct4x4dc( dct1 );
174 dct_asm.dct4x4dc( dct2 );
175 if( memcmp( dct1, dct2, 32 ) )
178 fprintf( stderr, " - dct4x4dc : [FAILED]\n" );
181 if( dct_asm.idct4x4dc )
183 int16_t dct1[4][4] __attribute((aligned(16))) = { {-12, 42, 23, 67},{2, 90, 89,56}, {67,43,-76,91},{56,-78,-54,1}};
184 int16_t dct2[4][4] __attribute((aligned(16))) = { {-12, 42, 23, 67},{2, 90, 89,56}, {67,43,-76,91},{56,-78,-54,1}};
186 dct_c.idct4x4dc( dct1 );
187 dct_asm.idct4x4dc( dct2 );
188 if( memcmp( dct1, dct2, 32 ) )
191 fprintf( stderr, " - idct4x4dc : [FAILED]\n" );
195 fprintf( stderr, " - (i)dct4x4dc : [OK]\n" );
198 fprintf( stderr, " - (i)dct4x4dc : [FAILED]\n" );
202 if( dct_asm.dct2x2dc )
204 int16_t dct1[2][2] __attribute((aligned(16))) = { {-12, 42},{2, 90}};
205 int16_t dct2[2][2] __attribute((aligned(16))) = { {-12, 42},{2, 90}};
207 dct_c.dct2x2dc( dct1 );
208 dct_asm.dct2x2dc( dct2 );
209 if( memcmp( dct1, dct2, 4*2 ) )
212 fprintf( stderr, " - dct2x2dc : [FAILED]\n" );
215 if( dct_asm.idct2x2dc )
217 int16_t dct1[2][2] __attribute((aligned(16))) = { {-12, 42},{2, 90}};
218 int16_t dct2[2][2] __attribute((aligned(16))) = { {-12, 42},{2, 90}};
220 dct_c.idct2x2dc( dct1 );
221 dct_asm.idct2x2dc( dct2 );
222 if( memcmp( dct1, dct2, 4*2 ) )
225 fprintf( stderr, " - idct2x2dc : [FAILED]\n" );
230 fprintf( stderr, " - (i)dct2x2dc : [OK]\n" );
233 fprintf( stderr, " - (i)dct2x2dc : [FAILED]\n" );
240 static int check_mc()
243 x264_mc_function_t mc_c[2] = {0};
244 x264_mc_function_t mc_asm[2] = {0};
245 uint8_t *src = &buf1[2*32+2];
246 uint8_t *dst1 = &buf3[2*32+2];
247 uint8_t *dst2 = &buf4[2*32+2];
249 int ret = 0, ok[2] = { 1, 1 };
251 x264_mc_init( 0, mc_c );
253 x264_mc_mmxext_init( mc_asm );
257 #define MC_TEST( t, w, h ) \
260 memset(dst1, 0xCD, (h) * 16); \
261 mc_c[t]( src, 32, dst1, 16, dx, dy, w, h ); \
262 memset(dst2, 0xCD, (h) * 16); \
263 mc_asm[t]( src, 32, dst2, 16, dx, dy, w, h ); \
264 if( memcmp( dst1, dst2, 16*16 ) ) \
266 fprintf( stderr, "mc["#t"][mv(%d,%d) %2dx%-2d] [FAILED]\n", dx, dy, w, h ); \
271 for( dy = 0; dy < 4; dy++ )
273 for( dx = 0; dx < 4; dx++ )
275 MC_TEST( 0, 16, 16 );
294 fprintf( stderr, " - mc luma : [OK]\n" );
297 fprintf( stderr, " - mc luma : [FAILED]\n" );
300 fprintf( stderr, " - mc chroma : [OK]\n" );
303 fprintf( stderr, " - mc chroma : [FAILED]\n" );
317 fprintf( stderr, "x264: MMXEXT against C\n" );
319 fprintf( stderr, "x264: ALTIVEC against C\n" );
322 buf1 = x264_malloc( 1024 ); /* 32 x 32 */
323 buf2 = x264_malloc( 1024 );
324 buf3 = x264_malloc( 1024 );
325 buf4 = x264_malloc( 1024 );
327 srand( x264_mdate() );
329 for( i = 0; i < 1024; i++ )
331 buf1[i] = rand() % 0xFF;
332 buf2[i] = rand() % 0xFF;
333 buf3[i] = buf4[i] = 0;
336 ret = check_pixel() +
342 fprintf( stderr, "x264: All tests passed Yeah :)\n" );
345 fprintf( stderr, "x264: at least one test has failed. Go and fix that Right Now!\n" );