Compare commits

...

2 Commits

Author SHA1 Message Date
tqcq
629bf5c15c feat: add O3 2024-10-20 14:47:37 +00:00
tqcq
fc97358971 fix: error 2024-10-20 14:46:16 +00:00
3 changed files with 17 additions and 6 deletions

0
.gitignore vendored Normal file
View File

View File

@ -4,7 +4,7 @@ LDIR=lib
BUILD=obj BUILD=obj
ODIR=src/.obj ODIR=src/.obj
CFLAGS=-I$(IDIR) #-ggdb CFLAGS=-I$(IDIR) -O3 #-ggdb
# CXX=g++ # CXX=g++
LDFLAGS= LDFLAGS=

View File

@ -11,6 +11,7 @@
#include <vector> #include <vector>
#include <set>
#include <functional> #include <functional>
#include <algorithm> #include <algorithm>
#include <bitset> #include <bitset>
@ -37,6 +38,7 @@
typedef std::vector<addr_tuple> set_t; typedef std::vector<addr_tuple> set_t;
//------------------------------------------- //-------------------------------------------
bool is_in(char* val, std::set<char*> arr);
bool is_in(char* val, std::vector<char*> arr); bool is_in(char* val, std::vector<char*> arr);
bool found_enough(std::vector<set_t> sets, uint64_t set_cnt, size_t set_size); bool found_enough(std::vector<set_t> sets, uint64_t set_cnt, size_t set_size);
void filter_sets(std::vector<set_t>& sets, size_t set_size); void filter_sets(std::vector<set_t>& sets, size_t set_size);
@ -44,9 +46,11 @@ void print_sets(std::vector<set_t> sets);
void verify_sets(std::vector<set_t>& sets, uint64_t threshold, size_t rounds); void verify_sets(std::vector<set_t>& sets, uint64_t threshold, size_t rounds);
//------------------------------------------- //-------------------------------------------
static std::vector<uint64_t> time_vals;
uint64_t time_tuple(volatile char* a1, volatile char* a2, size_t rounds) { uint64_t time_tuple(volatile char* a1, volatile char* a2, size_t rounds) {
uint64_t* time_vals = (uint64_t*) calloc(rounds, sizeof(uint64_t)); // uint64_t* time_vals = (uint64_t*) calloc(rounds, sizeof(uint64_t));
time_vals.resize(rounds);
uint64_t t0; uint64_t t0;
sched_yield(); sched_yield();
for (size_t i = 0; i < rounds; i++) { for (size_t i = 0; i < rounds; i++) {
@ -61,8 +65,8 @@ uint64_t time_tuple(volatile char* a1, volatile char* a2, size_t rounds) {
} }
uint64_t mdn = median(time_vals, rounds); uint64_t mdn = median(time_vals.data(), rounds);
free(time_vals); // free(time_vals);
return mdn; return mdn;
} }
@ -318,6 +322,7 @@ uint64_t find_row_mask(std::vector<set_t>& sets, std::vector<uint64_t> fn_masks,
next_mask: next_mask:
row_mask = next_bit_permutation(row_mask); row_mask = next_bit_permutation(row_mask);
} }
return row_mask;
// super hackish way to recover the real row mask // super hackish way to recover the real row mask
for (auto m:fn_masks) { for (auto m:fn_masks) {
@ -340,7 +345,8 @@ void rev_mc(size_t sets_cnt, size_t threshold, size_t rounds, size_t m_size, cha
int o_fd = 0; int o_fd = 0;
int huge_fd = 0; int huge_fd = 0;
std::vector<set_t> sets; std::vector<set_t> sets;
std::vector<char*> used_addr; // std::vector<char*> used_addr;
std::set<char*> used_addr;
std::vector<uint64_t> fn_masks; std::vector<uint64_t> fn_masks;
srand((unsigned) time(&t)); srand((unsigned) time(&t));
@ -371,7 +377,8 @@ void rev_mc(size_t sets_cnt, size_t threshold, size_t rounds, size_t m_size, cha
if (is_in(rnd_addr, used_addr)) if (is_in(rnd_addr, used_addr))
continue; continue;
used_addr.push_back(rnd_addr); // used_addr.push_back(rnd_addr);
used_addr.insert(rnd_addr);
addr_tuple tp = gen_addr_tuple(rnd_addr); addr_tuple tp = gen_addr_tuple(rnd_addr);
bool found_set = false; bool found_set = false;
@ -421,6 +428,10 @@ void rev_mc(size_t sets_cnt, size_t threshold, size_t rounds, size_t m_size, cha
//---------------------------------------------------------- //----------------------------------------------------------
// Helpers // Helpers
bool is_in(char* val, std::set<char*> arr) {
return arr.find(val) != arr.end();
}
bool is_in(char* val, std::vector<char*> arr) { bool is_in(char* val, std::vector<char*> arr) {
for (auto v: arr) { for (auto v: arr) {
if (val == v) { if (val == v) {