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"
14 #include "common/ppc/mc.h"
17 /* buf1, buf2: initialised to randome data and shouldn't write into them */
18 uint8_t * buf1, * buf2;
19 /* buf3, buf4: used to store output */
20 uint8_t * buf3, * buf4;
22 static int check_pixel()
24 x264_pixel_function_t pixel_c = {{0},{0},{0}};
25 x264_pixel_function_t pixel_asm = {{0}, {0},{0}};
29 memset( &pixel_asm, 0, sizeof( x264_pixel_function_t ) );
30 x264_pixel_init( 0, &pixel_c );
32 x264_pixel_init( X264_CPU_MMX|X264_CPU_MMXEXT, &pixel_asm );
35 x264_pixel_altivec_init( &pixel_asm );
38 for( i = 0, ok = 1; i < 7; i++ )
41 if( pixel_asm.sad[i] )
43 res_c = pixel_c.sad[i]( buf1, 32, buf2, 32 );
44 res_asm = pixel_asm.sad[i]( buf1, 32, buf2, 32 );
45 if( res_c != res_asm )
48 fprintf( stderr, "sad[%d]: %d != %d [FAILED]\n", i, res_c, res_asm );
53 fprintf( stderr, " - pixel sad : [OK]\n" );
56 fprintf( stderr, " - pixel sat : [FAILED]\n" );
59 for( i = 0, ok = 1; i < 7; i++ )
62 if( pixel_asm.satd[i] )
64 res_c = pixel_c.satd[i]( buf1, 32, buf2, 32 );
65 res_asm = pixel_asm.satd[i]( buf1, 32, buf2, 32 );
66 if( res_c != res_asm )
69 fprintf( stderr, "satd[%d]: %d != %d [FAILED]\n", i, res_c, res_asm );
75 fprintf( stderr, " - pixel satd : [OK]\n" );
78 fprintf( stderr, " - pixel satd : [FAILED]\n" );
81 for( i = 0, ok = 1; i < 7; i++ )
83 if( pixel_asm.avg[i] )
85 memcpy( buf3, buf1, 32*32 );
86 memcpy( buf4, buf1, 32*32 );
87 pixel_c.satd[i]( buf3, 32, buf2, 32 );
88 pixel_asm.satd[i]( buf4, 32, buf2, 32 );
89 if( memcmp( buf3, buf4, 32*32 ) )
92 fprintf( stderr, "avg[%d]: [FAILED]\n", i );
98 fprintf( stderr, " - pixel avg : [OK]\n" );
101 fprintf( stderr, " - pixel avg : [FAILED]\n" );
107 static int check_dct()
109 x264_dct_function_t dct_c;
110 x264_dct_function_t dct_asm;
112 int16_t dct1[16][4][4] __attribute((aligned(16)));
113 int16_t dct2[16][4][4] __attribute((aligned(16)));
115 memset( &dct_asm, 0, sizeof( dct_asm ) );
116 x264_dct_init( 0, &dct_c );
118 x264_dct_init( X264_CPU_MMX|X264_CPU_MMXEXT, &dct_asm );
120 #define TEST_DCT( name, t1, t2, size ) \
123 dct_c.name( t1, buf1, 32, buf2, 32 ); \
124 dct_asm.name( t2, buf1, 32, buf2, 32 ); \
125 if( memcmp( t1, t2, size ) ) \
128 fprintf( stderr, #name " [FAILED]\n" ); \
132 TEST_DCT( sub4x4_dct, dct1[0], dct2[0], 16*2 );
133 TEST_DCT( sub8x8_dct, dct1, dct2, 16*2*4 );
134 TEST_DCT( sub16x16_dct, dct1, dct2, 16*2*16 );
136 fprintf( stderr, " - sub_dctXxX : [OK]\n" );
139 fprintf( stderr, " - sub_dctXxX : [FAILED]\n" );
143 #define TEST_IDCT( name, t ) \
146 memcpy( buf3, buf1, 32*32 ); \
147 memcpy( buf4, buf1, 32*32 ); \
148 dct_c.name( buf3, 32, t ); \
149 dct_asm.name( buf4, 32, t ); \
150 if( memcmp( buf3, buf4, 32*32 ) ) \
153 fprintf( stderr, #name " [FAILED]\n" ); \
157 TEST_IDCT( add4x4_idct, dct1[0] );
158 TEST_IDCT( add8x8_idct, dct1 );
159 TEST_IDCT( add16x16_idct, dct1 );
161 fprintf( stderr, " - add_idctXxX : [OK]\n" );
164 fprintf( stderr, " - add_idctXxX : [FAILED]\n" );
169 if( dct_asm.dct4x4dc )
171 int16_t dct1[4][4] __attribute((aligned(16))) = { {-12, 42, 23, 67},{2, 90, 89,56}, {67,43,-76,91},{56,-78,-54,1}};
172 int16_t dct2[4][4] __attribute((aligned(16))) = { {-12, 42, 23, 67},{2, 90, 89,56}, {67,43,-76,91},{56,-78,-54,1}};
174 dct_c.dct4x4dc( dct1 );
175 dct_asm.dct4x4dc( dct2 );
176 if( memcmp( dct1, dct2, 32 ) )
179 fprintf( stderr, " - dct4x4dc : [FAILED]\n" );
182 if( dct_asm.idct4x4dc )
184 int16_t dct1[4][4] __attribute((aligned(16))) = { {-12, 42, 23, 67},{2, 90, 89,56}, {67,43,-76,91},{56,-78,-54,1}};
185 int16_t dct2[4][4] __attribute((aligned(16))) = { {-12, 42, 23, 67},{2, 90, 89,56}, {67,43,-76,91},{56,-78,-54,1}};
187 dct_c.idct4x4dc( dct1 );
188 dct_asm.idct4x4dc( dct2 );
189 if( memcmp( dct1, dct2, 32 ) )
192 fprintf( stderr, " - idct4x4dc : [FAILED]\n" );
196 fprintf( stderr, " - (i)dct4x4dc : [OK]\n" );
199 fprintf( stderr, " - (i)dct4x4dc : [FAILED]\n" );
203 if( dct_asm.dct2x2dc )
205 int16_t dct1[2][2] __attribute((aligned(16))) = { {-12, 42},{2, 90}};
206 int16_t dct2[2][2] __attribute((aligned(16))) = { {-12, 42},{2, 90}};
208 dct_c.dct2x2dc( dct1 );
209 dct_asm.dct2x2dc( dct2 );
210 if( memcmp( dct1, dct2, 4*2 ) )
213 fprintf( stderr, " - dct2x2dc : [FAILED]\n" );
216 if( dct_asm.idct2x2dc )
218 int16_t dct1[2][2] __attribute((aligned(16))) = { {-12, 42},{2, 90}};
219 int16_t dct2[2][2] __attribute((aligned(16))) = { {-12, 42},{2, 90}};
221 dct_c.idct2x2dc( dct1 );
222 dct_asm.idct2x2dc( dct2 );
223 if( memcmp( dct1, dct2, 4*2 ) )
226 fprintf( stderr, " - idct2x2dc : [FAILED]\n" );
231 fprintf( stderr, " - (i)dct2x2dc : [OK]\n" );
234 fprintf( stderr, " - (i)dct2x2dc : [FAILED]\n" );
241 static int check_mc()
243 x264_mc_functions_t mc_c = {0,0,0};
244 x264_mc_functions_t mc_a = {0,0,0};
246 uint8_t *src = &buf1[2*32+2];
247 uint8_t *src2[4] = { &buf1[2*32+2], &buf1[7*32+2],
248 &buf1[12*32+2], &buf1[17*32+2] };
249 uint8_t *dst1 = &buf3[2*32+2];
250 uint8_t *dst2 = &buf4[2*32+2];
253 int ret = 0, ok[2] = { 1, 1 };
255 x264_mc_init( 0, &mc_c );
257 x264_mc_mmxext_init( &mc_a );
260 x264_mc_altivec_init( &mc_a );
263 #define MC_TEST_LUMA( w, h ) \
266 memset(buf3, 0xCD, 1024); \
267 memset(buf4, 0xCD, 1024); \
268 mc_c.mc_luma( src2, 32, dst1, 16, dx, dy, w, h ); \
269 mc_a.mc_luma( src2, 32, dst2, 16, dx, dy, w, h ); \
270 if( memcmp( buf3, buf4, 1024 ) ) \
272 fprintf( stderr, "mc_luma[mv(%d,%d) %2dx%-2d] [FAILED]\n", dx, dy, w, h ); \
277 #define MC_TEST_CHROMA( w, h ) \
278 if( mc_a.mc_chroma ) \
280 memset(buf3, 0xCD, 1024); \
281 memset(buf4, 0xCD, 1024); \
282 mc_c.mc_chroma( src, 32, dst1, 16, dx, dy, w, h ); \
283 mc_a.mc_chroma( src, 32, dst2, 16, dx, dy, w, h ); \
284 if( memcmp( buf3, buf4, 1024 ) ) \
286 fprintf( stderr, "mc_chroma[mv(%d,%d) %2dx%-2d] [FAILED]\n", dx, dy, w, h ); \
291 for( dy = 0; dy < 4; dy++ )
293 for( dx = 0; dx < 4; dx++ )
295 MC_TEST_LUMA( 16, 16 );
296 MC_TEST_LUMA( 16, 8 );
297 MC_TEST_LUMA( 8, 16 );
298 MC_TEST_LUMA( 8, 8 );
299 MC_TEST_LUMA( 8, 4 );
300 MC_TEST_LUMA( 4, 8 );
301 MC_TEST_LUMA( 4, 4 );
303 MC_TEST_CHROMA( 8, 8 );
304 MC_TEST_CHROMA( 8, 4 );
305 MC_TEST_CHROMA( 4, 8 );
306 MC_TEST_CHROMA( 4, 4 );
307 MC_TEST_CHROMA( 4, 2 );
308 MC_TEST_CHROMA( 2, 4 );
309 MC_TEST_CHROMA( 2, 2 );
313 #undef MC_TEST_CHROMA
315 fprintf( stderr, " - mc luma : [OK]\n" );
318 fprintf( stderr, " - mc luma : [FAILED]\n" );
321 fprintf( stderr, " - mc chroma : [OK]\n" );
324 fprintf( stderr, " - mc chroma : [FAILED]\n" );
335 fprintf( stderr, "x264: MMXEXT against C\n" );
337 fprintf( stderr, "x264: ALTIVEC against C\n" );
340 buf1 = x264_malloc( 1024 ); /* 32 x 32 */
341 buf2 = x264_malloc( 1024 );
342 buf3 = x264_malloc( 1024 );
343 buf4 = x264_malloc( 1024 );
345 srand( x264_mdate() );
347 for( i = 0; i < 1024; i++ )
349 buf1[i] = rand() % 0xFF;
350 buf2[i] = rand() % 0xFF;
351 buf3[i] = buf4[i] = 0;
354 ret = check_pixel() +
360 fprintf( stderr, "x264: All tests passed Yeah :)\n" );
363 fprintf( stderr, "x264: at least one test has failed. Go and fix that Right Now!\n" );