mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-07-12 21:44:44 +03:00
fdr: use bytecode_ptr in fdr/teddy compilers
This commit is contained in:
parent
9996283112
commit
3590f73151
@ -30,8 +30,9 @@
|
||||
* \brief FDR literal matcher: build API.
|
||||
*/
|
||||
|
||||
#include "fdr_internal.h"
|
||||
#include "fdr_compile.h"
|
||||
|
||||
#include "fdr_internal.h"
|
||||
#include "fdr_confirm.h"
|
||||
#include "fdr_compile_internal.h"
|
||||
#include "fdr_engine_description.h"
|
||||
@ -40,7 +41,6 @@
|
||||
#include "grey.h"
|
||||
#include "ue2common.h"
|
||||
#include "hwlm/hwlm_build.h"
|
||||
#include "util/alloc.h"
|
||||
#include "util/compare.h"
|
||||
#include "util/dump_mask.h"
|
||||
#include "util/math.h"
|
||||
@ -86,7 +86,7 @@ private:
|
||||
void dumpMasks(const u8 *defaultMask);
|
||||
#endif
|
||||
void setupTab();
|
||||
aligned_unique_ptr<FDR> setupFDR();
|
||||
bytecode_ptr<FDR> setupFDR();
|
||||
void createInitialState(FDR *fdr);
|
||||
|
||||
public:
|
||||
@ -95,7 +95,7 @@ public:
|
||||
: eng(eng_in), grey(grey_in), tab(eng_in.getTabSizeBytes()),
|
||||
lits(move(lits_in)), make_small(make_small_in) {}
|
||||
|
||||
aligned_unique_ptr<FDR> build();
|
||||
bytecode_ptr<FDR> build();
|
||||
};
|
||||
|
||||
u8 *FDRCompiler::tabIndexToMask(u32 indexInTable) {
|
||||
@ -144,7 +144,7 @@ void FDRCompiler::createInitialState(FDR *fdr) {
|
||||
}
|
||||
}
|
||||
|
||||
aligned_unique_ptr<FDR> FDRCompiler::setupFDR() {
|
||||
bytecode_ptr<FDR> FDRCompiler::setupFDR() {
|
||||
size_t tabSize = eng.getTabSizeBytes();
|
||||
|
||||
auto floodControlTmp = setupFDRFloodControl(lits, eng, grey);
|
||||
@ -162,7 +162,7 @@ aligned_unique_ptr<FDR> FDRCompiler::setupFDR() {
|
||||
headerSize, tabSize, confirmTmp.size(), floodControlTmp.size(),
|
||||
size);
|
||||
|
||||
auto fdr = aligned_zmalloc_unique<FDR>(size);
|
||||
auto fdr = make_bytecode_ptr<FDR>(size, 64);
|
||||
assert(fdr); // otherwise would have thrown std::bad_alloc
|
||||
|
||||
fdr->size = size;
|
||||
@ -528,7 +528,7 @@ void FDRCompiler::setupTab() {
|
||||
#endif
|
||||
}
|
||||
|
||||
aligned_unique_ptr<FDR> FDRCompiler::build() {
|
||||
bytecode_ptr<FDR> FDRCompiler::build() {
|
||||
assignStringsToBuckets();
|
||||
setupTab();
|
||||
return setupFDR();
|
||||
@ -537,10 +537,9 @@ aligned_unique_ptr<FDR> FDRCompiler::build() {
|
||||
} // namespace
|
||||
|
||||
static
|
||||
aligned_unique_ptr<FDR> fdrBuildTableInternal(const vector<hwlmLiteral> &lits,
|
||||
bool make_small,
|
||||
const target_t &target,
|
||||
const Grey &grey, u32 hint) {
|
||||
bytecode_ptr<FDR> fdrBuildTableInternal(const vector<hwlmLiteral> &lits,
|
||||
bool make_small, const target_t &target,
|
||||
const Grey &grey, u32 hint) {
|
||||
DEBUG_PRINTF("cpu has %s\n", target.has_avx2() ? "avx2" : "no-avx2");
|
||||
|
||||
if (grey.fdrAllowTeddy) {
|
||||
@ -553,10 +552,8 @@ aligned_unique_ptr<FDR> fdrBuildTableInternal(const vector<hwlmLiteral> &lits,
|
||||
}
|
||||
}
|
||||
|
||||
const unique_ptr<FDREngineDescription> des =
|
||||
(hint == HINT_INVALID) ? chooseEngine(target, lits, make_small)
|
||||
: getFdrDescription(hint);
|
||||
|
||||
auto des = (hint == HINT_INVALID) ? chooseEngine(target, lits, make_small)
|
||||
: getFdrDescription(hint);
|
||||
if (!des) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -571,18 +568,18 @@ aligned_unique_ptr<FDR> fdrBuildTableInternal(const vector<hwlmLiteral> &lits,
|
||||
return fc.build();
|
||||
}
|
||||
|
||||
aligned_unique_ptr<FDR> fdrBuildTable(const vector<hwlmLiteral> &lits,
|
||||
bool make_small, const target_t &target,
|
||||
const Grey &grey) {
|
||||
bytecode_ptr<FDR> fdrBuildTable(const vector<hwlmLiteral> &lits,
|
||||
bool make_small, const target_t &target,
|
||||
const Grey &grey) {
|
||||
return fdrBuildTableInternal(lits, make_small, target, grey, HINT_INVALID);
|
||||
}
|
||||
|
||||
#if !defined(RELEASE_BUILD)
|
||||
|
||||
aligned_unique_ptr<FDR> fdrBuildTableHinted(const vector<hwlmLiteral> &lits,
|
||||
bool make_small, u32 hint,
|
||||
const target_t &target,
|
||||
const Grey &grey) {
|
||||
bytecode_ptr<FDR> fdrBuildTableHinted(const vector<hwlmLiteral> &lits,
|
||||
bool make_small, u32 hint,
|
||||
const target_t &target,
|
||||
const Grey &grey) {
|
||||
return fdrBuildTableInternal(lits, make_small, target, grey, hint);
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
||||
#define FDR_COMPILE_H
|
||||
|
||||
#include "ue2common.h"
|
||||
#include "util/alloc.h"
|
||||
#include "util/bytecode_ptr.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@ -46,15 +46,15 @@ struct hwlmLiteral;
|
||||
struct Grey;
|
||||
struct target_t;
|
||||
|
||||
ue2::aligned_unique_ptr<FDR>
|
||||
fdrBuildTable(const std::vector<hwlmLiteral> &lits, bool make_small,
|
||||
const target_t &target, const Grey &grey);
|
||||
bytecode_ptr<FDR> fdrBuildTable(const std::vector<hwlmLiteral> &lits,
|
||||
bool make_small, const target_t &target,
|
||||
const Grey &grey);
|
||||
|
||||
#if !defined(RELEASE_BUILD)
|
||||
|
||||
ue2::aligned_unique_ptr<FDR>
|
||||
fdrBuildTableHinted(const std::vector<hwlmLiteral> &lits, bool make_small,
|
||||
u32 hint, const target_t &target, const Grey &grey);
|
||||
bytecode_ptr<FDR> fdrBuildTableHinted(const std::vector<hwlmLiteral> &lits,
|
||||
bool make_small, u32 hint,
|
||||
const target_t &target, const Grey &grey);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -26,11 +26,15 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "teddy_compile.h"
|
||||
|
||||
#include "fdr.h"
|
||||
#include "fdr_internal.h"
|
||||
#include "fdr_compile_internal.h"
|
||||
#include "fdr_confirm.h"
|
||||
#include "fdr_engine_description.h"
|
||||
#include "teddy_internal.h"
|
||||
#include "teddy_engine_description.h"
|
||||
#include "grey.h"
|
||||
#include "ue2common.h"
|
||||
#include "util/alloc.h"
|
||||
@ -40,9 +44,6 @@
|
||||
#include "util/target_info.h"
|
||||
#include "util/verify_types.h"
|
||||
|
||||
#include "teddy_compile.h"
|
||||
#include "teddy_internal.h"
|
||||
#include "teddy_engine_description.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
@ -77,7 +78,7 @@ public:
|
||||
: eng(eng_in), grey(grey_in), lits(lits_in), make_small(make_small_in) {
|
||||
}
|
||||
|
||||
aligned_unique_ptr<FDR> build();
|
||||
bytecode_ptr<FDR> build();
|
||||
bool pack(map<BucketIndex, std::vector<LiteralIndex> > &bucketToLits);
|
||||
};
|
||||
|
||||
@ -277,7 +278,7 @@ bool TeddyCompiler::pack(map<BucketIndex,
|
||||
return true;
|
||||
}
|
||||
|
||||
aligned_unique_ptr<FDR> TeddyCompiler::build() {
|
||||
bytecode_ptr<FDR> TeddyCompiler::build() {
|
||||
if (lits.size() > eng.getNumBuckets() * TEDDY_BUCKET_LOAD) {
|
||||
DEBUG_PRINTF("too many literals: %zu\n", lits.size());
|
||||
return nullptr;
|
||||
@ -319,7 +320,7 @@ aligned_unique_ptr<FDR> TeddyCompiler::build() {
|
||||
floodControlTmp.size(),
|
||||
16 * maskWidth);
|
||||
|
||||
auto fdr = aligned_zmalloc_unique<FDR>(size);
|
||||
auto fdr = make_bytecode_ptr<FDR>(size, 64);
|
||||
assert(fdr); // otherwise would have thrown std::bad_alloc
|
||||
Teddy *teddy = (Teddy *)fdr.get(); // ugly
|
||||
u8 *teddy_base = (u8 *)teddy;
|
||||
@ -418,10 +419,10 @@ aligned_unique_ptr<FDR> TeddyCompiler::build() {
|
||||
|
||||
} // namespace
|
||||
|
||||
aligned_unique_ptr<FDR> teddyBuildTableHinted(const vector<hwlmLiteral> &lits,
|
||||
bool make_small, u32 hint,
|
||||
const target_t &target,
|
||||
const Grey &grey) {
|
||||
bytecode_ptr<FDR> teddyBuildTableHinted(const vector<hwlmLiteral> &lits,
|
||||
bool make_small, u32 hint,
|
||||
const target_t &target,
|
||||
const Grey &grey) {
|
||||
unique_ptr<TeddyEngineDescription> des;
|
||||
if (hint == HINT_INVALID) {
|
||||
des = chooseTeddyEngine(target, lits);
|
||||
|
@ -34,7 +34,7 @@
|
||||
#define TEDDY_COMPILE_H
|
||||
|
||||
#include "ue2common.h"
|
||||
#include "util/alloc.h"
|
||||
#include "util/bytecode_ptr.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@ -46,9 +46,10 @@ namespace ue2 {
|
||||
struct Grey;
|
||||
struct hwlmLiteral;
|
||||
|
||||
ue2::aligned_unique_ptr<FDR>
|
||||
teddyBuildTableHinted(const std::vector<hwlmLiteral> &lits, bool make_small,
|
||||
u32 hint, const target_t &target, const Grey &grey);
|
||||
bytecode_ptr<FDR> teddyBuildTableHinted(const std::vector<hwlmLiteral> &lits,
|
||||
bool make_small, u32 hint,
|
||||
const target_t &target,
|
||||
const Grey &grey);
|
||||
|
||||
} // namespace ue2
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user