Container System 0.1.0
High-performance C++20 type-safe container framework with SIMD-accelerated serialization
Loading...
Searching...
No Matches
kcenon::container::simd::simd_processor Class Reference

SIMD processor for vectorized operations on container values. More...

#include <simd_processor.h>

Collaboration diagram for kcenon::container::simd::simd_processor:
Collaboration graph

Static Public Member Functions

static float sum_floats (const std::vector< ValueVariant > &values)
 Sum all float values in a container using SIMD.
 
static double sum_doubles (const std::vector< ValueVariant > &values)
 Sum all double values in a container using SIMD.
 
static std::optional< float > min_float (const std::vector< ValueVariant > &values)
 Find minimum float value using SIMD.
 
static std::optional< float > max_float (const std::vector< ValueVariant > &values)
 Find maximum float value using SIMD.
 
template<typename T >
static std::optional< double > average (const std::vector< ValueVariant > &values)
 Compute average of numeric values.
 
static std::vector< size_t > find_equal_floats (const std::vector< ValueVariant > &values, float target)
 Vectorized comparison - find all values equal to target.
 
static std::vector< size_t > find_string_pattern (const std::vector< ValueVariant > &values, std::string_view pattern)
 Vectorized string search using SIMD.
 
template<typename T , typename Func >
static void transform_numeric (std::vector< ValueVariant > &values, Func &&func)
 Transform all numeric values by applying a function.
 
static std::optional< float > dot_product_floats (const std::vector< ValueVariant > &a, const std::vector< ValueVariant > &b)
 Parallel dot product of two float arrays.
 
static void fast_copy (const void *src, void *dst, size_t size)
 Fast memory copy using SIMD.
 
static bool fast_compare (const void *a, const void *b, size_t size)
 Fast memory comparison using SIMD.
 
static std::vector< std::vector< uint8_t > > parallel_serialize (const std::vector< ValueVariant > &values)
 Serialize multiple values in parallel.
 
static uint64_t simd_hash (const void *data, size_t size)
 Compute hash of data using SIMD.
 

Static Private Member Functions

static float sum_floats_scalar (const float *data, size_t count)
 
static float min_float_scalar (const float *data, size_t count)
 
static float max_float_scalar (const float *data, size_t count)
 

Detailed Description

SIMD processor for vectorized operations on container values.

Definition at line 100 of file simd_processor.h.

Member Function Documentation

◆ average()

template<typename T >
static std::optional< double > kcenon::container::simd::simd_processor::average ( const std::vector< ValueVariant > & values)
static

Compute average of numeric values.

◆ dot_product_floats()

static std::optional< float > kcenon::container::simd::simd_processor::dot_product_floats ( const std::vector< ValueVariant > & a,
const std::vector< ValueVariant > & b )
static

Parallel dot product of two float arrays.

◆ fast_compare()

bool kcenon::container::simd::simd_processor::fast_compare ( const void * a,
const void * b,
size_t size )
static

Fast memory comparison using SIMD.

Definition at line 524 of file simd_processor.cpp.

525 {
526 return std::memcmp(a, b, size) == 0;
527 }

◆ fast_copy()

void kcenon::container::simd::simd_processor::fast_copy ( const void * src,
void * dst,
size_t size )
static

Fast memory copy using SIMD.

Definition at line 518 of file simd_processor.cpp.

519 {
520 // Use standard memcpy which is often optimized with SIMD
521 std::memcpy(dst, src, size);
522 }

◆ find_equal_floats()

std::vector< size_t > kcenon::container::simd::simd_processor::find_equal_floats ( const std::vector< ValueVariant > & values,
float target )
static

Vectorized comparison - find all values equal to target.

Definition at line 502 of file simd_processor.cpp.

504 {
505 std::vector<size_t> indices;
506
507 for (size_t i = 0; i < values.size(); ++i) {
508 if (auto* f = std::get_if<float>(&values[i])) {
509 if (*f == target) {
510 indices.push_back(i);
511 }
512 }
513 }
514
515 return indices;
516 }

◆ find_string_pattern()

static std::vector< size_t > kcenon::container::simd::simd_processor::find_string_pattern ( const std::vector< ValueVariant > & values,
std::string_view pattern )
static

Vectorized string search using SIMD.

◆ max_float()

std::optional< float > kcenon::container::simd::simd_processor::max_float ( const std::vector< ValueVariant > & values)
static

Find maximum float value using SIMD.

Definition at line 476 of file simd_processor.cpp.

477 {
478 std::vector<float> floats;
479 floats.reserve(values.size());
480
481 for (const auto& val : values) {
482 if (auto* f = std::get_if<float>(&val)) {
483 floats.push_back(*f);
484 }
485 }
486
487 if (floats.empty()) return std::nullopt;
488
489 #if defined(HAS_AVX512)
490 return max_float_avx512(floats.data(), floats.size());
491 #elif defined(HAS_AVX2)
492 return max_float_avx2(floats.data(), floats.size());
493 #elif defined(HAS_X86_SIMD) && (defined(HAS_SSE2) || defined(HAS_SSE42))
494 return max_float_sse(floats.data(), floats.size());
495 #elif defined(HAS_ARM_NEON)
496 return max_float_neon(floats.data(), floats.size());
497 #else
498 return max_float_scalar(floats.data(), floats.size());
499 #endif
500 }
static float max_float_scalar(const float *data, size_t count)

