FFmpeg
checkasm.c
Go to the documentation of this file.
1 /*
2  * Assembly testing and benchmarking tool
3  * Copyright (c) 2015 Henrik Gramner
4  * Copyright (c) 2008 Loren Merritt
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  *
22  * Copyright © 2018, VideoLAN and dav1d authors
23  * Copyright © 2018, Two Orioles, LLC
24  * All rights reserved.
25  *
26  * Redistribution and use in source and binary forms, with or without
27  * modification, are permitted provided that the following conditions are met:
28  *
29  * 1. Redistributions of source code must retain the above copyright notice, this
30  * list of conditions and the following disclaimer.
31  *
32  * 2. Redistributions in binary form must reproduce the above copyright notice,
33  * this list of conditions and the following disclaimer in the documentation
34  * and/or other materials provided with the distribution.
35  *
36  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
37  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
38  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
40  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
41  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
45  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46  */
47 
48 #include "config.h"
49 #include "config_components.h"
50 
51 #ifndef _GNU_SOURCE
52 # define _GNU_SOURCE // for syscall (performance monitoring API), strsignal()
53 #endif
54 
55 #include <signal.h>
56 #include <stdarg.h>
57 #include <stdio.h>
58 #include <stdlib.h>
59 #include <string.h>
60 #include "checkasm.h"
61 #include "libavutil/common.h"
62 #include "libavutil/cpu.h"
63 #include "libavutil/intfloat.h"
64 #include "libavutil/random_seed.h"
65 
66 #if HAVE_IO_H
67 #include <io.h>
68 #endif
69 #if HAVE_PRCTL
70 #include <sys/prctl.h>
71 #endif
72 
73 #if defined(_WIN32) && !defined(SIGBUS)
74 /* non-standard, use the same value as mingw-w64 */
75 #define SIGBUS 10
76 #endif
77 
78 #if HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
79 #include <windows.h>
80 #define COLOR_RED FOREGROUND_RED
81 #define COLOR_GREEN FOREGROUND_GREEN
82 #define COLOR_YELLOW (FOREGROUND_RED|FOREGROUND_GREEN)
83 #else
84 #define COLOR_RED 1
85 #define COLOR_GREEN 2
86 #define COLOR_YELLOW 3
87 #endif
88 
89 #if HAVE_UNISTD_H
90 #include <unistd.h>
91 #endif
92 
93 #if !HAVE_ISATTY
94 #define isatty(fd) 1
95 #endif
96 
97 #if ARCH_ARM && HAVE_ARMV5TE_EXTERNAL
98 #include "libavutil/arm/cpu.h"
99 
100 void (*checkasm_checked_call)(void *func, int dummy, ...) = checkasm_checked_call_novfp;
101 #endif
102 
103 /* Trade-off between speed and accuracy */
104 uint64_t bench_runs = 1U << 10;
105 
106 /* List of tests to invoke */
107 static const struct {
108  const char *name;
109  void (*func)(void);
110 } tests[] = {
111 #if CONFIG_AVCODEC
112  #if CONFIG_AAC_DECODER
113  { "aacpsdsp", checkasm_check_aacpsdsp },
114  { "sbrdsp", checkasm_check_sbrdsp },
115  #endif
116  #if CONFIG_AAC_ENCODER
117  { "aacencdsp", checkasm_check_aacencdsp },
118  #endif
119  #if CONFIG_AC3DSP
120  { "ac3dsp", checkasm_check_ac3dsp },
121  #endif
122  #if CONFIG_ALAC_DECODER
123  { "alacdsp", checkasm_check_alacdsp },
124  #endif
125  #if CONFIG_AUDIODSP
126  { "audiodsp", checkasm_check_audiodsp },
127  #endif
128  #if CONFIG_BLOCKDSP
129  { "blockdsp", checkasm_check_blockdsp },
130  #endif
131  #if CONFIG_BSWAPDSP
132  { "bswapdsp", checkasm_check_bswapdsp },
133  #endif
134  #if CONFIG_DCA_DECODER
135  { "synth_filter", checkasm_check_synth_filter },
136  #endif
137  #if CONFIG_EXR_DECODER
138  { "exrdsp", checkasm_check_exrdsp },
139  #endif
140  #if CONFIG_FDCTDSP
141  { "fdctdsp", checkasm_check_fdctdsp },
142  #endif
143  #if CONFIG_FLAC_DECODER
144  { "flacdsp", checkasm_check_flacdsp },
145  #endif
146  #if CONFIG_FMTCONVERT
147  { "fmtconvert", checkasm_check_fmtconvert },
148  #endif
149  #if CONFIG_G722DSP
150  { "g722dsp", checkasm_check_g722dsp },
151  #endif
152  #if CONFIG_H263DSP
153  { "h263dsp", checkasm_check_h263dsp },
154  #endif
155  #if CONFIG_H264CHROMA
156  { "h264chroma", checkasm_check_h264chroma },
157  #endif
158  #if CONFIG_H264DSP
159  { "h264dsp", checkasm_check_h264dsp },
160  #endif
161  #if CONFIG_H264PRED
162  { "h264pred", checkasm_check_h264pred },
163  #endif
164  #if CONFIG_H264QPEL
165  { "h264qpel", checkasm_check_h264qpel },
166  #endif
167  #if CONFIG_HEVC_DECODER
168  { "hevc_add_res", checkasm_check_hevc_add_res },
169  { "hevc_deblock", checkasm_check_hevc_deblock },
170  { "hevc_idct", checkasm_check_hevc_idct },
171  { "hevc_pel", checkasm_check_hevc_pel },
172  { "hevc_sao", checkasm_check_hevc_sao },
173  #endif
174  #if CONFIG_HUFFYUV_DECODER
175  { "huffyuvdsp", checkasm_check_huffyuvdsp },
176  #endif
177  #if CONFIG_IDCTDSP
178  { "idctdsp", checkasm_check_idctdsp },
179  #endif
180  #if CONFIG_JPEG2000_DECODER
181  { "jpeg2000dsp", checkasm_check_jpeg2000dsp },
182  #endif
183  #if CONFIG_LLAUDDSP
184  { "llauddsp", checkasm_check_llauddsp },
185  #endif
186  #if CONFIG_HUFFYUVDSP
187  { "llviddsp", checkasm_check_llviddsp },
188  #endif
189  #if CONFIG_LLVIDENCDSP
190  { "llviddspenc", checkasm_check_llviddspenc },
191  #endif
192  #if CONFIG_LPC
193  { "lpc", checkasm_check_lpc },
194  #endif
195  #if CONFIG_ME_CMP
196  { "motion", checkasm_check_motion },
197  #endif
198  #if CONFIG_MPEGVIDEOENC
199  { "mpegvideoencdsp", checkasm_check_mpegvideoencdsp },
200  #endif
201  #if CONFIG_OPUS_DECODER
202  { "opusdsp", checkasm_check_opusdsp },
203  #endif
204  #if CONFIG_PIXBLOCKDSP
205  { "pixblockdsp", checkasm_check_pixblockdsp },
206  #endif
207  #if CONFIG_RV34DSP
208  { "rv34dsp", checkasm_check_rv34dsp },
209  #endif
210  #if CONFIG_RV40_DECODER
211  { "rv40dsp", checkasm_check_rv40dsp },
212  #endif
213  #if CONFIG_SVQ1_ENCODER
214  { "svq1enc", checkasm_check_svq1enc },
215  #endif
216  #if CONFIG_TAK_DECODER
217  { "takdsp", checkasm_check_takdsp },
218  #endif
219  #if CONFIG_UTVIDEO_DECODER
220  { "utvideodsp", checkasm_check_utvideodsp },
221  #endif
222  #if CONFIG_V210_DECODER
223  { "v210dec", checkasm_check_v210dec },
224  #endif
225  #if CONFIG_V210_ENCODER
226  { "v210enc", checkasm_check_v210enc },
227  #endif
228  #if CONFIG_VC1DSP
229  { "vc1dsp", checkasm_check_vc1dsp },
230  #endif
231  #if CONFIG_VP8DSP
232  { "vp8dsp", checkasm_check_vp8dsp },
233  #endif
234  #if CONFIG_VP9_DECODER
235  { "vp9dsp", checkasm_check_vp9dsp },
236  #endif
237  #if CONFIG_VIDEODSP
238  { "videodsp", checkasm_check_videodsp },
239  #endif
240  #if CONFIG_VORBIS_DECODER
241  { "vorbisdsp", checkasm_check_vorbisdsp },
242  #endif
243  #if CONFIG_VVC_DECODER
244  { "vvc_alf", checkasm_check_vvc_alf },
245  { "vvc_mc", checkasm_check_vvc_mc },
246  #endif
247 #endif
248 #if CONFIG_AVFILTER
249  #if CONFIG_AFIR_FILTER
250  { "af_afir", checkasm_check_afir },
251  #endif
252  #if CONFIG_BLEND_FILTER
253  { "vf_blend", checkasm_check_blend },
254  #endif
255  #if CONFIG_BWDIF_FILTER
256  { "vf_bwdif", checkasm_check_vf_bwdif },
257  #endif
258  #if CONFIG_COLORSPACE_FILTER
259  { "vf_colorspace", checkasm_check_colorspace },
260  #endif
261  #if CONFIG_EQ_FILTER
262  { "vf_eq", checkasm_check_vf_eq },
263  #endif
264  #if CONFIG_GBLUR_FILTER
265  { "vf_gblur", checkasm_check_vf_gblur },
266  #endif
267  #if CONFIG_HFLIP_FILTER
268  { "vf_hflip", checkasm_check_vf_hflip },
269  #endif
270  #if CONFIG_NLMEANS_FILTER
271  { "vf_nlmeans", checkasm_check_nlmeans },
272  #endif
273  #if CONFIG_THRESHOLD_FILTER
274  { "vf_threshold", checkasm_check_vf_threshold },
275  #endif
276  #if CONFIG_SOBEL_FILTER
277  { "vf_sobel", checkasm_check_vf_sobel },
278  #endif
279 #endif
280 #if CONFIG_SWSCALE
281  { "sw_gbrp", checkasm_check_sw_gbrp },
282  { "sw_range_convert", checkasm_check_sw_range_convert },
283  { "sw_rgb", checkasm_check_sw_rgb },
284  { "sw_scale", checkasm_check_sw_scale },
285  { "sw_yuv2rgb", checkasm_check_sw_yuv2rgb },
286  { "sw_yuv2yuv", checkasm_check_sw_yuv2yuv },
287 #endif
288 #if CONFIG_AVUTIL
289  { "fixed_dsp", checkasm_check_fixed_dsp },
290  { "float_dsp", checkasm_check_float_dsp },
291  { "lls", checkasm_check_lls },
292  { "av_tx", checkasm_check_av_tx },
293 #endif
294  { NULL }
295 };
296 
297 /* List of cpu flags to check */
298 static const struct {
299  const char *name;
300  const char *suffix;
301  int flag;
302 } cpus[] = {
303 #if ARCH_AARCH64
304  { "ARMV8", "armv8", AV_CPU_FLAG_ARMV8 },
305  { "NEON", "neon", AV_CPU_FLAG_NEON },
306  { "DOTPROD", "dotprod", AV_CPU_FLAG_DOTPROD },
307  { "I8MM", "i8mm", AV_CPU_FLAG_I8MM },
308 #elif ARCH_ARM
309  { "ARMV5TE", "armv5te", AV_CPU_FLAG_ARMV5TE },
310  { "ARMV6", "armv6", AV_CPU_FLAG_ARMV6 },
311  { "ARMV6T2", "armv6t2", AV_CPU_FLAG_ARMV6T2 },
312  { "VFP", "vfp", AV_CPU_FLAG_VFP },
313  { "VFP_VM", "vfp_vm", AV_CPU_FLAG_VFP_VM },
314  { "VFPV3", "vfp3", AV_CPU_FLAG_VFPV3 },
315  { "NEON", "neon", AV_CPU_FLAG_NEON },
316 #elif ARCH_PPC
317  { "ALTIVEC", "altivec", AV_CPU_FLAG_ALTIVEC },
318  { "VSX", "vsx", AV_CPU_FLAG_VSX },
319  { "POWER8", "power8", AV_CPU_FLAG_POWER8 },
320 #elif ARCH_RISCV
321  { "RVI", "rvi", AV_CPU_FLAG_RVI },
322  { "misaligned", "misaligned", AV_CPU_FLAG_RV_MISALIGNED },
323  { "RV_zbb", "rvb_b", AV_CPU_FLAG_RVB_BASIC },
324  { "RVB", "rvb", AV_CPU_FLAG_RVB },
325  { "RV_zve32x","rvv_i32", AV_CPU_FLAG_RVV_I32 },
326  { "RV_zve32f","rvv_f32", AV_CPU_FLAG_RVV_F32 },
327  { "RV_zve64x","rvv_i64", AV_CPU_FLAG_RVV_I64 },
328  { "RV_zve64d","rvv_f64", AV_CPU_FLAG_RVV_F64 },
329  { "RV_zvbb", "rv_zvbb", AV_CPU_FLAG_RV_ZVBB },
330 #elif ARCH_MIPS
331  { "MMI", "mmi", AV_CPU_FLAG_MMI },
332  { "MSA", "msa", AV_CPU_FLAG_MSA },
333 #elif ARCH_X86
334  { "MMX", "mmx", AV_CPU_FLAG_MMX|AV_CPU_FLAG_CMOV },
335  { "MMXEXT", "mmxext", AV_CPU_FLAG_MMXEXT },
336  { "3DNOW", "3dnow", AV_CPU_FLAG_3DNOW },
337  { "3DNOWEXT", "3dnowext", AV_CPU_FLAG_3DNOWEXT },
338  { "SSE", "sse", AV_CPU_FLAG_SSE },
339  { "SSE2", "sse2", AV_CPU_FLAG_SSE2|AV_CPU_FLAG_SSE2SLOW },
340  { "SSE3", "sse3", AV_CPU_FLAG_SSE3|AV_CPU_FLAG_SSE3SLOW },
341  { "SSSE3", "ssse3", AV_CPU_FLAG_SSSE3|AV_CPU_FLAG_ATOM },
342  { "SSE4.1", "sse4", AV_CPU_FLAG_SSE4 },
343  { "SSE4.2", "sse42", AV_CPU_FLAG_SSE42 },
344  { "AES-NI", "aesni", AV_CPU_FLAG_AESNI },
345  { "AVX", "avx", AV_CPU_FLAG_AVX },
346  { "XOP", "xop", AV_CPU_FLAG_XOP },
347  { "FMA3", "fma3", AV_CPU_FLAG_FMA3 },
348  { "FMA4", "fma4", AV_CPU_FLAG_FMA4 },
349  { "AVX2", "avx2", AV_CPU_FLAG_AVX2 },
350  { "AVX-512", "avx512", AV_CPU_FLAG_AVX512 },
351  { "AVX-512ICL", "avx512icl", AV_CPU_FLAG_AVX512ICL },
352 #elif ARCH_LOONGARCH
353  { "LSX", "lsx", AV_CPU_FLAG_LSX },
354  { "LASX", "lasx", AV_CPU_FLAG_LASX },
355 #endif
356  { NULL }
357 };
358 
359 typedef struct CheckasmFuncVersion {
361  void *func;
362  int ok;
363  int cpu;
366 
367 /* Binary search tree node */
368 typedef struct CheckasmFunc {
369  struct CheckasmFunc *child[2];
371  uint8_t color; /* 0 = red, 1 = black */
372  char name[1];
373 } CheckasmFunc;
374 
375 /* Internal state */
376 static struct {
380  const char *current_test_name;
381  const char *bench_pattern;
385 
386  /* perf */
387  int nop_time;
388  int sysfd;
389 
390  int cpu_flag;
391  const char *cpu_flag_name;
392  const char *test_pattern;
393  int verbose;
394  int csv;
395  int tsv;
396  volatile sig_atomic_t catch_signals;
397 } state;
398 
399 /* PRNG state */
401 
402 /* float compare support code */
403 static int is_negative(union av_intfloat32 u)
404 {
405  return u.i >> 31;
406 }
407 
408 int float_near_ulp(float a, float b, unsigned max_ulp)
409 {
410  union av_intfloat32 x, y;
411 
412  x.f = a;
413  y.f = b;
414 
415  if (is_negative(x) != is_negative(y)) {
416  // handle -0.0 == +0.0
417  return a == b;
418  }
419 
420  if (llabs((int64_t)x.i - y.i) <= max_ulp)
421  return 1;
422 
423  return 0;
424 }
425 
426 int float_near_ulp_array(const float *a, const float *b, unsigned max_ulp,
427  unsigned len)
428 {
429  unsigned i;
430 
431  for (i = 0; i < len; i++) {
432  if (!float_near_ulp(a[i], b[i], max_ulp))
433  return 0;
434  }
435  return 1;
436 }
437 
438 int float_near_abs_eps(float a, float b, float eps)
439 {
440  float abs_diff = fabsf(a - b);
441  if (abs_diff < eps)
442  return 1;
443 
444  fprintf(stderr, "test failed comparing %g with %g (abs diff=%g with EPS=%g)\n", a, b, abs_diff, eps);
445 
446  return 0;
447 }
448 
449 int float_near_abs_eps_array(const float *a, const float *b, float eps,
450  unsigned len)
451 {
452  unsigned i;
453 
454  for (i = 0; i < len; i++) {
455  if (!float_near_abs_eps(a[i], b[i], eps))
456  return 0;
457  }
458  return 1;
459 }
460 
461 int float_near_abs_eps_ulp(float a, float b, float eps, unsigned max_ulp)
462 {
463  return float_near_ulp(a, b, max_ulp) || float_near_abs_eps(a, b, eps);
464 }
465 
466 int float_near_abs_eps_array_ulp(const float *a, const float *b, float eps,
467  unsigned max_ulp, unsigned len)
468 {
469  unsigned i;
470 
471  for (i = 0; i < len; i++) {
472  if (!float_near_abs_eps_ulp(a[i], b[i], eps, max_ulp))
473  return 0;
474  }
475  return 1;
476 }
477 
478 int double_near_abs_eps(double a, double b, double eps)
479 {
480  double abs_diff = fabs(a - b);
481 
482  return abs_diff < eps;
483 }
484 
485 int double_near_abs_eps_array(const double *a, const double *b, double eps,
486  unsigned len)
487 {
488  unsigned i;
489 
490  for (i = 0; i < len; i++) {
491  if (!double_near_abs_eps(a[i], b[i], eps))
492  return 0;
493  }
494  return 1;
495 }
496 
497 /* Print colored text to stderr if the terminal supports it */
498 static void color_printf(int color, const char *fmt, ...)
499 {
500  static int use_color = -1;
501  va_list arg;
502 
503 #if HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
504  static HANDLE con;
505  static WORD org_attributes;
506 
507  if (use_color < 0) {
508  CONSOLE_SCREEN_BUFFER_INFO con_info;
509  con = GetStdHandle(STD_ERROR_HANDLE);
510  if (con && con != INVALID_HANDLE_VALUE && GetConsoleScreenBufferInfo(con, &con_info)) {
511  org_attributes = con_info.wAttributes;
512  use_color = 1;
513  } else
514  use_color = 0;
515  }
516  if (use_color)
517  SetConsoleTextAttribute(con, (org_attributes & 0xfff0) | (color & 0x0f));
518 #else
519  if (use_color < 0) {
520  const char *term = getenv("TERM");
521  use_color = term && strcmp(term, "dumb") && isatty(2);
522  }
523  if (use_color)
524  fprintf(stderr, "\x1b[%d;3%dm", (color & 0x08) >> 3, color & 0x07);
525 #endif
526 
527  va_start(arg, fmt);
528  vfprintf(stderr, fmt, arg);
529  va_end(arg);
530 
531  if (use_color) {
532 #if HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
533  SetConsoleTextAttribute(con, org_attributes);
534 #else
535  fprintf(stderr, "\x1b[0m");
536 #endif
537  }
538 }
539 
540 /* Deallocate a tree */
542 {
543  if (f) {
544  CheckasmFuncVersion *v = f->versions.next;
545  while (v) {
546  CheckasmFuncVersion *next = v->next;
547  free(v);
548  v = next;
549  }
550 
551  destroy_func_tree(f->child[0]);
552  destroy_func_tree(f->child[1]);
553  free(f);
554  }
555 }
556 
557 /* Allocate a zero-initialized block, clean up and exit on failure */
558 static void *checkasm_malloc(size_t size)
559 {
560  void *ptr = calloc(1, size);
561  if (!ptr) {
562  fprintf(stderr, "checkasm: malloc failed\n");
563  destroy_func_tree(state.funcs);
564  exit(1);
565  }
566  return ptr;
567 }
568 
569 /* Get the suffix of the specified cpu flag */
570 static const char *cpu_suffix(int cpu)
571 {
572  int i = FF_ARRAY_ELEMS(cpus);
573 
574  while (--i >= 0)
575  if (cpu & cpus[i].flag)
576  return cpus[i].suffix;
577 
578  return "c";
579 }
580 
581 static int cmp_nop(const void *a, const void *b)
582 {
583  return *(const uint16_t*)a - *(const uint16_t*)b;
584 }
585 
586 /* Measure the overhead of the timing code (in decicycles) */
587 static int measure_nop_time(void)
588 {
589  uint16_t nops[10000];
590  int i, nop_sum = 0;
591  av_unused const int sysfd = state.sysfd;
592 
593  uint64_t t = 0;
594  for (i = 0; i < 10000; i++) {
595  PERF_START(t);
596  PERF_STOP(t);
597  nops[i] = t;
598  }
599 
600  qsort(nops, 10000, sizeof(uint16_t), cmp_nop);
601  for (i = 2500; i < 7500; i++)
602  nop_sum += nops[i];
603 
604  return nop_sum / 500;
605 }
606 
607 static inline double avg_cycles_per_call(const CheckasmPerf *const p)
608 {
609  if (p->iterations) {
610  const double cycles = (double)(10 * p->cycles) / p->iterations - state.nop_time;
611  if (cycles > 0.0)
612  return cycles / 4.0; /* 4 calls per iteration */
613  }
614  return 0.0;
615 }
616 
617 /* Print benchmark results */
619 {
620  if (f) {
621  print_benchs(f->child[0]);
622 
623  /* Only print functions with at least one assembly version */
624  if (f->versions.cpu || f->versions.next) {
625  CheckasmFuncVersion *v = &f->versions;
626  const CheckasmPerf *p = &v->perf;
627  const double baseline = avg_cycles_per_call(p);
628  double decicycles;
629  do {
630  if (p->iterations) {
631  p = &v->perf;
632  decicycles = avg_cycles_per_call(p);
633  if (state.csv || state.tsv) {
634  const char sep = state.csv ? ',' : '\t';
635  printf("%s%c%s%c%.1f\n", f->name, sep,
636  cpu_suffix(v->cpu), sep,
637  decicycles / 10.0);
638  } else {
639  const int pad_length = 10 + 50 -
640  printf("%s_%s:", f->name, cpu_suffix(v->cpu));
641  const double ratio = decicycles ?
642  baseline / decicycles : 0.0;
643  printf("%*.1f (%5.2fx)\n", FFMAX(pad_length, 0),
644  decicycles / 10.0, ratio);
645  }
646  }
647  } while ((v = v->next));
648  }
649 
650  print_benchs(f->child[1]);
651  }
652 }
653 
654 /* ASCIIbetical sort except preserving natural order for numbers */
655 static int cmp_func_names(const char *a, const char *b)
656 {
657  const char *start = a;
658  int ascii_diff, digit_diff;
659 
660  for (; !(ascii_diff = *(const unsigned char*)a - *(const unsigned char*)b) && *a; a++, b++);
661  for (; av_isdigit(*a) && av_isdigit(*b); a++, b++);
662 
663  if (a > start && av_isdigit(a[-1]) && (digit_diff = av_isdigit(*a) - av_isdigit(*b)))
664  return digit_diff;
665 
666  return ascii_diff;
667 }
668 
669 /* Perform a tree rotation in the specified direction and return the new root */
671 {
672  CheckasmFunc *r = f->child[dir^1];
673  f->child[dir^1] = r->child[dir];
674  r->child[dir] = f;
675  r->color = f->color;
676  f->color = 0;
677  return r;
678 }
679 
680 #define is_red(f) ((f) && !(f)->color)
681 
682 /* Balance a left-leaning red-black tree at the specified node */
683 static void balance_tree(CheckasmFunc **root)
684 {
685  CheckasmFunc *f = *root;
686 
687  if (is_red(f->child[0]) && is_red(f->child[1])) {
688  f->color ^= 1;
689  f->child[0]->color = f->child[1]->color = 1;
690  }
691 
692  if (!is_red(f->child[0]) && is_red(f->child[1]))
693  *root = rotate_tree(f, 0); /* Rotate left */
694  else if (is_red(f->child[0]) && is_red(f->child[0]->child[0]))
695  *root = rotate_tree(f, 1); /* Rotate right */
696 }
697 
698 /* Get a node with the specified name, creating it if it doesn't exist */
699 static CheckasmFunc *get_func(CheckasmFunc **root, const char *name)
700 {
701  CheckasmFunc *f = *root;
702 
703  if (f) {
704  /* Search the tree for a matching node */
705  int cmp = cmp_func_names(name, f->name);
706  if (cmp) {
707  f = get_func(&f->child[cmp > 0], name);
708 
709  /* Rebalance the tree on the way up if a new node was inserted */
710  if (!f->versions.func)
711  balance_tree(root);
712  }
713  } else {
714  /* Allocate and insert a new node into the tree */
715  int name_length = strlen(name);
716  f = *root = checkasm_malloc(sizeof(CheckasmFunc) + name_length);
717  memcpy(f->name, name, name_length + 1);
718  }
719 
720  return f;
721 }
722 
724 
725 /* Crash handling: attempt to catch crashes and handle them
726  * gracefully instead of just aborting abruptly. */
727 #ifdef _WIN32
728 #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
729 static LONG NTAPI signal_handler(EXCEPTION_POINTERS *e) {
730  int s;
731 
732  if (!state.catch_signals)
733  return EXCEPTION_CONTINUE_SEARCH;
734 
735  switch (e->ExceptionRecord->ExceptionCode) {
736  case EXCEPTION_FLT_DIVIDE_BY_ZERO:
737  case EXCEPTION_INT_DIVIDE_BY_ZERO:
738  s = SIGFPE;
739  break;
740  case EXCEPTION_ILLEGAL_INSTRUCTION:
741  case EXCEPTION_PRIV_INSTRUCTION:
742  s = SIGILL;
743  break;
744  case EXCEPTION_ACCESS_VIOLATION:
745  case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
746  case EXCEPTION_DATATYPE_MISALIGNMENT:
747  case EXCEPTION_STACK_OVERFLOW:
748  s = SIGSEGV;
749  break;
750  case EXCEPTION_IN_PAGE_ERROR:
751  s = SIGBUS;
752  break;
753  default:
754  return EXCEPTION_CONTINUE_SEARCH;
755  }
756  state.catch_signals = 0;
758  return EXCEPTION_CONTINUE_EXECUTION; /* never reached, but shuts up gcc */
759 }
760 #endif
761 #else
762 static void signal_handler(int s);
763 
764 static const struct sigaction signal_handler_act = {
765  .sa_handler = signal_handler,
766  .sa_flags = SA_RESETHAND,
767 };
768 
769 static void signal_handler(int s) {
770  if (state.catch_signals) {
771  state.catch_signals = 0;
772  sigaction(s, &signal_handler_act, NULL);
774  }
775 }
776 #endif
777 
778 /* Compares a string with a wildcard pattern. */
779 static int wildstrcmp(const char *str, const char *pattern)
780 {
781  const char *wild = strchr(pattern, '*');
782  if (wild) {
783  const size_t len = wild - pattern;
784  if (strncmp(str, pattern, len)) return 1;
785  while (*++wild == '*');
786  if (!*wild) return 0;
787  str += len;
788  while (*str && wildstrcmp(str, wild)) str++;
789  return !*str;
790  }
791  return strcmp(str, pattern);
792 }
793 
794 /* Perform tests and benchmarks for the specified cpu flag if supported by the host */
795 static void check_cpu_flag(const char *name, int flag)
796 {
797  int old_cpu_flag = state.cpu_flag;
798 
799  flag |= old_cpu_flag;
800  av_force_cpu_flags(-1);
801  state.cpu_flag = flag & av_get_cpu_flags();
802  av_force_cpu_flags(state.cpu_flag);
803 
804  if (!flag || state.cpu_flag != old_cpu_flag) {
805  int i;
806 
807  state.cpu_flag_name = name;
808  for (i = 0; tests[i].func; i++) {
809  if (state.test_pattern && wildstrcmp(tests[i].name, state.test_pattern))
810  continue;
811  state.current_test_name = tests[i].name;
812  tests[i].func();
813  }
814  }
815 }
816 
817 /* Print the name of the current CPU flag, but only do it once */
818 static void print_cpu_name(void)
819 {
820  if (state.cpu_flag_name) {
821  color_printf(COLOR_YELLOW, "%s:\n", state.cpu_flag_name);
822  state.cpu_flag_name = NULL;
823  }
824 }
825 
826 #if CONFIG_LINUX_PERF
827 static int bench_init_linux(void)
828 {
829  struct perf_event_attr attr = {
830  .type = PERF_TYPE_HARDWARE,
831  .size = sizeof(struct perf_event_attr),
832  .config = PERF_COUNT_HW_CPU_CYCLES,
833  .disabled = 1, // start counting only on demand
834  .exclude_kernel = 1,
835  .exclude_hv = 1,
836 #if !ARCH_X86
837  .exclude_guest = 1,
838 #endif
839  };
840 
841  fprintf(stderr, "benchmarking with Linux Perf Monitoring API\n");
842 
843  state.sysfd = syscall(__NR_perf_event_open, &attr, 0, -1, -1, 0);
844  if (state.sysfd == -1) {
845  perror("perf_event_open");
846  return -1;
847  }
848  return 0;
849 }
850 #elif CONFIG_MACOS_KPERF
851 static int bench_init_kperf(void)
852 {
853  ff_kperf_init();
854  return 0;
855 }
856 #else
857 static int bench_init_ffmpeg(void)
858 {
859 #ifdef AV_READ_TIME
860  if (!checkasm_save_context()) {
862  AV_READ_TIME();
864  } else {
865  fprintf(stderr, "checkasm: unable to execute platform specific timer\n");
866  return -1;
867  }
868  fprintf(stderr, "benchmarking with native FFmpeg timers\n");
869  return 0;
870 #else
871  fprintf(stderr, "checkasm: --bench is not supported on your system\n");
872  return -1;
873 #endif
874 }
875 #endif
876 
877 static int bench_init(void)
878 {
879 #if CONFIG_LINUX_PERF
880  int ret = bench_init_linux();
881 #elif CONFIG_MACOS_KPERF
882  int ret = bench_init_kperf();
883 #else
884  int ret = bench_init_ffmpeg();
885 #endif
886  if (ret < 0)
887  return ret;
888 
889  state.nop_time = measure_nop_time();
890  fprintf(stderr, "nop: %d.%d\n", state.nop_time/10, state.nop_time%10);
891  return 0;
892 }
893 
894 static void bench_uninit(void)
895 {
896 #if CONFIG_LINUX_PERF
897  close(state.sysfd);
898 #endif
899 }
900 
901 static int usage(const char *path)
902 {
903  fprintf(stderr,
904  "Usage: %s [options...] [seed]\n"
905  " --test=<pattern> Run specific test.\n"
906  " --bench Run benchmark.\n"
907  " --csv, --tsv Output results in rows of comma or tab separated values.\n"
908  " --runs=<ptwo> Manual number of benchmark iterations to run 2**<ptwo>.\n"
909  " --verbose Increase verbosity.\n",
910  path);
911  return 1;
912 }
913 
914 int main(int argc, char *argv[])
915 {
916  unsigned int seed = av_get_random_seed();
917  int i, ret = 0;
918 
919 #ifdef _WIN32
920 #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
921  AddVectoredExceptionHandler(0, signal_handler);
922 #endif
923 #else
924  sigaction(SIGBUS, &signal_handler_act, NULL);
925  sigaction(SIGFPE, &signal_handler_act, NULL);
926  sigaction(SIGILL, &signal_handler_act, NULL);
927  sigaction(SIGSEGV, &signal_handler_act, NULL);
928 #endif
929 #if HAVE_PRCTL && defined(PR_SET_UNALIGN)
930  prctl(PR_SET_UNALIGN, PR_UNALIGN_SIGBUS);
931 #endif
932 #if ARCH_ARM && HAVE_ARMV5TE_EXTERNAL
934  checkasm_checked_call = checkasm_checked_call_vfp;
935 #endif
936 
937  if (!tests[0].func || !cpus[0].flag) {
938  fprintf(stderr, "checkasm: no tests to perform\n");
939  return 0;
940  }
941 
942  for (i = 1; i < argc; i++) {
943  const char *arg = argv[i];
944  unsigned long l;
945  char *end;
946 
947  if (!strncmp(arg, "--bench", 7)) {
948  if (bench_init() < 0)
949  return 1;
950  if (arg[7] == '=') {
951  state.bench_pattern = arg + 8;
952  state.bench_pattern_len = strlen(state.bench_pattern);
953  } else
954  state.bench_pattern = "*";
955  } else if (!strncmp(arg, "--test=", 7)) {
956  state.test_pattern = arg + 7;
957  } else if (!strcmp(arg, "--csv")) {
958  state.csv = 1; state.tsv = 0;
959  } else if (!strcmp(arg, "--tsv")) {
960  state.csv = 0; state.tsv = 1;
961  } else if (!strcmp(arg, "--verbose") || !strcmp(arg, "-v")) {
962  state.verbose = 1;
963  } else if (!strncmp(arg, "--runs=", 7)) {
964  l = strtoul(arg + 7, &end, 10);
965  if (*end == '\0') {
966  if (l > 30) {
967  fprintf(stderr, "checkasm: error: runs exponent must be within the range 0 <= 30\n");
968  usage(argv[0]);
969  }
970  bench_runs = 1U << l;
971  } else {
972  return usage(argv[0]);
973  }
974  } else if ((l = strtoul(arg, &end, 10)) <= UINT_MAX &&
975  *end == '\0') {
976  seed = l;
977  } else {
978  return usage(argv[0]);
979  }
980  }
981 
982  fprintf(stderr, "checkasm: using random seed %u\n", seed);
984 
985  if (state.bench_pattern)
986  fprintf(stderr, "checkasm: bench runs %" PRIu64 " (1 << %i)\n", bench_runs, av_log2(bench_runs));
987 
988  check_cpu_flag(NULL, 0);
989  for (i = 0; cpus[i].flag; i++)
991 
992  if (state.num_failed) {
993  fprintf(stderr, "checkasm: %d of %d tests have failed\n", state.num_failed, state.num_checked);
994  ret = 1;
995  } else {
996  fprintf(stderr, "checkasm: all %d tests passed\n", state.num_checked);
997  if (state.bench_pattern) {
998  print_benchs(state.funcs);
999  }
1000  }
1001 
1002  destroy_func_tree(state.funcs);
1003  bench_uninit();
1004  return ret;
1005 }
1006 
1007 /* Decide whether or not the specified function needs to be tested and
1008  * allocate/initialize data structures if needed. Returns a pointer to a
1009  * reference function if the function should be tested, otherwise NULL */
1010 void *checkasm_check_func(void *func, const char *name, ...)
1011 {
1012  char name_buf[256];
1013  void *ref = func;
1015  int name_length;
1016  va_list arg;
1017 
1018  va_start(arg, name);
1019  name_length = vsnprintf(name_buf, sizeof(name_buf), name, arg);
1020  va_end(arg);
1021 
1022  if (!func || name_length <= 0 || name_length >= sizeof(name_buf))
1023  return NULL;
1024 
1025  state.current_func = get_func(&state.funcs, name_buf);
1026  state.funcs->color = 1;
1027  v = &state.current_func->versions;
1028 
1029  if (v->func) {
1030  CheckasmFuncVersion *prev;
1031  do {
1032  /* Only test functions that haven't already been tested */
1033  if (v->func == func)
1034  return NULL;
1035 
1036  if (v->ok)
1037  ref = v->func;
1038 
1039  prev = v;
1040  } while ((v = v->next));
1041 
1042  v = prev->next = checkasm_malloc(sizeof(CheckasmFuncVersion));
1043  }
1044 
1045  v->func = func;
1046  v->ok = 1;
1047  v->cpu = state.cpu_flag;
1048  state.current_func_ver = v;
1049 
1050  if (state.cpu_flag)
1051  state.num_checked++;
1052 
1053  return ref;
1054 }
1055 
1056 /* Decide whether or not the current function needs to be benchmarked */
1058 {
1059  return !state.num_failed && state.bench_pattern &&
1060  !wildstrcmp(state.current_func->name, state.bench_pattern);
1061 }
1062 
1063 /* Indicate that the current test has failed */
1064 void checkasm_fail_func(const char *msg, ...)
1065 {
1066  if (state.current_func_ver && state.current_func_ver->cpu &&
1067  state.current_func_ver->ok)
1068  {
1069  va_list arg;
1070 
1071  print_cpu_name();
1072  fprintf(stderr, " %s_%s (", state.current_func->name, cpu_suffix(state.current_func_ver->cpu));
1073  va_start(arg, msg);
1074  vfprintf(stderr, msg, arg);
1075  va_end(arg);
1076  fprintf(stderr, ")\n");
1077 
1078  state.current_func_ver->ok = 0;
1079  state.num_failed++;
1080  }
1081 }
1082 
1084  state.catch_signals = enabled;
1085 }
1086 
1088  if (s) {
1089 #ifdef __GLIBC__
1090  checkasm_fail_func("fatal signal %d: %s", s, strsignal(s));
1091 #else
1092  checkasm_fail_func(s == SIGFPE ? "fatal arithmetic error" :
1093  s == SIGILL ? "illegal instruction" :
1094  s == SIGBUS ? "bus error" :
1095  "segmentation fault");
1096 #endif
1097  }
1098  return s;
1099 }
1100 
1101 /* Get the benchmark context of the current function */
1103 {
1104  CheckasmPerf *perf = &state.current_func_ver->perf;
1105  memset(perf, 0, sizeof(*perf));
1106  perf->sysfd = state.sysfd;
1107  return perf;
1108 }
1109 
1110 /* Print the outcome of all tests performed since the last time this function was called */
1111 void checkasm_report(const char *name, ...)
1112 {
1113  static int prev_checked, prev_failed, max_length;
1114 
1115  if (state.num_checked > prev_checked) {
1116  int pad_length = max_length + 4;
1117  va_list arg;
1118 
1119  print_cpu_name();
1120  pad_length -= fprintf(stderr, " - %s.", state.current_test_name);
1121  va_start(arg, name);
1122  pad_length -= vfprintf(stderr, name, arg);
1123  va_end(arg);
1124  fprintf(stderr, "%*c", FFMAX(pad_length, 0) + 2, '[');
1125 
1126  if (state.num_failed == prev_failed)
1127  color_printf(COLOR_GREEN, "OK");
1128  else
1129  color_printf(COLOR_RED, "FAILED");
1130  fprintf(stderr, "]\n");
1131 
1132  prev_checked = state.num_checked;
1133  prev_failed = state.num_failed;
1134  } else if (!state.cpu_flag) {
1135  /* Calculate the amount of padding required to make the output vertically aligned */
1136  int length = strlen(state.current_test_name);
1137  va_list arg;
1138 
1139  va_start(arg, name);
1140  length += vsnprintf(NULL, 0, name, arg);
1141  va_end(arg);
1142 
1143  if (length > max_length)
1144  max_length = length;
1145  }
1146 }
1147 
1148 #define DEF_CHECKASM_CHECK_FUNC(type, fmt) \
1149 int checkasm_check_##type(const char *file, int line, \
1150  const type *buf1, ptrdiff_t stride1, \
1151  const type *buf2, ptrdiff_t stride2, \
1152  int w, int h, const char *name) \
1153 { \
1154  int y = 0; \
1155  stride1 /= sizeof(*buf1); \
1156  stride2 /= sizeof(*buf2); \
1157  for (y = 0; y < h; y++) \
1158  if (memcmp(&buf1[y*stride1], &buf2[y*stride2], w*sizeof(*buf1))) \
1159  break; \
1160  if (y == h) \
1161  return 0; \
1162  checkasm_fail_func("%s:%d", file, line); \
1163  if (!state.verbose) \
1164  return 1; \
1165  fprintf(stderr, "%s:\n", name); \
1166  while (h--) { \
1167  for (int x = 0; x < w; x++) \
1168  fprintf(stderr, " " fmt, buf1[x]); \
1169  fprintf(stderr, " "); \
1170  for (int x = 0; x < w; x++) \
1171  fprintf(stderr, " " fmt, buf2[x]); \
1172  fprintf(stderr, " "); \
1173  for (int x = 0; x < w; x++) \
1174  fprintf(stderr, "%c", buf1[x] != buf2[x] ? 'x' : '.'); \
1175  buf1 += stride1; \
1176  buf2 += stride2; \
1177  fprintf(stderr, "\n"); \
1178  } \
1179  return 1; \
1180 }
1181 
1182 DEF_CHECKASM_CHECK_FUNC(uint8_t, "%02x")
1183 DEF_CHECKASM_CHECK_FUNC(uint16_t, "%04x")
1184 DEF_CHECKASM_CHECK_FUNC(uint32_t, "%08x")
1185 DEF_CHECKASM_CHECK_FUNC(int16_t, "%6d")
checkasm_check_nlmeans
void checkasm_check_nlmeans(void)
Definition: vf_nlmeans.c:32
AV_CPU_FLAG_VFP
#define AV_CPU_FLAG_VFP
Definition: cpu.h:68
checkasm_check_sw_gbrp
void checkasm_check_sw_gbrp(void)
Definition: sw_gbrp.c:397
bench_pattern_len
int bench_pattern_len
Definition: checkasm.c:382
av_force_cpu_flags
void av_force_cpu_flags(int arg)
Disables cpu detection and forces the specified flags.
Definition: cpu.c:79
checkasm_check_vp8dsp
void checkasm_check_vp8dsp(void)
Definition: vp8dsp.c:510
state
static struct @449 state
checkasm_check_blockdsp
void checkasm_check_blockdsp(void)
Definition: blockdsp.c:78
AV_CPU_FLAG_SSE3
#define AV_CPU_FLAG_SSE3
Prescott SSE3 functions.
Definition: cpu.h:39
checkasm_check_fdctdsp
void checkasm_check_fdctdsp(void)
Definition: fdctdsp.c:67
destroy_func_tree
static void destroy_func_tree(CheckasmFunc *f)
Definition: checkasm.c:541
r
const char * r
Definition: vf_curves.c:127
checkasm_check_videodsp
void checkasm_check_videodsp(void)
Definition: videodsp.c:81
cmp_nop
static int cmp_nop(const void *a, const void *b)
Definition: checkasm.c:581
checkasm_check_vf_eq
void checkasm_check_vf_eq(void)
Definition: vf_eq.c:76
AV_CPU_FLAG_RVB_BASIC
#define AV_CPU_FLAG_RVB_BASIC
Basic bit-manipulations.
Definition: cpu.h:94
COLOR_RED
#define COLOR_RED
Definition: checkasm.c:84
wildstrcmp
static int wildstrcmp(const char *str, const char *pattern)
Definition: checkasm.c:779
checkasm_lfg
AVLFG checkasm_lfg
Definition: checkasm.c:400
color
Definition: vf_paletteuse.c:511
av_lfg_init
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
Definition: lfg.c:32
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:251
checkasm_check_alacdsp
void checkasm_check_alacdsp(void)
Definition: alacdsp.c:116
AV_CPU_FLAG_LSX
#define AV_CPU_FLAG_LSX
Definition: cpu.h:81
checkasm_check_v210dec
void checkasm_check_v210dec(void)
Definition: v210dec.c:47
float_near_abs_eps_array
int float_near_abs_eps_array(const float *a, const float *b, float eps, unsigned len)
Definition: checkasm.c:449
AV_CPU_FLAG_SSE3SLOW
#define AV_CPU_FLAG_SSE3SLOW
SSE3 supported, but usually not faster.
Definition: cpu.h:40
CheckasmFunc
Definition: checkasm.c:368
checkasm_check_sw_yuv2yuv
void checkasm_check_sw_yuv2yuv(void)
Definition: sw_yuv2yuv.c:129
name
const char * name
Definition: checkasm.c:108
bench_pattern
const char * bench_pattern
Definition: checkasm.c:381
AV_CPU_FLAG_RV_ZVBB
#define AV_CPU_FLAG_RV_ZVBB
Vector basic bit-manipulations.
Definition: cpu.h:98
int64_t
long long int64_t
Definition: coverity.c:34
av_unused
#define av_unused
Definition: attributes.h:131
checkasm_check_hevc_idct
void checkasm_check_hevc_idct(void)
Definition: hevc_idct.c:108
checkasm_check_sw_scale
void checkasm_check_sw_scale(void)
Definition: sw_scale.c:362
CheckasmFunc::child
struct CheckasmFunc * child[2]
Definition: checkasm.c:369
checkasm_check_afir
void checkasm_check_afir(void)
Definition: af_afir.c:144
print_cpu_name
static void print_cpu_name(void)
Definition: checkasm.c:818
AV_CPU_FLAG_3DNOW
#define AV_CPU_FLAG_3DNOW
AMD 3DNOW.
Definition: cpu.h:33
av_intfloat32::i
uint32_t i
Definition: intfloat.h:28
float_near_abs_eps
int float_near_abs_eps(float a, float b, float eps)
Definition: checkasm.c:438
b
#define b
Definition: input.c:41
checkasm_check_aacpsdsp
void checkasm_check_aacpsdsp(void)
Definition: aacpsdsp.c:234
bench_uninit
static void bench_uninit(void)
Definition: checkasm.c:894
CheckasmFuncVersion::cpu
int cpu
Definition: checkasm.c:363
cpu_flag
int cpu_flag
Definition: checkasm.c:390
AV_CPU_FLAG_DOTPROD
#define AV_CPU_FLAG_DOTPROD
Definition: cpu.h:73
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:107
cpu_suffix
static const char * cpu_suffix(int cpu)
Definition: checkasm.c:570
CheckasmPerf::sysfd
int sysfd
Definition: checkasm.h:311
checkasm_check_llviddspenc
void checkasm_check_llviddspenc(void)
Definition: llviddspenc.c:104
intfloat.h
checkasm_check_h264dsp
void checkasm_check_h264dsp(void)
Definition: h264dsp.c:452
tf_sess_config.config
config
Definition: tf_sess_config.py:33
color_printf
static void color_printf(int color, const char *fmt,...)
Definition: checkasm.c:498
AV_CPU_FLAG_RVV_F64
#define AV_CPU_FLAG_RVV_F64
Vectors of double's.
Definition: cpu.h:93
av_get_random_seed
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
Definition: random_seed.c:167
main
int main(int argc, char *argv[])
Definition: checkasm.c:914
checkasm_check_motion
void checkasm_check_motion(void)
Definition: motion.c:137
checkasm_check_h263dsp
void checkasm_check_h263dsp(void)
Definition: h263dsp.c:54
AV_CPU_FLAG_RVB
#define AV_CPU_FLAG_RVB
B (bit manipulations)
Definition: cpu.h:100
AV_CPU_FLAG_SSSE3
#define AV_CPU_FLAG_SSSE3
Conroe SSSE3 functions.
Definition: cpu.h:42
double_near_abs_eps
int double_near_abs_eps(double a, double b, double eps)
Definition: checkasm.c:478
CheckasmPerf
Definition: checkasm.h:310
current_test_name
const char * current_test_name
Definition: checkasm.c:380
PERF_START
#define PERF_START(t)
Definition: checkasm.h:369
rotate_tree
static CheckasmFunc * rotate_tree(CheckasmFunc *f, int dir)
Definition: checkasm.c:670
dummy
int dummy
Definition: motion.c:66
AV_CPU_FLAG_XOP
#define AV_CPU_FLAG_XOP
Bulldozer XOP functions.
Definition: cpu.h:50
checkasm_check_vp9dsp
void checkasm_check_vp9dsp(void)
Definition: vp9dsp.c:627
checkasm.h
checkasm_check_vf_threshold
void checkasm_check_vf_threshold(void)
Definition: vf_threshold.c:79
checkasm_check_vf_gblur
void checkasm_check_vf_gblur(void)
Definition: vf_gblur.c:82
AV_CPU_FLAG_3DNOWEXT
#define AV_CPU_FLAG_3DNOWEXT
AMD 3DNowExt.
Definition: cpu.h:38
float_near_abs_eps_ulp
int float_near_abs_eps_ulp(float a, float b, float eps, unsigned max_ulp)
Definition: checkasm.c:461
checkasm_check_vvc_mc
void checkasm_check_vvc_mc(void)
Definition: vvc_mc.c:471
AV_CPU_FLAG_VSX
#define AV_CPU_FLAG_VSX
ISA 2.06.
Definition: cpu.h:62
fabsf
static __device__ float fabsf(float a)
Definition: cuda_runtime.h:181
checkasm_check_sw_yuv2rgb
void checkasm_check_sw_yuv2rgb(void)
Definition: sw_yuv2rgb.c:231
AV_CPU_FLAG_RVV_F32
#define AV_CPU_FLAG_RVV_F32
Vectors of float's *‍/.
Definition: cpu.h:91
num_failed
int num_failed
Definition: checkasm.c:384
checkasm_check_float_dsp
void checkasm_check_float_dsp(void)
Definition: float_dsp.c:297
AV_CPU_FLAG_AVX512
#define AV_CPU_FLAG_AVX512
AVX-512 functions: requires OS support even if YMM/ZMM registers aren't used.
Definition: cpu.h:57
bench_init
static int bench_init(void)
Definition: checkasm.c:877
checkasm_check_pixblockdsp
void checkasm_check_pixblockdsp(void)
Definition: pixblockdsp.c:82
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
CheckasmFuncVersion
Definition: checkasm.c:359
COLOR_YELLOW
#define COLOR_YELLOW
Definition: checkasm.c:86
nop_time
int nop_time
Definition: checkasm.c:387
CheckasmFuncVersion::perf
CheckasmPerf perf
Definition: checkasm.c:364
s
#define s(width, name)
Definition: cbs_vp9.c:198
checkasm_check_vf_bwdif
void checkasm_check_vf_bwdif(void)
Definition: vf_bwdif.c:72
checkasm_report
void checkasm_report(const char *name,...)
Definition: checkasm.c:1111
get_func
static CheckasmFunc * get_func(CheckasmFunc **root, const char *name)
Definition: checkasm.c:699
checkasm_fail_func
void checkasm_fail_func(const char *msg,...)
Definition: checkasm.c:1064
checkasm_check_sw_rgb
void checkasm_check_sw_rgb(void)
Definition: sw_rgb.c:451
checkasm_check_hevc_sao
void checkasm_check_hevc_sao(void)
Definition: hevc_sao.c:141
num_checked
int num_checked
Definition: checkasm.c:383
AV_CPU_FLAG_ARMV6
#define AV_CPU_FLAG_ARMV6
Definition: cpu.h:66
AV_READ_TIME
#define AV_READ_TIME
Definition: timer.h:28
AV_CPU_FLAG_SSE4
#define AV_CPU_FLAG_SSE4
Penryn SSE4.1 functions.
Definition: cpu.h:45
checkasm_check_hevc_pel
void checkasm_check_hevc_pel(void)
Definition: hevc_pel.c:607
checkasm_set_signal_handler_state
void checkasm_set_signal_handler_state(int enabled)
Definition: checkasm.c:1083
cmp
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...
Definition: motion_est.c:262
CheckasmPerf::iterations
int iterations
Definition: checkasm.h:313
CheckasmFuncVersion::ok
int ok
Definition: checkasm.c:362
arg
const char * arg
Definition: jacosubdec.c:67
func
void(* func)(void)
Definition: checkasm.c:109
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
NULL
#define NULL
Definition: coverity.c:32
measure_nop_time
static int measure_nop_time(void)
Definition: checkasm.c:587
checkasm_check_takdsp
void checkasm_check_takdsp(void)
Definition: takdsp.c:145
double_near_abs_eps_array
int double_near_abs_eps_array(const double *a, const double *b, double eps, unsigned len)
Definition: checkasm.c:485
AV_CPU_FLAG_LASX
#define AV_CPU_FLAG_LASX
Definition: cpu.h:82
AV_CPU_FLAG_AVX512ICL
#define AV_CPU_FLAG_AVX512ICL
F/CD/BW/DQ/VL/VNNI/IFMA/VBMI/VBMI2/VPOPCNTDQ/BITALG/GFNI/VAES/VPCLMULQDQ.
Definition: cpu.h:58
checkasm_check_fmtconvert
void checkasm_check_fmtconvert(void)
Definition: fmtconvert.c:46
checkasm_load_context
#define checkasm_load_context(s)
Definition: checkasm.h:73
AV_CPU_FLAG_MSA
#define AV_CPU_FLAG_MSA
Definition: cpu.h:78
checkasm_save_context
#define checkasm_save_context()
Definition: checkasm.h:72
cpus
static const struct @448 cpus[]
COLOR_GREEN
#define COLOR_GREEN
Definition: checkasm.c:85
checkasm_check_aacencdsp
void checkasm_check_aacencdsp(void)
Definition: aacencdsp.c:100
checkasm_check_vorbisdsp
void checkasm_check_vorbisdsp(void)
Definition: vorbisdsp.c:76
cpu.h
double
double
Definition: af_crystalizer.c:132
av_intfloat32
Definition: intfloat.h:27
AV_CPU_FLAG_CMOV
#define AV_CPU_FLAG_CMOV
supports cmov instruction
Definition: cpu.h:52
seed
static unsigned int seed
Definition: videogen.c:78
AV_CPU_FLAG_ALTIVEC
#define AV_CPU_FLAG_ALTIVEC
standard
Definition: cpu.h:61
checkasm_check_rv40dsp
void checkasm_check_rv40dsp(void)
Definition: rv40dsp.c:71
print_benchs
static void print_benchs(CheckasmFunc *f)
Definition: checkasm.c:618
current_func
CheckasmFunc * current_func
Definition: checkasm.c:378
AV_CPU_FLAG_I8MM
#define AV_CPU_FLAG_I8MM
Definition: cpu.h:74
checkasm_check_vc1dsp
void checkasm_check_vc1dsp(void)
Definition: vc1dsp.c:476
catch_signals
volatile sig_atomic_t catch_signals
Definition: checkasm.c:396
checkasm_check_h264chroma
void checkasm_check_h264chroma(void)
Definition: h264chroma.c:81
AV_CPU_FLAG_SSE2
#define AV_CPU_FLAG_SSE2
PIV SSE2 functions.
Definition: cpu.h:35
CheckasmFunc::color
uint8_t color
Definition: checkasm.c:371
AVLFG
Context structure for the Lagged Fibonacci PRNG.
Definition: lfg.h:33
f
f
Definition: af_crystalizer.c:122
checkasm_check_llauddsp
void checkasm_check_llauddsp(void)
Definition: llauddsp.c:108
AV_CPU_FLAG_AVX
#define AV_CPU_FLAG_AVX
AVX functions: requires OS support even if YMM registers aren't used.
Definition: cpu.h:48
csv
int csv
Definition: checkasm.c:394
AV_CPU_FLAG_FMA4
#define AV_CPU_FLAG_FMA4
Bulldozer FMA4 functions.
Definition: cpu.h:51
cpu.h
AV_CPU_FLAG_AVX2
#define AV_CPU_FLAG_AVX2
AVX2 functions: requires OS support even if YMM registers aren't used.
Definition: cpu.h:53
checkasm_check_llviddsp
void checkasm_check_llviddsp(void)
Definition: llviddsp.c:195
checkasm_handle_signal
int checkasm_handle_signal(int s)
Definition: checkasm.c:1087
AV_CPU_FLAG_SSE2SLOW
#define AV_CPU_FLAG_SSE2SLOW
SSE2 supported, but usually not faster.
Definition: cpu.h:36
tests
static const struct @447 tests[]
AV_CPU_FLAG_NEON
#define AV_CPU_FLAG_NEON
Definition: cpu.h:70
size
int size
Definition: twinvq_data.h:10344
DEF_CHECKASM_CHECK_FUNC
#define DEF_CHECKASM_CHECK_FUNC(type, fmt)
Definition: checkasm.c:1148
printf
printf("static const uint8_t my_array[100] = {\n")
sysfd
int sysfd
Definition: checkasm.c:388
have_neon
#define have_neon(flags)
Definition: cpu.h:26
CheckasmFuncVersion::func
void * func
Definition: checkasm.c:361
checkasm_check_h264pred
void checkasm_check_h264pred(void)
Definition: h264pred.c:233
av_isdigit
static av_const int av_isdigit(int c)
Locale-independent conversion of ASCII isdigit.
Definition: avstring.h:202
AV_CPU_FLAG_FMA3
#define AV_CPU_FLAG_FMA3
Haswell FMA3 functions.
Definition: cpu.h:54
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
ff_kperf_init
void ff_kperf_init(void)
Definition: macos_kperf.c:102
bench_runs
uint64_t bench_runs
Definition: checkasm.c:104
checkasm_check_huffyuvdsp
void checkasm_check_huffyuvdsp(void)
Definition: huffyuvdsp.c:95
float_near_abs_eps_array_ulp
int float_near_abs_eps_array_ulp(const float *a, const float *b, float eps, unsigned max_ulp, unsigned len)
Definition: checkasm.c:466
CheckasmPerf::cycles
uint64_t cycles
Definition: checkasm.h:312
checkasm_get_perf_context
CheckasmPerf * checkasm_get_perf_context(void)
Definition: checkasm.c:1102
checkasm_check_fixed_dsp
void checkasm_check_fixed_dsp(void)
Definition: fixed_dsp.c:133
checkasm_check_colorspace
void checkasm_check_colorspace(void)
Definition: vf_colorspace.c:309
checkasm_check_utvideodsp
void checkasm_check_utvideodsp(void)
Definition: utvideodsp.c:90
is_negative
static int is_negative(union av_intfloat32 u)
Definition: checkasm.c:403
checkasm_check_audiodsp
void checkasm_check_audiodsp(void)
Definition: audiodsp.c:52
checkasm_check_sw_range_convert
void checkasm_check_sw_range_convert(void)
Definition: sw_range_convert.c:124
AV_CPU_FLAG_RV_MISALIGNED
#define AV_CPU_FLAG_RV_MISALIGNED
Fast misaligned accesses.
Definition: cpu.h:99
checkasm_check_mpegvideoencdsp
void checkasm_check_mpegvideoencdsp(void)
Definition: mpegvideoencdsp.c:132
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
checkasm_check_flacdsp
void checkasm_check_flacdsp(void)
Definition: flacdsp.c:155
checkasm_check_func
void * checkasm_check_func(void *func, const char *name,...)
Definition: checkasm.c:1010
AV_CPU_FLAG_SSE42
#define AV_CPU_FLAG_SSE42
Nehalem SSE4.2 functions.
Definition: cpu.h:46
checkasm_check_idctdsp
void checkasm_check_idctdsp(void)
Definition: idctdsp.c:95
CheckasmFuncVersion::next
struct CheckasmFuncVersion * next
Definition: checkasm.c:360
vsnprintf
#define vsnprintf
Definition: snprintf.h:36
common.h
use_color
static int use_color
Definition: log.c:123
AV_CPU_FLAG_RVV_I32
#define AV_CPU_FLAG_RVV_I32
Vectors of 8/16/32-bit int's *‍/.
Definition: cpu.h:90
checkasm_check_synth_filter
void checkasm_check_synth_filter(void)
Definition: synth_filter.c:47
cmp_func_names
static int cmp_func_names(const char *a, const char *b)
Definition: checkasm.c:655
AV_CPU_FLAG_ARMV8
#define AV_CPU_FLAG_ARMV8
Definition: cpu.h:71
checkasm_check_lpc
void checkasm_check_lpc(void)
Definition: lpc.c:96
len
int len
Definition: vorbis_enc_data.h:426
checkasm_check_g722dsp
void checkasm_check_g722dsp(void)
Definition: g722dsp.c:53
checkasm_check_ac3dsp
void checkasm_check_ac3dsp(void)
Definition: ac3dsp.c:193
PERF_STOP
#define PERF_STOP(t)
Definition: checkasm.h:370
is_red
#define is_red(f)
Definition: checkasm.c:680
AV_CPU_FLAG_ATOM
#define AV_CPU_FLAG_ATOM
Atom processor, some SSSE3 instructions are slower.
Definition: cpu.h:44
have_vfp
#define have_vfp(flags)
Definition: cpu.h:27
checkasm_check_svq1enc
void checkasm_check_svq1enc(void)
Definition: svq1enc.c:63
checkasm_check_vf_hflip
void checkasm_check_vf_hflip(void)
Definition: vf_hflip.c:72
ret
ret
Definition: filter_design.txt:187
checkasm_check_lls
void checkasm_check_lls(void)
Definition: lls.c:80
checkasm_check_blend
void checkasm_check_blend(void)
Definition: vf_blend.c:89
verbose
int verbose
Definition: checkasm.c:393
AV_CPU_FLAG_VFPV3
#define AV_CPU_FLAG_VFPV3
Definition: cpu.h:69
checkasm_check_bswapdsp
void checkasm_check_bswapdsp(void)
Definition: bswapdsp.c:60
checkasm_context_buf
checkasm_context checkasm_context_buf
Definition: checkasm.c:723
U
#define U(x)
Definition: vpx_arith.h:37
AV_CPU_FLAG_ARMV5TE
#define AV_CPU_FLAG_ARMV5TE
Definition: cpu.h:65
AV_CPU_FLAG_MMX
#define AV_CPU_FLAG_MMX
standard MMX
Definition: cpu.h:30
suffix
const char * suffix
Definition: checkasm.c:300
checkasm_malloc
static void * checkasm_malloc(size_t size)
Definition: checkasm.c:558
AV_CPU_FLAG_RVI
#define AV_CPU_FLAG_RVI
I (full GPR bank)
Definition: cpu.h:85
checkasm_check_h264qpel
void checkasm_check_h264qpel(void)
Definition: h264qpel.c:51
random_seed.h
signal_handler
static void signal_handler(int s)
Definition: checkasm.c:769
AV_CPU_FLAG_AESNI
#define AV_CPU_FLAG_AESNI
Advanced Encryption Standard functions.
Definition: cpu.h:47
checkasm_bench_func
int checkasm_bench_func(void)
Definition: checkasm.c:1057
AV_CPU_FLAG_POWER8
#define AV_CPU_FLAG_POWER8
ISA 2.07.
Definition: cpu.h:63
cpu_flag_name
const char * cpu_flag_name
Definition: checkasm.c:391
checkasm_check_vf_sobel
void checkasm_check_vf_sobel(void)
Definition: vf_convolution.c:100
AV_CPU_FLAG_SSE
#define AV_CPU_FLAG_SSE
SSE functions.
Definition: cpu.h:34
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:112
float_near_ulp_array
int float_near_ulp_array(const float *a, const float *b, unsigned max_ulp, unsigned len)
Definition: checkasm.c:426
signal_handler_act
static const struct sigaction signal_handler_act
Definition: checkasm.c:764
AV_CPU_FLAG_MMXEXT
#define AV_CPU_FLAG_MMXEXT
SSE integer functions or AMD MMX ext.
Definition: cpu.h:31
checkasm_check_av_tx
void checkasm_check_av_tx(void)
Definition: av_tx.c:102
av_intfloat32::f
float f
Definition: intfloat.h:29
flag
int flag
Definition: checkasm.c:301
checkasm_check_v210enc
void checkasm_check_v210enc(void)
Definition: v210enc.c:84
checkasm_check_sbrdsp
void checkasm_check_sbrdsp(void)
Definition: sbrdsp.c:257
checkasm_check_hevc_deblock
void checkasm_check_hevc_deblock(void)
Definition: hevc_deblock.c:264
test_pattern
const char * test_pattern
Definition: checkasm.c:392
usage
static int usage(const char *path)
Definition: checkasm.c:901
AV_CPU_FLAG_VFP_VM
#define AV_CPU_FLAG_VFP_VM
VFPv2 vector mode, deprecated in ARMv7-A and unavailable in various CPUs implementations.
Definition: cpu.h:72
AV_CPU_FLAG_MMI
#define AV_CPU_FLAG_MMI
Definition: cpu.h:77
checkasm_check_jpeg2000dsp
void checkasm_check_jpeg2000dsp(void)
Definition: jpeg2000dsp.c:92
checkasm_check_hevc_add_res
void checkasm_check_hevc_add_res(void)
Definition: hevc_add_res.c:87
int32_t
int32_t
Definition: audioconvert.c:56
float_near_ulp
int float_near_ulp(float a, float b, unsigned max_ulp)
Definition: checkasm.c:408
current_func_ver
CheckasmFuncVersion * current_func_ver
Definition: checkasm.c:379
check_cpu_flag
static void check_cpu_flag(const char *name, int flag)
Definition: checkasm.c:795
checkasm_context
sigjmp_buf checkasm_context
Definition: checkasm.h:71
bench_init_ffmpeg
static int bench_init_ffmpeg(void)
Definition: checkasm.c:857
checkasm_check_rv34dsp
void checkasm_check_rv34dsp(void)
Definition: rv34dsp.c:82
CheckasmFunc::versions
CheckasmFuncVersion versions
Definition: checkasm.c:370
isatty
#define isatty(fd)
Definition: checkasm.c:94
avg_cycles_per_call
static double avg_cycles_per_call(const CheckasmPerf *const p)
Definition: checkasm.c:607
AV_CPU_FLAG_RVV_I64
#define AV_CPU_FLAG_RVV_I64
Vectors of 64-bit int's *‍/.
Definition: cpu.h:92
CheckasmFunc::name
char name[1]
Definition: checkasm.c:372
checkasm_check_vvc_alf
void checkasm_check_vvc_alf(void)
Definition: vvc_alf.c:184
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
checkasm_check_exrdsp
void checkasm_check_exrdsp(void)
Definition: exrdsp.c:77
balance_tree
static void balance_tree(CheckasmFunc **root)
Definition: checkasm.c:683
AV_CPU_FLAG_ARMV6T2
#define AV_CPU_FLAG_ARMV6T2
Definition: cpu.h:67
tsv
int tsv
Definition: checkasm.c:395
funcs
CheckasmFunc * funcs
Definition: checkasm.c:377
checkasm_check_opusdsp
void checkasm_check_opusdsp(void)
Definition: opusdsp.c:86