From a9eba12cce8077ac73668b5e3e9fbdd47f99cbf1 Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Tue, 14 Jun 2016 16:58:13 +1000 Subject: [PATCH] rose: inline block-mode eod check --- src/rose/block.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++-- src/rose/eod.c | 20 -------------------- src/rose/rose.h | 19 ++----------------- 3 files changed, 49 insertions(+), 39 deletions(-) diff --git a/src/rose/block.c b/src/rose/block.c index 5fc5c8a1..0df5144c 100644 --- a/src/rose/block.c +++ b/src/rose/block.c @@ -29,13 +29,14 @@ #include "catchup.h" #include "init.h" #include "match.h" +#include "program_runtime.h" +#include "rose.h" +#include "rose_common.h" #include "nfa/nfa_api.h" #include "nfa/nfa_internal.h" #include "nfa/nfa_rev_api.h" #include "nfa/mcclellan.h" #include "util/fatbit.h" -#include "rose.h" -#include "rose_common.h" static rose_inline void runAnchoredTableBlock(const struct RoseEngine *t, const void *atable, @@ -157,6 +158,38 @@ void init_for_block(const struct RoseEngine *t, struct hs_scratch *scratch, init_outfixes_for_block(t, scratch, state, is_small_block); } +static rose_inline +void roseBlockEodExec(const struct RoseEngine *t, u64a offset, + struct hs_scratch *scratch) { + assert(t->requiresEodCheck); + assert(t->maxBiAnchoredWidth == ROSE_BOUND_INF + || offset <= t->maxBiAnchoredWidth); + + assert(!can_stop_matching(scratch)); + assert(t->eodProgramOffset); + + // Ensure that history is correct before we look for EOD matches. + roseFlushLastByteHistory(t, scratch, offset); + scratch->tctxt.lastEndOffset = offset; + + DEBUG_PRINTF("running eod program at %u\n", t->eodProgramOffset); + + // There should be no pending delayed literals. + assert(!scratch->tctxt.filledDelayedSlots); + + const u64a som = 0; + const size_t match_len = 0; + const char in_anchored = 0; + const char in_catchup = 0; + const char from_mpv = 0; + const char skip_mpv_catchup = 1; + + // Note: we ignore the result, as this is the last thing to ever happen on + // a scan. + roseRunProgram(t, scratch, t->eodProgramOffset, som, offset, match_len, + in_anchored, in_catchup, from_mpv, skip_mpv_catchup); +} + void roseBlockExec_i(const struct RoseEngine *t, struct hs_scratch *scratch) { assert(t); assert(scratch); @@ -255,4 +288,16 @@ exit:; assert(!can_stop_matching(scratch)); roseCatchUpTo(t, scratch, length); + + if (!t->requiresEodCheck || !t->eodProgramOffset) { + DEBUG_PRINTF("no eod check required\n"); + return; + } + + if (can_stop_matching(scratch)) { + DEBUG_PRINTF("bailing, already halted\n"); + return; + } + + roseBlockEodExec(t, length, scratch); } diff --git a/src/rose/eod.c b/src/rose/eod.c index 4dee0150..249e7a9c 100644 --- a/src/rose/eod.c +++ b/src/rose/eod.c @@ -108,23 +108,3 @@ void roseEodExec(const struct RoseEngine *t, u64a offset, initContext(t, offset, scratch); roseEodExec_i(t, offset, scratch, 1); } - -static rose_inline -void prepForEod(const struct RoseEngine *t, struct hs_scratch *scratch, - size_t length) { - roseFlushLastByteHistory(t, scratch, length); - scratch->tctxt.lastEndOffset = length; -} - -void roseBlockEodExec(const struct RoseEngine *t, u64a offset, - struct hs_scratch *scratch) { - assert(t->requiresEodCheck); - assert(t->maxBiAnchoredWidth == ROSE_BOUND_INF - || offset <= t->maxBiAnchoredWidth); - - assert(!can_stop_matching(scratch)); - - // Ensure that history is correct before we look for EOD matches - prepForEod(t, scratch, scratch->core_info.len); - roseEodExec_i(t, offset, scratch, 0); -} diff --git a/src/rose/rose.h b/src/rose/rose.h index d79c2f0c..5b7940a2 100644 --- a/src/rose/rose.h +++ b/src/rose/rose.h @@ -39,8 +39,6 @@ // Initialise state space for engine use. void roseInitState(const struct RoseEngine *t, char *state); -void roseBlockEodExec(const struct RoseEngine *t, u64a offset, - struct hs_scratch *scratch); void roseBlockExec_i(const struct RoseEngine *t, struct hs_scratch *scratch); /* assumes core_info in scratch has been init to point to data */ @@ -57,28 +55,15 @@ void roseBlockExec(const struct RoseEngine *t, struct hs_scratch *scratch) { // If this block is shorter than our minimum width, then no pattern in this // RoseEngine could match. /* minWidth checks should have already been performed by the caller */ - const size_t length = scratch->core_info.len; - assert(length >= t->minWidth); + assert(scratch->core_info.len >= t->minWidth); // Similarly, we may have a maximum width (for engines constructed entirely // of bi-anchored patterns). /* This check is now handled by the interpreter */ assert(t->maxBiAnchoredWidth == ROSE_BOUND_INF - || length <= t->maxBiAnchoredWidth); + || scratch->core_info.len <= t->maxBiAnchoredWidth); roseBlockExec_i(t, scratch); - - if (!t->requiresEodCheck) { - DEBUG_PRINTF("no eod check required\n"); - return; - } - - if (can_stop_matching(scratch)) { - DEBUG_PRINTF("bailing, already halted\n"); - return; - } - - roseBlockEodExec(t, length, scratch); } /* assumes core_info in scratch has been init to point to data */