BitVecOr
Description
Perform bitwise OR operation between two bitvectors. Result is stored in result. Operand lengths must match.
Parameters
| Name | Direction | Description |
|---|---|---|
result |
out | Bitvector to store result in. |
a |
in | First bitvector operand. |
b |
in | Second bitvector operand. |
Usage example (from documentation)
BitVecOr(&result, &flags1, &flags2);Success
Returns to the caller. result->length == a->length; each bit result[i] == a[i] | b[i]. The operands are unchanged.
Failure
Function cannot fail. Mismatched operand lengths or invalid bitvectors are caller bugs and abort via LOG_FATAL.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:548:
}
void BitVecOr(BitVec *result, BitVec *a, BitVec *b) {
ValidateBitVec(result);
ValidateBitVec(a); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecOr\n");
BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
// Perform OR operation
BitVecOr(&result, &bv1, &bv2);
// Expected result: 1110 (1100 OR 1010)
result = result && (BitVecLen(&result_bv) == 0);
BitVecOr(&result_bv, &bv1, &bv2);
result = result && (BitVecLen(&result_bv) == 0);
// Test OR with different lengths (result should be max length)
BitVecOr(&result, &bv1, &bv2);
test_result = test_result && (BitVecLen(&result) == 8); test_result = test_result && (BitVecGet(&result, 0) == false);
BitVecOr(&result, &bv1, &bv2);
test_result = test_result && (BitVecGet(&result, 0) == true);
// Test A OR A = A
BitVecOr(&result, &bv1, &bv1);
bool or_identity = true;
for (int i = 0; i < 16; i++) { }
BitVecOr(&result, &bv1, &bv2);
bool or_ones = true;
for (int i = 0; i < 16; i++) {
// Test A OR B = B OR A
BitVecOr(&result1, &bv1, &bv2);
BitVecOr(&result2, &bv2, &bv1); // Test A OR B = B OR A
BitVecOr(&result1, &bv1, &bv2);
BitVecOr(&result2, &bv2, &bv1);
bool or_commutative = true;
// Test NULL operand - should abort
BitVecOr(&result, &bv1, NULL);
BitVecDeinit(&result); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmtLn("Testing BitVecOr");
BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
// Perform OR operation
BitVecOr(&result, &bv1, &bv2);
// Expected result: 1110 (1100 OR 1010)
result = result && (BitVecLen(&result_bv) == 0);
BitVecOr(&result_bv, &bv1, &bv2);
result = result && (BitVecLen(&result_bv) == 0);
// Test OR with different lengths (result should be max length)
BitVecOr(&result, &bv1, &bv2);
test_result = test_result && (BitVecLen(&result) == 8); test_result = test_result && (BitVecGet(&result, 0) == false);
BitVecOr(&result, &bv1, &bv2);
test_result = test_result && (BitVecGet(&result, 0) == true);
// Test A OR A = A
BitVecOr(&result, &bv1, &bv1);
bool or_identity = true;
for (int i = 0; i < 16; i++) { }
BitVecOr(&result, &bv1, &bv2);
bool or_ones = true;
for (int i = 0; i < 16; i++) {
// Test A OR B = B OR A
BitVecOr(&result1, &bv1, &bv2);
BitVecOr(&result2, &bv2, &bv1); // Test A OR B = B OR A
BitVecOr(&result1, &bv1, &bv2);
BitVecOr(&result2, &bv2, &bv1);
bool or_commutative = true;
// Test NULL operand - should abort
BitVecOr(&result, &bv1, NULL);
BitVecDeinit(&result);
Last updated on