cheatah
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>
7namespace cheatah::linalg {
9namespace detail {
10// By-value is intentional: the sole caller std::move()s into it, so the argument is
11// move-constructed (no copy) and the result moves out — passing by value is the efficient
12// choice here, not a redundant copy.
13// cppcheck-suppress passedByValue
14std::string scalar_if_empty(std::string features) {
15 if (features.empty()) return "scalar";
16 return features;
18} // namespace detail
20std::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#endif
32#if defined(__AVX2__)
33 add("AVX2");
34#endif
35#if defined(__AVX__)
36 add("AVX");
37#endif
38#if defined(__FMA__)
39 add("FMA");
40#endif
41#if defined(__SSE4_2__)
42 add("SSE4.2");
43#endif
44#if defined(__ARM_NEON) || defined(__ARM_NEON__)
45 add("NEON");
46#endif
48 return detail::scalar_if_empty(std::move(features));
51int 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#else
59 return 1;
60#endif
63} // namespace cheatah::linalg