OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches

SIMD abstraction layer for vectorized arithmetic operations. More...

#include <cstddef>
#include <cmath>
#include <algorithm>
#include <cassert>
Include dependency graph for SIMD.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  openswmm
 
namespace  openswmm::simd
 
namespace  openswmm::fastmath
 

Macros

#define OPENSWMM_RESTRICT   __restrict__
 
#define OPENSWMM_IVDEP
 
#define OPENSWMM_SIMD_SCALAR   1
 
#define OPENSWMM_SIMD_WIDTH   1
 Scalar fallback.
 

Functions

void openswmm::simd::add (const double *OPENSWMM_RESTRICT a, const double *OPENSWMM_RESTRICT b, double *OPENSWMM_RESTRICT dst, std::size_t n) noexcept
 Compute dst[i] = a[i] + b[i] over n doubles.
 
void openswmm::simd::multiply (const double *OPENSWMM_RESTRICT a, const double *OPENSWMM_RESTRICT b, double *OPENSWMM_RESTRICT dst, std::size_t n) noexcept
 Compute dst[i] = a[i] * b[i] over n doubles.
 
double openswmm::simd::min (const double *a, std::size_t n) noexcept
 Reduce an array to its minimum value.
 
double openswmm::simd::max (const double *a, std::size_t n) noexcept
 Reduce an array to its maximum value.
 
void openswmm::simd::clamp (double *a, double lo, double hi, std::size_t n) noexcept
 Clamp each array element in place to an inclusive interval.
 
double openswmm::simd::dot (const double *OPENSWMM_RESTRICT a, const double *OPENSWMM_RESTRICT b, std::size_t n) noexcept
 Sum corresponding products from two arrays.
 
constexpr std::size_t openswmm::simd::lane_width () noexcept
 Report the compile-time number of doubles per SIMD register.
 
void openswmm::simd::sqrt_array (const double *OPENSWMM_RESTRICT a, double *OPENSWMM_RESTRICT dst, std::size_t n) noexcept
 Compute dst[i] = sqrt(a[i]) over n doubles.
 
void openswmm::simd::fabs_array (const double *OPENSWMM_RESTRICT a, double *OPENSWMM_RESTRICT dst, std::size_t n) noexcept
 Compute dst[i] = fabs(a[i]) over n doubles.
 
void openswmm::simd::fma_array (const double *OPENSWMM_RESTRICT a, const double *OPENSWMM_RESTRICT b, const double *OPENSWMM_RESTRICT c, double *OPENSWMM_RESTRICT dst, std::size_t n) noexcept
 Compute dst[i] = a[i] * b[i] + c[i] over n doubles.
 
double openswmm::fastmath::pow3_2 (double x) noexcept
 Compute the real 3/2 power using square or cube roots.
 
double openswmm::fastmath::pow5_2 (double x) noexcept
 Compute the real 5/2 power using square or cube roots.
 
double openswmm::fastmath::pow5_3 (double x) noexcept
 Compute the real 5/3 power using square or cube roots.
 
double openswmm::fastmath::pow4_3 (double x) noexcept
 Compute the real 4/3 power using square or cube roots.
 
double openswmm::fastmath::pow2_3 (double x) noexcept
 Compute the real 2/3 power using square or cube roots.
 

Detailed Description

SIMD abstraction layer for vectorized arithmetic operations.

Provides a platform-neutral interface over:

  • x86_64: AVX2 (256-bit, 4 doubles per register)
  • arm64: NEON (128-bit, 2 doubles per register)
  • Other: Scalar fallback (auto-vectorized by the compiler)

The goal is to express numerical loops in a way that the compiler can vectorize, with explicit SIMD intrinsics as hints for the most performance-critical paths.

Usage philosophy

Do NOT pepper the solver code with raw intrinsics. Instead:

  1. Write the algorithm using the SIMD helpers in this file.
  2. Let the compiler auto-vectorize as much as possible.
  3. Profile; only use explicit intrinsics for hot loops that the compiler fails to vectorize.
Note
The scalar fallback is always available. If SIMD intrinsics are unavailable at compile time, the scalar path is used automatically.
See also
tests/unit/test_simd_math.cpp
tests/benchmarks/bench_hydraulics.cpp
Author
Caleb Buahin caleb.nosp@m..bua.nosp@m.hin@g.nosp@m.mail.nosp@m..com
License
Apache-2.0

Macro Definition Documentation

◆ OPENSWMM_IVDEP

#define OPENSWMM_IVDEP

◆ OPENSWMM_RESTRICT

#define OPENSWMM_RESTRICT   __restrict__

◆ OPENSWMM_SIMD_SCALAR

#define OPENSWMM_SIMD_SCALAR   1

◆ OPENSWMM_SIMD_WIDTH

#define OPENSWMM_SIMD_WIDTH   1

Scalar fallback.