36 #if HAVE_SETCONSOLETEXTATTRIBUTE
38 #define COLOR_RED FOREGROUND_RED
39 #define COLOR_GREEN FOREGROUND_GREEN
40 #define COLOR_YELLOW (FOREGROUND_RED|FOREGROUND_GREEN)
44 #define COLOR_YELLOW 3
152 #if HAVE_SETCONSOLETEXTATTRIBUTE
154 static WORD org_attributes;
157 CONSOLE_SCREEN_BUFFER_INFO con_info;
158 con = GetStdHandle(STD_ERROR_HANDLE);
160 org_attributes = con_info.wAttributes;
166 SetConsoleTextAttribute(con, (org_attributes & 0xfff0) | (color & 0x0f));
169 const char *term = getenv(
"TERM");
170 use_color = term && strcmp(term,
"dumb") &&
isatty(2);
173 fprintf(stderr,
"\x1b[%d;3%dm", (color & 0x08) >> 3, color & 0x07);
177 vfprintf(stderr, fmt, arg);
181 #if HAVE_SETCONSOLETEXTATTRIBUTE
182 SetConsoleTextAttribute(con, org_attributes);
184 fprintf(stderr,
"\x1b[0m");
209 void *ptr = calloc(1, size);
211 fprintf(stderr,
"checkasm: malloc failed\n");
225 return cpus[i].suffix;
231 static int cmp_nop(
const void *
a,
const void *
b)
233 return *(
const uint16_t*)a - *(
const uint16_t*)
b;
237 static int measure_nop_time(
void)
239 uint16_t nops[10000];
242 for (i = 0; i < 10000; i++) {
247 qsort(nops, 10000,
sizeof(uint16_t), cmp_nop);
248 for (i = 2500; i < 7500; i++)
251 return nop_sum / 500;
258 print_benchs(f->
child[0]);
266 printf(
"%s_%s: %d.%d\n", f->
name,
cpu_suffix(v->
cpu), decicycles/10, decicycles%10);
268 }
while ((v = v->
next));
271 print_benchs(f->
child[1]);
279 int ascii_diff, digit_diff;
281 for (; !(ascii_diff = *a - *
b) && *a; a++, b++);
293 while ((f = *f_ptr)) {
298 f_ptr = &f->
child[(cmp > 0)];
303 memcpy(f->
name, name, length+1);
311 int old_cpu_flag =
state.cpu_flag;
313 flag |= old_cpu_flag;
317 if (!flag ||
state.cpu_flag != old_cpu_flag) {
321 for (i = 0;
tests[i].func; i++) {
331 if (
state.cpu_flag_name) {
337 int main(
int argc,
char *argv[])
339 int i,
seed, ret = 0;
342 fprintf(stderr,
"checkasm: no tests to perform\n");
346 if (argc > 1 && !strncmp(argv[1],
"--bench", 7)) {
348 fprintf(stderr,
"checkasm: --bench is not supported on your system\n");
351 if (argv[1][7] ==
'=') {
352 state.bench_pattern = argv[1] + 8;
353 state.bench_pattern_len = strlen(
state.bench_pattern);
355 state.bench_pattern =
"";
362 fprintf(stderr,
"checkasm: using random seed %u\n", seed);
366 for (i = 0;
cpus[i].flag; i++)
369 if (
state.num_failed) {
370 fprintf(stderr,
"checkasm: %d of %d tests have failed\n",
state.num_failed,
state.num_checked);
373 fprintf(stderr,
"checkasm: all %d tests passed\n",
state.num_checked);
375 if (
state.bench_pattern) {
376 state.nop_time = measure_nop_time();
377 printf(
"nop: %d.%d\n",
state.nop_time/10,
state.nop_time%10);
378 print_benchs(
state.funcs);
399 name_length =
vsnprintf(name_buf,
sizeof(name_buf), name, arg);
402 if (!func || name_length <= 0 || name_length >=
sizeof(name_buf))
406 v = &
state.current_func->versions;
419 }
while ((v = v->
next));
427 state.current_func_ver =
v;
438 return !
state.num_failed &&
state.bench_pattern &&
439 !strncmp(
state.current_func->name,
state.bench_pattern,
state.bench_pattern_len);
445 if (
state.current_func_ver->cpu &&
state.current_func_ver->ok) {
451 vfprintf(stderr, msg, arg);
453 fprintf(stderr,
")\n");
455 state.current_func_ver->ok = 0;
463 state.current_func_ver->iterations += iterations;
464 state.current_func_ver->cycles += cycles;
470 static int prev_checked, prev_failed, max_length;
472 if (
state.num_checked > prev_checked) {
473 int pad_length = max_length + 4;
477 pad_length -= fprintf(stderr,
" - %s.",
state.current_test_name);
479 pad_length -= vfprintf(stderr, name, arg);
481 fprintf(stderr,
"%*c",
FFMAX(pad_length, 0) + 2,
'[');
483 if (
state.num_failed == prev_failed)
487 fprintf(stderr,
"]\n");
489 prev_checked =
state.num_checked;
490 prev_failed =
state.num_failed;
491 }
else if (!
state.cpu_flag) {
500 if (length > max_length)
#define AV_CPU_FLAG_AVX
AVX functions: requires OS support even if YMM registers aren't used.
int av_isdigit(int c)
Locale-independent conversion of ASCII isdigit.
#define AV_CPU_FLAG_ALTIVEC
standard
CheckasmFunc * current_func
static const struct @195 tests[]
#define AV_CPU_FLAG_SSE
SSE functions.
void av_set_cpu_flags_mask(int mask)
Set a mask on flags returned by av_get_cpu_flags().
#define AV_CPU_FLAG_CMOV
supports cmov instruction
void checkasm_check_h264pred(void)
static const char * cpu_suffix(int cpu)
CheckasmFuncVersion * current_func_ver
static int cmp_func_names(const char *a, const char *b)
void * checkasm_check_func(void *func, const char *name,...)
struct CheckasmFunc * child[2]
const char * cpu_flag_name
int checkasm_bench_func(void)
#define AV_CPU_FLAG_FMA3
Haswell FMA3 functions.
#define AV_CPU_FLAG_MMXEXT
SSE integer functions or AMD MMX ext.
int main(int argc, char *argv[])
#define AV_CPU_FLAG_ATOM
Atom processor, some SSSE3 instructions are slower.
#define AV_CPU_FLAG_AVX2
AVX2 functions: requires OS support even if YMM registers aren't used.
#define AV_CPU_FLAG_SSE2SLOW
SSE2 supported, but usually not faster.
void checkasm_check_h264qpel(void)
#define AV_CPU_FLAG_XOP
Bulldozer XOP functions.
#define AV_CPU_FLAG_SSE42
Nehalem SSE4.2 functions.
CheckasmFuncVersion versions
#define AV_CPU_FLAG_SSSE3
Conroe SSSE3 functions.
#define AV_CPU_FLAG_ARMV6T2
static CheckasmFunc * get_func(const char *name, int length)
#define AV_CPU_FLAG_ARMV5TE
#define AV_CPU_FLAG_SSE3
Prescott SSE3 functions.
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
compares a block (either a full macroblock or a partition thereof) against a proposed motion-compensa...
#define AV_CPU_FLAG_VFPV3
static void * checkasm_malloc(size_t size)
const char * bench_pattern
void checkasm_report(const char *name,...)
#define FF_ARRAY_ELEMS(a)
#define AV_CPU_FLAG_3DNOW
AMD 3DNOW.
#define AV_CPU_FLAG_ARMV6
#define AV_CPU_FLAG_SSE3SLOW
SSE3 supported, but usually not faster.
#define AV_CPU_FLAG_MMX
standard MMX
static const struct @196 cpus[]
#define AV_CPU_FLAG_FMA4
Bulldozer FMA4 functions.
#define AV_CPU_FLAG_SSE4
Penryn SSE4.1 functions.
#define AV_CPU_FLAG_VSX
ISA 2.06.
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
static void color_printf(int color, const char *fmt,...)
#define AV_CPU_FLAG_3DNOWEXT
AMD 3DNowExt.
#define AV_CPU_FLAG_POWER8
ISA 2.07.
void checkasm_update_bench(int iterations, uint64_t cycles)
static void destroy_func_tree(CheckasmFunc *f)
common internal and external API header
struct CheckasmFuncVersion * next
#define AV_CPU_FLAG_ARMV8
const char * current_test_name
static void check_cpu_flag(const char *name, int flag)
#define AV_CPU_FLAG_SSE2
PIV SSE2 functions.
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
void checkasm_fail_func(const char *msg,...)
#define INVALID_HANDLE_VALUE
void checkasm_check_bswapdsp(void)
static void print_cpu_name(void)