diff --git a/src/nfa/mcclellan.c b/src/nfa/mcclellan.c index ef670a93..314e88e7 100644 --- a/src/nfa/mcclellan.c +++ b/src/nfa/mcclellan.c @@ -1020,34 +1020,36 @@ void nfaExecMcClellan8_SimpStream(const struct NFA *nfa, char *state, const u8 *buf, char top, size_t start_off, size_t len, NfaCallback cb, void *ctxt) { const struct mcclellan *m = (const struct mcclellan *)getImplNfa(nfa); - if (top) { - *(u8 *)state = m->start_anchored; - } + + u8 s = top ? m->start_anchored : *(u8 *)state; if (m->flags & MCCLELLAN_FLAG_SINGLE) { - mcclellanExec8_i(m, (u8 *)state, buf + start_off, len - start_off, + mcclellanExec8_i(m, &s, buf + start_off, len - start_off, start_off, cb, ctxt, 1, NULL, CALLBACK_OUTPUT); } else { - mcclellanExec8_i(m, (u8 *)state, buf + start_off, len - start_off, + mcclellanExec8_i(m, &s, buf + start_off, len - start_off, start_off, cb, ctxt, 0, NULL, CALLBACK_OUTPUT); } + + *(u8 *)state = s; } void nfaExecMcClellan16_SimpStream(const struct NFA *nfa, char *state, const u8 *buf, char top, size_t start_off, size_t len, NfaCallback cb, void *ctxt) { const struct mcclellan *m = (const struct mcclellan *)getImplNfa(nfa); - if (top) { - *(u16 *)state = m->start_anchored; - } + + u16 s = top ? m->start_anchored : unaligned_load_u16(state); if (m->flags & MCCLELLAN_FLAG_SINGLE) { - mcclellanExec16_i(m, (u16 *)state, buf + start_off, len - start_off, + mcclellanExec16_i(m, &s, buf + start_off, len - start_off, start_off, cb, ctxt, 1, NULL, CALLBACK_OUTPUT); } else { - mcclellanExec16_i(m, (u16 *)state, buf + start_off, len - start_off, + mcclellanExec16_i(m, &s, buf + start_off, len - start_off, start_off, cb, ctxt, 0, NULL, CALLBACK_OUTPUT); } + + unaligned_store_u16(state, s); } char nfaExecMcClellan8_testEOD(const struct NFA *nfa, const char *state, diff --git a/src/rose/rose_build_anchored.cpp b/src/rose/rose_build_anchored.cpp index 96393ba1..57faa46c 100644 --- a/src/rose/rose_build_anchored.cpp +++ b/src/rose/rose_build_anchored.cpp @@ -228,7 +228,7 @@ u32 anchoredStateSize(const anchored_matcher_info &atable) { } const NFA *nfa = (const NFA *)((const char *)curr + sizeof(*curr)); - return curr->state_offset + nfa->scratchStateSize; + return curr->state_offset + nfa->streamStateSize; } bool anchoredIsMulti(const anchored_matcher_info &atable) { @@ -849,15 +849,8 @@ buildAnchoredAutomataMatcher(RoseBuildImpl &build, size_t *asize) { ami->next_offset = verify_u32(curr - prev_curr); } - // State must be aligned. - u32 align_req = state_alignment(*nfa); - assert(align_req <= 2); // only DFAs. - while (state_offset % align_req) { - state_offset++; - } - ami->state_offset = state_offset; - state_offset += nfa->scratchStateSize; + state_offset += nfa->streamStateSize; ami->anchoredMinDistance = start_offset[i]; } diff --git a/src/rose/rose_build_bytecode.cpp b/src/rose/rose_build_bytecode.cpp index c7c0891a..275f61d0 100644 --- a/src/rose/rose_build_bytecode.cpp +++ b/src/rose/rose_build_bytecode.cpp @@ -582,11 +582,6 @@ void fillStateOffsets(const RoseBuildImpl &tbi, u32 rolesWithStateCount, so->leftfixLagTable = curr_offset; curr_offset += laggedRoseCount; - // Anchored state is McClellan full state, and needs to be 2-byte aligned. - // We potentially waste a byte here. - if (curr_offset % 2) { - curr_offset++; - } so->anchorState = curr_offset; curr_offset += anchorStateSize; diff --git a/src/rose/stream.c b/src/rose/stream.c index 71984e92..476c4f7c 100644 --- a/src/rose/stream.c +++ b/src/rose/stream.c @@ -74,7 +74,7 @@ void runAnchoredTableStream(const struct RoseEngine *t, const void *atable, goto next_nfa; } } else { - if (!*(u16 *)state) { + if (!unaligned_load_u16(state)) { goto next_nfa; } }