是否有标准的 Linux 内核位操作宏,它返回 unsigned long 中设置的位数?
最佳答案
您可以使用:
hweight_long
include/linux/bitops.h
中的函数
否则 Linux 内核使用 gcc
带有 GNU 扩展和 gcc
还提供了这些内置函数:
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.
关于c - 用于计数位集的内核宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14366069/