Browse Source

update: apply new common code checker

master
Dnomd343 2 years ago
parent
commit
53c2211edb
  1. 32
      src/common_code/common_code.cc
  2. 2
      src/common_code/common_code.h
  3. 2
      src/main.cc
  4. 32
      src/utils/common.cc
  5. 2
      src/utils/common.h

32
src/common_code/common_code.cc

@ -88,37 +88,7 @@ std::string CommonCode::to_string(bool shorten) const { // convert uint64_t code
return result; // char* -> std::string
}
bool CommonCode::check(uint64_t common_code) { // check whether common code is valid
uint32_t head = common_code >> 32;
if (head >= 16 || (head & 0b11) == 0b11) { // check 2x2 block address
return false; // invalid common code
}
/// ensure that there are >= 2 space blocks
uint32_t fill_num = 0, space_num = 0;
auto range = Common::range_reverse((uint32_t)common_code); // get common code range
for (int i = 0; i < 32; i += 2) { // traverse range
switch ((range >> i) & 0b11) {
case 0b00: // space block
++space_num;
case 0b11: // 1x1 block
++fill_num;
break;
case 0b01: // 1x2 block
case 0b10: // 2x1 block
fill_num += 2;
}
if (fill_num >= 16) { // all block filled
break;
}
}
if (space_num < 2) {
return false; // at least 2 space
}
return Common::check_case(head, range); // check by head and range
}
bool CommonCode::check_demo(uint64_t common_code) {
bool CommonCode::check(uint64_t common_code) { // whether common code is valid
/// M_1x1 M_1x2 M_2x1 M_2x2
/// 1 0 0 0 1 1 0 0 1 0 0 0 1 1 0 0
/// 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0

2
src/common_code/common_code.h

@ -14,8 +14,6 @@ public:
static bool check(uint64_t common_code);
static CommonCode unsafe_create(uint64_t code);
static bool check_demo(uint64_t common_code);
RawCode to_raw_code() const;
ShortCode to_short_code() const;
std::string to_string(bool shorten = false) const;

2
src/main.cc

@ -337,7 +337,7 @@ int main() {
// int sum = 0;
for (uint64_t common_code = 0; common_code < 0x1000000000; ++common_code) {
if (CommonCode::check_demo(common_code)) {
if (CommonCode::check(common_code)) {
printf("%09lX\n", common_code);
// ++sum;
}

32
src/utils/common.cc

@ -7,38 +7,6 @@ uint32_t Common::range_reverse(uint32_t bin) { // reverse binary every 2-bits
return ((bin << 2) & 0xCCCCCCCC) | ((bin >> 2) & 0x33333333);
}
// TODO: remove legacy function -> combine as single function in CommonCode
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
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
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 true; // valid case
}
/// NOTE: don't check unknown ranges
uint8_t Common::check_range(uint32_t head, uint32_t range) { // check generated range
/// M_1x1 M_1x2 M_2x1 M_2x2

2
src/utils/common.h

@ -42,7 +42,7 @@
class Common {
public:
static uint32_t range_reverse(uint32_t bin);
static bool check_case(uint32_t head, uint32_t range);
// static bool check_case(uint32_t head, uint32_t range);
// TODO: with broken block offset return
static uint8_t check_range(uint32_t head, uint32_t range);

Loading…
Cancel
Save