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.
This commit is contained in:
Alice Carlotti
2025-12-30 08:52:24 +00:00
parent bf3dc8c64a
commit 41b4a73f37
3 changed files with 61 additions and 0 deletions

View File

@@ -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)

View File

@@ -22,3 +22,7 @@ GCC_14.0 {
__arm_tpidr2_save
__arm_za_disable
}
GCC_16.0 {
__arm_get_current_vg
}

View 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 \