aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/string/flsl.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/string/flsl.c')
-rw-r--r--lib/libc/string/flsl.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/lib/libc/string/flsl.c b/lib/libc/string/flsl.c
index 60370cf7d832..d88c8dfcdc63 100644
--- a/lib/libc/string/flsl.c
+++ b/lib/libc/string/flsl.c
@@ -3,6 +3,11 @@
*
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
+ * Copyright (c) 2023 The FreeBSD Foundation
+
+ *
+ * Portions of this software were developed by Robert Clausecker
+ * <fuz@FreeBSD.org> under sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -29,9 +34,7 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
+#include <limits.h>
#include <strings.h>
/*
@@ -40,11 +43,5 @@ __FBSDID("$FreeBSD$");
int
flsl(long mask)
{
- int bit;
-
- if (mask == 0)
- return (0);
- for (bit = 1; mask != 1; bit++)
- mask = (unsigned long)mask >> 1;
- return (bit);
+ return (mask == 0 ? 0 : CHAR_BIT * sizeof(mask) - __builtin_clzl(mask));
}