Next try.
Optimized versions for kernel ffs(3) on arm64, powerpc, powerpc64.

I have tested arm64; cwen@ has tested powerpc in userland.
powerpc64 is copied from powerpc.

ok?


Index: lib/libkern/arch/arm64/ffs.S
===================================================================
RCS file: lib/libkern/arch/arm64/ffs.S
diff -N lib/libkern/arch/arm64/ffs.S
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/libkern/arch/arm64/ffs.S        10 Jun 2020 17:38:50 -0000
@@ -0,0 +1,17 @@
+/*     $OpenBSD$ */
+/*
+ * Written by Christian Weisgerber <[email protected]>.
+ * 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)
Index: lib/libkern/arch/powerpc/ffs.S
===================================================================
RCS file: lib/libkern/arch/powerpc/ffs.S
diff -N lib/libkern/arch/powerpc/ffs.S
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/libkern/arch/powerpc/ffs.S      10 Jun 2020 17:39:02 -0000
@@ -0,0 +1,15 @@
+/*     $OpenBSD$ */
+/*
+ * Written by Christian Weisgerber <[email protected]>.
+ * 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)
Index: lib/libkern/arch/powerpc64/ffs.S
===================================================================
RCS file: lib/libkern/arch/powerpc64/ffs.S
diff -N lib/libkern/arch/powerpc64/ffs.S
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/libkern/arch/powerpc64/ffs.S    10 Jun 2020 17:39:06 -0000
@@ -0,0 +1,15 @@
+/*     $OpenBSD$ */
+/*
+ * Written by Christian Weisgerber <[email protected]>.
+ * 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)
-- 
Christian "naddy" Weisgerber                          [email protected]

Reply via email to