checkasm.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  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. #include "config.h"
  48. #include "config_components.h"
  49. #ifndef _GNU_SOURCE
  50. # define _GNU_SOURCE // for syscall (performance monitoring API), strsignal()
  51. #endif
  52. #include <signal.h>
  53. #include <stdarg.h>
  54. #include <stdio.h>
  55. #include <stdlib.h>
  56. #include <string.h>
  57. #include "checkasm.h"
  58. #include "libavutil/common.h"
  59. #include "libavutil/cpu.h"
  60. #include "libavutil/intfloat.h"
  61. #include "libavutil/random_seed.h"
  62. #if HAVE_IO_H
  63. #include <io.h>
  64. #endif
  65. #if HAVE_PRCTL
  66. #include <sys/prctl.h>
  67. #endif
  68. #if defined(_WIN32) && !defined(SIGBUS)
  69. /* non-standard, use the same value as mingw-w64 */
  70. #define SIGBUS 10
  71. #endif
  72. #if HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
  73. #include <windows.h>
  74. #define COLOR_RED FOREGROUND_RED
  75. #define COLOR_GREEN FOREGROUND_GREEN
  76. #define COLOR_YELLOW (FOREGROUND_RED|FOREGROUND_GREEN)
  77. #else
  78. #define COLOR_RED 1
  79. #define COLOR_GREEN 2
  80. #define COLOR_YELLOW 3
  81. #endif
  82. #if HAVE_UNISTD_H
  83. #include <unistd.h>
  84. #endif
  85. #if !HAVE_ISATTY
  86. #define isatty(fd) 1
  87. #endif
  88. #if ARCH_AARCH64
  89. #include "libavutil/aarch64/cpu.h"
  90. #endif
  91. #if ARCH_ARM && HAVE_ARMV5TE_EXTERNAL
  92. #include "libavutil/arm/cpu.h"
  93. void (*checkasm_checked_call)(void *func, int dummy, ...) = checkasm_checked_call_novfp;
  94. #endif
  95. /* Trade-off between speed and accuracy */
  96. uint64_t bench_runs = 1U << 10;
  97. /* List of tests to invoke */
  98. static const struct {
  99. const char *name;
  100. void (*func)(void);
  101. } tests[] = {
  102. #if CONFIG_AVCODEC
  103. #if CONFIG_AAC_DECODER
  104. { "aacpsdsp", checkasm_check_aacpsdsp },
  105. { "sbrdsp", checkasm_check_sbrdsp },
  106. #endif
  107. #if CONFIG_AAC_ENCODER
  108. { "aacencdsp", checkasm_check_aacencdsp },
  109. #endif
  110. #if CONFIG_AC3DSP
  111. { "ac3dsp", checkasm_check_ac3dsp },
  112. #endif
  113. #if CONFIG_ALAC_DECODER
  114. { "alacdsp", checkasm_check_alacdsp },
  115. #endif
  116. #if CONFIG_AUDIODSP
  117. { "audiodsp", checkasm_check_audiodsp },
  118. #endif
  119. #if CONFIG_BLOCKDSP
  120. { "blockdsp", checkasm_check_blockdsp },
  121. #endif
  122. #if CONFIG_BSWAPDSP
  123. { "bswapdsp", checkasm_check_bswapdsp },
  124. #endif
  125. #if CONFIG_DCA_DECODER
  126. { "synth_filter", checkasm_check_synth_filter },
  127. #endif
  128. #if CONFIG_EXR_DECODER
  129. { "exrdsp", checkasm_check_exrdsp },
  130. #endif
  131. #if CONFIG_FDCTDSP
  132. { "fdctdsp", checkasm_check_fdctdsp },
  133. #endif
  134. #if CONFIG_FLAC_DECODER
  135. { "flacdsp", checkasm_check_flacdsp },
  136. #endif
  137. #if CONFIG_FMTCONVERT
  138. { "fmtconvert", checkasm_check_fmtconvert },
  139. #endif
  140. #if CONFIG_G722DSP
  141. { "g722dsp", checkasm_check_g722dsp },
  142. #endif
  143. #if CONFIG_H263DSP
  144. { "h263dsp", checkasm_check_h263dsp },
  145. #endif
  146. #if CONFIG_H264CHROMA
  147. { "h264chroma", checkasm_check_h264chroma },
  148. #endif
  149. #if CONFIG_H264DSP
  150. { "h264dsp", checkasm_check_h264dsp },
  151. #endif
  152. #if CONFIG_H264PRED
  153. { "h264pred", checkasm_check_h264pred },
  154. #endif
  155. #if CONFIG_H264QPEL
  156. { "h264qpel", checkasm_check_h264qpel },
  157. #endif
  158. #if CONFIG_HEVC_DECODER
  159. { "hevc_add_res", checkasm_check_hevc_add_res },
  160. { "hevc_deblock", checkasm_check_hevc_deblock },
  161. { "hevc_idct", checkasm_check_hevc_idct },
  162. { "hevc_pel", checkasm_check_hevc_pel },
  163. { "hevc_sao", checkasm_check_hevc_sao },
  164. #endif
  165. #if CONFIG_HUFFYUV_DECODER
  166. { "huffyuvdsp", checkasm_check_huffyuvdsp },
  167. #endif
  168. #if CONFIG_IDCTDSP
  169. { "idctdsp", checkasm_check_idctdsp },
  170. #endif
  171. #if CONFIG_JPEG2000_DECODER
  172. { "jpeg2000dsp", checkasm_check_jpeg2000dsp },
  173. #endif
  174. #if CONFIG_LLAUDDSP
  175. { "llauddsp", checkasm_check_llauddsp },
  176. #endif
  177. #if CONFIG_HUFFYUVDSP
  178. { "llviddsp", checkasm_check_llviddsp },
  179. #endif
  180. #if CONFIG_LLVIDENCDSP
  181. { "llviddspenc", checkasm_check_llviddspenc },
  182. #endif
  183. #if CONFIG_LPC
  184. { "lpc", checkasm_check_lpc },
  185. #endif
  186. #if CONFIG_ME_CMP
  187. { "motion", checkasm_check_motion },
  188. #endif
  189. #if CONFIG_MPEGVIDEOENC
  190. { "mpegvideoencdsp", checkasm_check_mpegvideoencdsp },
  191. #endif
  192. #if CONFIG_OPUS_DECODER
  193. { "opusdsp", checkasm_check_opusdsp },
  194. #endif
  195. #if CONFIG_PIXBLOCKDSP
  196. { "pixblockdsp", checkasm_check_pixblockdsp },
  197. #endif
  198. #if CONFIG_RV34DSP
  199. { "rv34dsp", checkasm_check_rv34dsp },
  200. #endif
  201. #if CONFIG_RV40_DECODER
  202. { "rv40dsp", checkasm_check_rv40dsp },
  203. #endif
  204. #if CONFIG_SVQ1_ENCODER
  205. { "svq1enc", checkasm_check_svq1enc },
  206. #endif
  207. #if CONFIG_TAK_DECODER
  208. { "takdsp", checkasm_check_takdsp },
  209. #endif
  210. #if CONFIG_UTVIDEO_DECODER
  211. { "utvideodsp", checkasm_check_utvideodsp },
  212. #endif
  213. #if CONFIG_V210_DECODER
  214. { "v210dec", checkasm_check_v210dec },
  215. #endif
  216. #if CONFIG_V210_ENCODER
  217. { "v210enc", checkasm_check_v210enc },
  218. #endif
  219. #if CONFIG_VC1DSP
  220. { "vc1dsp", checkasm_check_vc1dsp },
  221. #endif
  222. #if CONFIG_VP8DSP
  223. { "vp8dsp", checkasm_check_vp8dsp },
  224. #endif
  225. #if CONFIG_VP9_DECODER
  226. { "vp9dsp", checkasm_check_vp9dsp },
  227. #endif
  228. #if CONFIG_VIDEODSP
  229. { "videodsp", checkasm_check_videodsp },
  230. #endif
  231. #if CONFIG_VORBIS_DECODER
  232. { "vorbisdsp", checkasm_check_vorbisdsp },
  233. #endif
  234. #if CONFIG_VVC_DECODER
  235. { "vvc_alf", checkasm_check_vvc_alf },
  236. { "vvc_mc", checkasm_check_vvc_mc },
  237. #endif
  238. #endif
  239. #if CONFIG_AVFILTER
  240. #if CONFIG_AFIR_FILTER
  241. { "af_afir", checkasm_check_afir },
  242. #endif
  243. #if CONFIG_BLEND_FILTER
  244. { "vf_blend", checkasm_check_blend },
  245. #endif
  246. #if CONFIG_BWDIF_FILTER
  247. { "vf_bwdif", checkasm_check_vf_bwdif },
  248. #endif
  249. #if CONFIG_COLORSPACE_FILTER
  250. { "vf_colorspace", checkasm_check_colorspace },
  251. #endif
  252. #if CONFIG_EQ_FILTER
  253. { "vf_eq", checkasm_check_vf_eq },
  254. #endif
  255. #if CONFIG_GBLUR_FILTER
  256. { "vf_gblur", checkasm_check_vf_gblur },
  257. #endif
  258. #if CONFIG_HFLIP_FILTER
  259. { "vf_hflip", checkasm_check_vf_hflip },
  260. #endif
  261. #if CONFIG_NLMEANS_FILTER
  262. { "vf_nlmeans", checkasm_check_nlmeans },
  263. #endif
  264. #if CONFIG_THRESHOLD_FILTER
  265. { "vf_threshold", checkasm_check_vf_threshold },
  266. #endif
  267. #if CONFIG_SOBEL_FILTER
  268. { "vf_sobel", checkasm_check_vf_sobel },
  269. #endif
  270. #endif
  271. #if CONFIG_SWSCALE
  272. { "sw_gbrp", checkasm_check_sw_gbrp },
  273. { "sw_range_convert", checkasm_check_sw_range_convert },
  274. { "sw_rgb", checkasm_check_sw_rgb },
  275. { "sw_scale", checkasm_check_sw_scale },
  276. { "sw_yuv2rgb", checkasm_check_sw_yuv2rgb },
  277. { "sw_yuv2yuv", checkasm_check_sw_yuv2yuv },
  278. #endif
  279. #if CONFIG_AVUTIL
  280. { "fixed_dsp", checkasm_check_fixed_dsp },
  281. { "float_dsp", checkasm_check_float_dsp },
  282. { "lls", checkasm_check_lls },
  283. { "av_tx", checkasm_check_av_tx },
  284. #endif
  285. { NULL }
  286. };
  287. /* List of cpu flags to check */
  288. static const struct {
  289. const char *name;
  290. const char *suffix;
  291. int flag;
  292. } cpus[] = {
  293. #if ARCH_AARCH64
  294. { "ARMV8", "armv8", AV_CPU_FLAG_ARMV8 },
  295. { "NEON", "neon", AV_CPU_FLAG_NEON },
  296. { "DOTPROD", "dotprod", AV_CPU_FLAG_DOTPROD },
  297. { "I8MM", "i8mm", AV_CPU_FLAG_I8MM },
  298. { "SVE", "sve", AV_CPU_FLAG_SVE },
  299. { "SVE2", "sve2", AV_CPU_FLAG_SVE2 },
  300. #elif ARCH_ARM
  301. { "ARMV5TE", "armv5te", AV_CPU_FLAG_ARMV5TE },
  302. { "ARMV6", "armv6", AV_CPU_FLAG_ARMV6 },
  303. { "ARMV6T2", "armv6t2", AV_CPU_FLAG_ARMV6T2 },
  304. { "VFP", "vfp", AV_CPU_FLAG_VFP },
  305. { "VFP_VM", "vfp_vm", AV_CPU_FLAG_VFP_VM },
  306. { "VFPV3", "vfp3", AV_CPU_FLAG_VFPV3 },
  307. { "NEON", "neon", AV_CPU_FLAG_NEON },
  308. #elif ARCH_PPC
  309. { "ALTIVEC", "altivec", AV_CPU_FLAG_ALTIVEC },
  310. { "VSX", "vsx", AV_CPU_FLAG_VSX },
  311. { "POWER8", "power8", AV_CPU_FLAG_POWER8 },
  312. #elif ARCH_RISCV
  313. { "RVI", "rvi", AV_CPU_FLAG_RVI },
  314. { "misaligned", "misaligned", AV_CPU_FLAG_RV_MISALIGNED },
  315. { "RV_zbb", "rvb_b", AV_CPU_FLAG_RVB_BASIC },
  316. { "RVB", "rvb", AV_CPU_FLAG_RVB },
  317. { "RV_zve32x","rvv_i32", AV_CPU_FLAG_RVV_I32 },
  318. { "RV_zve32f","rvv_f32", AV_CPU_FLAG_RVV_F32 },
  319. { "RV_zve64x","rvv_i64", AV_CPU_FLAG_RVV_I64 },
  320. { "RV_zve64d","rvv_f64", AV_CPU_FLAG_RVV_F64 },
  321. { "RV_zvbb", "rv_zvbb", AV_CPU_FLAG_RV_ZVBB },
  322. #elif ARCH_MIPS
  323. { "MMI", "mmi", AV_CPU_FLAG_MMI },
  324. { "MSA", "msa", AV_CPU_FLAG_MSA },
  325. #elif ARCH_X86
  326. { "MMX", "mmx", AV_CPU_FLAG_MMX|AV_CPU_FLAG_CMOV },
  327. { "MMXEXT", "mmxext", AV_CPU_FLAG_MMXEXT },
  328. { "3DNOW", "3dnow", AV_CPU_FLAG_3DNOW },
  329. { "3DNOWEXT", "3dnowext", AV_CPU_FLAG_3DNOWEXT },
  330. { "SSE", "sse", AV_CPU_FLAG_SSE },
  331. { "SSE2", "sse2", AV_CPU_FLAG_SSE2|AV_CPU_FLAG_SSE2SLOW },
  332. { "SSE3", "sse3", AV_CPU_FLAG_SSE3|AV_CPU_FLAG_SSE3SLOW },
  333. { "SSSE3", "ssse3", AV_CPU_FLAG_SSSE3|AV_CPU_FLAG_ATOM },
  334. { "SSE4.1", "sse4", AV_CPU_FLAG_SSE4 },
  335. { "SSE4.2", "sse42", AV_CPU_FLAG_SSE42 },
  336. { "AES-NI", "aesni", AV_CPU_FLAG_AESNI },
  337. { "AVX", "avx", AV_CPU_FLAG_AVX },
  338. { "XOP", "xop", AV_CPU_FLAG_XOP },
  339. { "FMA3", "fma3", AV_CPU_FLAG_FMA3 },
  340. { "FMA4", "fma4", AV_CPU_FLAG_FMA4 },
  341. { "AVX2", "avx2", AV_CPU_FLAG_AVX2 },
  342. { "AVX-512", "avx512", AV_CPU_FLAG_AVX512 },
  343. { "AVX-512ICL", "avx512icl", AV_CPU_FLAG_AVX512ICL },
  344. #elif ARCH_LOONGARCH
  345. { "LSX", "lsx", AV_CPU_FLAG_LSX },
  346. { "LASX", "lasx", AV_CPU_FLAG_LASX },
  347. #endif
  348. { NULL }
  349. };
  350. typedef struct CheckasmFuncVersion {
  351. struct CheckasmFuncVersion *next;
  352. void *func;
  353. int ok;
  354. int cpu;
  355. CheckasmPerf perf;
  356. } CheckasmFuncVersion;
  357. /* Binary search tree node */
  358. typedef struct CheckasmFunc {
  359. struct CheckasmFunc *child[2];
  360. CheckasmFuncVersion versions;
  361. uint8_t color; /* 0 = red, 1 = black */
  362. char name[1];
  363. } CheckasmFunc;
  364. /* Internal state */
  365. static struct {
  366. CheckasmFunc *funcs;
  367. CheckasmFunc *current_func;
  368. CheckasmFuncVersion *current_func_ver;
  369. const char *current_test_name;
  370. const char *bench_pattern;
  371. int bench_pattern_len;
  372. int num_checked;
  373. int num_failed;
  374. /* perf */
  375. int nop_time;
  376. int sysfd;
  377. int cpu_flag;
  378. const char *cpu_flag_name;
  379. const char *test_pattern;
  380. int verbose;
  381. int csv;
  382. int tsv;
  383. volatile sig_atomic_t catch_signals;
  384. } state;
  385. /* PRNG state */
  386. AVLFG checkasm_lfg;
  387. /* float compare support code */
  388. static int is_negative(union av_intfloat32 u)
  389. {
  390. return u.i >> 31;
  391. }
  392. int float_near_ulp(float a, float b, unsigned max_ulp)
  393. {
  394. union av_intfloat32 x, y;
  395. x.f = a;
  396. y.f = b;
  397. if (is_negative(x) != is_negative(y)) {
  398. // handle -0.0 == +0.0
  399. return a == b;
  400. }
  401. if (llabs((int64_t)x.i - y.i) <= max_ulp)
  402. return 1;
  403. return 0;
  404. }
  405. int float_near_ulp_array(const float *a, const float *b, unsigned max_ulp,
  406. unsigned len)
  407. {
  408. unsigned i;
  409. for (i = 0; i < len; i++) {
  410. if (!float_near_ulp(a[i], b[i], max_ulp))
  411. return 0;
  412. }
  413. return 1;
  414. }
  415. int float_near_abs_eps(float a, float b, float eps)
  416. {
  417. float abs_diff = fabsf(a - b);
  418. if (abs_diff < eps)
  419. return 1;
  420. fprintf(stderr, "test failed comparing %g with %g (abs diff=%g with EPS=%g)\n", a, b, abs_diff, eps);
  421. return 0;
  422. }
  423. int float_near_abs_eps_array(const float *a, const float *b, float eps,
  424. unsigned len)
  425. {
  426. unsigned i;
  427. for (i = 0; i < len; i++) {
  428. if (!float_near_abs_eps(a[i], b[i], eps))
  429. return 0;
  430. }
  431. return 1;
  432. }
  433. int float_near_abs_eps_ulp(float a, float b, float eps, unsigned max_ulp)
  434. {
  435. return float_near_ulp(a, b, max_ulp) || float_near_abs_eps(a, b, eps);
  436. }
  437. int float_near_abs_eps_array_ulp(const float *a, const float *b, float eps,
  438. unsigned max_ulp, unsigned len)
  439. {
  440. unsigned i;
  441. for (i = 0; i < len; i++) {
  442. if (!float_near_abs_eps_ulp(a[i], b[i], eps, max_ulp))
  443. return 0;
  444. }
  445. return 1;
  446. }
  447. int double_near_abs_eps(double a, double b, double eps)
  448. {
  449. double abs_diff = fabs(a - b);
  450. return abs_diff < eps;
  451. }
  452. int double_near_abs_eps_array(const double *a, const double *b, double eps,
  453. unsigned len)
  454. {
  455. unsigned i;
  456. for (i = 0; i < len; i++) {
  457. if (!double_near_abs_eps(a[i], b[i], eps))
  458. return 0;
  459. }
  460. return 1;
  461. }
  462. /* Print colored text to stderr if the terminal supports it */
  463. static void color_printf(int color, const char *fmt, ...)
  464. {
  465. static int use_color = -1;
  466. va_list arg;
  467. #if HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
  468. static HANDLE con;
  469. static WORD org_attributes;
  470. if (use_color < 0) {
  471. CONSOLE_SCREEN_BUFFER_INFO con_info;
  472. con = GetStdHandle(STD_ERROR_HANDLE);
  473. if (con && con != INVALID_HANDLE_VALUE && GetConsoleScreenBufferInfo(con, &con_info)) {
  474. org_attributes = con_info.wAttributes;
  475. use_color = 1;
  476. } else
  477. use_color = 0;
  478. }
  479. if (use_color)
  480. SetConsoleTextAttribute(con, (org_attributes & 0xfff0) | (color & 0x0f));
  481. #else
  482. if (use_color < 0) {
  483. const char *term = getenv("TERM");
  484. use_color = term && strcmp(term, "dumb") && isatty(2);
  485. }
  486. if (use_color)
  487. fprintf(stderr, "\x1b[%d;3%dm", (color & 0x08) >> 3, color & 0x07);
  488. #endif
  489. va_start(arg, fmt);
  490. vfprintf(stderr, fmt, arg);
  491. va_end(arg);
  492. if (use_color) {
  493. #if HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
  494. SetConsoleTextAttribute(con, org_attributes);
  495. #else
  496. fprintf(stderr, "\x1b[0m");
  497. #endif
  498. }
  499. }
  500. /* Deallocate a tree */
  501. static void destroy_func_tree(CheckasmFunc *f)
  502. {
  503. if (f) {
  504. CheckasmFuncVersion *v = f->versions.next;
  505. while (v) {
  506. CheckasmFuncVersion *next = v->next;
  507. free(v);
  508. v = next;
  509. }
  510. destroy_func_tree(f->child[0]);
  511. destroy_func_tree(f->child[1]);
  512. free(f);
  513. }
  514. }
  515. /* Allocate a zero-initialized block, clean up and exit on failure */
  516. static void *checkasm_malloc(size_t size)
  517. {
  518. void *ptr = calloc(1, size);
  519. if (!ptr) {
  520. fprintf(stderr, "checkasm: malloc failed\n");
  521. destroy_func_tree(state.funcs);
  522. exit(1);
  523. }
  524. return ptr;
  525. }
  526. /* Get the suffix of the specified cpu flag */
  527. static const char *cpu_suffix(int cpu)
  528. {
  529. int i = FF_ARRAY_ELEMS(cpus);
  530. while (--i >= 0)
  531. if (cpu & cpus[i].flag)
  532. return cpus[i].suffix;
  533. return "c";
  534. }
  535. static int cmp_nop(const void *a, const void *b)
  536. {
  537. return *(const uint16_t*)a - *(const uint16_t*)b;
  538. }
  539. /* Measure the overhead of the timing code (in decicycles) */
  540. static int measure_nop_time(void)
  541. {
  542. uint16_t nops[10000];
  543. int i, nop_sum = 0;
  544. av_unused const int sysfd = state.sysfd;
  545. uint64_t t = 0;
  546. for (i = 0; i < 10000; i++) {
  547. PERF_START(t);
  548. PERF_STOP(t);
  549. nops[i] = t;
  550. }
  551. qsort(nops, 10000, sizeof(uint16_t), cmp_nop);
  552. for (i = 2500; i < 7500; i++)
  553. nop_sum += nops[i];
  554. return nop_sum / 500;
  555. }
  556. static inline double avg_cycles_per_call(const CheckasmPerf *const p)
  557. {
  558. if (p->iterations) {
  559. const double cycles = (double)(10 * p->cycles) / p->iterations - state.nop_time;
  560. if (cycles > 0.0)
  561. return cycles / 4.0; /* 4 calls per iteration */
  562. }
  563. return 0.0;
  564. }
  565. /* Print benchmark results */
  566. static void print_benchs(CheckasmFunc *f)
  567. {
  568. if (f) {
  569. print_benchs(f->child[0]);
  570. /* Only print functions with at least one assembly version */
  571. if (f->versions.cpu || f->versions.next) {
  572. CheckasmFuncVersion *v = &f->versions;
  573. const CheckasmPerf *p = &v->perf;
  574. const double baseline = avg_cycles_per_call(p);
  575. double decicycles;
  576. do {
  577. if (p->iterations) {
  578. p = &v->perf;
  579. decicycles = avg_cycles_per_call(p);
  580. if (state.csv || state.tsv) {
  581. const char sep = state.csv ? ',' : '\t';
  582. printf("%s%c%s%c%.1f\n", f->name, sep,
  583. cpu_suffix(v->cpu), sep,
  584. decicycles / 10.0);
  585. } else {
  586. const int pad_length = 10 + 50 -
  587. printf("%s_%s:", f->name, cpu_suffix(v->cpu));
  588. const double ratio = decicycles ?
  589. baseline / decicycles : 0.0;
  590. printf("%*.1f (%5.2fx)\n", FFMAX(pad_length, 0),
  591. decicycles / 10.0, ratio);
  592. }
  593. }
  594. } while ((v = v->next));
  595. }
  596. print_benchs(f->child[1]);
  597. }
  598. }
  599. /* ASCIIbetical sort except preserving natural order for numbers */
  600. static int cmp_func_names(const char *a, const char *b)
  601. {
  602. const char *start = a;
  603. int ascii_diff, digit_diff;
  604. for (; !(ascii_diff = *(const unsigned char*)a - *(const unsigned char*)b) && *a; a++, b++);
  605. for (; av_isdigit(*a) && av_isdigit(*b); a++, b++);
  606. if (a > start && av_isdigit(a[-1]) && (digit_diff = av_isdigit(*a) - av_isdigit(*b)))
  607. return digit_diff;
  608. return ascii_diff;
  609. }
  610. /* Perform a tree rotation in the specified direction and return the new root */
  611. static CheckasmFunc *rotate_tree(CheckasmFunc *f, int dir)
  612. {
  613. CheckasmFunc *r = f->child[dir^1];
  614. f->child[dir^1] = r->child[dir];
  615. r->child[dir] = f;
  616. r->color = f->color;
  617. f->color = 0;
  618. return r;
  619. }
  620. #define is_red(f) ((f) && !(f)->color)
  621. /* Balance a left-leaning red-black tree at the specified node */
  622. static void balance_tree(CheckasmFunc **root)
  623. {
  624. CheckasmFunc *f = *root;
  625. if (is_red(f->child[0]) && is_red(f->child[1])) {
  626. f->color ^= 1;
  627. f->child[0]->color = f->child[1]->color = 1;
  628. }
  629. if (!is_red(f->child[0]) && is_red(f->child[1]))
  630. *root = rotate_tree(f, 0); /* Rotate left */
  631. else if (is_red(f->child[0]) && is_red(f->child[0]->child[0]))
  632. *root = rotate_tree(f, 1); /* Rotate right */
  633. }
  634. /* Get a node with the specified name, creating it if it doesn't exist */
  635. static CheckasmFunc *get_func(CheckasmFunc **root, const char *name)
  636. {
  637. CheckasmFunc *f = *root;
  638. if (f) {
  639. /* Search the tree for a matching node */
  640. int cmp = cmp_func_names(name, f->name);
  641. if (cmp) {
  642. f = get_func(&f->child[cmp > 0], name);
  643. /* Rebalance the tree on the way up if a new node was inserted */
  644. if (!f->versions.func)
  645. balance_tree(root);
  646. }
  647. } else {
  648. /* Allocate and insert a new node into the tree */
  649. int name_length = strlen(name);
  650. f = *root = checkasm_malloc(sizeof(CheckasmFunc) + name_length);
  651. memcpy(f->name, name, name_length + 1);
  652. }
  653. return f;
  654. }
  655. checkasm_context checkasm_context_buf;
  656. /* Crash handling: attempt to catch crashes and handle them
  657. * gracefully instead of just aborting abruptly. */
  658. #ifdef _WIN32
  659. #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
  660. static LONG NTAPI signal_handler(EXCEPTION_POINTERS *e) {
  661. int s;
  662. if (!state.catch_signals)
  663. return EXCEPTION_CONTINUE_SEARCH;
  664. switch (e->ExceptionRecord->ExceptionCode) {
  665. case EXCEPTION_FLT_DIVIDE_BY_ZERO:
  666. case EXCEPTION_INT_DIVIDE_BY_ZERO:
  667. s = SIGFPE;
  668. break;
  669. case EXCEPTION_ILLEGAL_INSTRUCTION:
  670. case EXCEPTION_PRIV_INSTRUCTION:
  671. s = SIGILL;
  672. break;
  673. case EXCEPTION_ACCESS_VIOLATION:
  674. case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
  675. case EXCEPTION_DATATYPE_MISALIGNMENT:
  676. case EXCEPTION_STACK_OVERFLOW:
  677. s = SIGSEGV;
  678. break;
  679. case EXCEPTION_IN_PAGE_ERROR:
  680. s = SIGBUS;
  681. break;
  682. default:
  683. return EXCEPTION_CONTINUE_SEARCH;
  684. }
  685. state.catch_signals = 0;
  686. checkasm_load_context(s);
  687. return EXCEPTION_CONTINUE_EXECUTION; /* never reached, but shuts up gcc */
  688. }
  689. #endif
  690. #else
  691. static void signal_handler(int s);
  692. static const struct sigaction signal_handler_act = {
  693. .sa_handler = signal_handler,
  694. .sa_flags = SA_RESETHAND,
  695. };
  696. static void signal_handler(int s) {
  697. if (state.catch_signals) {
  698. state.catch_signals = 0;
  699. sigaction(s, &signal_handler_act, NULL);
  700. checkasm_load_context(s);
  701. }
  702. }
  703. #endif
  704. /* Compares a string with a wildcard pattern. */
  705. static int wildstrcmp(const char *str, const char *pattern)
  706. {
  707. const char *wild = strchr(pattern, '*');
  708. if (wild) {
  709. const size_t len = wild - pattern;
  710. if (strncmp(str, pattern, len)) return 1;
  711. while (*++wild == '*');
  712. if (!*wild) return 0;
  713. str += len;
  714. while (*str && wildstrcmp(str, wild)) str++;
  715. return !*str;
  716. }
  717. return strcmp(str, pattern);
  718. }
  719. /* Perform tests and benchmarks for the specified cpu flag if supported by the host */
  720. static void check_cpu_flag(const char *name, int flag)
  721. {
  722. int old_cpu_flag = state.cpu_flag;
  723. flag |= old_cpu_flag;
  724. av_force_cpu_flags(-1);
  725. state.cpu_flag = flag & av_get_cpu_flags();
  726. av_force_cpu_flags(state.cpu_flag);
  727. if (!flag || state.cpu_flag != old_cpu_flag) {
  728. int i;
  729. state.cpu_flag_name = name;
  730. for (i = 0; tests[i].func; i++) {
  731. if (state.test_pattern && wildstrcmp(tests[i].name, state.test_pattern))
  732. continue;
  733. state.current_test_name = tests[i].name;
  734. tests[i].func();
  735. }
  736. }
  737. }
  738. /* Print the name of the current CPU flag, but only do it once */
  739. static void print_cpu_name(void)
  740. {
  741. if (state.cpu_flag_name) {
  742. color_printf(COLOR_YELLOW, "%s:\n", state.cpu_flag_name);
  743. state.cpu_flag_name = NULL;
  744. }
  745. }
  746. #if CONFIG_LINUX_PERF
  747. static int bench_init_linux(void)
  748. {
  749. struct perf_event_attr attr = {
  750. .type = PERF_TYPE_HARDWARE,
  751. .size = sizeof(struct perf_event_attr),
  752. .config = PERF_COUNT_HW_CPU_CYCLES,
  753. .disabled = 1, // start counting only on demand
  754. .exclude_kernel = 1,
  755. .exclude_hv = 1,
  756. #if !ARCH_X86
  757. .exclude_guest = 1,
  758. #endif
  759. };
  760. fprintf(stderr, "benchmarking with Linux Perf Monitoring API\n");
  761. state.sysfd = syscall(__NR_perf_event_open, &attr, 0, -1, -1, 0);
  762. if (state.sysfd == -1) {
  763. perror("perf_event_open");
  764. return -1;
  765. }
  766. return 0;
  767. }
  768. #elif CONFIG_MACOS_KPERF
  769. static int bench_init_kperf(void)
  770. {
  771. ff_kperf_init();
  772. return 0;
  773. }
  774. #else
  775. static int bench_init_ffmpeg(void)
  776. {
  777. #ifdef AV_READ_TIME
  778. if (!checkasm_save_context()) {
  779. checkasm_set_signal_handler_state(1);
  780. AV_READ_TIME();
  781. checkasm_set_signal_handler_state(0);
  782. } else {
  783. fprintf(stderr, "checkasm: unable to execute platform specific timer\n");
  784. return -1;
  785. }
  786. fprintf(stderr, "benchmarking with native FFmpeg timers\n");
  787. return 0;
  788. #else
  789. fprintf(stderr, "checkasm: --bench is not supported on your system\n");
  790. return -1;
  791. #endif
  792. }
  793. #endif
  794. static int bench_init(void)
  795. {
  796. #if CONFIG_LINUX_PERF
  797. int ret = bench_init_linux();
  798. #elif CONFIG_MACOS_KPERF
  799. int ret = bench_init_kperf();
  800. #else
  801. int ret = bench_init_ffmpeg();
  802. #endif
  803. if (ret < 0)
  804. return ret;
  805. state.nop_time = measure_nop_time();
  806. fprintf(stderr, "nop: %d.%d\n", state.nop_time/10, state.nop_time%10);
  807. return 0;
  808. }
  809. static void bench_uninit(void)
  810. {
  811. #if CONFIG_LINUX_PERF
  812. close(state.sysfd);
  813. #endif
  814. }
  815. static int usage(const char *path)
  816. {
  817. fprintf(stderr,
  818. "Usage: %s [options...] [seed]\n"
  819. " --test=<pattern> Run specific test.\n"
  820. " --bench Run benchmark.\n"
  821. " --csv, --tsv Output results in rows of comma or tab separated values.\n"
  822. " --runs=<ptwo> Manual number of benchmark iterations to run 2**<ptwo>.\n"
  823. " --verbose Increase verbosity.\n",
  824. path);
  825. return 1;
  826. }
  827. int main(int argc, char *argv[])
  828. {
  829. unsigned int seed = av_get_random_seed();
  830. int i, ret = 0;
  831. char arch_info_buf[50] = "";
  832. #ifdef _WIN32
  833. #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
  834. AddVectoredExceptionHandler(0, signal_handler);
  835. #endif
  836. #else
  837. sigaction(SIGBUS, &signal_handler_act, NULL);
  838. sigaction(SIGFPE, &signal_handler_act, NULL);
  839. sigaction(SIGILL, &signal_handler_act, NULL);
  840. sigaction(SIGSEGV, &signal_handler_act, NULL);
  841. #endif
  842. #if HAVE_PRCTL && defined(PR_SET_UNALIGN)
  843. prctl(PR_SET_UNALIGN, PR_UNALIGN_SIGBUS);
  844. #endif
  845. #if ARCH_ARM && HAVE_ARMV5TE_EXTERNAL
  846. if (have_vfp(av_get_cpu_flags()) || have_neon(av_get_cpu_flags()))
  847. checkasm_checked_call = checkasm_checked_call_vfp;
  848. #endif
  849. if (!tests[0].func || !cpus[0].flag) {
  850. fprintf(stderr, "checkasm: no tests to perform\n");
  851. return 0;
  852. }
  853. for (i = 1; i < argc; i++) {
  854. const char *arg = argv[i];
  855. unsigned long l;
  856. char *end;
  857. if (!strncmp(arg, "--bench", 7)) {
  858. if (bench_init() < 0)
  859. return 1;
  860. if (arg[7] == '=') {
  861. state.bench_pattern = arg + 8;
  862. state.bench_pattern_len = strlen(state.bench_pattern);
  863. } else
  864. state.bench_pattern = "*";
  865. } else if (!strncmp(arg, "--test=", 7)) {
  866. state.test_pattern = arg + 7;
  867. } else if (!strcmp(arg, "--csv")) {
  868. state.csv = 1; state.tsv = 0;
  869. } else if (!strcmp(arg, "--tsv")) {
  870. state.csv = 0; state.tsv = 1;
  871. } else if (!strcmp(arg, "--verbose") || !strcmp(arg, "-v")) {
  872. state.verbose = 1;
  873. } else if (!strncmp(arg, "--runs=", 7)) {
  874. l = strtoul(arg + 7, &end, 10);
  875. if (*end == '\0') {
  876. if (l > 30) {
  877. fprintf(stderr, "checkasm: error: runs exponent must be within the range 0 <= 30\n");
  878. usage(argv[0]);
  879. }
  880. bench_runs = 1U << l;
  881. } else {
  882. return usage(argv[0]);
  883. }
  884. } else if ((l = strtoul(arg, &end, 10)) <= UINT_MAX &&
  885. *end == '\0') {
  886. seed = l;
  887. } else {
  888. return usage(argv[0]);
  889. }
  890. }
  891. #if ARCH_AARCH64 && HAVE_SVE
  892. if (have_sve(av_get_cpu_flags()))
  893. snprintf(arch_info_buf, sizeof(arch_info_buf),
  894. "SVE %d bits, ", 8 * ff_aarch64_sve_length());
  895. #endif
  896. fprintf(stderr, "checkasm: %susing random seed %u\n", arch_info_buf, seed);
  897. av_lfg_init(&checkasm_lfg, seed);
  898. if (state.bench_pattern)
  899. fprintf(stderr, "checkasm: bench runs %" PRIu64 " (1 << %i)\n", bench_runs, av_log2(bench_runs));
  900. check_cpu_flag(NULL, 0);
  901. for (i = 0; cpus[i].flag; i++)
  902. check_cpu_flag(cpus[i].name, cpus[i].flag);
  903. if (state.num_failed) {
  904. fprintf(stderr, "checkasm: %d of %d tests have failed\n", state.num_failed, state.num_checked);
  905. ret = 1;
  906. } else {
  907. fprintf(stderr, "checkasm: all %d tests passed\n", state.num_checked);
  908. if (state.bench_pattern) {
  909. print_benchs(state.funcs);
  910. }
  911. }
  912. destroy_func_tree(state.funcs);
  913. bench_uninit();
  914. return ret;
  915. }
  916. /* Decide whether or not the specified function needs to be tested and
  917. * allocate/initialize data structures if needed. Returns a pointer to a
  918. * reference function if the function should be tested, otherwise NULL */
  919. void *checkasm_check_func(void *func, const char *name, ...)
  920. {
  921. char name_buf[256];
  922. void *ref = func;
  923. CheckasmFuncVersion *v;
  924. int name_length;
  925. va_list arg;
  926. va_start(arg, name);
  927. name_length = vsnprintf(name_buf, sizeof(name_buf), name, arg);
  928. va_end(arg);
  929. if (!func || name_length <= 0 || name_length >= sizeof(name_buf))
  930. return NULL;
  931. state.current_func = get_func(&state.funcs, name_buf);
  932. state.funcs->color = 1;
  933. v = &state.current_func->versions;
  934. if (v->func) {
  935. CheckasmFuncVersion *prev;
  936. do {
  937. /* Only test functions that haven't already been tested */
  938. if (v->func == func)
  939. return NULL;
  940. if (v->ok)
  941. ref = v->func;
  942. prev = v;
  943. } while ((v = v->next));
  944. v = prev->next = checkasm_malloc(sizeof(CheckasmFuncVersion));
  945. }
  946. v->func = func;
  947. v->ok = 1;
  948. v->cpu = state.cpu_flag;
  949. state.current_func_ver = v;
  950. if (state.cpu_flag)
  951. state.num_checked++;
  952. return ref;
  953. }
  954. /* Decide whether or not the current function needs to be benchmarked */
  955. int checkasm_bench_func(void)
  956. {
  957. return !state.num_failed && state.bench_pattern &&
  958. !wildstrcmp(state.current_func->name, state.bench_pattern);
  959. }
  960. /* Indicate that the current test has failed */
  961. void checkasm_fail_func(const char *msg, ...)
  962. {
  963. if (state.current_func_ver && state.current_func_ver->cpu &&
  964. state.current_func_ver->ok)
  965. {
  966. va_list arg;
  967. print_cpu_name();
  968. fprintf(stderr, " %s_%s (", state.current_func->name, cpu_suffix(state.current_func_ver->cpu));
  969. va_start(arg, msg);
  970. vfprintf(stderr, msg, arg);
  971. va_end(arg);
  972. fprintf(stderr, ")\n");
  973. state.current_func_ver->ok = 0;
  974. state.num_failed++;
  975. }
  976. }
  977. void checkasm_set_signal_handler_state(int enabled) {
  978. state.catch_signals = enabled;
  979. }
  980. int checkasm_handle_signal(int s) {
  981. if (s) {
  982. #ifdef __GLIBC__
  983. checkasm_fail_func("fatal signal %d: %s", s, strsignal(s));
  984. #else
  985. checkasm_fail_func(s == SIGFPE ? "fatal arithmetic error" :
  986. s == SIGILL ? "illegal instruction" :
  987. s == SIGBUS ? "bus error" :
  988. "segmentation fault");
  989. #endif
  990. }
  991. return s;
  992. }
  993. /* Get the benchmark context of the current function */
  994. CheckasmPerf *checkasm_get_perf_context(void)
  995. {
  996. CheckasmPerf *perf = &state.current_func_ver->perf;
  997. memset(perf, 0, sizeof(*perf));
  998. perf->sysfd = state.sysfd;
  999. return perf;
  1000. }
  1001. /* Print the outcome of all tests performed since the last time this function was called */
  1002. void checkasm_report(const char *name, ...)
  1003. {
  1004. static int prev_checked, prev_failed, max_length;
  1005. if (state.num_checked > prev_checked) {
  1006. int pad_length = max_length + 4;
  1007. va_list arg;
  1008. print_cpu_name();
  1009. pad_length -= fprintf(stderr, " - %s.", state.current_test_name);
  1010. va_start(arg, name);
  1011. pad_length -= vfprintf(stderr, name, arg);
  1012. va_end(arg);
  1013. fprintf(stderr, "%*c", FFMAX(pad_length, 0) + 2, '[');
  1014. if (state.num_failed == prev_failed)
  1015. color_printf(COLOR_GREEN, "OK");
  1016. else
  1017. color_printf(COLOR_RED, "FAILED");
  1018. fprintf(stderr, "]\n");
  1019. prev_checked = state.num_checked;
  1020. prev_failed = state.num_failed;
  1021. } else if (!state.cpu_flag) {
  1022. /* Calculate the amount of padding required to make the output vertically aligned */
  1023. int length = strlen(state.current_test_name);
  1024. va_list arg;
  1025. va_start(arg, name);
  1026. length += vsnprintf(NULL, 0, name, arg);
  1027. va_end(arg);
  1028. if (length > max_length)
  1029. max_length = length;
  1030. }
  1031. }
  1032. #define DEF_CHECKASM_CHECK_FUNC(type, fmt) \
  1033. int checkasm_check_##type(const char *file, int line, \
  1034. const type *buf1, ptrdiff_t stride1, \
  1035. const type *buf2, ptrdiff_t stride2, \
  1036. int w, int h, const char *name) \
  1037. { \
  1038. int y = 0; \
  1039. stride1 /= sizeof(*buf1); \
  1040. stride2 /= sizeof(*buf2); \
  1041. for (y = 0; y < h; y++) \
  1042. if (memcmp(&buf1[y*stride1], &buf2[y*stride2], w*sizeof(*buf1))) \
  1043. break; \
  1044. if (y == h) \
  1045. return 0; \
  1046. checkasm_fail_func("%s:%d", file, line); \
  1047. if (!state.verbose) \
  1048. return 1; \
  1049. fprintf(stderr, "%s:\n", name); \
  1050. while (h--) { \
  1051. for (int x = 0; x < w; x++) \
  1052. fprintf(stderr, " " fmt, buf1[x]); \
  1053. fprintf(stderr, " "); \
  1054. for (int x = 0; x < w; x++) \
  1055. fprintf(stderr, " " fmt, buf2[x]); \
  1056. fprintf(stderr, " "); \
  1057. for (int x = 0; x < w; x++) \
  1058. fprintf(stderr, "%c", buf1[x] != buf2[x] ? 'x' : '.'); \
  1059. buf1 += stride1; \
  1060. buf2 += stride2; \
  1061. fprintf(stderr, "\n"); \
  1062. } \
  1063. return 1; \
  1064. }
  1065. DEF_CHECKASM_CHECK_FUNC(uint8_t, "%02x")
  1066. DEF_CHECKASM_CHECK_FUNC(uint16_t, "%04x")
  1067. DEF_CHECKASM_CHECK_FUNC(uint32_t, "%08x")
  1068. DEF_CHECKASM_CHECK_FUNC(int16_t, "%6d")
  1069. DEF_CHECKASM_CHECK_FUNC(int32_t, "%9d")