From 1f33dab2e64bc23f737afc8fa3d0bf09a7974668 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 24 Jun 2024 21:56:08 -0400 Subject: [PATCH] freebsd_network: Move ffs/fls routines to libkern.h and use builtins. FreeBSD upstream did this a while back. Should fix the 32-bit build. --- .../compat/machine/x86_64/cpufunc.h | 47 ------------------- .../freebsd_network/compat/sys/libkern.h | 35 ++++++++++++++ 2 files changed, 35 insertions(+), 47 deletions(-) diff --git a/src/libs/compat/freebsd_network/compat/machine/x86_64/cpufunc.h b/src/libs/compat/freebsd_network/compat/machine/x86_64/cpufunc.h index 53a9a5d489..f981a6bb70 100644 --- a/src/libs/compat/freebsd_network/compat/machine/x86_64/cpufunc.h +++ b/src/libs/compat/freebsd_network/compat/machine/x86_64/cpufunc.h @@ -144,53 +144,6 @@ enable_intr(void) __asm __volatile("sti"); } -#ifdef _KERNEL - -#define HAVE_INLINE_FFS -#define ffs(x) __builtin_ffs(x) - -#define HAVE_INLINE_FFSL - -static __inline int -ffsl(long mask) -{ - return (mask == 0 ? mask : (int)bsfq((u_long)mask) + 1); -} - -#define HAVE_INLINE_FFSLL - -static __inline int -ffsll(long long mask) -{ - return (ffsl((long)mask)); -} - -#define HAVE_INLINE_FLS - -static __inline int -fls(int mask) -{ - return (mask == 0 ? mask : (int)bsrl((u_int)mask) + 1); -} - -#define HAVE_INLINE_FLSL - -static __inline int -flsl(long mask) -{ - return (mask == 0 ? mask : (int)bsrq((u_long)mask) + 1); -} - -#define HAVE_INLINE_FLSLL - -static __inline int -flsll(long long mask) -{ - return (flsl((long)mask)); -} - -#endif /* _KERNEL */ - static __inline void halt(void) { diff --git a/src/libs/compat/freebsd_network/compat/sys/libkern.h b/src/libs/compat/freebsd_network/compat/sys/libkern.h index 9517aec378..4fbaa73040 100644 --- a/src/libs/compat/freebsd_network/compat/sys/libkern.h +++ b/src/libs/compat/freebsd_network/compat/sys/libkern.h @@ -26,6 +26,41 @@ static __inline int imin(int a, int b) { return (a < b ? a : b); } extern int abs(int a); +#define ffs(x) __builtin_ffs(x) + +static __inline __pure2 int +ffsl(long mask) +{ + return (__builtin_ffsl((u_long)mask)); +} + +static __inline __pure2 int +ffsll(long long mask) +{ + return (__builtin_ffsll((unsigned long long)mask)); +} + +static __inline __pure2 int +fls(int mask) +{ + return (mask == 0 ? 0 : + 8 * sizeof(mask) - __builtin_clz((u_int)mask)); +} + +static __inline __pure2 int +flsl(long mask) +{ + return (mask == 0 ? 0 : + 8 * sizeof(mask) - __builtin_clzl((u_long)mask)); +} + +static __inline __pure2 int +flsll(long long mask) +{ + return (mask == 0 ? 0 : + 8 * sizeof(mask) - __builtin_clzll((unsigned long long)mask)); +} + __END_DECLS #endif /* _FBSD_COMPAT_SYS_LIBKERN_H_ */