]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
nfa: delete largely-unused struct LimExNFABase
authorJustin Viiret <justin.viiret@intel.com>
Tue, 2 Aug 2016 04:49:38 +0000 (14:49 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Wed, 10 Aug 2016 05:10:25 +0000 (15:10 +1000)
src/nfa/limex_internal.h
src/nfa/nfa_build_util.cpp

index 1483a9114839c713f827723ebe808f61438b091c..6bc9a5974fdaed451d1da28caf5152db8c8c3dc1 100644 (file)
@@ -99,24 +99,6 @@ enum LimExSquash {
     LIMEX_SQUASH_REPORT = 3  //!< squash when report is raised
 };
 
-struct LimExNFABase {
-    u8 reachMap[N_CHARS];
-    u32 reachSize;
-    u32 accelCount;
-    u32 accelTableOffset;
-    u32 accelAuxCount;
-    u32 accelAuxOffset;
-    u32 acceptCount;
-    u32 acceptOffset;
-    u32 acceptEodCount;
-    u32 acceptEodOffset;
-    u32 exceptionCount;
-    u32 exceptionOffset;
-    u32 exReportOffset;
-    u32 repeatCount;
-    u32 repeatOffset;
-};
-
 /* uniform looking types for the macros */
 typedef u8   u_8;
 typedef u16  u_16;
@@ -137,7 +119,7 @@ struct NFAException##size {                                                 \
     u8 trigger; /**< from enum LimExTrigger */                              \
 };                                                                          \
                                                                             \
-struct LimExNFA##size { /* MUST align with LimExNFABase */                  \
+struct LimExNFA##size {                                                     \
     u8 reachMap[N_CHARS]; /**< map of char -> entry in reach[] */           \
     u32 reachSize; /**< number of reach masks */                            \
     u32 accelCount; /**< number of entries in accel table */                \
index 9244dcfb3365e4c52d0c5dcea75b2b4b3a9482ac..ce47319663db44ad186beda4f3c569023fad145b 100644 (file)
@@ -78,7 +78,7 @@ struct DISPATCH_BY_NFA_TYPE_INT<sfunc, rv_t, arg_t, INVALID_NFA> {
                              decltype(arg), (NFAEngineType)0>::doOp(i, arg)
 }
 
-typedef bool (*has_accel_fn)(const NFA *nfa);
+typedef bool (*nfa_dispatch_fn)(const NFA *nfa);
 
 template<typename T>
 static
@@ -87,8 +87,37 @@ bool has_accel_limex(const NFA *nfa) {
     return limex->accelCount;
 }
 
+template<typename T>
+static
+bool has_repeats_limex(const NFA *nfa) {
+    const T *limex = (const T *)getImplNfa(nfa);
+    return limex->repeatCount;
+}
+
+
+template<typename T>
+static
+bool has_repeats_other_than_firsts_limex(const NFA *nfa) {
+    const T *limex = (const T *)getImplNfa(nfa);
+    const char *ptr = (const char *)limex;
+
+    const u32 *repeatOffset = (const u32 *)(ptr + limex->repeatOffset);
+
+    for (u32 i = 0; i < limex->repeatCount; i++) {
+        u32 offset = repeatOffset[i];
+        const NFARepeatInfo *info = (const NFARepeatInfo *)(ptr + offset);
+        const RepeatInfo *repeat =
+            (const RepeatInfo *)((const char *)info + sizeof(*info));
+        if (repeat->type != REPEAT_FIRST) {
+            return true;
+        }
+    }
+
+    return false;
+}
+
 static
-bool has_accel_generic(const NFA *) {
+bool dispatch_false(const NFA *) {
     return false;
 }
 
@@ -146,13 +175,20 @@ enum NFACategory {NFA_LIMEX, NFA_OTHER};
         static const NFACategory category = NFA_LIMEX;                  \
         typedef LimExNFA##mlt_size implNFA_t;                           \
         typedef u_##mlt_size tableRow_t;                                \
-        static const has_accel_fn has_accel;                            \
+        static const nfa_dispatch_fn has_accel;                         \
+        static const nfa_dispatch_fn has_repeats;                       \
+        static const nfa_dispatch_fn has_repeats_other_than_firsts;     \
         static const u32 stateAlign =                                   \
                 MAX(alignof(tableRow_t), alignof(RepeatControl));       \
         static const bool fast = mlt_size <= 64;                        \
     };                                                                  \
