]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
fdr: use bytecode_ptr in fdr/teddy compilers
authorJustin Viiret <justin.viiret@intel.com>
Mon, 20 Mar 2017 06:26:49 +0000 (17:26 +1100)
committerMatthew Barr <matthew.barr@intel.com>
Wed, 26 Apr 2017 05:19:36 +0000 (15:19 +1000)
src/fdr/fdr_compile.cpp
src/fdr/fdr_compile.h
src/fdr/teddy_compile.cpp
src/fdr/teddy_compile.h

index 8346e520ecfeefee872f3b101dacb9543aba1182..36bcda698f469e056038556e45f8ffaa5d12537a 100644 (file)
@@ -30,8 +30,9 @@
  * \brief FDR literal matcher: build API.
  */
 
-#include "fdr_internal.h"
 #include "fdr_compile.h"
+
+#include "fdr_internal.h"
 #include "fdr_confirm.h"
 #include "fdr_compile_internal.h"
 #include "fdr_engine_description.h"
@@ -40,7 +41,6 @@
 #include "grey.h"
 #include "ue2common.h"
 #include "hwlm/hwlm_build.h"
-#include "util/alloc.h"
 #include "util/compare.h"
 #include "util/dump_mask.h"
 #include "util/math.h"
@@ -86,7 +86,7 @@ private:
     void dumpMasks(const u8 *defaultMask);
 #endif
     void setupTab();
-    aligned_unique_ptr<FDR> setupFDR();
+    bytecode_ptr<FDR> setupFDR();
     void createInitialState(FDR *fdr);
 
 public:
@@ -95,7 +95,7 @@ public:
         : eng(eng_in), grey(grey_in), tab(eng_in.getTabSizeBytes()),
           lits(move(lits_in)), make_small(make_small_in) {}
 
-    aligned_unique_ptr<FDR> build();
+    bytecode_ptr<FDR> build();
 };
 
 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();
 
     auto floodControlTmp = setupFDRFloodControl(lits, eng, grey);
