27 # define _GNU_SOURCE // for syscall (performance monitoring API)
45 #if HAVE_SETCONSOLETEXTATTRIBUTE
47 #define COLOR_RED FOREGROUND_RED
48 #define COLOR_GREEN FOREGROUND_GREEN
49 #define COLOR_YELLOW (FOREGROUND_RED|FOREGROUND_GREEN)
53 #define COLOR_YELLOW 3
64 #if ARCH_ARM && HAVE_ARMV5TE_EXTERNAL
67 void (*checkasm_checked_call)(
void *
func,
int dummy, ...) = checkasm_checked_call_novfp;
76 #if CONFIG_AAC_DECODER
80 #if CONFIG_ALAC_DECODER
92 #if CONFIG_DCA_DECODER
95 #if CONFIG_EXR_DECODER
101 #if CONFIG_FMTCONVERT
116 #if CONFIG_HEVC_DECODER
120 #if CONFIG_JPEG2000_DECODER
123 #if CONFIG_HUFFYUVDSP
126 #if CONFIG_PIXBLOCKDSP
129 #if CONFIG_V210_ENCODER
135 #if CONFIG_VP9_DECODER
143 #if CONFIG_BLEND_FILTER
146 #if CONFIG_COLORSPACE_FILTER
158 static const struct {
256 if (llabs((int64_t)x.
i - y.
i) <= max_ulp)
267 for (i = 0; i <
len; i++) {
276 float abs_diff = fabsf(a - b);
278 return abs_diff < eps;
286 for (i = 0; i <
len; i++) {
299 unsigned max_ulp,
unsigned len)
303 for (i = 0; i <
len; i++) {
312 double abs_diff = fabs(a - b);
314 return abs_diff < eps;
322 for (i = 0; i <
len; i++) {
335 #if HAVE_SETCONSOLETEXTATTRIBUTE
337 static WORD org_attributes;
340 CONSOLE_SCREEN_BUFFER_INFO con_info;
341 con = GetStdHandle(STD_ERROR_HANDLE);
343 org_attributes = con_info.wAttributes;
349 SetConsoleTextAttribute(con, (org_attributes & 0xfff0) | (color & 0x0f));
352 const char *term = getenv(
"TERM");
353 use_color = term && strcmp(term,
"dumb") &&
isatty(2);
356 fprintf(stderr,
"\x1b[%d;3%dm", (color & 0x08) >> 3, color & 0x07);
360 vfprintf(stderr, fmt, arg);
364 #if HAVE_SETCONSOLETEXTATTRIBUTE
365 SetConsoleTextAttribute(con, org_attributes);
367 fprintf(stderr,
"\x1b[0m");
392 void *ptr = calloc(1, size);
394 fprintf(stderr,
"checkasm: malloc failed\n");
408 return cpus[
i].suffix;
415 return *(
const uint16_t*)a - *(
const uint16_t*)
b;
421 uint16_t nops[10000];
426 for (i = 0; i < 10000; i++) {
432 qsort(nops, 10000,
sizeof(uint16_t),
cmp_nop);
433 for (i = 2500; i < 7500; i++)
436 return nop_sum / 500;
452 printf(
"%s_%s: %d.%d\n", f->
name,
cpu_suffix(v->
cpu), decicycles/10, decicycles%10);
454 }
while ((v = v->
next));
465 int ascii_diff, digit_diff;
467 for (; !(ascii_diff = *(
const unsigned char*)a - *(
const unsigned char*)
b) && *a; a++, b++);
487 #define is_red(f) ((f) && !(f)->color)
522 int name_length = strlen(name);
524 memcpy(f->
name, name, name_length + 1);
533 int old_cpu_flag =
state.cpu_flag;
535 flag |= old_cpu_flag;
540 if (!flag ||
state.cpu_flag != old_cpu_flag) {
544 for (i = 0;
tests[
i].func; i++) {
556 if (
state.cpu_flag_name) {
562 #if CONFIG_LINUX_PERF
563 static int bench_init_linux(
void)
565 struct perf_event_attr attr = {
566 .type = PERF_TYPE_HARDWARE,
567 .size =
sizeof(
struct perf_event_attr),
568 .
config = PERF_COUNT_HW_CPU_CYCLES,
574 printf(
"benchmarking with Linux Perf Monitoring API\n");
576 state.sysfd = syscall(__NR_perf_event_open, &attr, 0, -1, -1, 0);
577 if (
state.sysfd == -1) {
588 printf(
"benchmarking with native FFmpeg timers\n");
591 fprintf(stderr,
"checkasm: --bench is not supported on your system\n");
598 #if CONFIG_LINUX_PERF
599 int ret = bench_init_linux();
607 printf(
"nop: %d.%d\n",
state.nop_time/10,
state.nop_time%10);
613 #if CONFIG_LINUX_PERF
619 int main(
int argc,
char *argv[])
624 #if ARCH_ARM && HAVE_ARMV5TE_EXTERNAL
626 checkasm_checked_call = checkasm_checked_call_vfp;
630 fprintf(stderr,
"checkasm: no tests to perform\n");
635 if (!strncmp(argv[1],
"--bench", 7)) {
638 if (argv[1][7] ==
'=') {
639 state.bench_pattern = argv[1] + 8;
640 state.bench_pattern_len = strlen(
state.bench_pattern);
642 state.bench_pattern =
"";
643 }
else if (!strncmp(argv[1],
"--test=", 7)) {
644 state.test_name = argv[1] + 7;
646 seed = strtoul(argv[1],
NULL, 10);
653 fprintf(stderr,
"checkasm: using random seed %u\n", seed);
657 for (i = 0;
cpus[i].flag; i++)
660 if (
state.num_failed) {
661 fprintf(stderr,
"checkasm: %d of %d tests have failed\n",
state.num_failed,
state.num_checked);
664 fprintf(stderr,
"checkasm: all %d tests passed\n",
state.num_checked);
665 if (
state.bench_pattern) {
687 name_length =
vsnprintf(name_buf,
sizeof(name_buf), name, arg);
690 if (!func || name_length <= 0 || name_length >=
sizeof(name_buf))
694 state.funcs->color = 1;
695 v = &
state.current_func->versions;
708 }
while ((v = v->
next));
716 state.current_func_ver = v;
727 return !
state.num_failed &&
state.bench_pattern &&
728 !strncmp(
state.current_func->name,
state.bench_pattern,
state.bench_pattern_len);
734 if (
state.current_func_ver->cpu &&
state.current_func_ver->ok) {
740 vfprintf(stderr, msg, arg);
742 fprintf(stderr,
")\n");
744 state.current_func_ver->ok = 0;
753 memset(perf, 0,
sizeof(*perf));
761 static int prev_checked, prev_failed, max_length;
763 if (
state.num_checked > prev_checked) {
764 int pad_length = max_length + 4;
768 pad_length -= fprintf(stderr,
" - %s.",
state.current_test_name);
770 pad_length -= vfprintf(stderr, name, arg);
772 fprintf(stderr,
"%*c",
FFMAX(pad_length, 0) + 2,
'[');
774 if (
state.num_failed == prev_failed)
778 fprintf(stderr,
"]\n");
780 prev_checked =
state.num_checked;
781 prev_failed =
state.num_failed;
782 }
else if (!
state.cpu_flag) {
791 if (length > max_length)
static int bench_init_ffmpeg(void)
static int cmp_nop(const void *a, const void *b)
#define AV_CPU_FLAG_AVX
AVX functions: requires OS support even if YMM registers aren't used.
#define AV_CPU_FLAG_ALTIVEC
standard
void checkasm_check_v210enc(void)
static int measure_nop_time(void)
static void bench_uninit(void)
static av_const int av_isdigit(int c)
Locale-independent conversion of ASCII isdigit.
CheckasmFunc * current_func
int float_near_abs_eps_array(const float *a, const float *b, float eps, unsigned len)
static int is_negative(union av_intfloat32 u)
CheckasmPerf * checkasm_get_perf_context(void)
static FFServerConfig config
#define AV_CPU_FLAG_SSE
SSE functions.
void checkasm_check_vp9dsp(void)
void checkasm_check_flacdsp(void)
#define AV_CPU_FLAG_CMOV
supports cmov instruction
void checkasm_check_h264pred(void)
static const char * cpu_suffix(int cpu)
CheckasmFuncVersion * current_func_ver
void checkasm_check_alacdsp(void)
static int cmp_func_names(const char *a, const char *b)
int float_near_abs_eps(float a, float b, float eps)
void * checkasm_check_func(void *func, const char *name,...)
void checkasm_check_aacpsdsp(void)
void checkasm_check_colorspace(void)
void checkasm_check_vp8dsp(void)
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.
static const struct @258 tests[]
void checkasm_check_sbrdsp(void)
static const struct @259 cpus[]
#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)
void checkasm_check_jpeg2000dsp(void)
#define AV_CPU_FLAG_XOP
Bulldozer XOP functions.
#define AV_CPU_FLAG_SSE42
Nehalem SSE4.2 functions.
static CheckasmFunc * get_func(CheckasmFunc **root, const char *name)
CheckasmFuncVersion versions
#define AV_CPU_FLAG_SSSE3
Conroe SSSE3 functions.
int float_near_ulp(float a, float b, unsigned max_ulp)
void checkasm_check_h264dsp(void)
#define AV_CPU_FLAG_ARMV6T2
void checkasm_check_hevc_add_res(void)
static int bench_init(void)
#define AV_CPU_FLAG_VFP_VM
VFPv2 vector mode, deprecated in ARMv7-A and unavailable in various CPUs implementations.
void checkasm_check_videodsp(void)
#define AV_CPU_FLAG_ARMV5TE
void checkasm_check_fixed_dsp(void)
static void print_benchs(CheckasmFunc *f)
void checkasm_check_audiodsp(void)
#define AV_CPU_FLAG_SSE3
Prescott SSE3 functions.
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
void checkasm_check_exrdsp(void)
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,...)
void checkasm_check_hevc_idct(void)
#define FF_ARRAY_ELEMS(a)
int float_near_ulp_array(const float *a, const float *b, unsigned max_ulp, unsigned len)
#define AV_CPU_FLAG_3DNOW
AMD 3DNOW.
int double_near_abs_eps(double a, double b, double eps)
#define AV_CPU_FLAG_ARMV6
#define AV_CPU_FLAG_SSE3SLOW
SSE3 supported, but usually not faster.
#define AV_CPU_FLAG_MMX
standard MMX
void checkasm_check_fmtconvert(void)
static CheckasmFunc * rotate_tree(CheckasmFunc *f, int dir)
#define AV_CPU_FLAG_FMA4
Bulldozer FMA4 functions.
#define AV_CPU_FLAG_SSE4
Penryn SSE4.1 functions.
#define AV_CPU_FLAG_AESNI
Advanced Encryption Standard functions.
#define AV_CPU_FLAG_VSX
ISA 2.06.
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
void checkasm_check_llviddsp(void)
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
int double_near_abs_eps_array(const double *a, const double *b, double eps, unsigned len)
static void color_printf(int color, const char *fmt,...)
#define AV_CPU_FLAG_3DNOWEXT
AMD 3DNowExt.
void checkasm_check_float_dsp(void)
#define AV_CPU_FLAG_POWER8
ISA 2.07.
int float_near_abs_eps_ulp(float a, float b, float eps, unsigned max_ulp)
static void destroy_func_tree(CheckasmFunc *f)
common internal and external API header
static int ref[MAX_W *MAX_W]
struct CheckasmFuncVersion * next
#define AV_CPU_FLAG_ARMV8
const char * current_test_name
static void check_cpu_flag(const char *name, int flag)
void checkasm_check_pixblockdsp(void)
void checkasm_check_synth_filter(void)
int float_near_abs_eps_array_ulp(const float *a, const float *b, float eps, unsigned max_ulp, unsigned len)
#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)
void av_force_cpu_flags(int arg)
Disables cpu detection and forces the specified flags.
void checkasm_check_g722dsp(void)
static void balance_tree(CheckasmFunc **root)
void checkasm_check_blend(void)
static void print_cpu_name(void)
void checkasm_check_blockdsp(void)