diff --git a/CMakeLists.txt b/CMakeLists.txt index d49de277..2652cea3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/grey.cpp b/src/grey.cpp index e2022e74..1f2fd904 100644 --- a/src/grey.cpp +++ b/src/grey.cpp @@ -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); diff --git a/src/grey.h b/src/grey.h index 8ac9e6b1..634fa3a7 100644 --- a/src/grey.h +++ b/src/grey.h @@ -88,7 +88,6 @@ struct Grey { bool floodAsPuffette; u32 nfaForceSize; - u32 nfaForceShifts; u32 maxHistoryAvailable; u32 minHistoryAvailable; diff --git a/src/nfa/limex.h b/src/nfa/limex.h index 2c429a67..57ee46df 100644 --- a/src/nfa/limex.h +++ b/src/nfa/limex.h @@ -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 diff --git a/src/nfa/limex_compile.cpp b/src/nfa/limex_compile.cpp index 5d51feb9..563d6c9c 100644 --- a/src/nfa/limex_compile.cpp +++ b/src/nfa/limex_compile.cpp @@ -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 struct NFATraits { }; @@ -261,6 +261,17 @@ void maskSetBits(Mask &m, const NFAStateSet &bits) { } } +template +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 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 struct Factory { // typedefs for readability, for types derived from traits @@ -1322,25 +1422,6 @@ struct Factory { typedef typename NFATraits::implNFA_t implNFA_t; typedef typename NFATraits::tableRow_t tableRow_t; - static - bool isExceptionalTransition(const NGHolder &h, const NFAEdge &e, - const ue2::unordered_map &state_ids, - const ue2::unordered_set &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::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 &exceptional) { + ue2::unordered_set &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 exceptional; - findExceptionalTransitions(args, exceptional); + u32 shiftCount = findBestNumOfVarShifts(args); + assert(shiftCount); + u32 maxShift = findMaxVarShift(args, shiftCount); + findExceptionalTransitions(args, exceptional, maxShift); map > exceptionMap; vector 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::maxShift != args.cc.grey.nfaForceShifts) { - return -1; - } - if (sz != NFATraits::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::maxShift != 0) { - score -= SHIFT_COST / 2; // first shift mask is cheap - score -= SHIFT_COST * (NFATraits::maxShift - 1); + int score; + u32 shiftCount = findBestNumOfVarShifts(args, &score); + if (shiftCount == 0) { + return -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; - } - return score; } }; @@ -1985,50 +2060,19 @@ struct scoreNfa { } }; -#define MAKE_LIMEX_TRAITS(mlt_size, mlt_shift) \ - template<> struct NFATraits { \ - 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; \ - }; \ +#define MAKE_LIMEX_TRAITS(mlt_size) \ + template<> struct NFATraits { \ + 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, 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) } // namespace diff --git a/src/nfa/limex_dump.cpp b/src/nfa/limex_dump.cpp index 084f35dd..8e1ee219 100644 --- a/src/nfa/limex_dump.cpp +++ b/src/nfa/limex_dump.cpp @@ -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 +static +void dumpLimexShifts(const limex_type *limex, FILE *f) { + u32 size = limex_traits::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 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 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::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(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) +#define LIMEX_DUMP_FNS(size) \ + DUMP_TEXT_FN(size) \ + DUMP_DOT_FN(size) -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) +LIMEX_DUMP_FNS(32) +LIMEX_DUMP_FNS(128) +LIMEX_DUMP_FNS(256) +LIMEX_DUMP_FNS(384) +LIMEX_DUMP_FNS(512) } // namespace ue2 diff --git a/src/nfa/limex_internal.h b/src/nfa/limex_internal.h index adae6ab7..1483a911 100644 --- a/src/nfa/limex_internal.h +++ b/src/nfa/limex_internal.h @@ -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) diff --git a/src/nfa/limex_native.c b/src/nfa/limex_native.c index 471e4bf0..e156cb81 100644 --- a/src/nfa/limex_native.c +++ b/src/nfa/limex_native.c @@ -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" diff --git a/src/nfa/limex_runtime.h b/src/nfa/limex_runtime.h index 4e111aa6..778d376d 100644 --- a/src/nfa/limex_runtime.h +++ b/src/nfa/limex_runtime.h @@ -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: \ ; \ } \ diff --git a/src/nfa/limex_runtime_impl.h b/src/nfa/limex_runtime_impl.h index 676ed370..9924ef8c 100644 --- a/src/nfa/limex_runtime_impl.h +++ b/src/nfa/limex_runtime_impl.h @@ -37,11 +37,11 @@ * 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 diff --git a/src/nfa/limex_simd128.c b/src/nfa/limex_simd128.c index 781c7972..f0fb1dd4 100644 --- a/src/nfa/limex_simd128.c +++ b/src/nfa/limex_simd128.c @@ -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: @@ -61,37 +61,6 @@ #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" diff --git a/src/nfa/limex_simd256.c b/src/nfa/limex_simd256.c index b4df1459..57648b69 100644 --- a/src/nfa/limex_simd256.c +++ b/src/nfa/limex_simd256.c @@ -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: @@ -58,37 +58,6 @@ #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" diff --git a/src/nfa/limex_simd384.c b/src/nfa/limex_simd384.c index 4b4b44bb..84061f61 100644 --- a/src/nfa/limex_simd384.c +++ b/src/nfa/limex_simd384.c @@ -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: @@ -58,37 +58,6 @@ #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" diff --git a/src/nfa/limex_simd512b.c b/src/nfa/limex_simd512.c similarity index 88% rename from src/nfa/limex_simd512b.c rename to src/nfa/limex_simd512.c index a3b705df..a6646d83 100644 --- a/src/nfa/limex_simd512b.c +++ b/src/nfa/limex_simd512.c @@ -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: @@ -58,12 +58,6 @@ #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 index 1c4a0fb9..00000000 --- a/src/nfa/limex_simd512a.c +++ /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 index 0918fca5..00000000 --- a/src/nfa/limex_simd512c.c +++ /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" diff --git a/src/nfa/nfa_api_dispatch.c b/src/nfa/nfa_api_dispatch.c index fb27e4eb..95b1898e 100644 --- a/src/nfa/nfa_api_dispatch.c +++ b/src/nfa/nfa_api_dispatch.c @@ -52,41 +52,11 @@ #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); \ diff --git a/src/nfa/nfa_build_util.cpp b/src/nfa/nfa_build_util.cpp index 2ac0505e..96d0dabe 100644 --- a/src/nfa/nfa_build_util.cpp +++ b/src/nfa/nfa_build_util.cpp @@ -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 { \ +#define MAKE_LIMEX_TRAITS(mlt_size) \ + template<> struct NFATraits { \ 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::has_accel \ + const has_accel_fn NFATraits::has_accel \ = has_accel_limex; \ DO_IF_DUMP_SUPPORT( \ - const char *NFATraits::name \ - = "LimEx (0-"#mlt_shift") "#mlt_size; \ - template<> struct getDescription { \ - static string call(const void *ptr) { \ - return getDescriptionLimEx((const NFA *)ptr); \ + const char *NFATraits::name \ + = "LimEx "#mlt_size; \ + template<> struct getDescription { \ + static string call(const void *ptr) { \ + return getDescriptionLimEx((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 { UNUSED static const char *name; diff --git a/src/nfa/nfa_dump_dispatch.cpp b/src/nfa/nfa_dump_dispatch.cpp index 4a59dc1e..577c2fd0 100644 --- a/src/nfa/nfa_dump_dispatch.cpp +++ b/src/nfa/nfa_dump_dispatch.cpp @@ -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); \ diff --git a/src/nfa/nfa_internal.h b/src/nfa/nfa_internal.h index 089e9683..d0a4ca0b 100644 --- a/src/nfa/nfa_internal.h +++ b/src/nfa/nfa_internal.h @@ -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; diff --git a/unit/internal/limex_nfa.cpp b/unit/internal/limex_nfa.cpp index 9d3c00b5..eb6ce08b 100644 --- a/unit/internal/limex_nfa.cpp +++ b/unit/internal/limex_nfa.cpp @@ -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);