limex: implement variable shift NFA engines

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.
This commit is contained in:
Kirill Rybalchenko 2016-04-21 16:52:43 +01:00 committed by Matthew Barr
parent cdaf705a87
commit 9d2403e8bb
21 changed files with 264 additions and 693 deletions

View File

@ -438,9 +438,7 @@ set (hs_exec_SRCS
src/nfa/limex_simd128.c src/nfa/limex_simd128.c
src/nfa/limex_simd256.c src/nfa/limex_simd256.c
src/nfa/limex_simd384.c src/nfa/limex_simd384.c
src/nfa/limex_simd512a.c src/nfa/limex_simd512.c
src/nfa/limex_simd512b.c
src/nfa/limex_simd512c.c
src/nfa/limex.h src/nfa/limex.h
src/nfa/limex_common_impl.h src/nfa/limex_common_impl.h
src/nfa/limex_context.h src/nfa/limex_context.h

View File

@ -81,7 +81,6 @@ Grey::Grey(void) :
allowZombies(true), allowZombies(true),
floodAsPuffette(false), floodAsPuffette(false),
nfaForceSize(0), nfaForceSize(0),
nfaForceShifts(0),
maxHistoryAvailable(DEFAULT_MAX_HISTORY), maxHistoryAvailable(DEFAULT_MAX_HISTORY),
minHistoryAvailable(0), /* debugging only */ minHistoryAvailable(0), /* debugging only */
maxAnchoredRegion(63), /* for rose's atable to run over */ 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(allowZombies);
G_UPDATE(floodAsPuffette); G_UPDATE(floodAsPuffette);
G_UPDATE(nfaForceSize); G_UPDATE(nfaForceSize);
G_UPDATE(nfaForceShifts);
G_UPDATE(highlanderSquash); G_UPDATE(highlanderSquash);
G_UPDATE(maxHistoryAvailable); G_UPDATE(maxHistoryAvailable);
G_UPDATE(minHistoryAvailable); G_UPDATE(minHistoryAvailable);

View File

@ -88,7 +88,6 @@ struct Grey {
bool floodAsPuffette; bool floodAsPuffette;
u32 nfaForceSize; u32 nfaForceSize;
u32 nfaForceShifts;
u32 maxHistoryAvailable; u32 maxHistoryAvailable;
u32 minHistoryAvailable; u32 minHistoryAvailable;

View File

@ -74,41 +74,11 @@ extern "C"
struct mq *q, s64a loc); \ struct mq *q, s64a loc); \
GENERATE_NFA_DUMP_DECL(gf_name) GENERATE_NFA_DUMP_DECL(gf_name)
GENERATE_NFA_DECL(nfaExecLimEx32_1) GENERATE_NFA_DECL(nfaExecLimEx32)
GENERATE_NFA_DECL(nfaExecLimEx32_2) GENERATE_NFA_DECL(nfaExecLimEx128)
GENERATE_NFA_DECL(nfaExecLimEx32_3) GENERATE_NFA_DECL(nfaExecLimEx256)
GENERATE_NFA_DECL(nfaExecLimEx32_4) GENERATE_NFA_DECL(nfaExecLimEx384)
GENERATE_NFA_DECL(nfaExecLimEx32_5) GENERATE_NFA_DECL(nfaExecLimEx512)
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)
#undef GENERATE_NFA_DECL #undef GENERATE_NFA_DECL
#undef GENERATE_NFA_DUMP_DECL #undef GENERATE_NFA_DUMP_DECL

View File

