|
@ -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); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool Common::check_case(uint32_t head, uint32_t range) { // check whether the case is valid
|
|
|
bool Common::check_case(uint32_t head, uint32_t range) { // whether the head and range is valid
|
|
|
uint32_t mask = 0b110011 << head; // fill 2x2 block
|
|
|
uint32_t mask = 0b110011 << head; // fill 2x2 block
|
|
|
for (int addr = 0; range; range >>= 2) { // traverse every 2-bits
|
|
|
for (int addr = 0; range; range >>= 2) { // traverse every 2-bits
|
|
|
while (mask >> addr & 0b1) { |
|
|
while (mask >> addr & 0b1) { |
|
@ -34,7 +34,39 @@ bool Common::check_case(uint32_t head, uint32_t range) { // check whether the ca |
|
|
mask |= 0b11 << addr; // fill 1x2 block
|
|
|
mask |= 0b11 << addr; // fill 1x2 block
|
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
// TODO: should we ensure that low-bits as 0?
|
|
|
|
|
|
} |
|
|
} |
|
|
return true; // valid case
|
|
|
return true; // valid case
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Common::check_case_safe(uint32_t head, uint32_t range) { // whether the case is valid
|
|
|
|
|
|
uint32_t space_num = 0; |
|
|
|
|
|
uint32_t mask = 0b110011 << head; // fill 2x2 block
|
|
|
|
|
|
for (int addr = 0; range; range >>= 2) { // traverse every 2-bits
|
|
|
|
|
|
while (mask >> addr & 0b1) { |
|
|
|
|
|
++addr; // search next not filled block
|
|
|
|
|
|
} |
|
|
|
|
|
switch (range & 0b11) { |
|
|
|
|
|
case 0b00: // space block
|
|
|
|
|
|
++space_num; |
|
|
|
|
|
case 0b11: // 1x1 block
|
|
|
|
|
|
if (addr > 19) { // invalid address
|
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
mask |= 0b1 << addr; // fill 1x1 block
|
|
|
|
|
|
break; |
|
|
|
|
|
case 0b10: // 2x1 block
|
|
|
|
|
|
if (addr > 15 || mask >> (addr + 4) & 0b1) { // invalid address
|
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
mask |= 0b10001 << addr; // fill 2x1 block
|
|
|
|
|
|
break; |
|
|
|
|
|
case 0b01: // 1x2 block
|
|
|
|
|
|
if (addr > 18 || (addr & 0b11) == 0b11 || mask >> (addr + 1) & 0b1) { // invalid address
|
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
mask |= 0b11 << addr; // fill 1x2 block
|
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return space_num >= 2; // at least 2 space
|
|
|
|
|
|
} |
|
|