References max_float_scalar().

Here is the call graph for this function:

◆ max_float_scalar()

float kcenon::container::simd::simd_processor::max_float_scalar ( const float * data,
size_t count )
staticprivate

Definition at line 43 of file simd_processor.cpp.

44 {
45 if (count == 0) return std::numeric_limits<float>::lowest();
46
47 float max_val = data[0];
48 for (size_t i = 1; i < count; ++i) {
49 if (data[i] > max_val) {
50 max_val = data[i];
51 }
52 }
53 return max_val;
54 }

Referenced by max_float().

Here is the caller graph for this function:

◆ min_float()

std::optional< float > kcenon::container::simd::simd_processor::min_float ( const std::vector< ValueVariant > & values)
static

Find minimum float value using SIMD.

Definition at line 450 of file simd_processor.cpp.

451 {
452 std::vector<float> floats;
453 floats.reserve(values.size());
454
455 for (const auto& val : values) {
456 if (auto* f = std::get_if<float>(&val)) {
457 floats.push_back(*f);
458 }
459 }
460
461 if (floats.empty()) return std::nullopt;
462
463 #if defined(HAS_AVX512)
464 return min_float_avx512(floats.data(), floats.size());
465 #elif defined(HAS_AVX2)
466 return min_float_avx2(floats.data(), floats.size());
467 #elif defined(HAS_X86_SIMD) && (defined(HAS_SSE2) || defined(HAS_SSE42))
468 return min_float_sse(floats.data(), floats.size());
469 #elif defined(HAS_ARM_NEON)
470 return min_float_neon(floats.data(), floats.size());
471 #else
472 return min_float_scalar(floats.data(), floats.size());
473 #endif
474 }
static float min_float_scalar(const float *data, size_t count)

References min_float_scalar().

Here is the call graph for this function:

◆ min_float_scalar()

float kcenon::container::simd::simd_processor::min_float_scalar ( const float * data,
size_t count )
staticprivate

Definition at line 30 of file simd_processor.cpp.

31 {
32 if (count == 0) return std::numeric_limits<float>::max();
33
34 float min_val = data[0];
35 for (size_t i = 1; i < count; ++i) {
36 if (data[i] < min_val) {
37 min_val = data[i];
38 }
39 }
40 return min_val;
41 }

Referenced by min_float().

Here is the caller graph for this function:

◆ parallel_serialize()

static std::vector< std::vector< uint8_t > > kcenon::container::simd::simd_processor::parallel_serialize ( const std::vector< ValueVariant > & values)
static

Serialize multiple values in parallel.

◆ simd_hash()

static uint64_t kcenon::container::simd::simd_processor::simd_hash ( const void * data,
size_t size )
static

Compute hash of data using SIMD.

◆ sum_doubles()

double kcenon::container::simd::simd_processor::sum_doubles ( const std::vector< ValueVariant > & values)
static

Sum all double values in a container using SIMD.

Definition at line 438 of file simd_processor.cpp.

439 {
440 // For now, use scalar implementation for doubles
441 double sum = 0.0;
442 for (const auto& val : values) {
443 if (auto* d = std::get_if<double>(&val)) {
444 sum += *d;
445 }
446 }
447 return sum;
448 }

◆ sum_floats()

float kcenon::container::simd::simd_processor::sum_floats ( const std::vector< ValueVariant > & values)
static

Sum all float values in a container using SIMD.

Definition at line 411 of file simd_processor.cpp.

412 {
413 // Extract float values
414 std::vector<float> floats;
415 floats.reserve(values.size());
416
417 for (const auto& val : values) {
418 if (auto* f = std::get_if<float>(&val)) {
419 floats.push_back(*f);
420 }
421 }
422
423 if (floats.empty()) return 0.0f;
424
425 #if defined(HAS_AVX512)
426 return sum_floats_avx512(floats.data(), floats.size());
427 #elif defined(HAS_AVX2)
428 return sum_floats_avx2(floats.data(), floats.size());
429 #elif defined(HAS_X86_SIMD) && (defined(HAS_SSE2) || defined(HAS_SSE42))
430 return sum_floats_sse(floats.data(), floats.size());
431 #elif defined(HAS_ARM_NEON)
432 return sum_floats_neon(floats.data(), floats.size());
433 #else
434 return sum_floats_scalar(floats.data(), floats.size());
435 #endif
436 }
static float sum_floats_scalar(const float *data, size_t count)

References sum_floats_scalar().

Here is the call graph for this function:

◆ sum_floats_scalar()

float kcenon::container::simd::simd_processor::sum_floats_scalar ( const float * data,
size_t count )
staticprivate

Definition at line 21 of file simd_processor.cpp.

22 {
23 float sum = 0.0f;
24 for (size_t i = 0; i < count; ++i) {
25 sum += data[i];
26 }
27 return sum;
28 }

Referenced by sum_floats().

Here is the caller graph for this function:

◆ transform_numeric()

template<typename T , typename Func >
static void kcenon::container::simd::simd_processor::transform_numeric ( std::vector< ValueVariant > & values,
Func && func )
static

Transform all numeric values by applying a function.


The documentation for this class was generated from the following files: