]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
limex: only compress active repeats
authorJustin Viiret <justin.viiret@intel.com>
Mon, 4 Jul 2016 02:56:03 +0000 (12:56 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Wed, 10 Aug 2016 04:52:56 +0000 (14:52 +1000)
src/nfa/limex_runtime_impl.h

index 2ea86ed26b1a3c6a465650023e7ad88c0ce25c7b..95f18d1b07611d321b7e2383d28a1aaafc3a5699 100644 (file)
@@ -363,16 +363,24 @@ void COMPRESS_REPEATS_FN(const IMPL_NFA_T *limex, void *dest, void *src,
     char *state_base = (char *)dest + limex->stateSize;
 
     for (u32 i = 0; i < limex->repeatCount; i++) {
+        DEBUG_PRINTF("repeat %u\n", i);
         const struct NFARepeatInfo *info = GET_NFA_REPEAT_INFO_FN(limex, i);
-        const struct RepeatInfo *repeat = getRepeatInfo(info);
 
-        if (TESTBIT_STATE(&s, info->cyclicState) &&
-            repeatHasMatch(repeat, &ctrl[i], state_base + info->stateOffset,
+        if (!TESTBIT_STATE(&s, info->cyclicState)) {
+            DEBUG_PRINTF("is dead\n");
+            continue;
+        }
+
+        const struct RepeatInfo *repeat = getRepeatInfo(info);
+        if (repeatHasMatch(repeat, &ctrl[i], state_base + info->stateOffset,
                            offset) == REPEAT_STALE) {
-            DEBUG_PRINTF("repeat %u is stale\n", i);
+            DEBUG_PRINTF("is stale, clearing state\n");
             CLEARBIT_STATE(&s, info->cyclicState);
+            continue;
         }
 
+        DEBUG_PRINTF("packing state (packedCtrlOffset=%u)\n",
+                     info->packedCtrlOffset);
         repeatPack(state_base + info->packedCtrlOffset, repeat, &ctrl[i],
                    offset);
     }
@@ -398,15 +406,24 @@ void EXPAND_REPEATS_FN(const IMPL_NFA_T *limex, void *dest, const void *src,
         return;
     }
 
-    // Note: we expand all repeats, as they may have *just* had their
-    // cyclic states switched off a moment ago. TODO: is this required?
+    // Note: state has already been expanded into 'dest'.
+    STATE_T s = LOAD_STATE(dest);
 
     union RepeatControl *ctrl =
         getRepeatControlBase((char *)dest, sizeof(STATE_T));
     const char *state_base = (const char *)src + limex->stateSize;
 
     for (u32 i = 0; i < limex->repeatCount; i++) {
+        DEBUG_PRINTF("repeat %u\n", i);
         const struct NFARepeatInfo *info = GET_NFA_REPEAT_INFO_FN(limex, i);
+
+        if (!TESTBIT_STATE(&s, info->cyclicState)) {
+            DEBUG_PRINTF("is dead\n");
+            continue;
+        }
+
+        DEBUG_PRINTF("unpacking state (packedCtrlOffset=%u)\n",
+                     info->packedCtrlOffset);
         const struct RepeatInfo *repeat = getRepeatInfo(info);
         repeatUnpack(state_base + info->packedCtrlOffset, repeat, offset,
                      &ctrl[i]);