Browse Source

fix: unset B_fill in raw code checker

legacy
Dnomd343 2 years ago
parent
commit
e7836aa7a8
  1. 41
      src/main.cc
  2. 9
      src/raw_code/convert.cc
  3. 18
      src/raw_code/raw_code.cc

41
src/main.cc

@ -362,14 +362,14 @@ int main() {
// printf("%09lX\n", CommonCode::from_string("1a9bf0c").unwrap());
// std::cout << CommonCode("4feA134") << std::endl;
std::vector<uint64_t> all_cases;
for (uint64_t head = 0; head < 16; ++head) {
for (const auto &range : AllCases::fetch()[head]) {
all_cases.emplace_back(head << 32 | range);
}
}
std::cout << "test size: " << all_cases.size() << std::endl;
// std::vector<uint64_t> all_cases;
// for (uint64_t head = 0; head < 16; ++head) {
// for (const auto &range : AllCases::fetch()[head]) {
// all_cases.emplace_back(head << 32 | range);
// }
// }
// std::cout << "test size: " << all_cases.size() << std::endl;
//
// for (const auto &common_code : all_cases) {
// if (RawCode::compact(RawCode::extract(common_code)) != common_code) {
// std::cout << "Error: " << CommonCode(common_code) << std::endl;
@ -382,12 +382,27 @@ int main() {
// std::cout << RawCode::check(CommonCode(0x4FEA13400).to_raw_code().unwrap()) << std::endl;
for (const auto &common_code : all_cases) {
if (!RawCode::check(RawCode::extract(common_code))) {
std::cout << "Error: " << CommonCode(common_code) << std::endl;
}
}
// for (const auto &common_code : all_cases) {
// if (!RawCode::check(RawCode::extract(common_code))) {
// std::cout << "Error: " << CommonCode(common_code) << std::endl;
// }
// }
// for (uint64_t common_code = 0; common_code < 0x100000000; ++common_code) {
// for (uint64_t common_code = 0x555A4000; common_code < 0x100000000; ++common_code) {
// if (RawCode::check(RawCode::extract(common_code)) != CommonCode::check(common_code)) {
// printf("%09lX\n", common_code);
// }
// if (common_code % 0x1000 == 0) {
// std::cout << std::hex << common_code << std::endl;
// }
// }
// TODO: why 0x555a4001 broken extract function?
// std::cout << RawCode(RawCode::extract(0x00000FEC4)).dump_case() << std::endl;
// std::cout << RawCode(RawCode::extract(0x000055480)).dump_case() << std::endl;
// std::cout << RawCode(RawCode::extract(0x0000FF004)).dump_case() << std::endl;
std::cout << RawCode::extract(0x555a4001) << std::endl;
// std::cerr << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl;
std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl;

9
src/raw_code/convert.cc

@ -47,6 +47,8 @@ uint64_t RawCode::compact(uint64_t raw_code) { // raw code --> common code
return head | (range << (unfilled << 1)); // fill low bits as zero
}
#include <iostream>
/// NOTE: ensure that input common code is valid !!!
uint64_t RawCode::extract(uint64_t common_code) { // common code --> raw code
auto code = C_2x2 << (common_code >> 32) * 3; // flag for 2x2 block
@ -55,6 +57,13 @@ uint64_t RawCode::extract(uint64_t common_code) { // common code --> raw code
while (0b111 & code >> addr) { // check low 3-bits -> next empty address
addr += 3; // found available address
}
// TODO: remove after test
if (addr >= 60) {
return 0;
}
// std::cout << "addr = " << addr << " | block = " << (range & 0b11) << std::endl;
switch (range & 0b11) { // match low 2-bits
case 0b01: // 1x2 block
code |= C_1x2 << addr;

18
src/raw_code/raw_code.cc

@ -27,6 +27,21 @@ std::string RawCode::dump_case() const {
}
bool RawCode::check(uint64_t raw_code) { // check whether raw code is valid
constexpr uint64_t MASK_1x1 = ~B_1x1 & 0b111;
constexpr uint64_t MASK_1x2 = MASK_1x1 << 3;
constexpr uint64_t MASK_2x1 = MASK_1x1 << 12;
constexpr uint64_t MASK_2x2 = MASK_1x1 << 3 | MASK_1x1 << 12 | MASK_1x1 << 15;
// if (MASK_1x2 != 0b100000) {
// printf("error\n");
// }
// if (MASK_2x1 != 0b100000000000000) {
// printf("error\n");
// }
// if (MASK_2x2 != 0b100100000000100000) {
// printf("error\n");
// }
if (raw_code >> 60) {
return false; // high 4-bits must be zero
}
@ -43,17 +58,20 @@ bool RawCode::check(uint64_t raw_code) { // check whether raw code is valid
if (addr > 15 || (raw_code & F_2x1) != C_2x1) {
return false; // invalid 2x1 block
}
raw_code &= ~MASK_2x1; // B_fill -> B_1x1
continue;
case B_1x2:
if ((addr & 0b11) == 0b11 || (raw_code & F_1x2) != C_1x2) {
return false; // invalid 1x2 block
}
raw_code &= ~MASK_1x2; // B_fill -> B_1x1
continue;
case B_2x2:
++head_num;
if (addr > 14 || (addr & 0b11) == 0b11 || (raw_code & F_2x2) != C_2x2) {
return false; // invalid 2x2 block
}
raw_code &= ~MASK_2x2; // B_fill -> B_1x1
continue;
default:
return false; // unknown flag -> 0b101 / 0b110

Loading…
Cancel
Save