]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
SHENG32: Compile priority sheng > mcsheng > sheng32.
authorChang, Harry <harry.chang@intel.com>
Mon, 20 Jul 2020 06:36:53 +0000 (06:36 +0000)
committerKonstantinos Margaritis <markos@users.noreply.github.com>
Mon, 25 Jan 2021 12:13:13 +0000 (14:13 +0200)
src/nfa/shengcompile.cpp
src/nfa/shengcompile.h
src/rose/rose_build_bytecode.cpp
src/smallwrite/smallwrite_build.cpp

index 8b93997363343e922e4ec813b5f5b8d4226642f4..f968bf59e771b0577cc6bafeeb9f377d56689158 100644 (file)
@@ -643,19 +643,40 @@ bytecode_ptr<NFA> shengCompile(raw_dfa &raw, const CompileContext &cc,
     DEBUG_PRINTF("This DFA %s die so effective number of states is %zu\n",
                  info.can_die ? "can" : "cannot", info.size());
     if (info.size() > 16) {
-#if defined(HAVE_AVX512VBMI)
-        if (info.size() > 32) {
-            DEBUG_PRINTF("Too many states\n");
-            return nullptr;
-        }
-        return shengCompile_int<sheng32>(raw, cc, accel_states, strat, info);
-#else
         DEBUG_PRINTF("Too many states\n");
         return nullptr;
-#endif
     }
 
     return shengCompile_int<sheng>(raw, cc, accel_states, strat, info);
 }
 
+#if defined(HAVE_AVX512VBMI)
+bytecode_ptr<NFA> sheng32Compile(raw_dfa &raw, const CompileContext &cc,
+                                 const ReportManager &rm, bool only_accel_init,
+                                 set<dstate_id_t> *accel_states) {
+    if (!cc.grey.allowSheng) {
+        DEBUG_PRINTF("Sheng is not allowed!\n");
+        return nullptr;
+    }
+
+    sheng_build_strat strat(raw, rm, only_accel_init);
+    dfa_info info(strat);
+
+    DEBUG_PRINTF("Trying to compile a %zu state Sheng\n", raw.states.size());
+
+    DEBUG_PRINTF("Anchored start state id: %u, floating start state id: %u\n",
+                 raw.start_anchored, raw.start_floating);
+
+    DEBUG_PRINTF("This DFA %s die so effective number of states is %zu\n",
+                 info.can_die ? "can" : "cannot", info.size());
+    assert(info.size() > 16);
+    if (info.size() > 32) {
+        DEBUG_PRINTF("Too many states\n");
+        return nullptr;
+    }
+
+    return shengCompile_int<sheng32>(raw, cc, accel_states, strat, info);
+}
+#endif
+
 } // namespace ue2
index d795b362381b5f778d46ca7fd9fb4d2c99b61dcd..b36e27beedb5f0f2b0fd7fe2f1cbcee17ccc614e 100644 (file)
@@ -71,6 +71,12 @@ bytecode_ptr<NFA> shengCompile(raw_dfa &raw, const CompileContext &cc,
                                const ReportManager &rm, bool only_accel_init,
                                std::set<dstate_id_t> *accel_states = nullptr);
 
+#if defined(HAVE_AVX512VBMI)
+bytecode_ptr<NFA> sheng32Compile(raw_dfa &raw, const CompileContext &cc,
+                                 const ReportManager &rm, bool only_accel_init,
+                                 std::set<dstate_id_t> *accel_states = nullptr);
+#endif
+
 struct sheng_escape_info {
     CharReach outs;
     CharReach outs2_single;
index 5cbb5c8486a8384cabd6a3a49774cafc9ae492a2..8e1d7095bdd13fb962dddcae136936670adcd02a 100644 (file)
@@ -632,6 +632,11 @@ bytecode_ptr<NFA> getDfa(raw_dfa &rdfa, bool is_transient,
          * bytecode and that they are usually run on small blocks */
         dfa = mcshengCompile(rdfa, cc, rm);
     }
+#if defined(HAVE_AVX512VBMI)
+    if (!dfa) {
+        dfa = sheng32Compile(rdfa, cc, rm, false);
+    }
+#endif
     if (!dfa) {
         // Sheng wasn't successful, so unleash McClellan!
         dfa = mcclellanCompile(rdfa, cc, rm, false);
index 345edfe95033a16e60684d4108906b10594e633a..909fdcb3b07a210cdac3f8c987e2b46c61366588 100644 (file)
@@ -793,6 +793,11 @@ bytecode_ptr<NFA> getDfa(raw_dfa &rdfa, const CompileContext &cc,
     bytecode_ptr<NFA> dfa = nullptr;
     if (cc.grey.allowSmallWriteSheng) {
         dfa = shengCompile(rdfa, cc, rm, only_accel_init, &accel_states);
+#if defined(HAVE_AVX512VBMI)
+        if (!dfa) {
+            dfa = sheng32Compile(rdfa, cc, rm, only_accel_init, &accel_states);
+        }
+#endif
     }
     if (!dfa) {
         dfa = mcclellanCompile(rdfa, cc, rm, only_accel_init,