aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Turner <andrew@FreeBSD.org>2026-02-03 14:01:32 +0000
committerAndrew Turner <andrew@FreeBSD.org>2026-02-03 17:11:51 +0000
commit32d1f18865abe94d351a6f178a93b7195595ec69 (patch)
tree6a2920e59bee6bc5c4595be80bd45fd83090953c
parentf0516ed4652cfb7435f8c5a16b46dc067779a1a8 (diff)
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
-rw-r--r--lib/libc/aarch64/string/Makefile.inc4
-rw-r--r--lib/libc/aarch64/string/memset_resolver.c13
-rw-r--r--lib/libc/aarch64/string/memset_zva64.S4
3 files changed, 20 insertions, 1 deletions
diff --git a/lib/libc/aarch64/string/Makefile.inc b/lib/libc/aarch64/string/Makefile.inc
index 20a844f80e17..bc05e849aa20 100644
--- a/lib/libc/aarch64/string/Makefile.inc
+++ b/lib/libc/aarch64/string/Makefile.inc
@@ -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
diff --git a/lib/libc/aarch64/string/memset_resolver.c b/lib/libc/aarch64/string/memset_resolver.c
index 34ca98aa1d34..277e8c177de9 100644
--- a/lib/libc/aarch64/string/memset_resolver.c
+++ b/lib/libc/aarch64/string/memset_resolver.c
@@ -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);
}
diff --git a/lib/libc/aarch64/string/memset_zva64.S b/lib/libc/aarch64/string/memset_zva64.S
new file mode 100644
index 000000000000..7f1cf6ba577a
--- /dev/null
+++ b/lib/libc/aarch64/string/memset_zva64.S
@@ -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"