mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
fdr: use bytecode_ptr internally
This commit is contained in:
parent
6499d306ec
commit
97516eccb6
@ -151,18 +151,18 @@ aligned_unique_ptr<FDR> FDRCompiler::setupFDR() {
|
|||||||
auto confirmTmp = setupFullConfs(lits, eng, bucketToLits, make_small);
|
auto confirmTmp = setupFullConfs(lits, eng, bucketToLits, make_small);
|
||||||
|
|
||||||
assert(ISALIGNED_16(tabSize));
|
assert(ISALIGNED_16(tabSize));
|
||||||
assert(ISALIGNED_16(confirmTmp.second));
|
assert(ISALIGNED_16(confirmTmp.size()));
|
||||||
assert(ISALIGNED_16(floodControlTmp.second));
|
assert(ISALIGNED_16(floodControlTmp.size()));
|
||||||
size_t headerSize = ROUNDUP_16(sizeof(FDR));
|
size_t headerSize = ROUNDUP_16(sizeof(FDR));
|
||||||
size_t size = ROUNDUP_16(headerSize + tabSize + confirmTmp.second +
|
size_t size = ROUNDUP_16(headerSize + tabSize + confirmTmp.size() +
|
||||||
floodControlTmp.second);
|
floodControlTmp.size());
|
||||||
|
|
||||||
DEBUG_PRINTF("sizes base=%zu tabSize=%zu confirm=%zu floodControl=%zu "
|
DEBUG_PRINTF("sizes base=%zu tabSize=%zu confirm=%zu floodControl=%zu "
|
||||||
"total=%zu\n",
|
"total=%zu\n",
|
||||||
headerSize, tabSize, confirmTmp.second, floodControlTmp.second,
|
headerSize, tabSize, confirmTmp.size(), floodControlTmp.size(),
|
||||||
size);
|
size);
|
||||||
|
|
||||||
aligned_unique_ptr<FDR> fdr = aligned_zmalloc_unique<FDR>(size);
|
auto fdr = aligned_zmalloc_unique<FDR>(size);
|
||||||
assert(fdr); // otherwise would have thrown std::bad_alloc
|
assert(fdr); // otherwise would have thrown std::bad_alloc
|
||||||
|
|
||||||
fdr->size = size;
|
fdr->size = size;
|
||||||
@ -171,16 +171,16 @@ aligned_unique_ptr<FDR> FDRCompiler::setupFDR() {
|
|||||||
createInitialState(fdr.get());
|
createInitialState(fdr.get());
|
||||||
|
|
||||||
u8 *fdr_base = (u8 *)fdr.get();
|
u8 *fdr_base = (u8 *)fdr.get();
|
||||||
u8 * ptr = fdr_base + ROUNDUP_16(sizeof(FDR));
|
u8 *ptr = fdr_base + ROUNDUP_16(sizeof(FDR));
|
||||||
copy(tab.begin(), tab.end(), ptr);
|
copy(tab.begin(), tab.end(), ptr);
|
||||||
ptr += tabSize;
|
ptr += tabSize;
|
||||||
|
|
||||||
memcpy(ptr, confirmTmp.first.get(), confirmTmp.second);
|
memcpy(ptr, confirmTmp.get(), confirmTmp.size());
|
||||||
ptr += confirmTmp.second;
|
ptr += confirmTmp.size();
|
||||||
|
|
||||||
fdr->floodOffset = verify_u32(ptr - fdr_base);
|
fdr->floodOffset = verify_u32(ptr - fdr_base);
|
||||||
memcpy(ptr, floodControlTmp.first.get(), floodControlTmp.second);
|
memcpy(ptr, floodControlTmp.get(), floodControlTmp.size());
|
||||||
ptr += floodControlTmp.second;
|
ptr += floodControlTmp.size();
|
||||||
|
|
||||||
/* we are allowing domains 9 to 15 only */
|
/* we are allowing domains 9 to 15 only */
|
||||||
assert(eng.bits > 8 && eng.bits < 16);
|
assert(eng.bits > 8 && eng.bits < 16);
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
#include "ue2common.h"
|
#include "ue2common.h"
|
||||||
#include "hwlm/hwlm_literal.h"
|
#include "hwlm/hwlm_literal.h"
|
||||||
#include "util/alloc.h"
|
#include "util/bytecode_ptr.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@ -57,20 +57,20 @@ class FDREngineDescription;
|
|||||||
struct hwlmStreamingControl;
|
struct hwlmStreamingControl;
|
||||||
struct Grey;
|
struct Grey;
|
||||||
|
|
||||||
std::pair<aligned_unique_ptr<u8>, size_t> setupFullConfs(
|
bytecode_ptr<u8> setupFullConfs(const std::vector<hwlmLiteral> &lits,
|
||||||
const std::vector<hwlmLiteral> &lits, const EngineDescription &eng,
|
const EngineDescription &eng,
|
||||||
std::map<BucketIndex, std::vector<LiteralIndex>> &bucketToLits,
|
std::map<BucketIndex, std::vector<LiteralIndex>> &bucketToLits,
|
||||||
bool make_small);
|
bool make_small);
|
||||||
|
|
||||||
// all suffixes include an implicit max_bucket_width suffix to ensure that
|
// all suffixes include an implicit max_bucket_width suffix to ensure that
|
||||||
// we always read a full-scale flood "behind" us in terms of what's in our
|
// we always read a full-scale flood "behind" us in terms of what's in our
|
||||||
// state; if we don't have a flood that's long enough we won't be in the
|
// state; if we don't have a flood that's long enough we won't be in the
|
||||||
// right state yet to allow blindly advancing
|
// right state yet to allow blindly advancing
|
||||||
std::pair<aligned_unique_ptr<u8>, size_t>
|
bytecode_ptr<u8> setupFDRFloodControl(const std::vector<hwlmLiteral> &lits,
|
||||||
setupFDRFloodControl(const std::vector<hwlmLiteral> &lits,
|
const EngineDescription &eng,
|
||||||
const EngineDescription &eng, const Grey &grey);
|
const Grey &grey);
|
||||||
|
|
||||||
std::pair<aligned_unique_ptr<u8>, size_t>
|
bytecode_ptr<u8>
|
||||||
fdrBuildTableStreaming(const std::vector<hwlmLiteral> &lits,
|
fdrBuildTableStreaming(const std::vector<hwlmLiteral> &lits,
|
||||||
hwlmStreamingControl &stream_control);
|
hwlmStreamingControl &stream_control);
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ getFDRConfirm(const vector<hwlmLiteral> &lits, bool make_small,
|
|||||||
return {move(fdrc), actual_size};
|
return {move(fdrc), actual_size};
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<aligned_unique_ptr<u8>, size_t>
|
bytecode_ptr<u8>
|
||||||
setupFullConfs(const vector<hwlmLiteral> &lits,
|
setupFullConfs(const vector<hwlmLiteral> &lits,
|
||||||
const EngineDescription &eng,
|
const EngineDescription &eng,
|
||||||
map<BucketIndex, vector<LiteralIndex>> &bucketToLits,
|
map<BucketIndex, vector<LiteralIndex>> &bucketToLits,
|
||||||
@ -374,7 +374,7 @@ setupFullConfs(const vector<hwlmLiteral> &lits,
|
|||||||
u32 totalConfSwitchSize = nBuckets * sizeof(u32);
|
u32 totalConfSwitchSize = nBuckets * sizeof(u32);
|
||||||
u32 totalSize = ROUNDUP_16(totalConfSwitchSize + totalConfirmSize);
|
u32 totalSize = ROUNDUP_16(totalConfSwitchSize + totalConfirmSize);
|
||||||
|
|
||||||
auto buf = aligned_zmalloc_unique<u8>(totalSize);
|
auto buf = make_bytecode_ptr<u8>(totalSize, 16);
|
||||||
assert(buf); // otherwise would have thrown std::bad_alloc
|
assert(buf); // otherwise would have thrown std::bad_alloc
|
||||||
|
|
||||||
u32 *confBase = (u32 *)buf.get();
|
u32 *confBase = (u32 *)buf.get();
|
||||||
@ -389,7 +389,8 @@ setupFullConfs(const vector<hwlmLiteral> &lits,
|
|||||||
ptr += p.second;
|
ptr += p.second;
|
||||||
confBase[idx] = confirm_offset;
|
confBase[idx] = confirm_offset;
|
||||||
}
|
}
|
||||||
return {move(buf), totalSize};
|
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ue2
|
} // namespace ue2
|
||||||
|
@ -91,9 +91,9 @@ void addFlood(vector<FDRFlood> &tmpFlood, u8 c, const hwlmLiteral &lit,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<aligned_unique_ptr<u8>, size_t>
|
bytecode_ptr<u8> setupFDRFloodControl(const vector<hwlmLiteral> &lits,
|
||||||
setupFDRFloodControl(const vector<hwlmLiteral> &lits,
|
const EngineDescription &eng,
|
||||||
const EngineDescription &eng, const Grey &grey) {
|
const Grey &grey) {
|
||||||
vector<FDRFlood> tmpFlood(N_CHARS);
|
vector<FDRFlood> tmpFlood(N_CHARS);
|
||||||
u32 default_suffix = eng.getDefaultFloodSuffixLength();
|
u32 default_suffix = eng.getDefaultFloodSuffixLength();
|
||||||
|
|
||||||
@ -207,7 +207,7 @@ setupFDRFloodControl(const vector<hwlmLiteral> &lits,
|
|||||||
size_t floodStructSize = sizeof(FDRFlood) * nDistinctFloods;
|
size_t floodStructSize = sizeof(FDRFlood) * nDistinctFloods;
|
||||||
size_t totalSize = ROUNDUP_16(floodHeaderSize + floodStructSize);
|
size_t totalSize = ROUNDUP_16(floodHeaderSize + floodStructSize);
|
||||||
|
|
||||||
auto buf = aligned_zmalloc_unique<u8>(totalSize);
|
auto buf = make_bytecode_ptr<u8>(totalSize, 16);
|
||||||
assert(buf); // otherwise would have thrown std::bad_alloc
|
assert(buf); // otherwise would have thrown std::bad_alloc
|
||||||
|
|
||||||
u32 *floodHeader = (u32 *)buf.get();
|
u32 *floodHeader = (u32 *)buf.get();
|
||||||
@ -227,7 +227,7 @@ setupFDRFloodControl(const vector<hwlmLiteral> &lits,
|
|||||||
DEBUG_PRINTF("made a flood structure with %zu + %zu = %zu\n",
|
DEBUG_PRINTF("made a flood structure with %zu + %zu = %zu\n",
|
||||||
floodHeaderSize, floodStructSize, totalSize);
|
floodHeaderSize, floodStructSize, totalSize);
|
||||||
|
|
||||||
return {move(buf), totalSize};
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ue2
|
} // namespace ue2
|
||||||
|
@ -315,11 +315,11 @@ aligned_unique_ptr<FDR> TeddyCompiler::build() {
|
|||||||
|
|
||||||
size_t size = ROUNDUP_N(sizeof(Teddy) +
|
size_t size = ROUNDUP_N(sizeof(Teddy) +
|
||||||
maskLen +
|
maskLen +
|
||||||
confirmTmp.second +
|
confirmTmp.size() +
|
||||||
floodControlTmp.second,
|
floodControlTmp.size(),
|
||||||
16 * maskWidth);
|
16 * maskWidth);
|
||||||
|
|
||||||
aligned_unique_ptr<FDR> fdr = aligned_zmalloc_unique<FDR>(size);
|
auto fdr = aligned_zmalloc_unique<FDR>(size);
|
||||||
assert(fdr); // otherwise would have thrown std::bad_alloc
|
assert(fdr); // otherwise would have thrown std::bad_alloc
|
||||||
Teddy *teddy = (Teddy *)fdr.get(); // ugly
|
Teddy *teddy = (Teddy *)fdr.get(); // ugly
|
||||||
u8 *teddy_base = (u8 *)teddy;
|
u8 *teddy_base = (u8 *)teddy;
|
||||||
@ -329,12 +329,12 @@ aligned_unique_ptr<FDR> TeddyCompiler::build() {
|
|||||||
teddy->maxStringLen = verify_u32(maxLen(lits));
|
teddy->maxStringLen = verify_u32(maxLen(lits));
|
||||||
|
|
||||||
u8 *ptr = teddy_base + sizeof(Teddy) + maskLen;
|
u8 *ptr = teddy_base + sizeof(Teddy) + maskLen;
|
||||||
memcpy(ptr, confirmTmp.first.get(), confirmTmp.second);
|
memcpy(ptr, confirmTmp.get(), confirmTmp.size());
|
||||||
ptr += confirmTmp.second;
|
ptr += confirmTmp.size();
|
||||||
|
|
||||||
teddy->floodOffset = verify_u32(ptr - teddy_base);
|
teddy->floodOffset = verify_u32(ptr - teddy_base);
|
||||||
memcpy(ptr, floodControlTmp.first.get(), floodControlTmp.second);
|
memcpy(ptr, floodControlTmp.get(), floodControlTmp.size());
|
||||||
ptr += floodControlTmp.second;
|
ptr += floodControlTmp.size();
|
||||||
|
|
||||||
u8 *baseMsk = teddy_base + sizeof(Teddy);
|
u8 *baseMsk = teddy_base + sizeof(Teddy);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user