simd-vector-engine 0.1.0

Runtime-dispatched SIMD kernels for scanning i32/f32 slices: count, sum, find and stream compaction on AVX-512, AVX2, NEON with a scalar fallback
Documentation
// Единственное место, где выбирается ISA.
// TU собран без -mavx512f, поэтому компилятор не поднимет AVX-512 выше проверки.

#include "sve/sve.hpp"

namespace sve {

std::size_t count_gt_i32(std::span<const std::int32_t> d, std::int32_t thr) {
    switch (best_isa()) {
#if defined(SVE_X86)
        case Isa::Avx512: return avx512::count_gt_i32(d, thr);
        case Isa::Avx2:   return avx2::count_gt_i32(d, thr);
#endif
#if defined(SVE_ARM)
        case Isa::Neon:   return neon::count_gt_i32(d, thr);
#endif
        default:          return scalar::count_gt_i32(d, thr);
    }
}

std::size_t count_gt_f32(std::span<const float> d, float thr) {
    switch (best_isa()) {
#if defined(SVE_X86)
        case Isa::Avx512: return avx512::count_gt_f32(d, thr);
        case Isa::Avx2:   return avx2::count_gt_f32(d, thr);
#endif
#if defined(SVE_ARM)
        case Isa::Neon:   return neon::count_gt_f32(d, thr);
#endif
        default:          return scalar::count_gt_f32(d, thr);
    }
}

std::int64_t sum_i32(std::span<const std::int32_t> d) {
    switch (best_isa()) {
#if defined(SVE_X86)
        case Isa::Avx512: return avx512::sum_i32(d);
        case Isa::Avx2:   return avx2::sum_i32(d);
#endif
#if defined(SVE_ARM)
        case Isa::Neon:   return neon::sum_i32(d);
#endif
        default:          return scalar::sum_i32(d);
    }
}

std::optional<std::size_t> find_i32(std::span<const std::int32_t> d, std::int32_t needle) {
    switch (best_isa()) {
#if defined(SVE_X86)
        case Isa::Avx512: return avx512::find_i32(d, needle);
        case Isa::Avx2:   return avx2::find_i32(d, needle);
#endif
#if defined(SVE_ARM)
        case Isa::Neon:   return neon::find_i32(d, needle);
#endif
        default:          return scalar::find_i32(d, needle);
    }
}

std::size_t filter_into_i32(std::span<const std::int32_t> d, std::int32_t thr,
                            std::span<std::int32_t> out) {
    switch (best_isa()) {
#if defined(SVE_X86)
        case Isa::Avx512: return avx512::filter_into_i32(d, thr, out);
        case Isa::Avx2:   return avx2::filter_into_i32(d, thr, out);
#endif
#if defined(SVE_ARM)
        case Isa::Neon:   return neon::filter_into_i32(d, thr, out);
#endif
        default:          return scalar::filter_into_i32(d, thr, out);
    }
}

}  // namespace sve