|
@ -7,7 +7,7 @@ uint32_t Common::range_reverse(uint32_t bin) { // reverse binary every 2-bits |
|
|
return ((bin << 2) & 0xCCCCCCCC) | ((bin >> 2) & 0x33333333); |
|
|
return ((bin << 2) & 0xCCCCCCCC) | ((bin >> 2) & 0x33333333); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// NOTE: don't check unknown ranges
|
|
|
/// WARN: don't check unknown data -> may cause infinite loop
|
|
|
uint8_t Common::check_range(uint32_t head, uint32_t range) { // check generated range
|
|
|
uint8_t Common::check_range(uint32_t head, uint32_t range) { // check generated range
|
|
|
/// M_1x1 M_1x2 M_2x1 M_2x2
|
|
|
/// M_1x1 M_1x2 M_2x1 M_2x2
|
|
|
/// 1 0 0 0 1 1 0 0 1 0 0 0 1 1 0 0
|
|
|
/// 1 0 0 0 1 1 0 0 1 0 0 0 1 1 0 0
|
|
@ -18,25 +18,24 @@ uint8_t Common::check_range(uint32_t head, uint32_t range) { // check generated |
|
|
constexpr uint32_t M_2x1 = 0b10001; |
|
|
constexpr uint32_t M_2x1 = 0b10001; |
|
|
constexpr uint32_t M_2x2 = 0b110011; |
|
|
constexpr uint32_t M_2x2 = 0b110011; |
|
|
|
|
|
|
|
|
int block_offset = 1; |
|
|
uint8_t block_offset = 1; |
|
|
uint32_t cache = M_2x2 << head; // fill 2x2 block
|
|
|
uint32_t cache = M_2x2 << head; // fill 2x2 block
|
|
|
for (int addr = 0; range; range >>= 2, ++block_offset) { // traverse every 2-bits
|
|
|
for (int addr = 0; range; range >>= 2, ++block_offset) { // traverse every 2-bits
|
|
|
// TODO: will addr >= 32 in some special cases?
|
|
|
|
|
|
while ((cache >> addr) & 0b1) { |
|
|
while ((cache >> addr) & 0b1) { |
|
|
++addr; // search next unfilled block
|
|
|
++addr; // search next unfilled block
|
|
|
} |
|
|
} |
|
|
switch (range & 0b11) { |
|
|
switch (range & 0b11) { |
|
|
case 0b00: // space
|
|
|
case 0b00: /// space
|
|
|
case 0b11: // 1x1 block
|
|
|
case 0b11: /// 1x1 block
|
|
|
cache |= M_1x1 << addr; // fill space or 1x1 block
|
|
|
cache |= M_1x1 << addr; // fill space or 1x1 block
|
|
|
break; |
|
|
break; |
|
|
case 0b10: // 2x1 block
|
|
|
case 0b10: /// 2x1 block
|
|
|
if (addr > 15 || cache >> (addr + 4) & 0b1) { // invalid address
|
|
|
if (addr > 15 || cache >> (addr + 4) & 0b1) { // invalid address
|
|
|
return block_offset; // broken block number
|
|
|
return block_offset; // broken block number
|
|
|
} |
|
|
} |
|
|
cache |= M_2x1 << addr; // fill 2x1 block
|
|
|
cache |= M_2x1 << addr; // fill 2x1 block
|
|
|
break; |
|
|
break; |
|
|
case 0b01: // 1x2 block
|
|
|
case 0b01: /// 1x2 block
|
|
|
if ((addr & 0b11) == 0b11 || cache >> (addr + 1) & 0b1) { // invalid address
|
|
|
if ((addr & 0b11) == 0b11 || cache >> (addr + 1) & 0b1) { // invalid address
|
|
|
return block_offset; // broken block number
|
|
|
return block_offset; // broken block number
|
|
|
} |
|
|
} |
|
|