]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libgcc: aarch64: Add __arm_get_current_vg
authorAlice Carlotti <alice.carlotti@arm.com>
Tue, 30 Dec 2025 08:52:24 +0000 (08:52 +0000)
committerAlice Carlotti <alice.carlotti@arm.com>
Mon, 23 Feb 2026 11:16:42 +0000 (11:16 +0000)
AAPCS64* specifies several runtime support routines that must be
supported by any platform that supports SME.  Add __arm_get_current_vg
to libgcc to help meet this requirement.  This will be used to enable
support for SME without (non-streaming) SVE.

*https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst

libgcc/ChangeLog:

* config/aarch64/libgcc-sme.ver: Add __arm_get_current_vg.
* config/aarch64/t-aarch64: Add new source file.
* config/aarch64/__arm_get_current_vg.S: New file.

libgcc/config/aarch64/__arm_get_current_vg.S [new file with mode: 0644]
libgcc/config/aarch64/libgcc-sme.ver
libgcc/config/aarch64/t-aarch64

diff --git a/libgcc/config/aarch64/__arm_get_current_vg.S b/libgcc/config/aarch64/__arm_get_current_vg.S
new file mode 100644 (file)
index 0000000..edce834
--- /dev/null
@@ -0,0 +1,56 @@
+/* Support routine for SME.
+   Copyright (C) 2025 Free Software Foundation, Inc.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "aarch64-asm.h"
+
+/* Disable ZA.  Call ABI:
+   - Private ZA, streaming-compatible.
+   - x1-x15, x19-x29, sp and fp regs are call preserved.
+   - Takes no argument.
+   - Returns the value of the current VG in x0 if this value exists, and
+     returns zero otherwise.  */
+
+HIDDEN (__aarch64_cpu_features)
+
+variant_pcs (__arm_get_current_vg)
+
+ENTRY (__arm_get_current_vg)
+       /* Check if SVE is available.  */
+       adrp    x16, __aarch64_cpu_features
+       ldr     x16, [x16, :lo12:__aarch64_cpu_features]
+       tbnz    x16, #30, L(end_cntd)
+
+       /* Check if SME is available.  */
+       tbz     x16, #42, L(end_zero)
+
+       /* Check if we're in streaming mode  */
+       .inst   0xd53b4250  /* mrs      x16, svcr  */
+       tbz     x16, #0, L(end_zero)
+L(end_cntd):
+       .inst   0x04e0e3e0  /* cntd     x0  */
+       ret
+L(end_zero):
+       mov     x0, 0
+       ret
+END (__arm_get_current_vg)
index 3bfed444102c9eaa62137328276d996e53d9a886..f8c67905ba71d3a36ccdefa69935eec99b78a11b 100644 (file)
@@ -22,3 +22,7 @@ GCC_14.0 {
   __arm_tpidr2_save
   __arm_za_disable
 }
+
+GCC_16.0 {
+  __arm_get_current_vg
+}
index b67ece153d01f63348fbeb1e435550826441a406..7bc51ad652483852e629a8b16ab3d42363633e68 100644 (file)
@@ -24,6 +24,7 @@ LIB2ADD += $(srcdir)/config/aarch64/cpuinfo.c
 # Add sme runtime to shared libgcc
 LIB2ADDEH += \
        $(srcdir)/config/aarch64/__aarch64_have_sme.c \
+       $(srcdir)/config/aarch64/__arm_get_current_vg.S \
        $(srcdir)/config/aarch64/__arm_sme_state.S \
        $(srcdir)/config/aarch64/__arm_tpidr2_restore.S \
        $(srcdir)/config/aarch64/__arm_tpidr2_save.S \