return r;
}
+
+/**
+ * u32_bitflip - flips bits in number.
+ * @n: number
+ *
+ * This function flips bits in the given number such that MSB becomes LSB and vice versa.
+ */
+
+u32
+u32_bitflip(u32 n)
+{
+ n = ((n & 0xffff0000) >> 16) | ((n & 0x0000ffff) << 16);
+ n = ((n & 0xff00ff00) >> 8) | ((n & 0x00ff00ff) << 8);
+ n = ((n & 0xf0f0f0f0) >> 4) | ((n & 0x0f0f0f0f) << 4);
+ n = ((n & 0xcccccccc) >> 2) | ((n & 0x33333333) << 2);
+ n = ((n & 0xaaaaaaaa) >> 1) | ((n & 0x55555555) << 1);
+ return n;
+}
return 1;
}
+static void
+check_bitflip(u32 n)
+{
+ u32 rot = u32_bitflip(n);
+ for (int i = 0; i < 16; i++)
+ {
+ bt_assert(!((n >> i) & 1) == !((rot << i) & 0x80000000));
+ bt_assert(!((rot >> i) & 1) == !((n << i) & 0x80000000));
+ }
+}
+
+static int
+t_bitflip(void)
+{
+ u32 i;
+
+ for (i = 0; i < MAX_NUM; i++)
+ {
+ check_bitflip(i);
+ check_bitflip((u32) bt_random());
+ }
+
+ return 1;
+}
+
int
main(int argc, char *argv[])
{
bt_test_suite(t_mkmask, "u32_mkmask()");
bt_test_suite(t_masklen, "u32_masklen()");
bt_test_suite(t_log2, "u32_log2()");
+ bt_test_suite(t_bitflip, "u32_bitflip()");
return bt_exit_value();
}