Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 1 Feb 2021 05:02:45 GMT
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: aae89f6f0957 - main - amd64: use compiler intrinsics for bsf* and bsr*
Message-ID:  <202102010502.11152jb4099013@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=aae89f6f09576351cc3a9a54959649e60fdd849b

commit aae89f6f09576351cc3a9a54959649e60fdd849b
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2021-01-31 23:35:30 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2021-02-01 04:53:23 +0000

    amd64: use compiler intrinsics for bsf* and bsr*
---
 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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202102010502.11152jb4099013>