From 9e319462a03a970ca9870c6e0f4c9c4593bca97a Mon Sep 17 00:00:00 2001 From: Justin Hibbits Date: Sun, 8 Dec 2019 04:36:42 +0000 Subject: [PATCH] powerpc: Use builtins for fls/flsl Summary: There's no need to use the fallback fls() and flsl() libkern functions when the PowerISA includes instructions that already do the bulk of the work. Take advantage of this through the GCC builtins __builtin_clz() and __builtin_clzl(). Reviewed by: luporl Differential Revision: https://reviews.freebsd.org/D22340 --- stand/powerpc/kboot/main.c | 1 - sys/conf/files.powerpc | 2 -- sys/powerpc/include/cpufunc.h | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/stand/powerpc/kboot/main.c b/stand/powerpc/kboot/main.c index 25eaf5064489..21721afcfab2 100644 --- a/stand/powerpc/kboot/main.c +++ b/stand/powerpc/kboot/main.c @@ -31,7 +31,6 @@ __FBSDID("$FreeBSD$"); #include #include -#define _KERNEL #include #include "bootstrap.h" #include "host_syscall.h" diff --git a/sys/conf/files.powerpc b/sys/conf/files.powerpc index 013fe0fea33b..a5d3ec7153d9 100644 --- a/sys/conf/files.powerpc +++ b/sys/conf/files.powerpc @@ -88,8 +88,6 @@ libkern/divdi3.c optional powerpc | powerpcspe libkern/ffs.c standard libkern/ffsl.c standard libkern/ffsll.c standard -libkern/fls.c standard -libkern/flsl.c standard libkern/flsll.c standard libkern/lshrdi3.c optional powerpc | powerpcspe libkern/memcmp.c standard diff --git a/sys/powerpc/include/cpufunc.h b/sys/powerpc/include/cpufunc.h index bad2042bbb19..162a591d863b 100644 --- a/sys/powerpc/include/cpufunc.h +++ b/sys/powerpc/include/cpufunc.h @@ -212,6 +212,20 @@ get_pcpu(void) return (ret); } +#define HAVE_INLINE_FLS +static __inline __pure2 int +fls(int mask) +{ + return (mask ? 32 - __builtin_clz(mask) : 0); +} + +#define HAVE_INLINE_FLSL +static __inline __pure2 int +flsl(long mask) +{ + return (mask ? (8 * sizeof(long) - __builtin_clzl(mask)) : 0); +} + /* "NOP" operations to signify priorities to the kernel. */ static __inline void nop_prio_vlow(void)