forked from xtensor-stack/xsimd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxsimd_cpu_features_arm.hpp
More file actions
87 lines (78 loc) · 2.83 KB
/
xsimd_cpu_features_arm.hpp
File metadata and controls
87 lines (78 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
***************************************************************************/
#ifndef XSIMD_CPU_FEATURES_ARM_HPP
#define XSIMD_CPU_FEATURES_ARM_HPP
#include "./xsimd_config.hpp"
#include "./xsimd_getauxval.hpp"
#if XSIMD_TARGET_ARM && XSIMD_HAVE_LINUX_GETAUXVAL
// HWCAP_XXX masks to use on getauxval results.
// Header does not exists on all architectures and masks are architecture
// specific.
#include <asm/hwcap.h>
#endif // XSIMD_TARGET_ARM && XSIMD_HAVE_LINUX_GETAUXVAL
namespace xsimd
{
/**
* An opinionated CPU feature detection utility for ARM.
*
* Combines compile-time knowledge with runtime detection when available.
* On Linux, runtime detection uses getauxval to query the auxiliary vector.
* On other platforms, only compile-time information is used.
*
* This is well defined on all architectures.
* It will always return false on non-ARM architectures.
*/
class arm_cpu_features : private linux_hwcap_backend_default
{
public:
inline bool neon() const noexcept;
inline bool neon64() const noexcept;
inline bool sve() const noexcept;
inline bool i8mm() const noexcept;
};
/********************
* Implementation *
********************/
inline bool arm_cpu_features::neon() const noexcept
{
#if XSIMD_TARGET_ARM && !XSIMD_TARGET_ARM64 && XSIMD_HAVE_LINUX_GETAUXVAL
return hwcap().has_feature(HWCAP_NEON);
#else
return static_cast<bool>(XSIMD_WITH_NEON);
#endif
}
inline bool arm_cpu_features::neon64() const noexcept
{
return static_cast<bool>(XSIMD_WITH_NEON64);
}
inline bool arm_cpu_features::sve() const noexcept
{
#if XSIMD_TARGET_ARM64 && XSIMD_HAVE_LINUX_GETAUXVAL
return hwcap().has_feature(HWCAP_SVE);
#else
return false;
#endif
}
inline bool arm_cpu_features::i8mm() const noexcept
{
#if XSIMD_TARGET_ARM64 && XSIMD_HAVE_LINUX_GETAUXVAL
#ifdef HWCAP2_I8MM
return hwcap2().has_feature(HWCAP2_I8MM);
#else
// Possibly missing on older Linux distributions
return hwcap2().has_feature(1 << 13);
#endif
#else
return false;
#endif
}
}
#endif