You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

722 lines
19KB

  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. #include <stdarg.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include "checkasm.h"
  27. #include "libavutil/common.h"
  28. #include "libavutil/cpu.h"
  29. #include "libavutil/intfloat.h"
  30. #include "libavutil/random_seed.h"
  31. #if HAVE_IO_H
  32. #include <io.h>
  33. #endif
  34. #if HAVE_SETCONSOLETEXTATTRIBUTE
  35. #include <windows.h>
  36. #define COLOR_RED FOREGROUND_RED
  37. #define COLOR_GREEN FOREGROUND_GREEN
  38. #define COLOR_YELLOW (FOREGROUND_RED|FOREGROUND_GREEN)
  39. #else
  40. #define COLOR_RED 1
  41. #define COLOR_GREEN 2
  42. #define COLOR_YELLOW 3
  43. #endif
  44. #if HAVE_UNISTD_H
  45. #include <unistd.h>
  46. #endif
  47. #if !HAVE_ISATTY
  48. #define isatty(fd) 1
  49. #endif
  50. #if ARCH_ARM && HAVE_ARMV5TE_EXTERNAL
  51. #include "libavutil/arm/cpu.h"
  52. void (*checkasm_checked_call)(void *func, int dummy, ...) = checkasm_checked_call_novfp;
  53. #endif
  54. /* List of tests to invoke */
  55. static const struct {
  56. const char *name;
  57. void (*func)(void);
  58. } tests[] = {
  59. #if CONFIG_AVCODEC
  60. #if CONFIG_AAC_DECODER
  61. { "aacpsdsp", checkasm_check_aacpsdsp },
  62. { "sbrdsp", checkasm_check_sbrdsp },
  63. #endif
  64. #if CONFIG_ALAC_DECODER
  65. { "alacdsp", checkasm_check_alacdsp },
  66. #endif
  67. #if CONFIG_AUDIODSP
  68. { "audiodsp", checkasm_check_audiodsp },
  69. #endif
  70. #if CONFIG_BLOCKDSP
  71. { "blockdsp", checkasm_check_blockdsp },
  72. #endif
  73. #if CONFIG_BSWAPDSP
  74. { "bswapdsp", checkasm_check_bswapdsp },
  75. #endif
  76. #if CONFIG_DCA_DECODER
  77. { "synth_filter", checkasm_check_synth_filter },
  78. #endif
  79. #if CONFIG_FLACDSP
  80. { "flacdsp", checkasm_check_flacdsp },
  81. #endif
  82. #if CONFIG_FMTCONVERT
  83. { "fmtconvert", checkasm_check_fmtconvert },
  84. #endif
  85. #if CONFIG_H264DSP
  86. { "h264dsp", checkasm_check_h264dsp },
  87. #endif
  88. #if CONFIG_H264PRED
  89. { "h264pred", checkasm_check_h264pred },
  90. #endif
  91. #if CONFIG_H264QPEL
  92. { "h264qpel", checkasm_check_h264qpel },
  93. #endif
  94. #if CONFIG_HEVC_DECODER
  95. { "hevc_add_res", checkasm_check_hevc_add_res },
  96. { "hevc_idct", checkasm_check_hevc_idct },
  97. #endif
  98. #if CONFIG_JPEG2000_DECODER
  99. { "jpeg2000dsp", checkasm_check_jpeg2000dsp },
  100. #endif
  101. #if CONFIG_HUFFYUVDSP
  102. { "llviddsp", checkasm_check_llviddsp },
  103. #endif
  104. #if CONFIG_PIXBLOCKDSP
  105. { "pixblockdsp", checkasm_check_pixblockdsp },
  106. #endif
  107. #if CONFIG_V210_ENCODER
  108. { "v210enc", checkasm_check_v210enc },
  109. #endif
  110. #if CONFIG_VP8DSP
  111. { "vp8dsp", checkasm_check_vp8dsp },
  112. #endif
  113. #if CONFIG_VP9_DECODER
  114. { "vp9dsp", checkasm_check_vp9dsp },
  115. #endif
  116. #if CONFIG_VIDEODSP
  117. { "videodsp", checkasm_check_videodsp },
  118. #endif
  119. #endif
  120. #if CONFIG_AVFILTER
  121. #if CONFIG_BLEND_FILTER
  122. { "vf_blend", checkasm_check_blend },
  123. #endif
  124. #if CONFIG_COLORSPACE_FILTER
  125. { "vf_colorspace", checkasm_check_colorspace },
  126. #endif
  127. #endif
  128. #if CONFIG_AVUTIL
  129. { "fixed_dsp", checkasm_check_fixed_dsp },
  130. { "float_dsp", checkasm_check_float_dsp },
  131. #endif
  132. { NULL }
  133. };
  134. /* List of cpu flags to check */
  135. static const struct {
  136. const char *name;
  137. const char *suffix;
  138. int flag;
  139. } cpus[] = {
  140. #if ARCH_AARCH64
  141. { "ARMV8", "armv8", AV_CPU_FLAG_ARMV8 },
  142. { "NEON", "neon", AV_CPU_FLAG_NEON },
  143. #elif ARCH_ARM
  144. { "ARMV5TE", "armv5te", AV_CPU_FLAG_ARMV5TE },
  145. { "ARMV6", "armv6", AV_CPU_FLAG_ARMV6 },
  146. { "ARMV6T2", "armv6t2", AV_CPU_FLAG_ARMV6T2 },
  147. { "VFP", "vfp", AV_CPU_FLAG_VFP },
  148. { "VFP_VM", "vfp_vm", AV_CPU_FLAG_VFP_VM },
  149. { "VFPV3", "vfp3", AV_CPU_FLAG_VFPV3 },
  150. { "NEON", "neon", AV_CPU_FLAG_NEON },
  151. #elif ARCH_PPC
  152. { "ALTIVEC", "altivec", AV_CPU_FLAG_ALTIVEC },
  153. { "VSX", "vsx", AV_CPU_FLAG_VSX },
  154. { "POWER8", "power8", AV_CPU_FLAG_POWER8 },
  155. #elif ARCH_X86
  156. { "MMX", "mmx", AV_CPU_FLAG_MMX|AV_CPU_FLAG_CMOV },
  157. { "MMXEXT", "mmxext", AV_CPU_FLAG_MMXEXT },
  158. { "3DNOW", "3dnow", AV_CPU_FLAG_3DNOW },
  159. { "3DNOWEXT", "3dnowext", AV_CPU_FLAG_3DNOWEXT },
  160. { "SSE", "sse", AV_CPU_FLAG_SSE },
  161. { "SSE2", "sse2", AV_CPU_FLAG_SSE2|AV_CPU_FLAG_SSE2SLOW },
  162. { "SSE3", "sse3", AV_CPU_FLAG_SSE3|AV_CPU_FLAG_SSE3SLOW },
  163. { "SSSE3", "ssse3", AV_CPU_FLAG_SSSE3|AV_CPU_FLAG_ATOM },
  164. { "SSE4.1", "sse4", AV_CPU_FLAG_SSE4 },
  165. { "SSE4.2", "sse42", AV_CPU_FLAG_SSE42 },
  166. { "AES-NI", "aesni", AV_CPU_FLAG_AESNI },
  167. { "AVX", "avx", AV_CPU_FLAG_AVX },
  168. { "XOP", "xop", AV_CPU_FLAG_XOP },
  169. { "FMA3", "fma3", AV_CPU_FLAG_FMA3 },
  170. { "FMA4", "fma4", AV_CPU_FLAG_FMA4 },
  171. { "AVX2", "avx2", AV_CPU_FLAG_AVX2 },
  172. #endif
  173. { NULL }
  174. };
  175. typedef struct CheckasmFuncVersion {
  176. struct CheckasmFuncVersion *next;
  177. void *func;
  178. int ok;
  179. int cpu;
  180. int iterations;
  181. uint64_t cycles;
  182. } CheckasmFuncVersion;
  183. /* Binary search tree node */
  184. typedef struct CheckasmFunc {
  185. struct CheckasmFunc *child[2];
  186. CheckasmFuncVersion versions;
  187. uint8_t color; /* 0 = red, 1 = black */
  188. char name[1];
  189. } CheckasmFunc;
  190. /* Internal state */
  191. static struct {
  192. CheckasmFunc *funcs;
  193. CheckasmFunc *current_func;
  194. CheckasmFuncVersion *current_func_ver;
  195. const char *current_test_name;
  196. const char *bench_pattern;
  197. int bench_pattern_len;
  198. int num_checked;
  199. int num_failed;
  200. int nop_time;
  201. int cpu_flag;
  202. const char *cpu_flag_name;
  203. const char *test_name;
  204. } state;
  205. /* PRNG state */
  206. AVLFG checkasm_lfg;
  207. /* float compare support code */
  208. static int is_negative(union av_intfloat32 u)
  209. {
  210. return u.i >> 31;
  211. }
  212. int float_near_ulp(float a, float b, unsigned max_ulp)
  213. {
  214. union av_intfloat32 x, y;
  215. x.f = a;
  216. y.f = b;
  217. if (is_negative(x) != is_negative(y)) {
  218. // handle -0.0 == +0.0
  219. return a == b;
  220. }
  221. if (llabs((int64_t)x.i - y.i) <= max_ulp)
  222. return 1;
  223. return 0;
  224. }
  225. int float_near_ulp_array(const float *a, const float *b, unsigned max_ulp,
  226. unsigned len)
  227. {
  228. unsigned i;
  229. for (i = 0; i < len; i++) {
  230. if (!float_near_ulp(a[i], b[i], max_ulp))
  231. return 0;
  232. }
  233. return 1;
  234. }
  235. int float_near_abs_eps(float a, float b, float eps)
  236. {
  237. float abs_diff = fabsf(a - b);
  238. return abs_diff < eps;
  239. }
  240. int float_near_abs_eps_array(const float *a, const float *b, float eps,
  241. unsigned len)
  242. {
  243. unsigned i;
  244. for (i = 0; i < len; i++) {
  245. if (!float_near_abs_eps(a[i], b[i], eps))
  246. return 0;
  247. }
  248. return 1;
  249. }
  250. int float_near_abs_eps_ulp(float a, float b, float eps, unsigned max_ulp)
  251. {
  252. return float_near_ulp(a, b, max_ulp) || float_near_abs_eps(a, b, eps);
  253. }
  254. int float_near_abs_eps_array_ulp(const float *a, const float *b, float eps,
  255. unsigned max_ulp, unsigned len)
  256. {
  257. unsigned i;
  258. for (i = 0; i < len; i++) {
  259. if (!float_near_abs_eps_ulp(a[i], b[i], eps, max_ulp))
  260. return 0;
  261. }
  262. return 1;
  263. }
  264. int double_near_abs_eps(double a, double b, double eps)
  265. {
  266. double abs_diff = fabs(a - b);
  267. return abs_diff < eps;
  268. }
  269. int double_near_abs_eps_array(const double *a, const double *b, double eps,
  270. unsigned len)
  271. {
  272. unsigned i;
  273. for (i = 0; i < len; i++) {
  274. if (!double_near_abs_eps(a[i], b[i], eps))
  275. return 0;
  276. }
  277. return 1;
  278. }
  279. /* Print colored text to stderr if the terminal supports it */
  280. static void color_printf(int color, const char *fmt, ...)
  281. {
  282. static int use_color = -1;
  283. va_list arg;
  284. #if HAVE_SETCONSOLETEXTATTRIBUTE
  285. static HANDLE con;
  286. static WORD org_attributes;
  287. if (use_color < 0) {
  288. CONSOLE_SCREEN_BUFFER_INFO con_info;
  289. con = GetStdHandle(STD_ERROR_HANDLE);
  290. if (con && con != INVALID_HANDLE_VALUE && GetConsoleScreenBufferInfo(con, &con_info)) {
  291. org_attributes = con_info.wAttributes;
  292. use_color = 1;
  293. } else
  294. use_color = 0;
  295. }
  296. if (use_color)
  297. SetConsoleTextAttribute(con, (org_attributes & 0xfff0) | (color & 0x0f));
  298. #else
  299. if (use_color < 0) {
  300. const char *term = getenv("TERM");
  301. use_color = term && strcmp(term, "dumb") && isatty(2);
  302. }
  303. if (use_color)
  304. fprintf(stderr, "\x1b[%d;3%dm", (color & 0x08) >> 3, color & 0x07);
  305. #endif
  306. va_start(arg, fmt);
  307. vfprintf(stderr, fmt, arg);
  308. va_end(arg);
  309. if (use_color) {
  310. #if HAVE_SETCONSOLETEXTATTRIBUTE
  311. SetConsoleTextAttribute(con, org_attributes);
  312. #else
  313. fprintf(stderr, "\x1b[0m");
  314. #endif
  315. }
  316. }
  317. /* Deallocate a tree */
  318. static void destroy_func_tree(CheckasmFunc *f)
  319. {
  320. if (f) {
  321. CheckasmFuncVersion *v = f->versions.next;
  322. while (v) {
  323. CheckasmFuncVersion *next = v->next;
  324. free(v);
  325. v = next;
  326. }
  327. destroy_func_tree(f->child[0]);
  328. destroy_func_tree(f->child[1]);
  329. free(f);
  330. }
  331. }
  332. /* Allocate a zero-initialized block, clean up and exit on failure */
  333. static void *checkasm_malloc(size_t size)
  334. {
  335. void *ptr = calloc(1, size);
  336. if (!ptr) {
  337. fprintf(stderr, "checkasm: malloc failed\n");
  338. destroy_func_tree(state.funcs);
  339. exit(1);
  340. }
  341. return ptr;
  342. }
  343. /* Get the suffix of the specified cpu flag */
  344. static const char *cpu_suffix(int cpu)
  345. {
  346. int i = FF_ARRAY_ELEMS(cpus);
  347. while (--i >= 0)
  348. if (cpu & cpus[i].flag)
  349. return cpus[i].suffix;
  350. return "c";
  351. }
  352. #ifdef AV_READ_TIME
  353. static int cmp_nop(const void *a, const void *b)
  354. {
  355. return *(const uint16_t*)a - *(const uint16_t*)b;
  356. }
  357. /* Measure the overhead of the timing code (in decicycles) */
  358. static int measure_nop_time(void)
  359. {
  360. uint16_t nops[10000];
  361. int i, nop_sum = 0;
  362. for (i = 0; i < 10000; i++) {
  363. uint64_t t = AV_READ_TIME();
  364. nops[i] = AV_READ_TIME() - t;
  365. }
  366. qsort(nops, 10000, sizeof(uint16_t), cmp_nop);
  367. for (i = 2500; i < 7500; i++)
  368. nop_sum += nops[i];
  369. return nop_sum / 500;
  370. }
  371. /* Print benchmark results */
  372. static void print_benchs(CheckasmFunc *f)
  373. {
  374. if (f) {
  375. print_benchs(f->child[0]);
  376. /* Only print functions with at least one assembly version */
  377. if (f->versions.cpu || f->versions.next) {
  378. CheckasmFuncVersion *v = &f->versions;
  379. do {
  380. if (v->iterations) {
  381. int decicycles = (10*v->cycles/v->iterations - state.nop_time) / 4;
  382. printf("%s_%s: %d.%d\n", f->name, cpu_suffix(v->cpu), decicycles/10, decicycles%10);
  383. }
  384. } while ((v = v->next));
  385. }
  386. print_benchs(f->child[1]);
  387. }
  388. }
  389. #endif
  390. /* ASCIIbetical sort except preserving natural order for numbers */
  391. static int cmp_func_names(const char *a, const char *b)
  392. {
  393. const char *start = a;
  394. int ascii_diff, digit_diff;
  395. for (; !(ascii_diff = *(const unsigned char*)a - *(const unsigned char*)b) && *a; a++, b++);
  396. for (; av_isdigit(*a) && av_isdigit(*b); a++, b++);
  397. if (a > start && av_isdigit(a[-1]) && (digit_diff = av_isdigit(*a) - av_isdigit(*b)))
  398. return digit_diff;
  399. return ascii_diff;
  400. }
  401. /* Perform a tree rotation in the specified direction and return the new root */
  402. static CheckasmFunc *rotate_tree(CheckasmFunc *f, int dir)
  403. {
  404. CheckasmFunc *r = f->child[dir^1];
  405. f->child[dir^1] = r->child[dir];
  406. r->child[dir] = f;
  407. r->color = f->color;
  408. f->color = 0;
  409. return r;
  410. }
  411. #define is_red(f) ((f) && !(f)->color)
  412. /* Balance a left-leaning red-black tree at the specified node */
  413. static void balance_tree(CheckasmFunc **root)
  414. {
  415. CheckasmFunc *f = *root;
  416. if (is_red(f->child[0]) && is_red(f->child[1])) {
  417. f->color ^= 1;
  418. f->child[0]->color = f->child[1]->color = 1;
  419. }
  420. if (!is_red(f->child[0]) && is_red(f->child[1]))
  421. *root = rotate_tree(f, 0); /* Rotate left */
  422. else if (is_red(f->child[0]) && is_red(f->child[0]->child[0]))
  423. *root = rotate_tree(f, 1); /* Rotate right */
  424. }
  425. /* Get a node with the specified name, creating it if it doesn't exist */
  426. static CheckasmFunc *get_func(CheckasmFunc **root, const char *name)
  427. {
  428. CheckasmFunc *f = *root;
  429. if (f) {
  430. /* Search the tree for a matching node */
  431. int cmp = cmp_func_names(name, f->name);
  432. if (cmp) {
  433. f = get_func(&f->child[cmp > 0], name);
  434. /* Rebalance the tree on the way up if a new node was inserted */
  435. if (!f->versions.func)
  436. balance_tree(root);
  437. }
  438. } else {
  439. /* Allocate and insert a new node into the tree */
  440. int name_length = strlen(name);
  441. f = *root = checkasm_malloc(sizeof(CheckasmFunc) + name_length);
  442. memcpy(f->name, name, name_length + 1);
  443. }
  444. return f;
  445. }
  446. /* Perform tests and benchmarks for the specified cpu flag if supported by the host */
  447. static void check_cpu_flag(const char *name, int flag)
  448. {
  449. int old_cpu_flag = state.cpu_flag;
  450. flag |= old_cpu_flag;
  451. av_force_cpu_flags(-1);
  452. state.cpu_flag = flag & av_get_cpu_flags();
  453. av_force_cpu_flags(state.cpu_flag);
  454. if (!flag || state.cpu_flag != old_cpu_flag) {
  455. int i;
  456. state.cpu_flag_name = name;
  457. for (i = 0; tests[i].func; i++) {
  458. if (state.test_name && strcmp(tests[i].name, state.test_name))
  459. continue;
  460. state.current_test_name = tests[i].name;
  461. tests[i].func();
  462. }
  463. }
  464. }
  465. /* Print the name of the current CPU flag, but only do it once */
  466. static void print_cpu_name(void)
  467. {
  468. if (state.cpu_flag_name) {
  469. color_printf(COLOR_YELLOW, "%s:\n", state.cpu_flag_name);
  470. state.cpu_flag_name = NULL;
  471. }
  472. }
  473. int main(int argc, char *argv[])
  474. {
  475. unsigned int seed = av_get_random_seed();
  476. int i, ret = 0;
  477. #if ARCH_ARM && HAVE_ARMV5TE_EXTERNAL
  478. if (have_vfp(av_get_cpu_flags()) || have_neon(av_get_cpu_flags()))
  479. checkasm_checked_call = checkasm_checked_call_vfp;
  480. #endif
  481. if (!tests[0].func || !cpus[0].flag) {
  482. fprintf(stderr, "checkasm: no tests to perform\n");
  483. return 0;
  484. }
  485. while (argc > 1) {
  486. if (!strncmp(argv[1], "--bench", 7)) {
  487. #ifndef AV_READ_TIME
  488. fprintf(stderr, "checkasm: --bench is not supported on your system\n");
  489. return 1;
  490. #endif
  491. if (argv[1][7] == '=') {
  492. state.bench_pattern = argv[1] + 8;
  493. state.bench_pattern_len = strlen(state.bench_pattern);
  494. } else
  495. state.bench_pattern = "";
  496. } else if (!strncmp(argv[1], "--test=", 7)) {
  497. state.test_name = argv[1] + 7;
  498. } else {
  499. seed = strtoul(argv[1], NULL, 10);
  500. }
  501. argc--;
  502. argv++;
  503. }
  504. fprintf(stderr, "checkasm: using random seed %u\n", seed);
  505. av_lfg_init(&checkasm_lfg, seed);
  506. check_cpu_flag(NULL, 0);
  507. for (i = 0; cpus[i].flag; i++)
  508. check_cpu_flag(cpus[i].name, cpus[i].flag);
  509. if (state.num_failed) {
  510. fprintf(stderr, "checkasm: %d of %d tests have failed\n", state.num_failed, state.num_checked);
  511. ret = 1;
  512. } else {
  513. fprintf(stderr, "checkasm: all %d tests passed\n", state.num_checked);
  514. #ifdef AV_READ_TIME
  515. if (state.bench_pattern) {
  516. state.nop_time = measure_nop_time();
  517. printf("nop: %d.%d\n", state.nop_time/10, state.nop_time%10);
  518. print_benchs(state.funcs);
  519. }
  520. #endif
  521. }
  522. destroy_func_tree(state.funcs);
  523. return ret;
  524. }
  525. /* Decide whether or not the specified function needs to be tested and
  526. * allocate/initialize data structures if needed. Returns a pointer to a
  527. * reference function if the function should be tested, otherwise NULL */
  528. void *checkasm_check_func(void *func, const char *name, ...)
  529. {
  530. char name_buf[256];
  531. void *ref = func;
  532. CheckasmFuncVersion *v;
  533. int name_length;
  534. va_list arg;
  535. va_start(arg, name);
  536. name_length = vsnprintf(name_buf, sizeof(name_buf), name, arg);
  537. va_end(arg);
  538. if (!func || name_length <= 0 || name_length >= sizeof(name_buf))
  539. return NULL;
  540. state.current_func = get_func(&state.funcs, name_buf);
  541. state.funcs->color = 1;
  542. v = &state.current_func->versions;
  543. if (v->func) {
  544. CheckasmFuncVersion *prev;
  545. do {
  546. /* Only test functions that haven't already been tested */
  547. if (v->func == func)
  548. return NULL;
  549. if (v->ok)
  550. ref = v->func;
  551. prev = v;
  552. } while ((v = v->next));
  553. v = prev->next = checkasm_malloc(sizeof(CheckasmFuncVersion));
  554. }
  555. v->func = func;
  556. v->ok = 1;
  557. v->cpu = state.cpu_flag;
  558. state.current_func_ver = v;
  559. if (state.cpu_flag)
  560. state.num_checked++;
  561. return ref;
  562. }
  563. /* Decide whether or not the current function needs to be benchmarked */
  564. int checkasm_bench_func(void)
  565. {
  566. return !state.num_failed && state.bench_pattern &&
  567. !strncmp(state.current_func->name, state.bench_pattern, state.bench_pattern_len);
  568. }
  569. /* Indicate that the current test has failed */
  570. void checkasm_fail_func(const char *msg, ...)
  571. {
  572. if (state.current_func_ver->cpu && state.current_func_ver->ok) {
  573. va_list arg;
  574. print_cpu_name();
  575. fprintf(stderr, " %s_%s (", state.current_func->name, cpu_suffix(state.current_func_ver->cpu));
  576. va_start(arg, msg);
  577. vfprintf(stderr, msg, arg);
  578. va_end(arg);
  579. fprintf(stderr, ")\n");
  580. state.current_func_ver->ok = 0;
  581. state.num_failed++;
  582. }
  583. }
  584. /* Update benchmark results of the current function */
  585. void checkasm_update_bench(int iterations, uint64_t cycles)
  586. {
  587. state.current_func_ver->iterations += iterations;
  588. state.current_func_ver->cycles += cycles;
  589. }
  590. /* Print the outcome of all tests performed since the last time this function was called */
  591. void checkasm_report(const char *name, ...)
  592. {
  593. static int prev_checked, prev_failed, max_length;
  594. if (state.num_checked > prev_checked) {
  595. int pad_length = max_length + 4;
  596. va_list arg;
  597. print_cpu_name();
  598. pad_length -= fprintf(stderr, " - %s.", state.current_test_name);
  599. va_start(arg, name);
  600. pad_length -= vfprintf(stderr, name, arg);
  601. va_end(arg);
  602. fprintf(stderr, "%*c", FFMAX(pad_length, 0) + 2, '[');
  603. if (state.num_failed == prev_failed)
  604. color_printf(COLOR_GREEN, "OK");
  605. else
  606. color_printf(COLOR_RED, "FAILED");
  607. fprintf(stderr, "]\n");
  608. prev_checked = state.num_checked;
  609. prev_failed = state.num_failed;
  610. } else if (!state.cpu_flag) {
  611. /* Calculate the amount of padding required to make the output vertically aligned */
  612. int length = strlen(state.current_test_name);
  613. va_list arg;
  614. va_start(arg, name);
  615. length += vsnprintf(NULL, 0, name, arg);
  616. va_end(arg);
  617. if (length > max_length)
  618. max_length = length;
  619. }
  620. }