[compiler-rt] [AArch64][compiler-rt] Add a function returning the current vector length (PR #92921)
Kerry McLaughlin via llvm-commits
llvm-commits at lists.llvm.org
Tue May 21 08:00:30 PDT 2024
https://github.com/kmclaughlin-arm updated https://github.com/llvm/llvm-project/pull/92921
>From 1038d54920dbfc6dbdad0842074f8dba463a9f35 Mon Sep 17 00:00:00 2001
From: Kerry McLaughlin <kerry.mclaughlin at arm.com>
Date: Tue, 21 May 2024 09:54:52 +0000
Subject: [PATCH 1/2] [AArch64][compiler-rt] Add a function returning the
current vector length
get_runtime_vl emits a cntd instruction if SVE is available at runtime,
otherwise it will return 0.
---
.../lib/builtins/aarch64/sme-abi-init.c | 25 +++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/compiler-rt/lib/builtins/aarch64/sme-abi-init.c b/compiler-rt/lib/builtins/aarch64/sme-abi-init.c
index b6ee12170d56d..331ec4b634b5b 100644
--- a/compiler-rt/lib/builtins/aarch64/sme-abi-init.c
+++ b/compiler-rt/lib/builtins/aarch64/sme-abi-init.c
@@ -2,6 +2,8 @@
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#include "../cpu_model/aarch64.c"
+
__attribute__((visibility("hidden"), nocommon))
_Bool __aarch64_has_sme_and_tpidr2_el0;
@@ -50,3 +52,26 @@ __attribute__((constructor(90)))
static void init_aarch64_has_sme(void) {
__aarch64_has_sme_and_tpidr2_el0 = has_sme();
}
+
+#if __GNUC__ >= 9
+#pragma GCC diagnostic ignored "-Wprio-ctor-dtor"
+#endif
+__attribute__((constructor(90)))
+void get_aarch64_cpu_features(void) {
+ if (!__aarch64_cpu_features.features)
+ __init_cpu_features();
+}
+
+__attribute__((target("sve")))
+long emit_cntd(void) {
+ long vl;
+ __asm__ __volatile__("cntd %0" : "=r" (vl));
+ return vl;
+}
+
+long get_runtime_vl(void) {
+ if (__aarch64_cpu_features.features & (1ULL << FEAT_SVE))
+ return emit_cntd();
+ else
+ return 0;
+}
>From 2baec75cb3ec90057b241b7c835699c93da7c149 Mon Sep 17 00:00:00 2001
From: Kerry McLaughlin <kerry.mclaughlin at arm.com>
Date: Tue, 21 May 2024 14:57:47 +0000
Subject: [PATCH 2/2] - Run clang-format
---
compiler-rt/lib/builtins/aarch64/sme-abi-init.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/compiler-rt/lib/builtins/aarch64/sme-abi-init.c b/compiler-rt/lib/builtins/aarch64/sme-abi-init.c
index 331ec4b634b5b..f8a47773b0a6e 100644
--- a/compiler-rt/lib/builtins/aarch64/sme-abi-init.c
+++ b/compiler-rt/lib/builtins/aarch64/sme-abi-init.c
@@ -56,16 +56,14 @@ static void init_aarch64_has_sme(void) {
#if __GNUC__ >= 9
#pragma GCC diagnostic ignored "-Wprio-ctor-dtor"
#endif
-__attribute__((constructor(90)))
-void get_aarch64_cpu_features(void) {
+__attribute__((constructor(90))) void get_aarch64_cpu_features(void) {
if (!__aarch64_cpu_features.features)
__init_cpu_features();
}
-__attribute__((target("sve")))
-long emit_cntd(void) {
+__attribute__((target("sve"))) long emit_cntd(void) {
long vl;
- __asm__ __volatile__("cntd %0" : "=r" (vl));
+ __asm__ __volatile__("cntd %0" : "=r"(vl));
return vl;
}
More information about the llvm-commits
mailing list