SHENG32: Compile priority sheng > mcsheng > sheng32.

This commit is contained in:
Chang, Harry 2020-07-20 06:36:53 +00:00 committed by Konstantinos Margaritis
parent cc747013c4
commit 6a42b37fca
4 changed files with 45 additions and 8 deletions

View File

@ -643,19 +643,40 @@ bytecode_ptr<NFA> shengCompile(raw_dfa &raw, const CompileContext &cc,
DEBUG_PRINTF("This DFA %s die so effective number of states is %zu\n", DEBUG_PRINTF("This DFA %s die so effective number of states is %zu\n",
info.can_die ? "can" : "cannot", info.size()); info.can_die ? "can" : "cannot", info.size());
if (info.size() > 16) { if (info.size() > 16) {
#if defined(HAVE_AVX512VBMI)
if (info.size() > 32) {
DEBUG_PRINTF("Too many states\n");
return nullptr;
}
return shengCompile_int<sheng32>(raw, cc, accel_states, strat, info);
#else
DEBUG_PRINTF("Too many states\n"); DEBUG_PRINTF("Too many states\n");
return nullptr; return nullptr;
#endif
} }
return shengCompile_int<sheng>(raw, cc, accel_states, strat, info); 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) {
if (!cc.grey.allowSheng) {
DEBUG_PRINTF("Sheng is not allowed!\n");
return nullptr;
}
sheng_build_strat strat(raw, rm, only_accel_init);
dfa_info info(strat);
DEBUG_PRINTF("Trying to compile a %zu state Sheng\n", raw.states.size());
DEBUG_PRINTF("Anchored start state id: %u, floating start state id: %u\n",
raw.start_anchored, raw.start_floating);
DEBUG_PRINTF("This DFA %s die so effective number of states is %zu\n",
info.can_die ? "can" : "cannot", info.size());
assert(info.size() > 16);
if (info.size() > 32) {
DEBUG_PRINTF("Too many states\n");
return nullptr;
}
return shengCompile_int<sheng32>(raw, cc, accel_states, strat, info);
}
#endif
} // namespace ue2 } // namespace ue2

View File

@ -71,6 +71,12 @@ bytecode_ptr<NFA> shengCompile(raw_dfa &raw, const CompileContext &cc,
const ReportManager &rm, bool only_accel_init, const ReportManager &rm, bool only_accel_init,
std::set<dstate_id_t> *accel_states = nullptr); 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);
#endif
struct sheng_escape_info { struct sheng_escape_info {
CharReach outs; CharReach outs;
CharReach outs2_single; CharReach outs2_single;

View File

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

View File

@ -793,6 +793,11 @@ bytecode_ptr<NFA> getDfa(raw_dfa &rdfa, const CompileContext &cc,
bytecode_ptr<NFA> dfa = nullptr; bytecode_ptr<NFA> dfa = nullptr;
if (cc.grey.allowSmallWriteSheng) { if (cc.grey.allowSmallWriteSheng) {
dfa = shengCompile(rdfa, cc, rm, only_accel_init, &accel_states); 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);
}
#endif
} }
if (!dfa) { if (!dfa) {
dfa = mcclellanCompile(rdfa, cc, rm, only_accel_init, dfa = mcclellanCompile(rdfa, cc, rm, only_accel_init,