]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Rose: remove alignment req for anchored DFA state
authorJustin Viiret <justin.viiret@intel.com>
Mon, 1 Feb 2016 00:07:07 +0000 (11:07 +1100)
committerMatthew Barr <matthew.barr@intel.com>
Tue, 1 Mar 2016 00:32:01 +0000 (11:32 +1100)
src/nfa/mcclellan.c
src/rose/rose_build_anchored.cpp
src/rose/rose_build_bytecode.cpp
src/rose/stream.c

index ef670a9300f9a27abe709c6797e607cbe82dd4b8..314e88e750173bbfe578275057b5fa728cc11692 100644 (file)
@@ -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,
index 96393ba17744ed3aff5fe01f33f80ccccff17367..57faa46c88c5ff268035f4ddf061735359e0b73b 100644 (file)
@@ -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];
     }
 
index c7c0891a86521388a8bd45efe467f424e113d81c..275f61d0f278afcf8a9f56663f993d7b2c8272c5 100644 (file)
@@ -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;
 
index 71984e92feb633cda7ec3847dd6f835af9992e05..476c4f7ce1acf97e691b259c7e959dcc34c227c8 100644 (file)
@@ -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;
                 }
             }