void dumpMasks(const u8 *defaultMask);
#endif
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);
public:
: eng(eng_in), tab(eng_in.getTabSizeBytes()), 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);
};
u8 *FDRCompiler::tabIndexToMask(u32 indexInTable) {
}
}
-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();
auto floodControlTmp = setupFDRFloodControl(lits, eng);
if (link.first) {
fdr->link = verify_u32(ptr - fdr_base);
- memcpy(ptr, link.first, link.second);
- aligned_free(link.first);
+ memcpy(ptr, link.first.get(), link.second);
} else {
fdr->link = 0;
}
#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();
setupTab();
return setupFDR(link);
fdrBuildTableInternal(const vector<hwlmLiteral> &lits, bool make_small,
const target_t &target, const Grey &grey, u32 hint,
hwlmStreamingControl *stream_control) {
- pair<u8 *, size_t> link(nullptr, 0);
+ pair<aligned_unique_ptr<u8>, size_t> link(nullptr, 0);
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");
if (grey.fdrAllowTeddy) {
- aligned_unique_ptr<FDR> fdr
- = teddyBuildTableHinted(lits, make_small, hint, target, link);
+ auto fdr = teddyBuildTableHinted(lits, make_small, hint, target, link);
if (fdr) {
DEBUG_PRINTF("build with teddy succeeded\n");
return fdr;
setupFDRFloodControl(const std::vector<hwlmLiteral> &lits,
const EngineDescription &eng);
-std::pair<u8 *, size_t>
+std::pair<aligned_unique_ptr<u8>, size_t>
fdrBuildTableStreaming(const std::vector<hwlmLiteral> &lits,
- hwlmStreamingControl *stream_control);
+ hwlmStreamingControl &stream_control);
static constexpr u32 HINT_INVALID = 0xffffffff;
return rv;
}
-pair<u8 *, size_t>
+pair<aligned_unique_ptr<u8>, size_t>
fdrBuildTableStreaming(const vector<hwlmLiteral> &lits,
- hwlmStreamingControl *stream_control) {
+ hwlmStreamingControl &stream_control) {
// refuse to compile if we are forced to have smaller than minimum
// history required for long-literal support, full stop
// otherwise, choose the maximum of the preferred history quantity
// (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;
- 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");
}
size_t max_len =
- MIN(stream_control->history_max,
- MAX(MIN_HISTORY_REQUIRED, stream_control->history_min));
+ MIN(stream_control.history_max,
+ MAX(MIN_HISTORY_REQUIRED, stream_control.history_min));
assert(max_len >= MIN_HISTORY_REQUIRED);
size_t max_mask_len = maxMaskLen(lits);
// we want enough history to manage the longest literal and the longest
// mask.
- stream_control->literal_history_required =
+ stream_control.literal_history_required =
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});
}
streamBits[CASELESS] = lg2(roundUpToPowerOfTwo(positions[CASELESS] + 2));
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
// then fill it in
- u8 * ptr = secondaryTable;
+ u8 * ptr = secondaryTable.get();
FDRSTableHeader * header = (FDRSTableHeader *)ptr;
// fill in header
header->pseudoEngineID = (u32)0xffffffff;
e = long_lits.end();
i != e; ++i) {
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
litTabPtr[entry].offset = offset;
}
// 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
- ptr = secondaryTable + htOffset[CASEFUL];
+ ptr = secondaryTable.get() + htOffset[CASEFUL];
for (u32 m = CASEFUL; m < MAX_MODES; ++m) {
fillHashes(long_lits, max_len, (FDRSHashEntry *)ptr, hashEntries[m],
(MODES)m, litToOffsetVal);
}
// tell the world what we did
- stream_control->literal_history_required = max_len;
- stream_control->literal_stream_state_required = tot_state_bytes;
- return make_pair(secondaryTable, tabSize);
+ stream_control.literal_history_required = max_len;
+ stream_control.literal_stream_state_required = tot_state_bytes;
+ return make_pair(move(secondaryTable), tabSize);
}
} // namespace ue2
const TeddyEngineDescription &eng_in, bool 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);
};
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) {
DEBUG_PRINTF("too many literals: %zu\n", lits.size());
return nullptr;
if (link.first) {
teddy->link = verify_u32(ptr - teddy_base);
- memcpy(ptr, link.first, link.second);
- aligned_free(link.first);
+ memcpy(ptr, link.first.get(), link.second);
} else {
teddy->link = 0;
}
} // namespace
-aligned_unique_ptr<FDR> teddyBuildTableHinted(const vector<hwlmLiteral> &lits,
- bool make_small, u32 hint,
- const target_t &target,
- pair<u8 *, size_t> link) {
+aligned_unique_ptr<FDR>
+teddyBuildTableHinted(const vector<hwlmLiteral> &lits, bool make_small,
+ u32 hint, const target_t &target,
+ pair<aligned_unique_ptr<u8>, size_t> &link) {
unique_ptr<TeddyEngineDescription> des;
if (hint == HINT_INVALID) {
des = chooseTeddyEngine(target, lits);
/*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
ue2::aligned_unique_ptr<FDR>
teddyBuildTableHinted(const std::vector<hwlmLiteral> &lits, bool make_small,
u32 hint, const target_t &target,
- std::pair<u8 *, size_t> link);
+ std::pair<aligned_unique_ptr<u8>, size_t> &link);
} // namespace ue2