One checkasm to rule them all

Developers in the VideoLAN community have been working on checkasm, a reusable, cross-platform library for testing and benchmarking hand-written assembly and intrinsics against reference C code.

Originally developed for x264, checkasm has been used in various forms by other multimedia projects for years. It is now a standalone VideoLAN project, released under the 2-clause BSD licence.

dav1d switched to the standalone library in 1.5.4, dav2d uses it from day one, and FFmpeg replaced its own version in June 2026. After years of maintaining different forks, we finally have one checkasm!

Why we need checkasm

Much of the performance of modern multimedia software comes from hand-tuned SIMD kernels: motion compensation, inverse transforms, intra prediction, loop filters, CDEF, film grain, scaling, blending, and quite a few audio processing functions. In projects like FFmpeg, dav1d, x264 and VLC, we need to test and benchmark these kernels against their C implementations, on every supported architecture and ABI.

Writing them is hard, tedious, and error-prone. Verifying that they are both correct and fast is harder.

There are quite a few problems that an ordinary test suite might miss:

  • it gives the right output for common block sizes, but fails on a corner case;
  • it writes one byte past the buffer;
  • it clobbers a callee-saved register, and the caller crashes three functions later;
  • it leaves the FPU or vector state dirty, and the next piece of C code computes garbage;
  • it is correct, but slower than the C version.

The ABI and calling convention also depend on the platform: Windows x64 and System V on the same x86-64 CPU, AAPCS on ARM, the psABI on RISC-V, 32-bit and 64-bit variants of each. On Windows x64, for example, xmm6 to xmm15 are callee-saved (the low 128 bits of the corresponding wider vector registers); under the System V AMD64 ABI, they are not. An assembly function that is fine on one can silently corrupt its caller on the other. Passing the tests on x86 does not tell us whether the corresponding ARM, RISC-V or LoongArch implementation is correct.

With billions of devices running this code, even small performance improvements matter, and bugs can affect a lot of people.

A bit of history

checkasm was originally developed for x264. The idea was simple: for every DSP function, call the C version and the assembly version on the same inputs, compare the outputs, and time both.

FFmpeg and later dav1d adopted checkasm and adapted it to their own tests, build systems and platforms. Over the years, the forks diverged, and fixes and improvements made in one project did not necessarily reach the others.

The standalone checkasm is a direct descendant of the dav1d variant, with the enhancements from the FFmpeg fork merged in. We presented it at the VideoLAN Developer Days 2025 in London, as “One checkasm to rule them all”.

Why now

More assembly. dav2d, our AV2 decoder, is the first of several projects we want to do on the model of dav1d. AV2 decoding is much more complex than AV1, so we need validation and benchmarking from day one, even before writing assembly. FFmpeg also keeps adding hand-written assembly. We should not have to fork checkasm again for every new project.

Correctness. We want to test every new piece of code, on all supported platforms, before it ships.

More architectures and extensions. On ARM, we need to deal with SVE, SME and GCS. LoongArch and PowerPC need their own support, and RISC-V brings the additional complexity of variable vector lengths (more on that below).

One copy of checkasm per project was not going to scale.

One checkasm

As a library, checkasm lets each project keep its own tests and reference C implementations. The test harness, input generation helpers, comparison tools, ABI checks, timers, statistics and reports are now shared.

In dav1d (MR !1812, “tests/checkasm: switch to external checkasm”), we use checkasm as an external dependency if it is installed. Otherwise, Meson builds it as a subproject from a git submodule.

FFmpeg had maintained its own version of checkasm for years, with a large number of tests. The nice part is that only three of the existing tests needed minor changes. FFmpeg builds the vendored checkasm sources with its own build system.

Correctness and ABI checks

For each function under test, checkasm compares the optimized implementations against the reference C code.

  • Inputs. Helpers to generate pseudo-random inputs across different seeds and data patterns, so that tests can exercise pathological corner cases as well as common inputs.
  • Comparison. The C and the assembly outputs are compared automatically. On a mismatch, checkasm reports the failure and dumps the data.
  • Buffers. Padded buffers and check helpers catch writes outside the expected area, before or after the buffer.
  • Crash resilience. Signal handling and stack-smashing detection: a kernel that crashes is reported as a failed test.

A buffer underwrite, caught by the test suite of checkasm itself, looks like this:

FAILURE: underwrite_64_x86 (../tests/generic.c:56)
 - generic.underwrite [FAILED]

The faulty buffer is dumped right after, so you see where it went wrong.

A kernel can produce the right pixels and still be broken. So checkasm also checks that each SIMD kernel respects the platform ABI. It detects register misuse, illegal opcodes, and missing state cleanup.

Platform What is checked
x86, x86-64 registers, stack, AVX2 state, MMX/FPU state
ARM, ARM64 (AArch64) registers, stack, VFP state
RISC-V registers, stack, vector state
LoongArch (32 and 64) registers
PowerPC (64le) no dedicated ABI checks yet

Benchmarking

