git: bea89d038ac5 - main - lib/libc/aarch64/string: add strlcat SIMD implementation
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 10 Jan 2025 15:03:58 UTC
The branch main has been updated by fuz:
URL: https://cgit.FreeBSD.org/src/commit/?id=bea89d038ac54048bb7dcb149cabd99067e5a3a9
commit bea89d038ac54048bb7dcb149cabd99067e5a3a9
Author: Getz Mikalsen <getz@FreeBSD.org>
AuthorDate: 2024-08-26 21:10:16 +0000
Commit: Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2025-01-10 15:02:40 +0000
lib/libc/aarch64/string: add strlcat SIMD implementation
This patch requires D46243 as it depends on strlcpy being labeled
__strlcpy.
It's a direct copy from the amd64 string functions using memchr and
strlcpy to implement strlcat.
Tested by: fuz (exprun)
Reviewed by: fuz, emaste
Sponsored by: Google LLC (GSoC 2024)
PR: 281175
Differential Revision: https://reviews.freebsd.org/D46272
---
lib/libc/aarch64/string/Makefile.inc | 3 ++-
lib/libc/aarch64/string/memchr.S | 4 ++++
lib/libc/aarch64/string/strlcat.c | 25 +++++++++++++++++++++++++
3 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/lib/libc/aarch64/string/Makefile.inc b/lib/libc/aarch64/string/Makefile.inc
index 876ef4257b4c..f8c67319fe12 100644
--- a/lib/libc/aarch64/string/Makefile.inc
+++ b/lib/libc/aarch64/string/Makefile.inc
@@ -29,7 +29,8 @@ MDSRCS+= \
strlcpy.S \
strncmp.S \
memccpy.S \
- strncat.c
+ strncat.c \
+ strlcat.c
#
# Add the above functions. Generate an asm file that includes the needed
diff --git a/lib/libc/aarch64/string/memchr.S b/lib/libc/aarch64/string/memchr.S
new file mode 100644
index 000000000000..6d4330d9115e
--- /dev/null
+++ b/lib/libc/aarch64/string/memchr.S
@@ -0,0 +1,4 @@
+ .weak memchr
+ .set memchr, __memchr_aarch64
+
+#include "aarch64/memchr.S"
diff --git a/lib/libc/aarch64/string/strlcat.c b/lib/libc/aarch64/string/strlcat.c
new file mode 100644
index 000000000000..c3c996163ade
--- /dev/null
+++ b/lib/libc/aarch64/string/strlcat.c
@@ -0,0 +1,25 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2023 Robert Clausecker
+ */
+
+#include <sys/cdefs.h>
+
+#include <string.h>
+
+void *__memchr_aarch64(const void *, int, size_t);
+size_t __strlcpy(char *restrict, const char *restrict, size_t);
+
+size_t
+strlcat(char *restrict dst, const char *restrict src, size_t dstsize)
+{
+ char *loc = __memchr_aarch64(dst, '\0', dstsize);
+
+ if (loc != NULL) {
+ size_t dstlen = (size_t)(loc - dst);
+
+ return (dstlen + __strlcpy(loc, src, dstsize - dstlen));
+ } else
+ return (dstsize + strlen(src));
+}