mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-30 19:47:43 +03:00
dfa: only accel init states from smwr path
If the small-write DFA has been built from literals, then we only need to look for accel states at init.
This commit is contained in:
committed by
Matthew Barr
parent
41d7aa8281
commit
0dd8536c6e
@@ -541,17 +541,17 @@ accel_dfa_build_strat::getAccelInfo(const Grey &grey) {
|
||||
dstate_id_t sds_proxy = get_sds_or_proxy(rdfa);
|
||||
DEBUG_PRINTF("sds %hu\n", sds_proxy);
|
||||
|
||||
for (size_t i = 0; i < rdfa.states.size(); i++) {
|
||||
/* Find accel info for a single state. */
|
||||
auto do_state = [&](size_t i) {
|
||||
if (i == DEAD_STATE) {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Note on report acceleration states: While we can't accelerate while
|
||||
* we
|
||||
* are spamming out callbacks, the QR code paths don't raise reports
|
||||
* we are spamming out callbacks, the QR code paths don't raise reports
|
||||
* during scanning so they can accelerate report states. */
|
||||
if (generates_callbacks(rdfa.kind) && !rdfa.states[i].reports.empty()) {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
size_t single_limit =
|
||||
@@ -562,15 +562,28 @@ accel_dfa_build_strat::getAccelInfo(const Grey &grey) {
|
||||
if (ei.cr.count() > single_limit) {
|
||||
DEBUG_PRINTF("state %zu is not accelerable has %zu\n", i,
|
||||
ei.cr.count());
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_PRINTF("state %zu should be accelerable %zu\n", i, ei.cr.count());
|
||||
|
||||
rv[i] = ei;
|
||||
};
|
||||
|
||||
if (only_accel_init) {
|
||||
DEBUG_PRINTF("only computing accel for init states\n");
|
||||
do_state(rdfa.start_anchored);
|
||||
if (rdfa.start_floating != rdfa.start_anchored) {
|
||||
do_state(rdfa.start_floating);
|
||||
}
|
||||
} else {
|
||||
DEBUG_PRINTF("computing accel for all states\n");
|
||||
for (size_t i = 0; i < rdfa.states.size(); i++) {
|
||||
do_state(i);
|
||||
}
|
||||
}
|
||||
|
||||
/* provide accleration states to states in the region of sds */
|
||||
/* provide acceleration states to states in the region of sds */
|
||||
if (contains(rv, sds_proxy)) {
|
||||
AccelScheme sds_ei = rv[sds_proxy];
|
||||
sds_ei.double_byte.clear(); /* region based on single byte scheme
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016, Intel Corporation
|
||||
* Copyright (c) 2015-2017, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -43,8 +43,8 @@ struct Grey;
|
||||
|
||||
class accel_dfa_build_strat : public dfa_build_strat {
|
||||
public:
|
||||
explicit accel_dfa_build_strat(const ReportManager &rm_in)
|
||||
: dfa_build_strat(rm_in) {}
|
||||
accel_dfa_build_strat(const ReportManager &rm_in, bool only_accel_init_in)
|
||||
: dfa_build_strat(rm_in), only_accel_init(only_accel_init_in) {}
|
||||
virtual AccelScheme find_escape_strings(dstate_id_t this_idx) const;
|
||||
virtual size_t accelSize(void) const = 0;
|
||||
virtual u32 max_allowed_offset_accel() const = 0;
|
||||
@@ -53,6 +53,8 @@ public:
|
||||
virtual void buildAccel(dstate_id_t this_idx, const AccelScheme &info,
|
||||
void *accel_out);
|
||||
virtual std::map<dstate_id_t, AccelScheme> getAccelInfo(const Grey &grey);
|
||||
private:
|
||||
bool only_accel_init;
|
||||
};
|
||||
|
||||
} // namespace ue2
|
||||
|
@@ -80,7 +80,7 @@ public:
|
||||
gough_build_strat(
|
||||
raw_som_dfa &r, const GoughGraph &g, const ReportManager &rm_in,
|
||||
const map<dstate_id_t, gough_accel_state_info> &accel_info)
|
||||
: mcclellan_build_strat(r, rm_in), rdfa(r), gg(g),
|
||||
: mcclellan_build_strat(r, rm_in, false), rdfa(r), gg(g),
|
||||
accel_gough_info(accel_info) {}
|
||||
unique_ptr<raw_report_info> gatherReports(vector<u32> &reports /* out */,
|
||||
vector<u32> &reports_eod /* out */,
|
||||
|
@@ -981,8 +981,9 @@ bytecode_ptr<NFA> mcclellanCompile_i(raw_dfa &raw, accel_dfa_build_strat &strat,
|
||||
|
||||
bytecode_ptr<NFA> mcclellanCompile(raw_dfa &raw, const CompileContext &cc,
|
||||
const ReportManager &rm,
|
||||
bool only_accel_init,
|
||||
set<dstate_id_t> *accel_states) {
|
||||
mcclellan_build_strat mbs(raw, rm);
|
||||
mcclellan_build_strat mbs(raw, rm, only_accel_init);
|
||||
return mcclellanCompile_i(raw, mbs, cc, accel_states);
|
||||
}
|
||||
|
||||
|
@@ -48,8 +48,9 @@ struct CompileContext;
|
||||
|
||||
class mcclellan_build_strat : public accel_dfa_build_strat {
|
||||
public:
|
||||
mcclellan_build_strat(raw_dfa &rdfa_in, const ReportManager &rm_in)
|
||||
: accel_dfa_build_strat(rm_in), rdfa(rdfa_in) {}
|
||||
mcclellan_build_strat(raw_dfa &rdfa_in, const ReportManager &rm_in,
|
||||
bool only_accel_init_in)
|
||||
: accel_dfa_build_strat(rm_in, only_accel_init_in), rdfa(rdfa_in) {}
|
||||
raw_dfa &get_raw() const override { return rdfa; }
|
||||
std::unique_ptr<raw_report_info> gatherReports(
|
||||
std::vector<u32> &reports /* out */,
|
||||
@@ -69,7 +70,7 @@ private:
|
||||
* states */
|
||||
bytecode_ptr<NFA>
|
||||
mcclellanCompile(raw_dfa &raw, const CompileContext &cc,
|
||||
const ReportManager &rm,
|
||||
const ReportManager &rm, bool only_accel_init,
|
||||
std::set<dstate_id_t> *accel_states = nullptr);
|
||||
|
||||
/* used internally by mcclellan/haig/gough compile process */
|
||||
|
@@ -1025,7 +1025,7 @@ bytecode_ptr<NFA> mcshengCompile(raw_dfa &raw, const CompileContext &cc,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
mcclellan_build_strat mbs(raw, rm);
|
||||
mcclellan_build_strat mbs(raw, rm, false);
|
||||
dfa_info info(mbs);
|
||||
bool using8bit = cc.grey.allowMcClellan8 && info.size() <= 256;
|
||||
|
||||
|
@@ -451,14 +451,14 @@ bool has_accel_sheng(const NFA *) {
|
||||
}
|
||||
|
||||
bytecode_ptr<NFA> shengCompile(raw_dfa &raw, const CompileContext &cc,
|
||||
const ReportManager &rm,
|
||||
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);
|
||||
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());
|
||||
|
@@ -45,8 +45,9 @@ struct raw_dfa;
|
||||
|
||||
class sheng_build_strat : public accel_dfa_build_strat {
|
||||
public:
|
||||
sheng_build_strat(raw_dfa &rdfa_in, const ReportManager &rm_in)
|
||||
: accel_dfa_build_strat(rm_in), rdfa(rdfa_in) {}
|
||||
sheng_build_strat(raw_dfa &rdfa_in, const ReportManager &rm_in,
|
||||
bool only_accel_init_in)
|
||||
: accel_dfa_build_strat(rm_in, only_accel_init_in), rdfa(rdfa_in) {}
|
||||
raw_dfa &get_raw() const override { return rdfa; }
|
||||
std::unique_ptr<raw_report_info> gatherReports(
|
||||
std::vector<u32> &reports /* out */,
|
||||
@@ -63,7 +64,7 @@ private:
|
||||
};
|
||||
|
||||
bytecode_ptr<NFA> shengCompile(raw_dfa &raw, const CompileContext &cc,
|
||||
const ReportManager &rm,
|
||||
const ReportManager &rm, bool only_accel_init,
|
||||
std::set<dstate_id_t> *accel_states = nullptr);
|
||||
|
||||
struct sheng_escape_info {
|
||||
|
Reference in New Issue
Block a user