Bit Operation Builtins (Using the GNU Compiler Collection (GCC))

#### 7.2.2 Bit Operation Builtins ¶

Built-in Function: `int` __builtin_ffs `(int x)` ¶

  Returns one plus the index of the least significant 1-bit of x, or if x is zero, returns zero.

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.

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.

Built-in Function: `int` __builtin_clrsb `(int x)` ¶

  Returns the number of leading redundant sign bits in x, i.e. the number of bits following the most significant bit that are identical to it. There are no special cases for 0 or other values.

Built-in Function: `int` __builtin_popcount `(unsigned int x)` ¶

  Returns the number of 1-bits in x.

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.

Built-in Function: `int` __builtin_ffsl `(long)` ¶

  Similar to `__builtin_ffs`, except the argument type is `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_clrsbl `(long)` ¶

  Similar to `__builtin_clrsb`, except the argument type is `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 `(long long)` ¶

  Similar to `__builtin_ffs`, except the argument type is `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_clrsbll `(long long)` ¶

  Similar to `__builtin_clrsb`, except the argument type is `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`.

Built-in Function: `int` __builtin_ffsg `(...)` ¶

  Similar to `__builtin_ffs`, except the argument is type-generic signed integer (standard, extended or bit-precise). No integral argument promotions are performed on the argument.

Built-in Function: `int` __builtin_clzg `(...)` ¶

  Similar to `__builtin_clz`, except the argument is type-generic unsigned integer (standard, extended or bit-precise) and there is optional second argument with int type. No integral argument promotions are performed on the first argument. If two arguments are specified, and first argument is 0, the result is the second argument. If only one argument is specified and it is 0, the result is undefined.

Built-in Function: `int` __builtin_ctzg `(...)` ¶

  Similar to `__builtin_ctz`, except the argument is type-generic unsigned integer (standard, extended or bit-precise) and there is optional second argument with int type. No integral argument promotions are performed on the first argument. If two arguments are specified, and first argument is 0, the result is the second argument. If only one argument is specified and it is 0, the result is undefined.

Built-in Function: `int` __builtin_clrsbg `(...)` ¶

  Similar to `__builtin_clrsb`, except the argument is type-generic signed integer (standard, extended or bit-precise). No integral argument promotions are performed on the argument.

Built-in Function: `int` __builtin_popcountg `(...)` ¶

  Similar to `__builtin_popcount`, except the argument is type-generic unsigned integer (standard, extended or bit-precise). No integral argument promotions are performed on the argument.

Built-in Function: `int` __builtin_parityg `(...)` ¶

  Similar to `__builtin_parity`, except the argument is type-generic unsigned integer (standard, extended or bit-precise). No integral argument promotions are performed on the argument.

Built-in Function: `type` __builtin_stdc_bit_ceil `(type arg)` ¶

  The `__builtin_stdc_bit_ceil` function is available only in C. It is type-generic, the argument can be any unsigned integer (standard, extended or bit-precise). No integral argument promotions are performed on the argument. It is equivalent to `arg <= 1 ? (type) 1 : (type) 2 << (prec - 1 - __builtin_clzg ((type) (arg - 1)))` where prec is bit width of type, except that side-effects in arg are evaluated just once.

Built-in Function: `type` __builtin_stdc_bit_floor `(type arg)` ¶

  The `__builtin_stdc_bit_floor` function is available only in C. It is type-generic, the argument can be any unsigned integer (standard, extended or bit-precise). No integral argument promotions are performed on the argument. It is equivalent to `arg == 0 ? (type) 0 : (type) 1 << (prec - 1 - __builtin_clzg (arg))` where prec is bit width of type, except that side-effects in arg are evaluated just once.

Built-in Function: `unsigned int` __builtin_stdc_bit_width `(type arg)` ¶

  The `__builtin_stdc_bit_width` function is available only in C. It is type-generic, the argument can be any unsigned integer (standard, extended or bit-precise). No integral argument promotions are performed on the argument. It is equivalent to `(unsigned int) (prec - __builtin_clzg (arg, prec))` where prec is bit width of type.

Built-in Function: `unsigned int` __builtin_stdc_count_ones `(type arg)` ¶

  The `__builtin_stdc_count_ones` function is available only in C. It is type-generic, the argument can be any unsigned integer (standard, extended or bit-precise). No integral argument promotions are performed on the argument. It is equivalent to `(unsigned int) __builtin_popcountg (arg)`

Built-in Function: `unsigned int` __builtin_stdc_count_zeros `(type arg)` ¶

  The `__builtin_stdc_count_zeros` function is available only in C. It is type-generic, the argument can be any unsigned integer (standard, extended or bit-precise). No integral argument promotions are performed on the argument. It is equivalent to `(unsigned int) __builtin_popcountg ((type) ~arg)`

Built-in Function: `unsigned int` __builtin_stdc_first_leading_one `(type arg)` ¶

  The `__builtin_stdc_first_leading_one` function is available only in C. It is type-generic, the argument can be any unsigned integer (standard, extended or bit-precise). No integral argument promotions are performed on the argument. It is equivalent to `__builtin_clzg (arg, -1) + 1U`

Built-in Function: `unsigned int` __builtin_stdc_first_leading_zero `(type arg)` ¶

  The `__builtin_stdc_first_leading_zero` function is available only in C. It is type-generic, the argument can be any unsigned integer (standard, extended or bit-precise). No integral argument promotions are performed on the argument. It is equivalent to `__builtin_clzg ((type) ~arg, -1) + 1U`

Built-in Function: `unsigned int` __builtin_stdc_first_trailing_one `(type arg)` ¶

  The `__builtin_stdc_first_trailing_one` function is available only in C. It is type-generic, the argument can be any unsigned integer (standard, extended or bit-precise). No integral argument promotions are performed on the argument. It is equivalent to `__builtin_ctzg (arg, -1) + 1U`

Built-in Function: `unsigned int` __builtin_stdc_first_trailing_zero `(type arg)` ¶

  The `__builtin_stdc_first_trailing_zero` function is available only in C. It is type-generic, the argument can be any unsigned integer (standard, extended or bit-precise). No integral argument promotions are performed on the argument. It is equivalent to `__builtin_ctzg ((type) ~arg, -1) + 1U`

Built-in Function: `unsigned int` __builtin_stdc_has_single_bit `(type arg)` ¶

  The `__builtin_stdc_has_single_bit` function is available only in C. It is type-generic, the argument can be any unsigned integer (standard, extended or bit-precise). No integral argument promotions are performed on the argument. It is equivalent to `(_Bool) (__builtin_popcountg (arg) == 1)`

Built-in Function: `unsigned int` __builtin_stdc_leading_ones `(type arg)` ¶

  The `__builtin_stdc_leading_ones` function is available only in C. It is type-generic, the argument can be any unsigned integer (standard, extended or bit-precise). No integral argument promotions are performed on the argument. It is equivalent to `(unsigned int) __builtin_clzg ((type) ~arg, prec)`

Built-in Function: `unsigned int` __builtin_stdc_leading_zeros `(type arg)` ¶

  The `__builtin_stdc_leading_zeros` function is available only in C. It is type-generic, the argument can be any unsigned integer (standard, extended or bit-precise). No integral argument promotions are performed on the argument. It is equivalent to `(unsigned int) __builtin_clzg (arg, prec)`

Built-in Function: `unsigned int` __builtin_stdc_trailing_ones `(type arg)` ¶

  The `__builtin_stdc_trailing_ones` function is available only in C. It is type-generic, the argument can be any unsigned integer (standard, extended or bit-precise). No integral argument promotions are performed on the argument. It is equivalent to `(unsigned int) __builtin_ctzg ((type) ~arg, prec)`

Built-in Function: `unsigned int` __builtin_stdc_trailing_zeros `(type arg)` ¶

  The `__builtin_stdc_trailing_zeros` function is available only in C. It is type-generic, the argument can be any unsigned integer (standard, extended or bit-precise). No integral argument promotions are performed on the argument. It is equivalent to `(unsigned int) __builtin_ctzg (arg, prec)`

Built-in Function: `type1` __builtin_stdc_rotate_left `(type1 arg1, type2 arg2)` ¶

  The `__builtin_stdc_rotate_left` function is available only in C. It is type-generic, the first argument can be any unsigned integer (standard, extended or bit-precise) and second argument any signed or unsigned integer or `char`. No integral argument promotions are performed on the arguments. It is equivalent to `(type1) ((arg1 << (arg2 % prec)) | (arg1 >> ((-(unsigned type2) arg2) % prec)))` where prec is bit width of type1, except that side-effects in arg1 and arg2 are evaluated just once. The behavior is undefined if arg2 is negative.

Built-in Function: `type1` __builtin_stdc_rotate_right `(type1 arg1, type2 arg2)` ¶

  The `__builtin_stdc_rotate_right` function is available only in C. It is type-generic, the first argument can be any unsigned integer (standard, extended or bit-precise) and second argument any signed or unsigned integer or `char`. No integral argument promotions are performed on the arguments. It is equivalent to `(type1) ((arg1 >> (arg2 % prec)) | (arg1 << ((-(unsigned type2) arg2) % prec)))` where prec is bit width of type1, except that side-effects in arg1 and arg2 are evaluated just once. The behavior is undefined if arg2 is negative.