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.
This commit is contained in:
Augustin Cavalier
2024-06-24 21:56:08 -04:00
parent 86021fd407
commit 1f33dab2e6
2 changed files with 35 additions and 47 deletions
@@ -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)
{
@@ -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_ */