Skip to content
BitVecForeachInRange

BitVecForeachInRange

BitVecForeachInRange

Description

Iterate over bits in a specific range of the given bitvector bv. This is a convenience macro that iterates over a range using an internally managed index. The variable var is declared and defined by this macro.

Parameters

Name Direction Description
bv in,out Bitvector to iterate over.
var in Name of variable to be used which’ll contain bit value of the current bit.
start in Starting index (inclusive).
end in Ending index (exclusive).

Usage example (Cross-references)

Usage examples (Cross-references)
    // Test BitVecForeachInRange macro
    bool test_bitvec_foreach_in_range(void) {
        WriteFmt("Testing BitVecForeachInRange macro\n");
    
        BitVec bv = BitVecInit();
        u64 false_count = 0;
    
        BitVecForeachInRange(&bv, bit, 1, 3) {
            // Should iterate over indices 1, 2
            // Values: true, true
        // Test range with start == end (should not execute)
        int count = 0;
        BitVecForeachInRange(&bv, bit, 5, 5) {
            (void)bit;
            count++; // Should not execute
        // Test range with single element
        count = 0;
        BitVecForeachInRange(&bv, bit, 3, 4) {
            count++;
            result = result && (bit == false); // 3 % 2 != 0
        // Test range at boundaries
        count = 0;
        BitVecForeachInRange(&bv, bit, 0, 2) {
            (void)bit;
            count++;
        // Test range at the end of bitvector
        count = 0;
        BitVecForeachInRange(&bv, bit, 8, 10) {
            (void)bit;
            count++;
    // Test BitVecForeachInRange macro
    bool test_bitvec_foreach_in_range(void) {
        WriteFmt("Testing BitVecForeachInRange macro\n");
    
        BitVec bv = BitVecInit();
        u64 false_count = 0;
    
        BitVecForeachInRange(&bv, bit, 1, 3) {
            // Should iterate over indices 1, 2
            // Values: true, true
        // Test range with start == end (should not execute)
        int count = 0;
        BitVecForeachInRange(&bv, bit, 5, 5) {
            (void)bit;
            count++; // Should not execute
        // Test range with single element
        count = 0;
        BitVecForeachInRange(&bv, bit, 3, 4) {
            count++;
            result = result && (bit == false); // 3 % 2 != 0
        // Test range at boundaries
        count = 0;
        BitVecForeachInRange(&bv, bit, 0, 2) {
            (void)bit;
            count++;
        // Test range at the end of bitvector
        count = 0;
        BitVecForeachInRange(&bv, bit, 8, 10) {
            (void)bit;
            count++;
Last updated on