Browse Source

feat: try to skip invalid range prefix for speed up

legacy
Dnomd343 2 years ago
parent
commit
cf89c55f72
  1. 5
      src/all_cases/all_cases.cc
  2. 82
      src/main.cc

5
src/all_cases/all_cases.cc

@ -45,6 +45,11 @@ void AllCases::build_data() { // find all cases
data[head].reserve(ALL_CASES_SIZE[head]); // memory pre-allocated data[head].reserve(ALL_CASES_SIZE[head]); // memory pre-allocated
/// head(4-bits) + basic ranges(32-bits) ==check==> release valid cases /// head(4-bits) + basic ranges(32-bits) ==check==> release valid cases
for (auto index = 0; index < basic_ranges.size(); ++index) { for (auto index = 0; index < basic_ranges.size(); ++index) {
if ((basic_ranges[index] & 0b111111) == 0b010111) {
continue;
}
auto broken_offset = Common::check_range(head, basic_ranges[index]); auto broken_offset = Common::check_range(head, basic_ranges[index]);
if (broken_offset) { // case invalid if (broken_offset) { // case invalid
auto delta = (uint32_t)1 << (32 - broken_offset * 2); // delta to next possible range auto delta = (uint32_t)1 << (32 - broken_offset * 2); // delta to next possible range

82
src/main.cc

@ -428,15 +428,50 @@ int main() {
// std::cout << RawCode::create(CommonCode(0x4FEA13400).to_raw_code().unwrap()) << std::endl; // std::cout << RawCode::create(CommonCode(0x4FEA13400).to_raw_code().unwrap()) << std::endl;
AllCases::build(); // AllCases::build();
//
std::set<uint32_t> used_ranges; // std::set<uint32_t> used_ranges;
for (const auto &ranges : AllCases::fetch()) { // for (const auto &ranges : AllCases::fetch()) {
for (const auto &range : ranges) { // for (const auto &range : ranges) {
used_ranges.emplace(Common::range_reverse(range)); // used_ranges.emplace(Common::range_reverse(range));
} // used_ranges.emplace(range);
} // }
// }
// std::cout << "used number: " << used_ranges.size() << std::endl; // std::cout << "used number: " << used_ranges.size() << std::endl;
//
// auto basic_ranges = BasicRanges::fetch();
// for (auto &range : basic_ranges) {
// range = Common::range_reverse(range);
// }
// int deep = 16;
// int deep = 6;
// std::cout << "check deep -> " << deep << "-bits" << std::endl;
// std::vector<std::vector<uint32_t> > data(1 << deep);
// for (auto &range : basic_ranges) {
// data[range >> (32 - deep)].emplace_back(range);
// }
//
// int sum = 0;
// for (uint32_t i = 0; i < data.size(); ++i) {
// auto &dat = data[i];
//
// int num = 0;
// for (auto &range : dat) {
// if (used_ranges.find(range) == used_ranges.end()) {
// ++num;
// }
// }
// printf("%02X: %d/%zu\n", i, num, dat.size());
// if (num == dat.size()) {
// printf("%02X -> %d\n", i, num);
// sum += num;
// }
//
// }
// std::cout << "sum = " << sum << std::endl;
// for (const auto &range : BasicRanges::fetch()) { // for (const auto &range : BasicRanges::fetch()) {
// if (used_ranges.find(range) == used_ranges.end()) { // if (used_ranges.find(range) == used_ranges.end()) {
@ -448,28 +483,29 @@ int main() {
// BasicRanges::build(); // BasicRanges::build();
BasicRanges::data.clear(); // BasicRanges::data.clear();
for (const auto &range : used_ranges) { // for (const auto &range : used_ranges) {
BasicRanges::data.emplace_back(Common::range_reverse(range)); // BasicRanges::data.emplace_back(Common::range_reverse(range));
} // }
std::sort(BasicRanges::data.begin(), BasicRanges::data.end()); // std::sort(BasicRanges::data.begin(), BasicRanges::data.end());
for (auto &range : BasicRanges::data) { // for (auto &range : BasicRanges::data) {
range = Common::range_reverse(range); // range = Common::range_reverse(range);
} // }
// std::cout << "basic ranges size: " << BasicRanges::data.size() << std::endl; // std::cout << "basic ranges size: " << BasicRanges::data.size() << std::endl;
for (auto &a : AllCases::data) { // for (auto &a : AllCases::data) {
a.clear(); // clear built data // a.clear(); // clear built data
} // }
AllCases::available = false; // AllCases::available = false;
//
// std::cout << "wait 3s" << std::endl;
// sleep(3);
std::cout << "wait 3s" << std::endl; BasicRanges::build();
sleep(3);
std::cout << "start benchmark" << std::endl; std::cout << "start benchmark" << std::endl;
auto start_time = clock(); auto start_time = clock();
// rebuild all cases
AllCases::build(); AllCases::build();
// uint32_t sum = 0; // uint32_t sum = 0;

Loading…
Cancel
Save