]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Check if any tugs are alive when compressing/expanding repeats
authorAlex Coyte <a.coyte@intel.com>
Mon, 27 Feb 2017 03:22:35 +0000 (14:22 +1100)
committerMatthew Barr <matthew.barr@intel.com>
Wed, 1 Mar 2017 02:05:20 +0000 (13:05 +1100)
src/nfa/limex_compile.cpp
src/nfa/limex_internal.h
src/nfa/limex_runtime_impl.h
src/nfa/repeat.c

index ba4d0f0d95b887939b66a13c8acfd3994ca6f57c..c75eae597d00e1c6fd3d49028b1202619b645bfb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2016, Intel Corporation
+ * Copyright (c) 2015-2017, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -1803,6 +1803,12 @@ struct Factory {
             assert(cyclic != NO_STATE);
             maskSetBit(limex->repeatCyclicMask, cyclic);
         }
+        /* also include tugs in repeat cyclic mask */
+        for (NFAVertex v : args.tugs) {
+            u32 v_state = args.state_ids.at(v);
+            assert(v_state != NO_STATE);
+            maskSetBit(limex->repeatCyclicMask, v_state);
+        }
     }
 
     static
index 723803c191999fb5884d717e7c5f17d900addd78..ccbf342232f17b1b6516e9456e03c21930735f00 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2016, Intel Corporation
+ * Copyright (c) 2015-2017, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -151,7 +151,7 @@ struct LimExNFA##size {                                                     \
                                     *  followers */                         \
     u_##size compressMask; /**< switch off before compress */               \
     u_##size exceptionMask;                                                 \
-    u_##size repeatCyclicMask;                                              \
+    u_##size repeatCyclicMask; /**< also includes tug states */             \
     u_##size zombieMask; /**< zombie if in any of the set states */         \
     u_##size shift[MAX_SHIFT_COUNT];                                        \
     u32 shiftCount; /**< number of shift masks used */                      \
index 45ceb2b5ef2e9ba4372bbb76685d2a1cf5f660a2..016d1f924b67236d88968a0ea3659a636a3b1d2c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2016, Intel Corporation
+ * Copyright (c) 2015-2017, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -393,19 +393,16 @@ void COMPRESS_REPEATS_FN(const IMPL_NFA_T *limex, void *dest, void *src,
         DEBUG_PRINTF("repeat %u\n", i);
         const struct NFARepeatInfo *info = GET_NFA_REPEAT_INFO_FN(limex, i);
 
-        if (!TESTBIT_STATE(s, info->cyclicState)) {
+        const ENG_STATE_T *tug_mask =
+            (const ENG_STATE_T *)((const char *)info + info->tugMaskOffset);
+        /* repeat may still be inspected if its tug state is on */
+        if (!TESTBIT_STATE(s, info->cyclicState)
+            && ISZERO_STATE(AND_STATE(s, LOAD_FROM_ENG(tug_mask)))) {
             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("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],
@@ -448,8 +445,11 @@ void EXPAND_REPEATS_FN(const IMPL_NFA_T *limex, void *dest, const void *src,
     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 ENG_STATE_T *tug_mask =
+            (const ENG_STATE_T *)((const char *)info + info->tugMaskOffset);
 
-        if (!TESTBIT_STATE(cyclics, info->cyclicState)) {
+        if (!TESTBIT_STATE(cyclics, info->cyclicState)
+            && ISZERO_STATE(AND_STATE(cyclics, LOAD_FROM_ENG(tug_mask)))) {
             DEBUG_PRINTF("is dead\n");
             continue;
         }
index 339829a52742edc01b16610504c69c894c896a09..5b2e4df4ed58f80fab6b97d0e6b0ac7feddab90d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2016, Intel Corporation
+ * Copyright (c) 2015-2017, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -177,6 +177,10 @@ u64a repeatLastTopRange(const union RepeatControl *ctrl, const void *state) {
 
 u64a repeatLastTopBitmap(const union RepeatControl *ctrl) {
     const struct RepeatBitmapControl *xs = &ctrl->bitmap;
+    if (!xs->bitmap) {
+        /* last top was too long ago */
+        return 0;
+    }
     return xs->offset + 63 - clz64(xs->bitmap);
 }