A collection of C++ performance and language studies, organized as a CMake superbuild of two subprojects.
Single-Core GEMM and Top-k on ARM64 and x86-64
A cross-platform, single-core performance study of two kernel classes on two machines (Apple M4 Max / NEON, Intel i9-9880H / AVX2).
Raw GFLOPS cannot compare these machines: clocks, lane widths, and memory systems all differ. Every result is therefore reported as a fraction of the machine's own measured arithmetic ceiling:
efficiency (%) = 100 × measured GFLOPS / measured FMA ceiling (same machine)
The ceiling is measured, not quoted from a specification. A benchmark issues independent fused multiply-add chains — enough to hide FMA latency, few enough to stay in registers — and reports the sustained rate. On the M4 Max, 16 independent NEON chains of 4 lanes each yield ~136.8 GFLOPS; on the i9-9880H, only 12 chains fit in the 16 YMM registers, each 8 lanes wide, yielding ~139.0 GFLOPS. The register count already shows up here, before any kernel is written.
At a high level, the GEMM study's finding is that the hardware gap between the two machines is real but the technique closes it: before packing and blocking, the same source extracts very different fractions of each machine's ceiling; after packing and blocking, both land in the same efficiency band. The operation count is identical at every stage, so any measured difference is a difference in data movement, and nothing else.
The top-k kernels are built on two forms of hardware parallelism. Data-level parallelism (DLP): one vector operation handles several lane pairs at once, so a compare-exchange stage of the selection network processes multiple candidates in a single instruction. Instruction-level parallelism (ILP): independent vector operations can overlap in flight, so a later network stage whose inputs are ready can issue before an earlier one retires — bounded by the dependency chain of the network, not by the programmer.
The clean conclusion of the top-k study:
SIMD bitonic Top-k converts a predictable fixed selection network into high-throughput vector work. Its asymptotic description alone looks worse than a heap for variable K, but for small fixed K, deterministic latency, known output size, and data-parallel hardware, its lower and more stable practical constant can make it the better engineering kernel.
The M4/i9 measurements add a second important conclusion:
The algorithm's workload structure is portable across machines; the speed is not. Both CPUs preserve the same linear-N, deeper-with-K, data-insensitive fixed-network behavior, while their vector execution and filter-path constants differ materially.
Read the full report for the method, measurements, and findings.
| path | contents |
|---|---|
simdlabs/ |
SIMD study: kernels, benchmark harnesses, plotting scripts, figures, and the report |
basicelements/ |
smaller single-file C++ language and pattern exercises |
setup_openblas.sh |
builds the pinned single-thread OpenBLAS reference into external/ |
pipfile_linux/, pipfile_mac/ |
per-platform pipenv environments for the plotting scripts |
Requires CMake ≥ 3.22, a C++23-capable compiler, and vcpkg
(VCPKG_ROOT set or ~/vcpkg present). The SimdGemm target additionally
needs the OpenBLAS reference:
./setup_openblas.sh --x86_64 # or --arm64 on Apple Silicon
VCPKG_ROOT=~/vcpkg cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --target SimdGemm SimdTopkIlp -jBenchmark binaries land in build/; the plotting scripts in simdlabs/
consume their Google Benchmark JSON output.
The source code, benchmark harnesses, experiments, measurements, plots, and reports in this repository are the original work of Muhammad-Ali Danish (ORCID 0009-0006-8146-4983).
The GEMM kernels build on established register-tiling, packing, and cache-blocking techniques, and the top-k kernels build on the classical bitonic sorting network. The specific sources consulted are credited in the report's acknowledgements.
This repository is the public release of work developed previously in a private development repository; version 1.0.0 records the first public snapshot.
Code is licensed under the MIT License. If you use this software or its results, cite it as described in CITATION.cff.