Skip to content

Commit cd378f7

Browse files
zvookinZalman Stern
andauthored
Query SVE vector register length in host target computation for ARM cpus with SVE/SVE2. (#8812)
* Add support for querying SVE vector register length on hosts that support SVE/SVE2. * Formatting. --------- Co-authored-by: Zalman Stern <[email protected]>
1 parent e41fd47 commit cd378f7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Target.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ using std::vector;
5757

5858
namespace {
5959

60+
#if defined(__aarch64__)
61+
__attribute__((target("+sve"))) int get_sve_vector_length() {
62+
register int result asm("w0");
63+
__asm__("cntb %x0, all, mul #8" : "=r"(result));
64+
return result;
65+
}
66+
#endif
67+
6068
#if defined(_M_IX86) || defined(_M_AMD64)
6169

6270
void cpuid(int info[4], int infoType, int extra) {
@@ -232,6 +240,7 @@ Target calculate_host_target() {
232240
#else
233241
#if defined(__arm__) || defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)
234242
Target::Arch arch = Target::ARM;
243+
bool has_scalable_vector = false;
235244

236245
#ifdef __APPLE__
237246
if (is_armv7s()) {
@@ -261,10 +270,12 @@ Target calculate_host_target() {
261270

262271
if (hwcaps & HWCAP_SVE) {
263272
initial_features.push_back(Target::SVE);
273+
has_scalable_vector = true;
264274
}
265275

266276
if (hwcaps2 & HWCAP2_SVE2) {
267277
initial_features.push_back(Target::SVE2);
278+
has_scalable_vector = true;
268279
}
269280
#endif
270281

@@ -286,10 +297,17 @@ Target calculate_host_target() {
286297

287298
if (IsProcessorFeaturePresent(PF_ARM_SVE_INSTRUCTIONS_AVAILABLE)) {
288299
initial_features.push_back(Target::SVE);
300+
has_scalable_vector = true;
289301
}
290302

291303
#endif
292304

305+
#if defined(__aarch64__)
306+
if (has_scalable_vector) {
307+
vector_bits = get_sve_vector_length();
308+
}
309+
#endif
310+
293311
#else
294312
#if defined(__powerpc__) && (defined(__FreeBSD__) || defined(__linux__))
295313
Target::Arch arch = Target::POWERPC;

0 commit comments

Comments
 (0)