]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
rose: move lookaround tables to engine blob
authorJustin Viiret <justin.viiret@intel.com>
Tue, 28 Feb 2017 00:18:23 +0000 (11:18 +1100)
committerMatthew Barr <matthew.barr@intel.com>
Wed, 26 Apr 2017 05:11:10 +0000 (15:11 +1000)
src/rose/rose_build_bytecode.cpp
src/rose/rose_build_dump.cpp

index 12b517570257dcff96ba98d2d8dd4ef79440ff0c..05e46ca8df918320b9f8a282b95980968b006a5f 100644 (file)
@@ -2683,13 +2683,15 @@ bool hasEodAnchors(const RoseBuildImpl &build, const build_context &bc,
 }
 
 static
-void fillLookaroundTables(char *look_base, char *reach_base,
-                          const vector<LookEntry> &look_vec) {
+void writeLookaroundTables(build_context &bc, RoseEngine &proto) {
+    const auto &look_vec = bc.lookaround;
     DEBUG_PRINTF("%zu lookaround table entries\n", look_vec.size());
 
-    s8 *look = (s8 *)look_base;
-    u8 *reach = (u8 *)reach_base; // base for 256-bit bitvectors
+    vector<s8> look_table(look_vec.size(), 0);
+    vector<u8> reach_table(REACH_BITVECTOR_LEN * look_vec.size(), 0);
 
+    s8 *look = look_table.data();
+    u8 *reach = reach_table.data();
     for (const auto &le : look_vec) {
         *look = verify_s8(le.offset);
         const CharReach &cr = le.reach;
@@ -2700,6 +2702,11 @@ void fillLookaroundTables(char *look_base, char *reach_base,
         ++look;
         reach += REACH_BITVECTOR_LEN;
     }
+
+    proto.lookaroundTableOffset =
+        bc.engine_blob.add(begin(look_table), end(look_table));
+    proto.lookaroundReachOffset =
+        bc.engine_blob.add(begin(reach_table), end(reach_table));
 }
 
 static
@@ -5376,6 +5383,8 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
 
     addSomRevNfas(bc, proto, ssm);
 
+    writeLookaroundTables(bc, proto);
+
     // Enforce role table resource limit.
     if (num_vertices(g) > cc.grey.limitRoseRoleCount) {
         throw ResourceLimitError();
@@ -5446,12 +5455,6 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
     proto.leftOffset = currOffset;
     currOffset += sizeof(LeftNfaInfo) * leftInfoTable.size();
 
-    proto.lookaroundReachOffset = currOffset;
-    currOffset += REACH_BITVECTOR_LEN * bc.lookaround.size();
-
-    proto.lookaroundTableOffset = currOffset;
-    currOffset += sizeof(s8) * bc.lookaround.size();
-
     currOffset = ROUNDUP_N(currOffset, sizeof(u32));
     proto.nfaInfoOffset = currOffset;
     currOffset += sizeof(NfaInfo) * queue_count;
@@ -5597,9 +5600,6 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
     bc.engine_blob.write_bytes(engine.get());
     copy_bytes(ptr + engine->leftOffset, leftInfoTable);
 
-    fillLookaroundTables(ptr + proto.lookaroundTableOffset,
-                         ptr + proto.lookaroundReachOffset, bc.lookaround);
-
     // Safety check: we shouldn't have written anything to the engine blob
     // after we copied it into the engine bytecode.
     assert(bc.engine_blob.size() == engineBlobSize);
index 2f882e68f67156f144483ca5e38e660969761f7b..a13fc9646c7b4a2a4fe096549b4fb10b3d9ec672 100644 (file)
@@ -1694,10 +1694,6 @@ void roseDumpText(const RoseEngine *t, FILE *f) {
             t->rolesWithStateCount * sizeof(u32));
     fprintf(f, " - nfa info table    : %zu bytes\n",
             t->queueCount * sizeof(NfaInfo));
-    fprintf(f, " - lookaround table  : %u bytes\n",
-            t->nfaInfoOffset - t->lookaroundTableOffset);
-    fprintf(f, " - lookaround reach  : %u bytes\n",
-            t->lookaroundTableOffset - t->lookaroundReachOffset);
 
     fprintf(f, "state space required : %u bytes\n", t->stateOffsets.end);
     fprintf(f, " - history buffer    : %u bytes\n", t->historyRequired);