-    const has_accel_fn NFATraits<LIMEX_NFA_##mlt_size>::has_accel       \
+    const nfa_dispatch_fn NFATraits<LIMEX_NFA_##mlt_size>::has_accel    \
             = has_accel_limex<LimExNFA##mlt_size>;                      \
+    const nfa_dispatch_fn NFATraits<LIMEX_NFA_##mlt_size>::has_repeats  \
+            = has_repeats_limex<LimExNFA##mlt_size>;                    \
+    const nfa_dispatch_fn                                               \
+        NFATraits<LIMEX_NFA_##mlt_size>::has_repeats_other_than_firsts  \
+            = has_repeats_other_than_firsts_limex<LimExNFA##mlt_size>;  \
     DO_IF_DUMP_SUPPORT(                                                 \
     const char *NFATraits<LIMEX_NFA_##mlt_size>::name                   \
         = "LimEx "#mlt_size;                                            \
@@ -173,9 +209,13 @@ template<> struct NFATraits<MCCLELLAN_NFA_8> {
     static const NFACategory category = NFA_OTHER;
     static const u32 stateAlign = 1;
     static const bool fast = true;
-    static const has_accel_fn has_accel;
+    static const nfa_dispatch_fn has_accel;
+    static const nfa_dispatch_fn has_repeats;
+    static const nfa_dispatch_fn has_repeats_other_than_firsts;
 };
-const has_accel_fn NFATraits<MCCLELLAN_NFA_8>::has_accel = has_accel_dfa;
+const nfa_dispatch_fn NFATraits<MCCLELLAN_NFA_8>::has_accel = has_accel_dfa;
+const nfa_dispatch_fn NFATraits<MCCLELLAN_NFA_8>::has_repeats = dispatch_false;
+const nfa_dispatch_fn NFATraits<MCCLELLAN_NFA_8>::has_repeats_other_than_firsts = dispatch_false;
 #if defined(DUMP_SUPPORT)
 const char *NFATraits<MCCLELLAN_NFA_8>::name = "McClellan 8";
 #endif
@@ -185,9 +225,13 @@ template<> struct NFATraits<MCCLELLAN_NFA_16> {
     static const NFACategory category = NFA_OTHER;
     static const u32 stateAlign = 2;
     static const bool fast = true;
-    static const has_accel_fn has_accel;
+    static const nfa_dispatch_fn has_accel;
+    static const nfa_dispatch_fn has_repeats;
+    static const nfa_dispatch_fn has_repeats_other_than_firsts;
 };
-const has_accel_fn NFATraits<MCCLELLAN_NFA_16>::has_accel = has_accel_dfa;
+const nfa_dispatch_fn NFATraits<MCCLELLAN_NFA_16>::has_accel = has_accel_dfa;
+const nfa_dispatch_fn NFATraits<MCCLELLAN_NFA_16>::has_repeats = dispatch_false;
+const nfa_dispatch_fn NFATraits<MCCLELLAN_NFA_16>::has_repeats_other_than_firsts = dispatch_false;
 #if defined(DUMP_SUPPORT)
 const char *NFATraits<MCCLELLAN_NFA_16>::name = "McClellan 16";
 #endif
@@ -197,9 +241,13 @@ template<> struct NFATraits<GOUGH_NFA_8> {
     static const NFACategory category = NFA_OTHER;
     static const u32 stateAlign = 8;
     static const bool fast = true;
-    static const has_accel_fn has_accel;
+    static const nfa_dispatch_fn has_accel;
+    static const nfa_dispatch_fn has_repeats;
+    static const nfa_dispatch_fn has_repeats_other_than_firsts;
 };
-const has_accel_fn NFATraits<GOUGH_NFA_8>::has_accel = has_accel_dfa;
+const nfa_dispatch_fn NFATraits<GOUGH_NFA_8>::has_accel = has_accel_dfa;
+const nfa_dispatch_fn NFATraits<GOUGH_NFA_8>::has_repeats = dispatch_false;
+const nfa_dispatch_fn NFATraits<GOUGH_NFA_8>::has_repeats_other_than_firsts = dispatch_false;
 #if defined(DUMP_SUPPORT)
 const char *NFATraits<GOUGH_NFA_8>::name = "Goughfish 8";
 #endif
@@ -209,9 +257,13 @@ template<> struct NFATraits<GOUGH_NFA_16> {
     static const NFACategory category = NFA_OTHER;
     static const u32 stateAlign = 8;
     static const bool fast = true;
-    static const has_accel_fn has_accel;
+    static const nfa_dispatch_fn has_accel;
+    static const nfa_dispatch_fn has_repeats;
+    static const nfa_dispatch_fn has_repeats_other_than_firsts;
 };
-const has_accel_fn NFATraits<GOUGH_NFA_16>::has_accel = has_accel_dfa;
+const nfa_dispatch_fn NFATraits<GOUGH_NFA_16>::has_accel = has_accel_dfa;
+const nfa_dispatch_fn NFATraits<GOUGH_NFA_16>::has_repeats = dispatch_false;
+const nfa_dispatch_fn NFATraits<GOUGH_NFA_16>::has_repeats_other_than_firsts = dispatch_false;
 #if defined(DUMP_SUPPORT)
 const char *NFATraits<GOUGH_NFA_16>::name = "Goughfish 16";
 #endif
@@ -221,9 +273,13 @@ template<> struct NFATraits<MPV_NFA_0> {
     static const NFACategory category = NFA_OTHER;
     static const u32 stateAlign = 8;
     static const bool fast = true;
-    static const has_accel_fn has_accel;
+    static const nfa_dispatch_fn has_accel;
+    static const nfa_dispatch_fn has_repeats;
+    static const nfa_dispatch_fn has_repeats_other_than_firsts;
 };
-const has_accel_fn NFATraits<MPV_NFA_0>::has_accel = has_accel_generic;
+const nfa_dispatch_fn NFATraits<MPV_NFA_0>::has_accel = dispatch_false;
+const nfa_dispatch_fn NFATraits<MPV_NFA_0>::has_repeats = dispatch_false;
+const nfa_dispatch_fn NFATraits<MPV_NFA_0>::has_repeats_other_than_firsts = dispatch_false;
 #if defined(DUMP_SUPPORT)
 const char *NFATraits<MPV_NFA_0>::name = "Mega-Puff-Vac";
 #endif
@@ -233,9 +289,13 @@ template<> struct NFATraits<CASTLE_NFA_0> {
     static const NFACategory category = NFA_OTHER;
     static const u32 stateAlign = 8;
     static const bool fast = true;
-    static const has_accel_fn has_accel;
+    static const nfa_dispatch_fn has_accel;
+    static const nfa_dispatch_fn has_repeats;
+    static const nfa_dispatch_fn has_repeats_other_than_firsts;
 };
-const has_accel_fn NFATraits<CASTLE_NFA_0>::has_accel = has_accel_generic;
+const nfa_dispatch_fn NFATraits<CASTLE_NFA_0>::has_accel = dispatch_false;
+const nfa_dispatch_fn NFATraits<CASTLE_NFA_0>::has_repeats = dispatch_false;
+const nfa_dispatch_fn NFATraits<CASTLE_NFA_0>::has_repeats_other_than_firsts = dispatch_false;
 #if defined(DUMP_SUPPORT)
 const char *NFATraits<CASTLE_NFA_0>::name = "Castle";
 #endif
@@ -245,9 +305,13 @@ template<> struct NFATraits<LBR_NFA_Dot> {
     static const NFACategory category = NFA_OTHER;
     static const u32 stateAlign = 8;
     static const bool fast = true;
-    static const has_accel_fn has_accel;
+    static const nfa_dispatch_fn has_accel;
+    static const nfa_dispatch_fn has_repeats;
+    static const nfa_dispatch_fn has_repeats_other_than_firsts;
 };
-const has_accel_fn NFATraits<LBR_NFA_Dot>::has_accel = has_accel_generic;
+const nfa_dispatch_fn NFATraits<LBR_NFA_Dot>::has_accel = dispatch_false;
+const nfa_dispatch_fn NFATraits<LBR_NFA_Dot>::has_repeats = dispatch_false;
+const nfa_dispatch_fn NFATraits<LBR_NFA_Dot>::has_repeats_other_than_firsts = dispatch_false;
 #if defined(DUMP_SUPPORT)
 const char *NFATraits<LBR_NFA_Dot>::name = "Lim Bounded Repeat (D)";
 #endif
@@ -257,9 +321,13 @@ template<> struct NFATraits<LBR_NFA_Verm> {
     static const NFACategory category = NFA_OTHER;
     static const u32 stateAlign = 8;
     static const bool fast = true;
-    static const has_accel_fn has_accel;
+    static const nfa_dispatch_fn has_accel;
+    static const nfa_dispatch_fn has_repeats;
+    static const nfa_dispatch_fn has_repeats_other_than_firsts;
 };
-const has_accel_fn NFATraits<LBR_NFA_Verm>::has_accel = has_accel_generic;
+const nfa_dispatch_fn NFATraits<LBR_NFA_Verm>::has_accel = dispatch_false;
+const nfa_dispatch_fn NFATraits<LBR_NFA_Verm>::has_repeats = dispatch_false;
+const nfa_dispatch_fn NFATraits<LBR_NFA_Verm>::has_repeats_other_than_firsts = dispatch_false;
 #if defined(DUMP_SUPPORT)
 const char *NFATraits<LBR_NFA_Verm>::name = "Lim Bounded Repeat (V)";
 #endif
@@ -269,9 +337,13 @@ template<> struct NFATraits<LBR_NFA_NVerm> {
     static const NFACategory category = NFA_OTHER;
     static const u32 stateAlign = 8;
     static const bool fast = true;
-    static const has_accel_fn has_accel;
+    static const nfa_dispatch_fn has_accel;
+    static const nfa_dispatch_fn has_repeats;
+    static const nfa_dispatch_fn has_repeats_other_than_firsts;
 };
-const has_accel_fn NFATraits<LBR_NFA_NVerm>::has_accel = has_accel_generic;
+const nfa_dispatch_fn NFATraits<LBR_NFA_NVerm>::has_accel = dispatch_false;
+const nfa_dispatch_fn NFATraits<LBR_NFA_NVerm>::has_repeats = dispatch_false;
+const nfa_dispatch_fn NFATraits<LBR_NFA_NVerm>::has_repeats_other_than_firsts = dispatch_false;
 #if defined(DUMP_SUPPORT)
 const char *NFATraits<LBR_NFA_NVerm>::name = "Lim Bounded Repeat (NV)";
 #endif
@@ -281,9 +353,13 @@ template<> struct NFATraits<LBR_NFA_Shuf> {
     static const NFACategory category = NFA_OTHER;
     static const u32 stateAlign = 8;
     static const bool fast = true;
-    static const has_accel_fn has_accel;
+    static const nfa_dispatch_fn has_accel;
+    static const nfa_dispatch_fn has_repeats;
+    static const nfa_dispatch_fn has_repeats_other_than_firsts;
 };
-const has_accel_fn NFATraits<LBR_NFA_Shuf>::has_accel = has_accel_generic;
+const nfa_dispatch_fn NFATraits<LBR_NFA_Shuf>::has_accel = dispatch_false;
+const nfa_dispatch_fn NFATraits<LBR_NFA_Shuf>::has_repeats = dispatch_false;
+const nfa_dispatch_fn NFATraits<LBR_NFA_Shuf>::has_repeats_other_than_firsts = dispatch_false;
 #if defined(DUMP_SUPPORT)
 const char *NFATraits<LBR_NFA_Shuf>::name = "Lim Bounded Repeat (S)";
 #endif
@@ -293,9 +369,13 @@ template<> struct NFATraits<LBR_NFA_Truf> {
     static const NFACategory category = NFA_OTHER;
     static const u32 stateAlign = 8;
     static const bool fast = true;
-    static const has_accel_fn has_accel;
+    static const nfa_dispatch_fn has_accel;
+    static const nfa_dispatch_fn has_repeats;
+    static const nfa_dispatch_fn has_repeats_other_than_firsts;
 };
-const has_accel_fn NFATraits<LBR_NFA_Truf>::has_accel = has_accel_generic;
+const nfa_dispatch_fn NFATraits<LBR_NFA_Truf>::has_accel = dispatch_false;
+const nfa_dispatch_fn NFATraits<LBR_NFA_Truf>::has_repeats = dispatch_false;
+const nfa_dispatch_fn NFATraits<LBR_NFA_Truf>::has_repeats_other_than_firsts = dispatch_false;
 #if defined(DUMP_SUPPORT)
 const char *NFATraits<LBR_NFA_Truf>::name = "Lim Bounded Repeat (M)";
 #endif
@@ -305,9 +385,13 @@ template<> struct NFATraits<TAMARAMA_NFA_0> {
     static const NFACategory category = NFA_OTHER;
     static const u32 stateAlign = 32;
     static const bool fast = true;
-    static const has_accel_fn has_accel;
+    static const nfa_dispatch_fn has_accel;
+    static const nfa_dispatch_fn has_repeats;
+    static const nfa_dispatch_fn has_repeats_other_than_firsts;
 };
-const has_accel_fn NFATraits<TAMARAMA_NFA_0>::has_accel = has_accel_generic;
+const nfa_dispatch_fn NFATraits<TAMARAMA_NFA_0>::has_accel = dispatch_false;
+const nfa_dispatch_fn NFATraits<TAMARAMA_NFA_0>::has_repeats = dispatch_false;
+const nfa_dispatch_fn NFATraits<TAMARAMA_NFA_0>::has_repeats_other_than_firsts = dispatch_false;
 #if defined(DUMP_SUPPORT)
 const char *NFATraits<TAMARAMA_NFA_0>::name = "Tamarama";
 #endif
@@ -362,42 +446,39 @@ struct is_limex {
 };
 }
 
