https://gcc.gnu.org/g:41b4a73f370116af73b24cf7d74099790c2f3223

commit r16-7637-g41b4a73f370116af73b24cf7d74099790c2f3223
Author: Alice Carlotti <[email protected]>
Date:   Tue Dec 30 08:52:24 2025 +0000

    libgcc: aarch64: Add __arm_get_current_vg
    
    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.

Diff:
---
 libgcc/config/aarch64/__arm_get_current_vg.S | 56 ++++++++++++++++++++++++++++
 libgcc/config/aarch64/libgcc-sme.ver         |  4 ++
 libgcc/config/aarch64/t-aarch64              |  1 +
 3 files changed, 61 insertions(+)

diff --git a/libgcc/config/aarch64/__arm_get_current_vg.S 
b/libgcc/config/aarch64/__arm_get_current_vg.S
new file mode 100644
index 000000000000..edce8340efa3
--- /dev/null
+++ b/libgcc/config/aarch64/__arm_get_current_vg.S
@@ -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)
diff --git a/libgcc/config/aarch64/libgcc-sme.ver 
b/libgcc/config/aarch64/libgcc-sme.ver
index 3bfed444102c..f8c67905ba71 100644
--- a/libgcc/config/aarch64/libgcc-sme.ver
+++ b/libgcc/config/aarch64/libgcc-sme.ver
@@ -22,3 +22,7 @@ GCC_14.0 {
   __arm_tpidr2_save
   __arm_za_disable
 }
+
+GCC_16.0 {
+  __arm_get_current_vg
+}
diff --git a/libgcc/config/aarch64/t-aarch64 b/libgcc/config/aarch64/t-aarch64
index b67ece153d01..7bc51ad65248 100644
--- a/libgcc/config/aarch64/t-aarch64
+++ b/libgcc/config/aarch64/t-aarch64
@@ -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 \

Reply via email to