]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Remove use of depth from Rose entirely
authorJustin Viiret <justin.viiret@intel.com>
Thu, 7 Jan 2016 23:10:10 +0000 (10:10 +1100)
committerMatthew Barr <matthew.barr@intel.com>
Tue, 1 Mar 2016 00:23:11 +0000 (11:23 +1100)
15 files changed:
src/rose/block.c
src/rose/eod.c
src/rose/init.c
src/rose/match.c
src/rose/match.h
src/rose/program_runtime.h
src/rose/rose_build_bytecode.cpp
src/rose/rose_build_dump.cpp
src/rose/rose_build_impl.h
src/rose/rose_build_misc.cpp
src/rose/rose_dump.cpp
src/rose/rose_internal.h
src/rose/rose_program.h
src/rose/stream.c
src/scratch.h

index b3833d4b54fe9cf3225f9bc089ada680ac27dbd8..3d1eb9e326e6d5428b81386b6b74dbc031625c5d 100644 (file)
@@ -141,7 +141,6 @@ void init_for_block(const struct RoseEngine *t, struct hs_scratch *scratch,
     struct RoseContext *tctxt = &scratch->tctxt;
 
     tctxt->t = t;
-    tctxt->depth = 1;
     tctxt->groups = t->initialGroups;
     tctxt->lit_offset_adjust = 1; // index after last byte
     tctxt->delayLastEndOffset = 0;
index a6524f9617ebc3b135ce38ba2ceef29c8dd10ed6..ef9873882bef97a6c7c6758f1924b1fbd4c5e591 100644 (file)
@@ -36,10 +36,8 @@ static really_inline
 void initContext(const struct RoseEngine *t, u8 *state, u64a offset,
                  struct hs_scratch *scratch, RoseCallback callback,
                  RoseCallbackSom som_callback, void *ctx) {
-    struct RoseRuntimeState *rstate = getRuntimeState(state);
     struct RoseContext *tctxt = &scratch->tctxt;
     tctxt->t = t;
-    tctxt->depth = rstate->stored_depth;
     tctxt->groups = loadGroups(t, state); /* TODO: diff groups for eod */
     tctxt->lit_offset_adjust = scratch->core_info.buf_offset
                              - scratch->core_info.hlen
index d2f85f2c582dc7eece6e0c49a5807f034204ab7e..1cb26821e1a7ce1babfc9da469e1f0647a538b2f 100644 (file)
 
 static really_inline
 void init_rstate(const struct RoseEngine *t, u8 *state) {
-    // Set runtime state: initial depth is 1 and we take our initial groups
-    // from the RoseEngine.
+    // Set runtime state: we take our initial groups from the RoseEngine.
     DEBUG_PRINTF("setting initial groups to 0x%016llx\n", t->initialGroups);
     struct RoseRuntimeState *rstate = getRuntimeState(state);
-    rstate->stored_depth = 1;
     storeGroups(t, state, t->initialGroups);
     rstate->flags = 0;
     rstate->broken = NOT_BROKEN;
index 1c688aabb534089fab9bd93223745d378a628440..89f0674e773728b093da3bd19f6d31171ff87fb4 100644 (file)
@@ -205,8 +205,7 @@ hwlmcb_rv_t roseDelayRebuildCallback(size_t start, size_t end, u32 id,
     printf("\n");
 #endif
 
-    DEBUG_PRINTF("STATE depth=%u, groups=0x%016llx\n", tctx->depth,
-                 tctx->groups);
+    DEBUG_PRINTF("STATE groups=0x%016llx\n", tctx->groups);
 
     if (isLiteralDR(id)) {
         return tctx->groups;
@@ -224,7 +223,7 @@ hwlmcb_rv_t roseDelayRebuildCallback(size_t start, size_t end, u32 id,
 
     pushDelayedMatches(tl, real_end, tctx);
 
-    /* we are just repopulating the delay queue, groups and depths should be
+    /* we are just repopulating the delay queue, groups should be
      * already set from the original scan. */
 
     return tctx->groups;
@@ -425,8 +424,7 @@ int roseAnchoredCallback(u64a end, u32 id, void *ctx) {
     u64a real_end = ci->buf_offset + end; // index after last byte
 
     DEBUG_PRINTF("MATCH id=%u offsets=[???,%llu]\n", id, real_end);
-    DEBUG_PRINTF("STATE depth=%u, groups=0x%016llx\n", tctxt->depth,
-                 tctxt->groups);
+    DEBUG_PRINTF("STATE groups=0x%016llx\n", tctxt->groups);
 
     if (can_stop_matching(tctxtToScratch(tctxt))) {
         DEBUG_PRINTF("received a match when we're already dead!\n");
@@ -492,8 +490,7 @@ int roseAnchoredCallback(u64a end, u32 id, void *ctx) {
         roseSquashGroup(tctxt, tl);
     }
 
-    DEBUG_PRINTF("DONE depth=%u, groups=0x%016llx\n", tctxt->depth,
-                 tctxt->groups);
+    DEBUG_PRINTF("DONE groups=0x%016llx\n", tctxt->groups);
 
     if (real_end > t->floatingMinLiteralMatchOffset) {
         recordAnchoredLiteralMatch(tctxt, id, real_end);
@@ -623,8 +620,7 @@ hwlmcb_rv_t playDelaySlot(struct RoseContext *tctxt, const u8 *delaySlotBase,
         DEBUG_PRINTF("DELAYED MATCH id=%u offset=%llu\n", literal_id, offset);
         hwlmcb_rv_t rv = roseProcessDelayedMatch(tctxt->t, offset, literal_id,
                                                  tctxt);
-        DEBUG_PRINTF("DONE depth=%u, groups=0x%016llx\n", tctxt->depth,
-                     tctxt->groups);
+        DEBUG_PRINTF("DONE groups=0x%016llx\n", tctxt->groups);
 
         /* delayed literals can't safely set groups.
          * However we may be setting groups that successors already have
@@ -656,8 +652,7 @@ hwlmcb_rv_t flushAnchoredLiteralAtLoc(struct RoseContext *tctxt, u32 curr_loc) {
                      curr_loc);
         hwlmcb_rv_t rv = roseProcessDelayedAnchoredMatch(tctxt->t, curr_loc,
                                                          literal_id, tctxt);
-        DEBUG_PRINTF("DONE depth=%u, groups=0x%016llx\n", tctxt->depth,
-                     tctxt->groups);
+        DEBUG_PRINTF("DONE groups=0x%016llx\n", tctxt->groups);
 
         /* anchored literals can't safely set groups.
          * However we may be setting groups that successors already
@@ -837,8 +832,7 @@ hwlmcb_rv_t roseCallback(size_t start, size_t end, u32 id, void *ctxt) {
 #endif
     DEBUG_PRINTF("last end %llu\n", tctx->lastEndOffset);
 
-    DEBUG_PRINTF("STATE depth=%u, groups=0x%016llx\n", tctx->depth,
-                 tctx->groups);
+    DEBUG_PRINTF("STATE groups=0x%016llx\n", tctx->groups);
 
     if (can_stop_matching(tctxtToScratch(tctx))) {
         DEBUG_PRINTF("received a match when we're already dead!\n");
@@ -864,8 +858,7 @@ hwlmcb_rv_t roseCallback(size_t start, size_t end, u32 id, void *ctxt) {
 
     rv = roseProcessMainMatch(tctx->t, real_end, id, tctx);
 
-    DEBUG_PRINTF("DONE depth=%hhu, groups=0x%016llx\n", tctx->depth,
-                 tctx->groups);
+    DEBUG_PRINTF("DONE groups=0x%016llx\n", tctx->groups);
 
     if (rv != HWLM_TERMINATE_MATCHING) {
         return tctx->groups;
index 59d83a42626fb97e4b7039436315e4afaeb076b8..cab1726736b8a1d7e6154aecf0122d4ce8157cb8 100644 (file)
@@ -260,14 +260,6 @@ hwlmcb_rv_t cleanUpDelayed(size_t length, u64a offset, struct RoseContext *tctxt
     return HWLM_CONTINUE_MATCHING;
 }
 
-static really_inline
-void update_depth(struct RoseContext *tctxt, u8 depth) {
-    u8 d = MAX(tctxt->depth, depth + 1);
-    assert(d >= tctxt->depth);
-    DEBUG_PRINTF("depth now %hhu was %hhu\n", d, tctxt->depth);
-    tctxt->depth = d;
-}
-
 static rose_inline
 void roseFlushLastByteHistory(const struct RoseEngine *t, u8 *state,
                               u64a currEnd, struct RoseContext *tctxt) {
index cc345e289c31883e26b7b40febdb2ffc61b9c659..6ba86ca658ce465dcb0c6945ff4426768a558128 100644 (file)
@@ -387,14 +387,6 @@ char roseTestLeftfix(const struct RoseEngine *t, u32 qi, u32 leftfixLag,
     }
 }
 
-static rose_inline
-void roseSetRole(const struct RoseEngine *t, u8 *state,
-                 struct RoseContext *tctxt, u32 stateIndex, u8 depth) {
-    DEBUG_PRINTF("state idx=%u, depth=%u\n", stateIndex, depth);
-    mmbit_set(getRoleState(state), t->rolesWithStateCount, stateIndex);
-    update_depth(tctxt, depth);
-}
-
 static rose_inline
 void roseTriggerInfix(const struct RoseEngine *t, u64a start, u64a end, u32 qi,
                       u32 topEvent, u8 cancel, struct RoseContext *tctxt) {
@@ -819,7 +811,6 @@ hwlmcb_rv_t roseRunProgram(const struct RoseEngine *t, u32 programOffset,
             PROGRAM_CASE(ANCHORED_DELAY) {
                 if (in_anchored && end > t->floatingMinLiteralMatchOffset) {
                     DEBUG_PRINTF("delay until playback\n");
-                    update_depth(tctxt, ri->depth);
                     tctxt->groups |= ri->groups;
                     *work_done = 1;
                     assert(ri->done_jump); // must progress
@@ -971,7 +962,9 @@ hwlmcb_rv_t roseRunProgram(const struct RoseEngine *t, u32 programOffset,
             PROGRAM_NEXT_INSTRUCTION
 
             PROGRAM_CASE(SET_STATE) {
-                roseSetRole(t, tctxt->state, tctxt, ri->index, ri->depth);
+                DEBUG_PRINTF("set state index %u\n", ri->index);
+                mmbit_set(getRoleState(tctxt->state), t->rolesWithStateCount,
+                          ri->index);
                 *work_done = 1;
             }
             PROGRAM_NEXT_INSTRUCTION
index 985efef506af9301ef98c6e10a0ccbc9ec645378..5c56f2d58e28891e300fe870b17774839593fb76 100644 (file)
@@ -2941,7 +2941,7 @@ void makeRoleCheckLeftfix(RoseBuildImpl &build, build_context &bc, RoseVertex v,
 }
 
 static
-void makeRoleAnchoredDelay(RoseBuildImpl &build, build_context &bc,
+void makeRoleAnchoredDelay(RoseBuildImpl &build, UNUSED build_context &bc,
                            RoseVertex v, vector<RoseInstruction> &program) {
     // Only relevant for roles that can be triggered by the anchored table.
     if (!build.isAnchored(v)) {
@@ -2952,7 +2952,6 @@ void makeRoleAnchoredDelay(RoseBuildImpl &build, build_context &bc,
     // floatingMinLiteralMatchOffset.
 
     auto ri = RoseInstruction(ROSE_INSTR_ANCHORED_DELAY);
-    ri.u.anchoredDelay.depth = (u8)min(254U, bc.depths.at(v));
     ri.u.anchoredDelay.groups = build.g[v].groups;
     program.push_back(ri);
 }
@@ -3107,7 +3106,6 @@ void makeRoleSetState(const build_context &bc, RoseVertex v,
     u32 idx = it->second;
     auto ri = RoseInstruction(ROSE_INSTR_SET_STATE);
     ri.u.setState.index = idx;
-    ri.u.setState.depth = (u8)min(254U, bc.depths.at(v));
     program.push_back(ri);
 }
 
@@ -3785,7 +3783,6 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
     aligned_unique_ptr<HWLM> sbtable = buildSmallBlockMatcher(*this, &sbsize);
 
     build_context bc;
-    bc.depths = findDepths(*this);
 
     // Build NFAs
     set<u32> no_retrigger_queues;
index 96ff77347715a0ce779451c81217678281bb0fb3..e73d81c3fe55527a188a6805b5ad963b65622d1a 100644 (file)
@@ -316,8 +316,6 @@ void dumpRoseLiterals(const RoseBuildImpl &build, const char *filename) {
     os << "ROSE LITERALS: a total of " << build.literals.right.size()
        << " literals and " << num_vertices(g) << " roles." << endl << endl;
 
-    const auto depths = findDepths(build);
-
     for (const auto &e : build.literals.right) {
         u32 id = e.first;
         const ue2_literal &s = e.second.s;
@@ -387,9 +385,8 @@ void dumpRoseLiterals(const RoseBuildImpl &build, const char *filename) {
 
         for (RoseVertex v : verts) {
             // role info
-            os << "  Index " << g[v].idx << ": depth=" << depths.at(v)
-               << ", groups=0x" << hex << setw(16) << setfill('0')
-               << g[v].groups << dec;
+            os << "  Index " << g[v].idx << ": groups=0x" << hex << setw(16)
+               << setfill('0') << g[v].groups << dec;
 
             if (g[v].reports.empty()) {
                 os << ", report=NONE";
index b2604ff048a2078579cc039785c7170bfbf98a24..a7f2e2f703c67a67cdc08ed7c332bf86d4a65ceb 100644 (file)
@@ -562,10 +562,6 @@ void normaliseLiteralMask(const ue2_literal &s, std::vector<u8> &msk,
 void fillHamsterLiteralList(const RoseBuildImpl &tbi, rose_literal_table table,
                             std::vector<hwlmLiteral> *hl);
 
-// Find the minimum depth in hops of each role. Note that a role may be
-// accessible from both the root and the anchored root.
-std::map<RoseVertex, u32> findDepths(const RoseBuildImpl &build);
-
 #ifndef NDEBUG
 bool canImplementGraphs(const RoseBuildImpl &tbi);
 #endif
index 9ec26d4c831de535bf9cd3c755e5d39fa05af017..044a4208f4c8dd4c1a211a7c3403173f06f0e6ec 100644 (file)
@@ -1108,39 +1108,6 @@ LeftEngInfo::operator bool() const {
     return graph || castle || dfa || haig;
 }
 
-// Find the minimum depth in hops of each role. Note that a role may be
-// accessible from both the root and the anchored root.
-map<RoseVertex, u32> findDepths(const RoseBuildImpl &build) {
-    const RoseGraph &g = build.g;
-    map<RoseVertex, u32> depths;
-
-    depths[build.root] = 0;
-    depths[build.anchored_root] = 0;
-
-    // BFS from root first.
-    breadth_first_search(g, build.root, visitor(make_bfs_visitor(
-            record_distances(boost::make_assoc_property_map(depths),
-                             boost::on_tree_edge()))).
-            vertex_index_map(get(&RoseVertexProps::idx, g)));
-
-    // BFS from anchored root, updating depths in the graph when they get
-    // smaller.
-    map<RoseVertex, u32> depthsAnch;
-    breadth_first_search(g, build.anchored_root, visitor(make_bfs_visitor(
-            record_distances(boost::make_assoc_property_map(depthsAnch),
-                             boost::on_tree_edge()))).
-            vertex_index_map(get(&RoseVertexProps::idx, g)));
-    for (const auto &e : depthsAnch) {
-        if (contains(depths, e.first)) {
-            LIMIT_TO_AT_MOST(&depths[e.first], e.second);
-        } else {
-            depths.insert(e);
-        }
-    }
-
-    return depths;
-}
-
 u32 roseQuality(const RoseEngine *t) {
     /* Rose is low quality if the atable is a Mcclellan 16 or has multiple DFAs
      */
index 484fde5f71af34bb608f3d6baee8f31b362286c8..6210d10226ecceea6ae6605de722a15c1dc550b8 100644 (file)
@@ -196,7 +196,6 @@ void dumpProgram(ofstream &os, const RoseEngine *t, const char *pc) {
         assert(code <= ROSE_INSTR_END);
         switch (code) {
             PROGRAM_CASE(ANCHORED_DELAY) {
-                os << "    depth " << u32{ri->depth} << endl;
                 os << "    groups 0x" << std::hex << ri->groups << std::dec
                    << endl;
                 os << "    done_jump +" << ri->done_jump << endl;
@@ -292,7 +291,6 @@ void dumpProgram(ofstream &os, const RoseEngine *t, const char *pc) {
             PROGRAM_NEXT_INSTRUCTION
 
             PROGRAM_CASE(SET_STATE) {
-                os << "    depth " << u32{ri->depth} << endl;
                 os << "    index " << ri->index << endl;
             }
             PROGRAM_NEXT_INSTRUCTION
index 1f927a2cb5a4b1c1936371456635f24c32960402..92a67ae14835457f2e3fd3b5912738c801d5cd35 100644 (file)
@@ -512,7 +512,6 @@ struct lit_benefits {
 #endif
 // Rose runtime state
 struct RoseRuntimeState {
-    u8 stored_depth; /* depth at stream boundary */
     u8 flags; /* high bit true if delay rebuild needed */
     u8 broken; /* user has requested that we stop matching */
 #if defined(_WIN32)
index a232907398863b786c1eed6eaa34bce3889ae312..3f59ba15ad6d2690e5758f20d8672152be125e1e 100644 (file)
@@ -66,7 +66,6 @@ enum RoseInstructionCode {
 
 struct ROSE_STRUCT_ANCHORED_DELAY {
     u8 code; //!< From enum RoseInstructionCode.
-    u8 depth; //!< Depth for this state.
     rose_group groups; //!< Bitmask.
     u32 done_jump; //!< Jump forward this many bytes if successful.
 };
@@ -160,7 +159,6 @@ struct ROSE_STRUCT_REPORT_SOM_KNOWN {
 
 struct ROSE_STRUCT_SET_STATE {
     u8 code; //!< From enum RoseInstructionCode.
-    u8 depth; //!< Depth for this state.
     u32 index; //!< State index in multibit.
 };
 
index ae119bcf64d8cb210e327b9fab8c91c78c580b97..0bbab851df1dd8e961415bbc90ae389e7f24cd99 100644 (file)
@@ -409,7 +409,6 @@ void ensureStreamNeatAndTidy(const struct RoseEngine *t, u8 *state,
     tctxt->lastEndOffset = offset + length;
     storeGroups(t, state, tctxt->groups);
     struct RoseRuntimeState *rstate = getRuntimeState(state);
-    rstate->stored_depth = tctxt->depth;
     rstate->flags = delay_rb_status;
 }
 
@@ -454,7 +453,6 @@ void roseStreamExec(const struct RoseEngine *t, u8 *state,
 
     struct RoseContext *tctxt = &scratch->tctxt;
     tctxt->t = t;
-    tctxt->depth = rstate->stored_depth;
     tctxt->mpv_inactive = 0;
     tctxt->groups = loadGroups(t, state);
     tctxt->lit_offset_adjust = offset + 1; // index after last byte
index a1efe6d94dce5a256d0513b161d85030e985e38a..1faf60f7067ba3c1ec6b42b07ad5ee090ceda3d9 100644 (file)
@@ -106,7 +106,6 @@ struct core_info {
 struct RoseContext {
     const struct RoseEngine *t;
     u8 *state; /**< base pointer to the full state */
-    u8 depth;
     u8 mpv_inactive;
     u64a groups;
     u64a lit_offset_adjust; /**< offset to add to matches coming from hwlm */