]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Move SVE functions into their own files.
authorGeorge Wort <george.wort@arm.com>
Tue, 20 Jul 2021 17:13:02 +0000 (18:13 +0100)
committerKonstantinos Margaritis <konstantinos@vectorcamp.gr>
Tue, 12 Oct 2021 08:51:34 +0000 (11:51 +0300)
Change-Id: I995ba4b7d2b558ee403693ee45d747d414d3b177

16 files changed:
src/nfa/castle.c
src/nfa/castle_sve.h [new file with mode: 0644]
src/nfa/lbr.c
src/nfa/lbr_sve.h [new file with mode: 0644]
src/nfa/shufti_simd.hpp
src/nfagraph/ng_lbr.cpp
src/nfagraph/ng_lbr_sve.hpp [new file with mode: 0644]
src/rose/counting_miracle.h
src/rose/counting_miracle_shufti_sve.h [new file with mode: 0644]
src/rose/counting_miracle_sve.h [new file with mode: 0644]
src/util/arch/arm/bitutils.h
src/util/arch/arm/bitutils_sve.h [new file with mode: 0644]
src/util/arch/arm/simd_utils.h
src/util/arch/arm/simd_utils_sve.h [new file with mode: 0644]
src/util/arch/arm/simd_utils_sve2.h [new file with mode: 0644]
src/util/state_compress.c

index dc6ec8f9d51b517d3b24647e11cb71d66fefbc3e..c7dd6d50eb371e8a599028a2347e22a1ae3815bf 100644 (file)
 #include "util/partial_store.h"
 #include "ue2common.h"
 
+#ifdef HAVE_SVE2
+#include "castle_sve.h"
+#endif
+
 static really_inline
 const struct SubCastle *getSubCastle(const struct Castle *c, u32 num) {
     assert(num < c->numRepeats);
@@ -553,42 +557,6 @@ char castleScanNVerm(const struct Castle *c, const u8 *buf, const size_t begin,
     return 1;
 }
 
-#ifdef HAVE_SVE2
-
-static really_inline
-char castleScanVerm16(const struct Castle *c, const u8 *buf, const size_t begin,
-                      const size_t end, size_t *loc) {
-    const u8 *ptr = vermicelli16Exec(c->u.verm16.mask, buf + begin, buf + end);
-    if (ptr == buf + end) {
-        DEBUG_PRINTF("no escape found\n");
-        return 0;
-    }
-
-    assert(loc);
-    assert(ptr >= buf && ptr < buf + end);
-    *loc = ptr - buf;
-    DEBUG_PRINTF("escape found at offset %zu\n", *loc);
-    return 1;
-}
-
-static really_inline
-char castleScanNVerm16(const struct Castle *c, const u8 *buf, const size_t begin,
-                       const size_t end, size_t *loc) {
-    const u8 *ptr = nvermicelli16Exec(c->u.verm16.mask, buf + begin, buf + end);
-    if (ptr == buf + end) {
-        DEBUG_PRINTF("no escape found\n");
-        return 0;
-    }
-
-    assert(loc);
-    assert(ptr >= buf && ptr < buf + end);
-    *loc = ptr - buf;
-    DEBUG_PRINTF("escape found at offset %zu\n", *loc);
-    return 1;
-}
-
-#endif // HAVE_SVE2
-
 static really_inline
 char castleScanShufti(const struct Castle *c, const u8 *buf, const size_t begin,
                       const size_t end, size_t *loc) {
@@ -690,42 +658,6 @@ char castleRevScanNVerm(const struct Castle *c, const u8 *buf,
     return 1;
 }
 
-#ifdef HAVE_SVE2
-
-static really_inline
-char castleRevScanVerm16(const struct Castle *c, const u8 *buf,
-                         const size_t begin, const size_t end, size_t *loc) {
-    const u8 *ptr = rvermicelli16Exec(c->u.verm16.mask, buf + begin, buf + end);
-    if (ptr == buf + begin - 1) {
-        DEBUG_PRINTF("no escape found\n");
-        return 0;
-    }
-
-    assert(loc);
-    assert(ptr >= buf && ptr < buf + end);
-    *loc = ptr - buf;
-    DEBUG_PRINTF("escape found at offset %zu\n", *loc);
-    return 1;
-}
-
-static really_inline
-char castleRevScanNVerm16(const struct Castle *c, const u8 *buf,
-                          const size_t begin, const size_t end, size_t *loc) {
-    const u8 *ptr = rnvermicelli16Exec(c->u.verm16.mask, buf + begin, buf + end);
-    if (ptr == buf + begin - 1) {
-        DEBUG_PRINTF("no escape found\n");
-        return 0;
-    }
-
-    assert(loc);
-    assert(ptr >= buf && ptr < buf + end);
-    *loc = ptr - buf;
-    DEBUG_PRINTF("escape found at offset %zu\n", *loc);
-    return 1;
-}
-
-#endif // HAVE_SVE2
-
 static really_inline
 char castleRevScanShufti(const struct Castle *c, const u8 *buf,
                          const size_t begin, const size_t end, size_t *loc) {
diff --git a/src/nfa/castle_sve.h b/src/nfa/castle_sve.h
new file mode 100644 (file)
index 0000000..a8f6452
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2015-2016, Intel Corporation
+ * Copyright (c) 2021, Arm Limited
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *  * Neither the name of Intel Corporation nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** \file
+ * \brief Castle for SVE: multi-tenant repeat engine, runtime code.
+ */
+
+static really_inline
+char castleScanVerm16(const struct Castle *c, const u8 *buf, const size_t begin,
+                      const size_t end, size_t *loc) {
+    const u8 *ptr = vermicelli16Exec(c->u.verm16.mask, buf + begin, buf + end);
+    if (ptr == buf + end) {
+        DEBUG_PRINTF("no escape found\n");
+        return 0;
+    }
+
+    assert(loc);
+    assert(ptr >= buf && ptr < buf + end);
+    *loc = ptr - buf;
+    DEBUG_PRINTF("escape found at offset %zu\n", *loc);
+    return 1;
+}
+
+static really_inline
+char castleScanNVerm16(const struct Castle *c, const u8 *buf, const size_t begin,
+                       const size_t end, size_t *loc) {
+    const u8 *ptr = nvermicelli16Exec(c->u.verm16.mask, buf + begin, buf + end);
+    if (ptr == buf + end) {
+        DEBUG_PRINTF("no escape found\n");
+        return 0;
+    }
+
+    assert(loc);
+    assert(ptr >= buf && ptr < buf + end);
+    *loc = ptr - buf;
+    DEBUG_PRINTF("escape found at offset %zu\n", *loc);
+    return 1;
+}
+
+static really_inline
+char castleRevScanVerm16(const struct Castle *c, const u8 *buf,
+                         const size_t begin, const size_t end, size_t *loc) {
+    const u8 *ptr = rvermicelli16Exec(c->u.verm16.mask, buf + begin, buf + end);
+    if (ptr == buf + begin - 1) {
+        DEBUG_PRINTF("no escape found\n");
+        return 0;
+    }
+
+    assert(loc);
+    assert(ptr >= buf && ptr < buf + end);
+    *loc = ptr - buf;
+    DEBUG_PRINTF("escape found at offset %zu\n", *loc);
+    return 1;
+}
+
+static really_inline
+char castleRevScanNVerm16(const struct Castle *c, const u8 *buf,
+                          const size_t begin, const size_t end, size_t *loc) {
+    const u8 *ptr = rnvermicelli16Exec(c->u.verm16.mask, buf + begin, buf + end);
+    if (ptr == buf + begin - 1) {
+        DEBUG_PRINTF("no escape found\n");
+        return 0;
+    }
+
+    assert(loc);
+    assert(ptr >= buf && ptr < buf + end);
+    *loc = ptr - buf;
+    DEBUG_PRINTF("escape found at offset %zu\n", *loc);
+    return 1;
+}
\ No newline at end of file
index 2c6ea163184617b89fd179f7070d627607d7c899..68e8e3f49c2deb931201fd8902fa930a11d4cc90 100644 (file)
@@ -362,56 +362,6 @@ char lbrRevScanNVerm(const struct NFA *nfa, const u8 *buf,
     return 1;
 }
 
-#ifdef HAVE_SVE2
-
-static really_inline
-char lbrRevScanVerm16(const struct NFA *nfa, const u8 *buf,
-                      size_t begin, size_t end, size_t *loc) {
-    assert(begin <= end);
-    assert(nfa->type == LBR_NFA_VERM16);
-    const struct lbr_verm16 *l = getImplNfa(nfa);
-
-    if (begin == end) {
-        return 0;
-    }
-
-    const u8 *ptr = rvermicelli16Exec(l->mask, buf + begin, buf + end);
-    if (ptr == buf + begin - 1) {
-        DEBUG_PRINTF("no escape found\n");
-        return 0;
-    }
-
-    assert(loc);
-    *loc = ptr - buf;
-    DEBUG_PRINTF("escape found at offset %zu\n", *loc);
-    return 1;
-}
-
-static really_inline
-char lbrRevScanNVerm16(const struct NFA *nfa, const u8 *buf,
-                       size_t begin, size_t end, size_t *loc) {
-    assert(begin <= end);
-    assert(nfa->type == LBR_NFA_NVERM16);
-    const struct lbr_verm16 *l = getImplNfa(nfa);
-
-    if (begin == end) {
-        return 0;
-    }
-
-    const u8 *ptr = rnvermicelli16Exec(l->mask, buf + begin, buf + end);
-    if (ptr == buf + begin - 1) {
-        DEBUG_PRINTF("no escape found\n");
-        return 0;
-    }
-
-    assert(loc);
-    *loc = ptr - buf;
-    DEBUG_PRINTF("escape found at offset %zu\n", *loc);
-    return 1;
-}
-
-#endif // HAVE_SVE2
-
 static really_inline
 char lbrRevScanShuf(const struct NFA *nfa, const u8 *buf,
                     size_t begin, size_t end,
@@ -518,56 +468,6 @@ char lbrFwdScanNVerm(const struct NFA *nfa, const u8 *buf,
     return 1;
 }
 
-#ifdef HAVE_SVE2
-
-static really_inline
-char lbrFwdScanVerm16(const struct NFA *nfa, const u8 *buf,
-                      size_t begin, size_t end, size_t *loc) {
-    assert(begin <= end);
-    assert(nfa->type == LBR_NFA_VERM16);
-    const struct lbr_verm16 *l = getImplNfa(nfa);
-
-    if (begin == end) {
-        return 0;
-    }
-
-    const u8 *ptr = vermicelli16Exec(l->mask, buf + begin, buf + end);
-    if (ptr == buf + end) {
-        DEBUG_PRINTF("no escape found\n");
-        return 0;
-    }
-
-    assert(loc);
-    *loc = ptr - buf;
-    DEBUG_PRINTF("escape found at offset %zu\n", *loc);
-    return 1;
-}
-
-static really_inline
-char lbrFwdScanNVerm16(const struct NFA *nfa, const u8 *buf,
-                       size_t begin, size_t end, size_t *loc) {
-    assert(begin <= end);
-    assert(nfa->type == LBR_NFA_NVERM16);
-    const struct lbr_verm16 *l = getImplNfa(nfa);
-
-    if (begin == end) {
-        return 0;
-    }
-
-    const u8 *ptr = nvermicelli16Exec(l->mask, buf + begin, buf + end);
-    if (ptr == buf + end) {
-        DEBUG_PRINTF("no escape found\n");
-        return 0;
-    }
-
-    assert(loc);
-    *loc = ptr - buf;
-    DEBUG_PRINTF("escape found at offset %zu\n", *loc);
-    return 1;
-}
-
-#endif // HAVE_SVE2
-
 static really_inline
 char lbrFwdScanShuf(const struct NFA *nfa, const u8 *buf,
                     size_t begin, size_t end,
@@ -625,18 +525,12 @@ char lbrFwdScanTruf(const struct NFA *nfa, const u8 *buf,
 #define ENGINE_ROOT_NAME NVerm
 #include "lbr_common_impl.h"
 
-#ifdef HAVE_SVE2
-
-#define ENGINE_ROOT_NAME Verm16
-#include "lbr_common_impl.h"
-
-#define ENGINE_ROOT_NAME NVerm16
-#include "lbr_common_impl.h"
-
-#endif // HAVE_SVE2
-
 #define ENGINE_ROOT_NAME Shuf
 #include "lbr_common_impl.h"
 
 #define ENGINE_ROOT_NAME Truf
 #include "lbr_common_impl.h"
+
+#ifdef HAVE_SVE2
+#include "lbr_sve.h"
+#endif
\ No newline at end of file
diff --git a/src/nfa/lbr_sve.h b/src/nfa/lbr_sve.h
new file mode 100644 (file)
index 0000000..8f5948b
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2015-2017, Intel Corporation
+ * Copyright (c) 2021, Arm Limited
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *  * Neither the name of Intel Corporation nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** \file
+ * \brief Large Bounded Repeat (LBR) engine for SVE: runtime code.
+ */
+
+static really_inline
+char lbrRevScanVerm16(const struct NFA *nfa, const u8 *buf,
+                      size_t begin, size_t end, size_t *loc) {
+    assert(begin <= end);
+    assert(nfa->type == LBR_NFA_VERM16);
+    const struct lbr_verm16 *l = getImplNfa(nfa);
+
+    if (begin == end) {
+        return 0;
+    }
+
+    const u8 *ptr = rvermicelli16Exec(l->mask, buf + begin, buf + end);
+    if (ptr == buf + begin - 1) {
+        DEBUG_PRINTF("no escape found\n");
+        return 0;
+    }
+
+    assert(loc);
+    *loc = ptr - buf;
+    DEBUG_PRINTF("escape found at offset %zu\n", *loc);
+    return 1;
+}
+
+static really_inline
+char lbrRevScanNVerm16(const struct NFA *nfa, const u8 *buf,
+                       size_t begin, size_t end, size_t *loc) {
+    assert(begin <= end);
+    assert(nfa->type == LBR_NFA_NVERM16);
+    const struct lbr_verm16 *l = getImplNfa(nfa);
+
+    if (begin == end) {
+        return 0;
+    }
+
+    const u8 *ptr = rnvermicelli16Exec(l->mask, buf + begin, buf + end);
+    if (ptr == buf + begin - 1) {
+        DEBUG_PRINTF("no escape found\n");
+        return 0;
+    }
+
+    assert(loc);
+    *loc = ptr - buf;
+    DEBUG_PRINTF("escape found at offset %zu\n", *loc);
+    return 1;
+}
+
+static really_inline
+char lbrFwdScanVerm16(const struct NFA *nfa, const u8 *buf,
+                      size_t begin, size_t end, size_t *loc) {
+    assert(begin <= end);
+    assert(nfa->type == LBR_NFA_VERM16);
+    const struct lbr_verm16 *l = getImplNfa(nfa);
+
+    if (begin == end) {
+        return 0;
+    }
+
+    const u8 *ptr = vermicelli16Exec(l->mask, buf + begin, buf + end);
+    if (ptr == buf + end) {
+        DEBUG_PRINTF("no escape found\n");
+        return 0;
+    }
+
+    assert(loc);
+    *loc = ptr - buf;
+    DEBUG_PRINTF("escape found at offset %zu\n", *loc);
+    return 1;
+}
+
+static really_inline
+char lbrFwdScanNVerm16(const struct NFA *nfa, const u8 *buf,
+                       size_t begin, size_t end, size_t *loc) {
+    assert(begin <= end);
+    assert(nfa->type == LBR_NFA_NVERM16);
+    const struct lbr_verm16 *l = getImplNfa(nfa);
+
+    if (begin == end) {
+        return 0;
+    }
+
+    const u8 *ptr = nvermicelli16Exec(l->mask, buf + begin, buf + end);
+    if (ptr == buf + end) {
+        DEBUG_PRINTF("no escape found\n");
+        return 0;
+    }
+
+    assert(loc);
+    *loc = ptr - buf;
+    DEBUG_PRINTF("escape found at offset %zu\n", *loc);
+    return 1;
+}
+
+#define ENGINE_ROOT_NAME Verm16
+#include "lbr_common_impl.h"
+
+#define ENGINE_ROOT_NAME NVerm16
+#include "lbr_common_impl.h"
\ No newline at end of file
index 3dbeeebb430d5a61e66673cb028c1990a7711502..668b253d6e5206ca423e6401885b42af0f3ff2c7 100644 (file)
@@ -270,7 +270,7 @@ static really_inline const u8 *shuftiDoubleMini(SuperVector<S> mask1_lo, SuperVe
     t.print8("t");
 
     typename SuperVector<S>::movemask_type z = t.eqmask(SuperVector<S>::Ones());
-    DEBUG_PRINTF("    z: 0x%08x\n", z);
+    DEBUG_PRINTF(" z: 0x%016llx\n", (u64a)z);
     return firstMatch<S>(buf, z);
 }
 
index ca3a1a2ef707ae57fd5eb7f6ee59c1dcb7a91b19..039eeb3b4f4c9697202e6cf104c200cf067846a2 100644 (file)
@@ -145,6 +145,10 @@ bytecode_ptr<NFA> makeLbrNfa(NFAEngineType nfa_type, enum RepeatType rtype,
     return nfa;
 }
 
+#ifdef HAVE_SVE2
+#include "ng_lbr_sve.hpp"
+#endif
+
 static
 bytecode_ptr<NFA> buildLbrDot(const CharReach &cr, const depth &repeatMin,
                               const depth &repeatMax, u32 minPeriod,
@@ -211,56 +215,6 @@ bytecode_ptr<NFA> buildLbrNVerm(const CharReach &cr, const depth &repeatMin,
     return nfa;
 }
 
-#ifdef HAVE_SVE2
-
-static
-bytecode_ptr<NFA> buildLbrVerm16(const CharReach &cr, const depth &repeatMin,
-                                 const depth &repeatMax, u32 minPeriod,
-                                 bool is_reset, ReportID report) {
-    const CharReach escapes(~cr);
-
-    if (escapes.count() > 16) {
-        return nullptr;
-    }
-
-    enum RepeatType rtype = chooseRepeatType(repeatMin, repeatMax, minPeriod,
-                                             is_reset);
-    auto nfa = makeLbrNfa<lbr_verm16>(LBR_NFA_VERM16, rtype, repeatMax);
-    struct lbr_verm16 *lv = (struct lbr_verm16 *)getMutableImplNfa(nfa.get());
-    vermicelli16Build(escapes, (u8 *)&lv->mask);
-
-    fillNfa<lbr_verm16>(nfa.get(), &lv->common, report, repeatMin, repeatMax,
-                        minPeriod, rtype);
-
-    DEBUG_PRINTF("built verm16 lbr\n");
-    return nfa;
-}
-
-static
-bytecode_ptr<NFA> buildLbrNVerm16(const CharReach &cr, const depth &repeatMin,
-                                  const depth &repeatMax, u32 minPeriod,
-                                  bool is_reset, ReportID report) {
-    const CharReach escapes(cr);
-
-    if (escapes.count() > 16) {
-        return nullptr;
-    }
-
-    enum RepeatType rtype = chooseRepeatType(repeatMin, repeatMax, minPeriod,
-                                             is_reset);
-    auto nfa = makeLbrNfa<lbr_verm16>(LBR_NFA_NVERM16, rtype, repeatMax);
-    struct lbr_verm16 *lv = (struct lbr_verm16 *)getMutableImplNfa(nfa.get());
-    vermicelli16Build(escapes, (u8 *)&lv->mask);
-
-    fillNfa<lbr_verm16>(nfa.get(), &lv->common, report, repeatMin, repeatMax,
-                        minPeriod, rtype);
-
-    DEBUG_PRINTF("built negated verm16 lbr\n");
-    return nfa;
-}
-
-#endif // HAVE_SVE2
-
 static
 bytecode_ptr<NFA> buildLbrShuf(const CharReach &cr, const depth &repeatMin,
                                const depth &repeatMax, u32 minPeriod,
diff --git a/src/nfagraph/ng_lbr_sve.hpp b/src/nfagraph/ng_lbr_sve.hpp
new file mode 100644 (file)
index 0000000..82df3ea
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2015-2017, Intel Corporation
+ * Copyright (c) 2021, Arm Limited
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *  * Neither the name of Intel Corporation nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * \file
+ * \brief Large Bounded Repeat (LBR) engine build code for SVE.
+ */
+
+static
+bytecode_ptr<NFA> buildLbrVerm16(const CharReach &cr, const depth &repeatMin,
+                                 const depth &repeatMax, u32 minPeriod,
+                                 bool is_reset, ReportID report) {
+    const CharReach escapes(~cr);
+
+    if (escapes.count() > 16) {
+        return nullptr;
+    }
+
+    enum RepeatType rtype = chooseRepeatType(repeatMin, repeatMax, minPeriod,
+                                             is_reset);
+    auto nfa = makeLbrNfa<lbr_verm16>(LBR_NFA_VERM16, rtype, repeatMax);
+    struct lbr_verm16 *lv = (struct lbr_verm16 *)getMutableImplNfa(nfa.get());
+    vermicelli16Build(escapes, (u8 *)&lv->mask);
+
+    fillNfa<lbr_verm16>(nfa.get(), &lv->common, report, repeatMin, repeatMax,
+                        minPeriod, rtype);
+
+    DEBUG_PRINTF("built verm16 lbr\n");
+    return nfa;
+}
+
+static
+bytecode_ptr<NFA> buildLbrNVerm16(const CharReach &cr, const depth &repeatMin,
+                                  const depth &repeatMax, u32 minPeriod,
+                                  bool is_reset, ReportID report) {
+    const CharReach escapes(cr);
+
+    if (escapes.count() > 16) {
+        return nullptr;
+    }
+
+    enum RepeatType rtype = chooseRepeatType(repeatMin, repeatMax, minPeriod,
+                                             is_reset);
+    auto nfa = makeLbrNfa<lbr_verm16>(LBR_NFA_NVERM16, rtype, repeatMax);
+    struct lbr_verm16 *lv = (struct lbr_verm16 *)getMutableImplNfa(nfa.get());
+    vermicelli16Build(escapes, (u8 *)&lv->mask);
+
+    fillNfa<lbr_verm16>(nfa.get(), &lv->common, report, repeatMin, repeatMax,
+                        minPeriod, rtype);
+
+    DEBUG_PRINTF("built negated verm16 lbr\n");
+    return nfa;
+}
\ No newline at end of file
index d61cc12c8980887dec96bd35748be54cc5e55a41..602907cb8627d2ab26cc5698a657af939e8c0c3a 100644 (file)
 #define COUNTING_MIRACLE_LEN_MAX 256
 
 #ifdef HAVE_SVE2
-
-static really_inline
-size_t countMatches(svuint8_t chars, svbool_t pg, const u8 *buf) {
-    svuint8_t vec = svld1_u8(pg, buf);
-    return svcntp_b8(svptrue_b8(), svmatch(pg, vec, chars));
-}
-
-static really_inline
-bool countLoopBody(svuint8_t chars, svbool_t pg, const u8 *d,
-                   u32 target_count, u32 *count_inout, const u8 **d_out) {
-    *count_inout += countMatches(chars, pg, d);
-    if (*count_inout >= target_count) {
-        *d_out = d;
-        return true;
-    }
-    return false;
-}
-
-static really_inline
-bool countOnce(svuint8_t chars, const u8 *d, const u8 *d_end,
-               u32 target_count, u32 *count_inout, const u8 **d_out) {
-    assert(d <= d_end);
-    svbool_t pg = svwhilelt_b8_s64(0, d_end - d);
-    return countLoopBody(chars, pg, d, target_count, count_inout, d_out);
-}
-
-static really_inline
-bool roseCountingMiracleScan(u8 c, const u8 *d, const u8 *d_end,
-                             u32 target_count, u32 *count_inout,
-                             const u8 **d_out) {
-    assert(d <= d_end);
-    svuint8_t chars = svdup_u8(c);
-    size_t len = d_end - d;
-    if (len <= svcntb()) {
-        bool rv = countOnce(chars, d, d_end, target_count, count_inout, d_out);
-        return rv;
-    }
-    // peel off first part to align to the vector size
-    const u8 *aligned_d_end = ROUNDDOWN_PTR(d_end, svcntb_pat(SV_POW2));
-    assert(d < aligned_d_end);
-    if (d_end != aligned_d_end) {
-        if (countOnce(chars, aligned_d_end, d_end,
-                      target_count, count_inout, d_out)) return true;
-        d_end = aligned_d_end;
-    }
-    size_t loops = (d_end - d) / svcntb();
-    for (size_t i = 0; i < loops; i++) {
-        d_end -= svcntb();
-        if (countLoopBody(chars, svptrue_b8(), d_end,
-                          target_count, count_inout, d_out)) return true;
-    }
-    if (d != d_end) {
-        if (countOnce(chars, d, d_end,
-                      target_count, count_inout, d_out)) return true;
-    }
-    return false;
-}
-
+#include "counting_miracle_sve.h"
 #else
 
 static really_inline
@@ -146,71 +89,7 @@ char roseCountingMiracleScan(u8 c, const u8 *d, const u8 *d_end,
 #endif
 
 #ifdef HAVE_SVE
-
-static really_inline
-size_t countShuftiMatches(svuint8_t mask_lo, svuint8_t mask_hi,
-                          const svbool_t pg, const u8 *buf) {
-    svuint8_t vec = svld1_u8(pg, buf);
-    svuint8_t c_lo = svtbl(mask_lo, svand_z(svptrue_b8(), vec, (uint8_t)0xf));
-    svuint8_t c_hi = svtbl(mask_hi, svlsr_z(svptrue_b8(), vec, 4));
-    svuint8_t t = svand_z(svptrue_b8(), c_lo, c_hi);
-    return svcntp_b8(svptrue_b8(), svcmpne(pg, t, (uint8_t)0));
-}
-
-static really_inline
-bool countShuftiLoopBody(svuint8_t mask_lo, svuint8_t mask_hi,
-                         const svbool_t pg, const u8 *d, u32 target_count,
-                         u32 *count_inout, const u8 **d_out) {
-    *count_inout += countShuftiMatches(mask_lo, mask_hi, pg, d);
-    if (*count_inout >= target_count) {
-        *d_out = d;
-        return true;
-    }
-    return false;
-}
-
-static really_inline
-bool countShuftiOnce(svuint8_t mask_lo, svuint8_t mask_hi,
-                     const u8 *d, const u8 *d_end, u32 target_count,
-                     u32 *count_inout, const u8 **d_out) {
-    svbool_t pg = svwhilelt_b8_s64(0, d_end - d);
-    return countShuftiLoopBody(mask_lo, mask_hi, pg, d, target_count,
-                               count_inout, d_out);
-}
-
-static really_inline
-bool roseCountingMiracleScanShufti(svuint8_t mask_lo, svuint8_t mask_hi,
-                                   UNUSED u8 poison, const u8 *d,
-                                   const u8 *d_end, u32 target_count,
-                                   u32 *count_inout, const u8 **d_out) {
-    assert(d <= d_end);
-    size_t len = d_end - d;
-    if (len <= svcntb()) {
-        char rv = countShuftiOnce(mask_lo, mask_hi, d, d_end, target_count,
-                                  count_inout, d_out);
-        return rv;
-    }
-    // peel off first part to align to the vector size
-    const u8 *aligned_d_end = ROUNDDOWN_PTR(d_end, svcntb_pat(SV_POW2));
-    assert(d < aligned_d_end);
-    if (d_end != aligned_d_end) {
-        if (countShuftiOnce(mask_lo, mask_hi, aligned_d_end, d_end,
-                            target_count, count_inout, d_out)) return true;
-        d_end = aligned_d_end;
-    }
-    size_t loops = (d_end - d) / svcntb();
-    for (size_t i = 0; i < loops; i++) {
-        d_end -= svcntb();
-        if (countShuftiLoopBody(mask_lo, mask_hi, svptrue_b8(), d_end,
-                                target_count, count_inout, d_out)) return true;
-    }
-    if (d != d_end) {
-        if (countShuftiOnce(mask_lo, mask_hi, d, d_end,
-                            target_count, count_inout, d_out)) return true;
-    }
-    return false;
-}
-
+#include "counting_miracle_shufti_sve.h"
 #else
 
 #define GET_LO_4(chars) and128(chars, low4bits)
diff --git a/src/rose/counting_miracle_shufti_sve.h b/src/rose/counting_miracle_shufti_sve.h
new file mode 100644 (file)
index 0000000..26991a8
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2015-2017, Intel Corporation
+ * Copyright (c) 2021, Arm Limited
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *  * Neither the name of Intel Corporation nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+static really_inline
+size_t countShuftiMatches(svuint8_t mask_lo, svuint8_t mask_hi,
+                          const svbool_t pg, const u8 *buf) {
+    svuint8_t vec = svld1_u8(pg, buf);
+    svuint8_t c_lo = svtbl(mask_lo, svand_z(svptrue_b8(), vec, (uint8_t)0xf));
+    svuint8_t c_hi = svtbl(mask_hi, svlsr_z(svptrue_b8(), vec, 4));
+    svuint8_t t = svand_z(svptrue_b8(), c_lo, c_hi);
+    return svcntp_b8(svptrue_b8(), svcmpne(pg, t, (uint8_t)0));
+}
+
+static really_inline
+bool countShuftiLoopBody(svuint8_t mask_lo, svuint8_t mask_hi,
+                         const svbool_t pg, const u8 *d, u32 target_count,
+                         u32 *count_inout, const u8 **d_out) {
+    *count_inout += countShuftiMatches(mask_lo, mask_hi, pg, d);
+    if (*count_inout >= target_count) {
+        *d_out = d;
+        return true;
+    }
+    return false;
+}
+
+static really_inline
+bool countShuftiOnce(svuint8_t mask_lo, svuint8_t mask_hi,
+                     const u8 *d, const u8 *d_end, u32 target_count,
+                     u32 *count_inout, const u8 **d_out) {
+    svbool_t pg = svwhilelt_b8_s64(0, d_end - d);
+    return countShuftiLoopBody(mask_lo, mask_hi, pg, d, target_count,
+                               count_inout, d_out);
+}
+
+static really_inline
+bool roseCountingMiracleScanShufti(svuint8_t mask_lo, svuint8_t mask_hi,
+                                   UNUSED u8 poison, const u8 *d,
+                                   const u8 *d_end, u32 target_count,
+                                   u32 *count_inout, const u8 **d_out) {
+    assert(d <= d_end);
+    size_t len = d_end - d;
+    if (len <= svcntb()) {
+        char rv = countShuftiOnce(mask_lo, mask_hi, d, d_end, target_count,
+                                  count_inout, d_out);
+        return rv;
+    }
+    // peel off first part to align to the vector size
+    const u8 *aligned_d_end = ROUNDDOWN_PTR(d_end, svcntb_pat(SV_POW2));
+    assert(d < aligned_d_end);
+    if (d_end != aligned_d_end) {
+        if (countShuftiOnce(mask_lo, mask_hi, aligned_d_end, d_end,
+                            target_count, count_inout, d_out)) return true;
+        d_end = aligned_d_end;
+    }
+    size_t loops = (d_end - d) / svcntb();
+    for (size_t i = 0; i < loops; i++) {
+        d_end -= svcntb();
+        if (countShuftiLoopBody(mask_lo, mask_hi, svptrue_b8(), d_end,
+                                target_count, count_inout, d_out)) return true;
+    }
+    if (d != d_end) {
+        if (countShuftiOnce(mask_lo, mask_hi, d, d_end,
+                            target_count, count_inout, d_out)) return true;
+    }
+    return false;
+}
\ No newline at end of file
diff --git a/src/rose/counting_miracle_sve.h b/src/rose/counting_miracle_sve.h
new file mode 100644 (file)
index 0000000..8a7114f
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2015-2017, Intel Corporation
+ * Copyright (c) 2021, Arm Limited
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *  * Neither the name of Intel Corporation nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+static really_inline
+size_t countMatches(svuint8_t chars, svbool_t pg, const u8 *buf) {
+    svuint8_t vec = svld1_u8(pg, buf);
+    return svcntp_b8(svptrue_b8(), svmatch(pg, vec, chars));
+}
+
+static really_inline
+bool countLoopBody(svuint8_t chars, svbool_t pg, const u8 *d,
+                   u32 target_count, u32 *count_inout, const u8 **d_out) {
+    *count_inout += countMatches(chars, pg, d);
+    if (*count_inout >= target_count) {
+        *d_out = d;
+        return true;
+    }
+    return false;
+}
+
+static really_inline
+bool countOnce(svuint8_t chars, const u8 *d, const u8 *d_end,
+               u32 target_count, u32 *count_inout, const u8 **d_out) {
+    assert(d <= d_end);
+    svbool_t pg = svwhilelt_b8_s64(0, d_end - d);
+    return countLoopBody(chars, pg, d, target_count, count_inout, d_out);
+}
+
+static really_inline
+bool roseCountingMiracleScan(u8 c, const u8 *d, const u8 *d_end,
+                             u32 target_count, u32 *count_inout,
+                             const u8 **d_out) {
+    assert(d <= d_end);
+    svuint8_t chars = svdup_u8(c);
+    size_t len = d_end - d;
+    if (len <= svcntb()) {
+        bool rv = countOnce(chars, d, d_end, target_count, count_inout, d_out);
+        return rv;
+    }
+    // peel off first part to align to the vector size
+    const u8 *aligned_d_end = ROUNDDOWN_PTR(d_end, svcntb_pat(SV_POW2));
+    assert(d < aligned_d_end);
+    if (d_end != aligned_d_end) {
+        if (countOnce(chars, aligned_d_end, d_end,
+                      target_count, count_inout, d_out)) return true;
+        d_end = aligned_d_end;
+    }
+    size_t loops = (d_end - d) / svcntb();
+    for (size_t i = 0; i < loops; i++) {
+        d_end -= svcntb();
+        if (countLoopBody(chars, svptrue_b8(), d_end,
+                          target_count, count_inout, d_out)) return true;
+    }
+    if (d != d_end) {
+        if (countOnce(chars, d, d_end,
+                      target_count, count_inout, d_out)) return true;
+    }
+    return false;
+}
\ No newline at end of file
index c73e623c1a1b7de58e24b0b54bae38905007c658..a2f98c99762e907e760a025e96cb056fe3aa91a5 100644 (file)
@@ -119,24 +119,23 @@ m128 compress128_impl(m128 x, m128 m) {
     return res;
 }
 
-static really_inline
-u32 expand32_impl(u32 x, u32 m) {
+
 #if defined(HAVE_SVE2_BITPERM)
-    return svlasta(svpfalse(), svbdep(svdup_u32(x), m));
+#include "bitutils_sve.h"
 #else
+
+static really_inline
+u32 expand32_impl(u32 x, u32 m) {
     return expand32_impl_c(x, m);
-#endif
 }
 
 static really_inline
 u64a expand64_impl(u64a x, u64a m) {
-#if defined(HAVE_SVE2_BITPERM)
-    return svlasta(svpfalse(), svbdep(svdup_u64(x), m));
-#else
     return expand64_impl_c(x, m);
-#endif
 }
 
+#endif // HAVE_SVE2_BITPERM
+
 static really_inline
 m128 expand128_impl(m128 x, m128 m) {
     m128 one = set1_2x64(1);
diff --git a/src/util/arch/arm/bitutils_sve.h b/src/util/arch/arm/bitutils_sve.h
new file mode 100644 (file)
index 0000000..1cd503d
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2015-2017, Intel Corporation
+ * Copyright (c) 2021, Arm Limited
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *  * Neither the name of Intel Corporation nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** \file
+ * \brief Bit-twiddling primitives for SVE (ctz, compress etc)
+ */
+
+static really_inline
+u32 expand32_impl(u32 x, u32 m) {
+    return svlasta(svpfalse(), svbdep(svdup_u32(x), m));
+}
+
+static really_inline
+u64a expand64_impl(u64a x, u64a m) {
+    return svlasta(svpfalse(), svbdep(svdup_u64(x), m));
+}
+
+static really_inline
+void bdep64x2(u64a *d, const u64a *x, const m128 *m) {
+    svbool_t pg = svptrue_pat_b64(SV_VL2);
+    svst1(pg, (uint64_t *)d, svbdep(svld1_u64(pg, (const uint64_t *)x),
+                                    svld1_u64(pg, (const uint64_t *)m)));
+}
index e5bc2948e0e0c21d582e7609fdf24965e83def87..917a6ad4475002e246d407c084408dbe54bcc6e7 100644 (file)
 #include "util/intrinsics.h"
 
 #ifdef HAVE_SVE
-
-really_really_inline
-uint64_t accelSearchGetOffset(svbool_t matched) {
-    return svcntp_b8(svptrue_b8(), svbrkb_z(svptrue_b8(), matched));
-}
-
-really_really_inline
-const u8 *accelSearchCheckMatched(const u8 *buf, svbool_t matched) {
-    if (unlikely(svptest_any(svptrue_b8(), matched))) {
-        const u8 *matchPos = buf + accelSearchGetOffset(matched);
-        DEBUG_PRINTF("match pos %p\n", matchPos);
-        return matchPos;
-    }
-    return NULL;
-}
-
-really_really_inline
-const u8 *accelRevSearchCheckMatched(const u8 *buf, svbool_t matched) {
-    if (unlikely(svptest_any(svptrue_b8(), matched))) {
-        const u8 *matchPos = buf + (svcntb() -
-            svcntp_b8(svptrue_b8(), svbrka_z(svptrue_b8(), svrev_b8(matched))));
-        DEBUG_PRINTF("match pos %p\n", matchPos);
-        return matchPos;
-    }
-    return NULL;
-}
-
-static really_inline
-svuint8_t getSVEMaskFrom128(m128 mask) {
-    return svld1_u8(svptrue_pat_b8(SV_VL16), (const uint8_t *)&mask);
-}
-
+#include "simd_utils_sve.h"
 #endif
 
 #ifdef HAVE_SVE2
-
-static really_inline
-svuint8_t getCharMaskSingle(const u8 c, bool noCase) {
-    if (noCase) {
-        uint16_t chars_u16 = (c & 0xdf) | ((c | 0x20) << 8);
-        return svreinterpret_u8(svdup_u16(chars_u16));
-    } else {
-        return svdup_u8(c);
-    }
-}
-
-static really_inline
-svuint16_t getCharMaskDouble(const u8 c0, const u8 c1, bool noCase) {
-    if (noCase) {
-        const uint64_t lowerFirst = c0 & 0xdf;
-        const uint64_t upperFirst = c0 | 0x20;
-        const uint64_t lowerSecond = c1 & 0xdf;
-        const uint64_t upperSecond = c1 | 0x20;
-        const uint64_t chars = lowerFirst | (lowerSecond << 8)
-                          | (lowerFirst << 16) | (upperSecond) << 24
-                          | (upperFirst << 32) | (lowerSecond) << 40
-                          | (upperFirst << 48) | (upperSecond) << 56;
-        return svreinterpret_u16(svdup_u64(chars));
-    } else {
-        uint16_t chars_u16 = c0 | (c1 << 8);
-        return svdup_u16(chars_u16);
-    }
-}
-
+#include "simd_utils_sve2.h"
 #endif
 
 #include <string.h> // for memcpy
diff --git a/src/util/arch/arm/simd_utils_sve.h b/src/util/arch/arm/simd_utils_sve.h
new file mode 100644 (file)
index 0000000..48a4a93
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2021, Arm Limited
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *  * Neither the name of Intel Corporation nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** \file
+ * \brief SVE primitive operations.
+ */
+
+really_really_inline
+uint64_t accelSearchGetOffset(svbool_t matched) {
+    return svcntp_b8(svptrue_b8(), svbrkb_z(svptrue_b8(), matched));
+}
+
+really_really_inline
+const u8 *accelSearchCheckMatched(const u8 *buf, svbool_t matched) {
+    if (unlikely(svptest_any(svptrue_b8(), matched))) {
+        const u8 *matchPos = buf + accelSearchGetOffset(matched);
+        DEBUG_PRINTF("match pos %p\n", matchPos);
+        return matchPos;
+    }
+    return NULL;
+}
+
+really_really_inline
+const u8 *accelRevSearchCheckMatched(const u8 *buf, svbool_t matched) {
+    if (unlikely(svptest_any(svptrue_b8(), matched))) {
+        const u8 *matchPos = buf + (svcntb() -
+            svcntp_b8(svptrue_b8(), svbrka_z(svptrue_b8(), svrev_b8(matched))));
+        DEBUG_PRINTF("match pos %p\n", matchPos);
+        return matchPos;
+    }
+    return NULL;
+}
+
+static really_inline
+svuint8_t getSVEMaskFrom128(m128 mask) {
+    return svld1_u8(svptrue_pat_b8(SV_VL16), (const uint8_t *)&mask);
+}
\ No newline at end of file
diff --git a/src/util/arch/arm/simd_utils_sve2.h b/src/util/arch/arm/simd_utils_sve2.h
new file mode 100644 (file)
index 0000000..188ef3f
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2021, Arm Limited
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *  * Neither the name of Intel Corporation nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** \file
+ * \brief SVE primitive operations.
+ */
+
+static really_inline
+svuint8_t getCharMaskSingle(const u8 c, bool noCase) {
+    if (noCase) {
+        uint16_t chars_u16 = (c & 0xdf) | ((c | 0x20) << 8);
+        return svreinterpret_u8(svdup_u16(chars_u16));
+    } else {
+        return svdup_u8(c);
+    }
+}
+
+static really_inline
+svuint16_t getCharMaskDouble(const u8 c0, const u8 c1, bool noCase) {
+    if (noCase) {
+        const uint64_t lowerFirst = c0 & 0xdf;
+        const uint64_t upperFirst = c0 | 0x20;
+        const uint64_t lowerSecond = c1 & 0xdf;
+        const uint64_t upperSecond = c1 | 0x20;
+        const uint64_t chars = lowerFirst | (lowerSecond << 8)
+                          | (lowerFirst << 16) | (upperSecond) << 24
+                          | (upperFirst << 32) | (lowerSecond) << 40
+                          | (upperFirst << 48) | (upperSecond) << 56;
+        return svreinterpret_u16(svdup_u64(chars));
+    } else {
+        uint16_t chars_u16 = c0 | (c1 << 8);
+        return svdup_u16(chars_u16);
+    }
+}
\ No newline at end of file
index e3f50949ac4b7f280540edbaca4312fe199a0b76..729eedb3865989175eb289e37b53df4ce75a0d76 100644 (file)
@@ -83,17 +83,6 @@ void loadcompressed64(u64a *x, const void *ptr, const u64a *m, u32 bytes) {
 #endif
 }
 
-#if defined(HAVE_SVE2_BITPERM)
-
-static really_inline
-void bdep64x2(u64a *d, const u64a *x, const m128 *m) {
-    svbool_t pg = svptrue_pat_b64(SV_VL2);
-    svst1(pg, (uint64_t *)d, svbdep(svld1_u64(pg, (const uint64_t *)x),
-                                    svld1_u64(pg, (const uint64_t *)m)));
-}
-
-#endif // HAVE_SVE2_BITPERM
-
 /*
  * 128-bit store/load.
  */