summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/ffs
diff options
context:
space:
mode:
authornaddy <>2020-06-26 20:16:22 +0000
committernaddy <>2020-06-26 20:16:22 +0000
commit0f164cb73d243a909a07b3c6ed09629b0b6349d0 (patch)
treea0f0ab0bd201689ff830ad67e8825974a88c533e /src/regress/lib/libc/ffs
parente6210caecae44d68e7e82bfee67db9bc9a706a01 (diff)
downloadopenbsd-0f164cb73d243a909a07b3c6ed09629b0b6349d0.tar.gz
openbsd-0f164cb73d243a909a07b3c6ed09629b0b6349d0.tar.bz2
openbsd-0f164cb73d243a909a07b3c6ed09629b0b6349d0.zip
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 'src/regress/lib/libc/ffs')
-rw-r--r--src/regress/lib/libc/ffs/Makefile6
-rw-r--r--src/regress/lib/libc/ffs/ffs_test.c18
2 files changed, 24 insertions, 0 deletions
diff --git a/src/regress/lib/libc/ffs/Makefile b/src/regress/lib/libc/ffs/Makefile
new file mode 100644
index 0000000000..1ad004394f
--- /dev/null
+++ b/src/regress/lib/libc/ffs/Makefile
@@ -0,0 +1,6 @@
1PROG= ffs_test
2
3# prevent constant folding and inlining of __builtin_ffs()
4CFLAGS+= -ffreestanding
5
6.include <bsd.regress.mk>
diff --git a/src/regress/lib/libc/ffs/ffs_test.c b/src/regress/lib/libc/ffs/ffs_test.c
new file mode 100644
index 0000000000..bc1e5c53c2
--- /dev/null
+++ b/src/regress/lib/libc/ffs/ffs_test.c
@@ -0,0 +1,18 @@
1/* $OpenBSD: ffs_test.c,v 1.1 2020/06/26 20:16:22 naddy Exp $ */
2/*
3 * Written by Christian Weisgerber <naddy@openbsd.org>.
4 * Public domain.
5 */
6
7#include <assert.h>
8#include <stdint.h>
9#include <string.h>
10
11int
12main(void)
13{
14 assert(ffs(0) == 0);
15 assert(ffs(0x8080) == 8);
16 assert(ffs(INT32_MIN) == 32);
17 return (0);
18}