Coverage Report

Created: 2026-11-03 04:34

/home/runner/work/LabNeura/LabNeura/src/labneura/backends/common/cpu_features.cpp
Line
Count
Source (jump to first uncovered line)
1
#include "labneura/backends/common/cpu_features.h"
2
3
#if defined(__x86_64__) || defined(_M_X64)
4
#include <cpuid.h>
5
#endif
6
7
namespace labneura {
8
9
// =======================
10
// CPU Feature Detection
11
// =======================
12
0
CPUFeatures detect_cpu_features() {
13
0
    CPUFeatures features{};
14
15
0
    #if defined(__x86_64__) || defined(_M_X64)
16
0
        unsigned int eax, ebx, ecx, edx;
17
18
        // Leaf 1: SSE4.1
19
0
        if (__get_cpuid(1, &eax, &ebx, &ecx, &edx)) {
20
0
            features.sse41 = (ecx & bit_SSE4_1) != 0;
21
0
        }
22
23
        // Leaf 7: AVX2
24
0
        if (__get_cpuid_count(7, 0, &eax, &ebx, &ecx, &edx)) {
25
0
            features.avx2 = (ebx & bit_AVX2) != 0;
26
0
        }
27
0
    #endif
28
29
0
    return features;
30
0
}
31
32
// =======================
33
// x86 AVX2 detection
34
// =======================
35
1.84k
bool cpu_supports_avx2() {
36
1.84k
#if defined(__x86_64__) || defined(_M_X64)
37
1.84k
    unsigned int eax, ebx, ecx, edx;
38
39
1.84k
    if (!__get_cpuid_max(0, nullptr))
40
0
        return false;
41
42
1.84k
    __cpuid_count(7, 0, eax, ebx, ecx, edx);
43
1.84k
    return (ebx & (1 << 5));  // AVX2 bit
44
#else
45
    return false;
46
#endif
47
1.84k
}
48
49
// =======================
50
// ARM NEON detection
51
// =======================
52
0
bool cpu_supports_neon() {
53
#if defined(__aarch64__)
54
    // AArch64 guarantees NEON
55
    return true;
56
#elif defined(__ARM_NEON)
57
    return true;
58
#else
59
0
    return false;
60
0
#endif
61
0
}
62
63
} // namespace labneura