diff mbox series

[2/4] elf: Simplify hwcaps masked value bit counting

Message ID 20220905201027.0338ebf933cfd767cfa83da3@otheo.eu
State New
Headers show
Series elf: Fix hwcaps string size overestimation | expand

Commit Message

Javier Pello Sept. 5, 2022, 6:10 p.m. UTC
Use a simpler way to count the number of bits set in the masked
value in _dl_important_hwcaps.

Signed-off-by: Javier Pello <devel@otheo.eu>
---
 elf/dl-hwcaps.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/elf/dl-hwcaps.c b/elf/dl-hwcaps.c
index 92eb5379..8f11a18f 100644
--- a/elf/dl-hwcaps.c
+++ b/elf/dl-hwcaps.c
@@ -197,8 +197,8 @@  _dl_important_hwcaps (const char *glibc_hwcaps_prepend,
 		  + hwcaps_counts.total_length);
 
   /* Count the number of bits set in the masked value.  */
-  for (n = 0; (~((1ULL << n) - 1) & masked) != 0; ++n)
-    if ((masked & (1ULL << n)) != 0)
+  for (uint64_t mm = masked; mm != 0; mm >>= 1)
+    if ((mm & 1ULL) != 0)
       ++cnt;
 
   /* For TLS enabled builds always add 'tls'.  */