2

Is there a standard Linux Kernel bit operation macro, which returns the number of bits set in an unsigned long ?

TheLoneJoker
  • 1,589
  • 1
  • 23
  • 36

2 Answers2

2

You can use:

hweight_long

function in include/linux/bitops.h

Othwerwise Linux kernel uses gcc with GNU extensions and gcc also provides these builtins:

Built-in Function: int __builtin_popcount (unsigned int x) Returns the number of 1-bits in x.

Built-in Function: int __builtin_popcountl (unsigned long) Similar to __builtin_popcount, except the argument type is unsigned long.

http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html

ouah
  • 142,963
  • 15
  • 272
  • 331
0

Since you included C in your tags. You could use C code to determine as pointed here

https://stackoverflow.com/a/2709523/1952879

Community
  • 1
  • 1
hmatar
  • 2,437
  • 2
  • 17
  • 27