libc/aarch64: Add memset for a 64 byte dc zva

On arm64 we can use the "dc zva" instruction to zero memory. The CPU
tells software if the instruction is implemented, and if so the size
and alignment it will use.

When the size is 64-bytes the Arm Optimized Routines implementation of
memset can use dc zva to zero memory, and has a build flag to skip
checking.

Use this flag to build a version of memset that will be used when this
assumption is true.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D54776
This commit is contained in:
Andrew Turner
2026-02-03 14:01:32 +00:00
parent f0516ed465
commit 32d1f18865
3 changed files with 20 additions and 1 deletions
+3 -1
View File
@@ -42,7 +42,8 @@ MDSRCS+= \
memcpy_resolver.c \
memmove_resolver.c \
memset.S \
memset_resolver.c
memset_resolver.c \
memset_zva64.S
#
# Add the above functions. Generate an asm file that includes the needed
@@ -77,3 +78,4 @@ CFLAGS.${FILE}+=-I${SRCTOP}/contrib/arm-optimized-routines/string
CFLAGS.memchr.S+=-I${SRCTOP}/contrib/arm-optimized-routines/string
CFLAGS.memcpy.S+=-I${SRCTOP}/contrib/arm-optimized-routines/string
CFLAGS.memset.S+=-I${SRCTOP}/contrib/arm-optimized-routines/string
CFLAGS.memset_zva64.S+=-I${SRCTOP}/contrib/arm-optimized-routines/string
+13
View File
@@ -25,18 +25,31 @@
* SUCH DAMAGE.
*/
#include <sys/types.h>
#include <machine/armreg.h>
#include <machine/ifunc.h>
#include <elf.h>
void *__memset_aarch64(void *, int, size_t);
void *__memset_aarch64_zva64(void *, int, size_t);
void *__memset_aarch64_mops(void *, int, size_t);
DEFINE_UIFUNC(, void *, memset, (void *, int, size_t))
{
uint64_t dczid;
if (ifunc_arg->_hwcap2 & HWCAP2_MOPS)
return (__memset_aarch64_mops);
/*
* Check for the DC ZVA instruction, and it will
* zero 64 bytes (4 * 4byte words).
*/
dczid = READ_SPECIALREG(dczid_el0);
if ((dczid & DCZID_DZP) == 0 && DCZID_BS_SIZE(dczid) == 4)
return (__memset_aarch64_zva64);
return (__memset_aarch64);
}
+4
View File
@@ -0,0 +1,4 @@
/* Used when we know we have a 64-byte dc zva instruction */
#define __memset_aarch64 __memset_aarch64_zva64
#define SKIP_ZVA_CHECK
#include "aarch64/memset.S"