1 /*****************************************************************************
2 * checkasm.c: assembly check tool
3 *****************************************************************************
4 * Copyright (C) 2003-2008 x264 project
6 * Authors: Loren Merritt <lorenm@u.washington.edu>
7 * Laurent Aimar <fenrir@via.ecp.fr>
8 * Fiona Glaser <fiona@x264.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
23 *****************************************************************************/
30 #include "common/common.h"
31 #include "common/cpu.h"
33 /* buf1, buf2: initialised to random data and shouldn't write into them */
34 uint8_t * buf1, * buf2;
35 /* buf3, buf4: used to store output */
36 uint8_t * buf3, * buf4;
40 #define report( name ) { \
41 if( used_asm && !quiet ) \
42 fprintf( stderr, " - %-21s [%s]\n", name, ok ? "OK" : "FAILED" ); \
46 #define BENCH_RUNS 100 // tradeoff between accuracy and speed
47 #define BENCH_ALIGNS 16 // number of stack+heap data alignments (another accuracy vs speed tradeoff)
48 #define MAX_FUNCS 1000 // just has to be big enough to hold all the existing functions
49 #define MAX_CPUS 10 // number of different combinations of cpu flags
52 void *pointer; // just for detecting duplicates
60 bench_t vers[MAX_CPUS];
64 int bench_pattern_len = 0;
65 const char *bench_pattern = "";
67 static bench_func_t benchs[MAX_FUNCS];
69 static const char *pixel_names[10] = { "16x16", "16x8", "8x16", "8x8", "8x4", "4x8", "4x4", "4x2", "2x4", "2x2" };
70 static const char *intra_predict_16x16_names[7] = { "v", "h", "dc", "p", "dcl", "dct", "dc8" };
71 static const char *intra_predict_8x8c_names[7] = { "dc", "h", "v", "p", "dcl", "dct", "dc8" };
72 static const char *intra_predict_4x4_names[12] = { "v", "h", "dc", "ddl", "ddr", "vr", "hd", "vl", "hu", "dcl", "dct", "dc8" };
73 static const char **intra_predict_8x8_names = intra_predict_4x4_names;
75 #define set_func_name(...) snprintf( func_name, sizeof(func_name), __VA_ARGS__ )
77 static inline uint32_t read_time(void)
79 #if defined(__GNUC__) && (defined(ARCH_X86) || defined(ARCH_X86_64))
81 asm volatile( "rdtsc" :"=a"(a) ::"edx" );
88 static bench_t* get_bench( const char *name, int cpu )
91 for( i=0; benchs[i].name && strcmp(name, benchs[i].name); i++ )
92 assert( i < MAX_FUNCS );
94 benchs[i].name = strdup( name );
96 return &benchs[i].vers[0];
97 for( j=1; benchs[i].vers[j].cpu && benchs[i].vers[j].cpu != cpu; j++ )
98 assert( j < MAX_CPUS );
99 benchs[i].vers[j].cpu = cpu;
100 return &benchs[i].vers[j];
103 int cmp_nop( const void *a, const void *b )
105 return *(uint16_t*)a - *(uint16_t*)b;
108 int cmp_bench( const void *a, const void *b )
110 // asciibetical sort except preserving numbers
111 const char *sa = ((bench_func_t*)a)->name;
112 const char *sb = ((bench_func_t*)b)->name;
115 if( !*sa && !*sb ) return 0;
116 if( isdigit(*sa) && isdigit(*sb) && isdigit(sa[1]) != isdigit(sb[1]) )
117 return isdigit(sa[1]) - isdigit(sb[1]);
118 if( *sa != *sb ) return *sa - *sb;
122 static void print_bench(void)
124 uint16_t nops[10000] = {0};
125 int i, j, k, nfuncs, nop_time=0;
127 for( i=0; i<10000; i++ )
130 nops[i] = read_time() - t;
132 qsort( nops, 10000, sizeof(uint16_t), cmp_nop );
133 for( i=500; i<9500; i++ )
136 printf( "nop: %d\n", nop_time );
138 for( i=0; i<MAX_FUNCS && benchs[i].name; i++ );
140 qsort( benchs, nfuncs, sizeof(bench_func_t), cmp_bench );
141 for( i=0; i<nfuncs; i++ )
142 for( j=0; j<MAX_CPUS && (!j || benchs[i].vers[j].cpu); j++ )
144 bench_t *b = &benchs[i].vers[j];
145 if( !b->den ) continue;
146 for( k=0; k<j && benchs[i].vers[k].pointer != b->pointer; k++ );
148 printf( "%s_%s%s: %"PRId64"\n", benchs[i].name,
149 b->cpu&X264_CPU_PHADD_IS_FAST ? "phadd" :
150 b->cpu&X264_CPU_SSSE3 ? "ssse3" :
151 b->cpu&X264_CPU_SSE3 ? "sse3" :
152 /* print sse2slow only if there's also a sse2fast version of the same func */
153 b->cpu&X264_CPU_SSE2_IS_SLOW && j<MAX_CPUS && b[1].cpu&X264_CPU_SSE2_IS_FAST && !(b[1].cpu&X264_CPU_SSE3) ? "sse2slow" :
154 b->cpu&X264_CPU_SSE2 ? "sse2" :
155 b->cpu&X264_CPU_MMX ? "mmx" : "c",
156 b->cpu&X264_CPU_CACHELINE_32 ? "_c32" :
157 b->cpu&X264_CPU_CACHELINE_64 ? "_c64" : "",
158 ((int64_t)10*b->cycles/b->den - nop_time)/4 );
162 #if defined(ARCH_X86) || defined(ARCH_X86_64)
163 int x264_stack_pagealign( int (*func)(), int align );
165 #define x264_stack_pagealign( func, align ) func()
168 #define call_c1(func,...) func(__VA_ARGS__)
171 /* detect when callee-saved regs aren't saved.
172 * needs an explicit asm check because it only sometimes crashes in normal use. */
173 long x264_checkasm_call( long (*func)(), int *ok, ... );
174 #define call_a1(func,...) x264_checkasm_call((long(*)())func, &ok, __VA_ARGS__)
176 #define call_a1 call_c1
179 #define call_bench(func,cpu,...)\
180 if( do_bench && !strncmp(func_name, bench_pattern, bench_pattern_len) )\
185 call_a1(func, __VA_ARGS__);\
186 for( ti=0; ti<(cpu?BENCH_RUNS:BENCH_RUNS/4); ti++ )\
188 uint32_t t = read_time();\
193 t = read_time() - t;\
194 if( t*tcount <= tsum*4 && ti > 0 )\
200 bench_t *b = get_bench( func_name, cpu );\
206 /* for most functions, run benchmark and correctness test at the same time.
207 * for those that modify their inputs, run the above macros separately */
208 #define call_a(func,...) ({ call_a2(func,__VA_ARGS__); call_a1(func,__VA_ARGS__); })
209 #define call_c(func,...) ({ call_c2(func,__VA_ARGS__); call_c1(func,__VA_ARGS__); })
210 #define call_a2(func,...) ({ call_bench(func,cpu_new,__VA_ARGS__); })
211 #define call_c2(func,...) ({ call_bench(func,0,__VA_ARGS__); })
214 static int check_pixel( int cpu_ref, int cpu_new )
216 x264_pixel_function_t pixel_c;
217 x264_pixel_function_t pixel_ref;
218 x264_pixel_function_t pixel_asm;
219 x264_predict_t predict_16x16[4+3];
220 x264_predict_t predict_8x8c[4+3];
221 x264_predict_t predict_4x4[9+3];
222 x264_predict8x8_t predict_8x8[9+3];
223 DECLARE_ALIGNED_16( uint8_t edge[33] );
224 uint16_t cost_mv[32];
225 int ret = 0, ok, used_asm;
228 x264_pixel_init( 0, &pixel_c );
229 x264_pixel_init( cpu_ref, &pixel_ref );
230 x264_pixel_init( cpu_new, &pixel_asm );
231 x264_predict_16x16_init( 0, predict_16x16 );
232 x264_predict_8x8c_init( 0, predict_8x8c );
233 x264_predict_8x8_init( 0, predict_8x8 );
234 x264_predict_4x4_init( 0, predict_4x4 );
235 x264_predict_8x8_filter( buf2+40, edge, ALL_NEIGHBORS, ALL_NEIGHBORS );
237 #define TEST_PIXEL( name, align ) \
238 for( i = 0, ok = 1, used_asm = 0; i < 7; i++ ) \
240 int res_c, res_asm; \
241 if( pixel_asm.name[i] != pixel_ref.name[i] ) \
243 set_func_name( "%s_%s", #name, pixel_names[i] ); \
244 for( j=0; j<64; j++ ) \
247 res_c = call_c( pixel_c.name[i], buf1, 16, buf2+j*!align, 64 ); \
248 res_asm = call_a( pixel_asm.name[i], buf1, 16, buf2+j*!align, 64 ); \
249 if( res_c != res_asm ) \
252 fprintf( stderr, #name "[%d]: %d != %d [FAILED]\n", i, res_c, res_asm ); \
258 report( "pixel " #name " :" );
260 TEST_PIXEL( sad, 0 );
261 TEST_PIXEL( ssd, 1 );
262 TEST_PIXEL( satd, 0 );
263 TEST_PIXEL( sa8d, 0 );
265 #define TEST_PIXEL_X( N ) \
266 for( i = 0, ok = 1, used_asm = 0; i < 7; i++ ) \
268 int res_c[4]={0}, res_asm[4]={0}; \
269 if( pixel_asm.sad_x##N[i] && pixel_asm.sad_x##N[i] != pixel_ref.sad_x##N[i] ) \
271 set_func_name( "sad_x%d_%s", N, pixel_names[i] ); \
272 for( j=0; j<64; j++) \
274 uint8_t *pix2 = buf2+j; \
276 res_c[0] = pixel_c.sad[i]( buf1, 16, pix2, 64 ); \
277 res_c[1] = pixel_c.sad[i]( buf1, 16, pix2+6, 64 ); \
278 res_c[2] = pixel_c.sad[i]( buf1, 16, pix2+1, 64 ); \
281 res_c[3] = pixel_c.sad[i]( buf1, 16, pix2+10, 64 ); \
282 call_a( pixel_asm.sad_x4[i], buf1, pix2, pix2+6, pix2+1, pix2+10, 64, res_asm ); \
285 call_a( pixel_asm.sad_x3[i], buf1, pix2, pix2+6, pix2+1, 64, res_asm ); \
286 if( memcmp(res_c, res_asm, sizeof(res_c)) ) \
289 fprintf( stderr, "sad_x"#N"[%d]: %d,%d,%d,%d != %d,%d,%d,%d [FAILED]\n", \
290 i, res_c[0], res_c[1], res_c[2], res_c[3], \
291 res_asm[0], res_asm[1], res_asm[2], res_asm[3] ); \
294 call_c2( pixel_c.sad_x4[i], buf1, pix2, pix2+6, pix2+1, pix2+10, 64, res_asm ); \
296 call_c2( pixel_c.sad_x3[i], buf1, pix2, pix2+6, pix2+1, 64, res_asm ); \
300 report( "pixel sad_x"#N" :" );
305 #define TEST_INTRA_SATD( name, pred, satd, i8x8, ... ) \
306 if( pixel_asm.name && pixel_asm.name != pixel_ref.name ) \
308 int res_c[3], res_asm[3]; \
309 set_func_name( #name );\
311 memcpy( buf3, buf2, 1024 ); \
312 for( i=0; i<3; i++ ) \
314 pred[i]( buf3+40, ##__VA_ARGS__ ); \
315 res_c[i] = pixel_c.satd( buf1+40, 16, buf3+40, 32 ); \
317 call_a( pixel_asm.name, buf1+40, i8x8 ? edge : buf3+40, res_asm ); \
318 if( memcmp(res_c, res_asm, sizeof(res_c)) ) \
321 fprintf( stderr, #name": %d,%d,%d != %d,%d,%d [FAILED]\n", \
322 res_c[0], res_c[1], res_c[2], \
323 res_asm[0], res_asm[1], res_asm[2] ); \
327 ok = 1; used_asm = 0;
328 TEST_INTRA_SATD( intra_satd_x3_16x16, predict_16x16, satd[PIXEL_16x16], 0 );
329 TEST_INTRA_SATD( intra_satd_x3_8x8c, predict_8x8c, satd[PIXEL_8x8], 0 );
330 TEST_INTRA_SATD( intra_satd_x3_4x4, predict_4x4, satd[PIXEL_4x4], 0 );
331 TEST_INTRA_SATD( intra_sa8d_x3_8x8, predict_8x8, sa8d[PIXEL_8x8], 1, edge );
332 report( "intra satd_x3 :" );
334 if( pixel_asm.ssim_4x4x2_core != pixel_ref.ssim_4x4x2_core ||
335 pixel_asm.ssim_end4 != pixel_ref.ssim_end4 )
338 int sums[5][4] = {{0}};
341 res_c = x264_pixel_ssim_wxh( &pixel_c, buf1+2, 32, buf2+2, 32, 32, 28 );
342 res_a = x264_pixel_ssim_wxh( &pixel_asm, buf1+2, 32, buf2+2, 32, 32, 28 );
343 if( fabs(res_c - res_a) > 1e-6 )
346 fprintf( stderr, "ssim: %.7f != %.7f [FAILED]\n", res_c, res_a );
348 set_func_name( "ssim_core" );
349 call_c2( pixel_c.ssim_4x4x2_core, buf1+2, 32, buf2+2, 32, sums );
350 call_a2( pixel_asm.ssim_4x4x2_core, buf1+2, 32, buf2+2, 32, sums );
351 set_func_name( "ssim_end" );
352 call_c2( pixel_c.ssim_end4, sums, sums, 4 );
353 call_a2( pixel_asm.ssim_end4, sums, sums, 4 );
357 ok = 1; used_asm = 0;
358 for( i=0; i<32; i++ )
360 for( i=0; i<100 && ok; i++ )
361 if( pixel_asm.ads[i&3] != pixel_ref.ads[i&3] )
363 DECLARE_ALIGNED_16( uint16_t sums[72] );
364 DECLARE_ALIGNED_16( int dc[4] );
365 int16_t mvs_a[32], mvs_c[32];
367 int thresh = rand() & 0x3fff;
368 set_func_name( "esa_ads" );
369 for( j=0; j<72; j++ )
370 sums[j] = rand() & 0x3fff;
372 dc[j] = rand() & 0x3fff;
374 mvn_c = call_c( pixel_c.ads[i&3], dc, sums, 32, cost_mv, mvs_c, 28, thresh );
375 mvn_a = call_a( pixel_asm.ads[i&3], dc, sums, 32, cost_mv, mvs_a, 28, thresh );
376 if( mvn_c != mvn_a || memcmp( mvs_c, mvs_a, mvn_c*sizeof(*mvs_c) ) )
379 printf("c%d: ", i&3);
380 for(j=0; j<mvn_c; j++)
381 printf("%d ", mvs_c[j]);
382 printf("\na%d: ", i&3);
383 for(j=0; j<mvn_a; j++)
384 printf("%d ", mvs_a[j]);
388 report( "esa ads:" );
393 static int check_dct( int cpu_ref, int cpu_new )
395 x264_dct_function_t dct_c;
396 x264_dct_function_t dct_ref;
397 x264_dct_function_t dct_asm;
398 x264_quant_function_t qf;
399 int ret = 0, ok, used_asm, i, interlace;
400 DECLARE_ALIGNED_16( int16_t dct1[16][4][4] );
401 DECLARE_ALIGNED_16( int16_t dct2[16][4][4] );
402 DECLARE_ALIGNED_16( int16_t dct4[16][4][4] );
403 DECLARE_ALIGNED_16( int16_t dct8[4][8][8] );
407 x264_dct_init( 0, &dct_c );
408 x264_dct_init( cpu_ref, &dct_ref);
409 x264_dct_init( cpu_new, &dct_asm );
411 memset( h, 0, sizeof(*h) );
412 h->pps = h->pps_array;
413 x264_param_default( &h->param );
414 h->param.analyse.i_luma_deadzone[0] = 0;
415 h->param.analyse.i_luma_deadzone[1] = 0;
416 h->param.analyse.b_transform_8x8 = 1;
418 h->pps->scaling_list[i] = x264_cqm_flat16;
420 x264_quant_init( h, 0, &qf );
422 #define TEST_DCT( name, t1, t2, size ) \
423 if( dct_asm.name != dct_ref.name ) \
425 set_func_name( #name );\
427 call_c( dct_c.name, t1, buf1, buf2 ); \
428 call_a( dct_asm.name, t2, buf1, buf2 ); \
429 if( memcmp( t1, t2, size ) ) \
432 fprintf( stderr, #name " [FAILED]\n" ); \
435 ok = 1; used_asm = 0;
436 TEST_DCT( sub4x4_dct, dct1[0], dct2[0], 16*2 );
437 TEST_DCT( sub8x8_dct, dct1, dct2, 16*2*4 );
438 TEST_DCT( sub16x16_dct, dct1, dct2, 16*2*16 );
439 report( "sub_dct4 :" );
441 ok = 1; used_asm = 0;
442 TEST_DCT( sub8x8_dct8, (void*)dct1[0], (void*)dct2[0], 64*2 );
443 TEST_DCT( sub16x16_dct8, (void*)dct1, (void*)dct2, 64*2*4 );
444 report( "sub_dct8 :" );
447 // fdct and idct are denormalized by different factors, so quant/dequant
448 // is needed to force the coefs into the right range.
449 dct_c.sub16x16_dct( dct4, buf1, buf2 );
450 dct_c.sub16x16_dct8( dct8, buf1, buf2 );
451 for( i=0; i<16; i++ )
453 qf.quant_4x4( dct4[i], h->quant4_mf[CQM_4IY][20], h->quant4_bias[CQM_4IY][20] );
454 qf.dequant_4x4( dct4[i], h->dequant4_mf[CQM_4IY], 20 );
458 qf.quant_8x8( dct8[i], h->quant8_mf[CQM_8IY][20], h->quant8_bias[CQM_8IY][20] );
459 qf.dequant_8x8( dct8[i], h->dequant8_mf[CQM_8IY], 20 );
462 #define TEST_IDCT( name, src ) \
463 if( dct_asm.name != dct_ref.name ) \
465 set_func_name( #name );\
467 memcpy( buf3, buf1, 32*32 ); \
468 memcpy( buf4, buf1, 32*32 ); \
469 memcpy( dct1, src, 512 ); \
470 memcpy( dct2, src, 512 ); \
471 call_c1( dct_c.name, buf3, (void*)dct1 ); \
472 call_a1( dct_asm.name, buf4, (void*)dct2 ); \
473 if( memcmp( buf3, buf4, 32*32 ) ) \
476 fprintf( stderr, #name " [FAILED]\n" ); \
478 call_c2( dct_c.name, buf3, (void*)dct1 ); \
479 call_a2( dct_asm.name, buf4, (void*)dct2 ); \
481 ok = 1; used_asm = 0;
482 TEST_IDCT( add4x4_idct, dct4 );
483 TEST_IDCT( add8x8_idct, dct4 );
484 TEST_IDCT( add16x16_idct, dct4 );
485 report( "add_idct4 :" );
487 ok = 1; used_asm = 0;
488 TEST_IDCT( add8x8_idct8, dct8 );
489 TEST_IDCT( add16x16_idct8, dct8 );
490 report( "add_idct8 :" );
493 ok = 1; used_asm = 0;
494 if( dct_asm.dct4x4dc != dct_ref.dct4x4dc )
496 DECLARE_ALIGNED_16( int16_t dct1[4][4] ) = {{-12, 42, 23, 67},{2, 90, 89,56},{67,43,-76,91},{56,-78,-54,1}};
497 DECLARE_ALIGNED_16( int16_t dct2[4][4] ) = {{-12, 42, 23, 67},{2, 90, 89,56},{67,43,-76,91},{56,-78,-54,1}};
498 set_func_name( "dct4x4dc" );
500 call_c1( dct_c.dct4x4dc, dct1 );
501 call_a1( dct_asm.dct4x4dc, dct2 );
502 if( memcmp( dct1, dct2, 32 ) )
505 fprintf( stderr, " - dct4x4dc : [FAILED]\n" );
507 call_c2( dct_c.dct4x4dc, dct1 );
508 call_a2( dct_asm.dct4x4dc, dct2 );
510 if( dct_asm.idct4x4dc != dct_ref.idct4x4dc )
512 DECLARE_ALIGNED_16( int16_t dct1[4][4] ) = {{-12, 42, 23, 67},{2, 90, 89,56},{67,43,-76,91},{56,-78,-54,1}};
513 DECLARE_ALIGNED_16( int16_t dct2[4][4] ) = {{-12, 42, 23, 67},{2, 90, 89,56},{67,43,-76,91},{56,-78,-54,1}};
514 set_func_name( "idct4x4dc" );
516 call_c1( dct_c.idct4x4dc, dct1 );
517 call_a1( dct_asm.idct4x4dc, dct2 );
518 if( memcmp( dct1, dct2, 32 ) )
521 fprintf( stderr, " - idct4x4dc : [FAILED]\n" );
523 call_c2( dct_c.idct4x4dc, dct1 );
524 call_a2( dct_asm.idct4x4dc, dct2 );
526 report( "(i)dct4x4dc :" );
528 ok = 1; used_asm = 0;
529 if( dct_asm.dct2x2dc != dct_ref.dct2x2dc )
531 DECLARE_ALIGNED_16( int16_t dct1[2][2] ) = {{-12, 42},{2, 90}};
532 DECLARE_ALIGNED_16( int16_t dct2[2][2] ) = {{-12, 42},{2, 90}};
533 set_func_name( "dct2x2dc" );
535 call_c( dct_c.dct2x2dc, dct1 );
536 call_a( dct_asm.dct2x2dc, dct2 );
537 if( memcmp( dct1, dct2, 4*2 ) )
540 fprintf( stderr, " - dct2x2dc : [FAILED]\n" );
543 if( dct_asm.idct2x2dc != dct_ref.idct2x2dc )
545 DECLARE_ALIGNED_16( int16_t dct1[2][2] ) = {{-12, 42},{2, 90}};
546 DECLARE_ALIGNED_16( int16_t dct2[2][2] ) = {{-12, 42},{2, 90}};
547 set_func_name( "idct2x2dc" );
549 call_c( dct_c.idct2x2dc, dct1 );
550 call_a( dct_asm.idct2x2dc, dct2 );
551 if( memcmp( dct1, dct2, 4*2 ) )
554 fprintf( stderr, " - idct2x2dc : [FAILED]\n" );
557 report( "(i)dct2x2dc :" );
559 x264_zigzag_function_t zigzag_c;
560 x264_zigzag_function_t zigzag_ref;
561 x264_zigzag_function_t zigzag_asm;
563 DECLARE_ALIGNED_16( int16_t level1[64] );
564 DECLARE_ALIGNED_16( int16_t level2[64] );
566 #define TEST_ZIGZAG_SCAN( name, t1, t2, dct, size ) \
567 if( zigzag_asm.name != zigzag_ref.name ) \
569 set_func_name( "zigzag_"#name"_%s", interlace?"field":"frame" );\
571 call_c( zigzag_c.name, t1, dct ); \
572 call_a( zigzag_asm.name, t2, dct ); \
573 if( memcmp( t1, t2, size*sizeof(int16_t) ) ) \
576 fprintf( stderr, #name " [FAILED]\n" ); \
580 #define TEST_ZIGZAG_SUB( name, t1, t2, size ) \
581 if( zigzag_asm.name != zigzag_ref.name ) \
583 set_func_name( "zigzag_"#name"_%s", interlace?"field":"frame" );\
585 memcpy( buf3, buf1, 16*FDEC_STRIDE ); \
586 memcpy( buf4, buf1, 16*FDEC_STRIDE ); \
587 call_c1( zigzag_c.name, t1, buf2, buf3 ); \
588 call_a1( zigzag_asm.name, t2, buf2, buf4 ); \
589 if( memcmp( t1, t2, size*sizeof(int16_t) )|| memcmp( buf3, buf4, 16*FDEC_STRIDE ) ) \
592 fprintf( stderr, #name " [FAILED]\n" ); \
594 call_c2( zigzag_c.name, t1, buf2, buf3 ); \
595 call_a2( zigzag_asm.name, t2, buf2, buf4 ); \
599 x264_zigzag_init( 0, &zigzag_c, 0 );
600 x264_zigzag_init( cpu_ref, &zigzag_ref, 0 );
601 x264_zigzag_init( cpu_new, &zigzag_asm, 0 );
603 ok = 1; used_asm = 0;
604 TEST_ZIGZAG_SCAN( scan_8x8, level1, level2, (void*)dct1, 64 );
605 TEST_ZIGZAG_SCAN( scan_4x4, level1, level2, dct1[0], 16 );
606 TEST_ZIGZAG_SUB( sub_4x4, level1, level2, 16 );
607 report( "zigzag_frame :" );
610 x264_zigzag_init( 0, &zigzag_c, 1 );
611 x264_zigzag_init( cpu_ref, &zigzag_ref, 1 );
612 x264_zigzag_init( cpu_new, &zigzag_asm, 1 );
614 ok = 1; used_asm = 0;
615 TEST_ZIGZAG_SCAN( scan_8x8, level1, level2, (void*)dct1, 64 );
616 TEST_ZIGZAG_SCAN( scan_4x4, level1, level2, dct1[0], 16 );
617 TEST_ZIGZAG_SUB( sub_4x4, level1, level2, 16 );
618 report( "zigzag_field :" );
619 #undef TEST_ZIGZAG_SCAN
620 #undef TEST_ZIGZAG_SUB
625 static int check_mc( int cpu_ref, int cpu_new )
627 x264_mc_functions_t mc_c;
628 x264_mc_functions_t mc_ref;
629 x264_mc_functions_t mc_a;
630 x264_pixel_function_t pixel;
632 uint8_t *src = &buf1[2*32+2];
633 uint8_t *src2[4] = { &buf1[3*64+2], &buf1[5*64+2],
634 &buf1[7*64+2], &buf1[9*64+2] };
635 uint8_t *dst1 = buf3;
636 uint8_t *dst2 = buf4;
638 int dx, dy, i, j, k, w;
639 int ret = 0, ok, used_asm;
641 x264_mc_init( 0, &mc_c );
642 x264_mc_init( cpu_ref, &mc_ref );
643 x264_mc_init( cpu_new, &mc_a );
644 x264_pixel_init( 0, &pixel );
646 #define MC_TEST_LUMA( w, h ) \
647 if( mc_a.mc_luma != mc_ref.mc_luma && !(w&(w-1)) && h<=16 ) \
649 set_func_name( "mc_luma_%dx%d", w, h );\
651 memset(buf3, 0xCD, 1024); \
652 memset(buf4, 0xCD, 1024); \
653 call_c( mc_c.mc_luma, dst1, 32, src2, 64, dx, dy, w, h ); \
654 call_a( mc_a.mc_luma, dst2, 32, src2, 64, dx, dy, w, h ); \
655 if( memcmp( buf3, buf4, 1024 ) ) \
657 fprintf( stderr, "mc_luma[mv(%d,%d) %2dx%-2d] [FAILED]\n", dx, dy, w, h ); \
661 if( mc_a.get_ref != mc_ref.get_ref ) \
663 uint8_t *ref = dst2; \
664 int ref_stride = 32; \
665 set_func_name( "get_ref_%dx%d", w, h );\
667 memset(buf3, 0xCD, 1024); \
668 memset(buf4, 0xCD, 1024); \
669 call_c( mc_c.mc_luma, dst1, 32, src2, 64, dx, dy, w, h ); \
670 ref = (uint8_t*) call_a( mc_a.get_ref, ref, &ref_stride, src2, 64, dx, dy, w, h ); \
671 for( i=0; i<h; i++ ) \
672 if( memcmp( dst1+i*32, ref+i*ref_stride, w ) ) \
674 fprintf( stderr, "get_ref[mv(%d,%d) %2dx%-2d] [FAILED]\n", dx, dy, w, h ); \
680 #define MC_TEST_CHROMA( w, h ) \
681 if( mc_a.mc_chroma != mc_ref.mc_chroma ) \
683 set_func_name( "mc_chroma_%dx%d", w, h );\
685 memset(buf3, 0xCD, 1024); \
686 memset(buf4, 0xCD, 1024); \
687 call_c( mc_c.mc_chroma, dst1, 16, src, 32, dx, dy, w, h ); \
688 call_a( mc_a.mc_chroma, dst2, 16, src, 32, dx, dy, w, h ); \
689 /* mc_chroma width=2 may write garbage to the right of dst. ignore that. */\
690 for( j=0; j<h; j++ ) \
691 for( i=w; i<4; i++ ) \
692 dst2[i+j*16] = dst1[i+j*16]; \
693 if( memcmp( buf3, buf4, 1024 ) ) \
695 fprintf( stderr, "mc_chroma[mv(%d,%d) %2dx%-2d] [FAILED]\n", dx, dy, w, h ); \
699 ok = 1; used_asm = 0;
700 for( dy = -8; dy < 8; dy++ )
701 for( dx = -128; dx < 128; dx++ )
703 if( rand()&15 ) continue; // running all of them is too slow
704 MC_TEST_LUMA( 20, 18 );
705 MC_TEST_LUMA( 16, 16 );
706 MC_TEST_LUMA( 16, 8 );
707 MC_TEST_LUMA( 12, 10 );
708 MC_TEST_LUMA( 8, 16 );
709 MC_TEST_LUMA( 8, 8 );
710 MC_TEST_LUMA( 8, 4 );
711 MC_TEST_LUMA( 4, 8 );
712 MC_TEST_LUMA( 4, 4 );
714 report( "mc luma :" );
716 ok = 1; used_asm = 0;
717 for( dy = -1; dy < 9; dy++ )
718 for( dx = -1; dx < 9; dx++ )
720 MC_TEST_CHROMA( 8, 8 );
721 MC_TEST_CHROMA( 8, 4 );
722 MC_TEST_CHROMA( 4, 8 );
723 MC_TEST_CHROMA( 4, 4 );
724 MC_TEST_CHROMA( 4, 2 );
725 MC_TEST_CHROMA( 2, 4 );
726 MC_TEST_CHROMA( 2, 2 );
728 report( "mc chroma :" );
730 #undef MC_TEST_CHROMA
732 #define MC_TEST_AVG( name, ... ) \
733 for( i = 0, ok = 1, used_asm = 0; i < 10; i++ ) \
735 memcpy( buf3, buf1, 1024 ); \
736 memcpy( buf4, buf1, 1024 ); \
737 if( mc_a.name[i] != mc_ref.name[i] ) \
739 set_func_name( "%s_%s", #name, pixel_names[i] );\
741 call_c1( mc_c.name[i], buf3, 32, buf2, 16, ##__VA_ARGS__ ); \
742 call_a1( mc_a.name[i], buf4, 32, buf2, 16, ##__VA_ARGS__ ); \
743 if( memcmp( buf3, buf4, 1024 ) ) \
746 fprintf( stderr, #name "[%d]: [FAILED]\n", i ); \
748 call_c2( mc_c.name[i], buf3, 32, buf2, 16, ##__VA_ARGS__ ); \
749 call_a2( mc_a.name[i], buf4, 32, buf2, 16, ##__VA_ARGS__ ); \
753 report( "mc avg :" );
754 ok = 1; used_asm = 0;
755 for( w = -64; w <= 128 && ok; w++ )
756 MC_TEST_AVG( avg_weight, w );
757 report( "mc wpredb :" );
759 if( mc_a.hpel_filter != mc_ref.hpel_filter )
761 uint8_t *src = buf1+8+2*64;
762 uint8_t *dstc[3] = { buf3+8, buf3+8+16*64, buf3+8+32*64 };
763 uint8_t *dsta[3] = { buf4+8, buf4+8+16*64, buf4+8+32*64 };
764 set_func_name( "hpel_filter" );
765 ok = 1; used_asm = 1;
766 memset( buf3, 0, 4096 );
767 memset( buf4, 0, 4096 );
768 call_c( mc_c.hpel_filter, dstc[0], dstc[1], dstc[2], src, 64, 48, 10 );
769 call_a( mc_a.hpel_filter, dsta[0], dsta[1], dsta[2], src, 64, 48, 10 );
771 for( j=0; j<10; j++ )
772 //FIXME ideally the first pixels would match too, but they aren't actually used
773 if( memcmp( dstc[i]+j*64+2, dsta[i]+j*64+2, 43 ) )
776 fprintf( stderr, "hpel filter differs at plane %c line %d\n", "hvc"[i], j );
777 for( k=0; k<48; k++ )
778 printf("%02x%s", dstc[i][j*64+k], (k+1)&3 ? "" : " ");
780 for( k=0; k<48; k++ )
781 printf("%02x%s", dsta[i][j*64+k], (k+1)&3 ? "" : " ");
785 report( "hpel filter :" );
788 if( mc_a.frame_init_lowres_core != mc_ref.frame_init_lowres_core )
790 uint8_t *dstc[4] = { buf3, buf3+1024, buf3+2048, buf3+3072 };
791 uint8_t *dsta[4] = { buf4, buf4+1024, buf4+2048, buf3+3072 };
792 set_func_name( "lowres_init" );
793 for( w=40; w<=48; w+=8 )
794 if( mc_a.frame_init_lowres_core != mc_ref.frame_init_lowres_core )
796 int stride = (w+8)&~15;
798 call_c( mc_c.frame_init_lowres_core, buf1, dstc[0], dstc[1], dstc[2], dstc[3], w*2, stride, w, 16 );
799 call_a( mc_a.frame_init_lowres_core, buf1, dsta[0], dsta[1], dsta[2], dsta[3], w*2, stride, w, 16 );
803 if( memcmp( dstc[j]+i*stride, dsta[j]+i*stride, w ) )
806 fprintf( stderr, "frame_init_lowres differs at plane %d line %d\n", j, i );
808 printf( "%d ", dstc[j][k+i*stride] );
811 printf( "%d ", dsta[j][k+i*stride] );
817 report( "lowres init :" );
823 static int check_deblock( int cpu_ref, int cpu_new )
825 x264_deblock_function_t db_c;
826 x264_deblock_function_t db_ref;
827 x264_deblock_function_t db_a;
828 int ret = 0, ok = 1, used_asm = 0;
829 int alphas[36], betas[36];
833 x264_deblock_init( 0, &db_c );
834 x264_deblock_init( cpu_ref, &db_ref );
835 x264_deblock_init( cpu_new, &db_a );
837 /* not exactly the real values of a,b,tc but close enough */
839 for( i = 35; i >= 0; i-- )
843 tcs[i][0] = tcs[i][2] = (c+6)/10;
844 tcs[i][1] = tcs[i][3] = (c+9)/20;
849 #define TEST_DEBLOCK( name, align, ... ) \
850 for( i = 0; i < 36; i++ ) \
852 int off = 8*32 + (i&15)*4*!align; /* benchmark various alignments of h filter */\
853 for( j = 0; j < 1024; j++ ) \
854 /* two distributions of random to excersize different failure modes */\
855 buf3[j] = rand() & (i&1 ? 0xf : 0xff ); \
856 memcpy( buf4, buf3, 1024 ); \
857 if( db_a.name != db_ref.name ) \
859 set_func_name( #name );\
861 call_c1( db_c.name, buf3+off, 32, alphas[i], betas[i], ##__VA_ARGS__ ); \
862 call_a1( db_a.name, buf4+off, 32, alphas[i], betas[i], ##__VA_ARGS__ ); \
863 if( memcmp( buf3, buf4, 1024 ) ) \
866 fprintf( stderr, #name "(a=%d, b=%d): [FAILED]\n", alphas[i], betas[i] ); \
869 call_c2( db_c.name, buf3+off, 32, alphas[i], betas[i], ##__VA_ARGS__ ); \
870 call_a2( db_a.name, buf4+off, 32, alphas[i], betas[i], ##__VA_ARGS__ ); \
874 TEST_DEBLOCK( deblock_h_luma, 0, tcs[i] );
875 TEST_DEBLOCK( deblock_v_luma, 1, tcs[i] );
876 TEST_DEBLOCK( deblock_h_chroma, 0, tcs[i] );
877 TEST_DEBLOCK( deblock_v_chroma, 1, tcs[i] );
878 TEST_DEBLOCK( deblock_h_luma_intra, 0 );
879 TEST_DEBLOCK( deblock_v_luma_intra, 1 );
880 TEST_DEBLOCK( deblock_h_chroma_intra, 0 );
881 TEST_DEBLOCK( deblock_v_chroma_intra, 1 );
883 report( "deblock :" );
888 static int check_quant( int cpu_ref, int cpu_new )
890 x264_quant_function_t qf_c;
891 x264_quant_function_t qf_ref;
892 x264_quant_function_t qf_a;
893 DECLARE_ALIGNED_16( int16_t dct1[64] );
894 DECLARE_ALIGNED_16( int16_t dct2[64] );
895 DECLARE_ALIGNED_16( uint8_t cqm_buf[64] );
896 int ret = 0, ok, used_asm;
897 int oks[2] = {1,1}, used_asms[2] = {0,0};
901 memset( h, 0, sizeof(*h) );
902 h->pps = h->pps_array;
903 x264_param_default( &h->param );
904 h->param.rc.i_qp_min = 26;
905 h->param.analyse.b_transform_8x8 = 1;
907 for( i_cqm = 0; i_cqm < 4; i_cqm++ )
911 for( i = 0; i < 6; i++ )
912 h->pps->scaling_list[i] = x264_cqm_flat16;
913 h->param.i_cqm_preset = h->pps->i_cqm_preset = X264_CQM_FLAT;
915 else if( i_cqm == 1 )
917 for( i = 0; i < 6; i++ )
918 h->pps->scaling_list[i] = x264_cqm_jvt[i];
919 h->param.i_cqm_preset = h->pps->i_cqm_preset = X264_CQM_JVT;
924 for( i = 0; i < 64; i++ )
925 cqm_buf[i] = 10 + rand() % 246;
927 for( i = 0; i < 64; i++ )
929 for( i = 0; i < 6; i++ )
930 h->pps->scaling_list[i] = cqm_buf;
931 h->param.i_cqm_preset = h->pps->i_cqm_preset = X264_CQM_CUSTOM;
935 x264_quant_init( h, 0, &qf_c );
936 x264_quant_init( h, cpu_ref, &qf_ref );
937 x264_quant_init( h, cpu_new, &qf_a );
939 #define INIT_QUANT8() \
941 static const int scale1d[8] = {32,31,24,31,32,31,24,31}; \
943 for( y = 0; y < 8; y++ ) \
944 for( x = 0; x < 8; x++ ) \
946 unsigned int scale = (255*scale1d[y]*scale1d[x])/16; \
947 dct1[y*8+x] = dct2[y*8+x] = (rand()%(2*scale+1))-scale; \
951 #define INIT_QUANT4() \
953 static const int scale1d[4] = {4,6,4,6}; \
955 for( y = 0; y < 4; y++ ) \
956 for( x = 0; x < 4; x++ ) \
958 unsigned int scale = 255*scale1d[y]*scale1d[x]; \
959 dct1[y*4+x] = dct2[y*4+x] = (rand()%(2*scale+1))-scale; \
963 #define TEST_QUANT_DC( name, cqm ) \
964 if( qf_a.name != qf_ref.name ) \
966 set_func_name( #name ); \
968 for( qp = 51; qp > 0; qp-- ) \
970 for( i = 0; i < 16; i++ ) \
971 dct1[i] = dct2[i] = (rand() & 0x1fff) - 0xfff; \
972 call_c1( qf_c.name, (void*)dct1, h->quant4_mf[CQM_4IY][qp][0], h->quant4_bias[CQM_4IY][qp][0] ); \
973 call_a1( qf_a.name, (void*)dct2, h->quant4_mf[CQM_4IY][qp][0], h->quant4_bias[CQM_4IY][qp][0] ); \
974 if( memcmp( dct1, dct2, 16*2 ) ) \
977 fprintf( stderr, #name "(cqm=%d): [FAILED]\n", i_cqm ); \
980 call_c2( qf_c.name, (void*)dct1, h->quant4_mf[CQM_4IY][qp][0], h->quant4_bias[CQM_4IY][qp][0] ); \
981 call_a2( qf_a.name, (void*)dct2, h->quant4_mf[CQM_4IY][qp][0], h->quant4_bias[CQM_4IY][qp][0] ); \
985 #define TEST_QUANT( qname, block, w ) \
986 if( qf_a.qname != qf_ref.qname ) \
988 set_func_name( #qname ); \
990 for( qp = 51; qp > 0; qp-- ) \
993 call_c1( qf_c.qname, (void*)dct1, h->quant##w##_mf[block][qp], h->quant##w##_bias[block][qp] ); \
994 call_a1( qf_a.qname, (void*)dct2, h->quant##w##_mf[block][qp], h->quant##w##_bias[block][qp] ); \
995 if( memcmp( dct1, dct2, w*w*2 ) ) \
998 fprintf( stderr, #qname "(qp=%d, cqm=%d, block="#block"): [FAILED]\n", qp, i_cqm ); \
1001 call_c2( qf_c.qname, (void*)dct1, h->quant##w##_mf[block][qp], h->quant##w##_bias[block][qp] ); \
1002 call_a2( qf_a.qname, (void*)dct2, h->quant##w##_mf[block][qp], h->quant##w##_bias[block][qp] ); \
1006 TEST_QUANT( quant_8x8, CQM_8IY, 8 );
1007 TEST_QUANT( quant_8x8, CQM_8PY, 8 );
1008 TEST_QUANT( quant_4x4, CQM_4IY, 4 );
1009 TEST_QUANT( quant_4x4, CQM_4PY, 4 );
1010 TEST_QUANT_DC( quant_4x4_dc, **h->quant4_mf[CQM_4IY] );
1011 TEST_QUANT_DC( quant_2x2_dc, **h->quant4_mf[CQM_4IC] );
1013 #define TEST_DEQUANT( qname, dqname, block, w ) \
1014 if( qf_a.dqname != qf_ref.dqname ) \
1016 set_func_name( "%s_%s", #dqname, i_cqm?"cqm":"flat" ); \
1018 for( qp = 51; qp > 0; qp-- ) \
1021 call_c( qf_c.qname, (void*)dct1, h->quant##w##_mf[block][qp], h->quant##w##_bias[block][qp] ); \
1022 memcpy( dct2, dct1, w*w*2 ); \
1023 call_c1( qf_c.dqname, (void*)dct1, h->dequant##w##_mf[block], qp ); \
1024 call_a1( qf_a.dqname, (void*)dct2, h->dequant##w##_mf[block], qp ); \
1025 if( memcmp( dct1, dct2, w*w*2 ) ) \
1028 fprintf( stderr, #dqname "(qp=%d, cqm=%d, block="#block"): [FAILED]\n", qp, i_cqm ); \
1031 call_c2( qf_c.dqname, (void*)dct1, h->dequant##w##_mf[block], qp ); \
1032 call_a2( qf_a.dqname, (void*)dct2, h->dequant##w##_mf[block], qp ); \
1036 TEST_DEQUANT( quant_8x8, dequant_8x8, CQM_8IY, 8 );
1037 TEST_DEQUANT( quant_8x8, dequant_8x8, CQM_8PY, 8 );
1038 TEST_DEQUANT( quant_4x4, dequant_4x4, CQM_4IY, 4 );
1039 TEST_DEQUANT( quant_4x4, dequant_4x4, CQM_4PY, 4 );
1041 x264_cqm_delete( h );
1044 ok = oks[0]; used_asm = used_asms[0];
1045 report( "quant :" );
1047 ok = oks[1]; used_asm = used_asms[1];
1048 report( "dequant :" );
1051 if( qf_a.denoise_dct_core != qf_ref.denoise_dct_core )
1054 for( size = 16; size <= 64; size += 48 )
1056 set_func_name( "denoise_dct" );
1058 memcpy(dct1, buf1, size*2);
1059 memcpy(dct2, buf1, size*2);
1060 memcpy(buf3+256, buf3, 256);
1061 call_c1( qf_c.denoise_dct_core, dct1, (uint32_t*)buf3, (uint16_t*)buf2, size );
1062 call_a1( qf_a.denoise_dct_core, dct2, (uint32_t*)(buf3+256), (uint16_t*)buf2, size );
1063 if( memcmp( dct1, dct2, size*2 ) || memcmp( buf3+4, buf3+256+4, (size-1)*sizeof(uint32_t) ) )
1065 call_c2( qf_c.denoise_dct_core, dct1, (uint32_t*)buf3, (uint16_t*)buf2, size );
1066 call_a2( qf_a.denoise_dct_core, dct2, (uint32_t*)(buf3+256), (uint16_t*)buf2, size );
1069 report( "denoise dct :" );
1074 static int check_intra( int cpu_ref, int cpu_new )
1076 int ret = 0, ok = 1, used_asm = 0;
1078 DECLARE_ALIGNED_16( uint8_t edge[33] );
1081 x264_predict_t predict_16x16[4+3];
1082 x264_predict_t predict_8x8c[4+3];
1083 x264_predict8x8_t predict_8x8[9+3];
1084 x264_predict_t predict_4x4[9+3];
1085 } ip_c, ip_ref, ip_a;
1087 x264_predict_16x16_init( 0, ip_c.predict_16x16 );
1088 x264_predict_8x8c_init( 0, ip_c.predict_8x8c );
1089 x264_predict_8x8_init( 0, ip_c.predict_8x8 );
1090 x264_predict_4x4_init( 0, ip_c.predict_4x4 );
1092 x264_predict_16x16_init( cpu_ref, ip_ref.predict_16x16 );
1093 x264_predict_8x8c_init( cpu_ref, ip_ref.predict_8x8c );
1094 x264_predict_8x8_init( cpu_ref, ip_ref.predict_8x8 );
1095 x264_predict_4x4_init( cpu_ref, ip_ref.predict_4x4 );
1097 x264_predict_16x16_init( cpu_new, ip_a.predict_16x16 );
1098 x264_predict_8x8c_init( cpu_new, ip_a.predict_8x8c );
1099 x264_predict_8x8_init( cpu_new, ip_a.predict_8x8 );
1100 x264_predict_4x4_init( cpu_new, ip_a.predict_4x4 );
1102 x264_predict_8x8_filter( buf1+48, edge, ALL_NEIGHBORS, ALL_NEIGHBORS );
1104 #define INTRA_TEST( name, dir, w, ... ) \
1105 if( ip_a.name[dir] != ip_ref.name[dir] )\
1107 set_func_name( "intra_%s_%s", #name, intra_##name##_names[dir] );\
1109 memcpy( buf3, buf1, 32*20 );\
1110 memcpy( buf4, buf1, 32*20 );\
1111 call_c( ip_c.name[dir], buf3+48, ##__VA_ARGS__ );\
1112 call_a( ip_a.name[dir], buf4+48, ##__VA_ARGS__ );\
1113 if( memcmp( buf3, buf4, 32*20 ) )\
1115 fprintf( stderr, #name "[%d] : [FAILED]\n", dir );\
1118 for(k=-1; k<16; k++)\
1119 printf("%2x ", edge[16+k]);\
1121 for(j=0; j<w; j++){\
1122 printf("%2x ", edge[14-j]);\
1124 printf("%2x ", buf4[48+k+j*32]);\
1128 for(j=0; j<w; j++){\
1131 printf("%2x ", buf3[48+k+j*32]);\
1137 for( i = 0; i < 12; i++ )
1138 INTRA_TEST( predict_4x4, i, 4 );
1139 for( i = 0; i < 7; i++ )
1140 INTRA_TEST( predict_8x8c, i, 8 );
1141 for( i = 0; i < 7; i++ )
1142 INTRA_TEST( predict_16x16, i, 16 );
1143 for( i = 0; i < 12; i++ )
1144 INTRA_TEST( predict_8x8, i, 8, edge );
1146 report( "intra pred :" );
1150 #define DECL_CABAC(cpu) \
1151 static void run_cabac_##cpu( uint8_t *dst )\
1155 x264_cabac_context_init( &cb, SLICE_TYPE_P, 26, 0 );\
1156 x264_cabac_encode_init( &cb, dst, dst+0xff0 );\
1157 for( i=0; i<0x1000; i++ )\
1158 x264_cabac_encode_decision_##cpu( &cb, buf1[i]>>1, buf1[i]&1 );\
1164 #define run_cabac_asm run_cabac_c
1167 static int check_cabac( int cpu_ref, int cpu_new )
1169 int ret = 0, ok, used_asm = 1;
1170 if( cpu_ref || run_cabac_c == run_cabac_asm)
1172 set_func_name( "cabac_encode_decision" );
1173 memcpy( buf4, buf3, 0x1000 );
1174 call_c( run_cabac_c, buf3 );
1175 call_a( run_cabac_asm, buf4 );
1176 ok = !memcmp( buf3, buf4, 0x1000 );
1177 report( "cabac :" );
1181 int check_all_funcs( int cpu_ref, int cpu_new )
1183 return check_pixel( cpu_ref, cpu_new )
1184 + check_dct( cpu_ref, cpu_new )
1185 + check_mc( cpu_ref, cpu_new )
1186 + check_intra( cpu_ref, cpu_new )
1187 + check_deblock( cpu_ref, cpu_new )
1188 + check_quant( cpu_ref, cpu_new )
1189 + check_cabac( cpu_ref, cpu_new );
1192 int add_flags( int *cpu_ref, int *cpu_new, int flags, const char *name )
1194 *cpu_ref = *cpu_new;
1196 if( *cpu_new & X264_CPU_SSE2_IS_FAST )
1197 *cpu_new &= ~X264_CPU_SSE2_IS_SLOW;
1199 fprintf( stderr, "x264: %s\n", name );
1200 return check_all_funcs( *cpu_ref, *cpu_new );
1203 int check_all_flags( void )
1206 int cpu0 = 0, cpu1 = 0;
1208 if( x264_cpu_detect() & X264_CPU_MMXEXT )
1210 ret |= add_flags( &cpu0, &cpu1, X264_CPU_MMX | X264_CPU_MMXEXT, "MMX" );
1211 ret |= add_flags( &cpu0, &cpu1, X264_CPU_CACHELINE_64, "MMX Cache64" );
1212 cpu1 &= ~X264_CPU_CACHELINE_64;
1214 ret |= add_flags( &cpu0, &cpu1, X264_CPU_CACHELINE_32, "MMX Cache32" );
1215 cpu1 &= ~X264_CPU_CACHELINE_32;
1218 if( x264_cpu_detect() & X264_CPU_SSE2 )
1220 ret |= add_flags( &cpu0, &cpu1, X264_CPU_SSE | X264_CPU_SSE2 | X264_CPU_SSE2_IS_SLOW, "SSE2Slow" );
1221 ret |= add_flags( &cpu0, &cpu1, X264_CPU_SSE2_IS_FAST, "SSE2Fast" );
1222 ret |= add_flags( &cpu0, &cpu1, X264_CPU_CACHELINE_64, "SSE2Fast Cache64" );
1224 if( x264_cpu_detect() & X264_CPU_SSE3 )
1225 ret |= add_flags( &cpu0, &cpu1, X264_CPU_SSE3 | X264_CPU_CACHELINE_64, "SSE3" );
1226 if( x264_cpu_detect() & X264_CPU_SSSE3 )
1228 cpu1 &= ~X264_CPU_CACHELINE_64;
1229 ret |= add_flags( &cpu0, &cpu1, X264_CPU_SSSE3, "SSSE3" );
1230 ret |= add_flags( &cpu0, &cpu1, X264_CPU_CACHELINE_64, "SSSE3 Cache64" );
1231 ret |= add_flags( &cpu0, &cpu1, X264_CPU_PHADD_IS_FAST, "PHADD" );
1234 if( x264_cpu_detect() & X264_CPU_ALTIVEC )
1236 fprintf( stderr, "x264: ALTIVEC against C\n" );
1237 ret = check_all_funcs( 0, X264_CPU_ALTIVEC );
1243 int main(int argc, char *argv[])
1248 if( argc > 1 && !strncmp( argv[1], "--bench", 7 ) )
1250 #if !defined(ARCH_X86) && !defined(ARCH_X86_64)
1251 fprintf( stderr, "no --bench for your cpu until you port rdtsc\n" );
1255 if( argv[1][7] == '=' )
1257 bench_pattern = argv[1]+8;
1258 bench_pattern_len = strlen(bench_pattern);
1264 i = ( argc > 1 ) ? atoi(argv[1]) : x264_mdate();
1265 fprintf( stderr, "x264: using random seed %u\n", i );
1268 buf1 = x264_malloc( 0x3e00 + 16*BENCH_ALIGNS );
1269 buf2 = buf1 + 0xf00;
1270 buf3 = buf2 + 0xf00;
1271 buf4 = buf3 + 0x1000;
1272 for( i=0; i<0x1e00; i++ )
1273 buf1[i] = rand() & 0xFF;
1274 memset( buf1+0x1e00, 0, 0x2000 );
1276 /* 16-byte alignment is guaranteed whenever it's useful, but some functions also vary in speed depending on %64 */
1278 for( i=0; i<BENCH_ALIGNS && !ret; i++ )
1280 buf2 = buf1 + 0xf00;
1281 buf3 = buf2 + 0xf00;
1282 buf4 = buf3 + 0x1000;
1283 ret |= x264_stack_pagealign( check_all_flags, i*16 );
1286 fprintf( stderr, "%d/%d\r", i+1, BENCH_ALIGNS );
1289 ret = check_all_flags();
1293 fprintf( stderr, "x264: at least one test has failed. Go and fix that Right Now!\n" );
1296 fprintf( stderr, "x264: All tests passed Yeah :)\n" );