git: 6d3ce617f398 - stable/13 - amd64: use compiler intrinsics for bsf* and bsr*
Mateusz Guzik
mjg at FreeBSD.org
Thu Feb 4 18:01:58 UTC 2021
The branch stable/13 has been updated by mjg:
URL: https://cgit.FreeBSD.org/src/commit/?id=6d3ce617f398d4066780555210270b97c30e7c0e
commit 6d3ce617f398d4066780555210270b97c30e7c0e
Author: Mateusz Guzik <mjg at FreeBSD.org>
AuthorDate: 2021-01-31 23:35:30 +0000
Commit: Mateusz Guzik <mjg at FreeBSD.org>
CommitDate: 2021-02-04 18:01:08 +0000
amd64: use compiler intrinsics for bsf* and bsr*
(cherry picked from commit aae89f6f09576351cc3a9a54959649e60fdd849b)
---
sys/amd64/include/cpufunc.h | 36 ++++--------------------------------
1 file changed, 4 insertions(+), 32 deletions(-)
diff --git a/sys/amd64/include/cpufunc.h b/sys/amd64/include/cpufunc.h
index 763ed2c64c8a..8ef298e1d7d5 100644
--- a/sys/amd64/include/cpufunc.h
+++ b/sys/amd64/include/cpufunc.h
@@ -65,41 +65,13 @@ breakpoint(void)
__asm __volatile("int $3");
}
-static __inline __pure2 u_int
-bsfl(u_int mask)
-{
- u_int result;
-
- __asm __volatile("bsfl %1,%0" : "=r" (result) : "rm" (mask));
- return (result);
-}
-
-static __inline __pure2 u_long
-bsfq(u_long mask)
-{
- u_long result;
-
- __asm __volatile("bsfq %1,%0" : "=r" (result) : "rm" (mask));
- return (result);
-}
-
-static __inline __pure2 u_int
-bsrl(u_int mask)
-{
- u_int result;
+#define bsfl(mask) __builtin_ctz(mask)
- __asm __volatile("bsrl %1,%0" : "=r" (result) : "rm" (mask));
- return (result);
-}
+#define bsfq(mask) __builtin_ctzl(mask)
-static __inline __pure2 u_long
-bsrq(u_long mask)
-{
- u_long result;
+#define bsrl(mask) (__builtin_clz(mask) ^ 0x1f)
- __asm __volatile("bsrq %1,%0" : "=r" (result) : "rm" (mask));
- return (result);
-}
+#define bsrq(mask) (__builtin_clzl(mask) ^ 0x3f)
static __inline void
clflush(u_long addr)
More information about the dev-commits-src-all
mailing list