@@ -162,7 +162,7 @@ aligned_unique_ptr<FDR> FDRCompiler::setupFDR() {
                  headerSize, tabSize, confirmTmp.size(), floodControlTmp.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
 
     fdr->size = size;
@@ -528,7 +528,7 @@ void FDRCompiler::setupTab() {
 #endif
 }
 
-aligned_unique_ptr<FDR> FDRCompiler::build() {
+bytecode_ptr<FDR> FDRCompiler::build() {
     assignStringsToBuckets();
     setupTab();
     return setupFDR();
@@ -537,10 +537,9 @@ aligned_unique_ptr<FDR> FDRCompiler::build() {
 } // namespace
 
 static
-aligned_unique_ptr<FDR> fdrBuildTableInternal(const vector<hwlmLiteral> &lits,
-                                              bool make_small,
-                                              const target_t &target,
-                                              const Grey &grey, u32 hint) {
+bytecode_ptr<FDR> fdrBuildTableInternal(const vector<hwlmLiteral> &lits,
+                                        bool make_small, const target_t &target,
+                                        const Grey &grey, u32 hint) {
     DEBUG_PRINTF("cpu has %s\n", target.has_avx2() ? "avx2" : "no-avx2");
 
     if (grey.fdrAllowTeddy) {
@@ -553,10 +552,8 @@ aligned_unique_ptr<FDR> fdrBuildTableInternal(const vector<hwlmLiteral> &lits,
         }
     }
 
-    const unique_ptr<FDREngineDescription> des =
-        (hint == HINT_INVALID) ? chooseEngine(target, lits, make_small)
-                               : getFdrDescription(hint);
-
+    auto des = (hint == HINT_INVALID) ? chooseEngine(target, lits, make_small)
+                                      : getFdrDescription(hint);
     if (!des) {
         return nullptr;
     }
@@ -571,18 +568,18 @@ aligned_unique_ptr<FDR> fdrBuildTableInternal(const vector<hwlmLiteral> &lits,
     return fc.build();
 }
 
-aligned_unique_ptr<FDR> fdrBuildTable(const vector<hwlmLiteral> &lits,
-                                      bool make_small, const target_t &target,
-                                      const Grey &grey) {
+bytecode_ptr<FDR> fdrBuildTable(const vector<hwlmLiteral> &lits,
+                                bool make_small, const target_t &target,
+                                const Grey &grey) {
     return fdrBuildTableInternal(lits, make_small, target, grey, HINT_INVALID);
 }
 
 #if !defined(RELEASE_BUILD)
 
-aligned_unique_ptr<FDR> fdrBuildTableHinted(const vector<hwlmLiteral> &lits,
-                                            bool make_small, u32 hint,
-                                            const target_t &target,
-                                            const Grey &grey) {
+bytecode_ptr<FDR> fdrBuildTableHinted(const vector<hwlmLiteral> &lits,
+                                      bool make_small, u32 hint,
+                                      const target_t &target,
+                                      const Grey &grey) {
     return fdrBuildTableInternal(lits, make_small, target, grey, hint);
 }
 
index a135a6e17d71bddeed725bcc89008ebe4f7ec7ec..58047600f03157f5c3e1ad1e87b807cfb3b6b7c9 100644 (file)
@@ -34,7 +34,7 @@
 #define FDR_COMPILE_H
 
 #include "ue2common.h"
-#include "util/alloc.h"
+#include "util/bytecode_ptr.h"
 
 #include <vector>
 
@@ -46,15 +46,15 @@ struct hwlmLiteral;
 struct Grey;
 struct target_t;
 
-ue2::aligned_unique_ptr<FDR>
-fdrBuildTable(const std::vector<hwlmLiteral> &lits, bool make_small,
-              const target_t &target, const Grey &grey);
+bytecode_ptr<FDR> fdrBuildTable(const std::vector<hwlmLiteral> &lits,
+                                bool make_small, const target_t &target,
+                                const Grey &grey);
 
 #if !defined(RELEASE_BUILD)
 
-ue2::aligned_unique_ptr<FDR>
-fdrBuildTableHinted(const std::vector<hwlmLiteral> &lits, bool make_small,
-                    u32 hint, const target_t &target, const Grey &grey);
+bytecode_ptr<FDR> fdrBuildTableHinted(const std::vector<hwlmLiteral> &lits,
+                                      bool make_small, u32 hint,
+                                      const target_t &target, const Grey &grey);
 
 #endif
 
index a5856110be814bbd92045e69d066dc15fe08eba4..33a1050cc15eeec6ed6f417f15058d76ad743ce0 100644 (file)
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "teddy_compile.h"
+
 #include "fdr.h"
 #include "fdr_internal.h"
 #include "fdr_compile_internal.h"
 #include "fdr_confirm.h"
 #include "fdr_engine_description.h"
+#include "teddy_internal.h"
+#include "teddy_engine_description.h"
 #include "grey.h"
 #include "ue2common.h"
 #include "util/alloc.h"
@@ -40,9 +44,6 @@
 #include "util/target_info.h"
 #include "util/verify_types.h"
 
-#include "teddy_compile.h"
-#include "teddy_internal.h"
-#include "teddy_engine_description.h"
 
 #include <algorithm>
 #include <cassert>
@@ -77,7 +78,7 @@ public:
         : 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);
 };
 
@@ -277,7 +278,7 @@ bool TeddyCompiler::pack(map<BucketIndex,
     return true;
 }
 
-aligned_unique_ptr<FDR> TeddyCompiler::build() {
+bytecode_ptr<FDR> TeddyCompiler::build() {
     if (lits.size() > eng.getNumBuckets() * TEDDY_BUCKET_LOAD) {
         DEBUG_PRINTF("too many literals: %zu\n", lits.size());
         return nullptr;
@@ -319,7 +320,7 @@ aligned_unique_ptr<FDR> TeddyCompiler::build() {
                             floodControlTmp.size(),
                             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
     Teddy *teddy = (Teddy *)fdr.get(); // ugly
     u8 *teddy_base = (u8 *)teddy;
@@ -418,10 +419,10 @@ aligned_unique_ptr<FDR> TeddyCompiler::build() {
 
 } // namespace
 
-aligned_unique_ptr<FDR> teddyBuildTableHinted(const vector<hwlmLiteral> &lits,
-                                              bool make_small, u32 hint,
-                                              const target_t &target,
-                                              const Grey &grey) {
+bytecode_ptr<FDR> teddyBuildTableHinted(const vector<hwlmLiteral> &lits,
+                                        bool make_small, u32 hint,
+                                        const target_t &target,
+                                        const Grey &grey) {
     unique_ptr<TeddyEngineDescription> des;
     if (hint == HINT_INVALID) {
         des = chooseTeddyEngine(target, lits);
index 07eb18f64061d0e817e2e76e110dd46076515a79..22e8740504737ab81ca07f119a6563b816e6d833 100644 (file)
@@ -34,7 +34,7 @@
 #define TEDDY_COMPILE_H
 
 #include "ue2common.h"
-#include "util/alloc.h"
+#include "util/bytecode_ptr.h"
 
 #include <vector>
 
@@ -46,9 +46,10 @@ namespace ue2 {
 struct Grey;
 struct hwlmLiteral;
 
-ue2::aligned_unique_ptr<FDR>
-teddyBuildTableHinted(const std::vector<hwlmLiteral> &lits, bool make_small,
-                      u32 hint, const target_t &target, const Grey &grey);
+bytecode_ptr<FDR> teddyBuildTableHinted(const std::vector<hwlmLiteral> &lits,
+                                        bool make_small, u32 hint,
+                                        const target_t &target,
+                                        const Grey &grey);
 
 } // namespace ue2