@ -169,10 +169,10 @@ struct build_info {
// Constants for scoring mechanism // 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 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 const int EXCEPTION_COST = 4; // limex: per exception
template<NFAEngineType t> struct NFATraits { }; 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 // Sets an entire byte in a mask to the given value
template<class Mask> template<class Mask>
void maskSetByte(Mask &m, const unsigned int idx, const char val) { 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; 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> template<NFAEngineType dtype>
struct Factory { struct Factory {
// typedefs for readability, for types derived from traits // 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>::implNFA_t implNFA_t;
typedef typename NFATraits<dtype>::tableRow_t tableRow_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 static
void allocState(NFA *nfa, u32 repeatscratchStateSize, void allocState(NFA *nfa, u32 repeatscratchStateSize,
u32 repeatStreamState) { u32 repeatStreamState) {
@ -1504,6 +1585,9 @@ struct Factory {
static static
void writeShiftMasks(const build_info &args, implNFA_t *limex) { void writeShiftMasks(const build_info &args, implNFA_t *limex) {
const NGHolder &h = args.h; const NGHolder &h = args.h;
u32 maxShift = findMaxVarShift(args, limex->shiftCount);
u32 shiftMask = 0;
int shiftMaskIdx = 0;
for (const auto &e : edges_range(h)) { for (const auto &e : edges_range(h)) {
u32 from = args.state_ids.at(source(e, 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 // We check for exceptional transitions here, as we don't want tug
// trigger transitions emitted as limited transitions (even if they // trigger transitions emitted as limited transitions (even if they
// could be in this model). // could be in this model).
if (!isExceptionalTransition(h, e, args.state_ids, args.tugs)) { if (!isExceptionalTransition(h, e, args, maxShift)) {
maskSetBit(limex->shift[to - from], from); 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 static
void findExceptionalTransitions(const build_info &args, void findExceptionalTransitions(const build_info &args,
ue2::unordered_set<NFAEdge> &exceptional) { ue2::unordered_set<NFAEdge> &exceptional,
u32 maxShift) {
const NGHolder &h = args.h; const NGHolder &h = args.h;
for (const auto &e : edges_range(h)) { for (const auto &e : edges_range(h)) {
@ -1533,7 +1634,7 @@ struct Factory {
continue; continue;
} }
if (isExceptionalTransition(h, e, args.state_ids, args.tugs)) { if (isExceptionalTransition(h, e, args, maxShift)) {
exceptional.insert(e); exceptional.insert(e);
} }
} }
@ -1778,7 +1879,10 @@ struct Factory {
} }
ue2::unordered_set<NFAEdge> exceptional; 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; map<ExceptionProto, vector<u32> > exceptionMap;
vector<ReportID> exceptionReports; vector<ReportID> exceptionReports;
@ -1874,6 +1978,7 @@ struct Factory {
writeAccepts(acceptMask, acceptEodMask, accepts, acceptsEod, squash, writeAccepts(acceptMask, acceptEodMask, accepts, acceptsEod, squash,
limex, acceptsOffset, acceptsEodOffset, squashOffset); limex, acceptsOffset, acceptsEodOffset, squashOffset);
limex->shiftCount = shiftCount;
writeShiftMasks(args, limex); writeShiftMasks(args, limex);
// Determine the state required for our state vector. // Determine the state required for our state vector.
@ -1907,8 +2012,6 @@ struct Factory {
} }
static int score(const build_info &args) { static int score(const build_info &args) {
const NGHolder &h = args.h;
// LimEx NFAs are available in sizes from 32 to 512-bit. // LimEx NFAs are available in sizes from 32 to 512-bit.
size_t num_states = args.num_states; size_t num_states = args.num_states;
@ -1928,45 +2031,17 @@ struct Factory {
sz = args.cc.grey.nfaForceSize; sz = args.cc.grey.nfaForceSize;
} }
if (args.cc.grey.nfaForceShifts &&
NFATraits<dtype>::maxShift != args.cc.grey.nfaForceShifts) {
return -1;
}
if (sz != NFATraits<dtype>::maxStates) { if (sz != NFATraits<dtype>::maxStates) {
return -1; // fail, size not appropriate return -1; // fail, size not appropriate
} }
// We are of the right size, calculate a score based on the number // We are of the right size, calculate a score based on the number
// of exceptions and the number of shifts used by this LimEx. // of exceptions and the number of shifts used by this LimEx.
int score = LIMEX_INITIAL_SCORE; int score;
if (NFATraits<dtype>::maxShift != 0) { u32 shiftCount = findBestNumOfVarShifts(args, &score);
score -= SHIFT_COST / 2; // first shift mask is cheap if (shiftCount == 0) {
score -= SHIFT_COST * (NFATraits<dtype>::maxShift - 1); 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; return score;
} }
}; };
@ -1985,50 +2060,19 @@ struct scoreNfa {
} }
}; };
#define MAKE_LIMEX_TRAITS(mlt_size, mlt_shift) \ #define MAKE_LIMEX_TRAITS(mlt_size) \
template<> struct NFATraits<LIMEX_NFA_##mlt_size##_##mlt_shift> { \ template<> struct NFATraits<LIMEX_NFA_##mlt_size> { \
typedef LimExNFA##mlt_size implNFA_t; \ typedef LimExNFA##mlt_size implNFA_t; \
typedef u_##mlt_size tableRow_t; \ typedef u_##mlt_size tableRow_t; \
typedef NFAException##mlt_size exception_t; \ typedef NFAException##mlt_size exception_t; \
static const size_t maxStates = mlt_size; \ static const size_t maxStates = mlt_size; \
static const u32 maxShift = mlt_shift; \ };
}; \
MAKE_LIMEX_TRAITS(32, 1) MAKE_LIMEX_TRAITS(32)
MAKE_LIMEX_TRAITS(32, 2) MAKE_LIMEX_TRAITS(128)
MAKE_LIMEX_TRAITS(32, 3) MAKE_LIMEX_TRAITS(256)
MAKE_LIMEX_TRAITS(32, 4) MAKE_LIMEX_TRAITS(384)
MAKE_LIMEX_TRAITS(32, 5) MAKE_LIMEX_TRAITS(512)
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)
} // namespace } // namespace

View 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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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> template<typename limex_type>
static static
void dumpLimexText(const limex_type *limex, FILE *f) { void dumpLimexText(const limex_type *limex, FILE *f) {
@ -270,6 +280,9 @@ void dumpLimexText(const limex_type *limex, FILE *f) {
topMask += size / 8; topMask += size / 8;
} }
// Dump shift masks
dumpLimexShifts(limex, f);
dumpSquash(limex, f); dumpSquash(limex, f);
dumpLimexReachMap(limex->reachMap, f); dumpLimexReachMap(limex->reachMap, f);
@ -420,78 +433,44 @@ void dumpExDotInfo(const limex_type *limex, u32 state, FILE *f) {
template<typename limex_type> template<typename limex_type>
static static
void dumpLimDotInfo(const limex_type *limex, u32 state, FILE *f) { 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], if (testbit((const u8 *)&limex->shift[j],
limex_traits<limex_type>::size, state)) { 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) \ #define DUMP_TEXT_FN(ddf_n) \
void nfaExecLimEx##ddf_n##_##ddf_s##_dumpText(const NFA *nfa, FILE *f) { \ void nfaExecLimEx##ddf_n##_dumpText(const NFA *nfa, FILE *f) { \
dumpLimexText((const LimExNFA##ddf_n *)getImplNfa(nfa), f); \ dumpLimexText((const LimExNFA##ddf_n *)getImplNfa(nfa), f); \
} }
#define DUMP_DOT_FN(ddf_u, ddf_n, ddf_s) \ #define DUMP_DOT_FN(ddf_n) \
void nfaExecLimEx##ddf_n##_##ddf_s##_dumpDot(const NFA *nfa, FILE *f) { \ void nfaExecLimEx##ddf_n##_dumpDot(const NFA *nfa, FILE *f) { \
const LimExNFA##ddf_n *limex = \ const LimExNFA##ddf_n *limex = \
(const LimExNFA##ddf_n *)getImplNfa(nfa); \ (const LimExNFA##ddf_n *)getImplNfa(nfa); \
\ \
dumpDotPreamble(f); \ dumpDotPreamble(f); \
u32 state_count = nfa->nPositions; \ u32 state_count = nfa->nPositions; \
dumpVertexDotInfo(limex, state_count, f, \ dumpVertexDotInfo(limex, state_count, f, \
limex_labeller<LimExNFA##ddf_n>(limex)); \ limex_labeller<LimExNFA##ddf_n>(limex)); \
for (u32 i = 0; i < state_count; i++) { \ for (u32 i = 0; i < state_count; i++) { \
dumpLimDotInfo(limex, i, f); \ dumpLimDotInfo(limex, i, f); \
dumpExDotInfo(limex, i, f); \ dumpExDotInfo(limex, i, f); \
} \ } \
\
dumpDotTrailer(f); \ dumpDotTrailer(f); \
} }
#define LIMEX_DUMP_FNS(ntype, size, shifts) \ #define LIMEX_DUMP_FNS(size) \
DUMP_TEXT_FN(ntype, size, shifts) \ DUMP_TEXT_FN(size) \
DUMP_DOT_FN(ntype, size, shifts) DUMP_DOT_FN(size)
LIMEX_DUMP_FNS(u32, 32, 1) LIMEX_DUMP_FNS(32)
LIMEX_DUMP_FNS(u32, 32, 2) LIMEX_DUMP_FNS(128)
LIMEX_DUMP_FNS(u32, 32, 3) LIMEX_DUMP_FNS(256)
LIMEX_DUMP_FNS(u32, 32, 4) LIMEX_DUMP_FNS(384)
LIMEX_DUMP_FNS(u32, 32, 5) LIMEX_DUMP_FNS(512)
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)
} // namespace ue2 } // namespace ue2

View 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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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 The value of NFA.stateSize gives the total state size in bytes (the sum of
all the above). 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 #ifndef LIMEX_INTERNAL_H
@ -77,7 +80,8 @@
#include "repeat_internal.h" #include "repeat_internal.h"
// Constants // 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_STATE 1 /**< pack state into stream state */
#define LIMEX_FLAG_COMPRESS_MASKED 2 /**< use reach mask-based compression */ #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 compressMask; /**< switch off before compress */ \
u_##size exceptionMask; \ u_##size exceptionMask; \
u_##size repeatCyclicMask; \ u_##size repeatCyclicMask; \
u_##size shift[MAX_MAX_SHIFT]; \
u_##size zombieMask; /**< zombie if in any of the set states */ \ u_##size zombieMask; /**< zombie if in any of the set states */ \
u_##size shift[MAX_SHIFT_COUNT]; \
u32 shiftCount; /**< number of shift masks used */ \
u8 shiftAmount[MAX_SHIFT_COUNT]; /**< shift amount for each mask */ \
}; };
CREATE_NFA_LIMEX(32) CREATE_NFA_LIMEX(32)

View 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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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 SIZE 32
#define STATE_T u32 #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" #include "limex_runtime_impl.h"

View File

@ -73,34 +73,35 @@ struct proto_cache {
}; };
// Shift macros for Limited NFAs. Defined in terms of uniform ops. // 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) \ #define NFA_EXEC_LIM_SHIFT(nels_type, nels_i) \
(JOIN(shift_, nels_type)( \ (JOIN(shift_, nels_type)( \
JOIN(and_, nels_type)(s, \ JOIN(and_, nels_type)(s, \
JOIN(load_, nels_type)(&limex->shift[nels_i])), \ 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 // Calculate the (limited model) successors for a number of variable shifts.
// LimExNFAxxx ptr in 'l', current state in 's' and successors in 'succ'. // 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 { \ do { \
succ = \ succ = NFA_EXEC_LIM_SHIFT(gls_type, 0); \
JOIN(and_, gls_type)(s, JOIN(load_, gls_type)(&limex->shift[0])); \ switch (limex->shiftCount) { \
switch (gls_shift) { \ case 8: \
case 7: \
succ = JOIN(or_, gls_type)(succ, NFA_EXEC_LIM_SHIFT(gls_type, 7)); \ 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)); \ 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)); \ 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)); \ 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)); \ 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)); \ 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)); \ succ = JOIN(or_, gls_type)(succ, NFA_EXEC_LIM_SHIFT(gls_type, 1)); \
case 1: \
case 0: \ case 0: \
; \ ; \
} \ } \

