Discard HAVE_AVX512VBMI checks at Sheng/McSheng compile time.

This commit is contained in:
Chang, Harry 2020-10-21 12:30:04 +00:00 committed by Konstantinos Margaritis
parent b19a41528a
commit 5ad3d64b4b
12 changed files with 18 additions and 77 deletions

View File

@ -152,6 +152,6 @@ char nfaExecMcSheng64_16_expandState(const struct NFA *nfa, void *dest,
#define nfaExecMcSheng64_16_testEOD NFA_API_NO_IMPL
#define nfaExecMcSheng64_16_reportCurrent NFA_API_NO_IMPL
#endif //end of HAVE_AVX512VBM
#endif //end of HAVE_AVX512VBMI
#endif

View File

@ -243,7 +243,6 @@ void populateBasicInfo(size_t state_size, const dfa_info &info,
}
}
#if defined(HAVE_AVX512VBMI)
static
mstate_aux *getAux64(NFA *n, dstate_id_t i) {
mcsheng64 *m = (mcsheng64 *)getMutableImplNfa(n);
@ -343,7 +342,6 @@ void populateBasicInfo64(size_t state_size, const dfa_info &info,
m->flags |= MCSHENG_FLAG_SINGLE;
}
}
#endif
static
size_t calcShermanRegionSize(const dfa_info &info) {
@ -719,7 +717,6 @@ void fill_in_succ_table_16(NFA *nfa, const dfa_info &info,
}
}
#if defined(HAVE_AVX512VBMI)
static
void fill_in_aux_info64(NFA *nfa, const dfa_info &info,
const map<dstate_id_t, AccelScheme> &accel_escape_info,
@ -793,7 +790,6 @@ void fill_in_succ_table_64_16(NFA *nfa, const dfa_info &info,
}
}
}
#endif
#define MAX_SHERMAN_LIST_LEN 8
@ -1113,7 +1109,6 @@ void fill_in_succ_table_8(NFA *nfa, const dfa_info &info,
}
}
#if defined(HAVE_AVX512VBMI)
static
void fill_in_sherman64(NFA *nfa, dfa_info &info, UNUSED u16 sherman_limit) {
char *nfa_base = (char *)nfa;
@ -1267,7 +1262,6 @@ void fill_in_succ_table_64_8(NFA *nfa, const dfa_info &info,
}
}
}
#endif
static
void allocateImplId8(dfa_info &info, dstate_id_t sheng_end,
@ -1366,7 +1360,6 @@ bytecode_ptr<NFA> mcshengCompile8(dfa_info &info, dstate_id_t sheng_end,
return nfa;
}
#if defined(HAVE_AVX512VBMI)
static
bytecode_ptr<NFA> mcsheng64Compile8(dfa_info &info, dstate_id_t sheng_end,
const map<dstate_id_t, AccelScheme> &accel_escape_info) {
@ -1418,7 +1411,6 @@ bytecode_ptr<NFA> mcsheng64Compile8(dfa_info &info, dstate_id_t sheng_end,
return nfa;
}
#endif
bytecode_ptr<NFA> mcshengCompile(raw_dfa &raw, const CompileContext &cc,
const ReportManager &rm) {
@ -1468,13 +1460,17 @@ bytecode_ptr<NFA> mcshengCompile(raw_dfa &raw, const CompileContext &cc,
return nfa;
}
#if defined(HAVE_AVX512VBMI)
bytecode_ptr<NFA> mcshengCompile64(raw_dfa &raw, const CompileContext &cc,
const ReportManager &rm) {
if (!cc.grey.allowMcSheng) {
return nullptr;
}
if (!cc.target_info.has_avx512vbmi()) {
DEBUG_PRINTF("McSheng64 failed, no HS_CPU_FEATURES_AVX512VBMI!\n");
return nullptr;
}
mcclellan_build_strat mbs(raw, rm, false);
dfa_info info(mbs);
bool using8bit = cc.grey.allowMcClellan8 && info.size() <= 256;
@ -1523,7 +1519,6 @@ bytecode_ptr<NFA> mcshengCompile64(raw_dfa &raw, const CompileContext &cc,
DEBUG_PRINTF("compile done\n");
return nfa;
}
#endif
bool has_accel_mcsheng(const NFA *) {
return true; /* consider the sheng region as accelerated */

View File

@ -53,4 +53,3 @@ const u64a mcsheng64_pext_mask[8] = {
0xff0000000000003f,
};
#endif

View File

@ -174,7 +174,6 @@ void describeEdge(FILE *f, const mcsheng *m, const u16 *t, u16 i) {
}
}
#if defined(HAVE_AVX512VBMI)
static
const mstate_aux *getAux64(const NFA *n, dstate_id_t i) {
auto *m = (const mcsheng64 *)getImplNfa(n);
@ -292,7 +291,6 @@ void describeEdge64(FILE *f, const mcsheng64 *m, const u16 *t, u16 i) {
fprintf(f, "\" ];\n");
}
}
#endif
static
void dumpAccelDot(FILE *f, u16 i, const union AccelAux *accel) {
@ -376,7 +374,6 @@ void describeNode(const NFA *n, const mcsheng *m, u16 i, FILE *f) {
}
#if defined(HAVE_AVX512VBMI)
static
void describeNode64(const NFA *n, const mcsheng64 *m, u16 i, FILE *f) {
const mstate_aux *aux = getAux64(n, i);
@ -436,7 +433,6 @@ void describeNode64(const NFA *n, const mcsheng64 *m, u16 i, FILE *f) {
}
}
#endif
static
void dumpDotPreambleDfa(FILE *f) {
@ -574,7 +570,6 @@ void dump_text_8(const NFA *nfa, FILE *f) {
dumpTextReverse(nfa, f);
}
#if defined(HAVE_AVX512VBMI)
static
void dump64_dot_16(const NFA *nfa, FILE *f) {
auto *m = (const mcsheng64 *)getImplNfa(nfa);
@ -699,7 +694,6 @@ void dump64_text_16(const NFA *nfa, FILE *f) {
fprintf(f, "\n");
dumpTextReverse(nfa, f);
}
#endif
void nfaExecMcSheng16_dump(const NFA *nfa, const string &base) {
assert(nfa->type == MCSHENG_NFA_16);
@ -714,19 +708,15 @@ void nfaExecMcSheng8_dump(const NFA *nfa, const string &base) {
}
void nfaExecMcSheng64_16_dump(UNUSED const NFA *nfa, UNUSED const string &base) {
#if defined(HAVE_AVX512VBMI)
assert(nfa->type == MCSHENG_64_NFA_16);
dump64_text_16(nfa, StdioFile(base + ".txt", "w"));
dump64_dot_16(nfa, StdioFile(base + ".dot", "w"));
#endif
}
void nfaExecMcSheng64_8_dump(UNUSED const NFA *nfa, UNUSED const string &base) {
#if defined(HAVE_AVX512VBMI)
assert(nfa->type == MCSHENG_64_NFA_8);
dump64_text_8(nfa, StdioFile(base + ".txt", "w"));
dump64_dot_8(nfa, StdioFile(base + ".dot", "w"));
#endif
}
} // namespace ue2

View File

@ -92,7 +92,6 @@ struct mcsheng {
* representing the data from a u64a. */
extern const u64a mcsheng_pext_mask[8];
#if defined(HAVE_AVX512VBMI)
struct mcsheng64 {
u16 state_count; /**< total number of states */
u32 length; /**< length of dfa in bytes */
@ -121,6 +120,5 @@ struct mcsheng64 {
};
extern const u64a mcsheng64_pext_mask[8];
#endif
#endif

View File

@ -152,12 +152,8 @@ static really_inline int isMcClellanType(u8 t) {
/** \brief True if the given type (from NFA::type) is a Sheng-McClellan hybrid
* DFA. */
static really_inline int isShengMcClellanType(u8 t) {
#if defined(HAVE_AVX512VBMI)
return t == MCSHENG_64_NFA_8 || t == MCSHENG_64_NFA_16 || t == MCSHENG_NFA_8 ||
t == MCSHENG_NFA_16;
#else
return t == MCSHENG_NFA_8 || t == MCSHENG_NFA_16;
#endif
return t == MCSHENG_NFA_8 || t == MCSHENG_NFA_16 ||
t == MCSHENG_64_NFA_8 || t == MCSHENG_64_NFA_16;
}
/** \brief True if the given type (from NFA::type) is a Gough DFA. */
@ -170,7 +166,6 @@ static really_inline int isSheng16Type(u8 t) {
return t == SHENG_NFA;
}
#if defined(HAVE_AVX512VBMI)
/** \brief True if the given type (from NFA::type) is a Sheng32 DFA. */
static really_inline int isSheng32Type(u8 t) {
return t == SHENG_NFA_32;
@ -180,15 +175,10 @@ static really_inline int isSheng32Type(u8 t) {
static really_inline int isSheng64Type(u8 t) {
return t == SHENG_NFA_64;
}
#endif
/** \brief True if the given type (from NFA::type) is a Sheng16/32/64 DFA. */
static really_inline int isShengType(u8 t) {
#if defined(HAVE_AVX512VBMI)
return t == SHENG_NFA || t == SHENG_NFA_32 || t == SHENG_NFA_64;
#else
return t == SHENG_NFA;
#endif
}
/**

View File

@ -38,7 +38,6 @@
#define SHENG_STATE_MASK 0xF
#define SHENG_STATE_FLAG_MASK 0x70
#if defined (HAVE_AVX512VBMI)
#define SHENG32_STATE_ACCEPT 0x20
#define SHENG32_STATE_DEAD 0x40
#define SHENG32_STATE_ACCEL 0x80
@ -49,7 +48,6 @@
#define SHENG64_STATE_DEAD 0x80
#define SHENG64_STATE_MASK 0x3F
#define SHENG64_STATE_FLAG_MASK 0xC0
#endif
#define SHENG_FLAG_SINGLE_REPORT 0x1
#define SHENG_FLAG_CAN_DIE 0x2
@ -80,7 +78,6 @@ struct sheng {
ReportID report;
};
#if defined (HAVE_AVX512VBMI)
struct sheng32 {
m512 succ_masks[256];
u32 length;
@ -106,6 +103,5 @@ struct sheng64 {
u8 flags;
ReportID report;
};
#endif
#endif /* SHENG_INTERNAL_H_ */

View File

@ -302,7 +302,6 @@ void dumpShuffleMask(const u8 chr, const u8 *buf, unsigned sz) {
DEBUG_PRINTF("chr %3u: %s\n", chr, o.str().c_str());
}
#if defined (HAVE_AVX512VBMI)
static really_inline
void dumpShuffleMask32(const u8 chr, const u8 *buf, unsigned sz) {
stringstream o;
@ -325,7 +324,6 @@ void dumpShuffleMask64(const u8 chr, const u8 *buf, unsigned sz) {
DEBUG_PRINTF("chr %3u: %s\n", chr, o.str().c_str());
}
#endif
#endif
static
void fillAccelOut(const map<dstate_id_t, AccelScheme> &accel_escape_info,
@ -358,7 +356,6 @@ u8 getShengState<sheng>(dstate &state, dfa_info &info,
return s;
}
#if defined(HAVE_AVX512VBMI)
template <>
u8 getShengState<sheng32>(dstate &state, dfa_info &info,
map<dstate_id_t, AccelScheme> &accelInfo) {
@ -387,7 +384,6 @@ u8 getShengState<sheng64>(dstate &state, dfa_info &info,
}
return s;
}
#endif
template <typename T>
static
@ -446,7 +442,6 @@ void populateBasicInfo<sheng>(struct NFA *n, dfa_info &info,
s->floating = getShengState<sheng>(info.floating, info, accelInfo);
}
#if defined(HAVE_AVX512VBMI)
template <>
void populateBasicInfo<sheng32>(struct NFA *n, dfa_info &info,
map<dstate_id_t, AccelScheme> &accelInfo,
@ -496,7 +491,6 @@ void populateBasicInfo<sheng64>(struct NFA *n, dfa_info &info,
s->anchored = getShengState<sheng64>(info.anchored, info, accelInfo);
s->floating = getShengState<sheng64>(info.floating, info, accelInfo);
}
#endif
template <typename T>
static
@ -582,7 +576,6 @@ bool createShuffleMasks<sheng>(sheng *s, dfa_info &info,
return true;
}
#if defined(HAVE_AVX512VBMI)
template <>
bool createShuffleMasks<sheng32>(sheng32 *s, dfa_info &info,
map<dstate_id_t, AccelScheme> &accelInfo) {
@ -627,7 +620,6 @@ bool createShuffleMasks<sheng64>(sheng64 *s, dfa_info &info,
}
return true;
}
#endif
bool has_accel_sheng(const NFA *) {
return true; /* consider the sheng region as accelerated */
@ -731,7 +723,6 @@ bytecode_ptr<NFA> shengCompile(raw_dfa &raw, const CompileContext &cc,
return shengCompile_int<sheng>(raw, cc, accel_states, strat, info);
}
#if defined(HAVE_AVX512VBMI)
bytecode_ptr<NFA> sheng32Compile(raw_dfa &raw, const CompileContext &cc,
const ReportManager &rm, bool only_accel_init,
set<dstate_id_t> *accel_states) {
@ -740,6 +731,11 @@ bytecode_ptr<NFA> sheng32Compile(raw_dfa &raw, const CompileContext &cc,
return nullptr;
}
if (!cc.target_info.has_avx512vbmi()) {
DEBUG_PRINTF("Sheng32 failed, no HS_CPU_FEATURES_AVX512VBMI!\n");
return nullptr;
}
sheng_build_strat strat(raw, rm, only_accel_init);
dfa_info info(strat);
@ -767,6 +763,11 @@ bytecode_ptr<NFA> sheng64Compile(raw_dfa &raw, const CompileContext &cc,
return nullptr;
}
if (!cc.target_info.has_avx512vbmi()) {
DEBUG_PRINTF("Sheng64 failed, no HS_CPU_FEATURES_AVX512VBMI!\n");
return nullptr;
}
sheng_build_strat strat(raw, rm, only_accel_init);
dfa_info info(strat);
@ -790,6 +791,5 @@ bytecode_ptr<NFA> sheng64Compile(raw_dfa &raw, const CompileContext &cc,
}
return nfa;
}
#endif
} // namespace ue2

View File

@ -71,7 +71,6 @@ bytecode_ptr<NFA> shengCompile(raw_dfa &raw, const CompileContext &cc,
const ReportManager &rm, bool only_accel_init,
std::set<dstate_id_t> *accel_states = nullptr);
#if defined(HAVE_AVX512VBMI)
bytecode_ptr<NFA> sheng32Compile(raw_dfa &raw, const CompileContext &cc,
const ReportManager &rm, bool only_accel_init,
std::set<dstate_id_t> *accel_states = nullptr);
@ -79,7 +78,6 @@ bytecode_ptr<NFA> sheng32Compile(raw_dfa &raw, const CompileContext &cc,
bytecode_ptr<NFA> sheng64Compile(raw_dfa &raw, const CompileContext &cc,
const ReportManager &rm, bool only_accel_init,
std::set<dstate_id_t> *accel_states = nullptr);
#endif
struct sheng_escape_info {
CharReach outs;

View File

@ -64,7 +64,6 @@ const sstate_aux *get_aux(const NFA *n, dstate_id_t i) {
return aux;
}
#if defined(HAVE_AVX512VBMI)
static
const sstate_aux *get_aux32(const NFA *n, dstate_id_t i) {
assert(n && isSheng32Type(n->type));
@ -94,7 +93,6 @@ const sstate_aux *get_aux64(const NFA *n, dstate_id_t i) {
return aux;
}
#endif
static
void dumpHeader(FILE *f, const sheng *s) {
@ -111,7 +109,6 @@ void dumpHeader(FILE *f, const sheng *s) {
!!(s->flags & SHENG_FLAG_SINGLE_REPORT));
}
#if defined(HAVE_AVX512VBMI)
static
void dumpHeader32(FILE *f, const sheng32 *s) {
fprintf(f, "number of states: %u, DFA engine size: %u\n", s->n_states,
@ -141,7 +138,6 @@ void dumpHeader64(FILE *f, const sheng64 *s) {
!!(s->flags & SHENG_FLAG_CAN_DIE),
!!(s->flags & SHENG_FLAG_SINGLE_REPORT));
}
#endif
static
void dumpAux(FILE *f, u32 state, const sstate_aux *aux) {
@ -151,7 +147,6 @@ void dumpAux(FILE *f, u32 state, const sstate_aux *aux) {
aux->top & SHENG_STATE_MASK);
}
#if defined(HAVE_AVX512VBMI)
static
void dumpAux32(FILE *f, u32 state, const sstate_aux *aux) {
fprintf(f, "state id: %u, reports offset: %u, EOD reports offset: %u, "
@ -167,7 +162,6 @@ void dumpAux64(FILE *f, u32 state, const sstate_aux *aux) {
state, aux->accept, aux->accept_eod, aux->accel,
aux->top & SHENG64_STATE_MASK);
}
#endif
static
void dumpReports(FILE *f, const report_list *rl) {
@ -197,7 +191,6 @@ void dumpMasks(FILE *f, const sheng *s) {
}
}
#if defined(HAVE_AVX512VBMI)
static
void dumpMasks32(FILE *f, const sheng32 *s) {
for (u32 chr = 0; chr < 256; chr++) {
@ -237,7 +230,6 @@ void dumpMasks64(FILE *f, const sheng64 *s) {
fprintf(f, "\n");
}
}
#endif
static
void nfaExecSheng_dumpText(const NFA *nfa, FILE *f) {
@ -277,7 +269,6 @@ void nfaExecSheng_dumpText(const NFA *nfa, FILE *f) {
fprintf(f, "\n");
}
#if defined(HAVE_AVX512VBMI)
static
void nfaExecSheng32_dumpText(const NFA *nfa, FILE *f) {
assert(nfa->type == SHENG_NFA_32);
@ -353,7 +344,6 @@ void nfaExecSheng64_dumpText(const NFA *nfa, FILE *f) {
fprintf(f, "\n");
}
#endif
static
void dumpDotPreambleDfa(FILE *f) {
@ -401,7 +391,6 @@ void describeNode<sheng>(const NFA *n, const sheng *s, u16 i, FILE *f) {
}
}
#if defined(HAVE_AVX512VBMI)
template <>
void describeNode<sheng32>(const NFA *n, const sheng32 *s, u16 i, FILE *f) {
const sstate_aux *aux = get_aux32(n, i);
@ -461,7 +450,6 @@ void describeNode<sheng64>(const NFA *n, const sheng64 *s, u16 i, FILE *f) {
fprintf(f, "STARTF -> %u [color = red ]\n", i);
}
}
#endif
static
void describeEdge(FILE *f, const u16 *t, u16 i) {
@ -514,7 +502,6 @@ void shengGetTransitions(const NFA *n, u16 state, u16 *t) {
t[TOP] = aux->top & SHENG_STATE_MASK;
}
#if defined(HAVE_AVX512VBMI)
static
void sheng32GetTransitions(const NFA *n, u16 state, u16 *t) {
assert(isSheng32Type(n->type));
@ -550,7 +537,6 @@ void sheng64GetTransitions(const NFA *n, u16 state, u16 *t) {
t[TOP] = aux->top & SHENG64_STATE_MASK;
}
#endif
static
void nfaExecSheng_dumpDot(const NFA *nfa, FILE *f) {
@ -572,7 +558,6 @@ void nfaExecSheng_dumpDot(const NFA *nfa, FILE *f) {
fprintf(f, "}\n");
}
#if defined(HAVE_AVX512VBMI)
static
void nfaExecSheng32_dumpDot(const NFA *nfa, FILE *f) {
assert(nfa->type == SHENG_NFA_32);
@ -612,7 +597,6 @@ void nfaExecSheng64_dumpDot(const NFA *nfa, FILE *f) {
fprintf(f, "}\n");
}
#endif
void nfaExecSheng_dump(const NFA *nfa, const string &base) {
assert(nfa->type == SHENG_NFA);
@ -621,19 +605,15 @@ void nfaExecSheng_dump(const NFA *nfa, const string &base) {
}
void nfaExecSheng32_dump(UNUSED const NFA *nfa, UNUSED const string &base) {
#if defined(HAVE_AVX512VBMI)
assert(nfa->type == SHENG_NFA_32);
nfaExecSheng32_dumpText(nfa, StdioFile(base + ".txt", "w"));
nfaExecSheng32_dumpDot(nfa, StdioFile(base + ".dot", "w"));
#endif
}
void nfaExecSheng64_dump(UNUSED const NFA *nfa, UNUSED const string &base) {
#if defined(HAVE_AVX512VBMI)
assert(nfa->type == SHENG_NFA_64);
nfaExecSheng64_dumpText(nfa, StdioFile(base + ".txt", "w"));
nfaExecSheng64_dumpDot(nfa, StdioFile(base + ".dot", "w"));
#endif
}
} // namespace ue2

View File

@ -632,8 +632,6 @@ bytecode_ptr<NFA> getDfa(raw_dfa &rdfa, bool is_transient,
* bytecode and that they are usually run on small blocks */
dfa = mcshengCompile(rdfa, cc, rm);
}
#if defined(HAVE_AVX512VBMI)
if (!dfa) {
dfa = sheng32Compile(rdfa, cc, rm, false);
}
@ -643,7 +641,6 @@ bytecode_ptr<NFA> getDfa(raw_dfa &rdfa, bool is_transient,
if (!dfa && !is_transient) {
dfa = mcshengCompile64(rdfa, cc, rm);
}
#endif
if (!dfa) {
// Sheng wasn't successful, so unleash McClellan!
dfa = mcclellanCompile(rdfa, cc, rm, false);

View File

@ -793,14 +793,12 @@ bytecode_ptr<NFA> getDfa(raw_dfa &rdfa, const CompileContext &cc,
bytecode_ptr<NFA> dfa = nullptr;
if (cc.grey.allowSmallWriteSheng) {
dfa = shengCompile(rdfa, cc, rm, only_accel_init, &accel_states);
#if defined(HAVE_AVX512VBMI)
if (!dfa) {
dfa = sheng32Compile(rdfa, cc, rm, only_accel_init, &accel_states);
}
if (!dfa) {
dfa = sheng64Compile(rdfa, cc, rm, only_accel_init, &accel_states);
}
#endif
}
if (!dfa) {
dfa = mcclellanCompile(rdfa, cc, rm, only_accel_init,