Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Apr 2026 23:07:57 +0000
From:      Robert Clausecker <fuz@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: bc537e970d7e - main - libc/fls*.c: use *_WIDTH macros over CHAR_BIT * sizeof(type)
Message-ID:  <69e954cd.3c06c.572f584f@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by fuz:

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

commit bc537e970d7e52d278952915b0b1842dfbb03afc
Author:     Robert Clausecker <fuz@FreeBSD.org>
AuthorDate: 2026-04-22 22:47:23 +0000
Commit:     Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2026-04-22 22:58:54 +0000

    libc/fls*.c: use *_WIDTH macros over CHAR_BIT * sizeof(type)
    
    Makes the code easier to understand.
    
    MFC after:      1 week
---
 lib/libc/string/fls.c   | 2 +-
 lib/libc/string/flsl.c  | 2 +-
 lib/libc/string/flsll.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/libc/string/fls.c b/lib/libc/string/fls.c
index ac5fb7738722..dfc8397056cb 100644
--- a/lib/libc/string/fls.c
+++ b/lib/libc/string/fls.c
@@ -42,5 +42,5 @@
 int
 fls(int mask)
 {
-	return (mask == 0 ? 0 : CHAR_BIT * sizeof(mask) - __builtin_clz(mask));
+	return (mask == 0 ? 0 : INT_WIDTH - __builtin_clz(mask));
 }
diff --git a/lib/libc/string/flsl.c b/lib/libc/string/flsl.c
index d88c8dfcdc63..c6457c1382bb 100644
--- a/lib/libc/string/flsl.c
+++ b/lib/libc/string/flsl.c
@@ -43,5 +43,5 @@
 int
 flsl(long mask)
 {
-	return (mask == 0 ? 0 : CHAR_BIT * sizeof(mask) - __builtin_clzl(mask));
+	return (mask == 0 ? 0 : LONG_WIDTH - __builtin_clzl(mask));
 }
diff --git a/lib/libc/string/flsll.c b/lib/libc/string/flsll.c
index 635ebacddf18..bf11f7c338f1 100644
--- a/lib/libc/string/flsll.c
+++ b/lib/libc/string/flsll.c
@@ -42,5 +42,5 @@
 int
 flsll(long long mask)
 {
-	return (mask == 0 ? 0 : CHAR_BIT * sizeof(mask) - __builtin_clzll(mask));
+	return (mask == 0 ? 0 : LLONG_WIDTH - __builtin_clzll(mask));
 }


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69e954cd.3c06c.572f584f>