checkasm 1.3.0
Assembly testing and benchmarking framework
Loading...
Searching...
No Matches
checkasm.h
Go to the documentation of this file.
1/*
2 * Copyright © 2025, Niklas Haas
3 * Copyright © 2018, VideoLAN and dav1d authors
4 * Copyright © 2018, Two Orioles, LLC
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
38
39#ifndef CHECKASM_CHECKASM_H
40#define CHECKASM_CHECKASM_H
41
42#include <stdint.h>
43
44#include "checkasm/attributes.h"
45
55
72#ifndef CHECKASM_HAVE_GENERIC
73 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
74 #define CHECKASM_HAVE_GENERIC 1
75 #else
76 #define CHECKASM_HAVE_GENERIC 0
77 #endif
78#endif
79 /* end of config group */
81
88typedef uint64_t CheckasmCpu;
89
96typedef uintptr_t CheckasmKey;
97
105typedef struct CheckasmCpuInfo {
106 const char *name;
107 const char *suffix;
109
120
127typedef struct CheckasmTest {
128 const char *name;
129 void (*func)(void);
130
142 void (*init)(void);
143 void (*uninit)(void);
145
160
182typedef struct CheckasmConfig {
193
201
211
222 void (*set_cpu_flags)(CheckasmCpu new_flags);
223
230 const char *test_pattern;
231
239 const char *function_pattern;
240
247 int bench;
248
258 unsigned bench_usec;
259
262
271
278
286 unsigned seed;
287
295 unsigned repeat;
296
306
312 unsigned cpu_affinity;
314
328
345
350static inline const char *checkasm_get_cpu_suffix(void)
351{
353 return info ? info->suffix : "c";
354}
355
366
377
394
415
451CHECKASM_API int checkasm_main(CheckasmConfig *config, int argc, const char *argv[]);
452
453#endif /* CHECKASM_CHECKASM_H */
Platform and compiler attribute macros.
#define CHECKASM_API
Symbol visibility attribute for public API functions.
Definition attributes.h:90
uint64_t CheckasmCpu
Opaque type representing a set of CPU feature flags.
Definition checkasm.h:88
CHECKASM_API void checkasm_list_tests(const CheckasmConfig *config)
Print available tests.
uintptr_t CheckasmKey
Opaque type used to identify function implementations.
Definition checkasm.h:96
CHECKASM_API void checkasm_list_functions(const CheckasmConfig *config)
Print available functions within tests.
static const char * checkasm_get_cpu_suffix(void)
Get the suffix for the current CPU flag, or "c" if none.
Definition checkasm.h:350
CheckasmFormat
Output format for benchmark results.
Definition checkasm.h:153
@ CHECKASM_FORMAT_PRETTY
Definition checkasm.h:154
@ CHECKASM_FORMAT_TSV
Definition checkasm.h:156
@ CHECKASM_FORMAT_HTML
Definition checkasm.h:158
@ CHECKASM_FORMAT_CSV
Definition checkasm.h:155
@ CHECKASM_FORMAT_JSON
Definition checkasm.h:157
CHECKASM_API int checkasm_run(const CheckasmConfig *config)
Run all tests and benchmarks matching the specified patterns.
CHECKASM_API void checkasm_list_cpu_flags(const CheckasmConfig *config)
Print available CPU flags to stdout.
CHECKASM_API const CheckasmCpuInfo * checkasm_get_cpu_info(void)
Get the CPU flag currently being tested.
CHECKASM_API CheckasmCpu checkasm_get_cpu_flags(void)
Get the current active set of CPU flags.
CHECKASM_API int checkasm_main(CheckasmConfig *config, int argc, const char *argv[])
Main entry point for checkasm test programs.
Configuration structure for the checkasm test suite.
Definition checkasm.h:182
int cpu_affinity_set
Enable process pinning via cpu_affinity.
Definition checkasm.h:305
int verbose
Enable verbose output.
Definition checkasm.h:270
const char * test_pattern
Pattern for filtering which tests to run.
Definition checkasm.h:230
unsigned cpu_affinity
CPU core ID for process pinning.
Definition checkasm.h:312
unsigned repeat
Number of times to repeat tests.
Definition checkasm.h:295
unsigned bench_usec
Target benchmark duration in microseconds.
Definition checkasm.h:258
CheckasmFormat format
Output format for benchmark results.
Definition checkasm.h:261
int bench
Enable benchmarking.
Definition checkasm.h:247
void(* set_cpu_flags)(CheckasmCpu new_flags)
Callback invoked when active CPU flags change.
Definition checkasm.h:222
int seed_set
Enable using the seed value.
Definition checkasm.h:277
const CheckasmCpuInfo * cpu_flags
List of CPU flags understood by the implementation.
Definition checkasm.h:192
const char * function_pattern
Pattern for filtering which functions within tests to run.
Definition checkasm.h:239
unsigned seed
Random number generator seed.
Definition checkasm.h:286
CheckasmCpu cpu
Detected CPU flags for the current system.
Definition checkasm.h:210
const CheckasmTest * tests
Array of test functions to execute.
Definition checkasm.h:200
Describes a CPU feature flag/capability.
Definition checkasm.h:105
CheckasmCpu mask
Bitmask of prior CPU flags to disable again.
Definition checkasm.h:118
CheckasmCpu flag
Definition checkasm.h:108
const char * suffix
Definition checkasm.h:107
const char * name
Definition checkasm.h:106
Describes a single test function.
Definition checkasm.h:127
void(* func)(void)
Definition checkasm.h:129
const char * name
Definition checkasm.h:128
void(* init)(void)
Optional initialization function.
Definition checkasm.h:142