-bool has_bounded_repeats_other_than_firsts(const NFA &nfa) {
-    if (!DISPATCH_BY_NFA_TYPE((NFAEngineType)nfa.type, is_limex, &nfa)) {
-        return false;
+namespace {
+template<NFAEngineType t>
+struct has_repeats_other_than_firsts_dispatch {
+    static nfa_dispatch_fn call(const void *) {
+        return NFATraits<t>::has_repeats_other_than_firsts;
     }
+};
+}
 
-    const LimExNFABase *limex = (const LimExNFABase *)getImplNfa(&nfa);
-    const char *ptr = (const char *)limex;
-
-    const u32 *repeatOffset = (const u32 *)(ptr + limex->repeatOffset);
+bool has_bounded_repeats_other_than_firsts(const NFA &nfa) {
+    return DISPATCH_BY_NFA_TYPE((NFAEngineType)nfa.type,
+                                has_repeats_other_than_firsts_dispatch,
+                                &nfa)(&nfa);
+}
 
-    for (u32 i = 0; i < limex->repeatCount; i++) {
-        u32 offset = repeatOffset[i];
-        const NFARepeatInfo *info = (const NFARepeatInfo *)(ptr + offset);
-        const RepeatInfo *repeat =
-            (const RepeatInfo *)((const char *)info + sizeof(*info));
-        if (repeat->type != REPEAT_FIRST) {
-            return true;
-        }
+namespace {
+template<NFAEngineType t>
+struct has_repeats_dispatch {
+    static nfa_dispatch_fn call(const void *) {
+        return NFATraits<t>::has_repeats;
     }
-
-    return false;
+};
 }
 
 bool has_bounded_repeats(const NFA &nfa) {
-    if (!DISPATCH_BY_NFA_TYPE((NFAEngineType)nfa.type, is_limex, &nfa)) {
-        return false;
-    }
-
-    const LimExNFABase *limex = (const LimExNFABase *)getImplNfa(&nfa);
-    return limex->repeatCount;
+    return DISPATCH_BY_NFA_TYPE((NFAEngineType)nfa.type, has_repeats_dispatch,
+                                &nfa)(&nfa);
 }
 
 namespace {
 template<NFAEngineType t>
 struct has_accel_dispatch {
-    static has_accel_fn call(const void *) {
+    static nfa_dispatch_fn call(const void *) {
         return NFATraits<t>::has_accel;
     }
 };
@@ -405,8 +486,7 @@ struct has_accel_dispatch {
 
 bool has_accel(const NFA &nfa) {
     return DISPATCH_BY_NFA_TYPE((NFAEngineType)nfa.type, has_accel_dispatch,
-                                &nfa)
-        (&nfa);
+                                &nfa)(&nfa);
 }
 
 bool requires_decompress_key(const NFA &nfa) {