__builtin_clz(unsigned x); // count leading zeros
__builtin_ctz(unsigned x); // count trailing zeros
__builtin_popcount(unsigned x); // 1的个数
// ffs, parity 感觉没啥用。前者返回ctz+1,后者返回popcount&1
// 另:与大多数函数一样,后缀 l 表示long型参数,后缀 ll 表示long long型参数。
__builtin_popcountll(unsigned long long x);
__builtin_clz(unsigned x); // count leading zeros
__builtin_ctz(unsigned x); // count trailing zeros
__builtin_popcount(unsigned x); // 1的个数
ffs, parity 感觉没啥用。前者返回ctz+1,后者返回popcount&1
另:与大多数函数一样,后缀 l 表示long型参数,后缀 ll 表示long long型参数。
如__builtin_popcountll(unsigned long long x);