Special Relativity in Financial Modeling 1.0.0
Lorentz transforms, spacetime classification, and geodesic price paths for quantitative finance
Loading...
Searching...
No Matches
Namespaces | Functions
simd_dispatch.cpp File Reference

Runtime dispatch: routes computeBetaBatch / computeGammaBatch to the widest available SIMD kernel at process start-up. More...

#include "srfm/simd/simd_dispatch.hpp"
#include "simd_batch_detail.hpp"
#include "srfm/simd/cpu_features.hpp"
#include <vector>
#include <cstddef>
#include <memory>

Go to the source code of this file.

Namespaces

namespace  srfm
 
namespace  srfm::simd
 

Functions

std::vector< srfm::momentum::BetaVelocity > srfm::simd::computeBetaBatch (const std::vector< double > &velocities, double &running_max) noexcept
 
std::vector< srfm::momentum::LorentzFactor > srfm::simd::computeGammaBatch (const std::vector< srfm::momentum::BetaVelocity > &betas) noexcept
 Compute γ_i = 1/√(1 − β_i²) for every element.
 

Detailed Description

Runtime dispatch: routes computeBetaBatch / computeGammaBatch to the widest available SIMD kernel at process start-up.

Module: src/simd/ Owner: AGT-08 — 2026-03-01

Responsibility

Implements the two public batch functions and the BetaCalculator class declared in include/srfm/simd/simd_dispatch.hpp.

Dispatch strategy

detect_simd_level() is called once and cached by cpu_features.hpp. Based on the result, a compile-time-known function pointer is selected:

AVX512F → detail::compute_beta_avx512 / compute_gamma_avx512
AVX2    → detail::compute_beta_avx2   / compute_gamma_avx2
*       → detail::compute_beta_scalar / compute_gamma_scalar

Wrapping raw doubles into BetaVelocity / LorentzFactor

After the SIMD kernel fills a double[] buffer:

• Beta: BetaVelocity::make(d).value() — the clamp in the kernel guarantees make() always returns a value, never nullopt.

• Gamma: SimdGammaCompute::make(d) — uses the friend declaration added to LorentzFactor so that we avoid an extra sqrt() per element.

Memory layout

Intermediate double buffers are stack-allocated for N ≤ STACK_THRESHOLD and heap-allocated (std::vector<double>) for larger batches, keeping the common hot-path (N ≈ 256) stack-resident and cache-hot.

Definition in file simd_dispatch.cpp.