— Built-in Function:
int __builtin_ffs (unsigned int x)
Returns one plus the index of the least significant 1-bit of x, or if x is zero, returns zero.
返回右起第一个‘1’的位置。
— Built-in Function: int __builtin_clz (unsigned int x)
Returns the number of leading 0-bits in x, starting at the most significant bit position. If x is 0, the result is undefined.
返回左起第一个‘1’之前0的个数。
— Built-in Function: int __builtin_ctz (unsigned int x)
Returns the number of trailing 0-bits in x, starting at the least significant bit position. If x is 0, the result is undefined.
返回右起第一个‘1’之后的0的个数。
— Built-in Function: int __builtin_popcount (unsigned int x)
Returns the number of 1-bits in x.
返回‘1’的个数。
— Built-in Function: int __builtin_parity (unsigned int x)
Returns the parity of x, i.e. the number of 1-bits in x modulo 2.
返回‘1’的个数的奇偶性。
— Built-in Function: int __builtin_ffsl (unsigned long)
Similar to __builtin_ffs, except the argument type is unsigned long.
— Built-in Function: int __builtin_clzl (unsigned long)
Similar to __builtin_clz, except the argument type is unsigned long.
— Built-in Function: int __builtin_ctzl (unsigned long)
Similar to __builtin_ctz, except the argument type is unsigned long.
— Built-in Function: int __builtin_popcountl (unsigned long)
Similar to __builtin_popcount, except the argument type is unsigned long.
— Built-in Function: int __builtin_parityl (unsigned long)
Similar to __builtin_parity, except the argument type is unsigned long.
— Built-in Function: int __builtin_ffsll (unsigned long long)
Similar to __builtin_ffs, except the argument type is unsigned long long.
— Built-in Function: int __builtin_clzll (unsigned long long)
Similar to __builtin_clz, except the argument type is unsigned long long.
— Built-in Function: int __builtin_ctzll (unsigned long long)
Similar to __builtin_ctz, except the argument type is unsigned long long.
— Built-in Function: int __builtin_popcountll (unsigned long long)
Similar to __builtin_popcount, except the argument type is unsigned long long.
— Built-in Function: int __builtin_parityll (unsigned long long)
Similar to __builtin_parity, except the argument type is unsigned long long.
【实验程序】
uint32_t g_arr[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, UINT_MAX-1, UINT_MAX};
|
printf ( "%s:\n" , g_str_func[0].c_str());
|
for
( int
i = 0; i < 12; i ++) { |
printf ( "%u(%s): %d\n" , t, b.to_string().c_str(),
__builtin_ffs(t)); |
printf ( "%s:\n" , g_str_func[1].c_str());
|
for
( int
i = 0; i < 12; i ++) { |
printf ( "%u(%s): %d\n" , t, b.to_string().c_str(),
__builtin_clz(t)); |
printf ( "%s:\n" , g_str_func[2].c_str());
|
for
( int
i = 0; i < 12; i ++) { |
printf ( "%u(%s): %d\n" , t, b.to_string().c_str(),
__builtin_ctz(t)); |
printf ( "%s:\n" , g_str_func[3].c_str());
|
for
( int
i = 0; i < 12; i ++) { |
printf ( "%u(%s): %d\n" , t, b.to_string().c_str(),
__builtin_popcount(t)); |
printf ( "%s:\n" , g_str_func[4].c_str());
|
for
( int
i = 0; i < 12; i ++) { |
printf ( "%u(%s): %d\n" , t, b.to_string().c_str(),
__builtin_parity(t)); |
这里存在一个为题,希望知道的朋友能够解释,就是为什么不能用函数指针指向这些内置函数。
【测试结果】
0(00000000000000000000000000000000): 0
|
1(00000000000000000000000000000001): 1
|
2(00000000000000000000000000000010): 2
|
3(00000000000000000000000000000011): 1
|
4(00000000000000000000000000000100): 3
|
5(00000000000000000000000000000101): 1
|
6(00000000000000000000000000000110): 2
|
7(00000000000000000000000000000111): 1
|
8(00000000000000000000000000001000): 4
|
9(00000000000000000000000000001001): 1
|
4294967294(11111111111111111111111111111110): 2
|
4294967295(11111111111111111111111111111111): 1
|
0(00000000000000000000000000000000): 31
|
1(00000000000000000000000000000001): 31
|
2(00000000000000000000000000000010): 30
|
3(00000000000000000000000000000011): 30
|
4(00000000000000000000000000000100): 29
|
5(00000000000000000000000000000101): 29
|
6(00000000000000000000000000000110): 29
|
7(00000000000000000000000000000111): 29
|
8(00000000000000000000000000001000): 28
|
9(00000000000000000000000000001001): 28
|
4294967294(11111111111111111111111111111110): 0
|
4294967295(11111111111111111111111111111111): 0
|
0(00000000000000000000000000000000): 0
|
1(00000000000000000000000000000001): 0
|
2(00000000000000000000000000000010): 1
|
3(00000000000000000000000000000011): 0
|
4(00000000000000000000000000000100): 2
|
5(00000000000000000000000000000101): 0
|
6(00000000000000000000000000000110): 1
|
7(00000000000000000000000000000111): 0
|
8(00000000000000000000000000001000): 3
|
9(00000000000000000000000000001001): 0
|
4294967294(11111111111111111111111111111110): 1
|
4294967295(11111111111111111111111111111111): 0
|
0(00000000000000000000000000000000): 0
|
1(00000000000000000000000000000001): 1
|
2(00000000000000000000000000000010): 1
|
3(00000000000000000000000000000011): 2
|
4(00000000000000000000000000000100): 1
|
5(00000000000000000000000000000101): 2
|
6(00000000000000000000000000000110): 2
|
7(00000000000000000000000000000111): 3
|
8(00000000000000000000000000001000): 1
|
9(00000000000000000000000000001001): 2
|
4294967294(11111111111111111111111111111110): 31
|
4294967295(11111111111111111111111111111111): 32
|
0(00000000000000000000000000000000): 0
|
1(00000000000000000000000000000001): 1
|
2(00000000000000000000000000000010): 1
|
3(00000000000000000000000000000011): 0
|
4(00000000000000000000000000000100): 1
|
5(00000000000000000000000000000101): 0
|
6(00000000000000000000000000000110): 0
|
7(00000000000000000000000000000111): 1
|
8(00000000000000000000000000001000): 1
|
9(00000000000000000000000000001001): 0
|
4294967294(11111111111111111111111111111110): 1
|
4294967295(11111111111111111111111111111111): 0
|
Process returned 0 (0x0) execution
time : 2.405 s
|
Press any key to
continue . |