Skip to content
Snippets Groups Projects
Commit 8d14b16e authored by Kostyantyn Vorobyov's avatar Kostyantyn Vorobyov
Browse files

[RTL] Refactoring functions dealing with initialization using bit-level

macros in e_acsl_bits.h
parent bbbf8228
No related branches found
No related tags found
No related merge requests found
...@@ -264,26 +264,18 @@ void __initialize (void * ptr, size_t size) { ...@@ -264,26 +264,18 @@ void __initialize (void * ptr, size_t size) {
* initialization of `size' bytes starting from `ptr'. */ * initialization of `size' bytes starting from `ptr'. */
unsigned i; unsigned i;
for(i = 0; i < size; i++) { for(i = 0; i < size; i++) {
// Byte-offset within the block, i.e., mark `offset' byte as initialized /* byte-offset within the block, i.e., mark `offset' byte as initialized */
size_t offset = (uintptr_t)ptr - tmp->ptr + i; size_t offset = (uintptr_t)ptr - tmp->ptr + i;
// Byte offset within tmp->init_ptr, i.e., a byte containing the bit to /* byte offset within tmp->init_ptr, i.e., a byte containing the bit to
// be toggled be toggled */
int byte = offset/8; int byte = offset/8;
// Bit-offset within the above byte, i.e., bit to be toggled /* bit-offset within the above byte, i.e., bit to be toggled */
int bit = offset%8; int bit = offset%8;
if (((tmp->init_ptr[byte] >> bit) & 1) == 0) { // if the bit is not set ... if (!bitcheck(bit, tmp->init_ptr[byte])) { /* if bit is unset ... */
tmp->init_ptr[byte] |= 1 << bit; // ... set the bit and ... bitset(bit, tmp->init_ptr[byte]); /* ... set the bit ... */
tmp->init_cpt++; // ... increment the counter tracking the number tmp->init_cpt++; /* ... and increment initialized bytes count */
// of initialized bits.
} }
/* NOTE:
* ((tmp->init_ptr[byte] >> bit) & 1)
* - shift's the bit of interest to position [0] and applies bitwise
* AND using mask '1000 0000', then if the result is 0 the bit is unset
* 1 << bit
* - bit-mask that has 1 shifted to the bit offset and the remaining
* bits are all zeroes */
} }
/* now fully initialized */ /* now fully initialized */
...@@ -341,7 +333,7 @@ int __initialized (void * ptr, size_t size) { ...@@ -341,7 +333,7 @@ int __initialized (void * ptr, size_t size) {
size_t offset = (uintptr_t)ptr - tmp->ptr + i; size_t offset = (uintptr_t)ptr - tmp->ptr + i;
int byte = offset/8; int byte = offset/8;
int bit = offset%8; int bit = offset%8;
if (((tmp->init_ptr[byte] >> bit) & 1) == 0) if (!bitcheck(bit, tmp->init_ptr[byte]))
return false; return false;
} }
return true; return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment