Coverage Report

Created: 2026-02-16 07:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/AK/CPUFeatures.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2024, Dan Klishch <danilklishch@gmail.com>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <AK/EnumBits.h>
10
#include <AK/Types.h>
11
12
namespace AK {
13
14
enum class CPUFeatures : u64 {
15
    None = 0ULL,
16
    Invalid = 1ULL << 63,
17
18
#if !defined(KERNEL) && (ARCH(I386) || ARCH(X86_64))
19
#    define AK_CAN_CODEGEN_FOR_X86_SSE42 1
20
    X86_SSE42 = 1ULL << 0,
21
#    define AK_CAN_CODEGEN_FOR_X86_SHA 1
22
    X86_SHA = 1ULL << 1,
23
#    define AK_CAN_CODEGEN_FOR_X86_AES 1
24
    X86_AES = 1ULL << 2,
25
#else
26
#    define AK_CAN_CODEGEN_FOR_X86_SSE42 0
27
    X86_SSE42 = Invalid,
28
#    define AK_CAN_CODEGEN_FOR_X86_SHA 0
29
    X86_SHA = Invalid,
30
#    define AK_CAN_CODEGEN_FOR_X86_AES 0
31
    X86_AES = Invalid,
32
#endif
33
};
34
35
AK_ENUM_BITWISE_OPERATORS(CPUFeatures);
36
37
#ifndef KERNEL
38
namespace Detail {
39
CPUFeatures detect_cpu_features_uncached();
40
}
41
42
inline CPUFeatures detect_cpu_features()
43
20
{
44
20
    static CPUFeatures const s_cached_features = Detail::detect_cpu_features_uncached();
45
20
    return s_cached_features;
46
20
}
47
#else
48
inline CPUFeatures detect_cpu_features()
49
{
50
    return CPUFeatures::None;
51
}
52
#endif
53
54
constexpr bool is_valid_feature(CPUFeatures feature)
55
0
{
56
0
    return !has_flag(feature, CPUFeatures::Invalid);
57
0
}
58
59
}
60
61
#ifdef USING_AK_GLOBALLY
62
using AK::CPUFeatures;
63
using AK::detect_cpu_features;
64
#endif