From c9da40319ade2fae5d8060ae1358116aed97dfe9 Mon Sep 17 00:00:00 2001 From: Christian Weisgerber Date: Fri, 26 Jun 2020 20:16:23 +0000 Subject: 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@ --- lib/libc/arch/aarch64/string/Makefile.inc | 4 ++-- lib/libc/arch/aarch64/string/ffs.S | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 lib/libc/arch/aarch64/string/ffs.S (limited to 'lib/libc/arch/aarch64') 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 . + * 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 -- cgit v1.2.3