summaryrefslogtreecommitdiff
path: root/lib/libc/arch/aarch64
diff options
context:
space:
mode:
authorChristian Weisgerber <naddy@cvs.openbsd.org>2020-06-26 20:16:23 +0000
committerChristian Weisgerber <naddy@cvs.openbsd.org>2020-06-26 20:16:23 +0000
commitc9da40319ade2fae5d8060ae1358116aed97dfe9 (patch)
tree3ddee878f1439fabcf48f89474b16afae6e0d6ab /lib/libc/arch/aarch64
parent1a7046d3da2194ba4e36d72d66bca98ce39141db (diff)
Provide an optimized implementation of ffs(3) in libc on
aarch64/powerpc/powerpc64, making use of the count leading zeros instruction. Also add a brief regression test. ok deraadt@ kettenis@
Diffstat (limited to 'lib/libc/arch/aarch64')
-rw-r--r--lib/libc/arch/aarch64/string/Makefile.inc4
-rw-r--r--lib/libc/arch/aarch64/string/ffs.S18
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/libc/arch/aarch64/string/Makefile.inc b/lib/libc/arch/aarch64/string/Makefile.inc
index a44e1d0265e..2a65a8da0dd 100644
--- a/lib/libc/arch/aarch64/string/Makefile.inc
+++ b/lib/libc/arch/aarch64/string/Makefile.inc
@@ -1,8 +1,8 @@
-# $OpenBSD: Makefile.inc,v 1.1 2017/01/11 18:09:24 patrick Exp $
+# $OpenBSD: Makefile.inc,v 1.2 2020/06/26 20:16:21 naddy Exp $
SRCS+= bcopy.c memcpy.c memmove.c \
strchr.c strrchr.c \
- bcmp.c bzero.c ffs.c memchr.c memcmp.c memset.c \
+ bcmp.c bzero.c ffs.S memchr.c memcmp.c memset.c \
strcmp.c strncmp.c \
strcat.c strcpy.c strcspn.c strlen.c strlcat.c strlcpy.c \
strncat.c strncpy.c strpbrk.c strsep.c \
diff --git a/lib/libc/arch/aarch64/string/ffs.S b/lib/libc/arch/aarch64/string/ffs.S
new file mode 100644
index 00000000000..94995c70110
--- /dev/null
+++ b/lib/libc/arch/aarch64/string/ffs.S
@@ -0,0 +1,18 @@
+/* $OpenBSD: ffs.S,v 1.1 2020/06/26 20:16:21 naddy Exp $ */
+/*
+ * Written by Christian Weisgerber <naddy@openbsd.org>.
+ * Public domain.
+ */
+
+#include "DEFS.h"
+
+ENTRY(ffs)
+ RETGUARD_SETUP(ffs, x15)
+ rbit w1, w0
+ clz w1, w1
+ cmp w0, wzr
+ csinc w0, wzr, w1, eq
+ RETGUARD_CHECK(ffs, x15)
+ ret
+END(ffs)
+.protected