summaryrefslogtreecommitdiff
path: root/sys/lib/libkern
diff options
context:
space:
mode:
authorChristian Weisgerber <naddy@cvs.openbsd.org>2020-06-10 20:19:30 +0000
committerChristian Weisgerber <naddy@cvs.openbsd.org>2020-06-10 20:19:30 +0000
commit6b922a96b4a4486590250e516d7e945eed418261 (patch)
treed7cc27461b162b0d3bd6100ad7afc455ac80bb5e /sys/lib/libkern
parentf1c0ba88f851d20e764a5221ddb503ad61596230 (diff)
Provide an optimized implementation of ffs(3) in the kernel on
arm64/powerpc/powerpc64, making use of the count leading zeros instruction. powerpc testing by cwen@; ok kettenis@ deraadt@
Diffstat (limited to 'sys/lib/libkern')
-rw-r--r--sys/lib/libkern/arch/arm64/ffs.S17
-rw-r--r--sys/lib/libkern/arch/powerpc/ffs.S15
-rw-r--r--sys/lib/libkern/arch/powerpc64/ffs.S15
3 files changed, 47 insertions, 0 deletions
diff --git a/sys/lib/libkern/arch/arm64/ffs.S b/sys/lib/libkern/arch/arm64/ffs.S
new file mode 100644
index 00000000000..03101cb2c9f
--- /dev/null
+++ b/sys/lib/libkern/arch/arm64/ffs.S
@@ -0,0 +1,17 @@
+/* $OpenBSD: ffs.S,v 1.1 2020/06/10 20:19:29 naddy Exp $ */
+/*
+ * Written by Christian Weisgerber <naddy@openbsd.org>.
+ * Public domain.
+ */
+
+#include <machine/asm.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)
diff --git a/sys/lib/libkern/arch/powerpc/ffs.S b/sys/lib/libkern/arch/powerpc/ffs.S
new file mode 100644
index 00000000000..13fe17fb4f8
--- /dev/null
+++ b/sys/lib/libkern/arch/powerpc/ffs.S
@@ -0,0 +1,15 @@
+/* $OpenBSD: ffs.S,v 1.1 2020/06/10 20:19:29 naddy Exp $ */
+/*
+ * Written by Christian Weisgerber <naddy@openbsd.org>.
+ * Public domain.
+ */
+
+#include <machine/asm.h>
+
+ENTRY(ffs)
+ neg %r4, %r3
+ and %r3, %r3, %r4
+ cntlzw %r3, %r3
+ subfic %r3, %r3, 32
+ blr
+END(ffs)
diff --git a/sys/lib/libkern/arch/powerpc64/ffs.S b/sys/lib/libkern/arch/powerpc64/ffs.S
new file mode 100644
index 00000000000..13fe17fb4f8
--- /dev/null
+++ b/sys/lib/libkern/arch/powerpc64/ffs.S
@@ -0,0 +1,15 @@
+/* $OpenBSD: ffs.S,v 1.1 2020/06/10 20:19:29 naddy Exp $ */
+/*
+ * Written by Christian Weisgerber <naddy@openbsd.org>.
+ * Public domain.
+ */
+
+#include <machine/asm.h>
+
+ENTRY(ffs)
+ neg %r4, %r3
+ and %r3, %r3, %r4
+ cntlzw %r3, %r3
+ subfic %r3, %r3, 32
+ blr
+END(ffs)