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 // GCC doesn't align stack variables on ARM, so use .bss
36 #define ALIGNED_16( var ) DECLARE_ALIGNED( static var, 16 )
39 /* buf1, buf2: initialised to random data and shouldn't write into them */
40 uint8_t * buf1, * buf2;
41 /* buf3, buf4: used to store output */
42 uint8_t * buf3, * buf4;
46 #define report( name ) { \
47 if( used_asm && !quiet ) \
48 fprintf( stderr, " - %-21s [%s]\n", name, ok ? "OK" : "FAILED" ); \
52 #define BENCH_RUNS 100 // tradeoff between accuracy and speed
53 #define BENCH_ALIGNS 16 // number of stack+heap data alignments (another accuracy vs speed tradeoff)
54 #define MAX_FUNCS 1000 // just has to be big enough to hold all the existing functions
55 #define MAX_CPUS 10 // number of different combinations of cpu flags
58 void *pointer; // just for detecting duplicates
66 bench_t vers[MAX_CPUS];
70 int bench_pattern_len = 0;
71 const char *bench_pattern = "";
73 static bench_func_t benchs[MAX_FUNCS];
75 static const char *pixel_names[10] = { "16x16", "16x8", "8x16", "8x8", "8x4", "4x8", "4x4", "4x2", "2x4", "2x2" };
76 static const char *intra_predict_16x16_names[7] = { "v", "h", "dc", "p", "dcl", "dct", "dc8" };
77 static const char *intra_predict_8x8c_names[7] = { "dc", "h", "v", "p", "dcl", "dct", "dc8" };
78 static const char *intra_predict_4x4_names[12] = { "v", "h", "dc", "ddl", "ddr", "vr", "hd", "vl", "hu", "dcl", "dct", "dc8" };
79 static const char **intra_predict_8x8_names = intra_predict_4x4_names;
81 #define set_func_name(...) snprintf( func_name, sizeof(func_name), __VA_ARGS__ )
83 static inline uint32_t read_time(void)
86 #if defined(__GNUC__) && (defined(ARCH_X86) || defined(ARCH_X86_64))
87 asm volatile( "rdtsc" :"=a"(a) ::"edx" );
88 #elif defined(ARCH_PPC)
89 asm volatile( "mftb %0" : "=r" (a) );
90 #elif defined(ARCH_ARM) // ARMv7 only
91 asm volatile( "mrc p15, 0, %0, c9, c13, 0" : "=r"(a) );
96 static bench_t* get_bench( const char *name, int cpu )
99 for( i = 0; benchs[i].name && strcmp(name, benchs[i].name); i++ )
100 assert( i < MAX_FUNCS );
101 if( !benchs[i].name )
102 benchs[i].name = strdup( name );
104 return &benchs[i].vers[0];
105 for( j = 1; benchs[i].vers[j].cpu && benchs[i].vers[j].cpu != cpu; j++ )
106 assert( j < MAX_CPUS );
107 benchs[i].vers[j].cpu = cpu;
108 return &benchs[i].vers[j];
111 static int cmp_nop( const void *a, const void *b )
113 return *(uint16_t*)a - *(uint16_t*)b;
116 static int cmp_bench( const void *a, const void *b )
118 // asciibetical sort except preserving numbers
119 const char *sa = ((bench_func_t*)a)->name;
120 const char *sb = ((bench_func_t*)b)->name;
125 if( isdigit( *sa ) && isdigit( *sb ) && isdigit( sa[1] ) != isdigit( sb[1] ) )
126 return isdigit( sa[1] ) - isdigit( sb[1] );
132 static void print_bench(void)
134 uint16_t nops[10000] = {0};
135 int nfuncs, nop_time=0;
137 for( int i = 0; i < 10000; i++ )
140 nops[i] = read_time() - t;
142 qsort( nops, 10000, sizeof(uint16_t), cmp_nop );
143 for( int i = 500; i < 9500; i++ )
146 printf( "nop: %d\n", nop_time );
148 for( nfuncs = 0; nfuncs < MAX_FUNCS && benchs[nfuncs].name; nfuncs++ );
149 qsort( benchs, nfuncs, sizeof(bench_func_t), cmp_bench );
150 for( int i = 0; i < nfuncs; i++ )
151 for( int j = 0; j < MAX_CPUS && (!j || benchs[i].vers[j].cpu); j++ )
154 bench_t *b = &benchs[i].vers[j];
157 for( k = 0; k < j && benchs[i].vers[k].pointer != b->pointer; k++ );
160 printf( "%s_%s%s: %"PRId64"\n", benchs[i].name,
161 b->cpu&X264_CPU_SSE4 ? "sse4" :
162 b->cpu&X264_CPU_SHUFFLE_IS_FAST ? "fastshuffle" :
163 b->cpu&X264_CPU_SSSE3 ? "ssse3" :
164 b->cpu&X264_CPU_SSE3 ? "sse3" :
165 /* print sse2slow only if there's also a sse2fast version of the same func */
166 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" :
167 b->cpu&X264_CPU_SSE2 ? "sse2" :
168 b->cpu&X264_CPU_MMX ? "mmx" :
169 b->cpu&X264_CPU_ALTIVEC ? "altivec" :
170 b->cpu&X264_CPU_NEON ? "neon" :
171 b->cpu&X264_CPU_ARMV6 ? "armv6" : "c",
172 b->cpu&X264_CPU_CACHELINE_32 ? "_c32" :
173 b->cpu&X264_CPU_CACHELINE_64 ? "_c64" :
174 b->cpu&X264_CPU_SSE_MISALIGN ? "_misalign" :
175 b->cpu&X264_CPU_LZCNT ? "_lzcnt" :
176 b->cpu&X264_CPU_FAST_NEON_MRC ? "_fast_mrc" : "",
177 ((int64_t)10*b->cycles/b->den - nop_time)/4 );
181 #if defined(ARCH_X86) || defined(ARCH_X86_64)
182 int x264_stack_pagealign( int (*func)(), int align );
184 #define x264_stack_pagealign( func, align ) func()
187 #define call_c1(func,...) func(__VA_ARGS__)
189 #if defined(ARCH_X86) || defined(_WIN64)
190 /* detect when callee-saved regs aren't saved.
191 * needs an explicit asm check because it only sometimes crashes in normal use. */
192 intptr_t x264_checkasm_call( intptr_t (*func)(), int *ok, ... );
193 #define call_a1(func,...) x264_checkasm_call((intptr_t(*)())func, &ok, __VA_ARGS__)
195 #define call_a1 call_c1
198 #define call_bench(func,cpu,...)\
199 if( do_bench && !strncmp(func_name, bench_pattern, bench_pattern_len) )\
203 call_a1(func, __VA_ARGS__);\
204 for( int ti = 0; ti < (cpu?BENCH_RUNS:BENCH_RUNS/4); ti++ )\
206 uint32_t t = read_time();\
211 t = read_time() - t;\
212 if( t*tcount <= tsum*4 && ti > 0 )\
218 bench_t *b = get_bench( func_name, cpu );\
224 /* for most functions, run benchmark and correctness test at the same time.
225 * for those that modify their inputs, run the above macros separately */
226 #define call_a(func,...) ({ call_a2(func,__VA_ARGS__); call_a1(func,__VA_ARGS__); })
227 #define call_c(func,...) ({ call_c2(func,__VA_ARGS__); call_c1(func,__VA_ARGS__); })
228 #define call_a2(func,...) ({ call_bench(func,cpu_new,__VA_ARGS__); })
229 #define call_c2(func,...) ({ call_bench(func,0,__VA_ARGS__); })
232 static int check_pixel( int cpu_ref, int cpu_new )
234 x264_pixel_function_t pixel_c;
235 x264_pixel_function_t pixel_ref;
236 x264_pixel_function_t pixel_asm;
237 x264_predict_t predict_16x16[4+3];
238 x264_predict_t predict_8x8c[4+3];
239 x264_predict_t predict_4x4[9+3];
240 x264_predict8x8_t predict_8x8[9+3];
241 x264_predict_8x8_filter_t predict_8x8_filter;
242 ALIGNED_16( uint8_t edge[33] );
243 uint16_t cost_mv[32];
244 int ret = 0, ok, used_asm;
246 x264_pixel_init( 0, &pixel_c );
247 x264_pixel_init( cpu_ref, &pixel_ref );
248 x264_pixel_init( cpu_new, &pixel_asm );
249 x264_predict_16x16_init( 0, predict_16x16 );
250 x264_predict_8x8c_init( 0, predict_8x8c );
251 x264_predict_8x8_init( 0, predict_8x8, &predict_8x8_filter );
252 x264_predict_4x4_init( 0, predict_4x4 );
253 predict_8x8_filter( buf2+40, edge, ALL_NEIGHBORS, ALL_NEIGHBORS );
256 for( int i = 0; i < 256; i++ )
261 buf3[i] = ~(buf4[i] = -(z&1));
263 // random pattern made of maxed pixel differences, in case an intermediate value overflows
264 for( int i = 256; i < 0x1000; i++ )
265 buf3[i] = ~(buf4[i] = -(buf1[i&~0x88]&1));
267 #define TEST_PIXEL( name, align ) \
268 ok = 1, used_asm = 0;\
269 for( int i = 0; i < 7; i++ ) \
271 int res_c, res_asm; \
272 if( pixel_asm.name[i] != pixel_ref.name[i] ) \
274 set_func_name( "%s_%s", #name, pixel_names[i] ); \
276 for( int j = 0; j < 64; j++ ) \
278 res_c = call_c( pixel_c.name[i], buf1, 16, buf2+j*!align, 64 ); \
279 res_asm = call_a( pixel_asm.name[i], buf1, 16, buf2+j*!align, 64 ); \
280 if( res_c != res_asm ) \
283 fprintf( stderr, #name "[%d]: %d != %d [FAILED]\n", i, res_c, res_asm ); \
287 for( int j = 0; j < 0x1000 && ok; j += 256 ) \
289 res_c = pixel_c .name[i]( buf3+j, 16, buf4+j, 16 ); \
290 res_asm = pixel_asm.name[i]( buf3+j, 16, buf4+j, 16 ); \
291 if( res_c != res_asm ) \
294 fprintf( stderr, #name "[%d]: overflow %d != %d\n", i, res_c, res_asm ); \
299 report( "pixel " #name " :" );
301 TEST_PIXEL( sad, 0 );
302 TEST_PIXEL( sad_aligned, 1 );
303 TEST_PIXEL( ssd, 1 );
304 TEST_PIXEL( satd, 0 );
305 TEST_PIXEL( sa8d, 1 );
307 #define TEST_PIXEL_X( N ) \
308 ok = 1; used_asm = 0;\
309 for( int i = 0; i < 7; i++ ) \
311 int res_c[4]={0}, res_asm[4]={0}; \
312 if( pixel_asm.sad_x##N[i] && pixel_asm.sad_x##N[i] != pixel_ref.sad_x##N[i] ) \
314 set_func_name( "sad_x%d_%s", N, pixel_names[i] ); \
316 for( int j = 0; j < 64; j++ ) \
318 uint8_t *pix2 = buf2+j; \
319 res_c[0] = pixel_c.sad[i]( buf1, 16, pix2, 64 ); \
320 res_c[1] = pixel_c.sad[i]( buf1, 16, pix2+6, 64 ); \
321 res_c[2] = pixel_c.sad[i]( buf1, 16, pix2+1, 64 ); \
324 res_c[3] = pixel_c.sad[i]( buf1, 16, pix2+10, 64 ); \
325 call_a( pixel_asm.sad_x4[i], buf1, pix2, pix2+6, pix2+1, pix2+10, 64, res_asm ); \
328 call_a( pixel_asm.sad_x3[i], buf1, pix2, pix2+6, pix2+1, 64, res_asm ); \
329 if( memcmp(res_c, res_asm, sizeof(res_c)) ) \
332 fprintf( stderr, "sad_x"#N"[%d]: %d,%d,%d,%d != %d,%d,%d,%d [FAILED]\n", \
333 i, res_c[0], res_c[1], res_c[2], res_c[3], \
334 res_asm[0], res_asm[1], res_asm[2], res_asm[3] ); \
337 call_c2( pixel_c.sad_x4[i], buf1, pix2, pix2+6, pix2+1, pix2+10, 64, res_asm ); \
339 call_c2( pixel_c.sad_x3[i], buf1, pix2, pix2+6, pix2+1, 64, res_asm ); \
343 report( "pixel sad_x"#N" :" );
348 #define TEST_PIXEL_VAR( i ) \
349 if( pixel_asm.var[i] != pixel_ref.var[i] ) \
351 set_func_name( "%s_%s", "var", pixel_names[i] ); \
353 /* abi-check wrapper can't return uint64_t, so separate it from return value check */\
354 call_c1( pixel_c.var[i], buf1, 16 ); \
355 call_a1( pixel_asm.var[i], buf1, 16 ); \
356 uint64_t res_c = pixel_c.var[i]( buf1, 16 ); \
357 uint64_t res_asm = pixel_asm.var[i]( buf1, 16 ); \
358 if( res_c != res_asm ) \
361 fprintf( stderr, "var[%d]: %d %d != %d %d [FAILED]\n", i, (int)res_c, (int)(res_c>>32), (int)res_asm, (int)(res_asm>>32) ); \
363 call_c2( pixel_c.var[i], buf1, 16 ); \
364 call_a2( pixel_asm.var[i], buf1, 16 ); \
367 ok = 1; used_asm = 0;
368 TEST_PIXEL_VAR( PIXEL_16x16 );
369 TEST_PIXEL_VAR( PIXEL_8x8 );
370 report( "pixel var :" );
372 ok = 1; used_asm = 0;
373 if( pixel_asm.var2_8x8 != pixel_ref.var2_8x8 )
375 int res_c, res_asm, ssd_c, ssd_asm;
376 set_func_name( "var2_8x8" );
378 res_c = call_c( pixel_c.var2_8x8, buf1, 16, buf2, 16, &ssd_c );
379 res_asm = call_a( pixel_asm.var2_8x8, buf1, 16, buf2, 16, &ssd_asm );
380 if( res_c != res_asm || ssd_c != ssd_asm )
383 fprintf( stderr, "var2_8x8: %d != %d or %d != %d [FAILED]\n", res_c, res_asm, ssd_c, ssd_asm );
387 report( "pixel var2 :" );
389 ok = 1; used_asm = 0;
390 for( int i = 0; i < 4; i++ )
391 if( pixel_asm.hadamard_ac[i] != pixel_ref.hadamard_ac[i] )
393 set_func_name( "hadamard_ac_%s", pixel_names[i] );
395 for( int j = 0; j < 32; j++ )
397 uint8_t *pix = (j&16 ? buf1 : buf3) + (j&15)*256;
398 call_c1( pixel_c.hadamard_ac[i], buf1, 16 );
399 call_a1( pixel_asm.hadamard_ac[i], buf1, 16 );
400 uint64_t rc = pixel_c.hadamard_ac[i]( pix, 16 );
401 uint64_t ra = pixel_asm.hadamard_ac[i]( pix, 16 );
405 fprintf( stderr, "hadamard_ac[%d]: %d,%d != %d,%d\n", i, (int)rc, (int)(rc>>32), (int)ra, (int)(ra>>32) );
409 call_c2( pixel_c.hadamard_ac[i], buf1, 16 );
410 call_a2( pixel_asm.hadamard_ac[i], buf1, 16 );
412 report( "pixel hadamard_ac :" );
414 #define TEST_INTRA_MBCMP( name, pred, satd, i8x8, ... ) \
415 if( pixel_asm.name && pixel_asm.name != pixel_ref.name ) \
417 int res_c[3], res_asm[3]; \
418 set_func_name( #name );\
420 memcpy( buf3, buf2, 1024 ); \
421 for( int i = 0; i < 3; i++ ) \
423 pred[i]( buf3+48, ##__VA_ARGS__ ); \
424 res_c[i] = pixel_c.satd( buf1+48, 16, buf3+48, 32 ); \
426 call_a( pixel_asm.name, buf1+48, i8x8 ? edge : buf3+48, res_asm ); \
427 if( memcmp(res_c, res_asm, sizeof(res_c)) ) \
430 fprintf( stderr, #name": %d,%d,%d != %d,%d,%d [FAILED]\n", \
431 res_c[0], res_c[1], res_c[2], \
432 res_asm[0], res_asm[1], res_asm[2] ); \
436 ok = 1; used_asm = 0;
437 TEST_INTRA_MBCMP( intra_satd_x3_16x16, predict_16x16, satd[PIXEL_16x16], 0 );
438 TEST_INTRA_MBCMP( intra_satd_x3_8x8c , predict_8x8c , satd[PIXEL_8x8] , 0 );
439 TEST_INTRA_MBCMP( intra_satd_x3_4x4 , predict_4x4 , satd[PIXEL_4x4] , 0 );
440 TEST_INTRA_MBCMP( intra_sa8d_x3_8x8 , predict_8x8 , sa8d[PIXEL_8x8] , 1, edge );
441 report( "intra satd_x3 :" );
442 TEST_INTRA_MBCMP( intra_sad_x3_16x16 , predict_16x16, sad [PIXEL_16x16], 0 );
443 TEST_INTRA_MBCMP( intra_sad_x3_8x8c , predict_8x8c , sad [PIXEL_8x8] , 0 );
444 TEST_INTRA_MBCMP( intra_sad_x3_8x8 , predict_8x8 , sad [PIXEL_8x8] , 1, edge );
445 TEST_INTRA_MBCMP( intra_sad_x3_4x4 , predict_4x4 , sad [PIXEL_4x4] , 0 );
446 report( "intra sad_x3 :" );
448 if( pixel_asm.ssim_4x4x2_core != pixel_ref.ssim_4x4x2_core ||
449 pixel_asm.ssim_end4 != pixel_ref.ssim_end4 )
452 ALIGNED_16( int sums[5][4] ) = {{0}};
455 res_c = x264_pixel_ssim_wxh( &pixel_c, buf1+2, 32, buf2+2, 32, 32, 28, buf3 );
456 res_a = x264_pixel_ssim_wxh( &pixel_asm, buf1+2, 32, buf2+2, 32, 32, 28, buf3 );
457 if( fabs( res_c - res_a ) > 1e-6 )
460 fprintf( stderr, "ssim: %.7f != %.7f [FAILED]\n", res_c, res_a );
462 set_func_name( "ssim_core" );
463 call_c2( pixel_c.ssim_4x4x2_core, buf1+2, 32, buf2+2, 32, sums );
464 call_a2( pixel_asm.ssim_4x4x2_core, buf1+2, 32, buf2+2, 32, sums );
465 set_func_name( "ssim_end" );
466 call_c2( pixel_c.ssim_end4, sums, sums, 4 );
467 call_a2( pixel_asm.ssim_end4, sums, sums, 4 );
471 ok = 1; used_asm = 0;
472 for( int i = 0; i < 32; i++ )
474 for( int i = 0; i < 100 && ok; i++ )
475 if( pixel_asm.ads[i&3] != pixel_ref.ads[i&3] )
477 ALIGNED_16( uint16_t sums[72] );
478 ALIGNED_16( int dc[4] );
479 int16_t mvs_a[32], mvs_c[32];
481 int thresh = rand() & 0x3fff;
482 set_func_name( "esa_ads" );
483 for( int j = 0; j < 72; j++ )
484 sums[j] = rand() & 0x3fff;
485 for( int j = 0; j < 4; j++ )
486 dc[j] = rand() & 0x3fff;
488 mvn_c = call_c( pixel_c.ads[i&3], dc, sums, 32, cost_mv, mvs_c, 28, thresh );
489 mvn_a = call_a( pixel_asm.ads[i&3], dc, sums, 32, cost_mv, mvs_a, 28, thresh );
490 if( mvn_c != mvn_a || memcmp( mvs_c, mvs_a, mvn_c*sizeof(*mvs_c) ) )
493 printf( "c%d: ", i&3 );
494 for( int j = 0; j < mvn_c; j++ )
495 printf( "%d ", mvs_c[j] );
496 printf( "\na%d: ", i&3 );
497 for( int j = 0; j < mvn_a; j++ )
498 printf( "%d ", mvs_a[j] );
502 report( "esa ads:" );
507 static int check_dct( int cpu_ref, int cpu_new )
509 x264_dct_function_t dct_c;
510 x264_dct_function_t dct_ref;
511 x264_dct_function_t dct_asm;
512 x264_quant_function_t qf;
513 int ret = 0, ok, used_asm, interlace;
514 ALIGNED_16( int16_t dct1[16][16] );
515 ALIGNED_16( int16_t dct2[16][16] );
516 ALIGNED_16( int16_t dct4[16][16] );
517 ALIGNED_16( int16_t dct8[4][64] );
518 ALIGNED_8( int16_t dctdc[2][4] );
522 x264_dct_init( 0, &dct_c );
523 x264_dct_init( cpu_ref, &dct_ref);
524 x264_dct_init( cpu_new, &dct_asm );
526 memset( h, 0, sizeof(*h) );
527 h->pps = h->pps_array;
528 x264_param_default( &h->param );
529 h->chroma_qp_table = i_chroma_qp_table + 12;
530 h->param.analyse.i_luma_deadzone[0] = 0;
531 h->param.analyse.i_luma_deadzone[1] = 0;
532 h->param.analyse.b_transform_8x8 = 1;
533 for( int i = 0; i < 6; i++ )
534 h->pps->scaling_list[i] = x264_cqm_flat16;
536 x264_quant_init( h, 0, &qf );
538 #define TEST_DCT( name, t1, t2, size ) \
539 if( dct_asm.name != dct_ref.name ) \
541 set_func_name( #name );\
543 call_c( dct_c.name, t1, buf1, buf2 ); \
544 call_a( dct_asm.name, t2, buf1, buf2 ); \
545 if( memcmp( t1, t2, size ) ) \
548 fprintf( stderr, #name " [FAILED]\n" ); \
551 ok = 1; used_asm = 0;
552 TEST_DCT( sub4x4_dct, dct1[0], dct2[0], 16*2 );
553 TEST_DCT( sub8x8_dct, dct1, dct2, 16*2*4 );
554 TEST_DCT( sub8x8_dct_dc, dctdc[0], dctdc[1], 4*2 );
555 TEST_DCT( sub16x16_dct, dct1, dct2, 16*2*16 );
556 report( "sub_dct4 :" );
558 ok = 1; used_asm = 0;
559 TEST_DCT( sub8x8_dct8, (void*)dct1[0], (void*)dct2[0], 64*2 );
560 TEST_DCT( sub16x16_dct8, (void*)dct1, (void*)dct2, 64*2*4 );
561 report( "sub_dct8 :" );
564 // fdct and idct are denormalized by different factors, so quant/dequant
565 // is needed to force the coefs into the right range.
566 dct_c.sub16x16_dct( dct4, buf1, buf2 );
567 dct_c.sub16x16_dct8( dct8, buf1, buf2 );
568 for( int i = 0; i < 16; i++ )
570 qf.quant_4x4( dct4[i], h->quant4_mf[CQM_4IY][20], h->quant4_bias[CQM_4IY][20] );
571 qf.dequant_4x4( dct4[i], h->dequant4_mf[CQM_4IY], 20 );
573 for( int i = 0; i < 4; i++ )
575 qf.quant_8x8( dct8[i], h->quant8_mf[CQM_8IY][20], h->quant8_bias[CQM_8IY][20] );
576 qf.dequant_8x8( dct8[i], h->dequant8_mf[CQM_8IY], 20 );
579 #define TEST_IDCT( name, src ) \
580 if( dct_asm.name != dct_ref.name ) \
582 set_func_name( #name );\
584 memcpy( buf3, buf1, 32*32 ); \
585 memcpy( buf4, buf1, 32*32 ); \
586 memcpy( dct1, src, 512 ); \
587 memcpy( dct2, src, 512 ); \
588 call_c1( dct_c.name, buf3, (void*)dct1 ); \
589 call_a1( dct_asm.name, buf4, (void*)dct2 ); \
590 if( memcmp( buf3, buf4, 32*32 ) ) \
593 fprintf( stderr, #name " [FAILED]\n" ); \
595 call_c2( dct_c.name, buf3, (void*)dct1 ); \
596 call_a2( dct_asm.name, buf4, (void*)dct2 ); \
598 ok = 1; used_asm = 0;
599 TEST_IDCT( add4x4_idct, dct4 );
600 TEST_IDCT( add8x8_idct, dct4 );
601 TEST_IDCT( add8x8_idct_dc, dct4 );
602 TEST_IDCT( add16x16_idct, dct4 );
603 TEST_IDCT( add16x16_idct_dc, dct4 );
604 report( "add_idct4 :" );
606 ok = 1; used_asm = 0;
607 TEST_IDCT( add8x8_idct8, dct8 );
608 TEST_IDCT( add16x16_idct8, dct8 );
609 report( "add_idct8 :" );
612 #define TEST_DCTDC( name )\
613 ok = 1; used_asm = 0;\
614 if( dct_asm.name != dct_ref.name )\
616 set_func_name( #name );\
618 uint16_t *p = (uint16_t*)buf1;\
619 for( int i = 0; i < 16 && ok; i++ )\
621 for( int j = 0; j < 16; j++ )\
622 dct1[0][j] = !i ? (j^j>>1^j>>2^j>>3)&1 ? 4080 : -4080 /* max dc */\
623 : i<8 ? (*p++)&1 ? 4080 : -4080 /* max elements */\
624 : ((*p++)&0x1fff)-0x1000; /* general case */\
625 memcpy( dct2, dct1, 32 );\
626 call_c1( dct_c.name, dct1[0] );\
627 call_a1( dct_asm.name, dct2[0] );\
628 if( memcmp( dct1, dct2, 32 ) )\
631 call_c2( dct_c.name, dct1[0] );\
632 call_a2( dct_asm.name, dct2[0] );\
634 report( #name " :" );
636 TEST_DCTDC( dct4x4dc );
637 TEST_DCTDC( idct4x4dc );
640 x264_zigzag_function_t zigzag_c;
641 x264_zigzag_function_t zigzag_ref;
642 x264_zigzag_function_t zigzag_asm;
644 ALIGNED_16( int16_t level1[64] );
645 ALIGNED_16( int16_t level2[64] );
647 #define TEST_ZIGZAG_SCAN( name, t1, t2, dct, size ) \
648 if( zigzag_asm.name != zigzag_ref.name ) \
650 set_func_name( "zigzag_"#name"_%s", interlace?"field":"frame" );\
652 memcpy(dct, buf1, size*sizeof(int16_t));\
653 call_c( zigzag_c.name, t1, dct ); \
654 call_a( zigzag_asm.name, t2, dct ); \
655 if( memcmp( t1, t2, size*sizeof(int16_t) ) ) \
658 fprintf( stderr, #name " [FAILED]\n" ); \
662 #define TEST_ZIGZAG_SUB( name, t1, t2, size ) \
663 if( zigzag_asm.name != zigzag_ref.name ) \
666 set_func_name( "zigzag_"#name"_%s", interlace?"field":"frame" );\
668 memcpy( buf3, buf1, 16*FDEC_STRIDE ); \
669 memcpy( buf4, buf1, 16*FDEC_STRIDE ); \
670 nz_c = call_c1( zigzag_c.name, t1, buf2, buf3 ); \
671 nz_a = call_a1( zigzag_asm.name, t2, buf2, buf4 ); \
672 if( memcmp( t1, t2, size*sizeof(int16_t) )|| memcmp( buf3, buf4, 16*FDEC_STRIDE ) || nz_c != nz_a ) \
675 fprintf( stderr, #name " [FAILED]\n" ); \
677 call_c2( zigzag_c.name, t1, buf2, buf3 ); \
678 call_a2( zigzag_asm.name, t2, buf2, buf4 ); \
681 #define TEST_ZIGZAG_SUBAC( name, t1, t2 ) \
682 if( zigzag_asm.name != zigzag_ref.name ) \
685 int16_t dc_a, dc_c; \
686 set_func_name( "zigzag_"#name"_%s", interlace?"field":"frame" );\
688 for( int i = 0; i < 2; i++ ) \
690 memcpy( buf3, buf2, 16*FDEC_STRIDE ); \
691 memcpy( buf4, buf2, 16*FDEC_STRIDE ); \
692 for( int j = 0; j < 4; j++ ) \
694 memcpy( buf3 + j*FDEC_STRIDE, (i?buf1:buf2) + j*FENC_STRIDE, 4 ); \
695 memcpy( buf4 + j*FDEC_STRIDE, (i?buf1:buf2) + j*FENC_STRIDE, 4 ); \
697 nz_c = call_c1( zigzag_c.name, t1, buf2, buf3, &dc_c ); \
698 nz_a = call_a1( zigzag_asm.name, t2, buf2, buf4, &dc_a ); \
699 if( memcmp( t1+1, t2+1, 15*sizeof(int16_t) ) || memcmp( buf3, buf4, 16*FDEC_STRIDE ) || nz_c != nz_a || dc_c != dc_a ) \
702 fprintf( stderr, #name " [FAILED]\n" ); \
706 call_c2( zigzag_c.name, t1, buf2, buf3, &dc_c ); \
707 call_a2( zigzag_asm.name, t2, buf2, buf4, &dc_a ); \
710 #define TEST_INTERLEAVE( name, t1, t2, dct, size ) \
711 if( zigzag_asm.name != zigzag_ref.name ) \
713 for( int j = 0; j < 100; j++ ) \
715 set_func_name( "zigzag_"#name"_%s", interlace?"field":"frame" );\
717 memcpy(dct, buf1, size*sizeof(int16_t));\
718 for( int i = 0; i < size; i++ ) \
719 dct[i] = rand()&0x1F ? 0 : dct[i]; \
720 memcpy(buf3, buf4, 10*sizeof(uint8_t)); \
721 call_c( zigzag_c.name, t1, dct, buf3 ); \
722 call_a( zigzag_asm.name, t2, dct, buf4 ); \
723 if( memcmp( t1, t2, size*sizeof(int16_t) ) || memcmp( buf3, buf4, 10*sizeof(uint8_t) ) ) \
731 x264_zigzag_init( 0, &zigzag_c, 0 );
732 x264_zigzag_init( cpu_ref, &zigzag_ref, 0 );
733 x264_zigzag_init( cpu_new, &zigzag_asm, 0 );
735 ok = 1; used_asm = 0;
736 TEST_ZIGZAG_SCAN( scan_8x8, level1, level2, (void*)dct1, 64 );
737 TEST_ZIGZAG_SCAN( scan_4x4, level1, level2, dct1[0], 16 );
738 TEST_ZIGZAG_SUB( sub_4x4, level1, level2, 16 );
739 TEST_ZIGZAG_SUBAC( sub_4x4ac, level1, level2 );
740 report( "zigzag_frame :" );
743 x264_zigzag_init( 0, &zigzag_c, 1 );
744 x264_zigzag_init( cpu_ref, &zigzag_ref, 1 );
745 x264_zigzag_init( cpu_new, &zigzag_asm, 1 );
747 ok = 1; used_asm = 0;
748 TEST_ZIGZAG_SCAN( scan_8x8, level1, level2, (void*)dct1, 64 );
749 TEST_ZIGZAG_SCAN( scan_4x4, level1, level2, dct1[0], 16 );
750 TEST_ZIGZAG_SUB( sub_4x4, level1, level2, 16 );
751 TEST_ZIGZAG_SUBAC( sub_4x4ac, level1, level2 );
752 report( "zigzag_field :" );
754 ok = 1; used_asm = 0;
755 TEST_INTERLEAVE( interleave_8x8_cavlc, level1, level2, dct1[0], 64 );
756 report( "zigzag_interleave :" );
757 #undef TEST_ZIGZAG_SCAN
758 #undef TEST_ZIGZAG_SUB
763 static int check_mc( int cpu_ref, int cpu_new )
765 x264_mc_functions_t mc_c;
766 x264_mc_functions_t mc_ref;
767 x264_mc_functions_t mc_a;
768 x264_pixel_function_t pixel;
770 uint8_t *src = &buf1[2*64+2];
771 uint8_t *src2[4] = { &buf1[3*64+2], &buf1[5*64+2],
772 &buf1[7*64+2], &buf1[9*64+2] };
773 uint8_t *dst1 = buf3;
774 uint8_t *dst2 = buf4;
776 int ret = 0, ok, used_asm;
778 x264_mc_init( 0, &mc_c );
779 x264_mc_init( cpu_ref, &mc_ref );
780 x264_mc_init( cpu_new, &mc_a );
781 x264_pixel_init( 0, &pixel );
783 #define MC_TEST_LUMA( w, h ) \
784 if( mc_a.mc_luma != mc_ref.mc_luma && !(w&(w-1)) && h<=16 ) \
786 const x264_weight_t *weight = weight_none; \
787 set_func_name( "mc_luma_%dx%d", w, h );\
789 memset( buf3, 0xCD, 1024 ); \
790 memset( buf4, 0xCD, 1024 ); \
791 call_c( mc_c.mc_luma, dst1, 32, src2, 64, dx, dy, w, h, weight ); \
792 call_a( mc_a.mc_luma, dst2, 32, src2, 64, dx, dy, w, h, weight ); \
793 if( memcmp( buf3, buf4, 1024 ) ) \
795 fprintf( stderr, "mc_luma[mv(%d,%d) %2dx%-2d] [FAILED]\n", dx, dy, w, h ); \
799 if( mc_a.get_ref != mc_ref.get_ref ) \
801 uint8_t *ref = dst2; \
802 int ref_stride = 32; \
803 const x264_weight_t *weight = weight_none; \
804 set_func_name( "get_ref_%dx%d", w, h );\
806 memset( buf3, 0xCD, 1024 ); \
807 memset( buf4, 0xCD, 1024 ); \
808 call_c( mc_c.mc_luma, dst1, 32, src2, 64, dx, dy, w, h, weight ); \
809 ref = (uint8_t*) call_a( mc_a.get_ref, ref, &ref_stride, src2, 64, dx, dy, w, h, weight ); \
810 for( int i = 0; i < h; i++ ) \
811 if( memcmp( dst1+i*32, ref+i*ref_stride, w ) ) \
813 fprintf( stderr, "get_ref[mv(%d,%d) %2dx%-2d] [FAILED]\n", dx, dy, w, h ); \
819 #define MC_TEST_CHROMA( w, h ) \
820 if( mc_a.mc_chroma != mc_ref.mc_chroma ) \
822 set_func_name( "mc_chroma_%dx%d", w, h );\
824 memset( buf3, 0xCD, 1024 ); \
825 memset( buf4, 0xCD, 1024 ); \
826 call_c( mc_c.mc_chroma, dst1, 16, src, 64, dx, dy, w, h ); \
827 call_a( mc_a.mc_chroma, dst2, 16, src, 64, dx, dy, w, h ); \
828 /* mc_chroma width=2 may write garbage to the right of dst. ignore that. */\
829 for( int j = 0; j < h; j++ ) \
830 for( int i = w; i < 4; i++ ) \
831 dst2[i+j*16] = dst1[i+j*16]; \
832 if( memcmp( buf3, buf4, 1024 ) ) \
834 fprintf( stderr, "mc_chroma[mv(%d,%d) %2dx%-2d] [FAILED]\n", dx, dy, w, h ); \
838 ok = 1; used_asm = 0;
839 for( int dy = -8; dy < 8; dy++ )
840 for( int dx = -128; dx < 128; dx++ )
842 if( rand()&15 ) continue; // running all of them is too slow
843 MC_TEST_LUMA( 20, 18 );
844 MC_TEST_LUMA( 16, 16 );
845 MC_TEST_LUMA( 16, 8 );
846 MC_TEST_LUMA( 12, 10 );
847 MC_TEST_LUMA( 8, 16 );
848 MC_TEST_LUMA( 8, 8 );
849 MC_TEST_LUMA( 8, 4 );
850 MC_TEST_LUMA( 4, 8 );
851 MC_TEST_LUMA( 4, 4 );
853 report( "mc luma :" );
855 ok = 1; used_asm = 0;
856 for( int dy = -1; dy < 9; dy++ )
857 for( int dx = -128; dx < 128; dx++ )
859 if( rand()&15 ) continue;
860 MC_TEST_CHROMA( 8, 8 );
861 MC_TEST_CHROMA( 8, 4 );
862 MC_TEST_CHROMA( 4, 8 );
863 MC_TEST_CHROMA( 4, 4 );
864 MC_TEST_CHROMA( 4, 2 );
865 MC_TEST_CHROMA( 2, 4 );
866 MC_TEST_CHROMA( 2, 2 );
868 report( "mc chroma :" );
870 #undef MC_TEST_CHROMA
872 #define MC_TEST_AVG( name, weight ) \
874 ok = 1, used_asm = 0; \
875 for( int i = 0; i < 10; i++ ) \
877 memcpy( buf3, buf1+320, 320 ); \
878 memcpy( buf4, buf1+320, 320 ); \
879 if( mc_a.name[i] != mc_ref.name[i] ) \
881 set_func_name( "%s_%s", #name, pixel_names[i] );\
883 call_c1( mc_c.name[i], buf3, 16, buf2+1, 16, buf1+18, 16, weight ); \
884 call_a1( mc_a.name[i], buf4, 16, buf2+1, 16, buf1+18, 16, weight ); \
885 if( memcmp( buf3, buf4, 320 ) ) \
888 fprintf( stderr, #name "[%d]: [FAILED]\n", i ); \
890 call_c2( mc_c.name[i], buf3, 16, buf2+1, 16, buf1+18, 16, weight ); \
891 call_a2( mc_a.name[i], buf4, 16, buf2+1, 16, buf1+18, 16, weight ); \
896 for( int w = -63; w <= 127 && ok; w++ )
897 MC_TEST_AVG( avg, w );
898 report( "mc wpredb :" );
900 #define MC_TEST_WEIGHT( name, weight, aligned ) \
901 int align_off = (aligned ? 0 : rand()%16); \
902 ok = 1, used_asm = 0;\
903 for( int i = 1; i <= 5; i++ ) \
905 ALIGNED_16( uint8_t buffC[640] ); \
906 ALIGNED_16( uint8_t buffA[640] ); \
907 int j = X264_MAX( i*4, 2 ); \
908 memset( buffC, 0, 640 ); \
909 memset( buffA, 0, 640 ); \
912 /* w12 is the same as w16 in some cases */ \
913 if( i == 3 && mc_a.name[i] == mc_a.name[i+1] ) \
915 if( mc_a.name[i] != mc_ref.name[i] ) \
917 set_func_name( "%s_w%d", #name, j ); \
919 call_c1( mc_c.weight[i], buffC, 32, buf2+align_off, 32, &weight, 16 ); \
920 mc_a.weight_cache(&ha, &weight); \
921 call_a1( weight.weightfn[i], buffA, 32, buf2+align_off, 32, &weight, 16 ); \
922 for( int k = 0; k < 16; k++ ) \
923 if( memcmp( &buffC[k*32], &buffA[k*32], j ) ) \
926 fprintf( stderr, #name "[%d]: [FAILED] s:%d o:%d d%d\n", i, s, o, d ); \
929 call_c2( mc_c.weight[i], buffC, 32, buf2+align_off, 32, &weight, 16 ); \
930 call_a2( weight.weightfn[i], buffA, 32, buf2+align_off, 32, &weight, 16 ); \
934 ok = 1; used_asm = 0;
937 for( int s = 0; s <= 127 && ok; s++ )
939 for( int o = -128; o <= 127 && ok; o++ )
941 if( rand() & 2047 ) continue;
942 for( int d = 0; d <= 7 && ok; d++ )
946 x264_weight_t weight = { .i_scale = s, .i_denom = d, .i_offset = o };
947 MC_TEST_WEIGHT( weight, weight, (align_cnt++ % 4) );
952 report( "mc weight :" );
954 ok = 1; used_asm = 0;
955 for( int o = 0; o <= 127 && ok; o++ )
958 if( rand() & 15 ) continue;
959 x264_weight_t weight = { .i_scale = 1, .i_denom = 0, .i_offset = o };
960 MC_TEST_WEIGHT( offsetadd, weight, (align_cnt++ % 4) );
962 report( "mc offsetadd :" );
963 ok = 1; used_asm = 0;
964 for( int o = -128; o < 0 && ok; o++ )
967 if( rand() & 15 ) continue;
968 x264_weight_t weight = { .i_scale = 1, .i_denom = 0, .i_offset = o };
969 MC_TEST_WEIGHT( offsetsub, weight, (align_cnt++ % 4) );
971 report( "mc offsetsub :" );
973 if( mc_a.hpel_filter != mc_ref.hpel_filter )
975 uint8_t *srchpel = buf1+8+2*64;
976 uint8_t *dstc[3] = { buf3+8, buf3+8+16*64, buf3+8+32*64 };
977 uint8_t *dsta[3] = { buf4+8, buf4+8+16*64, buf4+8+32*64 };
978 void *tmp = buf3+49*64;
979 set_func_name( "hpel_filter" );
980 ok = 1; used_asm = 1;
981 memset( buf3, 0, 4096 );
982 memset( buf4, 0, 4096 );
983 call_c( mc_c.hpel_filter, dstc[0], dstc[1], dstc[2], srchpel, 64, 48, 10, tmp );
984 call_a( mc_a.hpel_filter, dsta[0], dsta[1], dsta[2], srchpel, 64, 48, 10, tmp );
985 for( int i = 0; i < 3; i++ )
986 for( int j = 0; j < 10; j++ )
987 //FIXME ideally the first pixels would match too, but they aren't actually used
988 if( memcmp( dstc[i]+j*64+2, dsta[i]+j*64+2, 43 ) )
991 fprintf( stderr, "hpel filter differs at plane %c line %d\n", "hvc"[i], j );
992 for( int k = 0; k < 48; k++ )
993 printf( "%02x%s", dstc[i][j*64+k], (k+1)&3 ? "" : " " );
995 for( int k = 0; k < 48; k++ )
996 printf( "%02x%s", dsta[i][j*64+k], (k+1)&3 ? "" : " " );
1000 report( "hpel filter :" );
1003 if( mc_a.frame_init_lowres_core != mc_ref.frame_init_lowres_core )
1005 uint8_t *dstc[4] = { buf3, buf3+1024, buf3+2048, buf3+3072 };
1006 uint8_t *dsta[4] = { buf4, buf4+1024, buf4+2048, buf4+3072 };
1007 set_func_name( "lowres_init" );
1008 ok = 1; used_asm = 1;
1009 for( int w = 40; w <= 48; w += 8 )
1011 int stride = (w+8)&~15;
1012 call_c( mc_c.frame_init_lowres_core, buf1, dstc[0], dstc[1], dstc[2], dstc[3], w*2, stride, w, 16 );
1013 call_a( mc_a.frame_init_lowres_core, buf1, dsta[0], dsta[1], dsta[2], dsta[3], w*2, stride, w, 16 );
1014 for( int i = 0; i < 16; i++ )
1016 for( int j = 0; j < 4; j++ )
1017 if( memcmp( dstc[j]+i*stride, dsta[j]+i*stride, w ) )
1020 fprintf( stderr, "frame_init_lowres differs at plane %d line %d\n", j, i );
1021 for( int k = 0; k < w; k++ )
1022 printf( "%d ", dstc[j][k+i*stride] );
1024 for( int k = 0; k < w; k++ )
1025 printf( "%d ", dsta[j][k+i*stride] );
1031 report( "lowres init :" );
1034 #define INTEGRAL_INIT( name, size, ... )\
1035 if( mc_a.name != mc_ref.name )\
1038 set_func_name( #name );\
1040 memcpy( buf3, buf1, size*2*stride );\
1041 memcpy( buf4, buf1, size*2*stride );\
1042 uint16_t *sum = (uint16_t*)buf3;\
1043 call_c1( mc_c.name, __VA_ARGS__ );\
1044 sum = (uint16_t*)buf4;\
1045 call_a1( mc_a.name, __VA_ARGS__ );\
1046 if( memcmp( buf3, buf4, (stride-8)*2 )\
1047 || (size>9 && memcmp( buf3+18*stride, buf4+18*stride, (stride-8)*2 )))\
1049 call_c2( mc_c.name, __VA_ARGS__ );\
1050 call_a2( mc_a.name, __VA_ARGS__ );\
1052 ok = 1; used_asm = 0;
1053 INTEGRAL_INIT( integral_init4h, 2, sum+stride, buf2, stride );
1054 INTEGRAL_INIT( integral_init8h, 2, sum+stride, buf2, stride );
1055 INTEGRAL_INIT( integral_init4v, 14, sum, sum+9*stride, stride );
1056 INTEGRAL_INIT( integral_init8v, 9, sum, stride );
1057 report( "integral init :" );
1059 if( mc_a.mbtree_propagate_cost != mc_ref.mbtree_propagate_cost )
1061 ok = 1; used_asm = 1;
1062 set_func_name( "mbtree_propagate" );
1063 int *dsta = (int*)buf3;
1064 int *dstc = dsta+400;
1065 uint16_t *prop = (uint16_t*)buf1;
1066 uint16_t *intra = (uint16_t*)buf4;
1067 uint16_t *inter = intra+400;
1068 uint16_t *qscale = inter+400;
1069 uint16_t *rnd = (uint16_t*)buf2;
1071 for( int i = 0; i < 400; i++ )
1073 intra[i] = *rnd++ & 0x7fff;
1074 intra[i] += !intra[i];
1075 inter[i] = *rnd++ & 0x7fff;
1076 qscale[i] = *rnd++ & 0x7fff;
1078 call_c( mc_c.mbtree_propagate_cost, dstc, prop, intra, inter, qscale, 400 );
1079 call_a( mc_a.mbtree_propagate_cost, dsta, prop, intra, inter, qscale, 400 );
1080 // I don't care about exact rounding, this is just how close the floating-point implementation happens to be
1082 for( int i = 0; i < 400; i++ )
1083 ok &= abs( dstc[i]-dsta[i] ) <= (abs( dstc[i])>512 ) || fabs( (double)dstc[i]/dsta[i]-1 ) < 1e-6;
1084 report( "mbtree propagate :" );
1090 static int check_deblock( int cpu_ref, int cpu_new )
1092 x264_deblock_function_t db_c;
1093 x264_deblock_function_t db_ref;
1094 x264_deblock_function_t db_a;
1095 int ret = 0, ok = 1, used_asm = 0;
1096 int alphas[36], betas[36];
1099 x264_deblock_init( 0, &db_c );
1100 x264_deblock_init( cpu_ref, &db_ref );
1101 x264_deblock_init( cpu_new, &db_a );
1103 /* not exactly the real values of a,b,tc but close enough */
1104 for( int i = 35; i >= 0; i-- )
1106 int a = 255, c = 250;
1109 tcs[i][0] = tcs[i][2] = (c+6)/10;
1110 tcs[i][1] = tcs[i][3] = (c+9)/20;
1115 #define TEST_DEBLOCK( name, align, ... ) \
1116 for( int i = 0; i < 36; i++ ) \
1118 int off = 8*32 + (i&15)*4*!align; /* benchmark various alignments of h filter */\
1119 for( int j = 0; j < 1024; j++ ) \
1120 /* two distributions of random to excersize different failure modes */\
1121 buf3[j] = rand() & (i&1 ? 0xf : 0xff ); \
1122 memcpy( buf4, buf3, 1024 ); \
1123 if( db_a.name != db_ref.name ) \
1125 set_func_name( #name );\
1127 call_c1( db_c.name, buf3+off, 32, alphas[i], betas[i], ##__VA_ARGS__ ); \
1128 call_a1( db_a.name, buf4+off, 32, alphas[i], betas[i], ##__VA_ARGS__ ); \
1129 if( memcmp( buf3, buf4, 1024 ) ) \
1132 fprintf( stderr, #name "(a=%d, b=%d): [FAILED]\n", alphas[i], betas[i] ); \
1135 call_c2( db_c.name, buf3+off, 32, alphas[i], betas[i], ##__VA_ARGS__ ); \
1136 call_a2( db_a.name, buf4+off, 32, alphas[i], betas[i], ##__VA_ARGS__ ); \
1140 TEST_DEBLOCK( deblock_h_luma, 0, tcs[i] );
1141 TEST_DEBLOCK( deblock_v_luma, 1, tcs[i] );
1142 TEST_DEBLOCK( deblock_h_chroma, 0, tcs[i] );
1143 TEST_DEBLOCK( deblock_v_chroma, 1, tcs[i] );
1144 TEST_DEBLOCK( deblock_h_luma_intra, 0 );
1145 TEST_DEBLOCK( deblock_v_luma_intra, 1 );
1146 TEST_DEBLOCK( deblock_h_chroma_intra, 0 );
1147 TEST_DEBLOCK( deblock_v_chroma_intra, 1 );
1149 report( "deblock :" );
1154 static int check_quant( int cpu_ref, int cpu_new )
1156 x264_quant_function_t qf_c;
1157 x264_quant_function_t qf_ref;
1158 x264_quant_function_t qf_a;
1159 ALIGNED_16( int16_t dct1[64] );
1160 ALIGNED_16( int16_t dct2[64] );
1161 ALIGNED_16( uint8_t cqm_buf[64] );
1162 int ret = 0, ok, used_asm;
1163 int oks[2] = {1,1}, used_asms[2] = {0,0};
1166 memset( h, 0, sizeof(*h) );
1167 h->pps = h->pps_array;
1168 x264_param_default( &h->param );
1169 h->chroma_qp_table = i_chroma_qp_table + 12;
1170 h->param.rc.i_qp_min = 26;
1171 h->param.analyse.b_transform_8x8 = 1;
1173 for( int i_cqm = 0; i_cqm < 4; i_cqm++ )
1177 for( int i = 0; i < 6; i++ )
1178 h->pps->scaling_list[i] = x264_cqm_flat16;
1179 h->param.i_cqm_preset = h->pps->i_cqm_preset = X264_CQM_FLAT;
1181 else if( i_cqm == 1 )
1183 for( int i = 0; i < 6; i++ )
1184 h->pps->scaling_list[i] = x264_cqm_jvt[i];
1185 h->param.i_cqm_preset = h->pps->i_cqm_preset = X264_CQM_JVT;
1190 for( int i = 0; i < 64; i++ )
1191 cqm_buf[i] = 10 + rand() % 246;
1193 for( int i = 0; i < 64; i++ )
1195 for( int i = 0; i < 6; i++ )
1196 h->pps->scaling_list[i] = cqm_buf;
1197 h->param.i_cqm_preset = h->pps->i_cqm_preset = X264_CQM_CUSTOM;
1201 x264_quant_init( h, 0, &qf_c );
1202 x264_quant_init( h, cpu_ref, &qf_ref );
1203 x264_quant_init( h, cpu_new, &qf_a );
1205 #define INIT_QUANT8(j) \
1207 static const int scale1d[8] = {32,31,24,31,32,31,24,31}; \
1208 for( int i = 0; i < 64; i++ ) \
1210 unsigned int scale = (255*scale1d[i>>3]*scale1d[i&7])/16; \
1211 dct1[i] = dct2[i] = j ? (rand()%(2*scale+1))-scale : 0; \
1215 #define INIT_QUANT4(j) \
1217 static const int scale1d[4] = {4,6,4,6}; \
1218 for( int i = 0; i < 16; i++ ) \
1220 unsigned int scale = 255*scale1d[i>>2]*scale1d[i&3]; \
1221 dct1[i] = dct2[i] = j ? (rand()%(2*scale+1))-scale : 0; \
1225 #define TEST_QUANT_DC( name, cqm ) \
1226 if( qf_a.name != qf_ref.name ) \
1228 set_func_name( #name ); \
1230 for( int qp = 51; qp > 0; qp-- ) \
1232 for( int j = 0; j < 2; j++ ) \
1234 int result_c, result_a; \
1235 for( int i = 0; i < 16; i++ ) \
1236 dct1[i] = dct2[i] = j ? (rand() & 0x1fff) - 0xfff : 0; \
1237 result_c = call_c1( qf_c.name, dct1, h->quant4_mf[CQM_4IY][qp][0], h->quant4_bias[CQM_4IY][qp][0] ); \
1238 result_a = call_a1( qf_a.name, dct2, h->quant4_mf[CQM_4IY][qp][0], h->quant4_bias[CQM_4IY][qp][0] ); \
1239 if( memcmp( dct1, dct2, 16*2 ) || result_c != result_a ) \
1242 fprintf( stderr, #name "(cqm=%d): [FAILED]\n", i_cqm ); \
1245 call_c2( qf_c.name, dct1, h->quant4_mf[CQM_4IY][qp][0], h->quant4_bias[CQM_4IY][qp][0] ); \
1246 call_a2( qf_a.name, dct2, h->quant4_mf[CQM_4IY][qp][0], h->quant4_bias[CQM_4IY][qp][0] ); \
1251 #define TEST_QUANT( qname, block, w ) \
1252 if( qf_a.qname != qf_ref.qname ) \
1254 set_func_name( #qname ); \
1256 for( int qp = 51; qp > 0; qp-- ) \
1258 for( int j = 0; j < 2; j++ ) \
1261 int result_c = call_c1( qf_c.qname, dct1, h->quant##w##_mf[block][qp], h->quant##w##_bias[block][qp] ); \
1262 int result_a = call_a1( qf_a.qname, dct2, h->quant##w##_mf[block][qp], h->quant##w##_bias[block][qp] ); \
1263 if( memcmp( dct1, dct2, w*w*2 ) || result_c != result_a ) \
1266 fprintf( stderr, #qname "(qp=%d, cqm=%d, block="#block"): [FAILED]\n", qp, i_cqm ); \
1269 call_c2( qf_c.qname, dct1, h->quant##w##_mf[block][qp], h->quant##w##_bias[block][qp] ); \
1270 call_a2( qf_a.qname, dct2, h->quant##w##_mf[block][qp], h->quant##w##_bias[block][qp] ); \
1275 TEST_QUANT( quant_8x8, CQM_8IY, 8 );
1276 TEST_QUANT( quant_8x8, CQM_8PY, 8 );
1277 TEST_QUANT( quant_4x4, CQM_4IY, 4 );
1278 TEST_QUANT( quant_4x4, CQM_4PY, 4 );
1279 TEST_QUANT_DC( quant_4x4_dc, **h->quant4_mf[CQM_4IY] );
1280 TEST_QUANT_DC( quant_2x2_dc, **h->quant4_mf[CQM_4IC] );
1282 #define TEST_DEQUANT( qname, dqname, block, w ) \
1283 if( qf_a.dqname != qf_ref.dqname ) \
1285 set_func_name( "%s_%s", #dqname, i_cqm?"cqm":"flat" ); \
1287 for( int qp = 51; qp > 0; qp-- ) \
1290 call_c1( qf_c.qname, dct1, h->quant##w##_mf[block][qp], h->quant##w##_bias[block][qp] ); \
1291 memcpy( dct2, dct1, w*w*2 ); \
1292 call_c1( qf_c.dqname, dct1, h->dequant##w##_mf[block], qp ); \
1293 call_a1( qf_a.dqname, dct2, h->dequant##w##_mf[block], qp ); \
1294 if( memcmp( dct1, dct2, w*w*2 ) ) \
1297 fprintf( stderr, #dqname "(qp=%d, cqm=%d, block="#block"): [FAILED]\n", qp, i_cqm ); \
1300 call_c2( qf_c.dqname, dct1, h->dequant##w##_mf[block], qp ); \
1301 call_a2( qf_a.dqname, dct2, h->dequant##w##_mf[block], qp ); \
1305 TEST_DEQUANT( quant_8x8, dequant_8x8, CQM_8IY, 8 );
1306 TEST_DEQUANT( quant_8x8, dequant_8x8, CQM_8PY, 8 );
1307 TEST_DEQUANT( quant_4x4, dequant_4x4, CQM_4IY, 4 );
1308 TEST_DEQUANT( quant_4x4, dequant_4x4, CQM_4PY, 4 );
1310 #define TEST_DEQUANT_DC( qname, dqname, block, w ) \
1311 if( qf_a.dqname != qf_ref.dqname ) \
1313 set_func_name( "%s_%s", #dqname, i_cqm?"cqm":"flat" ); \
1315 for( int qp = 51; qp > 0; qp-- ) \
1317 for( int i = 0; i < 16; i++ ) \
1319 call_c1( qf_c.qname, dct1, h->quant##w##_mf[block][qp][0]>>1, h->quant##w##_bias[block][qp][0]>>1 ); \
1320 memcpy( dct2, dct1, w*w*2 ); \
1321 call_c1( qf_c.dqname, dct1, h->dequant##w##_mf[block], qp ); \
1322 call_a1( qf_a.dqname, dct2, h->dequant##w##_mf[block], qp ); \
1323 if( memcmp( dct1, dct2, w*w*2 ) ) \
1326 fprintf( stderr, #dqname "(qp=%d, cqm=%d, block="#block"): [FAILED]\n", qp, i_cqm ); \
1328 call_c2( qf_c.dqname, dct1, h->dequant##w##_mf[block], qp ); \
1329 call_a2( qf_a.dqname, dct2, h->dequant##w##_mf[block], qp ); \
1333 TEST_DEQUANT_DC( quant_4x4_dc, dequant_4x4_dc, CQM_4IY, 4 );
1335 x264_cqm_delete( h );
1338 ok = oks[0]; used_asm = used_asms[0];
1339 report( "quant :" );
1341 ok = oks[1]; used_asm = used_asms[1];
1342 report( "dequant :" );
1344 ok = 1; used_asm = 0;
1345 if( qf_a.denoise_dct != qf_ref.denoise_dct )
1348 for( int size = 16; size <= 64; size += 48 )
1350 set_func_name( "denoise_dct" );
1351 memcpy( dct1, buf1, size*2 );
1352 memcpy( dct2, buf1, size*2 );
1353 memcpy( buf3+256, buf3, 256 );
1354 call_c1( qf_c.denoise_dct, dct1, (uint32_t*)buf3, (uint16_t*)buf2, size );
1355 call_a1( qf_a.denoise_dct, dct2, (uint32_t*)(buf3+256), (uint16_t*)buf2, size );
1356 if( memcmp( dct1, dct2, size*2 ) || memcmp( buf3+4, buf3+256+4, (size-1)*sizeof(uint32_t) ) )
1358 call_c2( qf_c.denoise_dct, dct1, (uint32_t*)buf3, (uint16_t*)buf2, size );
1359 call_a2( qf_a.denoise_dct, dct2, (uint32_t*)(buf3+256), (uint16_t*)buf2, size );
1362 report( "denoise dct :" );
1364 #define TEST_DECIMATE( decname, w, ac, thresh ) \
1365 if( qf_a.decname != qf_ref.decname ) \
1367 set_func_name( #decname ); \
1369 for( int i = 0; i < 100; i++ ) \
1371 for( int idx = 0; idx < w*w; idx++ ) \
1372 dct1[idx] = !(rand()&3) + (!(rand()&15))*(rand()&3); \
1375 int result_c = call_c( qf_c.decname, dct1 ); \
1376 int result_a = call_a( qf_a.decname, dct1 ); \
1377 if( X264_MIN(result_c,thresh) != X264_MIN(result_a,thresh) ) \
1380 fprintf( stderr, #decname ": [FAILED]\n" ); \
1386 ok = 1; used_asm = 0;
1387 TEST_DECIMATE( decimate_score64, 8, 0, 6 );
1388 TEST_DECIMATE( decimate_score16, 4, 0, 6 );
1389 TEST_DECIMATE( decimate_score15, 4, 1, 7 );
1390 report( "decimate_score :" );
1392 #define TEST_LAST( last, lastname, w, ac ) \
1393 if( qf_a.last != qf_ref.last ) \
1395 set_func_name( #lastname ); \
1397 for( int i = 0; i < 100; i++ ) \
1400 int max = rand() & (w*w-1); \
1401 memset( dct1, 0, w*w*2 ); \
1402 for( int idx = ac; idx < max; idx++ ) \
1403 nnz |= dct1[idx] = !(rand()&3) + (!(rand()&15))*rand(); \
1406 int result_c = call_c( qf_c.last, dct1+ac ); \
1407 int result_a = call_a( qf_a.last, dct1+ac ); \
1408 if( result_c != result_a ) \
1411 fprintf( stderr, #lastname ": [FAILED]\n" ); \
1417 ok = 1; used_asm = 0;
1418 TEST_LAST( coeff_last[DCT_CHROMA_DC], coeff_last4, 2, 0 );
1419 TEST_LAST( coeff_last[ DCT_LUMA_AC], coeff_last15, 4, 1 );
1420 TEST_LAST( coeff_last[ DCT_LUMA_4x4], coeff_last16, 4, 0 );
1421 TEST_LAST( coeff_last[ DCT_LUMA_8x8], coeff_last64, 8, 0 );
1422 report( "coeff_last :" );
1424 #define TEST_LEVELRUN( lastname, name, w, ac ) \
1425 if( qf_a.lastname != qf_ref.lastname ) \
1427 set_func_name( #name ); \
1429 for( int i = 0; i < 100; i++ ) \
1431 x264_run_level_t runlevel_c, runlevel_a; \
1433 int max = rand() & (w*w-1); \
1434 memset( dct1, 0, w*w*2 ); \
1435 memcpy( &runlevel_a, buf1+i, sizeof(x264_run_level_t) ); \
1436 memcpy( &runlevel_c, buf1+i, sizeof(x264_run_level_t) ); \
1437 for( int idx = ac; idx < max; idx++ ) \
1438 nnz |= dct1[idx] = !(rand()&3) + (!(rand()&15))*rand(); \
1441 int result_c = call_c( qf_c.lastname, dct1+ac, &runlevel_c ); \
1442 int result_a = call_a( qf_a.lastname, dct1+ac, &runlevel_a ); \
1443 if( result_c != result_a || runlevel_c.last != runlevel_a.last || \
1444 memcmp(runlevel_c.level, runlevel_a.level, sizeof(int16_t)*result_c) || \
1445 memcmp(runlevel_c.run, runlevel_a.run, sizeof(uint8_t)*(result_c-1)) ) \
1448 fprintf( stderr, #name ": [FAILED]\n" ); \
1454 ok = 1; used_asm = 0;
1455 TEST_LEVELRUN( coeff_level_run[DCT_CHROMA_DC], coeff_level_run4, 2, 0 );
1456 TEST_LEVELRUN( coeff_level_run[ DCT_LUMA_AC], coeff_level_run15, 4, 1 );
1457 TEST_LEVELRUN( coeff_level_run[ DCT_LUMA_4x4], coeff_level_run16, 4, 0 );
1458 report( "coeff_level_run :" );
1463 static int check_intra( int cpu_ref, int cpu_new )
1465 int ret = 0, ok = 1, used_asm = 0;
1466 ALIGNED_16( uint8_t edge[33] );
1467 ALIGNED_16( uint8_t edge2[33] );
1470 x264_predict_t predict_16x16[4+3];
1471 x264_predict_t predict_8x8c[4+3];
1472 x264_predict8x8_t predict_8x8[9+3];
1473 x264_predict_t predict_4x4[9+3];
1474 x264_predict_8x8_filter_t predict_8x8_filter;
1475 } ip_c, ip_ref, ip_a;
1477 x264_predict_16x16_init( 0, ip_c.predict_16x16 );
1478 x264_predict_8x8c_init( 0, ip_c.predict_8x8c );
1479 x264_predict_8x8_init( 0, ip_c.predict_8x8, &ip_c.predict_8x8_filter );
1480 x264_predict_4x4_init( 0, ip_c.predict_4x4 );
1482 x264_predict_16x16_init( cpu_ref, ip_ref.predict_16x16 );
1483 x264_predict_8x8c_init( cpu_ref, ip_ref.predict_8x8c );
1484 x264_predict_8x8_init( cpu_ref, ip_ref.predict_8x8, &ip_ref.predict_8x8_filter );
1485 x264_predict_4x4_init( cpu_ref, ip_ref.predict_4x4 );
1487 x264_predict_16x16_init( cpu_new, ip_a.predict_16x16 );
1488 x264_predict_8x8c_init( cpu_new, ip_a.predict_8x8c );
1489 x264_predict_8x8_init( cpu_new, ip_a.predict_8x8, &ip_a.predict_8x8_filter );
1490 x264_predict_4x4_init( cpu_new, ip_a.predict_4x4 );
1492 ip_c.predict_8x8_filter( buf1+48, edge, ALL_NEIGHBORS, ALL_NEIGHBORS );
1494 #define INTRA_TEST( name, dir, w, ... ) \
1495 if( ip_a.name[dir] != ip_ref.name[dir] )\
1497 set_func_name( "intra_%s_%s", #name, intra_##name##_names[dir] );\
1499 memcpy( buf3, buf1, 32*20 );\
1500 memcpy( buf4, buf1, 32*20 );\
1501 call_c( ip_c.name[dir], buf3+48, ##__VA_ARGS__ );\
1502 call_a( ip_a.name[dir], buf4+48, ##__VA_ARGS__ );\
1503 if( memcmp( buf3, buf4, 32*20 ) )\
1505 fprintf( stderr, #name "[%d] : [FAILED]\n", dir );\
1507 for( int k = -1; k < 16; k++ )\
1508 printf( "%2x ", edge[16+k] );\
1510 for( int j = 0; j < w; j++ )\
1512 printf( "%2x ", edge[14-j] );\
1513 for( int k = 0; k < w; k++ )\
1514 printf( "%2x ", buf4[48+k+j*32] );\
1518 for( int j = 0; j < w; j++ )\
1521 for( int k = 0; k < w; k++ )\
1522 printf( "%2x ", buf3[48+k+j*32] );\
1528 for( int i = 0; i < 12; i++ )
1529 INTRA_TEST( predict_4x4, i, 4 );
1530 for( int i = 0; i < 7; i++ )
1531 INTRA_TEST( predict_8x8c, i, 8 );
1532 for( int i = 0; i < 7; i++ )
1533 INTRA_TEST( predict_16x16, i, 16 );
1534 for( int i = 0; i < 12; i++ )
1535 INTRA_TEST( predict_8x8, i, 8, edge );
1537 set_func_name("intra_predict_8x8_filter");
1538 if( ip_a.predict_8x8_filter != ip_ref.predict_8x8_filter )
1541 for( int i = 0; i < 32; i++ )
1543 memcpy( edge2, edge, 33 );
1544 call_c(ip_c.predict_8x8_filter, buf1+48, edge, (i&24)>>1, i&7);
1545 call_a(ip_a.predict_8x8_filter, buf1+48, edge2, (i&24)>>1, i&7);
1546 if( memcmp( edge, edge2, 33 ) )
1548 fprintf( stderr, "predict_8x8_filter : [FAILED] %d %d\n", (i&24)>>1, i&7);
1554 report( "intra pred :" );
1558 #define DECL_CABAC(cpu) \
1559 static void run_cabac_##cpu( uint8_t *dst )\
1562 x264_cabac_context_init( &cb, SLICE_TYPE_P, 26, 0 );\
1563 x264_cabac_encode_init( &cb, dst, dst+0xff0 );\
1564 for( int i = 0; i < 0x1000; i++ )\
1565 x264_cabac_encode_decision_##cpu( &cb, buf1[i]>>1, buf1[i]&1 );\
1571 #define run_cabac_asm run_cabac_c
1574 static int check_cabac( int cpu_ref, int cpu_new )
1576 int ret = 0, ok, used_asm = 1;
1577 if( cpu_ref || run_cabac_c == run_cabac_asm)
1579 set_func_name( "cabac_encode_decision" );
1580 memcpy( buf4, buf3, 0x1000 );
1581 call_c( run_cabac_c, buf3 );
1582 call_a( run_cabac_asm, buf4 );
1583 ok = !memcmp( buf3, buf4, 0x1000 );
1584 report( "cabac :" );
1588 static int check_all_funcs( int cpu_ref, int cpu_new )
1590 return check_pixel( cpu_ref, cpu_new )
1591 + check_dct( cpu_ref, cpu_new )
1592 + check_mc( cpu_ref, cpu_new )
1593 + check_intra( cpu_ref, cpu_new )
1594 + check_deblock( cpu_ref, cpu_new )
1595 + check_quant( cpu_ref, cpu_new )
1596 + check_cabac( cpu_ref, cpu_new );
1599 static int add_flags( int *cpu_ref, int *cpu_new, int flags, const char *name )
1601 *cpu_ref = *cpu_new;
1603 if( *cpu_new & X264_CPU_SSE2_IS_FAST )
1604 *cpu_new &= ~X264_CPU_SSE2_IS_SLOW;
1606 fprintf( stderr, "x264: %s\n", name );
1607 return check_all_funcs( *cpu_ref, *cpu_new );
1610 static int check_all_flags( void )
1613 int cpu0 = 0, cpu1 = 0;
1615 if( x264_cpu_detect() & X264_CPU_MMXEXT )
1617 ret |= add_flags( &cpu0, &cpu1, X264_CPU_MMX | X264_CPU_MMXEXT, "MMX" );
1618 ret |= add_flags( &cpu0, &cpu1, X264_CPU_CACHELINE_64, "MMX Cache64" );
1619 cpu1 &= ~X264_CPU_CACHELINE_64;
1621 ret |= add_flags( &cpu0, &cpu1, X264_CPU_CACHELINE_32, "MMX Cache32" );
1622 cpu1 &= ~X264_CPU_CACHELINE_32;
1624 if( x264_cpu_detect() & X264_CPU_LZCNT )
1626 ret |= add_flags( &cpu0, &cpu1, X264_CPU_LZCNT, "MMX_LZCNT" );
1627 cpu1 &= ~X264_CPU_LZCNT;
1630 if( x264_cpu_detect() & X264_CPU_SSE2 )
1632 ret |= add_flags( &cpu0, &cpu1, X264_CPU_SSE | X264_CPU_SSE2 | X264_CPU_SSE2_IS_SLOW, "SSE2Slow" );
1633 ret |= add_flags( &cpu0, &cpu1, X264_CPU_SSE2_IS_FAST, "SSE2Fast" );
1634 ret |= add_flags( &cpu0, &cpu1, X264_CPU_CACHELINE_64, "SSE2Fast Cache64" );
1635 ret |= add_flags( &cpu0, &cpu1, X264_CPU_SHUFFLE_IS_FAST, "SSE2 FastShuffle" );
1636 cpu1 &= ~X264_CPU_SHUFFLE_IS_FAST;
1638 if( x264_cpu_detect() & X264_CPU_SSE_MISALIGN )
1640 cpu1 &= ~X264_CPU_CACHELINE_64;
1641 ret |= add_flags( &cpu0, &cpu1, X264_CPU_SSE_MISALIGN, "SSE_Misalign" );
1642 cpu1 &= ~X264_CPU_SSE_MISALIGN;
1644 if( x264_cpu_detect() & X264_CPU_LZCNT )
1646 cpu1 &= ~X264_CPU_CACHELINE_64;
1647 ret |= add_flags( &cpu0, &cpu1, X264_CPU_LZCNT, "SSE_LZCNT" );
1648 cpu1 &= ~X264_CPU_LZCNT;
1650 if( x264_cpu_detect() & X264_CPU_SSE3 )
1651 ret |= add_flags( &cpu0, &cpu1, X264_CPU_SSE3 | X264_CPU_CACHELINE_64, "SSE3" );
1652 if( x264_cpu_detect() & X264_CPU_SSSE3 )
1654 cpu1 &= ~X264_CPU_CACHELINE_64;
1655 ret |= add_flags( &cpu0, &cpu1, X264_CPU_SSSE3, "SSSE3" );
1656 ret |= add_flags( &cpu0, &cpu1, X264_CPU_CACHELINE_64, "SSSE3 Cache64" );
1657 ret |= add_flags( &cpu0, &cpu1, X264_CPU_SHUFFLE_IS_FAST, "SSSE3 FastShuffle" );
1658 cpu1 &= ~X264_CPU_SHUFFLE_IS_FAST;
1660 if( x264_cpu_detect() & X264_CPU_SSE4 )
1662 cpu1 &= ~X264_CPU_CACHELINE_64;
1663 ret |= add_flags( &cpu0, &cpu1, X264_CPU_SSE4, "SSE4" );
1665 #elif defined(ARCH_PPC)
1666 if( x264_cpu_detect() & X264_CPU_ALTIVEC )
1668 fprintf( stderr, "x264: ALTIVEC against C\n" );
1669 ret = check_all_funcs( 0, X264_CPU_ALTIVEC );
1671 #elif defined(ARCH_ARM)
1672 if( x264_cpu_detect() & X264_CPU_ARMV6 )
1673 ret |= add_flags( &cpu0, &cpu1, X264_CPU_ARMV6, "ARMv6" );
1674 if( x264_cpu_detect() & X264_CPU_NEON )
1675 ret |= add_flags( &cpu0, &cpu1, X264_CPU_NEON, "NEON" );
1676 if( x264_cpu_detect() & X264_CPU_FAST_NEON_MRC )
1677 ret |= add_flags( &cpu0, &cpu1, X264_CPU_FAST_NEON_MRC, "Fast NEON MRC" );
1682 int main(int argc, char *argv[])
1686 if( argc > 1 && !strncmp( argv[1], "--bench", 7 ) )
1688 #if !defined(ARCH_X86) && !defined(ARCH_X86_64) && !defined(ARCH_PPC) && !defined(ARCH_ARM)
1689 fprintf( stderr, "no --bench for your cpu until you port rdtsc\n" );
1693 if( argv[1][7] == '=' )
1695 bench_pattern = argv[1]+8;
1696 bench_pattern_len = strlen(bench_pattern);
1702 int seed = ( argc > 1 ) ? atoi(argv[1]) : x264_mdate();
1703 fprintf( stderr, "x264: using random seed %u\n", seed );
1706 buf1 = x264_malloc( 0x3e00 + 16*BENCH_ALIGNS );
1709 fprintf( stderr, "malloc failed, unable to initiate tests!\n" );
1712 buf2 = buf1 + 0xf00;
1713 buf3 = buf2 + 0xf00;
1714 buf4 = buf3 + 0x1000;
1715 for( int i = 0; i < 0x1e00; i++ )
1716 buf1[i] = rand() & 0xFF;
1717 memset( buf1+0x1e00, 0, 0x2000 );
1719 /* 16-byte alignment is guaranteed whenever it's useful, but some functions also vary in speed depending on %64 */
1721 for( int i = 0; i < BENCH_ALIGNS && !ret; i++ )
1723 buf2 = buf1 + 0xf00;
1724 buf3 = buf2 + 0xf00;
1725 buf4 = buf3 + 0x1000;
1726 ret |= x264_stack_pagealign( check_all_flags, i*16 );
1729 fprintf( stderr, "%d/%d\r", i+1, BENCH_ALIGNS );
1732 ret = check_all_flags();
1736 fprintf( stderr, "x264: at least one test has failed. Go and fix that Right Now!\n" );
1739 fprintf( stderr, "x264: All tests passed Yeah :)\n" );