Source
stdlib/linalg/simd.cpp
1
// Copyright (c) 2026 BigBrain LLC. MIT-licensed (see LICENSE).2
// Original work; see ACKNOWLEDGMENTS.md for the open-source ideas we build upon.3
#include "simd.hpp"5
#include <utility>7
namespace cheatah::linalg {9
namespace detail {10
// By-value is intentional: the sole caller std::move()s into it, so the argument is11
// move-constructed (no copy) and the result moves out — passing by value is the efficient12
// choice here, not a redundant copy.13
// cppcheck-suppress passedByValue14
std::string scalar_if_empty(std::string features) {15
if (features.empty()) return "scalar";16
return features;17
}18
} // namespace detail20
std::string simd_features() {21
std::string features;22
const auto add = [&](const char* name) {23
if (!features.empty()) {24
features += ';';25
}26
features += name;27
};29
#if defined(__AVX512F__)30
add("AVX512F");31
#endif32
#if defined(__AVX2__)33
add("AVX2");34
#endif35
#if defined(__AVX__)36
add("AVX");37
#endif38
#if defined(__FMA__)39
add("FMA");40
#endif41
#if defined(__SSE4_2__)42
add("SSE4.2");43
#endif44
#if defined(__ARM_NEON) || defined(__ARM_NEON__)45
add("NEON");46
#endif48
return detail::scalar_if_empty(std::move(features));49
}51
int simd_lane_doubles() noexcept {52
#if defined(__AVX512F__)53
return 8;54
#elif defined(__AVX__)55
return 4;56
#elif defined(__SSE2__) || defined(__ARM_NEON) || defined(__ARM_NEON__)57
return 2;58
#else59
return 1;60
#endif61
}63
} // namespace cheatah::linalg