POSIX Shared Memory Data Structures 1.0
High-performance lock-free data structures for inter-process communication
Loading...
Searching...
No Matches
shm_simd Namespace Reference

Classes

class  SimdArray
 Helper class for SIMD operations on shm_array. More...
 

Functions

bool is_aligned (const void *ptr, size_t alignment) noexcept
 Check if pointer is aligned to boundary.
 
float sum_floats (const float *data, size_t count) noexcept
 Vectorized sum of float array using AVX2.
 
float dot_product (const float *a, const float *b, size_t count) noexcept
 Vectorized dot product of two float arrays.
 
void scale_floats (float *data, size_t count, float scale) noexcept
 Vectorized array scaling (multiply by scalar)
 
void fma_floats (const float *a, const float *b, const float *c, float *result, size_t count) noexcept
 Vectorized FMA operation: result = a * b + c.
 
float min_float (const float *data, size_t count) noexcept
 Find minimum value in float array.
 
float max_float (const float *data, size_t count) noexcept
 Find maximum value in float array.
 
template<int distance = 1>
void prefetch_read (const void *ptr) noexcept
 Prefetch data for read.
 
void prefetch_write (void *ptr) noexcept
 Prefetch data for write.
 
void stream_store_floats (float *dest, const float *src, size_t count) noexcept
 Stream store (bypass cache) for large arrays.
 

Function Documentation

◆ dot_product()

float shm_simd::dot_product ( const float *  a,
const float *  b,
size_t  count 
)
inlinenoexcept

Vectorized dot product of two float arrays.

Parameters
aFirst array
bSecond array
countNumber of elements
Returns
Dot product a·b
Performance:
~8x faster than scalar for aligned arrays

Definition at line 94 of file shm_simd_utils.h.

Referenced by calculate_kinetic_energy_simd(), and shm_simd::SimdArray< TableType >::dot().

◆ fma_floats()

void shm_simd::fma_floats ( const float *  a,
const float *  b,
const float *  c,
float *  result,
size_t  count 
)
inlinenoexcept

Vectorized FMA operation: result = a * b + c.

Parameters
aFirst multiplicand array
bSecond multiplicand array
cAddend array
resultOutput array
countNumber of elements
Note
Uses FMA instructions if available (single rounding)

Definition at line 162 of file shm_simd_utils.h.

◆ is_aligned()

bool shm_simd::is_aligned ( const void *  ptr,
size_t  alignment 
)
inlinenoexcept

Check if pointer is aligned to boundary.

Parameters
ptrPointer to check
alignmentRequired alignment (must be power of 2)
Returns
true if aligned

Definition at line 28 of file shm_simd_utils.h.

Referenced by main(), and stream_store_floats().

◆ max_float()

float shm_simd::max_float ( const float *  data,
size_t  count 
)
inlinenoexcept

Find maximum value in float array.

Parameters
dataInput array
countNumber of elements
Returns
Maximum value

Definition at line 218 of file shm_simd_utils.h.

Referenced by shm_simd::SimdArray< TableType >::max().

◆ min_float()

float shm_simd::min_float ( const float *  data,
size_t  count 
)
inlinenoexcept

Find minimum value in float array.

Parameters
dataInput array
countNumber of elements
Returns
Minimum value

Definition at line 187 of file shm_simd_utils.h.

Referenced by shm_simd::SimdArray< TableType >::min().

◆ prefetch_read()

template<int distance = 1>
void shm_simd::prefetch_read ( const void *  ptr)
inlinenoexcept

Prefetch data for read.

Parameters
ptrAddress to prefetch
distanceHow many cache lines ahead (0-3)
Note
Hints to CPU to load data into cache

Definition at line 251 of file shm_simd_utils.h.

◆ prefetch_write()

void shm_simd::prefetch_write ( void *  ptr)
inlinenoexcept

Prefetch data for write.

Parameters
ptrAddress to prefetch
Note
Prepares cache line for modification

Definition at line 262 of file shm_simd_utils.h.

◆ scale_floats()

void shm_simd::scale_floats ( float *  data,
size_t  count,
float  scale 
)
inlinenoexcept

Vectorized array scaling (multiply by scalar)

Parameters
dataArray to scale (modified in-place)
countNumber of elements
scaleScale factor
Example:
shm_array<float> values(shm, "values", 1000);
shm_simd::scale_floats(values.data(), values.size(), 2.0f);
Fixed-size array in shared memory with zero-overhead access.
Definition shm_array.h:63
void scale_floats(float *data, size_t count, float scale) noexcept
Vectorized array scaling (multiply by scalar)

Definition at line 135 of file shm_simd_utils.h.

Referenced by calculate_kinetic_energy_simd(), and shm_simd::SimdArray< TableType >::scale().

◆ stream_store_floats()

void shm_simd::stream_store_floats ( float *  dest,
const float *  src,
size_t  count 
)
inlinenoexcept

Stream store (bypass cache) for large arrays.

Parameters
destDestination (should be 32-byte aligned)
srcSource data
countNumber of floats to copy
Note
Use for data that won't be read soon (avoids cache pollution)

Definition at line 275 of file shm_simd_utils.h.

References is_aligned().

◆ sum_floats()

float shm_simd::sum_floats ( const float *  data,
size_t  count 
)
inlinenoexcept

Vectorized sum of float array using AVX2.

Parameters
dataInput array (should be 32-byte aligned for best performance)
countNumber of elements
Returns
Sum of all elements
Note
Falls back to scalar for unaligned or small arrays
Example:
shm_array<float> temps(shm, "temperatures", 1000);
float total = shm_simd::sum_floats(temps.data(), temps.size());
float sum_floats(const float *data, size_t count) noexcept
Vectorized sum of float array using AVX2.

Definition at line 47 of file shm_simd_utils.h.

Referenced by shm_simd::SimdArray< TableType >::sum().