]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
limex: implement variable shift NFA engines
authorKirill Rybalchenko <kirill.rybalchenko@intel.com>
Thu, 21 Apr 2016 15:52:43 +0000 (16:52 +0100)
committerMatthew Barr <matthew.barr@intel.com>
Fri, 8 Jul 2016 00:57:29 +0000 (10:57 +1000)
Replaces the old LimEx NFA engines, which were specialised for model
size and number of shifts, with a new set of engines that can handle a
variable number of shifts.

21 files changed:
CMakeLists.txt
src/grey.cpp
src/grey.h
src/nfa/limex.h
src/nfa/limex_compile.cpp
src/nfa/limex_dump.cpp
src/nfa/limex_internal.h
src/nfa/limex_native.c
src/nfa/limex_runtime.h
src/nfa/limex_runtime_impl.h
src/nfa/limex_simd128.c
src/nfa/limex_simd256.c
src/nfa/limex_simd384.c
src/nfa/limex_simd512.c [moved from src/nfa/limex_simd512b.c with 88% similarity]
src/nfa/limex_simd512a.c [deleted file]
src/nfa/limex_simd512c.c [deleted file]
src/nfa/nfa_api_dispatch.c
src/nfa/nfa_build_util.cpp
src/nfa/nfa_dump_dispatch.cpp
src/nfa/nfa_internal.h
unit/internal/limex_nfa.cpp

