diff --git a/src/rose/block.c b/src/rose/block.c index c0b5e0e4..55323c2e 100644 --- a/src/rose/block.c +++ b/src/rose/block.c @@ -260,8 +260,8 @@ int roseBlockFloating(const struct RoseEngine *t, struct hs_scratch *scratch) { DEBUG_PRINTF("BEGIN FLOATING (over %zu/%zu)\n", flen, length); DEBUG_PRINTF("-- %016llx\n", tctxt->groups); - hwlmExec(ftable, buffer, flen, t->floatingMinDistance, roseCallback, - scratch, tctxt->groups); + hwlmExec(ftable, buffer, flen, t->floatingMinDistance, roseFloatingCallback, + scratch, tctxt->groups & t->floating_group_mask); return can_stop_matching(scratch); } diff --git a/src/rose/match.c b/src/rose/match.c index 4e9e72a6..e89c8d3a 100644 --- a/src/rose/match.c +++ b/src/rose/match.c @@ -516,7 +516,8 @@ anchored_leftovers:; return rv; } -hwlmcb_rv_t roseCallback(size_t start, size_t end, u32 id, void *ctxt) { +static really_inline +hwlmcb_rv_t roseCallback_i(size_t start, size_t end, u32 id, void *ctxt) { struct hs_scratch *scratch = ctxt; struct RoseContext *tctx = &scratch->tctxt; const struct RoseEngine *t = scratch->core_info.rose; @@ -564,6 +565,17 @@ hwlmcb_rv_t roseCallback(size_t start, size_t end, u32 id, void *ctxt) { return HWLM_TERMINATE_MATCHING; } +hwlmcb_rv_t roseCallback(size_t start, size_t end, u32 id, void *ctxt) { + return roseCallback_i(start, end, id, ctxt); +} + +hwlmcb_rv_t roseFloatingCallback(size_t start, size_t end, u32 id, void *ctxt) { + struct hs_scratch *scratch = ctxt; + const struct RoseEngine *t = scratch->core_info.rose; + + return roseCallback_i(start, end, id, ctxt) & t->floating_group_mask; +} + /** * \brief Match callback adaptor used for matches from pure-literal cases. * diff --git a/src/rose/match.h b/src/rose/match.h index cee32fc2..5b587aec 100644 --- a/src/rose/match.h +++ b/src/rose/match.h @@ -51,6 +51,7 @@ int roseNfaSomAdaptor(u64a from_offset, u64a offset, ReportID id, void *context) /* Callbacks, defined in match.c */ hwlmcb_rv_t roseCallback(size_t start, size_t end, u32 id, void *ctx); +hwlmcb_rv_t roseFloatingCallback(size_t start, size_t end, u32 id, void *ctx); hwlmcb_rv_t roseDelayRebuildCallback(size_t start, size_t end, u32 id, void *ctx); int roseAnchoredCallback(u64a end, u32 id, void *ctx); diff --git a/src/rose/rose_build_bytecode.cpp b/src/rose/rose_build_bytecode.cpp index cab0d60a..3f36a05e 100644 --- a/src/rose/rose_build_bytecode.cpp +++ b/src/rose/rose_build_bytecode.cpp @@ -4370,9 +4370,10 @@ aligned_unique_ptr RoseBuildImpl::buildFinalEngine(u32 minWidth) { } // Build floating HWLM matcher. + rose_group fgroups = 0; size_t fsize = 0; size_t floatingStreamStateRequired = 0; - auto ftable = buildFloatingMatcher(*this, &fsize, &historyRequired, + auto ftable = buildFloatingMatcher(*this, &fgroups, &fsize, &historyRequired, &floatingStreamStateRequired); u32 fmatcherOffset = 0; if (ftable) { @@ -4584,6 +4585,7 @@ aligned_unique_ptr RoseBuildImpl::buildFinalEngine(u32 minWidth) { fillMatcherDistances(*this, engine.get()); engine->initialGroups = getInitialGroups(); + engine->floating_group_mask = fgroups; engine->totalNumLiterals = verify_u32(literal_info.size()); engine->asize = verify_u32(asize); engine->ematcherRegionSize = ematcher_region_size; diff --git a/src/rose/rose_build_matchers.cpp b/src/rose/rose_build_matchers.cpp index f4597de7..b66556fc 100644 --- a/src/rose/rose_build_matchers.cpp +++ b/src/rose/rose_build_matchers.cpp @@ -580,10 +580,12 @@ vector fillHamsterLiteralList(const RoseBuildImpl &build, } aligned_unique_ptr buildFloatingMatcher(const RoseBuildImpl &build, + rose_group *fgroups, size_t *fsize, size_t *historyRequired, size_t *streamStateRequired) { *fsize = 0; + *fgroups = 0; auto fl = fillHamsterLiteralList(build, ROSE_FLOATING); if (fl.empty()) { @@ -591,6 +593,10 @@ aligned_unique_ptr buildFloatingMatcher(const RoseBuildImpl &build, return nullptr; } + for (const hwlmLiteral &hlit : fl) { + *fgroups |= hlit.groups; + } + hwlmStreamingControl ctl; hwlmStreamingControl *ctlp; if (build.cc.streaming) { diff --git a/src/rose/rose_build_matchers.h b/src/rose/rose_build_matchers.h index 1dd53cd8..7d5c9283 100644 --- a/src/rose/rose_build_matchers.h +++ b/src/rose/rose_build_matchers.h @@ -48,6 +48,7 @@ std::vector fillHamsterLiteralList(const RoseBuildImpl &build, rose_literal_table table); aligned_unique_ptr buildFloatingMatcher(const RoseBuildImpl &build, + rose_group *fgroups, size_t *fsize, size_t *historyRequired, size_t *streamStateRequired); diff --git a/src/rose/rose_dump.cpp b/src/rose/rose_dump.cpp index 40979e8c..9f55dbf2 100644 --- a/src/rose/rose_dump.cpp +++ b/src/rose/rose_dump.cpp @@ -930,6 +930,7 @@ void roseDumpText(const RoseEngine *t, FILE *f) { fprintf(f, "\n"); fprintf(f, "initial groups : 0x%016llx\n", t->initialGroups); + fprintf(f, "floating groups : 0x%016llx\n", t->floating_group_mask); fprintf(f, "handled key count : %u\n", t->handledKeyCount); fprintf(f, "\n"); @@ -1035,6 +1036,7 @@ void roseDumpStructRaw(const RoseEngine *t, FILE *f) { DUMP_U32(t, floatingMinLiteralMatchOffset); DUMP_U32(t, nfaInfoOffset); DUMP_U64(t, initialGroups); + DUMP_U64(t, floating_group_mask); DUMP_U32(t, size); DUMP_U32(t, delay_count); DUMP_U32(t, delay_base_id); diff --git a/src/rose/rose_internal.h b/src/rose/rose_internal.h index af5b2a95..9dd17350 100644 --- a/src/rose/rose_internal.h +++ b/src/rose/rose_internal.h @@ -401,6 +401,7 @@ struct RoseEngine { * table */ u32 nfaInfoOffset; /* offset to the nfa info offset array */ rose_group initialGroups; + rose_group floating_group_mask; /* groups that are used by the ftable */ u32 size; // (bytes) u32 delay_count; /* number of delayed literal ids. */ u32 delay_base_id; /* literal id of the first delayed literal. diff --git a/src/rose/stream.c b/src/rose/stream.c index 0e382f03..ffe965dd 100644 --- a/src/rose/stream.c +++ b/src/rose/stream.c @@ -461,8 +461,8 @@ void roseStreamExec(const struct RoseEngine *t, struct hs_scratch *scratch) { tctxt->minMatchOffset = offset; tctxt->minNonMpvMatchOffset = offset; tctxt->next_mpv_offset = 0; - DEBUG_PRINTF("BEGIN: history len=%zu, buffer len=%zu\n", - scratch->core_info.hlen, scratch->core_info.len); + DEBUG_PRINTF("BEGIN: history len=%zu, buffer len=%zu groups=%016llx\n", + scratch->core_info.hlen, scratch->core_info.len, tctxt->groups); fatbit_clear(scratch->aqa); scratch->al_log_sum = 0; @@ -540,8 +540,9 @@ void roseStreamExec(const struct RoseEngine *t, struct hs_scratch *scratch) { } DEBUG_PRINTF("BEGIN FLOATING (over %zu/%zu)\n", flen, length); - hwlmExecStreaming(ftable, scratch, flen, start, roseCallback, scratch, - tctxt->groups, stream_state); + hwlmExecStreaming(ftable, scratch, flen, start, roseFloatingCallback, + scratch, tctxt->groups & t->floating_group_mask, + stream_state); } flush_delay_and_exit: