]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
fdr/teddy: simplify computing of confirm base
authorJustin Viiret <justin.viiret@intel.com>
Wed, 24 May 2017 01:10:39 +0000 (11:10 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Mon, 21 Aug 2017 00:39:00 +0000 (10:39 +1000)
src/fdr/fdr.c
src/fdr/fdr_compile.cpp
src/fdr/fdr_internal.h
src/fdr/teddy.c
src/fdr/teddy_avx2.c
src/fdr/teddy_compile.cpp
src/fdr/teddy_internal.h
src/fdr/teddy_runtime_common.h

index aa5f1804edbc73ccdb9fc4c70af570731b787f67..c77e31ff50a0378fdf920dd70ceacf9e2801fa44 100644 (file)
@@ -734,8 +734,7 @@ hwlm_error_t fdr_engine_exec(const struct FDR *fdr,
     const u64a *ft =
         (const u64a *)((const u8 *)fdr + ROUNDUP_CL(sizeof(struct FDR)));
     assert(ISALIGNED_CL(ft));
-    const u32 *confBase =
-        (const u32 *)((const u8 *)ft + ROUNDUP_CL(fdr->tabSize));
+    const u32 *confBase = (const u32 *)((const u8 *)fdr + fdr->confOffset);
     assert(ISALIGNED_CL(confBase));
     struct zone zones[ZONE_MAX];
     assert(fdr->domain > 8 && fdr->domain < 16);
index e4f8c194427b3f06d150cfaf84ca41796d4c0939..cd0013e4d3afcf97a1cd2ac389fdd88c7942bf2c 100644 (file)
@@ -190,6 +190,7 @@ bytecode_ptr<FDR> FDRCompiler::setupFDR() {
 
     // Write confirm structures.
     assert(ISALIGNED_CL(ptr));
+    fdr->confOffset = verify_u32(ptr - fdr_base);
     memcpy(ptr, confirmTable.get(), confirmTable.size());
     ptr += ROUNDUP_CL(confirmTable.size());
 
index a425d78c894d930accdf5ea2d271b18530ade329..dd81c2dc87ce885afbfcfb252d1ac5189ad831cb 100644 (file)
@@ -69,6 +69,7 @@ struct FDR {
     u32 engineID;
     u32 size;
     u32 maxStringLen;
+    u32 confOffset;
     u32 floodOffset;
 
     u8 stride; /* stride - how frequeuntly the data is consulted by the first
index a3f7cfaf4bc498e969895c464cdb8b74fc16dcf3..636c741b445ba187afe43ff598abe64b44c57a90 100644 (file)
@@ -191,7 +191,7 @@ hwlm_error_t fdr_exec_teddy_msks1(const struct FDR *fdr,
                  a->buf, a->len, a->start_offset);
 
     const m128 *maskBase = getMaskBase(teddy);
-    const u32 *confBase = getConfBase(teddy, 1);
+    const u32 *confBase = getConfBase(teddy);
 
     const u8 *mainStart = ROUNDUP_PTR(ptr, 16);
     DEBUG_PRINTF("derive: ptr: %p mainstart %p\n", ptr, mainStart);
@@ -247,7 +247,7 @@ hwlm_error_t fdr_exec_teddy_msks1_pck(const struct FDR *fdr,
                  a->buf, a->len, a->start_offset);
 
     const m128 *maskBase = getMaskBase(teddy);
-    const u32 *confBase = getConfBase(teddy, 1);
+    const u32 *confBase = getConfBase(teddy);
 
     const u8 *mainStart = ROUNDUP_PTR(ptr, 16);
     DEBUG_PRINTF("derive: ptr: %p mainstart %p\n", ptr, mainStart);
@@ -303,7 +303,7 @@ hwlm_error_t fdr_exec_teddy_msks2(const struct FDR *fdr,
                  a->buf, a->len, a->start_offset);
 
     const m128 *maskBase = getMaskBase(teddy);
-    const u32 *confBase = getConfBase(teddy, 2);
+    const u32 *confBase = getConfBase(teddy);
 
     m128 res_old_1 = ones128();
     const u8 *mainStart = ROUNDUP_PTR(ptr, 16);
@@ -360,7 +360,7 @@ hwlm_error_t fdr_exec_teddy_msks2_pck(const struct FDR *fdr,
                  a->buf, a->len, a->start_offset);
 
     const m128 *maskBase = getMaskBase(teddy);
-    const u32 *confBase = getConfBase(teddy, 2);
+    const u32 *confBase = getConfBase(teddy);
 
     m128 res_old_1 = ones128();
     const u8 *mainStart = ROUNDUP_PTR(ptr, 16);
@@ -417,7 +417,7 @@ hwlm_error_t fdr_exec_teddy_msks3(const struct FDR *fdr,
                  a->buf, a->len, a->start_offset);
 
     const m128 *maskBase = getMaskBase(teddy);
-    const u32 *confBase = getConfBase(teddy, 3);
+    const u32 *confBase = getConfBase(teddy);
 
     m128 res_old_1 = ones128();
     m128 res_old_2 = ones128();
@@ -479,7 +479,7 @@ hwlm_error_t fdr_exec_teddy_msks3_pck(const struct FDR *fdr,
                  a->buf, a->len, a->start_offset);
 
     const m128 *maskBase = getMaskBase(teddy);
-    const u32 *confBase = getConfBase(teddy, 3);
+    const u32 *confBase = getConfBase(teddy);
 
     m128 res_old_1 = ones128();
     m128 res_old_2 = ones128();
@@ -541,7 +541,7 @@ hwlm_error_t fdr_exec_teddy_msks4(const struct FDR *fdr,
                  a->buf, a->len, a->start_offset);
 
     const m128 *maskBase = getMaskBase(teddy);
-    const u32 *confBase = getConfBase(teddy, 4);
+    const u32 *confBase = getConfBase(teddy);
 
     m128 res_old_1 = ones128();
     m128 res_old_2 = ones128();
@@ -605,7 +605,7 @@ hwlm_error_t fdr_exec_teddy_msks4_pck(const struct FDR *fdr,
                  a->buf, a->len, a->start_offset);
 
     const m128 *maskBase = getMaskBase(teddy);
-    const u32 *confBase = getConfBase(teddy, 4);
+    const u32 *confBase = getConfBase(teddy);
 
     m128 res_old_1 = ones128();
     m128 res_old_2 = ones128();
index 38ac3f72ae266f337287befc3e6dcb244bc1d39f..89117b0b28465e31bc5bf7fec8eb30dda15305fe 100644 (file)
@@ -200,12 +200,6 @@ const m256 *getMaskBase_avx2(const struct Teddy *teddy) {
     return (const m256 *)((const u8 *)teddy + ROUNDUP_CL(sizeof(struct Teddy)));
 }
 
-static really_inline
-const u32 *getConfBase_avx2(const struct Teddy *teddy, u8 numMask) {
-    return (const u32 *)((const u8 *)teddy + ROUNDUP_CL(sizeof(struct Teddy)) +
-                         ROUNDUP_CL((numMask * 32 * 2)));
-}
-
 hwlm_error_t fdr_exec_teddy_avx2_msks1_fat(const struct FDR *fdr,
                                            const struct FDR_Runtime_Args *a,
                                            hwlm_group_t control) {
@@ -220,7 +214,7 @@ hwlm_error_t fdr_exec_teddy_avx2_msks1_fat(const struct FDR *fdr,
                  a->buf, a->len, a->start_offset);
 
     const m256 *maskBase = getMaskBase_avx2(teddy);
-    const u32 *confBase = getConfBase_avx2(teddy, 1);
+    const u32 *confBase = getConfBase(teddy);
 
     const u8 *mainStart = ROUNDUP_PTR(ptr, 16);
     DEBUG_PRINTF("derive: ptr: %p mainstart %p\n", ptr, mainStart);
@@ -276,7 +270,7 @@ hwlm_error_t fdr_exec_teddy_avx2_msks1_pck_fat(const struct FDR *fdr,
                  a->buf, a->len, a->start_offset);
 
     const m256 *maskBase = getMaskBase_avx2(teddy);
-    const u32 *confBase = getConfBase_avx2(teddy, 1);
+    const u32 *confBase = getConfBase(teddy);
 
     const u8 *mainStart = ROUNDUP_PTR(ptr, 16);
     DEBUG_PRINTF("derive: ptr: %p mainstart %p\n", ptr, mainStart);
@@ -332,7 +326,7 @@ hwlm_error_t fdr_exec_teddy_avx2_msks2_fat(const struct FDR *fdr,
                  a->buf, a->len, a->start_offset);
 
     const m256 *maskBase = getMaskBase_avx2(teddy);
-    const u32 *confBase = getConfBase_avx2(teddy, 2);
+    const u32 *confBase = getConfBase(teddy);
 
     m256 res_old_1 = ones256();
     const u8 *mainStart = ROUNDUP_PTR(ptr, 16);
@@ -390,7 +384,7 @@ hwlm_error_t fdr_exec_teddy_avx2_msks2_pck_fat(const struct FDR *fdr,
                  a->buf, a->len, a->start_offset);
 
     const m256 *maskBase = getMaskBase_avx2(teddy);
-    const u32 *confBase = getConfBase_avx2(teddy, 2);
+    const u32 *confBase = getConfBase(teddy);
 
     m256 res_old_1 = ones256();
     const u8 *mainStart = ROUNDUP_PTR(ptr, 16);
@@ -448,7 +442,7 @@ hwlm_error_t fdr_exec_teddy_avx2_msks3_fat(const struct FDR *fdr,
                  a->buf, a->len, a->start_offset);
 
     const m256 *maskBase = getMaskBase_avx2(teddy);
-    const u32 *confBase = getConfBase_avx2(teddy, 3);
+    const u32 *confBase = getConfBase(teddy);
 
     m256 res_old_1 = ones256();
     m256 res_old_2 = ones256();
@@ -511,7 +505,7 @@ hwlm_error_t fdr_exec_teddy_avx2_msks3_pck_fat(const struct FDR *fdr,
                  a->buf, a->len, a->start_offset);
 
     const m256 *maskBase = getMaskBase_avx2(teddy);
-    const u32 *confBase = getConfBase_avx2(teddy, 3);
+    const u32 *confBase = getConfBase(teddy);
 
     m256 res_old_1 = ones256();
     m256 res_old_2 = ones256();
@@ -574,7 +568,7 @@ hwlm_error_t fdr_exec_teddy_avx2_msks4_fat(const struct FDR *fdr,
                  a->buf, a->len, a->start_offset);
 
     const m256 *maskBase = getMaskBase_avx2(teddy);
-    const u32 *confBase = getConfBase_avx2(teddy, 4);
+    const u32 *confBase = getConfBase(teddy);
 
     m256 res_old_1 = ones256();
     m256 res_old_2 = ones256();
@@ -638,7 +632,7 @@ hwlm_error_t fdr_exec_teddy_avx2_msks4_pck_fat(const struct FDR *fdr,
                  a->buf, a->len, a->start_offset);
 
     const m256 *maskBase = getMaskBase_avx2(teddy);
-    const u32 *confBase = getConfBase_avx2(teddy, 4);
+    const u32 *confBase = getConfBase(teddy);
 
     m256 res_old_1 = ones256();
     m256 res_old_2 = ones256();
index 19e595fb7e1244142f78aad223f3745811dc8985..2ea70f13216a368879d4d9ff3f1bd2c8a871a470 100644 (file)
@@ -335,6 +335,7 @@ bytecode_ptr<FDR> TeddyCompiler::build() {
     // Write confirm structures.
     u8 *ptr = teddy_base + headerSize + maskLen;
     assert(ISALIGNED_CL(ptr));
+    teddy->confOffset = verify_u32(ptr - teddy_base);
     memcpy(ptr, confirmTable.get(), confirmTable.size());
     ptr += ROUNDUP_CL(confirmTable.size());
 
index bbd8e788500d3df7a51bfd8ff36b2b88f5917e94..f3319bd201a6f1f084418478b4eb53bb10e3a214 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2017, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -36,6 +36,7 @@ struct Teddy {
     u32 engineID;
     u32 size;
     u32 maxStringLen;
+    u32 confOffset;
     u32 floodOffset;
     u32 link;
     u32 pad1;
index 883a68fc3bcfd65a8a408f4e0ac3e395a6246d34..f63df7240648bc6dac41fe2ea2ea0f48e957d64b 100644 (file)
@@ -244,9 +244,8 @@ const m128 *getMaskBase(const struct Teddy *teddy) {
 }
 
 static really_inline
-const u32 *getConfBase(const struct Teddy *teddy, u8 numMask) {
-    return (const u32 *)((const u8 *)teddy + ROUNDUP_CL(sizeof(struct Teddy)) +
-                         ROUNDUP_CL(numMask * 32));
+const u32 *getConfBase(const struct Teddy *teddy) {
+    return (const u32 *)((const u8 *)teddy + teddy->confOffset);
 }
 
 #endif /* TEDDY_RUNTIME_COMMON_H_ */