Bit Operation Library

XWOS Bit Operation Library

Bit Operations

XWOS provides a bit operation template library. Various non-function-pointer types defined in Basic Types can use bit operations. The bit operation function templates include:

  • xwbop_s1m(): Set all bits in the data mask portion to 1
  • xwbop_c0m(): Clear all bits in the data mask portion to 0
  • xwbop_x1m(): Toggle all bits in the data mask portion
  • xwbop_rbit(): Mirror-reverse the bits of the data
  • xwbop_re(): Reverse the endianness of the data
  • xwbop_ffs(): Find the first bit set to 1 starting from the least significant bit
  • xwbop_fls(): Find the first bit set to 1 starting from the most significant bit
  • xwbop_ffz(): Find the first bit cleared to 0 starting from the least significant bit
  • xwbop_flz(): Find the first bit cleared to 0 starting from the most significant bit
  • xwbop_weight(): Count the number of 1 bits in the data

The first parameter of all bit operation functions is the Basic Type, and the second parameter is the data or pointer to the data, for example:

xwssq_t idx;
/* Find the first bit set to 1 from the LSB in data "0" of type "xwu32_t", result is -1 */
idx = xwbop_ffs(xwu32_t, 0);

/* Find the first bit set to 1 from the LSB in data "0xF0" of type "xwu32_t", result is 4 */
idx = xwbop_ffs(xwu32_t, 0xF0);

 /* Mirror-reverse data "0xAA" of type "xwu32_t", result is 0x55 */
xwu32_t rdata = xwbop_rbit(xwu32_t, 0xAA);

Bitmap Operations

XWOS provides the basic type xwbmp_t for defining bitmaps. A bitmap is an array of xwbmp_t. Users can declare bitmaps of any number of bits. XWOS provides a function set for convenient bitmap operations:

  • xwbmpop_declare(): Declare a bitmap
  • xwbmpop_assign(): Assign
  • xwbmpop_cmp(): Compare two bitmaps
  • xwbmpop_s1all(): Set all bits to 1
  • xwbmpop_c0all(): Clear all bits to 0
  • xwbmpop_s1i(): Set a certain bit in the bitmap to 1
  • xwbmpop_s1m(): Set the mask portion of the bitmap to 1
  • xwbmpop_c0i(): Clear a certain bit in the bitmap to 0
  • xwbmpop_c0m(): Clear the mask portion of the bitmap to 0
  • xwbmpop_x1i(): Toggle a certain bit in the bitmap
  • xwbmpop_x1m(): Toggle the mask portion of the bitmap
  • xwbmpop_t1i(): Test whether a certain bit in the bitmap is 1
  • xwbmpop_t1ma(): Test whether all bits in the mask portion are 1
  • xwbmpop_t1ma_then_c0m(): Test whether all bits in the mask portion are 1, and if so, clear the mask portion to 0
  • xwbmpop_t1mo(): Test whether at least one bit in the mask portion is 1
  • xwbmpop_t1mo_then_c0m(): Test whether at least one bit in the mask portion is 1, and if so, clear the mask portion to 0
  • xwbmpop_t0ma(): Test whether all bits in the mask portion are 0
  • xwbmpop_t0ma_then_s1m(): Test whether all bits in the mask portion are 0, and if so, set the mask portion to 1
  • xwbmpop_t0mo(): Test whether at least one bit in the mask portion is 0
  • xwbmpop_t0mo_then_s1m(): Test whether at least one bit in the mask portion is 0, and if so, set the mask portion to 1
  • xwbmpop_not(): NOT operation
  • xwbmpop_and(): AND operation
  • xwbmpop_or(): OR operation
  • xwbmpop_xor(): XOR operation
  • xwbmpop_ffs(): Find the first bit set to 1 starting from the LSB
  • xwbmpop_fls(): Find the first bit set to 1 starting from the MSB
  • xwbmpop_ffz(): Find the first bit cleared to 0 starting from the LSB
  • xwbmpop_flz(): Find the first bit cleared to 0 starting from the MSB
  • xwbmpop_weight(): Count the number of 1 bits

API Reference