static rose_inline
void recordAnchoredLiteralMatch(const struct RoseEngine *t,
- struct hs_scratch *scratch, u32 literal_id,
+ struct hs_scratch *scratch, u32 anch_id,
u64a end) {
assert(end);
struct fatbit **anchoredLiteralRows = getAnchoredLiteralLog(scratch);
- DEBUG_PRINTF("record %u @ %llu\n", literal_id, end);
+ DEBUG_PRINTF("record %u (of %u) @ %llu\n", anch_id, t->anchored_count, end);
if (!bf64_set(&scratch->al_log_sum, end - 1)) {
// first time, clear row
fatbit_clear(anchoredLiteralRows[end - 1]);
}
- u32 rel_idx = literal_id - t->anchored_base_id;
- DEBUG_PRINTF("record %u @ %llu index %u/%u\n", literal_id, end, rel_idx,
- t->anchored_count);
- assert(rel_idx < t->anchored_count);
- fatbit_set(anchoredLiteralRows[end - 1], t->anchored_count, rel_idx);
+ assert(anch_id < t->anchored_count);
+ fatbit_set(anchoredLiteralRows[end - 1], t->anchored_count, anch_id);
}
static rose_inline
/** \brief Mapping from final ID to the set of literals it is used for. */
map<u32, flat_set<u32>> final_id_to_literal;
+
+ /** \brief Mapping from final ID to anchored program index. */
+ map<u32, u32> anchored_programs;
};
/** \brief subengine info including built engine and
return;
}
- program.add_before_end(make_unique<RoseInstrRecordAnchored>(final_id));
+ auto it = bc.anchored_programs.find(final_id);
+ if (it == bc.anchored_programs.end()) {
+ u32 anch_id = verify_u32(bc.anchored_programs.size());
+ it = bc.anchored_programs.emplace(final_id, anch_id).first;
+ DEBUG_PRINTF("added anch_id=%u for final_id %u\n", anch_id, final_id);
+ }
+ u32 anch_id = it->second;
+ program.add_before_end(make_unique<RoseInstrRecordAnchored>(anch_id));
}
static
auto lit_edge_map = findEdgesByLiteral(build);
vector<u32> programs;
+ programs.resize(bc.anchored_programs.size(), ROSE_INVALID_PROG_OFFSET);
- for (u32 final_id = build.anchored_base_id;
- final_id < build.delay_base_id; final_id++) {
+ for (const auto &m : bc.anchored_programs) {
+ u32 final_id = m.first;
+ u32 anch_id = m.second;
u32 offset = writeLiteralProgram(build, bc, {final_id}, lit_edge_map);
- programs.push_back(offset);
+ DEBUG_PRINTF("final_id %u -> anch prog at %u\n", final_id, offset);
+ programs[anch_id] = offset;
}
DEBUG_PRINTF("%zu anchored programs\n", programs.size());
engine->delay_fatbit_size = fatbit_size(engine->delay_count);
engine->delay_base_id = delay_base_id;
engine->anchored_base_id = anchored_base_id;
- engine->anchored_count = delay_base_id - anchored_base_id;
+ engine->anchored_count = bc.anchored_programs.size();
engine->anchored_fatbit_size = fatbit_size(engine->anchored_count);
engine->rosePrefixCount = rosePrefixCount;