diff options
author | Christian Weisgerber <naddy@cvs.openbsd.org> | 2020-06-26 20:16:23 +0000 |
---|---|---|
committer | Christian Weisgerber <naddy@cvs.openbsd.org> | 2020-06-26 20:16:23 +0000 |
commit | c9da40319ade2fae5d8060ae1358116aed97dfe9 (patch) | |
tree | 3ddee878f1439fabcf48f89474b16afae6e0d6ab /lib/libc/arch | |
parent | 1a7046d3da2194ba4e36d72d66bca98ce39141db (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')
-rw-r--r-- | lib/libc/arch/aarch64/string/Makefile.inc | 4 | ||||
-rw-r--r-- | lib/libc/arch/aarch64/string/ffs.S | 18 | ||||
-rw-r--r-- | lib/libc/arch/powerpc/string/Makefile.inc | 4 | ||||
-rw-r--r-- | lib/libc/arch/powerpc/string/ffs.S | 16 | ||||
-rw-r--r-- | lib/libc/arch/powerpc64/string/Makefile.inc | 4 | ||||
-rw-r--r-- | lib/libc/arch/powerpc64/string/ffs.S | 15 |
6 files changed, 55 insertions, 6 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 diff --git a/lib/libc/arch/powerpc/string/Makefile.inc b/lib/libc/arch/powerpc/string/Makefile.inc index 4a97429a2c3..065455f8679 100644 --- a/lib/libc/arch/powerpc/string/Makefile.inc +++ b/lib/libc/arch/powerpc/string/Makefile.inc @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile.inc,v 1.6 2015/05/15 22:29:37 millert Exp $ +# $OpenBSD: Makefile.inc,v 1.7 2020/06/26 20:16:21 naddy Exp $ SRCS+= memcpy.c memmove.S \ strchr.c strrchr.c \ - bcmp.c bzero.c ffs.c memchr.c memcmp.c memset.c strcat.c \ + bcmp.c bzero.c ffs.S memchr.c memcmp.c memset.c strcat.c \ strcmp.c strcpy.c strcspn.c strlen.c strlcat.c strlcpy.c \ strncat.c strncmp.c strncpy.c strpbrk.c strsep.c \ strspn.c strstr.c swab.c diff --git a/lib/libc/arch/powerpc/string/ffs.S b/lib/libc/arch/powerpc/string/ffs.S new file mode 100644 index 00000000000..d7091526d41 --- /dev/null +++ b/lib/libc/arch/powerpc/string/ffs.S @@ -0,0 +1,16 @@ +/* $OpenBSD: ffs.S,v 1.1 2020/06/26 20:16:21 naddy Exp $ */ +/* + * Written by Christian Weisgerber <naddy@openbsd.org>. + * Public domain. + */ + +#include "SYS.h" + +ENTRY(ffs) + neg %r4, %r3 + and %r3, %r3, %r4 + cntlzw %r3, %r3 + subfic %r3, %r3, 32 + blr +END(ffs) +.protected diff --git a/lib/libc/arch/powerpc64/string/Makefile.inc b/lib/libc/arch/powerpc64/string/Makefile.inc index da0411aa36e..ba6e9dde0e5 100644 --- a/lib/libc/arch/powerpc64/string/Makefile.inc +++ b/lib/libc/arch/powerpc64/string/Makefile.inc @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile.inc,v 1.1 2020/06/25 02:34:22 drahn Exp $ +# $OpenBSD: Makefile.inc,v 1.2 2020/06/26 20:16:21 naddy Exp $ SRCS+= memcpy.c memmove.S \ strchr.c strrchr.c \ - bcmp.c bzero.c ffs.c memchr.c memcmp.c memset.c strcat.c \ + bcmp.c bzero.c ffs.S memchr.c memcmp.c memset.c strcat.c \ strcmp.c strcpy.c strcspn.c strlen.c strlcat.c strlcpy.c \ strncat.c strncmp.c strncpy.c strpbrk.c strsep.c \ strspn.c strstr.c swab.c diff --git a/lib/libc/arch/powerpc64/string/ffs.S b/lib/libc/arch/powerpc64/string/ffs.S new file mode 100644 index 00000000000..8e656698ec9 --- /dev/null +++ b/lib/libc/arch/powerpc64/string/ffs.S @@ -0,0 +1,15 @@ +/* $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) + neg %r4, %r3 + and %r3, %r3, %r4 + cntlzw %r3, %r3 + subfic %r3, %r3, 32 + blr +END_BUILTIN(ffs) |