View File

@ -37,11 +37,11 @@
* Version 2.0: now with X-Macros, so you get line numbers in your debugger. * Version 2.0: now with X-Macros, so you get line numbers in your debugger.
*/ */
#if !defined(SIZE) || !defined(STATE_T) || !defined(SHIFT) #if !defined(SIZE) || !defined(STATE_T)
# error Must define SIZE and STATE_T and SHIFT in includer. # error Must define SIZE and STATE_T in includer.
#endif #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) #define IMPL_NFA_T JOIN(struct LimExNFA, SIZE)
@ -201,7 +201,7 @@ without_accel:
u8 c = input[i]; u8 c = input[i];
STATE_T succ; 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, if (RUN_EXCEPTIONS_FN(limex, exceptions, exReports, exceptionMap, s,
EXCEPTION_MASK, i, offset, &succ, final_loc, ctx, EXCEPTION_MASK, i, offset, &succ, final_loc, ctx,
@ -252,7 +252,7 @@ with_accel:
u8 c = input[i]; u8 c = input[i];
STATE_T succ; 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, if (RUN_EXCEPTIONS_FN(limex, exceptions, exReports, exceptionMap, s,
EXCEPTION_MASK, i, offset, &succ, final_loc, ctx, 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]; u8 c = input[i-1];
STATE_T succ; 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, if (RUN_EXCEPTIONS_FN(limex, exceptions, exReports, exceptionMap, s,
EXCEPTION_MASK, i, offset, &succ, final_loc, ctx, EXCEPTION_MASK, i, offset, &succ, final_loc, ctx,
@ -935,5 +935,4 @@ enum nfa_zombie_status JOIN(LIMEX_API_ROOT, _zombie_status)(
// Parameters. // Parameters.
#undef SIZE #undef SIZE
#undef STATE_T #undef STATE_T
#undef SHIFT
#undef LIMEX_API_ROOT #undef LIMEX_API_ROOT

View 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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -61,37 +61,6 @@
#define INLINE_ATTR really_inline #define INLINE_ATTR really_inline
#include "limex_common_impl.h" #include "limex_common_impl.h"
#define SIZE 128 #define SIZE 128
#define STATE_T m128 #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
#include "limex_runtime_impl.h" #include "limex_runtime_impl.h"

View 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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -58,37 +58,6 @@
#define INLINE_ATTR really_inline #define INLINE_ATTR really_inline
#include "limex_common_impl.h" #include "limex_common_impl.h"
#define SIZE 256 #define SIZE 256
#define STATE_T m256 #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
#include "limex_runtime_impl.h" #include "limex_runtime_impl.h"

View 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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -58,37 +58,6 @@
#define INLINE_ATTR really_inline #define INLINE_ATTR really_inline
#include "limex_common_impl.h" #include "limex_common_impl.h"
#define SIZE 384 #define SIZE 384
#define STATE_T m384 #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
#include "limex_runtime_impl.h" #include "limex_runtime_impl.h"

View 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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -58,12 +58,6 @@
#define INLINE_ATTR really_inline #define INLINE_ATTR really_inline
#include "limex_common_impl.h" #include "limex_common_impl.h"
#define SIZE 512 #define SIZE 512
#define STATE_T m512 #define STATE_T m512
#define SHIFT 4
#include "limex_runtime_impl.h"
#define SIZE 512
#define STATE_T m512
#define SHIFT 5
#include "limex_runtime_impl.h" #include "limex_runtime_impl.h"

View File

@ -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"

View File

@ -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"

View File

@ -52,41 +52,11 @@
#define DISPATCH_BY_NFA_TYPE(dbnt_func) \ #define DISPATCH_BY_NFA_TYPE(dbnt_func) \
switch (nfa->type) { \ switch (nfa->type) { \
DISPATCH_CASE(LIMEX, LimEx, 32_1, dbnt_func); \ DISPATCH_CASE(LIMEX, LimEx, 32, dbnt_func); \
DISPATCH_CASE(LIMEX, LimEx, 32_2, dbnt_func); \ DISPATCH_CASE(LIMEX, LimEx, 128, dbnt_func); \
DISPATCH_CASE(LIMEX, LimEx, 32_3, dbnt_func); \ DISPATCH_CASE(LIMEX, LimEx, 256, dbnt_func); \
DISPATCH_CASE(LIMEX, LimEx, 32_4, dbnt_func); \ DISPATCH_CASE(LIMEX, LimEx, 384, dbnt_func); \
DISPATCH_CASE(LIMEX, LimEx, 32_5, dbnt_func); \ DISPATCH_CASE(LIMEX, LimEx, 512, 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(MCCLELLAN, McClellan, 8, dbnt_func); \ DISPATCH_CASE(MCCLELLAN, McClellan, 8, dbnt_func); \
DISPATCH_CASE(MCCLELLAN, McClellan, 16, dbnt_func); \ DISPATCH_CASE(MCCLELLAN, McClellan, 16, dbnt_func); \
DISPATCH_CASE(GOUGH, Gough, 8, dbnt_func); \ DISPATCH_CASE(GOUGH, Gough, 8, dbnt_func); \

View 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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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) #define DO_IF_DUMP_SUPPORT(a)
#endif #endif
#define MAKE_LIMEX_TRAITS(mlt_size, mlt_shift) \ #define MAKE_LIMEX_TRAITS(mlt_size) \
template<> struct NFATraits<LIMEX_NFA_##mlt_size##_##mlt_shift> { \ template<> struct NFATraits<LIMEX_NFA_##mlt_size> { \
static UNUSED const char *name; \ static UNUSED const char *name; \
static const NFACategory category = NFA_LIMEX; \ static const NFACategory category = NFA_LIMEX; \
typedef LimExNFA##mlt_size implNFA_t; \ typedef LimExNFA##mlt_size implNFA_t; \
@ -151,52 +151,22 @@ enum NFACategory {NFA_LIMEX, NFA_OTHER};
MAX(alignof(tableRow_t), alignof(RepeatControl)); \ MAX(alignof(tableRow_t), alignof(RepeatControl)); \
static const bool fast = mlt_size <= 64; \ 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>; \ = has_accel_limex<LimExNFA##mlt_size>; \
DO_IF_DUMP_SUPPORT( \ DO_IF_DUMP_SUPPORT( \
const char *NFATraits<LIMEX_NFA_##mlt_size##_##mlt_shift>::name \ const char *NFATraits<LIMEX_NFA_##mlt_size>::name \
= "LimEx (0-"#mlt_shift") "#mlt_size; \ = "LimEx "#mlt_size; \
template<> struct getDescription<LIMEX_NFA_##mlt_size##_##mlt_shift> { \ template<> struct getDescription<LIMEX_NFA_##mlt_size> { \
static string call(const void *ptr) { \ static string call(const void *ptr) { \
return getDescriptionLimEx<LIMEX_NFA_##mlt_size##_##mlt_shift>((const NFA *)ptr); \ return getDescriptionLimEx<LIMEX_NFA_##mlt_size>((const NFA *)ptr); \
} \ } \
};) };)
MAKE_LIMEX_TRAITS(32, 1) MAKE_LIMEX_TRAITS(32)
MAKE_LIMEX_TRAITS(32, 2) MAKE_LIMEX_TRAITS(128)
MAKE_LIMEX_TRAITS(32, 3) MAKE_LIMEX_TRAITS(256)
MAKE_LIMEX_TRAITS(32, 4) MAKE_LIMEX_TRAITS(384)
MAKE_LIMEX_TRAITS(32, 5) MAKE_LIMEX_TRAITS(512)
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)
template<> struct NFATraits<MCCLELLAN_NFA_8> { template<> struct NFATraits<MCCLELLAN_NFA_8> {
UNUSED static const char *name; UNUSED static const char *name;

View 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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -57,41 +57,11 @@ namespace ue2 {
#define DISPATCH_BY_NFA_TYPE(dbnt_func) \ #define DISPATCH_BY_NFA_TYPE(dbnt_func) \
DEBUG_PRINTF("dispatch for NFA type %u\n", nfa->type); \ DEBUG_PRINTF("dispatch for NFA type %u\n", nfa->type); \
switch (nfa->type) { \ switch (nfa->type) { \
DISPATCH_CASE(LIMEX, LimEx, 32_1, dbnt_func); \ DISPATCH_CASE(LIMEX, LimEx, 32, dbnt_func); \
DISPATCH_CASE(LIMEX, LimEx, 32_2, dbnt_func); \ DISPATCH_CASE(LIMEX, LimEx, 128, dbnt_func); \
DISPATCH_CASE(LIMEX, LimEx, 32_3, dbnt_func); \ DISPATCH_CASE(LIMEX, LimEx, 256, dbnt_func); \
DISPATCH_CASE(LIMEX, LimEx, 32_4, dbnt_func); \ DISPATCH_CASE(LIMEX, LimEx, 384, dbnt_func); \
DISPATCH_CASE(LIMEX, LimEx, 32_5, dbnt_func); \ DISPATCH_CASE(LIMEX, LimEx, 512, 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(MCCLELLAN, McClellan, 8, dbnt_func); \ DISPATCH_CASE(MCCLELLAN, McClellan, 8, dbnt_func); \
DISPATCH_CASE(MCCLELLAN, McClellan, 16, dbnt_func); \ DISPATCH_CASE(MCCLELLAN, McClellan, 16, dbnt_func); \
DISPATCH_CASE(GOUGH, Gough, 8, dbnt_func); \ DISPATCH_CASE(GOUGH, Gough, 8, dbnt_func); \

View File

@ -51,41 +51,11 @@ extern "C"
// Common data structures for NFAs // Common data structures for NFAs
enum NFAEngineType { enum NFAEngineType {
LIMEX_NFA_32_1, LIMEX_NFA_32,
LIMEX_NFA_32_2, LIMEX_NFA_128,
LIMEX_NFA_32_3, LIMEX_NFA_256,
LIMEX_NFA_32_4, LIMEX_NFA_384,
LIMEX_NFA_32_5, LIMEX_NFA_512,
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,
MCCLELLAN_NFA_8, /**< magic pseudo nfa */ MCCLELLAN_NFA_8, /**< magic pseudo nfa */
MCCLELLAN_NFA_16, /**< magic pseudo nfa */ MCCLELLAN_NFA_16, /**< magic pseudo nfa */
GOUGH_NFA_8, /**< 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. */ /** \brief True if the given type (from NFA::type) is an NFA. */
static really_inline int isNfaType(u8 t) { static really_inline int isNfaType(u8 t) {
switch (t) { switch (t) {
case LIMEX_NFA_32_1: case LIMEX_NFA_32:
case LIMEX_NFA_32_2: case LIMEX_NFA_128:
case LIMEX_NFA_32_3: case LIMEX_NFA_256:
case LIMEX_NFA_32_4: case LIMEX_NFA_384:
case LIMEX_NFA_32_5: case LIMEX_NFA_512:
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:
return 1; return 1;
default: default:
break; break;

View File

@ -130,7 +130,7 @@ protected:
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
LimEx, LimExModelTest, 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) { TEST_P(LimExModelTest, StateSize) {
ASSERT_TRUE(nfa != nullptr); ASSERT_TRUE(nfa != nullptr);
@ -337,7 +337,7 @@ protected:
}; };
INSTANTIATE_TEST_CASE_P(LimExReverse, LimExReverseTest, 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) { TEST_P(LimExReverseTest, BlockExecReverse) {
ASSERT_TRUE(nfa != nullptr); ASSERT_TRUE(nfa != nullptr);
@ -424,7 +424,7 @@ protected:
}; };
INSTANTIATE_TEST_CASE_P(LimExZombie, LimExZombieTest, 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) { TEST_P(LimExZombieTest, GetZombieStatus) {
ASSERT_TRUE(nfa != nullptr); ASSERT_TRUE(nfa != nullptr);