variableScope

This commit is contained in:
gtsoul-tech 2024-04-29 13:13:07 +03:00
parent 62e3450eae
commit 987cd17160
17 changed files with 45 additions and 55 deletions

View File

@ -63,12 +63,10 @@ static void run_benchmarks(int size, int loops, int max_matches,
InitFunc &&init, BenchFunc &&func) {
init(bench);
double total_sec = 0.0;
u64a total_size = 0;
double bw = 0.0;
double avg_bw = 0.0;
double max_bw = 0.0;
double avg_time = 0.0;
if (max_matches) {
double avg_bw = 0.0;
int pos = 0;
for (int j = 0; j < max_matches - 1; j++) {
bench.buf[pos] = 'b';
@ -90,7 +88,7 @@ static void run_benchmarks(int size, int loops, int max_matches,
total_sec += dt;
/*convert microseconds to seconds*/
/*calculate bandwidth*/
bw = (actual_size / dt) * 1000000.0 / 1048576.0;
double bw = (actual_size / dt) * 1000000.0 / 1048576.0;
/*std::cout << "act_size = " << act_size << std::endl;
std::cout << "dt = " << dt << std::endl;
std::cout << "bw = " << bw << std::endl;*/
@ -107,6 +105,7 @@ static void run_benchmarks(int size, int loops, int max_matches,
printf("%-18s, %-12d, %-10d, %-6d, %-10.3f, %-9.3f, %-8.3f, %-7.3f\n",
bench.label, max_matches, size ,loops, total_sec, avg_time, max_bw, avg_bw);
} else {
u64a total_size = 0;
auto start = std::chrono::steady_clock::now();
for (int i = 0; i < loops; i++) {
const u8 *res = func(bench);

View File

@ -605,8 +605,9 @@ double eval_set(Benchmark &bench, Sigdata &sigs, unsigned int mode,
scan_time = measure_stream_time(bench, repeatCount);
}
size_t bytes = bench.bytes();
size_t matches = bench.matches();
if (diagnose) {
size_t matches = bench.matches();
std::ios::fmtflags f(cout.flags());
cout << "Scan time " << std::fixed << std::setprecision(3) << scan_time
<< " sec, Scanned " << bytes * repeatCount << " bytes, Throughput "

View File

@ -547,9 +547,9 @@ u32 crc32c_sb8_64_bit(u32 running_crc, const unsigned char* p_buf,
u32 block = *(const u32 *)p_buf;
crc ^= block;
p_buf += 4;
term1 = crc_tableil8_o88[crc & 0x000000FF] ^
u32 term1 = crc_tableil8_o88[crc & 0x000000FF] ^
crc_tableil8_o80[(crc >> 8) & 0x000000FF];
term2 = crc >> 16;
u32 term2 = crc >> 16;
crc = term1 ^
crc_tableil8_o72[term2 & 0x000000FF] ^
crc_tableil8_o64[(term2 >> 8) & 0x000000FF];

View File

@ -489,7 +489,6 @@ char castleMatchLoop(const struct Castle *c, const u64a begin, const u64a end,
// full_state (scratch).
u64a offset = end; // min offset of next match
u32 activeIdx = 0;
mmbit_clear(matching, c->numRepeats);
if (c->exclusive) {
u8 *active = (u8 *)stream_state;
@ -497,7 +496,7 @@ char castleMatchLoop(const struct Castle *c, const u64a begin, const u64a end,
for (u32 i = mmbit_iterate(groups, c->numGroups, MMB_INVALID);
i != MMB_INVALID; i = mmbit_iterate(groups, c->numGroups, i)) {
u8 *cur = active + i * c->activeIdxSize;
activeIdx = partial_load_u32(cur, c->activeIdxSize);
u32 activeIdx = partial_load_u32(cur, c->activeIdxSize);
u64a match = subCastleNextMatch(c, full_state, stream_state,
loc, activeIdx);
set_matching(c, match, groups, matching, c->numGroups, i,

View File

@ -94,9 +94,6 @@ u32 repeatRecurTable(struct RepeatStateInfo *info, const depth &repeatMax,
static
u32 findOptimalPatchSize(struct RepeatStateInfo *info, const depth &repeatMax,
const u32 minPeriod, u32 rv) {
u32 cnt = 0;
u32 patch_bits = 0;
u32 total_size = 0;
u32 min = ~0U;
u32 patch_len = 0;
@ -105,11 +102,11 @@ u32 findOptimalPatchSize(struct RepeatStateInfo *info, const depth &repeatMax,
}
for (u32 i = minPeriod; i <= rv; i++) {
cnt = ((u32)repeatMax + (i - 1)) / i + 1;
u32 cnt = ((u32)repeatMax + (i - 1)) / i + 1;
// no bit packing version
patch_bits = calcPackedBits(info->table[i]);
total_size = (patch_bits + 7U) / 8U * cnt;
u32 patch_bits = calcPackedBits(info->table[i]);
u32 total_size = (patch_bits + 7U) / 8U * cnt;
if (total_size < min) {
patch_len = i;

View File

@ -513,12 +513,12 @@ static
bool doHaig(const NGHolder &g, som_type som,
const vector<vector<CharReach>> &triggers, bool unordered_som,
raw_som_dfa *rdfa) {
u32 state_limit = HAIG_FINAL_DFA_STATE_LIMIT; /* haig never backs down from
a fight */
using StateSet = typename Auto::StateSet;
vector<StateSet> nfa_state_map;
Auto n(g, som, triggers, unordered_som);
try {
u32 state_limit = HAIG_FINAL_DFA_STATE_LIMIT; /* haig never backs down from
a fight */
if (!determinise(n, rdfa->states, state_limit, &nfa_state_map)) {
DEBUG_PRINTF("state limit exceeded\n");
return false;

View File

@ -636,12 +636,12 @@ bool reversePathReachSubset(const NFAEdge &e, const NFAVertex &dom,
NFAVertex start = source(e, g);
using RevGraph = boost::reverse_graph<NGHolder, const NGHolder &>;
map<RevGraph::vertex_descriptor, boost::default_color_type> vertexColor;
// Walk the graph backwards from v, examining each node. We fail (return
// false) if we encounter a node with reach NOT a subset of domReach, and
// we stop searching at dom.
try {
map<RevGraph::vertex_descriptor, boost::default_color_type> vertexColor;
depth_first_visit(RevGraph(g), start,
ReachSubsetVisitor(domReach),
make_assoc_property_map(vertexColor),
@ -664,12 +664,12 @@ bool forwardPathReachSubset(const NFAEdge &e, const NFAVertex &dom,
}
NFAVertex start = target(e, g);
map<NFAVertex, boost::default_color_type> vertexColor;
// Walk the graph forward from v, examining each node. We fail (return
// false) if we encounter a node with reach NOT a subset of domReach, and
// we stop searching at dom.
try {
map<NFAVertex, boost::default_color_type> vertexColor;
depth_first_visit(g, start, ReachSubsetVisitor(domReach),
make_assoc_property_map(vertexColor),
VertexIs<NGHolder, NFAVertex>(dom));

View File

@ -348,10 +348,9 @@ void getSimpleRoseLiterals(const NGHolder &g, bool seeking_anchored,
map<NFAVertex, u64a> scores;
map<NFAVertex, unique_ptr<VertLitInfo>> lit_info;
set<ue2_literal> s;
for (auto v : a_dom) {
s = getLiteralSet(g, v, true); /* RHS will take responsibility for any
set<ue2_literal> s = getLiteralSet(g, v, true); /* RHS will take responsibility for any
revisits to the target vertex */
if (s.empty()) {
@ -2868,7 +2867,6 @@ static
bool splitForImplementability(RoseInGraph &vg, NGHolder &h,
const vector<RoseInEdge> &edges,
const CompileContext &cc) {
vector<pair<ue2_literal, u32>> succ_lits;
DEBUG_PRINTF("trying to split %s with %zu vertices on %zu edges\n",
to_string(h.kind).c_str(), num_vertices(h), edges.size());
@ -2877,6 +2875,7 @@ bool splitForImplementability(RoseInGraph &vg, NGHolder &h,
}
if (!generates_callbacks(h)) {
vector<pair<ue2_literal, u32>> succ_lits;
for (const auto &e : edges) {
const auto &lit = vg[target(e, vg)].s;
u32 delay = vg[e].graph_lag;
@ -2889,8 +2888,8 @@ bool splitForImplementability(RoseInGraph &vg, NGHolder &h,
}
unique_ptr<VertLitInfo> split;
bool last_chance = true;
if (h.kind == NFA_PREFIX) {
bool last_chance = true;
auto depths = calcDepths(h);
split = findBestPrefixSplit(h, depths, vg, edges, last_chance, cc);

View File

@ -109,20 +109,20 @@ void ComponentAlternation::append(unique_ptr<Component> component) {
vector<PositionInfo> ComponentAlternation::first() const {
// firsts come from all our subcomponents in position order. This will
// maintain left-to-right priority order.
vector<PositionInfo> firsts, subfirsts;
vector<PositionInfo> firsts;
for (const auto &c : children) {
subfirsts = c->first();
vector<PositionInfo> subfirsts = c->first();
firsts.insert(firsts.end(), subfirsts.begin(), subfirsts.end());
}
return firsts;
}
vector<PositionInfo> ComponentAlternation::last() const {
vector<PositionInfo> lasts, sublasts;
vector<PositionInfo> lasts;
for (const auto &c : children) {
sublasts = c->last();
vector<PositionInfo> sublasts = c->last();
lasts.insert(lasts.end(), sublasts.begin(), sublasts.end());
}
return lasts;

View File

@ -157,10 +157,10 @@ void ComponentSequence::finalize() {
}
vector<PositionInfo> ComponentSequence::first() const {
vector<PositionInfo> firsts, subfirsts;
vector<PositionInfo> firsts;
for (const auto &c : children) {
subfirsts = c->first();
vector<PositionInfo> subfirsts = c->first();
replaceEpsilons(firsts, subfirsts);
if (!c->empty()) {
break;
@ -229,12 +229,12 @@ void applyEpsilonVisits(vector<PositionInfo> &lasts,
}
vector<PositionInfo> ComponentSequence::last() const {
vector<PositionInfo> lasts, sublasts;
vector<PositionInfo> lasts;
vector<eps_info> visits(1);
auto i = children.rbegin(), e = children.rend();
for (; i != e; ++i) {
sublasts = (*i)->last();
vector<PositionInfo> sublasts = (*i)->last();
applyEpsilonVisits(sublasts, visits);
lasts.insert(lasts.end(), sublasts.begin(), sublasts.end());
if ((*i)->empty()) {

View File

@ -260,14 +260,14 @@ void ParsedLogical::parseLogicalCombination(unsigned id, const char *logical,
u32 ekey, u64a min_offset,
u64a max_offset) {
u32 ckey = getCombKey(id);
vector<LogicalOperator> op_stack;
vector<u32> subid_stack;
u32 lkey_start = INVALID_LKEY; // logical operation's lkey
u32 paren = 0; // parentheses
u32 digit = (u32)-1; // digit start offset, invalid offset is -1
u32 subid = (u32)-1;
u32 i;
try {
vector<LogicalOperator> op_stack;
u32 paren = 0; // parentheses
for (i = 0; logical[i]; i++) {
if (isdigit(logical[i])) {
if (digit == (u32)-1) { // new digit start

View File

@ -393,8 +393,9 @@ bool validateTransientMask(const vector<CharReach> &mask, bool anchored,
none_of(begin(lits), end(lits), mixed_sensitivity));
// Build the HWLM literal mask.
vector<u8> msk, cmp;
vector<u8> msk;
if (grey.roseHamsterMasks) {
vector<u8> cmp;
buildLiteralMask(mask, msk, cmp, delay);
}

View File

@ -2251,10 +2251,9 @@ vector<u32> buildSuffixEkeyLists(const RoseBuildImpl &build, build_context &bc,
/* for each outfix also build elists */
for (const auto &outfix : build.outfixes) {
u32 qi = outfix.get_queue();
set<u32> ekeys = reportsToEkeys(all_reports(outfix), build.rm);
if (!ekeys.empty()) {
u32 qi = outfix.get_queue();
qi_to_ekeys[qi] = {ekeys.begin(), ekeys.end()};
}
}

View File

@ -155,13 +155,13 @@ u32 compress32_impl_c(u32 x, u32 m) {
return 0;
}
u32 mk, mp, mv, t;
u32 mk, mv;
x &= m; // clear irrelevant bits
mk = ~m << 1; // we will count 0's to right
for (u32 i = 0; i < 5; i++) {
mp = mk ^ (mk << 1);
u32 mp = mk ^ (mk << 1);
mp ^= mp << 2;
mp ^= mp << 4;
mp ^= mp << 8;
@ -169,7 +169,7 @@ u32 compress32_impl_c(u32 x, u32 m) {
mv = mp & m; // bits to move
m = (m ^ mv) | (mv >> (1 << i)); // compress m
t = x & mv;
u32 t = x & mv;
x = (x ^ t) | (t >> (1 << i)); // compress x
mk = mk & ~mp;
}
@ -239,14 +239,14 @@ u32 expand32_impl_c(u32 x, u32 m) {
return 0;
}
u32 m0, mk, mp, mv, t;
u32 m0, mk, mv;
u32 array[5];
m0 = m; // save original mask
mk = ~m << 1; // we will count 0's to right
for (int i = 0; i < 5; i++) {
mp = mk ^ (mk << 1); // parallel suffix
u32 mp = mk ^ (mk << 1); // parallel suffix
mp = mp ^ (mp << 2);
mp = mp ^ (mp << 4);
mp = mp ^ (mp << 8);
@ -259,7 +259,7 @@ u32 expand32_impl_c(u32 x, u32 m) {
for (int i = 4; i >= 0; i--) {
mv = array[i];
t = x << (1 << i);
u32 t = x << (1 << i);
x = (x & ~mv) | (t & mv);
}
@ -409,7 +409,7 @@ u64a pdep64_impl_c(u64a x, u64a _m) {
u64a result = 0x0UL;
const u64a mask = 0x8000000000000000UL;
u64a m = _m;
u64a c, t;
u64a p;
/* The pop-count of the mask gives the number of the bits from
@ -421,8 +421,8 @@ u64a pdep64_impl_c(u64a x, u64a _m) {
each mask bit as it is processed. */
while (m != 0)
{
c = __builtin_clzl (m);
t = x << (p - c);
u64a c = __builtin_clzl (m);
u64a t = x << (p - c);
m ^= (mask >> c);
result |= (t & (mask >> c));
p++;

View File

@ -277,10 +277,9 @@ TEST_P(RepeatTest, FillRing) {
}
// We should be able to see matches for all of these (beyond the last top offset).
enum TriggerResult rv;
for (u64a i = offset + info.repeatMax;
i <= offset + info.repeatMax + info.repeatMin; i++) {
rv = processTugTrigger(&info, ctrl, state, i);
enum TriggerResult rv = processTugTrigger(&info, ctrl, state, i);
if (rv == TRIGGER_SUCCESS_CACHE) {
rv = TRIGGER_SUCCESS;
}
@ -998,16 +997,14 @@ TEST_P(SparseOptimalTest, FillTops) {
repeatStore(info, ctrl, state, offset, 0);
ASSERT_EQ(offset, repeatLastTop(info, ctrl, state));
u64a offset2;
for (u32 i = min_period; i < patch_count * patch_size; i += min_period) {
offset2 = offset + i;
u64a offset2 = offset + i;
repeatStore(info, ctrl, state, offset2, 1);
ASSERT_EQ(offset2, repeatLastTop(info, ctrl, state));
}
u64a exit2;
for (u32 i = 0; i < patch_count * patch_size; i += min_period) {
exit2 = exit + i;
u64a exit2 = exit + i;
for (u32 j = exit2 + info->repeatMin;
j <= offset + info->repeatMax; j++) {
ASSERT_EQ(REPEAT_MATCH, repeatHasMatch(info, ctrl, state, j));

View File

@ -87,12 +87,11 @@ static int initLegalValidMasks(u64a validMasks[]) {
*/
static int initLegalNegMasks(u64a negMasks[]) {
u64a data = 0;
u64a offset;
int num = 0;
while (data != ONES64) {
negMasks[num] = data;
num++;
offset = (data | (data +1)) ^ data;
u64a offset = (data | (data +1)) ^ data;
data += 0xfeULL * offset + 1;
}
negMasks[num] = data;

View File

@ -194,10 +194,9 @@ TEST(ValidateMask32, testMask32_3) {
u32 valid_mask = ONES32 << (left + right) >> left;
for (int i = 0; i < test_len; i++) {
const auto &t = testBasic[i];
int bool_result;
for (int j = 0; j < 5000; j++) {
u32 neg_mask = neg_mask_rand.Generate(1u << 31);
bool_result = (neg_mask & valid_mask) ==
int bool_result = (neg_mask & valid_mask) ==
(t.neg_mask & valid_mask);
EXPECT_EQ(bool_result, validateMask32(t.data.a256,
valid_mask,