Browse Source

feat: more interfaces for RawCode

legacy
Dnomd343 2 years ago
parent
commit
45b68bc7a0
  1. 40
      src/main.cc
  2. 6
      src/raw_code/convert.cc
  3. 23
      src/raw_code/raw_code.cc
  4. 20
      src/raw_code/raw_code.h

40
src/main.cc

@ -69,16 +69,16 @@
// std::cout << "[" << start << ", " << end << ")" << std::endl; // std::cout << "[" << start << ", " << end << ")" << std::endl;
//} //}
void raw_code_check_verify(uint64_t index) { //void raw_code_check_verify(uint64_t index) {
uint64_t start = index * 0x100000000; // uint64_t start = index * 0x100000000;
uint64_t end = start + 0x100000000; // uint64_t end = start + 0x100000000;
for (uint64_t common_code = start; common_code < end; ++common_code) { // for (uint64_t common_code = start; common_code < end; ++common_code) {
if (RawCode::check(RawCode::extract(common_code)) != CommonCode::check(common_code)) { // if (RawCode::check(RawCode::extract(common_code)) != CommonCode::check(common_code)) {
printf("Error -> %09lX\n", common_code); // printf("Error -> %09lX\n", common_code);
} // }
} // }
std::cout << "verify ok: " << std::hex << "[" << start << ", " << end << ")" << std::endl; // std::cout << "verify ok: " << std::hex << "[" << start << ", " << end << ")" << std::endl;
} //}
int main() { int main() {
@ -409,15 +409,15 @@ int main() {
// } // }
// } // }
std::thread tasks[16]; // std::thread tasks[16];
std::cout << "verify start" << std::endl; // std::cout << "verify start" << std::endl;
for (int i = 0; i < 16; ++i) { // for (int i = 0; i < 16; ++i) {
tasks[i] = std::thread(raw_code_check_verify, i); // tasks[i] = std::thread(raw_code_check_verify, i);
} // }
for (auto &t : tasks) { // for (auto &t : tasks) {
t.join(); // t.join();
} // }
std::cout << "verify complete" << std::endl; // std::cout << "verify complete" << std::endl;
// TODO: why 0x555a4001 broken extract function? // TODO: why 0x555a4001 broken extract function?
// std::cout << RawCode(RawCode::extract(0x00000FEC4)).dump_case() << std::endl; // std::cout << RawCode(RawCode::extract(0x00000FEC4)).dump_case() << std::endl;
@ -425,6 +425,8 @@ int main() {
// std::cout << RawCode(RawCode::extract(0x0000FF004)).dump_case() << std::endl; // std::cout << RawCode(RawCode::extract(0x0000FF004)).dump_case() << std::endl;
// std::cout << RawCode::extract(0x555a4001) << std::endl; // std::cout << RawCode::extract(0x555a4001) << std::endl;
std::cout << RawCode::create(CommonCode(0x4FEA13400).to_raw_code().unwrap()).dump_case() << std::endl;
std::cerr << (clock() - start_time) / CLOCKS_PER_SEC << "s" << std::endl; std::cerr << (clock() - start_time) / CLOCKS_PER_SEC << "s" << std::endl;
// std::cerr << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << 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; // std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl;

6
src/raw_code/convert.cc

@ -57,12 +57,6 @@ uint64_t RawCode::extract(uint64_t common_code) { // common code --> raw code
while ((code >> addr) & 0b111 && addr < 60) { // check low 3-bits -> next empty address while ((code >> addr) & 0b111 && addr < 60) { // check low 3-bits -> next empty address
addr += 3; // found available address addr += 3; // found available address
} }
// TODO: remove after test
if (addr >= 60) {
return 0;
}
switch (range & 0b11) { // match low 2-bits switch (range & 0b11) { // match low 2-bits
case 0b01: // 1x2 block case 0b01: // 1x2 block
code |= C_1x2 << addr; code |= C_1x2 << addr;

23
src/raw_code/raw_code.cc

@ -1,9 +1,26 @@
#include <string> #include <stdexcept>
#include "common.h" #include "common.h"
#include "raw_code.h" #include "raw_code.h"
uint64_t RawCode::unwrap() const { // get raw uint64_t code uint64_t RawCode::unwrap() const {
return code; return code; // raw uint64_t code
}
RawCode RawCode::create(uint64_t raw_code) {
return RawCode(raw_code);
}
RawCode RawCode::unsafe_create(uint64_t raw_code) { // create without check
auto raw = RawCode(); // init directly
raw.code = raw_code;
return raw;
}
RawCode::RawCode(uint64_t raw_code) {
if (!RawCode::check(raw_code)) { // check input raw code
throw std::invalid_argument("invalid raw code");
}
code = raw_code;
} }
std::string RawCode::dump_case() const { std::string RawCode::dump_case() const {

20
src/raw_code/raw_code.h

@ -16,25 +16,19 @@ public:
static bool check(uint64_t raw_code); static bool check(uint64_t raw_code);
// friend std::ostream& operator<<(std::ostream &out, const RawCode &self); // friend std::ostream& operator<<(std::ostream &out, const RawCode &self);
explicit RawCode(uint64_t raw_code);
explicit RawCode(const CommonCode &common_code); explicit RawCode(const CommonCode &common_code);
// TODO: check raw_code before object create static RawCode create(uint64_t raw_code);
explicit RawCode(uint64_t raw_code) : code(raw_code) {} static RawCode unsafe_create(uint64_t raw_code);
// TODO: mirror functions
// static RawCode create(uint64_t raw_code);
static RawCode from_common_code(const CommonCode &common_code); static RawCode from_common_code(const CommonCode &common_code);
// TODO: unsafe_create static function // TODO: mirror functions
static uint64_t compact(uint64_t raw_code);
static uint64_t extract(uint64_t common_code);
private: private:
uint64_t code; uint64_t code;
RawCode() = default; // unsafe initialize
// static uint64_t compact(uint64_t raw_code); static uint64_t compact(uint64_t raw_code);
// static uint64_t extract(uint64_t common_code); static uint64_t extract(uint64_t common_code);
}; };

Loading…
Cancel
Save