mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
fdr/teddy: switch over remaining smart ptrs
This commit is contained in:
parent
aebbd4f169
commit
57cd2331f5
@ -81,7 +81,7 @@ private:
|
|||||||
void dumpMasks(const u8 *defaultMask);
|
void dumpMasks(const u8 *defaultMask);
|
||||||
#endif
|
#endif
|
||||||
void setupTab();
|
void setupTab();
|
||||||
aligned_unique_ptr<FDR> setupFDR(pair<u8 *, size_t> link);
|
aligned_unique_ptr<FDR> setupFDR(pair<aligned_unique_ptr<u8>, size_t> &link);
|
||||||
void createInitialState(FDR *fdr);
|
void createInitialState(FDR *fdr);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -90,7 +90,7 @@ public:
|
|||||||
: eng(eng_in), tab(eng_in.getTabSizeBytes()), lits(lits_in),
|
: eng(eng_in), tab(eng_in.getTabSizeBytes()), lits(lits_in),
|
||||||
make_small(make_small_in) {}
|
make_small(make_small_in) {}
|
||||||
|
|
||||||
aligned_unique_ptr<FDR> build(pair<u8 *, size_t> link);
|
aligned_unique_ptr<FDR> build(pair<aligned_unique_ptr<u8>, size_t> &link);
|
||||||
};
|
};
|
||||||
|
|
||||||
u8 *FDRCompiler::tabIndexToMask(u32 indexInTable) {
|
u8 *FDRCompiler::tabIndexToMask(u32 indexInTable) {
|
||||||
@ -141,7 +141,8 @@ void FDRCompiler::createInitialState(FDR *fdr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
aligned_unique_ptr<FDR> FDRCompiler::setupFDR(pair<u8 *, size_t> link) {
|
aligned_unique_ptr<FDR>
|
||||||
|
FDRCompiler::setupFDR(pair<aligned_unique_ptr<u8>, size_t> &link) {
|
||||||
size_t tabSize = eng.getTabSizeBytes();
|
size_t tabSize = eng.getTabSizeBytes();
|
||||||
|
|
||||||
auto floodControlTmp = setupFDRFloodControl(lits, eng);
|
auto floodControlTmp = setupFDRFloodControl(lits, eng);
|
||||||
@ -189,8 +190,7 @@ aligned_unique_ptr<FDR> FDRCompiler::setupFDR(pair<u8 *, size_t> link) {
|
|||||||
|
|
||||||
if (link.first) {
|
if (link.first) {
|
||||||
fdr->link = verify_u32(ptr - fdr_base);
|
fdr->link = verify_u32(ptr - fdr_base);
|
||||||
memcpy(ptr, link.first, link.second);
|
memcpy(ptr, link.first.get(), link.second);
|
||||||
aligned_free(link.first);
|
|
||||||
} else {
|
} else {
|
||||||
fdr->link = 0;
|
fdr->link = 0;
|
||||||
}
|
}
|
||||||
@ -498,7 +498,8 @@ void FDRCompiler::setupTab() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
aligned_unique_ptr<FDR> FDRCompiler::build(pair<u8 *, size_t> link) {
|
aligned_unique_ptr<FDR>
|
||||||
|
FDRCompiler::build(pair<aligned_unique_ptr<u8>, size_t> &link) {
|
||||||
assignStringsToBuckets();
|
assignStringsToBuckets();
|
||||||
setupTab();
|
setupTab();
|
||||||
return setupFDR(link);
|
return setupFDR(link);
|
||||||
@ -511,16 +512,15 @@ aligned_unique_ptr<FDR>
|
|||||||
fdrBuildTableInternal(const vector<hwlmLiteral> &lits, bool make_small,
|
fdrBuildTableInternal(const vector<hwlmLiteral> &lits, bool make_small,
|
||||||
const target_t &target, const Grey &grey, u32 hint,
|
const target_t &target, const Grey &grey, u32 hint,
|
||||||
hwlmStreamingControl *stream_control) {
|
hwlmStreamingControl *stream_control) {
|
||||||
pair<u8 *, size_t> link(nullptr, 0);
|
pair<aligned_unique_ptr<u8>, size_t> link(nullptr, 0);
|
||||||
if (stream_control) {
|
if (stream_control) {
|
||||||
link = fdrBuildTableStreaming(lits, stream_control);
|
link = fdrBuildTableStreaming(lits, *stream_control);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_PRINTF("cpu has %s\n", target.has_avx2() ? "avx2" : "no-avx2");
|
DEBUG_PRINTF("cpu has %s\n", target.has_avx2() ? "avx2" : "no-avx2");
|
||||||
|
|
||||||
if (grey.fdrAllowTeddy) {
|
if (grey.fdrAllowTeddy) {
|
||||||
aligned_unique_ptr<FDR> fdr
|
auto fdr = teddyBuildTableHinted(lits, make_small, hint, target, link);
|
||||||
= teddyBuildTableHinted(lits, make_small, hint, target, link);
|
|
||||||
if (fdr) {
|
if (fdr) {
|
||||||
DEBUG_PRINTF("build with teddy succeeded\n");
|
DEBUG_PRINTF("build with teddy succeeded\n");
|
||||||
return fdr;
|
return fdr;
|
||||||
|
@ -70,9 +70,9 @@ std::pair<aligned_unique_ptr<u8>, size_t>
|
|||||||
setupFDRFloodControl(const std::vector<hwlmLiteral> &lits,
|
setupFDRFloodControl(const std::vector<hwlmLiteral> &lits,
|
||||||
const EngineDescription &eng);
|
const EngineDescription &eng);
|
||||||
|
|
||||||
std::pair<u8 *, size_t>
|
std::pair<aligned_unique_ptr<u8>, size_t>
|
||||||
fdrBuildTableStreaming(const std::vector<hwlmLiteral> &lits,
|
fdrBuildTableStreaming(const std::vector<hwlmLiteral> &lits,
|
||||||
hwlmStreamingControl *stream_control);
|
hwlmStreamingControl &stream_control);
|
||||||
|
|
||||||
static constexpr u32 HINT_INVALID = 0xffffffff;
|
static constexpr u32 HINT_INVALID = 0xffffffff;
|
||||||
|
|
||||||
|
@ -306,24 +306,24 @@ size_t maxMaskLen(const vector<hwlmLiteral> &lits) {
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<u8 *, size_t>
|
pair<aligned_unique_ptr<u8>, size_t>
|
||||||
fdrBuildTableStreaming(const vector<hwlmLiteral> &lits,
|
fdrBuildTableStreaming(const vector<hwlmLiteral> &lits,
|
||||||
hwlmStreamingControl *stream_control) {
|
hwlmStreamingControl &stream_control) {
|
||||||
// refuse to compile if we are forced to have smaller than minimum
|
// refuse to compile if we are forced to have smaller than minimum
|
||||||
// history required for long-literal support, full stop
|
// history required for long-literal support, full stop
|
||||||
// otherwise, choose the maximum of the preferred history quantity
|
// otherwise, choose the maximum of the preferred history quantity
|
||||||
// (currently a fairly extravagant 32) or the already used history
|
// (currently a fairly extravagant 32) or the already used history
|
||||||
// quantity - subject to the limitation of stream_control->history_max
|
// quantity - subject to the limitation of stream_control.history_max
|
||||||
|
|
||||||
const size_t MIN_HISTORY_REQUIRED = 32;
|
const size_t MIN_HISTORY_REQUIRED = 32;
|
||||||
|
|
||||||
if (MIN_HISTORY_REQUIRED > stream_control->history_max) {
|
if (MIN_HISTORY_REQUIRED > stream_control.history_max) {
|
||||||
throw std::logic_error("Cannot set history to minimum history required");
|
throw std::logic_error("Cannot set history to minimum history required");
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t max_len =
|
size_t max_len =
|
||||||
MIN(stream_control->history_max,
|
MIN(stream_control.history_max,
|
||||||
MAX(MIN_HISTORY_REQUIRED, stream_control->history_min));
|
MAX(MIN_HISTORY_REQUIRED, stream_control.history_min));
|
||||||
assert(max_len >= MIN_HISTORY_REQUIRED);
|
assert(max_len >= MIN_HISTORY_REQUIRED);
|
||||||
size_t max_mask_len = maxMaskLen(lits);
|
size_t max_mask_len = maxMaskLen(lits);
|
||||||
|
|
||||||
@ -334,9 +334,9 @@ fdrBuildTableStreaming(const vector<hwlmLiteral> &lits,
|
|||||||
|
|
||||||
// we want enough history to manage the longest literal and the longest
|
// we want enough history to manage the longest literal and the longest
|
||||||
// mask.
|
// mask.
|
||||||
stream_control->literal_history_required =
|
stream_control.literal_history_required =
|
||||||
max(maxLen(lits), max_mask_len) - 1;
|
max(maxLen(lits), max_mask_len) - 1;
|
||||||
stream_control->literal_stream_state_required = 0;
|
stream_control.literal_stream_state_required = 0;
|
||||||
return make_pair(nullptr, size_t{0});
|
return make_pair(nullptr, size_t{0});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,11 +381,11 @@ fdrBuildTableStreaming(const vector<hwlmLiteral> &lits,
|
|||||||
streamBits[CASELESS] = lg2(roundUpToPowerOfTwo(positions[CASELESS] + 2));
|
streamBits[CASELESS] = lg2(roundUpToPowerOfTwo(positions[CASELESS] + 2));
|
||||||
u32 tot_state_bytes = (streamBits[CASEFUL] + streamBits[CASELESS] + 7) / 8;
|
u32 tot_state_bytes = (streamBits[CASEFUL] + streamBits[CASELESS] + 7) / 8;
|
||||||
|
|
||||||
u8 * secondaryTable = (u8 *)aligned_zmalloc(tabSize);
|
auto secondaryTable = aligned_zmalloc_unique<u8>(tabSize);
|
||||||
assert(secondaryTable); // otherwise would have thrown std::bad_alloc
|
assert(secondaryTable); // otherwise would have thrown std::bad_alloc
|
||||||
|
|
||||||
// then fill it in
|
// then fill it in
|
||||||
u8 * ptr = secondaryTable;
|
u8 * ptr = secondaryTable.get();
|
||||||
FDRSTableHeader * header = (FDRSTableHeader *)ptr;
|
FDRSTableHeader * header = (FDRSTableHeader *)ptr;
|
||||||
// fill in header
|
// fill in header
|
||||||
header->pseudoEngineID = (u32)0xffffffff;
|
header->pseudoEngineID = (u32)0xffffffff;
|
||||||
@ -411,7 +411,7 @@ fdrBuildTableStreaming(const vector<hwlmLiteral> &lits,
|
|||||||
e = long_lits.end();
|
e = long_lits.end();
|
||||||
i != e; ++i) {
|
i != e; ++i) {
|
||||||
u32 entry = verify_u32(i - long_lits.begin());
|
u32 entry = verify_u32(i - long_lits.begin());
|
||||||
u32 offset = verify_u32(ptr - secondaryTable);
|
u32 offset = verify_u32(ptr - secondaryTable.get());
|
||||||
|
|
||||||
// point the table entry to the string location
|
// point the table entry to the string location
|
||||||
litTabPtr[entry].offset = offset;
|
litTabPtr[entry].offset = offset;
|
||||||
@ -425,10 +425,10 @@ fdrBuildTableStreaming(const vector<hwlmLiteral> &lits,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fill in final lit table entry with current ptr (serves as end value)
|
// fill in final lit table entry with current ptr (serves as end value)
|
||||||
litTabPtr[long_lits.size()].offset = verify_u32(ptr - secondaryTable);
|
litTabPtr[long_lits.size()].offset = verify_u32(ptr - secondaryTable.get());
|
||||||
|
|
||||||
// fill hash tables
|
// fill hash tables
|
||||||
ptr = secondaryTable + htOffset[CASEFUL];
|
ptr = secondaryTable.get() + htOffset[CASEFUL];
|
||||||
for (u32 m = CASEFUL; m < MAX_MODES; ++m) {
|
for (u32 m = CASEFUL; m < MAX_MODES; ++m) {
|
||||||
fillHashes(long_lits, max_len, (FDRSHashEntry *)ptr, hashEntries[m],
|
fillHashes(long_lits, max_len, (FDRSHashEntry *)ptr, hashEntries[m],
|
||||||
(MODES)m, litToOffsetVal);
|
(MODES)m, litToOffsetVal);
|
||||||
@ -436,9 +436,9 @@ fdrBuildTableStreaming(const vector<hwlmLiteral> &lits,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// tell the world what we did
|
// tell the world what we did
|
||||||
stream_control->literal_history_required = max_len;
|
stream_control.literal_history_required = max_len;
|
||||||
stream_control->literal_stream_state_required = tot_state_bytes;
|
stream_control.literal_stream_state_required = tot_state_bytes;
|
||||||
return make_pair(secondaryTable, tabSize);
|
return make_pair(move(secondaryTable), tabSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ue2
|
} // namespace ue2
|
||||||
|
@ -74,7 +74,7 @@ public:
|
|||||||
const TeddyEngineDescription &eng_in, bool make_small_in)
|
const TeddyEngineDescription &eng_in, bool make_small_in)
|
||||||
: eng(eng_in), lits(lits_in), make_small(make_small_in) {}
|
: eng(eng_in), lits(lits_in), make_small(make_small_in) {}
|
||||||
|
|
||||||
aligned_unique_ptr<FDR> build(pair<u8 *, size_t> link);
|
aligned_unique_ptr<FDR> build(pair<aligned_unique_ptr<u8>, size_t> &link);
|
||||||
bool pack(map<BucketIndex, std::vector<LiteralIndex> > &bucketToLits);
|
bool pack(map<BucketIndex, std::vector<LiteralIndex> > &bucketToLits);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -281,7 +281,8 @@ bool TeddyCompiler::pack(map<BucketIndex,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
aligned_unique_ptr<FDR> TeddyCompiler::build(pair<u8 *, size_t> link) {
|
aligned_unique_ptr<FDR>
|
||||||
|
TeddyCompiler::build(pair<aligned_unique_ptr<u8>, size_t> &link) {
|
||||||
if (lits.size() > eng.getNumBuckets() * TEDDY_BUCKET_LOAD) {
|
if (lits.size() > eng.getNumBuckets() * TEDDY_BUCKET_LOAD) {
|
||||||
DEBUG_PRINTF("too many literals: %zu\n", lits.size());
|
DEBUG_PRINTF("too many literals: %zu\n", lits.size());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -342,8 +343,7 @@ aligned_unique_ptr<FDR> TeddyCompiler::build(pair<u8 *, size_t> link) {
|
|||||||
|
|
||||||
if (link.first) {
|
if (link.first) {
|
||||||
teddy->link = verify_u32(ptr - teddy_base);
|
teddy->link = verify_u32(ptr - teddy_base);
|
||||||
memcpy(ptr, link.first, link.second);
|
memcpy(ptr, link.first.get(), link.second);
|
||||||
aligned_free(link.first);
|
|
||||||
} else {
|
} else {
|
||||||
teddy->link = 0;
|
teddy->link = 0;
|
||||||
}
|
}
|
||||||
@ -436,10 +436,10 @@ aligned_unique_ptr<FDR> TeddyCompiler::build(pair<u8 *, size_t> link) {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
aligned_unique_ptr<FDR> teddyBuildTableHinted(const vector<hwlmLiteral> &lits,
|
aligned_unique_ptr<FDR>
|
||||||
bool make_small, u32 hint,
|
teddyBuildTableHinted(const vector<hwlmLiteral> &lits, bool make_small,
|
||||||
const target_t &target,
|
u32 hint, const target_t &target,
|
||||||
pair<u8 *, size_t> link) {
|
pair<aligned_unique_ptr<u8>, size_t> &link) {
|
||||||
unique_ptr<TeddyEngineDescription> des;
|
unique_ptr<TeddyEngineDescription> des;
|
||||||
if (hint == HINT_INVALID) {
|
if (hint == HINT_INVALID) {
|
||||||
des = chooseTeddyEngine(target, lits);
|
des = chooseTeddyEngine(target, lits);
|
||||||
|
@ -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:
|
||||||
@ -49,7 +49,7 @@ struct hwlmLiteral;
|
|||||||
ue2::aligned_unique_ptr<FDR>
|
ue2::aligned_unique_ptr<FDR>
|
||||||
teddyBuildTableHinted(const std::vector<hwlmLiteral> &lits, bool make_small,
|
teddyBuildTableHinted(const std::vector<hwlmLiteral> &lits, bool make_small,
|
||||||
u32 hint, const target_t &target,
|
u32 hint, const target_t &target,
|
||||||
std::pair<u8 *, size_t> link);
|
std::pair<aligned_unique_ptr<u8>, size_t> &link);
|
||||||
|
|
||||||
} // namespace ue2
|
} // namespace ue2
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user