The other use of checkasm is benchmarking. We need repeatable measurements, with sub-nanosecond timing resolution where the hardware permits it, and an indication of how much we can trust the numbers.

  • Timers. Platform-specific, high-resolution timers, for cycle counting. Hardware timers on x86, ARM, LoongArch and PowerPC; on RISC-V, OS-specific fallbacks.
  • Scaling. The runtime of each benchmark scales with the complexity of the test.
  • Statistics. Robust outlier rejection, regression, confidence intervals, variance and standard deviation, histogram estimation. checkasm reports its own timing error.
  • Output. For each function, the C time, the assembly time, and the speedup. JSON and HTML reports, with the CPU and the configuration.

Here is an example from the documentation, using --verbose to benchmark dav1d’s entropy decoder on an Intel Core Ultra 7 258V (on a pretty busy system).

checkasm –verbose benchmark output: msac functions in C, SSE2 and AVX2, with cycles, nanoseconds and speedup vs ref

Yes, one SSE2 implementation is slower than its C reference, and the AVX2 implementation of another function is slower than its SSE2 version! This is why we benchmark the different implementations, rather than assuming that a newer instruction set will be faster.

When the remaining work is a few percent here and there, rough timing numbers are useless. You need numbers you can bisect on.

Making it work everywhere

Two releases were particularly important in making the dav1d version usable by other projects: 1.1.0 in January 2026 and 1.2.0 in June 2026. The latter had everything needed to replace FFmpeg’s own checkasm.

  • Independent of the host build system. It is a Meson library, but static default config headers make vendoring simple, and a standalone Makefile serves projects that do not use Meson.
  • Better checks. New buffer helpers, checkasm_check1d() and CHECK_BUF_RECT(); function variant testing, with checkasm_set_func_variant(); and a check for the Zen 4 vzeroupper bug on x86_32.
  • Better benchmarking. More reliable ARM timers, an integer overflow fixed in the statistics, and the CPU info in the reports.
  • More platforms. ARM SME and GCS, the correct VLEN on RISC-V, shared libraries on RISC-V and LoongArch, WASI. And OS/2. Yes, OS/2.

We also have docs now, with an introduction, a tutorial and all the config options, plus Doxygen comments on every public API.

The RISC-V challenge

The hardest case is the RISC-V Vector extension (RVV).

Unlike fixed-width SIMD instruction sets such as SSE, AVX and NEON, RVV has an implementation-defined vector register width (VLEN), with the number of active elements configured at runtime.

A kernel may run on machines with 128-bit, 256-bit or 512-bit vector registers, and the best tuning, unrolling and LMUL can differ a lot between them. As with ARM’s SVE, every supported vector length needs testing. With RVV, we also have fairly young hardware and toolchains.

This work was done within the VideoLAN Program of the Sovereign Tech Fund, as part of the dav1d milestones on RISC-V.

We used checkasm to validate and benchmark the RVV kernels added to dav1d in the 1.5 “Sonic” series, including tests on several real RVV boards. Here are some speedups over the C reference reported in the merge requests:

Function Hardware Speedup vs C
w_mask_420_w64_8bpc SpacemiT K1 12.01x
w_mask_444_w32_8bpc Kendryte K230 10.10x
emu_edge_w16_8bpc Kendryte K230 (VLEN=128) 5.03x
emu_edge_w16_8bpc SpacemiT K1 (VLEN=256) 5.06x
cdef_filter_8x8_11_8bpc K230, Banana Pi F3 up to 4.61x
blend_w32_16bpc K230, SpacemiT K1 5.9x to 6.1x
blend_v_w32_16bpc SpacemiT K1 7.49x
blend_h_w128_8bpc VLEN=512 variant 49.50x

The same kernel can give different results at different vector lengths, or on different microarchitectures with the same vector length. We need to test both.

These numbers are for individual kernels. For the whole decoder, dav1d is at least twice as fast as the C-only version on current RVV systems, such as the K230 and the SpacemiT K1.

What’s next

dav2d uses checkasm from day one. We are following the same development approach as dav1d: start with a clean, portable decoder, add validation early, use checkasm to validate and benchmark the optimized code, then write the SIMD for the hot paths.

We would like to see checkasm used outside multimedia too, in image processing, signal processing, compression, numerical computing and other projects with hand-written SIMD. Our ambition is to make it the reference tool for validating SIMD in open source.

At VideoLAN, we also want to maintain the tools and libraries that other multimedia projects need, not just our own players and codecs.

If your project has its own copy of checkasm, or no checkasm at all, try it.

Contributors

Huge thanks to Niklas Haas, who did most of this work: the unification, the rewrite as a library and the integrations into dav1d and FFmpeg. And to Martin Storsjö, who also made major contributions.

The standalone project is already close to 800 commits, with numerous other contributors: Cameron Cawley, Rémi Denis-Courmont, Marvin Scholz, Nathan E. Egge, Henrik Gramner, KO Myung-Hun, J. Dekker, Tyler Kim, Zhao Zhili, Brad Smith, Felix Paul Kühne, Konstantin Pavlov and Matthias Dressel. Thanks to all of them, and to everybody who reviewed along the way.

And many thanks to the Sovereign Tech Fund for funding this work.