fdr: use bytecode_ptr in fdr/teddy compilers

This commit is contained in:
Justin Viiret 2017-03-20 17:26:49 +11:00 committed by Matthew Barr
parent 9996283112
commit 3590f73151
4 changed files with 42 additions and 43 deletions

View File

@ -30,8 +30,9 @@
* \brief FDR literal matcher: build API. * \brief FDR literal matcher: build API.
*/ */
#include "fdr_internal.h"
#include "fdr_compile.h" #include "fdr_compile.h"
#include "fdr_internal.h"
#include "fdr_confirm.h" #include "fdr_confirm.h"
#include "fdr_compile_internal.h" #include "fdr_compile_internal.h"
#include "fdr_engine_description.h" #include "fdr_engine_description.h"
@ -40,7 +41,6 @@
#include "grey.h" #include "grey.h"
#include "ue2common.h" #include "ue2common.h"
#include "hwlm/hwlm_build.h" #include "hwlm/hwlm_build.h"
#include "util/alloc.h"
#include "util/compare.h" #include "util/compare.h"
#include "util/dump_mask.h" #include "util/dump_mask.h"
#include "util/math.h" #include "util/math.h"
@ -86,7 +86,7 @@ private:
void dumpMasks(const u8 *defaultMask); void dumpMasks(const u8 *defaultMask);
#endif #endif
void setupTab(); void setupTab();
aligned_unique_ptr<FDR> setupFDR(); bytecode_ptr<FDR> setupFDR();
void createInitialState(FDR *fdr); void createInitialState(FDR *fdr);
public: public:
@ -95,7 +95,7 @@ public:
: eng(eng_in), grey(grey_in), tab(eng_in.getTabSizeBytes()), : eng(eng_in), grey(grey_in), tab(eng_in.getTabSizeBytes()),
lits(move(lits_in)), make_small(make_small_in) {} lits(move(lits_in)), make_small(make_small_in) {}
aligned_unique_ptr<FDR> build(); bytecode_ptr<FDR> build();
}; };
u8 *FDRCompiler::tabIndexToMask(u32 indexInTable) { 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(); size_t tabSize = eng.getTabSizeBytes();
auto floodControlTmp = setupFDRFloodControl(lits, eng, grey); auto floodControlTmp = setupFDRFloodControl(lits, eng, grey);
@ -162,7 +162,7 @@ aligned_unique_ptr<FDR> FDRCompiler::setupFDR() {
headerSize, tabSize, confirmTmp.size(), floodControlTmp.size(), headerSize, tabSize, confirmTmp.size(), floodControlTmp.size(),
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 assert(fdr); // otherwise would have thrown std::bad_alloc
fdr->size = size; fdr->size = size;
@ -528,7 +528,7 @@ void FDRCompiler::setupTab() {
#endif #endif
} }
aligned_unique_ptr<FDR> FDRCompiler::build() { bytecode_ptr<FDR> FDRCompiler::build() {
assignStringsToBuckets(); assignStringsToBuckets();
setupTab(); setupTab();
return setupFDR(); return setupFDR();
@ -537,9 +537,8 @@ aligned_unique_ptr<FDR> FDRCompiler::build() {
} // namespace } // namespace
static static
aligned_unique_ptr<FDR> fdrBuildTableInternal(const vector<hwlmLiteral> &lits, bytecode_ptr<FDR> fdrBuildTableInternal(const vector<hwlmLiteral> &lits,
bool make_small, bool make_small, const target_t &target,
const target_t &target,
const Grey &grey, u32 hint) { const Grey &grey, u32 hint) {
DEBUG_PRINTF("cpu has %s\n", target.has_avx2() ? "avx2" : "no-avx2"); DEBUG_PRINTF("cpu has %s\n", target.has_avx2() ? "avx2" : "no-avx2");
@ -553,10 +552,8 @@ aligned_unique_ptr<FDR> fdrBuildTableInternal(const vector<hwlmLiteral> &lits,
} }
} }
const unique_ptr<FDREngineDescription> des = auto des = (hint == HINT_INVALID) ? chooseEngine(target, lits, make_small)
(hint == HINT_INVALID) ? chooseEngine(target, lits, make_small)
: getFdrDescription(hint); : getFdrDescription(hint);
if (!des) { if (!des) {
return nullptr; return nullptr;
} }
@ -571,7 +568,7 @@ aligned_unique_ptr<FDR> fdrBuildTableInternal(const vector<hwlmLiteral> &lits,
return fc.build(); return fc.build();
} }
aligned_unique_ptr<FDR> fdrBuildTable(const vector<hwlmLiteral> &lits, bytecode_ptr<FDR> fdrBuildTable(const vector<hwlmLiteral> &lits,
bool make_small, const target_t &target, bool make_small, const target_t &target,
const Grey &grey) { const Grey &grey) {
return fdrBuildTableInternal(lits, make_small, target, grey, HINT_INVALID); return fdrBuildTableInternal(lits, make_small, target, grey, HINT_INVALID);
@ -579,7 +576,7 @@ aligned_unique_ptr<FDR> fdrBuildTable(const vector<hwlmLiteral> &lits,
#if !defined(RELEASE_BUILD) #if !defined(RELEASE_BUILD)
aligned_unique_ptr<FDR> fdrBuildTableHinted(const vector<hwlmLiteral> &lits, bytecode_ptr<FDR> fdrBuildTableHinted(const vector<hwlmLiteral> &lits,
bool make_small, u32 hint, bool make_small, u32 hint,
const target_t &target, const target_t &target,
const Grey &grey) { const Grey &grey) {

View File

@ -34,7 +34,7 @@
#define FDR_COMPILE_H #define FDR_COMPILE_H
#include "ue2common.h" #include "ue2common.h"
#include "util/alloc.h" #include "util/bytecode_ptr.h"
#include <vector> #include <vector>
@ -46,15 +46,15 @@ struct hwlmLiteral;
struct Grey; struct Grey;
struct target_t; struct target_t;
ue2::aligned_unique_ptr<FDR> bytecode_ptr<FDR> fdrBuildTable(const std::vector<hwlmLiteral> &lits,
fdrBuildTable(const std::vector<hwlmLiteral> &lits, bool make_small, bool make_small, const target_t &target,
const target_t &target, const Grey &grey); const Grey &grey);
#if !defined(RELEASE_BUILD) #if !defined(RELEASE_BUILD)
ue2::aligned_unique_ptr<FDR> bytecode_ptr<FDR> fdrBuildTableHinted(const std::vector<hwlmLiteral> &lits,
fdrBuildTableHinted(const std::vector<hwlmLiteral> &lits, bool make_small, bool make_small, u32 hint,
u32 hint, const target_t &target, const Grey &grey); const target_t &target, const Grey &grey);
#endif #endif

View File

@ -26,11 +26,15 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "teddy_compile.h"
#include "fdr.h" #include "fdr.h"
#include "fdr_internal.h" #include "fdr_internal.h"
#include "fdr_compile_internal.h" #include "fdr_compile_internal.h"
#include "fdr_confirm.h" #include "fdr_confirm.h"
#include "fdr_engine_description.h" #include "fdr_engine_description.h"
#include "teddy_internal.h"
#include "teddy_engine_description.h"
#include "grey.h" #include "grey.h"
#include "ue2common.h" #include "ue2common.h"
#include "util/alloc.h" #include "util/alloc.h"
@ -40,9 +44,6 @@
#include "util/target_info.h" #include "util/target_info.h"
#include "util/verify_types.h" #include "util/verify_types.h"
#include "teddy_compile.h"
#include "teddy_internal.h"
#include "teddy_engine_description.h"
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
@ -77,7 +78,7 @@ public:
: eng(eng_in), grey(grey_in), lits(lits_in), make_small(make_small_in) { : 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); bool pack(map<BucketIndex, std::vector<LiteralIndex> > &bucketToLits);
}; };
@ -277,7 +278,7 @@ bool TeddyCompiler::pack(map<BucketIndex,
return true; return true;
} }
aligned_unique_ptr<FDR> TeddyCompiler::build() { bytecode_ptr<FDR> TeddyCompiler::build() {
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;
@ -319,7 +320,7 @@ aligned_unique_ptr<FDR> TeddyCompiler::build() {
floodControlTmp.size(), floodControlTmp.size(),
16 * maskWidth); 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 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;
@ -418,7 +419,7 @@ aligned_unique_ptr<FDR> TeddyCompiler::build() {
} // namespace } // namespace
aligned_unique_ptr<FDR> teddyBuildTableHinted(const vector<hwlmLiteral> &lits, bytecode_ptr<FDR> teddyBuildTableHinted(const vector<hwlmLiteral> &lits,
bool make_small, u32 hint, bool make_small, u32 hint,
const target_t &target, const target_t &target,
const Grey &grey) { const Grey &grey) {

View File

@ -34,7 +34,7 @@
#define TEDDY_COMPILE_H #define TEDDY_COMPILE_H
#include "ue2common.h" #include "ue2common.h"
#include "util/alloc.h" #include "util/bytecode_ptr.h"
#include <vector> #include <vector>
@ -46,9 +46,10 @@ namespace ue2 {
struct Grey; struct Grey;
struct hwlmLiteral; struct hwlmLiteral;
ue2::aligned_unique_ptr<FDR> bytecode_ptr<FDR> teddyBuildTableHinted(const std::vector<hwlmLiteral> &lits,
teddyBuildTableHinted(const std::vector<hwlmLiteral> &lits, bool make_small, bool make_small, u32 hint,
u32 hint, const target_t &target, const Grey &grey); const target_t &target,
const Grey &grey);
} // namespace ue2 } // namespace ue2