index d49de2775cf142e66f75e2a78b018a52a98814e7..2652cea3a35c3136d845dbbc71166b525b1474ce 100644 (file)
@@ -438,9 +438,7 @@ set (hs_exec_SRCS
     src/nfa/limex_simd128.c
     src/nfa/limex_simd256.c
     src/nfa/limex_simd384.c
-    src/nfa/limex_simd512a.c
-    src/nfa/limex_simd512b.c
-    src/nfa/limex_simd512c.c
+    src/nfa/limex_simd512.c
     src/nfa/limex.h
     src/nfa/limex_common_impl.h
     src/nfa/limex_context.h
index e2022e74163e14672f3d9174db14cf21401f405f..1f2fd9041e36e8cb3f05a75fc9675305817aa015 100644 (file)
@@ -81,7 +81,6 @@ Grey::Grey(void) :
                    allowZombies(true),
                    floodAsPuffette(false),
                    nfaForceSize(0),
-                   nfaForceShifts(0),
                    maxHistoryAvailable(DEFAULT_MAX_HISTORY),
                    minHistoryAvailable(0), /* debugging only */
                    maxAnchoredRegion(63), /* for rose's atable to run over */
@@ -234,7 +233,6 @@ void applyGreyOverrides(Grey *g, const string &s) {
         G_UPDATE(allowZombies);
         G_UPDATE(floodAsPuffette);
         G_UPDATE(nfaForceSize);
-        G_UPDATE(nfaForceShifts);
         G_UPDATE(highlanderSquash);
         G_UPDATE(maxHistoryAvailable);
         G_UPDATE(minHistoryAvailable);
index 8ac9e6b180430519243e1245aab3d1b366f27cdc..634fa3a7d444286b78e94b077680a7573c45bbc3 100644 (file)
@@ -88,7 +88,6 @@ struct Grey {
     bool floodAsPuffette;
 
     u32 nfaForceSize;
-    u32 nfaForceShifts;
 
     u32 maxHistoryAvailable;
     u32 minHistoryAvailable;
index 2c429a67732717029bb0f8eee6e2b12ae800bb02..57ee46df3c0627c97c7f80f53259e4f15373aa34 100644 (file)
@@ -74,41 +74,11 @@ extern "C"
                                                    struct mq *q, s64a loc);    \
     GENERATE_NFA_DUMP_DECL(gf_name)
 
-GENERATE_NFA_DECL(nfaExecLimEx32_1)
-GENERATE_NFA_DECL(nfaExecLimEx32_2)
-GENERATE_NFA_DECL(nfaExecLimEx32_3)
-GENERATE_NFA_DECL(nfaExecLimEx32_4)
-GENERATE_NFA_DECL(nfaExecLimEx32_5)
-GENERATE_NFA_DECL(nfaExecLimEx32_6)
-GENERATE_NFA_DECL(nfaExecLimEx32_7)
-GENERATE_NFA_DECL(nfaExecLimEx128_1)
-GENERATE_NFA_DECL(nfaExecLimEx128_2)
-GENERATE_NFA_DECL(nfaExecLimEx128_3)
-GENERATE_NFA_DECL(nfaExecLimEx128_4)
-GENERATE_NFA_DECL(nfaExecLimEx128_5)
-GENERATE_NFA_DECL(nfaExecLimEx128_6)
-GENERATE_NFA_DECL(nfaExecLimEx128_7)
-GENERATE_NFA_DECL(nfaExecLimEx256_1)
-GENERATE_NFA_DECL(nfaExecLimEx256_2)
-GENERATE_NFA_DECL(nfaExecLimEx256_3)
-GENERATE_NFA_DECL(nfaExecLimEx256_4)
-GENERATE_NFA_DECL(nfaExecLimEx256_5)
-GENERATE_NFA_DECL(nfaExecLimEx256_6)
-GENERATE_NFA_DECL(nfaExecLimEx256_7)
-GENERATE_NFA_DECL(nfaExecLimEx384_1)
-GENERATE_NFA_DECL(nfaExecLimEx384_2)
-GENERATE_NFA_DECL(nfaExecLimEx384_3)
-GENERATE_NFA_DECL(nfaExecLimEx384_4)
-GENERATE_NFA_DECL(nfaExecLimEx384_5)
-GENERATE_NFA_DECL(nfaExecLimEx384_6)
-GENERATE_NFA_DECL(nfaExecLimEx384_7)
-GENERATE_NFA_DECL(nfaExecLimEx512_1)
-GENERATE_NFA_DECL(nfaExecLimEx512_2)
-GENERATE_NFA_DECL(nfaExecLimEx512_3)
-GENERATE_NFA_DECL(nfaExecLimEx512_4)
-GENERATE_NFA_DECL(nfaExecLimEx512_5)
-GENERATE_NFA_DECL(nfaExecLimEx512_6)
-GENERATE_NFA_DECL(nfaExecLimEx512_7)
+GENERATE_NFA_DECL(nfaExecLimEx32)
+GENERATE_NFA_DECL(nfaExecLimEx128)
+GENERATE_NFA_DECL(nfaExecLimEx256)
+GENERATE_NFA_DECL(nfaExecLimEx384)
+GENERATE_NFA_DECL(nfaExecLimEx512)
 
 #undef GENERATE_NFA_DECL
 #undef GENERATE_NFA_DUMP_DECL
index 5d51feb9b2105a22239f9fbc528e365d35e9aabc..563d6c9c9ec86d0f48cba2aeead2db69c156066b 100644 (file)
@@ -169,10 +169,10 @@ struct build_info {
 
 // Constants for scoring mechanism
 
-#define LAST_LIMEX_NFA LIMEX_NFA_512_7
+#define LAST_LIMEX_NFA LIMEX_NFA_512
 
 const int LIMEX_INITIAL_SCORE = 2000;
-const int SHIFT_COST = 20; // limex: cost per shift mask
+const int SHIFT_COST = 10; // limex: cost per shift mask
 const int EXCEPTION_COST = 4; // limex: per exception
 
 template<NFAEngineType t> struct NFATraits { };
@@ -261,6 +261,17 @@ void maskSetBits(Mask &m, const NFAStateSet &bits) {
     }
 }
 
+template<class Mask>
+bool isMaskZero(Mask &m) {
+    u8 *m8 = (u8 *)&m;
+    for (u32 i = 0; i < sizeof(m); i++) {
+        if (m8[i]) {
+            return false;
+        }
+    }
+    return true;
+}
+
 // Sets an entire byte in a mask to the given value
 template<class Mask>
 void maskSetByte(Mask &m, const unsigned int idx, const char val) {
@@ -1315,6 +1326,95 @@ u32 depth_to_u32(const depth &d) {
     return d_val;
 }
 
+static
+bool isExceptionalTransition(const NGHolder &h, const NFAEdge &e,
+                             const build_info &args, u32 maxShift) {
+    NFAVertex from = source(e, h);
+    NFAVertex to = target(e, h);
+    u32 f = args.state_ids.at(from);
+    u32 t = args.state_ids.at(to);
+    if (!isLimitedTransition(f, t, maxShift)) {
+        return true;
+    }
+
+    // All transitions out of a tug trigger are exceptional.
+    if (contains(args.tugs, from)) {
+        return true;
+    }
+    return false;
+}
+
+static
+u32 findMaxVarShift(const build_info &args, u32 nShifts) {
+    const NGHolder &h = args.h;
+    u32 shiftMask = 0;
+    for (const auto &e : edges_range(h)) {
+        u32 from = args.state_ids.at(source(e, h));
+        u32 to = args.state_ids.at(target(e, h));
+        if (from == NO_STATE || to == NO_STATE) {
+            continue;
+        }
+        if (!isExceptionalTransition(h, e, args, MAX_SHIFT_AMOUNT)) {
+            shiftMask |= (1UL << (to - from));
+        }
+    }
+
+    u32 maxVarShift = 0;
+    for (u32 shiftCnt = 0; shiftMask != 0 && shiftCnt < nShifts; shiftCnt++) {
+        maxVarShift = findAndClearLSB_32(&shiftMask);
+    }
+
+    return maxVarShift;
+}
+
+static
+int getLimexScore(const build_info &args, u32 nShifts) {
+    const NGHolder &h = args.h;
+    u32 maxVarShift = nShifts;
+    int score = LIMEX_INITIAL_SCORE;
+
+    score -= SHIFT_COST * nShifts;
+    maxVarShift = findMaxVarShift(args, nShifts);
+
+    NFAStateSet exceptionalStates(args.num_states);
+    for (const auto &e : edges_range(h)) {
+        u32 from = args.state_ids.at(source(e, h));
+        u32 to = args.state_ids.at(target(e, h));
+        if (from == NO_STATE || to == NO_STATE) {
+            continue;
+        }
+        if (isExceptionalTransition(h, e, args, maxVarShift)) {
+            exceptionalStates.set(from);
+        }
+    }
+    score -= EXCEPTION_COST * exceptionalStates.count();
+    if (score < 0) {
+        score = 0;
+    }
+    return score;
+}
+
+// This function finds the best shift scheme with highest score
+// Returns number of shifts and score calculated for appropriate scheme
+// Returns zero if no appropriate scheme was found
+static
+u32 findBestNumOfVarShifts(const build_info &args,
+                           int *bestScoreRet = nullptr) {
+    u32 bestNumOfVarShifts = 0;
+    int bestScore = 0;
+    for (u32 shiftCount = 1; shiftCount <= MAX_SHIFT_COUNT; shiftCount++) {
+        int score = getLimexScore(args, shiftCount);
+        if (score > bestScore) {
+            bestScore = score;
+            bestNumOfVarShifts = shiftCount;
+        }
+    }
+    if (bestScoreRet != nullptr) {
+        *bestScoreRet = bestScore;
+    }
+    return bestNumOfVarShifts;
+}
+
 template<NFAEngineType dtype>
 struct Factory {
     // typedefs for readability, for types derived from traits
@@ -1322,25 +1422,6 @@ struct Factory {
     typedef typename NFATraits<dtype>::implNFA_t implNFA_t;
     typedef typename NFATraits<dtype>::tableRow_t tableRow_t;
 
-    static
-    bool isExceptionalTransition(const NGHolder &h, const NFAEdge &e,
-                                 const ue2::unordered_map<NFAVertex, u32> &state_ids,
-                                 const ue2::unordered_set<NFAVertex> &tugs) {
-        NFAVertex from = source(e, h);
-        NFAVertex to = target(e, h);
-        u32 f = state_ids.at(from);
-        u32 t = state_ids.at(to);
-        if (!isLimitedTransition(f, t, NFATraits<dtype>::maxShift)) {
-            return true;
-        }
-
-        // All transitions out of a tug trigger are exceptional.
-        if (contains(tugs, from)) {
-            return true;
-        }
-        return false;
-    }
-
     static
     void allocState(NFA *nfa, u32 repeatscratchStateSize,
                     u32 repeatStreamState) {
@@ -1504,6 +1585,9 @@ struct Factory {
     static
     void writeShiftMasks(const build_info &args, implNFA_t *limex) {
         const NGHolder &h = args.h;
+        u32 maxShift = findMaxVarShift(args, limex->shiftCount);
+        u32 shiftMask = 0;
+        int shiftMaskIdx = 0;
 
         for (const auto &e : edges_range(h)) {
             u32 from = args.state_ids.at(source(e, h));
@@ -1515,15 +1599,32 @@ struct Factory {
             // We check for exceptional transitions here, as we don't want tug
             // trigger transitions emitted as limited transitions (even if they
             // could be in this model).
-            if (!isExceptionalTransition(h, e, args.state_ids, args.tugs)) {
-                maskSetBit(limex->shift[to - from], from);
+            if (!isExceptionalTransition(h, e, args, maxShift)) {
+                u32 shift = to - from;
+                if ((shiftMask & (1UL << shift)) == 0UL) {
+                    shiftMask |= (1UL << shift);
+                    limex->shiftAmount[shiftMaskIdx++] = (u8)shift;
+                }
+                assert(limex->shiftCount <= MAX_SHIFT_COUNT);
+                for (u32 i = 0; i < limex->shiftCount; i++) {
+                    if (limex->shiftAmount[i] == (u8)shift) {
+                        maskSetBit(limex->shift[i], from);
+                        break;
+                    }
+                }
+            }
+        }
+        if (maxShift && limex->shiftCount > 1) {
+            for (u32 i = 0; i < limex->shiftCount; i++) {
+                assert(!isMaskZero(limex->shift[i]));
             }
         }
     }
 
     static
     void findExceptionalTransitions(const build_info &args,
-                                    ue2::unordered_set<NFAEdge> &exceptional) {
+                                    ue2::unordered_set<NFAEdge> &exceptional,
+                                    u32 maxShift) {
         const NGHolder &h = args.h;
 
         for (const auto &e : edges_range(h)) {
@@ -1533,7 +1634,7 @@ struct Factory {
                 continue;
             }
 
-            if (isExceptionalTransition(h, e, args.state_ids, args.tugs)) {
+            if (isExceptionalTransition(h, e, args, maxShift)) {
                 exceptional.insert(e);
             }
         }
@@ -1778,7 +1879,10 @@ struct Factory {
         }
 
         ue2::unordered_set<NFAEdge> exceptional;
-        findExceptionalTransitions(args, exceptional);
+        u32 shiftCount = findBestNumOfVarShifts(args);
+        assert(shiftCount);
+        u32 maxShift = findMaxVarShift(args, shiftCount);
+        findExceptionalTransitions(args, exceptional, maxShift);
 
         map<ExceptionProto, vector<u32> > exceptionMap;
         vector<ReportID> exceptionReports;
@@ -1874,6 +1978,7 @@ struct Factory {
         writeAccepts(acceptMask, acceptEodMask, accepts, acceptsEod, squash,
                      limex, acceptsOffset, acceptsEodOffset, squashOffset);
 
+        limex->shiftCount = shiftCount;
         writeShiftMasks(args, limex);
 
         // Determine the state required for our state vector.
@@ -1907,8 +2012,6 @@ struct Factory {
     }
 
     static int score(const build_info &args) {
-        const NGHolder &h = args.h;
-
         // LimEx NFAs are available in sizes from 32 to 512-bit.
         size_t num_states = args.num_states;
 
@@ -1928,45 +2031,17 @@ struct Factory {
             sz = args.cc.grey.nfaForceSize;
         }
 
-        if (args.cc.grey.nfaForceShifts &&
-            NFATraits<dtype>::maxShift != args.cc.grey.nfaForceShifts) {
-            return -1;
-        }
-
         if (sz != NFATraits<dtype>::maxStates) {
             return -1; // fail, size not appropriate
         }
 
         // We are of the right size, calculate a score based on the number
         // of exceptions and the number of shifts used by this LimEx.
-        int score = LIMEX_INITIAL_SCORE;
-        if (NFATraits<dtype>::maxShift != 0) {
-            score -= SHIFT_COST / 2; // first shift mask is cheap
-            score -= SHIFT_COST * (NFATraits<dtype>::maxShift - 1);
-        }
-
-        NFAStateSet exceptionalStates(num_states); // outbound exc trans
-
-        for (const auto &e : edges_range(h)) {
-            u32 from = args.state_ids.at(source(e, h));
-            u32 to = args.state_ids.at(target(e, h));
-            if (from == NO_STATE || to == NO_STATE) {
-                continue;
-            }
-
-            if (isExceptionalTransition(h, e, args.state_ids, args.tugs)) {
-                exceptionalStates.set(from);
-            }
-        }
-        DEBUG_PRINTF("%zu exceptional states\n", exceptionalStates.count());
-        score -= EXCEPTION_COST * exceptionalStates.count();
-
-        /* ensure that we always report a valid score if have the right number
-         * of states */
-        if (score < 0) {
-            score = 0;
+        int score;
+        u32 shiftCount = findBestNumOfVarShifts(args, &score);
+        if (shiftCount == 0) {
+            return -1;
         }
-
         return score;
     }
 };
@@ -1985,50 +2060,19 @@ struct scoreNfa {
     }
 };
 
-#define MAKE_LIMEX_TRAITS(mlt_size, mlt_shift)                          \
-    template<> struct NFATraits<LIMEX_NFA_##mlt_size##_##mlt_shift> {   \
-        typedef LimExNFA##mlt_size implNFA_t;                           \
-        typedef u_##mlt_size tableRow_t;                                \
-        typedef NFAException##mlt_size exception_t;                     \
-        static const size_t maxStates = mlt_size;                       \
-        static const u32 maxShift = mlt_shift;                          \
-    };                                                                  \
-
-MAKE_LIMEX_TRAITS(32, 1)
-MAKE_LIMEX_TRAITS(32, 2)
-MAKE_LIMEX_TRAITS(32, 3)
-MAKE_LIMEX_TRAITS(32, 4)
-MAKE_LIMEX_TRAITS(32, 5)
-MAKE_LIMEX_TRAITS(32, 6)
-MAKE_LIMEX_TRAITS(32, 7)
-MAKE_LIMEX_TRAITS(128, 1)
-MAKE_LIMEX_TRAITS(128, 2)
-MAKE_LIMEX_TRAITS(128, 3)
-MAKE_LIMEX_TRAITS(128, 4)
-MAKE_LIMEX_TRAITS(128, 5)
-MAKE_LIMEX_TRAITS(128, 6)
-MAKE_LIMEX_TRAITS(128, 7)
-MAKE_LIMEX_TRAITS(256, 1)
-MAKE_LIMEX_TRAITS(256, 2)
-MAKE_LIMEX_TRAITS(256, 3)
-MAKE_LIMEX_TRAITS(256, 4)
-MAKE_LIMEX_TRAITS(256, 5)
-MAKE_LIMEX_TRAITS(256, 6)
-MAKE_LIMEX_TRAITS(256, 7)
-MAKE_LIMEX_TRAITS(384, 1)
-MAKE_LIMEX_TRAITS(384, 2)
-MAKE_LIMEX_TRAITS(384, 3)
-MAKE_LIMEX_TRAITS(384, 4)
-MAKE_LIMEX_TRAITS(384, 5)
-MAKE_LIMEX_TRAITS(384, 6)
-MAKE_LIMEX_TRAITS(384, 7)
-MAKE_LIMEX_TRAITS(512, 1)
-MAKE_LIMEX_TRAITS(512, 2)
-MAKE_LIMEX_TRAITS(512, 3)
-MAKE_LIMEX_TRAITS(512, 4)
-MAKE_LIMEX_TRAITS(512, 5)
-MAKE_LIMEX_TRAITS(512, 6)
-MAKE_LIMEX_TRAITS(512, 7)
+#define MAKE_LIMEX_TRAITS(mlt_size)                                            \
+    template<> struct NFATraits<LIMEX_NFA_##mlt_size> {                        \
+        typedef LimExNFA##mlt_size implNFA_t;                                  \
+        typedef u_##mlt_size tableRow_t;                                       \
+        typedef NFAException##mlt_size exception_t;                            \
+        static const size_t maxStates = mlt_size;                              \
+    };
+
+MAKE_LIMEX_TRAITS(32)
+MAKE_LIMEX_TRAITS(128)
+MAKE_LIMEX_TRAITS(256)
+MAKE_LIMEX_TRAITS(384)
+MAKE_LIMEX_TRAITS(512)
 
 } // namespace
 
index 084f35dd1c823c0eb71e3dd159b47f37ad1632f7..8e1ee219c86a41e1be3657d99ad92b7f8bf6c881 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2016, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -244,6 +244,16 @@ void dumpLimexExceptions(const limex_type *limex, FILE *f) {
     }
 }
 
+template<typename limex_type>
+static
+void dumpLimexShifts(const limex_type *limex, FILE *f) {
+    u32 size = limex_traits<limex_type>::size;
+    fprintf(f, "Shift Masks:\n");
+    for(u32 i = 0; i < limex->shiftCount; i++) {
+        fprintf(f, "\t Shift %u(%hhu)\t\tMask: %s\n", i, limex->shiftAmount[i],
+                dumpMask((const u8 *)&limex->shift[i], size).c_str());
+    }
+}
 template<typename limex_type>
 static
 void dumpLimexText(const limex_type *limex, FILE *f) {
@@ -270,6 +280,9 @@ void dumpLimexText(const limex_type *limex, FILE *f) {
         topMask += size / 8;
     }
 
+    // Dump shift masks
+    dumpLimexShifts(limex, f);
+
     dumpSquash(limex, f);
 
     dumpLimexReachMap(limex->reachMap, f);
@@ -420,78 +433,44 @@ void dumpExDotInfo(const limex_type *limex, u32 state, FILE *f) {
 template<typename limex_type>
 static
 void dumpLimDotInfo(const limex_type *limex, u32 state, FILE *f) {
-    for (u32 j = 0; j < MAX_MAX_SHIFT; j++) {
+    for (u32 j = 0; j < limex->shiftCount; j++) {
+        const u32 shift_amount = limex->shiftAmount[j];
         if (testbit((const u8 *)&limex->shift[j],
                     limex_traits<limex_type>::size, state)) {
-            fprintf(f, "%u -> %u;\n", state, state + j);
+            fprintf(f, "%u -> %u;\n", state, state + shift_amount);
         }
     }
 }
 
-#define DUMP_TEXT_FN(ddf_u, ddf_n, ddf_s)                                      \
-    void nfaExecLimEx##ddf_n##_##ddf_s##_dumpText(const NFA *nfa, FILE *f) {   \
+#define DUMP_TEXT_FN(ddf_n)                                                    \
+    void nfaExecLimEx##ddf_n##_dumpText(const NFA *nfa, FILE *f) {             \
         dumpLimexText((const LimExNFA##ddf_n *)getImplNfa(nfa), f);            \
     }
 
-#define DUMP_DOT_FN(ddf_u, ddf_n, ddf_s)                                       \
-    void nfaExecLimEx##ddf_n##_##ddf_s##_dumpDot(const NFA *nfa, FILE *f) {    \
+#define DUMP_DOT_FN(ddf_n)                                                     \
+    void nfaExecLimEx##ddf_n##_dumpDot(const NFA *nfa, FILE *f) {              \
         const LimExNFA##ddf_n *limex =                                         \
             (const LimExNFA##ddf_n *)getImplNfa(nfa);                          \
                                                                                \
         dumpDotPreamble(f);                                                    \
-        u32 state_count = nfa->nPositions;                              \
+        u32 state_count = nfa->nPositions;                                     \
         dumpVertexDotInfo(limex, state_count, f,                               \
                           limex_labeller<LimExNFA##ddf_n>(limex));             \
         for (u32 i = 0; i < state_count; i++) {                                \
             dumpLimDotInfo(limex, i, f);                                       \
             dumpExDotInfo(limex, i, f);                                        \
         }                                                                      \
-                                                                               \
         dumpDotTrailer(f);                                                     \
     }
 
-#define LIMEX_DUMP_FNS(ntype, size, shifts)                                    \
-    DUMP_TEXT_FN(ntype, size, shifts)                                          \
-    DUMP_DOT_FN(ntype, size, shifts)
-
-LIMEX_DUMP_FNS(u32, 32, 1)
-LIMEX_DUMP_FNS(u32, 32, 2)
-LIMEX_DUMP_FNS(u32, 32, 3)
-LIMEX_DUMP_FNS(u32, 32, 4)
-LIMEX_DUMP_FNS(u32, 32, 5)
-LIMEX_DUMP_FNS(u32, 32, 6)
-LIMEX_DUMP_FNS(u32, 32, 7)
-
-LIMEX_DUMP_FNS(m128, 128, 1)
-LIMEX_DUMP_FNS(m128, 128, 2)
-LIMEX_DUMP_FNS(m128, 128, 3)
-LIMEX_DUMP_FNS(m128, 128, 4)
-LIMEX_DUMP_FNS(m128, 128, 5)
-LIMEX_DUMP_FNS(m128, 128, 6)
-LIMEX_DUMP_FNS(m128, 128, 7)
-
-LIMEX_DUMP_FNS(m256, 256, 1)
-LIMEX_DUMP_FNS(m256, 256, 2)
-LIMEX_DUMP_FNS(m256, 256, 3)
-LIMEX_DUMP_FNS(m256, 256, 4)
-LIMEX_DUMP_FNS(m256, 256, 5)
-LIMEX_DUMP_FNS(m256, 256, 6)
-LIMEX_DUMP_FNS(m256, 256, 7)
-
-LIMEX_DUMP_FNS(m384, 384, 1)
-LIMEX_DUMP_FNS(m384, 384, 2)
-LIMEX_DUMP_FNS(m384, 384, 3)
-LIMEX_DUMP_FNS(m384, 384, 4)
-LIMEX_DUMP_FNS(m384, 384, 5)
-LIMEX_DUMP_FNS(m384, 384, 6)
-LIMEX_DUMP_FNS(m384, 384, 7)
-
-LIMEX_DUMP_FNS(m512, 512, 1)
-LIMEX_DUMP_FNS(m512, 512, 2)
-LIMEX_DUMP_FNS(m512, 512, 3)
-LIMEX_DUMP_FNS(m512, 512, 4)
-LIMEX_DUMP_FNS(m512, 512, 5)
-LIMEX_DUMP_FNS(m512, 512, 6)
-LIMEX_DUMP_FNS(m512, 512, 7)
+#define LIMEX_DUMP_FNS(size)                                                   \
+    DUMP_TEXT_FN(size)                                                         \
+    DUMP_DOT_FN(size)
+
+LIMEX_DUMP_FNS(32)
+LIMEX_DUMP_FNS(128)
+LIMEX_DUMP_FNS(256)
+LIMEX_DUMP_FNS(384)
+LIMEX_DUMP_FNS(512)
 
 } // namespace ue2
index adae6ab7c6410f706d3e05c2a1a5850ea3ad4340..1483a9114839c713f827723ebe808f61438b091c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2016, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -68,6 +68,9 @@
     The value of NFA.stateSize gives the total state size in bytes (the sum of
     all the above).
 
+    Number of shifts should be always greater or equal to 1
+    Number of shifts 0 means that no appropriate NFA engine was found.
+
 */
 
 #ifndef LIMEX_INTERNAL_H
@@ -77,7 +80,8 @@
 #include "repeat_internal.h"
 
 // Constants
-#define MAX_MAX_SHIFT 8      /**< largest maxshift used by a LimEx NFA */
+#define MAX_SHIFT_COUNT 8   /**< largest number of shifts used by a LimEx NFA */
+#define MAX_SHIFT_AMOUNT 16 /**< largest shift amount used by a LimEx NFA */
 
 #define LIMEX_FLAG_COMPRESS_STATE  1 /**< pack state into stream state */
 #define LIMEX_FLAG_COMPRESS_MASKED 2 /**< use reach mask-based compression */
@@ -168,8 +172,10 @@ struct LimExNFA##size { /* MUST align with LimExNFABase */                  \
     u_##size compressMask; /**< switch off before compress */               \
     u_##size exceptionMask;                                                 \
     u_##size repeatCyclicMask;                                              \
-    u_##size shift[MAX_MAX_SHIFT];                                          \
     u_##size zombieMask; /**< zombie if in any of the set states */         \
+    u_##size shift[MAX_SHIFT_COUNT];                                        \
+    u32 shiftCount; /**< number of shift masks used */                      \
+    u8 shiftAmount[MAX_SHIFT_COUNT]; /**< shift amount for each mask */     \
 };
 
 CREATE_NFA_LIMEX(32)
index 471e4bf0a48c4c9f31542ef91f517295a0482348..e156cb81385fb460689b4ba3f39298f249708905 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2016, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -132,35 +132,4 @@ int processExceptional32(u32 s, u32 estate, UNUSED u32 diffmask, u32 *succ,
 
 #define SIZE                32
 #define STATE_T             u32
-#define SHIFT               1
-#include "limex_runtime_impl.h"
-
-#define SIZE                32
-#define STATE_T             u32
-#define SHIFT               2
-#include "limex_runtime_impl.h"
-
-#define SIZE                32
-#define STATE_T             u32
-#define SHIFT               3
-#include "limex_runtime_impl.h"
-
-#define SIZE                32
-#define STATE_T             u32
-#define SHIFT               4
-#include "limex_runtime_impl.h"
-
-#define SIZE                32
-#define STATE_T             u32
-#define SHIFT               5
-#include "limex_runtime_impl.h"
-
-#define SIZE                32
-#define STATE_T             u32
-#define SHIFT               6
-#include "limex_runtime_impl.h"
-
-#define SIZE                32
-#define STATE_T             u32
-#define SHIFT               7
 #include "limex_runtime_impl.h"
index 4e111aa623475946427dd0701cbeeb45794c0375..778d376df6dfe4db2ce3f3d1457f247089a125b0 100644 (file)
@@ -73,34 +73,35 @@ struct proto_cache {
 };
 
 // Shift macros for Limited NFAs. Defined in terms of uniform ops.
+// LimExNFAxxx ptr in 'limex' and the current state in 's'
 #define NFA_EXEC_LIM_SHIFT(nels_type, nels_i)                                  \
     (JOIN(shift_, nels_type)(                                                  \
         JOIN(and_, nels_type)(s,                                               \
                               JOIN(load_, nels_type)(&limex->shift[nels_i])),  \
-        nels_i))
+        limex->shiftAmount[nels_i]))
 
-// Calculate the (limited model) successors for a given max shift. Assumes
-// LimExNFAxxx ptr in 'l', current state in 's' and successors in 'succ'.
+// Calculate the (limited model) successors for a number of variable shifts.
+// Assumes current state in 's' and successors in 'succ'.
 
-#define NFA_EXEC_GET_LIM_SUCC(gls_type, gls_shift)                             \
+#define NFA_EXEC_GET_LIM_SUCC(gls_type)                                        \
     do {                                                                       \
-        succ =                                                                 \
-            JOIN(and_, gls_type)(s, JOIN(load_, gls_type)(&limex->shift[0]));  \
-        switch (gls_shift) {                                                   \
-        case 7:                                                                \
+        succ = NFA_EXEC_LIM_SHIFT(gls_type, 0);                                \
+        switch (limex->shiftCount) {                                           \
+        case 8:                                                                \
             succ = JOIN(or_, gls_type)(succ, NFA_EXEC_LIM_SHIFT(gls_type, 7)); \
-        case 6:                                                                \
+        case 7:                                                                \
             succ = JOIN(or_, gls_type)(succ, NFA_EXEC_LIM_SHIFT(gls_type, 6)); \
-        case 5:                                                                \
+        case 6:                                                                \
             succ = JOIN(or_, gls_type)(succ, NFA_EXEC_LIM_SHIFT(gls_type, 5)); \
-        case 4:                                                                \
+        case 5:                                                                \
             succ = JOIN(or_, gls_type)(succ, NFA_EXEC_LIM_SHIFT(gls_type, 4)); \
-        case 3:                                                                \
+        case 4:                                                                \
             succ = JOIN(or_, gls_type)(succ, NFA_EXEC_LIM_SHIFT(gls_type, 3)); \
-        case 2:                                                                \
+        case 3:                                                                \
             succ = JOIN(or_, gls_type)(succ, NFA_EXEC_LIM_SHIFT(gls_type, 2)); \
-        case 1:                                                                \
+        case 2:                                                                \
             succ = JOIN(or_, gls_type)(succ, NFA_EXEC_LIM_SHIFT(gls_type, 1)); \
+        case 1:                                                                \
         case 0:                                                                \
             ;                                                                  \
         }                                                                      \
index 676ed3700c11cece2d95084c3d7dd64e9ed2a87a..9924ef8c0a64bfea68b7f8961e23ae6ef995e8a8 100644 (file)
   * Version 2.0: now with X-Macros, so you get line numbers in your debugger.
   */
 
-#if !defined(SIZE) || !defined(STATE_T) || !defined(SHIFT)
-#  error Must define SIZE and STATE_T and SHIFT in includer.
+#if !defined(SIZE) || !defined(STATE_T)
+#  error Must define SIZE and STATE_T in includer.
 #endif
 
-#define LIMEX_API_ROOT   JOIN(JOIN(JOIN(nfaExecLimEx, SIZE), _), SHIFT)
+#define LIMEX_API_ROOT   JOIN(nfaExecLimEx, SIZE)
 
 #define IMPL_NFA_T          JOIN(struct LimExNFA, SIZE)
 
@@ -201,7 +201,7 @@ without_accel:
 
         u8 c = input[i];
         STATE_T succ;
-        NFA_EXEC_GET_LIM_SUCC(STATE_T, SHIFT);
+        NFA_EXEC_GET_LIM_SUCC(STATE_T);
 
         if (RUN_EXCEPTIONS_FN(limex, exceptions, exReports, exceptionMap, s,
                               EXCEPTION_MASK, i, offset, &succ, final_loc, ctx,
@@ -252,7 +252,7 @@ with_accel:
 
         u8 c = input[i];
         STATE_T succ;
-        NFA_EXEC_GET_LIM_SUCC(STATE_T, SHIFT);
+        NFA_EXEC_GET_LIM_SUCC(STATE_T);
 
         if (RUN_EXCEPTIONS_FN(limex, exceptions, exReports, exceptionMap, s,
                               EXCEPTION_MASK, i, offset, &succ, final_loc, ctx,
@@ -318,7 +318,7 @@ char REV_STREAM_FN(const IMPL_NFA_T *limex, const u8 *input, size_t length,
 
         u8 c = input[i-1];
         STATE_T succ;
-        NFA_EXEC_GET_LIM_SUCC(STATE_T, SHIFT);
+        NFA_EXEC_GET_LIM_SUCC(STATE_T);
 
         if (RUN_EXCEPTIONS_FN(limex, exceptions, exReports, exceptionMap, s,
                               EXCEPTION_MASK, i, offset, &succ, final_loc, ctx,
@@ -935,5 +935,4 @@ enum nfa_zombie_status JOIN(LIMEX_API_ROOT, _zombie_status)(
 // Parameters.
 #undef SIZE
 #undef STATE_T
-#undef SHIFT
 #undef LIMEX_API_ROOT
index 781c79721eba03eb7a653fb47b3525aa64a051e2..f0fb1dd466659ccfd1dd5f671e1a917ccead788a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2016, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
 #define INLINE_ATTR really_inline
 #include "limex_common_impl.h"
 
-#define SIZE                128
-#define STATE_T             m128
-#define SHIFT               1
-#include "limex_runtime_impl.h"
-
-#define SIZE                128
-#define STATE_T             m128
-#define SHIFT               2
-#include "limex_runtime_impl.h"
-
-#define SIZE                128
-#define STATE_T             m128
-#define SHIFT               3
-#include "limex_runtime_impl.h"
-
-#define SIZE                128
-#define STATE_T             m128
-#define SHIFT               4
-#include "limex_runtime_impl.h"
-
-#define SIZE                128
-#define STATE_T             m128
-#define SHIFT               5
-#include "limex_runtime_impl.h"
-
-#define SIZE                128
-#define STATE_T             m128
-#define SHIFT               6
-#include "limex_runtime_impl.h"
-
-#define SIZE                128
-#define STATE_T             m128
-#define SHIFT               7
+#define SIZE 128
+#define STATE_T m128
 #include "limex_runtime_impl.h"
index b4df1459557f987c49774a40b8913f531cfdc7d4..57648b69c539d88c7d89fb9762eb8eaf75587181 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2016, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
 #define INLINE_ATTR really_inline
 #include "limex_common_impl.h"
 
-#define SIZE                256
-#define STATE_T             m256
-#define SHIFT               1
-#include "limex_runtime_impl.h"
-
-#define SIZE                256
-#define STATE_T             m256
-#define SHIFT               2
-#include "limex_runtime_impl.h"
-
-#define SIZE                256
-#define STATE_T             m256
-#define SHIFT               3
-#include "limex_runtime_impl.h"
-
-#define SIZE                256
-#define STATE_T             m256
-#define SHIFT               4
-#include "limex_runtime_impl.h"
-
-#define SIZE                256
-#define STATE_T             m256
-#define SHIFT               5
-#include "limex_runtime_impl.h"
-
-#define SIZE                256
-#define STATE_T             m256
-#define SHIFT               6
-#include "limex_runtime_impl.h"
-
-#define SIZE                256
-#define STATE_T             m256
-#define SHIFT               7
+#define SIZE 256
+#define STATE_T m256
 #include "limex_runtime_impl.h"
index 4b4b44bbd4f0fc16b42f5cb9dc7df65db7810be7..84061f61dcfec48a23b43ab63619be5ea185000e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2016, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
 #define INLINE_ATTR really_inline
 #include "limex_common_impl.h"
 
-#define SIZE                384
-#define STATE_T             m384
-#define SHIFT               1
-#include "limex_runtime_impl.h"
-
-#define SIZE                384
-#define STATE_T             m384
-#define SHIFT               2
-#include "limex_runtime_impl.h"
-
-#define SIZE                384
-#define STATE_T             m384
-#define SHIFT               3
-#include "limex_runtime_impl.h"
-
-#define SIZE                384
-#define STATE_T             m384
-#define SHIFT               4
-#include "limex_runtime_impl.h"
-
-#define SIZE                384
-#define STATE_T             m384
-#define SHIFT               5
-#include "limex_runtime_impl.h"
-
-#define SIZE                384
-#define STATE_T             m384
-#define SHIFT               6
-#include "limex_runtime_impl.h"
-
-#define SIZE                384
-#define STATE_T             m384
-#define SHIFT               7
+#define SIZE 384
+#define STATE_T m384
 #include "limex_runtime_impl.h"
similarity index 88%
rename from src/nfa/limex_simd512b.c
rename to src/nfa/limex_simd512.c
index a3b705dfdfb3726752129620f63de266ee642c6f..a6646d83801ce3439fe6823f191f9114eed8f271 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2016, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
 #define INLINE_ATTR really_inline
 #include "limex_common_impl.h"
 
-#define SIZE                512
-#define STATE_T             m512
-#define SHIFT               4
-#include "limex_runtime_impl.h"
-
-#define SIZE                512
-#define STATE_T             m512
-#define SHIFT               5
+#define SIZE 512
+#define STATE_T m512
 #include "limex_runtime_impl.h"
diff --git a/src/nfa/limex_simd512a.c b/src/nfa/limex_simd512a.c
deleted file mode 100644 (file)
index 1c4a0fb..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2015, Intel Corporation
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *  * Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *  * Neither the name of Intel Corporation nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** \file
- * \brief LimEx NFA: 512-bit SIMD runtime implementations.
- */
-
-//#define DEBUG_INPUT
-//#define DEBUG_EXCEPTIONS
-
-#include "limex.h"
-
-#include "accel.h"
-#include "limex_internal.h"
-#include "nfa_internal.h"
-#include "ue2common.h"
-#include "util/bitutils.h"
-#include "util/simd_utils.h"
-
-// Common code
-#include "limex_runtime.h"
-
-#define SIZE 512
-#define STATE_T m512
-#include "limex_exceptional.h"
-
-#define SIZE 512
-#define STATE_T m512
-#include "limex_state_impl.h"
-
-#define SIZE 512
-#define STATE_T m512
-#define INLINE_ATTR really_inline
-#include "limex_common_impl.h"
-
-#define SIZE                512
-#define STATE_T             m512
-#define SHIFT               2
-#include "limex_runtime_impl.h"
-
-#define SIZE                512
-#define STATE_T             m512
-#define SHIFT               1
-#include "limex_runtime_impl.h"
-
-#define SIZE                512
-#define STATE_T             m512
-#define SHIFT               3
-#include "limex_runtime_impl.h"
diff --git a/src/nfa/limex_simd512c.c b/src/nfa/limex_simd512c.c
deleted file mode 100644 (file)
index 0918fca..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2015, Intel Corporation
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *  * Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *  * Neither the name of Intel Corporation nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** \file
- * \brief LimEx NFA: 512-bit SIMD runtime implementations.
- */
-
-//#define DEBUG_INPUT
-//#define DEBUG_EXCEPTIONS
-
-#include "limex.h"
-
-#include "accel.h"
-#include "limex_internal.h"
-#include "nfa_internal.h"
-#include "ue2common.h"
-#include "util/bitutils.h"
-#include "util/simd_utils.h"
-
-// Common code
-#include "limex_runtime.h"
-
-#define SIZE 512
-#define STATE_T m512
-#include "limex_exceptional.h"
-
-#define SIZE 512
-#define STATE_T m512
-#include "limex_state_impl.h"
-
-#define SIZE 512
-#define STATE_T m512
-#define INLINE_ATTR really_inline
-#include "limex_common_impl.h"
-
-#define SIZE                512
-#define STATE_T             m512
-#define SHIFT               6
-#include "limex_runtime_impl.h"
-
-#define SIZE                512
-#define STATE_T             m512
-#define SHIFT               7
-#include "limex_runtime_impl.h"
index fb27e4ebb43ddcbdbb0ca4663533d4529f1974d9..95b1898e6c8d4445897f06001e4a82936fdadb57 100644 (file)
 
 #define DISPATCH_BY_NFA_TYPE(dbnt_func)                       \
     switch (nfa->type) {                                      \
-        DISPATCH_CASE(LIMEX,   LimEx,   32_1, dbnt_func);     \
-        DISPATCH_CASE(LIMEX,   LimEx,   32_2, dbnt_func);     \
-        DISPATCH_CASE(LIMEX,   LimEx,   32_3, dbnt_func);     \
-        DISPATCH_CASE(LIMEX,   LimEx,   32_4, dbnt_func);     \
-        DISPATCH_CASE(LIMEX,   LimEx,   32_5, dbnt_func);     \
-        DISPATCH_CASE(LIMEX,   LimEx,   32_6, dbnt_func);     \
-        DISPATCH_CASE(LIMEX,   LimEx,   32_7, dbnt_func);     \
-        DISPATCH_CASE(LIMEX,   LimEx,   128_1, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   128_2, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   128_3, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   128_4, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   128_5, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   128_6, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   128_7, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   256_1, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   256_2, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   256_3, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   256_4, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   256_5, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   256_6, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   256_7, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   384_1, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   384_2, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   384_3, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   384_4, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   384_5, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   384_6, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   384_7, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   512_1, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   512_2, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   512_3, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   512_4, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   512_5, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   512_6, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   512_7, dbnt_func);    \
+        DISPATCH_CASE(LIMEX, LimEx, 32, dbnt_func);           \
+        DISPATCH_CASE(LIMEX, LimEx, 128, dbnt_func);          \
+        DISPATCH_CASE(LIMEX, LimEx, 256, dbnt_func);          \
+        DISPATCH_CASE(LIMEX, LimEx, 384, dbnt_func);          \
+        DISPATCH_CASE(LIMEX, LimEx, 512, dbnt_func);          \
         DISPATCH_CASE(MCCLELLAN, McClellan, 8, dbnt_func);    \
         DISPATCH_CASE(MCCLELLAN, McClellan, 16, dbnt_func);   \
         DISPATCH_CASE(GOUGH, Gough, 8, dbnt_func);            \
index 2ac0505ecf4a1726d4cbebe529ac015b5264eda1..96d0dabe66350032f8cbd2592560ce7951372fbd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2016, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -140,8 +140,8 @@ enum NFACategory {NFA_LIMEX, NFA_OTHER};
 #define DO_IF_DUMP_SUPPORT(a)
 #endif
 
-#define MAKE_LIMEX_TRAITS(mlt_size, mlt_shift)                          \
-    template<> struct NFATraits<LIMEX_NFA_##mlt_size##_##mlt_shift> {   \
+#define MAKE_LIMEX_TRAITS(mlt_size)                                     \
+    template<> struct NFATraits<LIMEX_NFA_##mlt_size> {                 \
         static UNUSED const char *name;                                 \
         static const NFACategory category = NFA_LIMEX;                  \
         typedef LimExNFA##mlt_size implNFA_t;                           \
@@ -151,52 +151,22 @@ enum NFACategory {NFA_LIMEX, NFA_OTHER};
                 MAX(alignof(tableRow_t), alignof(RepeatControl));       \
         static const bool fast = mlt_size <= 64;                        \
     };                                                                  \
-    const has_accel_fn NFATraits<LIMEX_NFA_##mlt_size##_##mlt_shift>::has_accel \
+    const has_accel_fn NFATraits<LIMEX_NFA_##mlt_size>::has_accel       \
             = has_accel_limex<LimExNFA##mlt_size>;                      \
     DO_IF_DUMP_SUPPORT(                                                 \
-    const char *NFATraits<LIMEX_NFA_##mlt_size##_##mlt_shift>::name     \
-        = "LimEx (0-"#mlt_shift") "#mlt_size;                           \
-    template<> struct getDescription<LIMEX_NFA_##mlt_size##_##mlt_shift> { \
-        static string call(const void *ptr) {                            \
-            return getDescriptionLimEx<LIMEX_NFA_##mlt_size##_##mlt_shift>((const NFA *)ptr); \
+    const char *NFATraits<LIMEX_NFA_##mlt_size>::name                   \
+        = "LimEx "#mlt_size;                                            \
+    template<> struct getDescription<LIMEX_NFA_##mlt_size> {            \
+        static string call(const void *ptr) {                           \
+            return getDescriptionLimEx<LIMEX_NFA_##mlt_size>((const NFA *)ptr); \
         } \
     };)
 
-MAKE_LIMEX_TRAITS(32, 1)
-MAKE_LIMEX_TRAITS(32, 2)
-MAKE_LIMEX_TRAITS(32, 3)
-MAKE_LIMEX_TRAITS(32, 4)
-MAKE_LIMEX_TRAITS(32, 5)
-MAKE_LIMEX_TRAITS(32, 6)
-MAKE_LIMEX_TRAITS(32, 7)
-MAKE_LIMEX_TRAITS(128, 1)
-MAKE_LIMEX_TRAITS(128, 2)
-MAKE_LIMEX_TRAITS(128, 3)
-MAKE_LIMEX_TRAITS(128, 4)
-MAKE_LIMEX_TRAITS(128, 5)
-MAKE_LIMEX_TRAITS(128, 6)
-MAKE_LIMEX_TRAITS(128, 7)
-MAKE_LIMEX_TRAITS(256, 1)
-MAKE_LIMEX_TRAITS(256, 2)
-MAKE_LIMEX_TRAITS(256, 3)
-MAKE_LIMEX_TRAITS(256, 4)
-MAKE_LIMEX_TRAITS(256, 5)
-MAKE_LIMEX_TRAITS(256, 6)
-MAKE_LIMEX_TRAITS(256, 7)
-MAKE_LIMEX_TRAITS(384, 1)
-MAKE_LIMEX_TRAITS(384, 2)
-MAKE_LIMEX_TRAITS(384, 3)
-MAKE_LIMEX_TRAITS(384, 4)
-MAKE_LIMEX_TRAITS(384, 5)
-MAKE_LIMEX_TRAITS(384, 6)
-MAKE_LIMEX_TRAITS(384, 7)
-MAKE_LIMEX_TRAITS(512, 1)
-MAKE_LIMEX_TRAITS(512, 2)
-MAKE_LIMEX_TRAITS(512, 3)
-MAKE_LIMEX_TRAITS(512, 4)
-MAKE_LIMEX_TRAITS(512, 5)
-MAKE_LIMEX_TRAITS(512, 6)
-MAKE_LIMEX_TRAITS(512, 7)
+MAKE_LIMEX_TRAITS(32)
+MAKE_LIMEX_TRAITS(128)
+MAKE_LIMEX_TRAITS(256)
+MAKE_LIMEX_TRAITS(384)
+MAKE_LIMEX_TRAITS(512)
 
 template<> struct NFATraits<MCCLELLAN_NFA_8> {
     UNUSED static const char *name;
index 4a59dc1e00d0e431c0020b32cbc4afadd7e98b0b..577c2fd001a1ef6eaed6afca13147d69c1edef1e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2016, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -57,41 +57,11 @@ namespace ue2 {
 #define DISPATCH_BY_NFA_TYPE(dbnt_func)                       \
     DEBUG_PRINTF("dispatch for NFA type %u\n", nfa->type);    \
     switch (nfa->type) {                                      \
-        DISPATCH_CASE(LIMEX,   LimEx,   32_1, dbnt_func);     \
-        DISPATCH_CASE(LIMEX,   LimEx,   32_2, dbnt_func);     \
-        DISPATCH_CASE(LIMEX,   LimEx,   32_3, dbnt_func);     \
-        DISPATCH_CASE(LIMEX,   LimEx,   32_4, dbnt_func);     \
-        DISPATCH_CASE(LIMEX,   LimEx,   32_5, dbnt_func);     \
-        DISPATCH_CASE(LIMEX,   LimEx,   32_6, dbnt_func);     \
-        DISPATCH_CASE(LIMEX,   LimEx,   32_7, dbnt_func);     \
-        DISPATCH_CASE(LIMEX,   LimEx,   128_1, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   128_2, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   128_3, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   128_4, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   128_5, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   128_6, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   128_7, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   256_1, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   256_2, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   256_3, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   256_4, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   256_5, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   256_6, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   256_7, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   384_1, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   384_2, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   384_3, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   384_4, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   384_5, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   384_6, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   384_7, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   512_1, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   512_2, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   512_3, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   512_4, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   512_5, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   512_6, dbnt_func);    \
-        DISPATCH_CASE(LIMEX,   LimEx,   512_7, dbnt_func);    \
+        DISPATCH_CASE(LIMEX, LimEx, 32, dbnt_func);           \
+        DISPATCH_CASE(LIMEX, LimEx, 128, dbnt_func);          \
+        DISPATCH_CASE(LIMEX, LimEx, 256, dbnt_func);          \
+        DISPATCH_CASE(LIMEX, LimEx, 384, dbnt_func);          \
+        DISPATCH_CASE(LIMEX, LimEx, 512, dbnt_func);          \
         DISPATCH_CASE(MCCLELLAN, McClellan, 8, dbnt_func);    \
         DISPATCH_CASE(MCCLELLAN, McClellan, 16, dbnt_func);   \
         DISPATCH_CASE(GOUGH, Gough, 8, dbnt_func);            \
index 089e96838b697a276b9b5c5c4f11ef323bf590f8..d0a4ca0b4107015cc26599705f957f0b46a62d68 100644 (file)
@@ -51,41 +51,11 @@ extern "C"
 // Common data structures for NFAs
 
 enum NFAEngineType {
-    LIMEX_NFA_32_1,
-    LIMEX_NFA_32_2,
-    LIMEX_NFA_32_3,
-    LIMEX_NFA_32_4,
-    LIMEX_NFA_32_5,
-    LIMEX_NFA_32_6,
-    LIMEX_NFA_32_7,
-    LIMEX_NFA_128_1,
-    LIMEX_NFA_128_2,
-    LIMEX_NFA_128_3,
-    LIMEX_NFA_128_4,
-    LIMEX_NFA_128_5,
-    LIMEX_NFA_128_6,
-    LIMEX_NFA_128_7,
-    LIMEX_NFA_256_1,
-    LIMEX_NFA_256_2,
-    LIMEX_NFA_256_3,
-    LIMEX_NFA_256_4,
-    LIMEX_NFA_256_5,
-    LIMEX_NFA_256_6,
-    LIMEX_NFA_256_7,
-    LIMEX_NFA_384_1,
-    LIMEX_NFA_384_2,
-    LIMEX_NFA_384_3,
-    LIMEX_NFA_384_4,
-    LIMEX_NFA_384_5,
-    LIMEX_NFA_384_6,
-    LIMEX_NFA_384_7,
-    LIMEX_NFA_512_1,
-    LIMEX_NFA_512_2,
-    LIMEX_NFA_512_3,
-    LIMEX_NFA_512_4,
-    LIMEX_NFA_512_5,
-    LIMEX_NFA_512_6,
-    LIMEX_NFA_512_7,
+    LIMEX_NFA_32,
+    LIMEX_NFA_128,
+    LIMEX_NFA_256,
+    LIMEX_NFA_384,
+    LIMEX_NFA_512,
     MCCLELLAN_NFA_8,    /**< magic pseudo nfa */
     MCCLELLAN_NFA_16,   /**< magic pseudo nfa */
     GOUGH_NFA_8,        /**< magic pseudo nfa */
@@ -184,41 +154,11 @@ static really_inline int isDfaType(u8 t) {
 /** \brief True if the given type (from NFA::type) is an NFA. */
 static really_inline int isNfaType(u8 t) {
     switch (t) {
-    case LIMEX_NFA_32_1:
-    case LIMEX_NFA_32_2:
-    case LIMEX_NFA_32_3:
-    case LIMEX_NFA_32_4:
-    case LIMEX_NFA_32_5:
-    case LIMEX_NFA_32_6:
-    case LIMEX_NFA_32_7:
-    case LIMEX_NFA_128_1:
-    case LIMEX_NFA_128_2:
-    case LIMEX_NFA_128_3:
-    case LIMEX_NFA_128_4:
-    case LIMEX_NFA_128_5:
-    case LIMEX_NFA_128_6:
-    case LIMEX_NFA_128_7:
-    case LIMEX_NFA_256_1:
-    case LIMEX_NFA_256_2:
-    case LIMEX_NFA_256_3:
-    case LIMEX_NFA_256_4:
-    case LIMEX_NFA_256_5:
-    case LIMEX_NFA_256_6:
-    case LIMEX_NFA_256_7:
-    case LIMEX_NFA_384_1:
-    case LIMEX_NFA_384_2:
-    case LIMEX_NFA_384_3:
-    case LIMEX_NFA_384_4:
-    case LIMEX_NFA_384_5:
-    case LIMEX_NFA_384_6:
-    case LIMEX_NFA_384_7:
-    case LIMEX_NFA_512_1:
-    case LIMEX_NFA_512_2:
-    case LIMEX_NFA_512_3:
-    case LIMEX_NFA_512_4:
-    case LIMEX_NFA_512_5:
-    case LIMEX_NFA_512_6:
-    case LIMEX_NFA_512_7:
+    case LIMEX_NFA_32:
+    case LIMEX_NFA_128:
+    case LIMEX_NFA_256:
+    case LIMEX_NFA_384:
+    case LIMEX_NFA_512:
         return 1;
     default:
         break;
index 9d3c00b5e6689f3a7df4f9e3589d84c2a5d79773..eb6ce08bce9d7228da8e43dd0b25e774a03c69ad 100644 (file)
@@ -130,7 +130,7 @@ protected:
 
 INSTANTIATE_TEST_CASE_P(
     LimEx, LimExModelTest,
-    Range((int)LIMEX_NFA_32_1, (int)LIMEX_NFA_512_7));
+    Range((int)LIMEX_NFA_32, (int)LIMEX_NFA_512));
 
 TEST_P(LimExModelTest, StateSize) {
     ASSERT_TRUE(nfa != nullptr);
@@ -337,7 +337,7 @@ protected:
 };
 
 INSTANTIATE_TEST_CASE_P(LimExReverse, LimExReverseTest,
-                        Range((int)LIMEX_NFA_32_1, (int)LIMEX_NFA_512_7));
+                        Range((int)LIMEX_NFA_32, (int)LIMEX_NFA_512));
 
 TEST_P(LimExReverseTest, BlockExecReverse) {
     ASSERT_TRUE(nfa != nullptr);
@@ -424,7 +424,7 @@ protected:
 };
 
 INSTANTIATE_TEST_CASE_P(LimExZombie, LimExZombieTest,
-                        Range((int)LIMEX_NFA_32_1, (int)LIMEX_NFA_512_7));
+                        Range((int)LIMEX_NFA_32, (int)LIMEX_NFA_512));
 
 TEST_P(LimExZombieTest, GetZombieStatus) {
     ASSERT_TRUE(nfa != nullptr);