Lines Matching +full:128 +full:- +full:bit
4 * SPDX-License-Identifier: Apache-2.0
17 #define BIT_INDEX(bit) ((3 - ((bit >> 3) & 0x3)) + 4*(bit >> 5)) argument
19 #define BIT_INDEX(bit) (bit >> 3) argument
21 #define BIT_VAL(bit) (1 << (bit & 0x7)) argument
61 zassert_equal(ba->num_bits, num_bits, in validate_bitarray_define()
63 num_bits, ba->num_bits); in validate_bitarray_define()
65 zassert_equal(ba->num_bundles, num_bundles, in validate_bitarray_define()
67 num_bundles, ba->num_bundles); in validate_bitarray_define()
70 zassert_equal(ba->bundles[i], FREE, in validate_bitarray_define()
88 SYS_BITARRAY_DEFINE(ba_128_bit, 128); in ZTEST()
100 validate_bitarray_define(&ba_128_bit, 128); in ZTEST()
109 for (i = 0; i < ba->num_bundles; i++) { in bitarray_bundles_is_zero()
110 if (ba->bundles[i] != 0) { in bitarray_bundles_is_zero()
132 size_t bit, bundle_idx, bit_idx_in_bundle; in ZTEST() local
141 for (bit = 0U; bit < ba.num_bits; ++bit) { in ZTEST()
142 bundle_idx = bit / (sizeof(ba.bundles[0]) * 8); in ZTEST()
143 bit_idx_in_bundle = bit % (sizeof(ba.bundles[0]) * 8); in ZTEST()
145 ret = sys_bitarray_set_bit(&ba, bit); in ZTEST()
147 "sys_bitarray_set_bit failed on bit %d", bit); in ZTEST()
148 zassert_equal(ba.bundles[bundle_idx], BIT(bit_idx_in_bundle), in ZTEST()
149 "sys_bitarray_set_bit did not set bit %d\n", bit); in ZTEST()
150 zassert_not_equal(sys_bitfield_test_bit((mem_addr_t)ba.bundles, bit), in ZTEST()
151 0, "sys_bitarray_set_bit did not set bit %d\n", bit); in ZTEST()
153 ret = sys_bitarray_test_bit(&ba, bit, &bit_val); in ZTEST()
155 "sys_bitarray_test_bit failed at bit %d", bit); in ZTEST()
157 "sys_bitarray_test_bit did not detect bit %d\n", bit); in ZTEST()
159 ret = sys_bitarray_clear_bit(&ba, bit); in ZTEST()
161 "sys_bitarray_clear_bit failed at bit %d", bit); in ZTEST()
163 "sys_bitarray_clear_bit did not clear bit %d\n", bit); in ZTEST()
164 zassert_equal(sys_bitfield_test_bit((mem_addr_t)ba.bundles, bit), in ZTEST()
165 0, "sys_bitarray_set_bit did not set bit %d\n", bit); in ZTEST()
167 ret = sys_bitarray_test_bit(&ba, bit, &bit_val); in ZTEST()
169 "sys_bitarray_test_bit failed at bit %d", bit); in ZTEST()
171 "sys_bitarray_test_bit erroneously detected bit %d\n", in ZTEST()
172 bit); in ZTEST()
174 ret = sys_bitarray_test_and_set_bit(&ba, bit, &bit_val); in ZTEST()
176 "sys_bitarray_test_and_set_bit failed at bit %d", bit); in ZTEST()
178 "sys_bitarray_test_and_set_bit erroneously detected bit %d\n", in ZTEST()
179 bit); in ZTEST()
180 zassert_equal(ba.bundles[bundle_idx], BIT(bit_idx_in_bundle), in ZTEST()
181 "sys_bitarray_test_and_set_bit did not set bit %d\n", bit); in ZTEST()
182 zassert_not_equal(sys_bitfield_test_bit((mem_addr_t)ba.bundles, bit), in ZTEST()
183 0, "sys_bitarray_set_bit did not set bit %d\n", bit); in ZTEST()
185 ret = sys_bitarray_test_and_set_bit(&ba, bit, &bit_val); in ZTEST()
187 "sys_bitarray_test_and_set_bit failed at bit %d", bit); in ZTEST()
189 "sys_bitarray_test_and_set_bit did not detect bit %d\n", in ZTEST()
190 bit); in ZTEST()
191 zassert_equal(ba.bundles[bundle_idx], BIT(bit_idx_in_bundle), in ZTEST()
192 "sys_bitarray_test_and_set_bit cleared bit %d\n", bit); in ZTEST()
193 zassert_not_equal(sys_bitfield_test_bit((mem_addr_t)ba.bundles, bit), in ZTEST()
194 0, "sys_bitarray_set_bit did not set bit %d\n", bit); in ZTEST()
196 ret = sys_bitarray_test_and_clear_bit(&ba, bit, &bit_val); in ZTEST()
198 "sys_bitarray_test_and_clear_bit failed at bit %d", bit); in ZTEST()
200 "sys_bitarray_test_and_clear_bit did not detect bit %d\n", in ZTEST()
201 bit); in ZTEST()
203 "sys_bitarray_test_and_clear_bit did not clear bit %d\n", in ZTEST()
204 bit); in ZTEST()
205 zassert_equal(sys_bitfield_test_bit((mem_addr_t)ba.bundles, bit), in ZTEST()
206 0, "sys_bitarray_set_bit did not set bit %d\n", bit); in ZTEST()
208 ret = sys_bitarray_test_and_clear_bit(&ba, bit, &bit_val); in ZTEST()
210 "sys_bitarray_test_and_clear_bit failed at bit %d", bit); in ZTEST()
212 "sys_bitarray_test_and_clear_bit erroneously detected bit %d\n", in ZTEST()
213 bit); in ZTEST()
215 "sys_bitarray_test_and_clear_bit set bit %d\n", in ZTEST()
216 bit); in ZTEST()
217 zassert_equal(sys_bitfield_test_bit((mem_addr_t)ba.bundles, bit), in ZTEST()
218 0, "sys_bitarray_set_bit did not set bit %d\n", bit); in ZTEST()
222 * total bits in bit array. Also needs to make sure bits in ZTEST()
252 ret = sys_bitarray_set_bit(&ba, -1); in ZTEST()
257 ret = sys_bitarray_clear_bit(&ba, -1); in ZTEST()
262 ret = sys_bitarray_test_bit(&ba, -1, &bit_val); in ZTEST()
267 ret = sys_bitarray_test_and_set_bit(&ba, -1, &bit_val); in ZTEST()
273 ret = sys_bitarray_test_and_clear_bit(&ba, -1, &bit_val); in ZTEST()
287 SYS_BITARRAY_DEFINE(ba_128, 128); in alloc_and_free_predefined()
289 printk("Testing bit array alloc and free with predefined patterns\n"); in alloc_and_free_predefined()
291 /* Pre-populate the bits */ in alloc_and_free_predefined()
340 /* test in-between bundles */ in alloc_and_free_predefined()
367 val = val & (val - 1); in count_bits()
379 for (idx = 0; idx < ba->num_bundles; idx++) { in get_bitarray_popcnt()
380 popcnt += count_bits(ba->bundles[idx]); in get_bitarray_popcnt()
390 size_t bit; in alloc_and_free_loop() local
397 printk("Testing bit array alloc and free with divisor %d\n", divisor); in alloc_and_free_loop()
399 for (bit = 0U; bit < ba.num_bits; ++bit) { in alloc_and_free_loop()
402 "bit count expected %u, got %u (at bit %u)", in alloc_and_free_loop()
403 expected_popcnt, cur_popcnt, bit); in alloc_and_free_loop()
406 num_bits = (ba.num_bits - bit) / divisor; in alloc_and_free_loop()
411 "sys_bitarray_free() should fail but not (bit %u)", in alloc_and_free_loop()
412 bit); in alloc_and_free_loop()
415 "sys_bitarray_alloc() failed (%d) at bit %u", in alloc_and_free_loop()
416 ret, bit); in alloc_and_free_loop()
417 zassert_equal(offset, bit, in alloc_and_free_loop()
419 bit, offset); in alloc_and_free_loop()
426 "bit count expected %u, got %u (at bit %u)", in alloc_and_free_loop()
427 expected_popcnt, cur_popcnt, bit); in alloc_and_free_loop()
429 /* Free all but the first bit of allocated region */ in alloc_and_free_loop()
430 ret = sys_bitarray_free(&ba, (num_bits - 1), (bit + 1)); in alloc_and_free_loop()
431 if ((num_bits == 0) || ((num_bits - 1) == 0)) { in alloc_and_free_loop()
433 "sys_bitarray_free() should fail but not (bit %u)", in alloc_and_free_loop()
434 bit); in alloc_and_free_loop()
437 "sys_bitarray_free() failed (%d) at bit %u", in alloc_and_free_loop()
438 ret, (bit + 1)); in alloc_and_free_loop()
440 expected_popcnt -= num_bits - 1; in alloc_and_free_loop()
456 printk("Testing bit array interval alloc and free\n"); in alloc_and_free_interval()
458 /* Pre-populate the bits so that 4-bit already allocated, in alloc_and_free_interval()
487 "bit count expected %u, got %u (cnt %u)", in alloc_and_free_interval()
533 SYS_BITARRAY_DEFINE(ba, 128); in ZTEST()
535 printk("Testing bit array region popcount spanning single bundle\n"); in ZTEST()
537 /* Pre-populate the bits */ in ZTEST()
568 printk("Testing bit array region popcount spanning multiple bundles\n"); in ZTEST()
570 /* Pre-populate the bits. in ZTEST()
571 * First and last bit of bitarray are set in ZTEST()
597 ret = sys_bitarray_popcount_region(&ba, 128, 0, &count); in ZTEST()
604 zassert_equal(ret, -EINVAL, "sys_bitarray_popcount_region() returned unexpected value: %d", in ZTEST()
606 ret = sys_bitarray_popcount_region(&ba, 0, 128, &count); in ZTEST()
607 zassert_equal(ret, -EINVAL, "sys_bitarray_popcount_region() returned unexpected value: %d", in ZTEST()
609 ret = sys_bitarray_popcount_region(&ba, 128, 0, &count); in ZTEST()
612 ret = sys_bitarray_popcount_region(&ba, 128, 1, &count); in ZTEST()
613 zassert_equal(ret, -EINVAL, "sys_bitarray_popcount_region() returned unexpected value: %d", in ZTEST()
616 zassert_equal(ret, -EINVAL, "sys_bitarray_popcount_region() returned unexpected value: %d", in ZTEST()
629 SYS_BITARRAY_DEFINE(ba, 128); in ZTEST()
630 SYS_BITARRAY_DEFINE(bb, 128); in ZTEST()
633 printk("Testing bit array region xor spanning single bundle\n"); in ZTEST()
635 /* Pre-populate the bits */ in ZTEST()
668 /* Pre-populate the bits */ in ZTEST()
686 /* Pre-populate the bits */ in ZTEST()
704 printk("Testing bit array region xor spanning multiple bundles\n"); in ZTEST()
706 /* Pre-populate the bits */ in ZTEST()
717 ret = sys_bitarray_xor(&ba, &bb, 32*3 - 2, 32 + 1); in ZTEST()
729 /* Pre-populate the bits */ in ZTEST()
749 zassert_equal(ret, -EINVAL, "sys_bitarray_xor() returned unexpected value: %d", ret); in ZTEST()
751 zassert_equal(ret, -EINVAL, "sys_bitarray_xor() returned unexpected value: %d", ret); in ZTEST()
753 ret = sys_bitarray_xor(&ba, &bb, 128, 0); in ZTEST()
755 ret = sys_bitarray_xor(&ba, &bb, 128, 1); in ZTEST()
756 zassert_equal(ret, -EINVAL, "sys_bitarray_xor() returned unexpected value: %d", ret); in ZTEST()
758 zassert_equal(ret, -EINVAL, "sys_bitarray_xor() returned unexpected value: %d", ret); in ZTEST()
760 zassert_equal(ret, -EINVAL, "sys_bitarray_xor() returned unexpected value: %d", ret); in ZTEST()
773 SYS_BITARRAY_DEFINE(ba, 128); in ZTEST()
775 printk("Testing bit array nth bit set finding spanning single bundle\n"); in ZTEST()
777 /* Pre-populate the bits */ in ZTEST()
806 printk("Testing bit array nth bit set finding spanning multiple bundles\n"); in ZTEST()
808 ret = sys_bitarray_find_nth_set(&ba, 1, 128, 0, &found_at); in ZTEST()
813 ret = sys_bitarray_find_nth_set(&ba, 8, 128, 0, &found_at); in ZTEST()
818 ret = sys_bitarray_find_nth_set(&ba, 8, 128, 1, &found_at); in ZTEST()
819 zassert_equal(ret, -EINVAL, "sys_bitarray_find_nth_set() returned unexpected value: %d", in ZTEST()
854 ret = sys_bitarray_find_nth_set(&ba, 1, 128, 0, &found_at); in ZTEST()
857 ret = sys_bitarray_find_nth_set(&ba, 1, 128, 1, &found_at); in ZTEST()
858 zassert_equal(ret, -EINVAL, "sys_bitarray_find_nth_set() returned unexpected value: %d", in ZTEST()
862 zassert_equal(ret, -EINVAL, "sys_bitarray_find_nth_set() returned unexpected value: %d", in ZTEST()
865 ret = sys_bitarray_find_nth_set(&ba, 0, 128, 0, &found_at); in ZTEST()
866 zassert_equal(ret, -EINVAL, "sys_bitarray_find_nth_set() returned unexpected value: %d", in ZTEST()
883 printk("Testing bit array region bit tests\n"); in ZTEST()
885 /* Pre-populate the bits */ in ZTEST()
921 printk("Testing bit array region bit manipulations\n"); in ZTEST()
923 /* Pre-populate the bits */ in ZTEST()
963 zassert_equal(ret, -EINVAL, "sys_bitarray_set_region() should fail but not"); in ZTEST()
968 zassert_equal(ret, -EINVAL, "sys_bitarray_set_region() should fail but not"); in ZTEST()
973 zassert_equal(ret, -EINVAL, "sys_bitarray_clear_region() should fail but not"); in ZTEST()
978 zassert_equal(ret, -EINVAL, "sys_bitarray_clear_region() should fail but not"); in ZTEST()
982 SYS_BITARRAY_DEFINE(bw, 128); in ZTEST()
984 /* Pre-populate the bits */ in ZTEST()
1015 * bit and least significant bit work as expected.
1022 unsigned int bit; in ZTEST() local
1049 /* boundary test, input is max - 1 */ in ZTEST()
1054 /* equivalent class testing, each bit means a class */ in ZTEST()
1055 for (bit = 0; bit < 32 ; bit++) { in ZTEST()
1056 value = 1UL << bit; in ZTEST()
1057 zassert_equal(find_msb_set(value), bit + 1, "MSB is not matched"); in ZTEST()
1058 zassert_equal(find_lsb_set(value), bit + 1, "LSB is not matched"); in ZTEST()