]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
variableScope
authorgtsoul-tech <gtsoulkanakis@gmail.com>
Mon, 29 Apr 2024 10:13:07 +0000 (13:13 +0300)
committergtsoul-tech <gtsoulkanakis@gmail.com>
Mon, 29 Apr 2024 10:13:07 +0000 (13:13 +0300)
17 files changed:
benchmarks/benchmarks.cpp
examples/patbench.cc
src/crc32.c
src/nfa/castle.c
src/nfa/repeatcompile.cpp
src/nfagraph/ng_haig.cpp
src/nfagraph/ng_redundancy.cpp
src/nfagraph/ng_violet.cpp
src/parser/ComponentAlternation.cpp
src/parser/ComponentSequence.cpp
src/parser/logical_combination.cpp
src/rose/rose_build_add_mask.cpp
src/rose/rose_build_bytecode.cpp
src/util/arch/common/bitutils.h
unit/internal/repeat.cpp
unit/internal/rose_mask.cpp
unit/internal/rose_mask_32.cpp

index e48652e9c446deb2641a1e67c53f7f9a2b86c6fe..3c1a0bab64e1ed68ba3c5ce0cdaa96b9d7bfb35d 100644 (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);
index 1f965f131d0fb5efb0ed06de0716810b33d6a83e..b1ec276646bae8aa1141966452efb2b00c63303e 100644 (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 "
index 19c7b7fa9d3fec3a5a029209183ddfe01462b7da..c2f151192495148ee36e3fd0f48042f95b73ae3c 100644 (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];
index 29208f8d47023e0428fd66c3dc1370d15ad6098c..128f34898bd1f6c06bb2e61a162fd3ee2ed3f41c 100644 (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,
index 60b513524fe3d88d2a32e688f998b0caeb2776be..d9544675a79d96ecd5b0ed086f9bafc9ec34d4b5 100644 (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;
index bf951a0b0bf4e0cbe2d603c1d10b1cb244a1afa6..ede0f79b960c407591b8d4ffd966b64038d37e40 100644 (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;
index a499a40d41fa6bd31fab59ccfd9e1c4942c3b875..baabf285019d6540fcfc10291ae503bdf8a61bff 100644 (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));
index 02461e9818fed2495af143d9c1275fc34d83a6b6..b39cfba20c80ac9db5e39c2f4de372b7296746d9 100644 (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);
index e38c9ce79fd1dba2db2e7680733629cb1a8969d2..c4bad67254bf6c0dbaea869780a04ec88e26cd05 100644 (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;
index 2b78177b8ae87a2b30e15b73a29133b639544197..f520020696db67686442507a8231214a9fe1c1ce 100644 (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()) {
index a37f4e5f0eeda78258cf6d1ec208717b2e1f239d..bbe41b833493a6ac126336bc086f26eb0b132683 100644 (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
index c3736f62f48bd845d5312fe7dee3ef811a08c372..7e0e00b08ea460148d12eae5a264ef5d01184d63 100644 (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);
     }
 
index 2df3b3a393d35bab9886a9ca29fc92084e82d495..639edddcd8c9e943fbda17fd494cbd318030be54 100644 (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()};
         }
     }
index e5ab0d058c392327423084eb8570a6b3422453c7..897c9197cf81fee63b074363f51e3b5479a849e3 100644 (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++;
index 5665a0c3ed44e9bf867c11797266efa8895621bd..41a54c5fe33cff29548330fb372dbf2272359484 100644 (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));
index e6be00f359879a495fa84236c28ab2c25bc87716..ed1af956e35cda8721dc78695b3125b8eedca43b 100644 (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;
index 732f51a03e0593bc40786f564c9c143522661b07..bb444ead84f1963cd615d797b6c8ce356cc2e9c2 100644 (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,