mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-11-19 02:30:35 +03:00
Rose: pack global state bits into one u8
Eliminate the RoseRuntimeState structure in favour of a single status byte that is stored in scratch and copied to/from stream state.
This commit is contained in:
committed by
Matthew Barr
parent
28f379d738
commit
9e9bb6a960
@@ -258,9 +258,7 @@ void roseBlockExec_i(const struct RoseEngine *t, struct hs_scratch *scratch,
|
||||
}
|
||||
|
||||
exit:;
|
||||
u8 dummy_delay_mask = 0;
|
||||
if (cleanUpDelayed(length, 0, tctxt, &dummy_delay_mask)
|
||||
== HWLM_TERMINATE_MATCHING) {
|
||||
if (cleanUpDelayed(length, 0, scratch) == HWLM_TERMINATE_MATCHING) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -98,8 +98,7 @@ hwlmcb_rv_t roseEodRunMatcher(const struct RoseEngine *t, u64a offset,
|
||||
hwlmExec(etable, eod_data, eod_len, adj, roseCallback, tctxt, tctxt->groups);
|
||||
|
||||
// We may need to fire delayed matches
|
||||
u8 dummy_delay_mask = 0;
|
||||
return cleanUpDelayed(0, offset, tctxt, &dummy_delay_mask);
|
||||
return cleanUpDelayed(0, offset, scratch);
|
||||
}
|
||||
|
||||
static rose_inline
|
||||
|
||||
@@ -45,10 +45,7 @@ static really_inline
|
||||
void init_rstate(const struct RoseEngine *t, char *state) {
|
||||
// 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);
|
||||
storeGroups(t, state, t->initialGroups);
|
||||
rstate->flags = 0;
|
||||
rstate->broken = NOT_BROKEN;
|
||||
}
|
||||
|
||||
static really_inline
|
||||
|
||||
@@ -237,12 +237,13 @@ hwlmcb_rv_t flushQueuedLiterals(struct RoseContext *tctxt, u64a end) {
|
||||
}
|
||||
|
||||
static really_inline
|
||||
hwlmcb_rv_t cleanUpDelayed(size_t length, u64a offset, struct RoseContext *tctxt,
|
||||
u8 *status) {
|
||||
if (can_stop_matching(tctxtToScratch(tctxt))) {
|
||||
hwlmcb_rv_t cleanUpDelayed(size_t length, u64a offset,
|
||||
struct hs_scratch *scratch) {
|
||||
if (can_stop_matching(scratch)) {
|
||||
return HWLM_TERMINATE_MATCHING;
|
||||
}
|
||||
|
||||
struct RoseContext *tctxt = &scratch->tctxt;
|
||||
if (flushQueuedLiterals(tctxt, length + offset)
|
||||
== HWLM_TERMINATE_MATCHING) {
|
||||
return HWLM_TERMINATE_MATCHING;
|
||||
@@ -250,9 +251,9 @@ hwlmcb_rv_t cleanUpDelayed(size_t length, u64a offset, struct RoseContext *tctxt
|
||||
|
||||
if (tctxt->filledDelayedSlots) {
|
||||
DEBUG_PRINTF("dirty\n");
|
||||
*status |= DELAY_FLOAT_DIRTY;
|
||||
scratch->core_info.status |= STATUS_DELAY_DIRTY;
|
||||
} else {
|
||||
*status &= ~DELAY_FLOAT_DIRTY;
|
||||
scratch->core_info.status &= ~STATUS_DELAY_DIRTY;
|
||||
}
|
||||
|
||||
tctxt->filledDelayedSlots = 0;
|
||||
|
||||
@@ -211,9 +211,7 @@ hwlmcb_rv_t roseHaltIfExhausted(const struct RoseEngine *t,
|
||||
struct hs_scratch *scratch) {
|
||||
struct core_info *ci = &scratch->core_info;
|
||||
if (isAllExhausted(t, ci->exhaustionVector)) {
|
||||
if (!ci->broken) {
|
||||
ci->broken = BROKEN_EXHAUSTED;
|
||||
}
|
||||
ci->status |= STATUS_EXHAUSTED;
|
||||
scratch->tctxt.groups = 0;
|
||||
DEBUG_PRINTF("all exhausted, termination requested\n");
|
||||
return HWLM_TERMINATE_MATCHING;
|
||||
|
||||
@@ -561,9 +561,9 @@ void fillStateOffsets(const RoseBuildImpl &tbi, u32 rolesWithStateCount,
|
||||
RoseStateOffsets *so) {
|
||||
u32 curr_offset = 0;
|
||||
|
||||
// First, runtime state (stores per-stream state, like whether we need a
|
||||
// First, runtime status (stores per-stream state, like whether we need a
|
||||
// delay rebuild or have been told to halt matching.)
|
||||
curr_offset += sizeof(RoseRuntimeState);
|
||||
curr_offset += sizeof(u8);
|
||||
|
||||
// Role state storage.
|
||||
curr_offset += mmbit_size(rolesWithStateCount);
|
||||
@@ -4433,7 +4433,7 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
|
||||
&stateOffsets);
|
||||
|
||||
scatter_plan_raw state_scatter;
|
||||
buildStateScatterPlan(sizeof(RoseRuntimeState), bc.numStates,
|
||||
buildStateScatterPlan(sizeof(u8), bc.numStates,
|
||||
activeLeftCount, rosePrefixCount, stateOffsets,
|
||||
cc.streaming, activeArrayCount, outfixBeginQueue,
|
||||
outfixEndQueue, &state_scatter);
|
||||
|
||||
@@ -865,7 +865,6 @@ void roseDumpText(const RoseEngine *t, FILE *f) {
|
||||
t->historyRequired);
|
||||
fprintf(f, " - exhaustion vector : %u bytes\n", (t->ekeyCount + 7) / 8);
|
||||
fprintf(f, " - role state mmbit : %u bytes\n", t->stateSize);
|
||||
fprintf(f, " - runtime state : %zu bytes\n", sizeof(RoseRuntimeState));
|
||||
fprintf(f, " - floating matcher : %u bytes\n", t->floatingStreamState);
|
||||
fprintf(f, " - active array : %u bytes\n",
|
||||
mmbit_size(t->activeArrayCount));
|
||||
|
||||
@@ -48,8 +48,6 @@ typedef u64a rose_group;
|
||||
#define MAX_DELAY (DELAY_SLOT_COUNT - 1)
|
||||
#define DELAY_MASK (DELAY_SLOT_COUNT - 1)
|
||||
|
||||
#define DELAY_FLOAT_DIRTY (1U << 7) /* delay literal matched in history */
|
||||
|
||||
// Direct report stuff
|
||||
#define LITERAL_DR_FLAG (1U << 31)
|
||||
#define LITERAL_MDR_FLAG ((1U << 30) | (1U << 31))
|
||||
@@ -214,7 +212,7 @@ struct NfaInfo {
|
||||
*
|
||||
* State not covered by this structure includes:
|
||||
*
|
||||
* -# the RoseRuntimeState structure
|
||||
* -# the first byte, containing the status bitmask
|
||||
* -# the role state multibit
|
||||
*/
|
||||
struct RoseStateOffsets {
|
||||
@@ -476,12 +474,6 @@ struct RoseEngine {
|
||||
struct scatter_full_plan state_init;
|
||||
};
|
||||
|
||||
// Rose runtime state
|
||||
struct RoseRuntimeState {
|
||||
u8 flags; /* high bit true if delay rebuild needed */
|
||||
u8 broken; /* user has requested that we stop matching */
|
||||
};
|
||||
|
||||
struct ALIGN_CL_DIRECTIVE anchored_matcher_info {
|
||||
u32 next_offset; /* relative to this, 0 for end */
|
||||
u32 state_offset; /* relative to anchorState */
|
||||
|
||||
@@ -55,14 +55,6 @@
|
||||
|
||||
#define rose_inline really_inline
|
||||
|
||||
/** \brief Fetch runtime state ptr. */
|
||||
static really_inline
|
||||
struct RoseRuntimeState *getRuntimeState(char *state) {
|
||||
struct RoseRuntimeState *rs = (struct RoseRuntimeState *)(state);
|
||||
assert(ISALIGNED_N(rs, 8));
|
||||
return rs;
|
||||
}
|
||||
|
||||
static really_inline
|
||||
const void *getByOffset(const struct RoseEngine *t, u32 offset) {
|
||||
assert(offset < t->size);
|
||||
@@ -71,7 +63,7 @@ const void *getByOffset(const struct RoseEngine *t, u32 offset) {
|
||||
|
||||
static really_inline
|
||||
void *getRoleState(char *state) {
|
||||
return state + sizeof(struct RoseRuntimeState);
|
||||
return state + sizeof(u8); // status flags
|
||||
}
|
||||
|
||||
/** \brief Fetch the active array for suffix nfas. */
|
||||
|
||||
@@ -393,7 +393,7 @@ void roseSaveNfaStreamState(const struct RoseEngine *t, char *state,
|
||||
static rose_inline
|
||||
void ensureStreamNeatAndTidy(const struct RoseEngine *t, char *state,
|
||||
struct hs_scratch *scratch, size_t length,
|
||||
u64a offset, u8 delay_rb_status) {
|
||||
u64a offset) {
|
||||
struct RoseContext *tctxt = &scratch->tctxt;
|
||||
|
||||
if (roseCatchUpTo(t, state, length + scratch->core_info.buf_offset, scratch,
|
||||
@@ -406,8 +406,6 @@ void ensureStreamNeatAndTidy(const struct RoseEngine *t, char *state,
|
||||
roseFlushLastByteHistory(t, state, offset + length, tctxt);
|
||||
tctxt->lastEndOffset = offset + length;
|
||||
storeGroups(t, state, tctxt->groups);
|
||||
struct RoseRuntimeState *rstate = getRuntimeState(state);
|
||||
rstate->flags = delay_rb_status;
|
||||
}
|
||||
|
||||
static really_inline
|
||||
@@ -418,6 +416,8 @@ void do_rebuild(const struct RoseEngine *t, const struct HWLM *ftable,
|
||||
const u8 *buf = scratch->core_info.hbuf + scratch->core_info.hlen - len;
|
||||
DEBUG_PRINTF("BEGIN FLOATING REBUILD over %zu bytes\n", len);
|
||||
|
||||
scratch->core_info.status &= ~STATUS_DELAY_DIRTY;
|
||||
|
||||
hwlmExec(ftable, buf, len, 0, roseDelayRebuildCallback, scratch,
|
||||
scratch->tctxt.groups);
|
||||
assert(!can_stop_matching(scratch));
|
||||
@@ -446,7 +446,6 @@ void roseStreamExec(const struct RoseEngine *t, struct hs_scratch *scratch,
|
||||
}
|
||||
|
||||
char *state = scratch->core_info.state;
|
||||
struct RoseRuntimeState *rstate = getRuntimeState(state);
|
||||
|
||||
struct RoseContext *tctxt = &scratch->tctxt;
|
||||
tctxt->mpv_inactive = 0;
|
||||
@@ -475,8 +474,6 @@ void roseStreamExec(const struct RoseEngine *t, struct hs_scratch *scratch,
|
||||
streamInitSufPQ(t, state, scratch);
|
||||
}
|
||||
|
||||
u8 delay_rb_status = rstate->flags;
|
||||
|
||||
u32 alen = t->anchoredDistance > offset ?
|
||||
MIN(length + offset, t->anchoredDistance) - offset : 0;
|
||||
|
||||
@@ -507,12 +504,13 @@ void roseStreamExec(const struct RoseEngine *t, struct hs_scratch *scratch,
|
||||
|
||||
size_t hlength = scratch->core_info.hlen;
|
||||
|
||||
char rebuild = hlength && (delay_rb_status & DELAY_FLOAT_DIRTY)
|
||||
&& (t->maxFloatingDelayedMatch == ROSE_BOUND_INF
|
||||
|| offset < t->maxFloatingDelayedMatch);
|
||||
char rebuild = hlength &&
|
||||
(scratch->core_info.status & STATUS_DELAY_DIRTY) &&
|
||||
(t->maxFloatingDelayedMatch == ROSE_BOUND_INF ||
|
||||
offset < t->maxFloatingDelayedMatch);
|
||||
DEBUG_PRINTF("**rebuild %hhd status %hhu mfdm %u, offset %llu\n",
|
||||
rebuild, delay_rb_status, t->maxFloatingDelayedMatch,
|
||||
offset);
|
||||
rebuild, scratch->core_info.status,
|
||||
t->maxFloatingDelayedMatch, offset);
|
||||
|
||||
if (!flen) {
|
||||
if (rebuild) { /* rebuild floating delayed match stuff */
|
||||
@@ -552,17 +550,16 @@ void roseStreamExec(const struct RoseEngine *t, struct hs_scratch *scratch,
|
||||
|
||||
flush_delay_and_exit:
|
||||
DEBUG_PRINTF("flushing floating\n");
|
||||
if (cleanUpDelayed(length, offset, tctxt, &delay_rb_status)
|
||||
== HWLM_TERMINATE_MATCHING) {
|
||||
if (cleanUpDelayed(length, offset, scratch) == HWLM_TERMINATE_MATCHING) {
|
||||
return;
|
||||
}
|
||||
|
||||
exit:
|
||||
DEBUG_PRINTF("CLEAN UP TIME\n");
|
||||
if (!can_stop_matching(scratch)) {
|
||||
ensureStreamNeatAndTidy(t, state, scratch, length, offset,
|
||||
delay_rb_status);
|
||||
ensureStreamNeatAndTidy(t, state, scratch, length, offset);
|
||||
}
|
||||
DEBUG_PRINTF("DONE STREAMING SCAN, dirty = %hhu\n", delay_rb_status);
|
||||
DEBUG_PRINTF("DONE STREAMING SCAN, status = %u\n",
|
||||
scratch->core_info.status);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user