diff options
author | bnagaev <bnagaev@yandex-team.ru> | 2022-02-10 16:47:04 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:04 +0300 |
commit | c74559fb88da8adac0d9186cfa55a6b13c47695f (patch) | |
tree | b83306b6e37edeea782e9eed673d89286c4fef35 /contrib/libs/hyperscan/src/hwlm | |
parent | d6449ba66291ff0c0d352c82e6eb3efb4c8a7e8d (diff) | |
download | ydb-c74559fb88da8adac0d9186cfa55a6b13c47695f.tar.gz |
Restoring authorship annotation for <bnagaev@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/hyperscan/src/hwlm')
-rw-r--r-- | contrib/libs/hyperscan/src/hwlm/hwlm.c | 404 | ||||
-rw-r--r-- | contrib/libs/hyperscan/src/hwlm/hwlm.h | 248 | ||||
-rw-r--r-- | contrib/libs/hyperscan/src/hwlm/hwlm_build.cpp | 382 | ||||
-rw-r--r-- | contrib/libs/hyperscan/src/hwlm/hwlm_build.h | 154 | ||||
-rw-r--r-- | contrib/libs/hyperscan/src/hwlm/hwlm_internal.h | 124 | ||||
-rw-r--r-- | contrib/libs/hyperscan/src/hwlm/hwlm_literal.cpp | 210 | ||||
-rw-r--r-- | contrib/libs/hyperscan/src/hwlm/hwlm_literal.h | 230 | ||||
-rw-r--r-- | contrib/libs/hyperscan/src/hwlm/noodle_build.cpp | 162 | ||||
-rw-r--r-- | contrib/libs/hyperscan/src/hwlm/noodle_build.h | 114 | ||||
-rw-r--r-- | contrib/libs/hyperscan/src/hwlm/noodle_engine.c | 498 | ||||
-rw-r--r-- | contrib/libs/hyperscan/src/hwlm/noodle_engine.h | 110 | ||||
-rw-r--r-- | contrib/libs/hyperscan/src/hwlm/noodle_engine_avx2.c | 406 | ||||
-rw-r--r-- | contrib/libs/hyperscan/src/hwlm/noodle_engine_sse.c | 350 | ||||
-rw-r--r-- | contrib/libs/hyperscan/src/hwlm/noodle_internal.h | 78 |
14 files changed, 1735 insertions, 1735 deletions
diff --git a/contrib/libs/hyperscan/src/hwlm/hwlm.c b/contrib/libs/hyperscan/src/hwlm/hwlm.c index a46cb26103..8cf585a98c 100644 --- a/contrib/libs/hyperscan/src/hwlm/hwlm.c +++ b/contrib/libs/hyperscan/src/hwlm/hwlm.c @@ -1,191 +1,191 @@ -/* +/* * 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: - * - * * 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 Hamster Wheel Literal Matcher: runtime. - */ -#include "hwlm.h" -#include "hwlm_internal.h" -#include "noodle_engine.h" -#include "scratch.h" -#include "ue2common.h" -#include "fdr/fdr.h" -#include "nfa/accel.h" -#include "nfa/shufti.h" + * + * 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 Hamster Wheel Literal Matcher: runtime. + */ +#include "hwlm.h" +#include "hwlm_internal.h" +#include "noodle_engine.h" +#include "scratch.h" +#include "ue2common.h" +#include "fdr/fdr.h" +#include "nfa/accel.h" +#include "nfa/shufti.h" #include "nfa/truffle.h" -#include "nfa/vermicelli.h" -#include <string.h> - -#define MIN_ACCEL_LEN_BLOCK 16 -#define MIN_ACCEL_LEN_STREAM 16 - -static really_inline -const u8 *run_hwlm_accel(const union AccelAux *aux, const u8 *ptr, - const u8 *end) { - switch (aux->accel_type) { - case ACCEL_VERM: - DEBUG_PRINTF("single vermicelli for 0x%02hhx\n", aux->verm.c); - return vermicelliExec(aux->verm.c, 0, ptr, end); - case ACCEL_VERM_NOCASE: - DEBUG_PRINTF("single vermicelli-nocase for 0x%02hhx\n", aux->verm.c); - return vermicelliExec(aux->verm.c, 1, ptr, end); - case ACCEL_DVERM: - DEBUG_PRINTF("double vermicelli for 0x%02hhx%02hhx\n", aux->dverm.c1, - aux->dverm.c2); - return vermicelliDoubleExec(aux->dverm.c1, aux->dverm.c2, 0, ptr, end); - case ACCEL_DVERM_NOCASE: - DEBUG_PRINTF("double vermicelli-nocase for 0x%02hhx%02hhx\n", - aux->dverm.c1, aux->dverm.c2); - return vermicelliDoubleExec(aux->dverm.c1, aux->dverm.c2, 1, ptr, end); - case ACCEL_SHUFTI: - DEBUG_PRINTF("single shufti\n"); - return shuftiExec(aux->shufti.lo, aux->shufti.hi, ptr, end); +#include "nfa/vermicelli.h" +#include <string.h> + +#define MIN_ACCEL_LEN_BLOCK 16 +#define MIN_ACCEL_LEN_STREAM 16 + +static really_inline +const u8 *run_hwlm_accel(const union AccelAux *aux, const u8 *ptr, + const u8 *end) { + switch (aux->accel_type) { + case ACCEL_VERM: + DEBUG_PRINTF("single vermicelli for 0x%02hhx\n", aux->verm.c); + return vermicelliExec(aux->verm.c, 0, ptr, end); + case ACCEL_VERM_NOCASE: + DEBUG_PRINTF("single vermicelli-nocase for 0x%02hhx\n", aux->verm.c); + return vermicelliExec(aux->verm.c, 1, ptr, end); + case ACCEL_DVERM: + DEBUG_PRINTF("double vermicelli for 0x%02hhx%02hhx\n", aux->dverm.c1, + aux->dverm.c2); + return vermicelliDoubleExec(aux->dverm.c1, aux->dverm.c2, 0, ptr, end); + case ACCEL_DVERM_NOCASE: + DEBUG_PRINTF("double vermicelli-nocase for 0x%02hhx%02hhx\n", + aux->dverm.c1, aux->dverm.c2); + return vermicelliDoubleExec(aux->dverm.c1, aux->dverm.c2, 1, ptr, end); + case ACCEL_SHUFTI: + DEBUG_PRINTF("single shufti\n"); + return shuftiExec(aux->shufti.lo, aux->shufti.hi, ptr, end); case ACCEL_TRUFFLE: DEBUG_PRINTF("truffle\n"); return truffleExec(aux->truffle.mask1, aux->truffle.mask2, ptr, end); - default: - /* no acceleration, fall through and return current ptr */ + default: + /* no acceleration, fall through and return current ptr */ DEBUG_PRINTF("no accel; %u\n", (int)aux->accel_type); assert(aux->accel_type == ACCEL_NONE); - return ptr; - } -} - -static really_inline -void do_accel_block(const union AccelAux *aux, const u8 *buf, size_t len, - size_t *start) { - if (len - *start < MIN_ACCEL_LEN_BLOCK) { - return; - } - - const u8 *ptr = buf + *start; - const u8 *end = buf + len; - const u8 offset = aux->generic.offset; - ptr = run_hwlm_accel(aux, ptr, end); - - if (offset) { - ptr -= offset; - if (ptr < buf) { - ptr = buf; - } - } - assert(ptr >= buf); - *start = ptr - buf; -} - -static really_inline -int inaccurate_accel(u8 type) { - /* accels which don't always catch up to the boundary - * DSHUFTI is also inaccurate but it is not used by the hamsters */ - return type == ACCEL_DVERM_NOCASE || type == ACCEL_DVERM; -} - -static never_inline -void do_accel_streaming(const union AccelAux *aux, const u8 *hbuf, size_t hlen, - const u8 *buf, size_t len, size_t *start) { - if (aux->accel_type == ACCEL_NONE || len - *start < MIN_ACCEL_LEN_STREAM) { - return; - } - - const u8 offset = aux->generic.offset; - - DEBUG_PRINTF("using accel %hhu offset %hhu\n", aux->accel_type, offset); - - // Scan history buffer, but only if the start offset (which always refers to - // buf) is zero. - - if (!*start && hlen) { - const u8 *ptr1 = hbuf; - const u8 *end1 = hbuf + hlen; - if (hlen >= 16) { - ptr1 = run_hwlm_accel(aux, ptr1, end1); - } - - if ((hlen <= 16 || inaccurate_accel(aux->accel_type)) - && end1 != ptr1 && end1 - ptr1 <= 16) { - DEBUG_PRINTF("already scanned %zu/%zu\n", ptr1 - hbuf, hlen); - /* see if we can finish off the history buffer completely */ - u8 ALIGN_DIRECTIVE temp[17]; - ptrdiff_t tlen = end1 - ptr1; - memcpy(temp, ptr1, tlen); - memset(temp + tlen, 0, 17 - tlen); - if (len) { /* for dverm */ - temp[end1 - ptr1] = *buf; - } - - const u8 *tempp = run_hwlm_accel(aux, temp, temp + 17); - - if (tempp - temp >= tlen) { - ptr1 = end1; - } - DEBUG_PRINTF("got %zu\n", tempp - temp); - } - - if (ptr1 != end1) { - DEBUG_PRINTF("bailing in history\n"); - return; - } - } - - DEBUG_PRINTF("scanning main buffer, start=%zu, len=%zu\n", *start, len); - - const u8 *ptr2 = buf + *start; - const u8 *end2 = buf + len; - - const u8 *found = run_hwlm_accel(aux, ptr2, end2); - - if (found >= ptr2 + offset) { - size_t delta = found - offset - ptr2; - DEBUG_PRINTF("got %zu/%zu in 2nd buffer\n", delta, len); - *start += delta; - } else if (hlen) { - UNUSED size_t remaining = offset + ptr2 - found; - DEBUG_PRINTF("got %zu/%zu remaining in 1st buffer\n", remaining, hlen); - } -} - -hwlm_error_t hwlmExec(const struct HWLM *t, const u8 *buf, size_t len, + return ptr; + } +} + +static really_inline +void do_accel_block(const union AccelAux *aux, const u8 *buf, size_t len, + size_t *start) { + if (len - *start < MIN_ACCEL_LEN_BLOCK) { + return; + } + + const u8 *ptr = buf + *start; + const u8 *end = buf + len; + const u8 offset = aux->generic.offset; + ptr = run_hwlm_accel(aux, ptr, end); + + if (offset) { + ptr -= offset; + if (ptr < buf) { + ptr = buf; + } + } + assert(ptr >= buf); + *start = ptr - buf; +} + +static really_inline +int inaccurate_accel(u8 type) { + /* accels which don't always catch up to the boundary + * DSHUFTI is also inaccurate but it is not used by the hamsters */ + return type == ACCEL_DVERM_NOCASE || type == ACCEL_DVERM; +} + +static never_inline +void do_accel_streaming(const union AccelAux *aux, const u8 *hbuf, size_t hlen, + const u8 *buf, size_t len, size_t *start) { + if (aux->accel_type == ACCEL_NONE || len - *start < MIN_ACCEL_LEN_STREAM) { + return; + } + + const u8 offset = aux->generic.offset; + + DEBUG_PRINTF("using accel %hhu offset %hhu\n", aux->accel_type, offset); + + // Scan history buffer, but only if the start offset (which always refers to + // buf) is zero. + + if (!*start && hlen) { + const u8 *ptr1 = hbuf; + const u8 *end1 = hbuf + hlen; + if (hlen >= 16) { + ptr1 = run_hwlm_accel(aux, ptr1, end1); + } + + if ((hlen <= 16 || inaccurate_accel(aux->accel_type)) + && end1 != ptr1 && end1 - ptr1 <= 16) { + DEBUG_PRINTF("already scanned %zu/%zu\n", ptr1 - hbuf, hlen); + /* see if we can finish off the history buffer completely */ + u8 ALIGN_DIRECTIVE temp[17]; + ptrdiff_t tlen = end1 - ptr1; + memcpy(temp, ptr1, tlen); + memset(temp + tlen, 0, 17 - tlen); + if (len) { /* for dverm */ + temp[end1 - ptr1] = *buf; + } + + const u8 *tempp = run_hwlm_accel(aux, temp, temp + 17); + + if (tempp - temp >= tlen) { + ptr1 = end1; + } + DEBUG_PRINTF("got %zu\n", tempp - temp); + } + + if (ptr1 != end1) { + DEBUG_PRINTF("bailing in history\n"); + return; + } + } + + DEBUG_PRINTF("scanning main buffer, start=%zu, len=%zu\n", *start, len); + + const u8 *ptr2 = buf + *start; + const u8 *end2 = buf + len; + + const u8 *found = run_hwlm_accel(aux, ptr2, end2); + + if (found >= ptr2 + offset) { + size_t delta = found - offset - ptr2; + DEBUG_PRINTF("got %zu/%zu in 2nd buffer\n", delta, len); + *start += delta; + } else if (hlen) { + UNUSED size_t remaining = offset + ptr2 - found; + DEBUG_PRINTF("got %zu/%zu remaining in 1st buffer\n", remaining, hlen); + } +} + +hwlm_error_t hwlmExec(const struct HWLM *t, const u8 *buf, size_t len, size_t start, HWLMCallback cb, struct hs_scratch *scratch, - hwlm_group_t groups) { + hwlm_group_t groups) { assert(t); - DEBUG_PRINTF("buf len=%zu, start=%zu, groups=%llx\n", len, start, groups); - if (!groups) { - DEBUG_PRINTF("groups all off\n"); - return HWLM_SUCCESS; - } - - assert(start < len); - - if (t->type == HWLM_ENGINE_NOOD) { - DEBUG_PRINTF("calling noodExec\n"); + DEBUG_PRINTF("buf len=%zu, start=%zu, groups=%llx\n", len, start, groups); + if (!groups) { + DEBUG_PRINTF("groups all off\n"); + return HWLM_SUCCESS; + } + + assert(start < len); + + if (t->type == HWLM_ENGINE_NOOD) { + DEBUG_PRINTF("calling noodExec\n"); return noodExec(HWLM_C_DATA(t), buf, len, start, cb, scratch); - } + } assert(t->type == HWLM_ENGINE_FDR); const union AccelAux *aa = &t->accel0; @@ -196,38 +196,38 @@ hwlm_error_t hwlmExec(const struct HWLM *t, const u8 *buf, size_t len, do_accel_block(aa, buf, len, &start); DEBUG_PRINTF("calling frankie (groups=%08llx, start=%zu)\n", groups, start); return fdrExec(HWLM_C_DATA(t), buf, len, start, cb, scratch, groups); -} - +} + hwlm_error_t hwlmExecStreaming(const struct HWLM *t, size_t len, size_t start, HWLMCallback cb, struct hs_scratch *scratch, hwlm_group_t groups) { assert(t); assert(scratch); - const u8 *hbuf = scratch->core_info.hbuf; - const size_t hlen = scratch->core_info.hlen; - const u8 *buf = scratch->core_info.buf; - - DEBUG_PRINTF("hbuf len=%zu, buf len=%zu, start=%zu, groups=%llx\n", hlen, - len, start, groups); - - if (!groups) { - return HWLM_SUCCESS; - } - - assert(start < len); - - if (t->type == HWLM_ENGINE_NOOD) { - DEBUG_PRINTF("calling noodExec\n"); - // If we've been handed a start offset, we can use a block mode scan at - // that offset. - if (start) { + const u8 *hbuf = scratch->core_info.hbuf; + const size_t hlen = scratch->core_info.hlen; + const u8 *buf = scratch->core_info.buf; + + DEBUG_PRINTF("hbuf len=%zu, buf len=%zu, start=%zu, groups=%llx\n", hlen, + len, start, groups); + + if (!groups) { + return HWLM_SUCCESS; + } + + assert(start < len); + + if (t->type == HWLM_ENGINE_NOOD) { + DEBUG_PRINTF("calling noodExec\n"); + // If we've been handed a start offset, we can use a block mode scan at + // that offset. + if (start) { return noodExec(HWLM_C_DATA(t), buf, len, start, cb, scratch); - } else { - return noodExecStreaming(HWLM_C_DATA(t), hbuf, hlen, buf, len, cb, + } else { + return noodExecStreaming(HWLM_C_DATA(t), hbuf, hlen, buf, len, cb, scratch); - } - } + } + } assert(t->type == HWLM_ENGINE_FDR); const union AccelAux *aa = &t->accel0; @@ -239,4 +239,4 @@ hwlm_error_t hwlmExecStreaming(const struct HWLM *t, size_t len, size_t start, DEBUG_PRINTF("calling frankie (groups=%08llx, start=%zu)\n", groups, start); return fdrExecStreaming(HWLM_C_DATA(t), hbuf, hlen, buf, len, start, cb, scratch, groups); -} +} diff --git a/contrib/libs/hyperscan/src/hwlm/hwlm.h b/contrib/libs/hyperscan/src/hwlm/hwlm.h index 95a537bd50..224ecf6bf9 100644 --- a/contrib/libs/hyperscan/src/hwlm/hwlm.h +++ b/contrib/libs/hyperscan/src/hwlm/hwlm.h @@ -1,145 +1,145 @@ -/* +/* * 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: - * - * * 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 Hamster Wheel Literal Matcher: runtime API. - */ - -#ifndef HWLM_H -#define HWLM_H - -#include "ue2common.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -/** \brief Error return type for exec functions. */ -typedef int hwlm_error_t; - -/** \brief Type representing a set of groups as a bitmap. */ -typedef u64a hwlm_group_t; - -/** \brief HWLM callback return type. */ -typedef hwlm_group_t hwlmcb_rv_t; - -/** \brief Value representing all possible literal groups. */ -#define HWLM_ALL_GROUPS ((hwlm_group_t)~0ULL) - -/** \brief Callback return value indicating that we should continue matching. */ -#define HWLM_CONTINUE_MATCHING HWLM_ALL_GROUPS - -/** \brief Callback return value indicating that we should halt matching. */ -#define HWLM_TERMINATE_MATCHING 0 - -/** \brief Matching finished without being terminated by the user. */ -#define HWLM_SUCCESS 0 - -/** \brief The user terminated matching by returning HWLM_TERMINATE_MATCHING - * from the match callback. */ -#define HWLM_TERMINATED 1 - -/** \brief An error occurred during matching. - * - * This should only be used if an unsupported engine was called (like one - * designed for a different architecture). */ -#define HWLM_ERROR_UNKNOWN 2 - + * + * 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 Hamster Wheel Literal Matcher: runtime API. + */ + +#ifndef HWLM_H +#define HWLM_H + +#include "ue2common.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** \brief Error return type for exec functions. */ +typedef int hwlm_error_t; + +/** \brief Type representing a set of groups as a bitmap. */ +typedef u64a hwlm_group_t; + +/** \brief HWLM callback return type. */ +typedef hwlm_group_t hwlmcb_rv_t; + +/** \brief Value representing all possible literal groups. */ +#define HWLM_ALL_GROUPS ((hwlm_group_t)~0ULL) + +/** \brief Callback return value indicating that we should continue matching. */ +#define HWLM_CONTINUE_MATCHING HWLM_ALL_GROUPS + +/** \brief Callback return value indicating that we should halt matching. */ +#define HWLM_TERMINATE_MATCHING 0 + +/** \brief Matching finished without being terminated by the user. */ +#define HWLM_SUCCESS 0 + +/** \brief The user terminated matching by returning HWLM_TERMINATE_MATCHING + * from the match callback. */ +#define HWLM_TERMINATED 1 + +/** \brief An error occurred during matching. + * + * This should only be used if an unsupported engine was called (like one + * designed for a different architecture). */ +#define HWLM_ERROR_UNKNOWN 2 + /** \brief Max length of the literal passed to HWLM. */ #define HWLM_LITERAL_MAX_LEN 8 -struct hs_scratch; -struct HWLM; - -/** \brief The type for an HWLM callback. - * +struct hs_scratch; +struct HWLM; + +/** \brief The type for an HWLM callback. + * * This callback receives an end-of-match offset, the ID of the match and * the context pointer that was passed into \ref hwlmExec or * \ref hwlmExecStreaming. - * - * A callback return of \ref HWLM_TERMINATE_MATCHING will stop matching. - * - * A callback return of \ref HWLM_CONTINUE_MATCHING continues matching. - * - * An arbitrary group mask may be given as the return value. This will be taken - * as a hint by the underlying engine that only literals with groups - * overlapping the provided mask need to be reported. - * - * The underlying engine may choose not to report a match if there is no group - * belonging to the literal which was active at the when the end match location - * was first reached. - */ + * + * A callback return of \ref HWLM_TERMINATE_MATCHING will stop matching. + * + * A callback return of \ref HWLM_CONTINUE_MATCHING continues matching. + * + * An arbitrary group mask may be given as the return value. This will be taken + * as a hint by the underlying engine that only literals with groups + * overlapping the provided mask need to be reported. + * + * The underlying engine may choose not to report a match if there is no group + * belonging to the literal which was active at the when the end match location + * was first reached. + */ typedef hwlmcb_rv_t (*HWLMCallback)(size_t end, u32 id, struct hs_scratch *scratch); - -/** \brief Match strings in table. - * - * If a match occurs, the callback function given will be called with the index - * of the last character in the string and the \p context (passed through - * without interpretation). - * - * Returns \ref HWLM_TERMINATED if scanning is cancelled due to the callback - * returning \ref HWLM_TERMINATE_MATCHING. - * + +/** \brief Match strings in table. + * + * If a match occurs, the callback function given will be called with the index + * of the last character in the string and the \p context (passed through + * without interpretation). + * + * Returns \ref HWLM_TERMINATED if scanning is cancelled due to the callback + * returning \ref HWLM_TERMINATE_MATCHING. + * * \p start is the first offset at which a match may start. Note: match * starts may include masks overhanging the main literal. - * - * The underlying engine may choose not to report any match which starts before - * the first possible match of a literal which is in the initial group mask. - */ -hwlm_error_t hwlmExec(const struct HWLM *tab, const u8 *buf, size_t len, + * + * The underlying engine may choose not to report any match which starts before + * the first possible match of a literal which is in the initial group mask. + */ +hwlm_error_t hwlmExec(const struct HWLM *tab, const u8 *buf, size_t len, size_t start, HWLMCallback callback, struct hs_scratch *scratch, hwlm_group_t groups); - -/** \brief As for \ref hwlmExec, but a streaming case across two buffers. - * - * \p len is the length of the main buffer to be scanned. - * - * \p start is an advisory hint representing the first offset at which a match + +/** \brief As for \ref hwlmExec, but a streaming case across two buffers. + * + * \p len is the length of the main buffer to be scanned. + * + * \p start is an advisory hint representing the first offset at which a match * may start. Some underlying literal matches may not respect it. Note: match * starts may include masks overhanging the main literal. - * + * * \p scratch is used to access the history buffer, history length and * the main buffer. * - * Two buffers/lengths are provided. Matches that occur entirely within - * the history buffer will not be reported by this function. The offsets - * reported for the main buffer are relative to the start of that buffer (a - * match at byte 10 of the main buffer is reported as 10). Matches that start - * in the history buffer will have starts reported with 'negative' values. - */ + * Two buffers/lengths are provided. Matches that occur entirely within + * the history buffer will not be reported by this function. The offsets + * reported for the main buffer are relative to the start of that buffer (a + * match at byte 10 of the main buffer is reported as 10). Matches that start + * in the history buffer will have starts reported with 'negative' values. + */ hwlm_error_t hwlmExecStreaming(const struct HWLM *tab, size_t len, size_t start, HWLMCallback callback, struct hs_scratch *scratch, hwlm_group_t groups); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif diff --git a/contrib/libs/hyperscan/src/hwlm/hwlm_build.cpp b/contrib/libs/hyperscan/src/hwlm/hwlm_build.cpp index bbd49d340d..1b33281529 100644 --- a/contrib/libs/hyperscan/src/hwlm/hwlm_build.cpp +++ b/contrib/libs/hyperscan/src/hwlm/hwlm_build.cpp @@ -1,65 +1,65 @@ -/* +/* * 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: - * - * * 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 Hamster Wheel Literal Matcher: build code. - */ + * + * 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 Hamster Wheel Literal Matcher: build code. + */ #include "hwlm_build.h" -#include "grey.h" -#include "hwlm.h" -#include "hwlm_internal.h" +#include "grey.h" +#include "hwlm.h" +#include "hwlm_internal.h" #include "hwlm_literal.h" -#include "noodle_engine.h" -#include "noodle_build.h" +#include "noodle_engine.h" +#include "noodle_build.h" #include "scratch.h" -#include "ue2common.h" -#include "fdr/fdr_compile.h" +#include "ue2common.h" +#include "fdr/fdr_compile.h" #include "fdr/fdr_compile_internal.h" #include "fdr/fdr_engine_description.h" #include "fdr/teddy_engine_description.h" -#include "util/compile_context.h" -#include "util/compile_error.h" +#include "util/compile_context.h" +#include "util/compile_error.h" #include "util/make_unique.h" -#include "util/ue2string.h" - -#include <cassert> -#include <cstring> -#include <vector> - -using namespace std; - -namespace ue2 { - +#include "util/ue2string.h" + +#include <cassert> +#include <cstring> +#include <vector> + +using namespace std; + +namespace ue2 { + HWLMProto::HWLMProto(u8 engType_in, vector<hwlmLiteral> lits_in) : engType(engType_in), lits(move(lits_in)) {} - + HWLMProto::HWLMProto(u8 engType_in, unique_ptr<FDREngineDescription> eng_in, vector<hwlmLiteral> lits_in, @@ -67,7 +67,7 @@ HWLMProto::HWLMProto(u8 engType_in, bool make_small_in) : engType(engType_in), fdrEng(move(eng_in)), lits(move(lits_in)), bucketToLits(move(bucketToLits_in)), make_small(make_small_in) {} - + HWLMProto::HWLMProto(u8 engType_in, unique_ptr<TeddyEngineDescription> eng_in, vector<hwlmLiteral> lits_in, @@ -76,45 +76,45 @@ HWLMProto::HWLMProto(u8 engType_in, : engType(engType_in), teddyEng(move(eng_in)), lits(move(lits_in)), bucketToLits(move(bucketToLits_in)), make_small(make_small_in) {} - + HWLMProto::~HWLMProto() {} - -static -void dumpLits(UNUSED const vector<hwlmLiteral> &lits) { -#ifdef DEBUG - DEBUG_PRINTF("building lit table for:\n"); - for (const auto &lit : lits) { - printf("\t%u:%016llx %s%s\n", lit.id, lit.groups, - escapeString(lit.s).c_str(), lit.nocase ? " (nc)" : ""); - } -#endif -} - -#ifndef NDEBUG -// Called by an assertion. -static -bool everyoneHasGroups(const vector<hwlmLiteral> &lits) { - for (const auto &lit : lits) { - if (!lit.groups) { - return false; - } - } - return true; -} -#endif - -static -bool isNoodleable(const vector<hwlmLiteral> &lits, - const CompileContext &cc) { - if (!cc.grey.allowNoodle) { - return false; - } - - if (lits.size() != 1) { - DEBUG_PRINTF("too many literals for noodle\n"); - return false; - } - + +static +void dumpLits(UNUSED const vector<hwlmLiteral> &lits) { +#ifdef DEBUG + DEBUG_PRINTF("building lit table for:\n"); + for (const auto &lit : lits) { + printf("\t%u:%016llx %s%s\n", lit.id, lit.groups, + escapeString(lit.s).c_str(), lit.nocase ? " (nc)" : ""); + } +#endif +} + +#ifndef NDEBUG +// Called by an assertion. +static +bool everyoneHasGroups(const vector<hwlmLiteral> &lits) { + for (const auto &lit : lits) { + if (!lit.groups) { + return false; + } + } + return true; +} +#endif + +static +bool isNoodleable(const vector<hwlmLiteral> &lits, + const CompileContext &cc) { + if (!cc.grey.allowNoodle) { + return false; + } + + if (lits.size() != 1) { + DEBUG_PRINTF("too many literals for noodle\n"); + return false; + } + return true; } @@ -132,7 +132,7 @@ bytecode_ptr<HWLM> hwlmBuild(const HWLMProto &proto, const CompileContext &cc, auto noodle = noodBuildTable(lit); if (noodle) { engSize = noodle.size(); - } + } eng = move(noodle); } else { DEBUG_PRINTF("building a new deal\n"); @@ -141,12 +141,12 @@ bytecode_ptr<HWLM> hwlmBuild(const HWLMProto &proto, const CompileContext &cc, engSize = fdr.size(); } eng = move(fdr); - } - + } + if (!eng) { return nullptr; - } - + } + assert(engSize); if (engSize > cc.grey.limitLiteralMatcherSize) { throw ResourceLimitError(); @@ -159,111 +159,111 @@ bytecode_ptr<HWLM> hwlmBuild(const HWLMProto &proto, const CompileContext &cc, memcpy(HWLM_DATA(h.get()), eng.get(), engSize); return h; -} - +} + unique_ptr<HWLMProto> hwlmBuildProto(vector<hwlmLiteral> &lits, bool make_small, const CompileContext &cc) { - assert(!lits.empty()); - dumpLits(lits); - - // Check that we haven't exceeded the maximum number of literals. - if (lits.size() > cc.grey.limitLiteralCount) { - throw ResourceLimitError(); - } - - // Safety and resource limit checks. - u64a total_chars = 0; - for (const auto &lit : lits) { - assert(!lit.s.empty()); - - if (lit.s.length() > cc.grey.limitLiteralLength) { - throw ResourceLimitError(); - } - total_chars += lit.s.length(); - if (total_chars > cc.grey.limitLiteralMatcherChars) { - throw ResourceLimitError(); - } - - // We do not allow the all-ones ID, as we reserve that for internal use - // within literal matchers. - if (lit.id == 0xffffffffu) { - assert(!"reserved id 0xffffffff used"); - throw CompileError("Internal error."); - } - } - + assert(!lits.empty()); + dumpLits(lits); + + // Check that we haven't exceeded the maximum number of literals. + if (lits.size() > cc.grey.limitLiteralCount) { + throw ResourceLimitError(); + } + + // Safety and resource limit checks. + u64a total_chars = 0; + for (const auto &lit : lits) { + assert(!lit.s.empty()); + + if (lit.s.length() > cc.grey.limitLiteralLength) { + throw ResourceLimitError(); + } + total_chars += lit.s.length(); + if (total_chars > cc.grey.limitLiteralMatcherChars) { + throw ResourceLimitError(); + } + + // We do not allow the all-ones ID, as we reserve that for internal use + // within literal matchers. + if (lit.id == 0xffffffffu) { + assert(!"reserved id 0xffffffff used"); + throw CompileError("Internal error."); + } + } + unique_ptr<HWLMProto> proto; - - DEBUG_PRINTF("building table with %zu strings\n", lits.size()); - - assert(everyoneHasGroups(lits)); - + + DEBUG_PRINTF("building table with %zu strings\n", lits.size()); + + assert(everyoneHasGroups(lits)); + if (isNoodleable(lits, cc)) { - DEBUG_PRINTF("build noodle table\n"); + DEBUG_PRINTF("build noodle table\n"); proto = ue2::make_unique<HWLMProto>(HWLM_ENGINE_NOOD, lits); - } else { - DEBUG_PRINTF("building a new deal\n"); + } else { + DEBUG_PRINTF("building a new deal\n"); proto = fdrBuildProto(HWLM_ENGINE_FDR, lits, make_small, cc.target_info, cc.grey); if (!proto) { return nullptr; - } - } - + } + } + return proto; -} - -size_t hwlmSize(const HWLM *h) { - size_t engSize = 0; - - switch (h->type) { - case HWLM_ENGINE_NOOD: - engSize = noodSize((const noodTable *)HWLM_C_DATA(h)); - break; - case HWLM_ENGINE_FDR: - engSize = fdrSize((const FDR *)HWLM_C_DATA(h)); - break; - } - - if (!engSize) { - return 0; - } - - return engSize + ROUNDUP_CL(sizeof(*h)); -} - -size_t hwlmFloodProneSuffixLen(size_t numLiterals, const CompileContext &cc) { - const size_t NO_LIMIT = ~(size_t)0; - - // NOTE: this function contains a number of magic numbers which are - // conservative estimates of flood-proneness based on internal details of - // the various literal engines that fall under the HWLM aegis. If you - // change those engines, you might need to change this function too. - - DEBUG_PRINTF("%zu literals\n", numLiterals); - - if (cc.grey.allowNoodle && numLiterals <= 1) { - DEBUG_PRINTF("noodle\n"); - return NO_LIMIT; - } - - if (cc.grey.fdrAllowTeddy) { - if (numLiterals <= 48) { - DEBUG_PRINTF("teddy\n"); - return 3; - } - if (cc.target_info.has_avx2() && numLiterals <= 96) { - DEBUG_PRINTF("avx2 teddy\n"); - return 3; - } - } - - // TODO: we had thought we could push this value up to 9, but it seems that - // hurts performance on floods in some FDR models. Super-conservative for - // now. - DEBUG_PRINTF("fdr\n"); - return 3; -} - -} // namespace ue2 +} + +size_t hwlmSize(const HWLM *h) { + size_t engSize = 0; + + switch (h->type) { + case HWLM_ENGINE_NOOD: + engSize = noodSize((const noodTable *)HWLM_C_DATA(h)); + break; + case HWLM_ENGINE_FDR: + engSize = fdrSize((const FDR *)HWLM_C_DATA(h)); + break; + } + + if (!engSize) { + return 0; + } + + return engSize + ROUNDUP_CL(sizeof(*h)); +} + +size_t hwlmFloodProneSuffixLen(size_t numLiterals, const CompileContext &cc) { + const size_t NO_LIMIT = ~(size_t)0; + + // NOTE: this function contains a number of magic numbers which are + // conservative estimates of flood-proneness based on internal details of + // the various literal engines that fall under the HWLM aegis. If you + // change those engines, you might need to change this function too. + + DEBUG_PRINTF("%zu literals\n", numLiterals); + + if (cc.grey.allowNoodle && numLiterals <= 1) { + DEBUG_PRINTF("noodle\n"); + return NO_LIMIT; + } + + if (cc.grey.fdrAllowTeddy) { + if (numLiterals <= 48) { + DEBUG_PRINTF("teddy\n"); + return 3; + } + if (cc.target_info.has_avx2() && numLiterals <= 96) { + DEBUG_PRINTF("avx2 teddy\n"); + return 3; + } + } + + // TODO: we had thought we could push this value up to 9, but it seems that + // hurts performance on floods in some FDR models. Super-conservative for + // now. + DEBUG_PRINTF("fdr\n"); + return 3; +} + +} // namespace ue2 diff --git a/contrib/libs/hyperscan/src/hwlm/hwlm_build.h b/contrib/libs/hyperscan/src/hwlm/hwlm_build.h index bb13ec011b..91f227dce4 100644 --- a/contrib/libs/hyperscan/src/hwlm/hwlm_build.h +++ b/contrib/libs/hyperscan/src/hwlm/hwlm_build.h @@ -1,73 +1,73 @@ -/* +/* * 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: - * - * * 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 Hamster Wheel Literal Matcher: build API. - */ - -#ifndef HWLM_BUILD_H -#define HWLM_BUILD_H - -#include "hwlm.h" -#include "hwlm_literal.h" -#include "ue2common.h" + * + * 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 Hamster Wheel Literal Matcher: build API. + */ + +#ifndef HWLM_BUILD_H +#define HWLM_BUILD_H + +#include "hwlm.h" +#include "hwlm_literal.h" +#include "ue2common.h" #include "util/bytecode_ptr.h" - + #include <map> -#include <memory> -#include <vector> - -struct HWLM; - -namespace ue2 { - +#include <memory> +#include <vector> + +struct HWLM; + +namespace ue2 { + class FDREngineDescription; class TeddyEngineDescription; -struct CompileContext; -struct Grey; - +struct CompileContext; +struct Grey; + /** \brief Class representing a literal matcher prototype. */ struct HWLMProto { /** * \brief Engine type to distinguish noodle from FDR and Teddy. */ u8 engType; - + /** * \brief FDR engine description. */ std::unique_ptr<FDREngineDescription> fdrEng; - + /** * \brief Teddy engine description. */ std::unique_ptr<TeddyEngineDescription> teddyEng; - + /** * \brief HWLM literals passed from Rose. */ @@ -96,36 +96,36 @@ struct HWLMProto { bool make_small_in); ~HWLMProto(); -}; - -/** \brief Build an \ref HWLM literal matcher runtime structure for a group of - * literals. - * +}; + +/** \brief Build an \ref HWLM literal matcher runtime structure for a group of + * literals. + * * \param proto Literal matcher prototype. - * \param cc Compile context. - * \param expected_groups FIXME: document me! - * - * Build failures are generally a result of memory allocation failure. These - * may result in a nullptr return value, or a std::bad_alloc exception being - * thrown. - */ + * \param cc Compile context. + * \param expected_groups FIXME: document me! + * + * Build failures are generally a result of memory allocation failure. These + * may result in a nullptr return value, or a std::bad_alloc exception being + * thrown. + */ bytecode_ptr<HWLM> hwlmBuild(const HWLMProto &proto, const CompileContext &cc, hwlm_group_t expected_groups = HWLM_ALL_GROUPS); - + std::unique_ptr<HWLMProto> hwlmBuildProto(std::vector<hwlmLiteral> &lits, bool make_small, const CompileContext &cc); -/** - * Returns an estimate of the number of repeated characters on the end of a - * literal that will make a literal set of size \a numLiterals suffer - * performance degradation. - */ -size_t hwlmFloodProneSuffixLen(size_t numLiterals, const CompileContext &cc); - -/** \brief Return the size in bytes of an HWLM structure. */ -size_t hwlmSize(const HWLM *h); - -} // namespace - -#endif // HWLM_BUILD_H +/** + * Returns an estimate of the number of repeated characters on the end of a + * literal that will make a literal set of size \a numLiterals suffer + * performance degradation. + */ +size_t hwlmFloodProneSuffixLen(size_t numLiterals, const CompileContext &cc); + +/** \brief Return the size in bytes of an HWLM structure. */ +size_t hwlmSize(const HWLM *h); + +} // namespace + +#endif // HWLM_BUILD_H diff --git a/contrib/libs/hyperscan/src/hwlm/hwlm_internal.h b/contrib/libs/hyperscan/src/hwlm/hwlm_internal.h index 92941160aa..e35c84fdf7 100644 --- a/contrib/libs/hyperscan/src/hwlm/hwlm_internal.h +++ b/contrib/libs/hyperscan/src/hwlm/hwlm_internal.h @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2015, Intel Corporation - * - * 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 Hamster Wheel Literal Matcher: data structures. - */ - -#ifndef HWLM_INTERNAL_H -#define HWLM_INTERNAL_H - -#include "hwlm.h" -#include "ue2common.h" -#include "nfa/accel.h" - -/** \brief Underlying engine is FDR. */ -#define HWLM_ENGINE_FDR 12 - -/** \brief Underlying engine is Noodle. */ -#define HWLM_ENGINE_NOOD 16 - -/** \brief Main Hamster Wheel Literal Matcher header. Followed by - * engine-specific structure. */ -struct HWLM { - u8 type; /**< HWLM_ENGINE_NOOD or HWLM_ENGINE_FDR */ - hwlm_group_t accel1_groups; /**< accelerable groups. */ - union AccelAux accel1; /**< used if group mask is subset of accel1_groups */ - union AccelAux accel0; /**< fallback accel scheme */ -}; - -/** \brief Fetch a const pointer to the underlying engine. */ -#define HWLM_C_DATA(p) ((const void *)((const char *)(p) \ - + ROUNDUP_CL(sizeof(struct HWLM)))) - -/** \brief Fetch a pointer to the underlying engine. */ -#define HWLM_DATA(p) ((void *)((char *)(p) + ROUNDUP_CL(sizeof(struct HWLM)))) - -#endif +/* + * Copyright (c) 2015, Intel Corporation + * + * 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 Hamster Wheel Literal Matcher: data structures. + */ + +#ifndef HWLM_INTERNAL_H +#define HWLM_INTERNAL_H + +#include "hwlm.h" +#include "ue2common.h" +#include "nfa/accel.h" + +/** \brief Underlying engine is FDR. */ +#define HWLM_ENGINE_FDR 12 + +/** \brief Underlying engine is Noodle. */ +#define HWLM_ENGINE_NOOD 16 + +/** \brief Main Hamster Wheel Literal Matcher header. Followed by + * engine-specific structure. */ +struct HWLM { + u8 type; /**< HWLM_ENGINE_NOOD or HWLM_ENGINE_FDR */ + hwlm_group_t accel1_groups; /**< accelerable groups. */ + union AccelAux accel1; /**< used if group mask is subset of accel1_groups */ + union AccelAux accel0; /**< fallback accel scheme */ +}; + +/** \brief Fetch a const pointer to the underlying engine. */ +#define HWLM_C_DATA(p) ((const void *)((const char *)(p) \ + + ROUNDUP_CL(sizeof(struct HWLM)))) + +/** \brief Fetch a pointer to the underlying engine. */ +#define HWLM_DATA(p) ((void *)((char *)(p) + ROUNDUP_CL(sizeof(struct HWLM)))) + +#endif diff --git a/contrib/libs/hyperscan/src/hwlm/hwlm_literal.cpp b/contrib/libs/hyperscan/src/hwlm/hwlm_literal.cpp index bdab5edd69..692f7c6c0e 100644 --- a/contrib/libs/hyperscan/src/hwlm/hwlm_literal.cpp +++ b/contrib/libs/hyperscan/src/hwlm/hwlm_literal.cpp @@ -1,95 +1,95 @@ -/* +/* * Copyright (c) 2015-2019, Intel Corporation - * - * 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 Hamster Wheel Literal Matcher: literal representation at build time. - */ -#include "hwlm_literal.h" -#include "util/bitutils.h" // for CASE_BIT -#include "util/compare.h" // for ourisalpha -#include "util/ue2string.h" // for escapeString - + * + * 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 Hamster Wheel Literal Matcher: literal representation at build time. + */ +#include "hwlm_literal.h" +#include "util/bitutils.h" // for CASE_BIT +#include "util/compare.h" // for ourisalpha +#include "util/ue2string.h" // for escapeString + #include <algorithm> -#include <iomanip> -#include <sstream> - -using namespace std; - -namespace ue2 { - -#ifdef DEBUG -static UNUSED -std::string dumpMask(const vector<u8> &v) { - ostringstream oss; - vector<u8>::const_iterator it, ite; - for (it = v.begin(), ite = v.end(); it != ite; ++it) { - oss << setfill('0') << setw(2) << hex << (unsigned int)*it; - } - return oss.str(); -} -#endif - -bool maskIsConsistent(const std::string &s, bool nocase, const vector<u8> &msk, - const vector<u8> &cmp) { - string::const_reverse_iterator si = s.rbegin(); - vector<u8>::const_reverse_iterator mi = msk.rbegin(), ci = cmp.rbegin(); - - for (; si != s.rend() && mi != msk.rend(); ++si, ++mi, ++ci) { - u8 c = *si, m = *mi, v = *ci; - if (nocase && ourisalpha(c)) { - m &= ~CASE_BIT; - v &= ~CASE_BIT; - } - - assert(ci != cmp.rend()); - if ((c & m) != v) { - DEBUG_PRINTF("c = %02hhx; *ci = %02hhx m =%02hhx\n", c, *ci, m); - DEBUG_PRINTF("s = %s; dist = %zd\n", s.c_str(), si - s.rbegin()); - return false; - } - } - - return true; -} - -/** \brief Complete constructor, takes group information and msk/cmp. - * - * This constructor takes a msk/cmp pair. Both must be vectors of length <= - * \ref HWLM_MASKLEN. */ -hwlmLiteral::hwlmLiteral(const std::string &s_in, bool nocase_in, - bool noruns_in, u32 id_in, hwlm_group_t groups_in, - const vector<u8> &msk_in, const vector<u8> &cmp_in) - : s(s_in), id(id_in), nocase(nocase_in), noruns(noruns_in), - groups(groups_in), msk(msk_in), cmp(cmp_in) { +#include <iomanip> +#include <sstream> + +using namespace std; + +namespace ue2 { + +#ifdef DEBUG +static UNUSED +std::string dumpMask(const vector<u8> &v) { + ostringstream oss; + vector<u8>::const_iterator it, ite; + for (it = v.begin(), ite = v.end(); it != ite; ++it) { + oss << setfill('0') << setw(2) << hex << (unsigned int)*it; + } + return oss.str(); +} +#endif + +bool maskIsConsistent(const std::string &s, bool nocase, const vector<u8> &msk, + const vector<u8> &cmp) { + string::const_reverse_iterator si = s.rbegin(); + vector<u8>::const_reverse_iterator mi = msk.rbegin(), ci = cmp.rbegin(); + + for (; si != s.rend() && mi != msk.rend(); ++si, ++mi, ++ci) { + u8 c = *si, m = *mi, v = *ci; + if (nocase && ourisalpha(c)) { + m &= ~CASE_BIT; + v &= ~CASE_BIT; + } + + assert(ci != cmp.rend()); + if ((c & m) != v) { + DEBUG_PRINTF("c = %02hhx; *ci = %02hhx m =%02hhx\n", c, *ci, m); + DEBUG_PRINTF("s = %s; dist = %zd\n", s.c_str(), si - s.rbegin()); + return false; + } + } + + return true; +} + +/** \brief Complete constructor, takes group information and msk/cmp. + * + * This constructor takes a msk/cmp pair. Both must be vectors of length <= + * \ref HWLM_MASKLEN. */ +hwlmLiteral::hwlmLiteral(const std::string &s_in, bool nocase_in, + bool noruns_in, u32 id_in, hwlm_group_t groups_in, + const vector<u8> &msk_in, const vector<u8> &cmp_in) + : s(s_in), id(id_in), nocase(nocase_in), noruns(noruns_in), + groups(groups_in), msk(msk_in), cmp(cmp_in) { assert(s.size() <= HWLM_LITERAL_MAX_LEN); - assert(msk.size() <= HWLM_MASKLEN); - assert(msk.size() == cmp.size()); - + assert(msk.size() <= HWLM_MASKLEN); + assert(msk.size() == cmp.size()); + // If we've been handled a nocase literal, all letter characters must be // upper-case. if (nocase) { @@ -98,20 +98,20 @@ hwlmLiteral::hwlmLiteral(const std::string &s_in, bool nocase_in, DEBUG_PRINTF("literal '%s'%s, msk=%s, cmp=%s\n", escapeString(s).c_str(), nocase ? " (nocase)" : "", dumpMask(msk).c_str(), - dumpMask(cmp).c_str()); - - - // Mask and compare vectors MUST be the same size. - assert(msk.size() == cmp.size()); - - // We must have been passed a msk/cmp that can be applied to s. - assert(maskIsConsistent(s, nocase, msk, cmp)); - - // In the name of good hygiene, zap msk/cmp if msk is all zeroes. + dumpMask(cmp).c_str()); + + + // Mask and compare vectors MUST be the same size. + assert(msk.size() == cmp.size()); + + // We must have been passed a msk/cmp that can be applied to s. + assert(maskIsConsistent(s, nocase, msk, cmp)); + + // In the name of good hygiene, zap msk/cmp if msk is all zeroes. if (all_of(begin(msk), end(msk), [](u8 val) { return val == 0; })) { - msk.clear(); - cmp.clear(); - } -} - -} // namespace ue2 + msk.clear(); + cmp.clear(); + } +} + +} // namespace ue2 diff --git a/contrib/libs/hyperscan/src/hwlm/hwlm_literal.h b/contrib/libs/hyperscan/src/hwlm/hwlm_literal.h index b9bf17538a..598de81471 100644 --- a/contrib/libs/hyperscan/src/hwlm/hwlm_literal.h +++ b/contrib/libs/hyperscan/src/hwlm/hwlm_literal.h @@ -1,71 +1,71 @@ -/* +/* * Copyright (c) 2015-2019, Intel Corporation - * - * 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 Hamster Wheel Literal Matcher: literal representation at build time. - */ - -#ifndef HWLM_LITERAL_H -#define HWLM_LITERAL_H - -#include "hwlm.h" -#include "ue2common.h" - -#include <string> + * + * 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 Hamster Wheel Literal Matcher: literal representation at build time. + */ + +#ifndef HWLM_LITERAL_H +#define HWLM_LITERAL_H + +#include "hwlm.h" +#include "ue2common.h" + +#include <string> #include <tuple> -#include <vector> - -namespace ue2 { - -/** \brief Max length of the hwlmLiteral::msk and hwlmLiteral::cmp vectors. */ -#define HWLM_MASKLEN 8 - +#include <vector> + +namespace ue2 { + +/** \brief Max length of the hwlmLiteral::msk and hwlmLiteral::cmp vectors. */ +#define HWLM_MASKLEN 8 + #define INVALID_LIT_ID ~0U -/** \brief Class representing a literal, fed to \ref hwlmBuild. */ -struct hwlmLiteral { - std::string s; //!< \brief The literal itself. - - /** \brief The ID to pass to the callback if this literal matches. - * - * Note that the special value 0xFFFFFFFF is reserved for internal use and - * should not be used. */ - u32 id; - - bool nocase; //!< \brief True if literal is case-insensitive. - - /** \brief Matches for runs of this literal can be quashed. - * - * Advisory flag meaning that there is no value in returning runs of - * additional matches for a literal after the first one, so such matches - * can be quashed by the literal matcher. */ - bool noruns; - +/** \brief Class representing a literal, fed to \ref hwlmBuild. */ +struct hwlmLiteral { + std::string s; //!< \brief The literal itself. + + /** \brief The ID to pass to the callback if this literal matches. + * + * Note that the special value 0xFFFFFFFF is reserved for internal use and + * should not be used. */ + u32 id; + + bool nocase; //!< \brief True if literal is case-insensitive. + + /** \brief Matches for runs of this literal can be quashed. + * + * Advisory flag meaning that there is no value in returning runs of + * additional matches for a literal after the first one, so such matches + * can be quashed by the literal matcher. */ + bool noruns; + /** \brief included literal id. */ u32 included_id = INVALID_LIT_ID; @@ -81,53 +81,53 @@ struct hwlmLiteral { */ u8 squash = 0; - /** \brief Set of groups that literal belongs to. - * - * Use \ref HWLM_ALL_GROUPS for a literal that could match regardless of - * the groups that are switched on. */ - hwlm_group_t groups; - - /** \brief Supplementary comparison mask. - * - * These two values add a supplementary comparison that is done over the - * final 8 bytes of the string -- if v is those bytes, then the string must - * match as well as (v & msk) == cmp. - * - * An empty msk is the safe way of not adding any comparison to the string - * unnecessarily filling in msk may turn off optimizations. - * - * The msk/cmp mechanism must NOT place a value into the literal that - * conflicts with the contents of the string, but can be allowed to add - * additional power within the string -- for example, to allow some case - * sensitivity within a case-insensitive string. - - * Values are stored in memory order -- i.e. the last byte of the mask - * corresponds to the last byte of the string. Both vectors must be the - * same size, and must not exceed \ref HWLM_MASKLEN in length. - */ - std::vector<u8> msk; - - /** \brief Supplementary comparison value. - * - * See documentation for \ref msk. - */ - std::vector<u8> cmp; - - /** \brief Complete constructor, takes group information and msk/cmp. - * - * This constructor takes a msk/cmp pair. Both must be vectors of length <= - * \ref HWLM_MASKLEN. */ - hwlmLiteral(const std::string &s_in, bool nocase_in, bool noruns_in, - u32 id_in, hwlm_group_t groups_in, - const std::vector<u8> &msk_in, const std::vector<u8> &cmp_in); + /** \brief Set of groups that literal belongs to. + * + * Use \ref HWLM_ALL_GROUPS for a literal that could match regardless of + * the groups that are switched on. */ + hwlm_group_t groups; + + /** \brief Supplementary comparison mask. + * + * These two values add a supplementary comparison that is done over the + * final 8 bytes of the string -- if v is those bytes, then the string must + * match as well as (v & msk) == cmp. + * + * An empty msk is the safe way of not adding any comparison to the string + * unnecessarily filling in msk may turn off optimizations. + * + * The msk/cmp mechanism must NOT place a value into the literal that + * conflicts with the contents of the string, but can be allowed to add + * additional power within the string -- for example, to allow some case + * sensitivity within a case-insensitive string. + + * Values are stored in memory order -- i.e. the last byte of the mask + * corresponds to the last byte of the string. Both vectors must be the + * same size, and must not exceed \ref HWLM_MASKLEN in length. + */ + std::vector<u8> msk; + + /** \brief Supplementary comparison value. + * + * See documentation for \ref msk. + */ + std::vector<u8> cmp; + + /** \brief Complete constructor, takes group information and msk/cmp. + * + * This constructor takes a msk/cmp pair. Both must be vectors of length <= + * \ref HWLM_MASKLEN. */ + hwlmLiteral(const std::string &s_in, bool nocase_in, bool noruns_in, + u32 id_in, hwlm_group_t groups_in, + const std::vector<u8> &msk_in, const std::vector<u8> &cmp_in); /** \brief Simple constructor: no group information, no msk/cmp. * * This constructor is only used in internal unit test. */ hwlmLiteral(const std::string &s_in, bool nocase_in, u32 id_in) : hwlmLiteral(s_in, nocase_in, false, id_in, HWLM_ALL_GROUPS, {}, {}) {} -}; - +}; + inline bool operator<(const hwlmLiteral &a, const hwlmLiteral &b) { return std::tie(a.id, a.s, a.nocase, a.noruns, a.groups, a.msk, a.cmp) < @@ -141,13 +141,13 @@ bool operator==(const hwlmLiteral &a, const hwlmLiteral &b) { a.cmp == b.cmp; } -/** - * Consistency test; returns false if the given msk/cmp test can never match - * the literal string s. - */ -bool maskIsConsistent(const std::string &s, bool nocase, - const std::vector<u8> &msk, const std::vector<u8> &cmp); - -} // namespace ue2 - -#endif // HWLM_LITERAL_H +/** + * Consistency test; returns false if the given msk/cmp test can never match + * the literal string s. + */ +bool maskIsConsistent(const std::string &s, bool nocase, + const std::vector<u8> &msk, const std::vector<u8> &cmp); + +} // namespace ue2 + +#endif // HWLM_LITERAL_H diff --git a/contrib/libs/hyperscan/src/hwlm/noodle_build.cpp b/contrib/libs/hyperscan/src/hwlm/noodle_build.cpp index 711944455f..a0128d0ad7 100644 --- a/contrib/libs/hyperscan/src/hwlm/noodle_build.cpp +++ b/contrib/libs/hyperscan/src/hwlm/noodle_build.cpp @@ -1,53 +1,53 @@ -/* +/* * 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: - * - * * 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. - */ - + * + * 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 Noodle literal matcher: build code. - */ - -#include "noodle_build.h" + * \brief Noodle literal matcher: build code. + */ + +#include "noodle_build.h" #include "hwlm_literal.h" -#include "noodle_internal.h" +#include "noodle_internal.h" #include "util/bitutils.h" -#include "util/compare.h" -#include "util/verify_types.h" +#include "util/compare.h" +#include "util/verify_types.h" #include "ue2common.h" - + #include <cstring> // for memcpy #include <vector> using std::vector; -namespace ue2 { - -static +namespace ue2 { + +static u64a make_u64a_mask(const vector<u8> &v) { assert(v.size() <= sizeof(u64a)); if (v.size() > sizeof(u64a)) { @@ -67,24 +67,24 @@ size_t findNoodFragOffset(const hwlmLiteral &lit) { const auto &s = lit.s; const size_t len = lit.s.length(); - size_t offset = 0; - for (size_t i = 0; i + 1 < len; i++) { - int diff = 0; + size_t offset = 0; + for (size_t i = 0; i + 1 < len; i++) { + int diff = 0; const char c = s[i]; const char d = s[i + 1]; if (lit.nocase && ourisalpha(c)) { - diff = (mytoupper(c) != mytoupper(d)); - } else { - diff = (c != d); - } - offset = i; - if (diff) { - break; - } - } - return offset; -} - + diff = (mytoupper(c) != mytoupper(d)); + } else { + diff = (c != d); + } + offset = i; + if (diff) { + break; + } + } + return offset; +} + bytecode_ptr<noodTable> noodBuildTable(const hwlmLiteral &lit) { const auto &s = lit.s; @@ -115,11 +115,11 @@ bytecode_ptr<noodTable> noodBuildTable(const hwlmLiteral &lit) { } auto n = make_zeroed_bytecode_ptr<noodTable>(sizeof(noodTable)); - assert(n); + assert(n); DEBUG_PRINTF("size of nood %zu\n", sizeof(noodTable)); - + size_t key_offset = findNoodFragOffset(lit); - + n->id = lit.id; n->single = s.length() == 1 ? 1 : 0; n->key_offset = verify_u8(s.length() - key_offset); @@ -133,39 +133,39 @@ bytecode_ptr<noodTable> noodBuildTable(const hwlmLiteral &lit) { n->msk = make_u64a_mask(n_msk); n->cmp = make_u64a_mask(n_cmp); n->msk_len = mask_len; - - return n; -} - + + return n; +} + size_t noodSize(const noodTable *) { return sizeof(noodTable); -} - -} // namespace ue2 - -#ifdef DUMP_SUPPORT -#include <cctype> - -namespace ue2 { - -void noodPrintStats(const noodTable *n, FILE *f) { - fprintf(f, "Noodle table\n"); +} + +} // namespace ue2 + +#ifdef DUMP_SUPPORT +#include <cctype> + +namespace ue2 { + +void noodPrintStats(const noodTable *n, FILE *f) { + fprintf(f, "Noodle table\n"); fprintf(f, "Key Offset: %u\n", n->key_offset); fprintf(f, "Msk: %llx Cmp: %llx MskLen %u\n", n->msk >> 8 * (8 - n->msk_len), n->cmp >> 8 * (8 - n->msk_len), n->msk_len); - fprintf(f, "String: "); + fprintf(f, "String: "); for (u32 i = 0; i < n->msk_len; i++) { const u8 *m = (const u8 *)&n->cmp; if (isgraph(m[i]) && m[i] != '\\') { fprintf(f, "%c", m[i]); - } else { + } else { fprintf(f, "\\x%02hhx", m[i]); - } - } - fprintf(f, "\n"); -} - -} // namespace ue2 - -#endif + } + } + fprintf(f, "\n"); +} + +} // namespace ue2 + +#endif diff --git a/contrib/libs/hyperscan/src/hwlm/noodle_build.h b/contrib/libs/hyperscan/src/hwlm/noodle_build.h index b7cda6b5ab..b5725f0827 100644 --- a/contrib/libs/hyperscan/src/hwlm/noodle_build.h +++ b/contrib/libs/hyperscan/src/hwlm/noodle_build.h @@ -1,65 +1,65 @@ -/* +/* * 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: - * - * * 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 Noodle literal matcher: build code. - */ - + * + * 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 Noodle literal matcher: build code. + */ + #ifndef NOODLE_BUILD_H #define NOODLE_BUILD_H - -#include "ue2common.h" + +#include "ue2common.h" #include "util/bytecode_ptr.h" - -struct noodTable; - -namespace ue2 { - + +struct noodTable; + +namespace ue2 { + struct hwlmLiteral; -/** \brief Construct a Noodle matcher for the given literal. */ +/** \brief Construct a Noodle matcher for the given literal. */ bytecode_ptr<noodTable> noodBuildTable(const hwlmLiteral &lit); - -size_t noodSize(const noodTable *n); - -} // namespace ue2 - -#ifdef DUMP_SUPPORT - -#include <cstdio> - -namespace ue2 { - -void noodPrintStats(const noodTable *n, FILE *f); - -} // namespace ue2 - -#endif // DUMP_SUPPORT - + +size_t noodSize(const noodTable *n); + +} // namespace ue2 + +#ifdef DUMP_SUPPORT + +#include <cstdio> + +namespace ue2 { + +void noodPrintStats(const noodTable *n, FILE *f); + +} // namespace ue2 + +#endif // DUMP_SUPPORT + #endif /* NOODLE_BUILD_H */ - + diff --git a/contrib/libs/hyperscan/src/hwlm/noodle_engine.c b/contrib/libs/hyperscan/src/hwlm/noodle_engine.c index 7fda12de77..d4f6902a2d 100644 --- a/contrib/libs/hyperscan/src/hwlm/noodle_engine.c +++ b/contrib/libs/hyperscan/src/hwlm/noodle_engine.c @@ -1,60 +1,60 @@ -/* +/* * 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: - * - * * 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 Noodle literal matcher: runtime. - */ -#include "hwlm.h" -#include "noodle_engine.h" -#include "noodle_internal.h" + * + * 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 Noodle literal matcher: runtime. + */ +#include "hwlm.h" +#include "noodle_engine.h" +#include "noodle_internal.h" #include "scratch.h" -#include "ue2common.h" +#include "ue2common.h" #include "util/arch.h" -#include "util/bitutils.h" -#include "util/compare.h" +#include "util/bitutils.h" +#include "util/compare.h" #include "util/intrinsics.h" #include "util/join.h" -#include "util/masked_move.h" +#include "util/masked_move.h" #include "util/partial_store.h" -#include "util/simd_utils.h" - -#include <ctype.h> -#include <stdbool.h> -#include <string.h> - -/** \brief Noodle runtime context. */ -struct cb_info { - HWLMCallback cb; //!< callback function called on match - u32 id; //!< ID to pass to callback on match +#include "util/simd_utils.h" + +#include <ctype.h> +#include <stdbool.h> +#include <string.h> + +/** \brief Noodle runtime context. */ +struct cb_info { + HWLMCallback cb; //!< callback function called on match + u32 id; //!< ID to pass to callback on match struct hs_scratch *scratch; //!< scratch to pass to callback - size_t offsetAdj; //!< used in streaming mode -}; - + size_t offsetAdj; //!< used in streaming mode +}; + #if defined(HAVE_AVX512) #define CHUNKSIZE 64 #define MASK_TYPE m512 @@ -73,51 +73,51 @@ struct cb_info { #endif -#define RETURN_IF_TERMINATED(x) \ - { \ - if ((x) == HWLM_TERMINATED) { \ - return HWLM_TERMINATED; \ - } \ - } - -#define SINGLE_ZSCAN() \ - do { \ - while (unlikely(z)) { \ +#define RETURN_IF_TERMINATED(x) \ + { \ + if ((x) == HWLM_TERMINATED) { \ + return HWLM_TERMINATED; \ + } \ + } + +#define SINGLE_ZSCAN() \ + do { \ + while (unlikely(z)) { \ Z_TYPE pos = JOIN(findAndClearLSB_, Z_BITS)(&z); \ - size_t matchPos = d - buf + pos; \ + size_t matchPos = d - buf + pos; \ DEBUG_PRINTF("match pos %zu\n", matchPos); \ hwlmcb_rv_t rv = final(n, buf, len, 1, cbi, matchPos); \ - RETURN_IF_TERMINATED(rv); \ - } \ - } while (0) - -#define DOUBLE_ZSCAN() \ - do { \ - while (unlikely(z)) { \ + RETURN_IF_TERMINATED(rv); \ + } \ + } while (0) + +#define DOUBLE_ZSCAN() \ + do { \ + while (unlikely(z)) { \ Z_TYPE pos = JOIN(findAndClearLSB_, Z_BITS)(&z); \ - size_t matchPos = d - buf + pos - 1; \ + size_t matchPos = d - buf + pos - 1; \ DEBUG_PRINTF("match pos %zu\n", matchPos); \ hwlmcb_rv_t rv = final(n, buf, len, 0, cbi, matchPos); \ - RETURN_IF_TERMINATED(rv); \ - } \ - } while (0) - -static really_inline -u8 caseClear8(u8 x, bool noCase) { - return (u8)(noCase ? (x & (u8)0xdf) : x); -} - -// Make sure the rest of the string is there. The single character scanner -// is used only for single chars with case insensitivity used correctly, -// so it can go straight to the callback if we get this far. -static really_inline + RETURN_IF_TERMINATED(rv); \ + } \ + } while (0) + +static really_inline +u8 caseClear8(u8 x, bool noCase) { + return (u8)(noCase ? (x & (u8)0xdf) : x); +} + +// Make sure the rest of the string is there. The single character scanner +// is used only for single chars with case insensitivity used correctly, +// so it can go straight to the callback if we get this far. +static really_inline hwlm_error_t final(const struct noodTable *n, const u8 *buf, UNUSED size_t len, char single, const struct cb_info *cbi, size_t pos) { if (single) { if (n->msk_len == 1) { goto match; - } - } + } + } assert(len >= n->msk_len); u64a v = partial_load_u64a(buf + pos + n->key_offset - n->msk_len, n->msk_len); @@ -131,34 +131,34 @@ match: pos -= cbi->offsetAdj; DEBUG_PRINTF("match @ %zu\n", pos + n->key_offset); hwlmcb_rv_t rv = cbi->cb(pos + n->key_offset - 1, cbi->id, cbi->scratch); - if (rv == HWLM_TERMINATE_MATCHING) { - return HWLM_TERMINATED; - } - return HWLM_SUCCESS; -} - + if (rv == HWLM_TERMINATE_MATCHING) { + return HWLM_TERMINATED; + } + return HWLM_SUCCESS; +} + #if defined(HAVE_AVX512) #define CHUNKSIZE 64 #define MASK_TYPE m512 #include "noodle_engine_avx512.c" #elif defined(HAVE_AVX2) -#define CHUNKSIZE 32 -#define MASK_TYPE m256 -#include "noodle_engine_avx2.c" -#else -#define CHUNKSIZE 16 -#define MASK_TYPE m128 -#include "noodle_engine_sse.c" -#endif - -static really_inline +#define CHUNKSIZE 32 +#define MASK_TYPE m256 +#include "noodle_engine_avx2.c" +#else +#define CHUNKSIZE 16 +#define MASK_TYPE m128 +#include "noodle_engine_sse.c" +#endif + +static really_inline hwlm_error_t scanSingleMain(const struct noodTable *n, const u8 *buf, size_t len, size_t start, bool noCase, const struct cb_info *cbi) { - + const MASK_TYPE mask1 = getMask(n->key0, noCase); - const MASK_TYPE caseMask = getCaseMask(); - + const MASK_TYPE caseMask = getCaseMask(); + size_t offset = start + n->msk_len - 1; size_t end = len; assert(offset < end); @@ -169,231 +169,231 @@ hwlm_error_t scanSingleMain(const struct noodTable *n, const u8 *buf, if (end - offset < CHUNKSIZE) { rv = scanSingleShort(n, buf, len, noCase, caseMask, mask1, cbi, offset, end); - return rv; - } - + return rv; + } + if (end - offset == CHUNKSIZE) { rv = scanSingleUnaligned(n, buf, len, offset, noCase, caseMask, mask1, cbi, offset, end); - return rv; - } - - uintptr_t data = (uintptr_t)buf; + return rv; + } + + uintptr_t data = (uintptr_t)buf; uintptr_t s2Start = ROUNDUP_N(data + offset, CHUNKSIZE) - data; - uintptr_t last = data + end; - uintptr_t s2End = ROUNDDOWN_N(last, CHUNKSIZE) - data; + uintptr_t last = data + end; + uintptr_t s2End = ROUNDDOWN_N(last, CHUNKSIZE) - data; uintptr_t s3Start = end - CHUNKSIZE; - + if (offset != s2Start) { - // first scan out to the fast scan starting point - DEBUG_PRINTF("stage 1: -> %zu\n", s2Start); + // first scan out to the fast scan starting point + DEBUG_PRINTF("stage 1: -> %zu\n", s2Start); rv = scanSingleUnaligned(n, buf, len, offset, noCase, caseMask, mask1, cbi, offset, s2Start); - RETURN_IF_TERMINATED(rv); - } - - if (likely(s2Start != s2End)) { - // scan as far as we can, bounded by the last point this key can - // possibly match - DEBUG_PRINTF("fast: ~ %zu -> %zu\n", s2Start, s2End); + RETURN_IF_TERMINATED(rv); + } + + if (likely(s2Start != s2End)) { + // scan as far as we can, bounded by the last point this key can + // possibly match + DEBUG_PRINTF("fast: ~ %zu -> %zu\n", s2Start, s2End); rv = scanSingleFast(n, buf, len, noCase, caseMask, mask1, cbi, s2Start, s2End); - RETURN_IF_TERMINATED(rv); - } - - // if we are done bail out + RETURN_IF_TERMINATED(rv); + } + + // if we are done bail out if (s2End == len) { - return HWLM_SUCCESS; - } - + return HWLM_SUCCESS; + } + DEBUG_PRINTF("stage 3: %zu -> %zu\n", s2End, len); rv = scanSingleUnaligned(n, buf, len, s3Start, noCase, caseMask, mask1, cbi, s2End, len); - - return rv; + + return rv; #else // HAVE_AVX512 return scanSingle512(n, buf, len, noCase, caseMask, mask1, cbi, offset, end); #endif -} - -static really_inline +} + +static really_inline hwlm_error_t scanDoubleMain(const struct noodTable *n, const u8 *buf, size_t len, size_t start, bool noCase, - const struct cb_info *cbi) { - // we stop scanning for the key-fragment when the rest of the key can't - // possibly fit in the remaining buffer + const struct cb_info *cbi) { + // we stop scanning for the key-fragment when the rest of the key can't + // possibly fit in the remaining buffer size_t end = len - n->key_offset + 2; - + // the first place the key can match size_t offset = start + n->msk_len - n->key_offset; - const MASK_TYPE caseMask = getCaseMask(); + const MASK_TYPE caseMask = getCaseMask(); const MASK_TYPE mask1 = getMask(n->key0, noCase); const MASK_TYPE mask2 = getMask(n->key1, noCase); - + #if !defined(HAVE_AVX512) hwlm_error_t rv; if (end - offset < CHUNKSIZE) { rv = scanDoubleShort(n, buf, len, noCase, caseMask, mask1, mask2, cbi, offset, end); - return rv; - } + return rv; + } if (end - offset == CHUNKSIZE) { rv = scanDoubleUnaligned(n, buf, len, offset, noCase, caseMask, mask1, mask2, cbi, offset, end); - return rv; - } - - uintptr_t data = (uintptr_t)buf; + return rv; + } + + uintptr_t data = (uintptr_t)buf; uintptr_t s2Start = ROUNDUP_N(data + offset, CHUNKSIZE) - data; - uintptr_t s1End = s2Start + 1; - uintptr_t last = data + end; - uintptr_t s2End = ROUNDDOWN_N(last, CHUNKSIZE) - data; - uintptr_t s3Start = end - CHUNKSIZE; + uintptr_t s1End = s2Start + 1; + uintptr_t last = data + end; + uintptr_t s2End = ROUNDDOWN_N(last, CHUNKSIZE) - data; + uintptr_t s3Start = end - CHUNKSIZE; uintptr_t off = offset; - + if (s2Start != off) { - // first scan out to the fast scan starting point plus one char past to - // catch the key on the overlap + // first scan out to the fast scan starting point plus one char past to + // catch the key on the overlap DEBUG_PRINTF("stage 1: %zu -> %zu\n", off, s2Start); rv = scanDoubleUnaligned(n, buf, len, offset, noCase, caseMask, mask1, mask2, cbi, off, s1End); - RETURN_IF_TERMINATED(rv); - } - off = s1End; - - if (s2Start >= end) { - DEBUG_PRINTF("s2 == mL %zu\n", end); - return HWLM_SUCCESS; - } - - if (likely(s2Start != s2End)) { - // scan as far as we can, bounded by the last point this key can - // possibly match - DEBUG_PRINTF("fast: ~ %zu -> %zu\n", s2Start, s3Start); + RETURN_IF_TERMINATED(rv); + } + off = s1End; + + if (s2Start >= end) { + DEBUG_PRINTF("s2 == mL %zu\n", end); + return HWLM_SUCCESS; + } + + if (likely(s2Start != s2End)) { + // scan as far as we can, bounded by the last point this key can + // possibly match + DEBUG_PRINTF("fast: ~ %zu -> %zu\n", s2Start, s3Start); rv = scanDoubleFast(n, buf, len, noCase, caseMask, mask1, mask2, cbi, s2Start, s2End); - RETURN_IF_TERMINATED(rv); - off = s2End; - } - - // if there isn't enough data left to match the key, bail out - if (s2End == end) { - return HWLM_SUCCESS; - } - - DEBUG_PRINTF("stage 3: %zu -> %zu\n", s3Start, end); + RETURN_IF_TERMINATED(rv); + off = s2End; + } + + // if there isn't enough data left to match the key, bail out + if (s2End == end) { + return HWLM_SUCCESS; + } + + DEBUG_PRINTF("stage 3: %zu -> %zu\n", s3Start, end); rv = scanDoubleUnaligned(n, buf, len, s3Start, noCase, caseMask, mask1, mask2, cbi, off, end); - - return rv; + + return rv; #else // AVX512 return scanDouble512(n, buf, len, noCase, caseMask, mask1, mask2, cbi, offset, end); #endif // AVX512 -} - - -static really_inline +} + + +static really_inline hwlm_error_t scanSingleNoCase(const struct noodTable *n, const u8 *buf, size_t len, size_t start, - const struct cb_info *cbi) { + const struct cb_info *cbi) { return scanSingleMain(n, buf, len, start, 1, cbi); -} - -static really_inline +} + +static really_inline hwlm_error_t scanSingleCase(const struct noodTable *n, const u8 *buf, size_t len, size_t start, - const struct cb_info *cbi) { + const struct cb_info *cbi) { return scanSingleMain(n, buf, len, start, 0, cbi); -} - -// Single-character specialisation, used when keyLen = 1 -static really_inline +} + +// Single-character specialisation, used when keyLen = 1 +static really_inline hwlm_error_t scanSingle(const struct noodTable *n, const u8 *buf, size_t len, size_t start, bool noCase, const struct cb_info *cbi) { if (!ourisalpha(n->key0)) { - noCase = 0; // force noCase off if we don't have an alphabetic char - } - - // kinda ugly, but this forces constant propagation - if (noCase) { + noCase = 0; // force noCase off if we don't have an alphabetic char + } + + // kinda ugly, but this forces constant propagation + if (noCase) { return scanSingleNoCase(n, buf, len, start, cbi); - } else { + } else { return scanSingleCase(n, buf, len, start, cbi); - } -} - - -static really_inline + } +} + + +static really_inline hwlm_error_t scanDoubleNoCase(const struct noodTable *n, const u8 *buf, size_t len, size_t start, - const struct cb_info *cbi) { + const struct cb_info *cbi) { return scanDoubleMain(n, buf, len, start, 1, cbi); -} - -static really_inline +} + +static really_inline hwlm_error_t scanDoubleCase(const struct noodTable *n, const u8 *buf, size_t len, size_t start, - const struct cb_info *cbi) { + const struct cb_info *cbi) { return scanDoubleMain(n, buf, len, start, 0, cbi); -} - - -static really_inline +} + + +static really_inline hwlm_error_t scanDouble(const struct noodTable *n, const u8 *buf, size_t len, size_t start, bool noCase, const struct cb_info *cbi) { - // kinda ugly, but this forces constant propagation - if (noCase) { + // kinda ugly, but this forces constant propagation + if (noCase) { return scanDoubleNoCase(n, buf, len, start, cbi); - } else { + } else { return scanDoubleCase(n, buf, len, start, cbi); - } -} - -// main entry point for the scan code -static really_inline + } +} + +// main entry point for the scan code +static really_inline hwlm_error_t scan(const struct noodTable *n, const u8 *buf, size_t len, size_t start, char single, bool noCase, const struct cb_info *cbi) { if (len - start < n->msk_len) { - // can't find string of length keyLen in a shorter buffer - return HWLM_SUCCESS; - } - + // can't find string of length keyLen in a shorter buffer + return HWLM_SUCCESS; + } + if (single) { return scanSingle(n, buf, len, start, noCase, cbi); - } else { + } else { return scanDouble(n, buf, len, start, noCase, cbi); - } -} - -/** \brief Block-mode scanner. */ -hwlm_error_t noodExec(const struct noodTable *n, const u8 *buf, size_t len, + } +} + +/** \brief Block-mode scanner. */ +hwlm_error_t noodExec(const struct noodTable *n, const u8 *buf, size_t len, size_t start, HWLMCallback cb, struct hs_scratch *scratch) { - assert(n && buf); - + assert(n && buf); + struct cb_info cbi = {cb, n->id, scratch, 0}; DEBUG_PRINTF("nood scan of %zu bytes for %*s @ %p\n", len, n->msk_len, (const char *)&n->cmp, buf); return scan(n, buf, len, start, n->single, n->nocase, &cbi); -} - -/** \brief Streaming-mode scanner. */ -hwlm_error_t noodExecStreaming(const struct noodTable *n, const u8 *hbuf, - size_t hlen, const u8 *buf, size_t len, +} + +/** \brief Streaming-mode scanner. */ +hwlm_error_t noodExecStreaming(const struct noodTable *n, const u8 *hbuf, + size_t hlen, const u8 *buf, size_t len, HWLMCallback cb, struct hs_scratch *scratch) { - assert(n); - + assert(n); + if (len + hlen < n->msk_len) { DEBUG_PRINTF("not enough bytes for a match\n"); return HWLM_SUCCESS; } - + struct cb_info cbi = {cb, n->id, scratch, 0}; DEBUG_PRINTF("nood scan of %zu bytes (%zu hlen) for %*s @ %p\n", len, hlen, n->msk_len, (const char *)&n->cmp, buf); @@ -404,14 +404,14 @@ hwlm_error_t noodExecStreaming(const struct noodTable *n, const u8 *hbuf, * buffer plus what we've been given to scan. Since this is relatively * short, just check against msk+cmp per byte offset for matches. */ - assert(hbuf); + assert(hbuf); u8 ALIGN_DIRECTIVE temp_buf[HWLM_LITERAL_MAX_LEN * 2]; memset(temp_buf, 0, sizeof(temp_buf)); - + assert(n->msk_len); size_t tl1 = MIN((size_t)n->msk_len - 1, hlen); size_t tl2 = MIN((size_t)n->msk_len - 1, len); - + assert(tl1 + tl2 <= sizeof(temp_buf)); assert(tl1 + tl2 >= n->msk_len); assert(tl1 <= sizeof(u64a)); @@ -432,11 +432,11 @@ hwlm_error_t noodExecStreaming(const struct noodTable *n, const u8 *hbuf, return HWLM_TERMINATED; } } - } - } - - assert(buf); - - cbi.offsetAdj = 0; + } + } + + assert(buf); + + cbi.offsetAdj = 0; return scan(n, buf, len, 0, n->single, n->nocase, &cbi); -} +} diff --git a/contrib/libs/hyperscan/src/hwlm/noodle_engine.h b/contrib/libs/hyperscan/src/hwlm/noodle_engine.h index f910e28d69..64422c41f0 100644 --- a/contrib/libs/hyperscan/src/hwlm/noodle_engine.h +++ b/contrib/libs/hyperscan/src/hwlm/noodle_engine.h @@ -1,60 +1,60 @@ -/* +/* * 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: - * - * * 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 Noodle literal matcher: runtime API. - */ - -#ifndef NOODLE_ENGINE_H -#define NOODLE_ENGINE_H - -#include "hwlm.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct noodTable; + * + * 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 Noodle literal matcher: runtime API. + */ + +#ifndef NOODLE_ENGINE_H +#define NOODLE_ENGINE_H + +#include "hwlm.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct noodTable; struct hs_scratch; - -/** \brief Block-mode scanner. */ -hwlm_error_t noodExec(const struct noodTable *n, const u8 *buf, size_t len, + +/** \brief Block-mode scanner. */ +hwlm_error_t noodExec(const struct noodTable *n, const u8 *buf, size_t len, size_t start, HWLMCallback cb, struct hs_scratch *scratch); - -/** \brief Streaming-mode scanner. */ -hwlm_error_t noodExecStreaming(const struct noodTable *n, const u8 *hbuf, - size_t hlen, const u8 *buf, size_t len, + +/** \brief Streaming-mode scanner. */ +hwlm_error_t noodExecStreaming(const struct noodTable *n, const u8 *hbuf, + size_t hlen, const u8 *buf, size_t len, HWLMCallback cb, struct hs_scratch *scratch); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif diff --git a/contrib/libs/hyperscan/src/hwlm/noodle_engine_avx2.c b/contrib/libs/hyperscan/src/hwlm/noodle_engine_avx2.c index 2cb1f88149..5edc646af1 100644 --- a/contrib/libs/hyperscan/src/hwlm/noodle_engine_avx2.c +++ b/contrib/libs/hyperscan/src/hwlm/noodle_engine_avx2.c @@ -1,233 +1,233 @@ -/* +/* * 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: - * - * * 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. - */ - -/* noodle scan parts for AVX */ - -static really_inline m256 getMask(u8 c, bool noCase) { - u8 k = caseClear8(c, noCase); - return set32x8(k); -} - -static really_inline m256 getCaseMask(void) { - return set32x8(0xdf); -} - -static really_inline + * + * 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. + */ + +/* noodle scan parts for AVX */ + +static really_inline m256 getMask(u8 c, bool noCase) { + u8 k = caseClear8(c, noCase); + return set32x8(k); +} + +static really_inline m256 getCaseMask(void) { + return set32x8(0xdf); +} + +static really_inline hwlm_error_t scanSingleUnaligned(const struct noodTable *n, const u8 *buf, size_t len, size_t offset, bool noCase, m256 caseMask, m256 mask1, const struct cb_info *cbi, size_t start, size_t end) { - const u8 *d = buf + offset; - DEBUG_PRINTF("start %zu end %zu offset %zu\n", start, end, offset); - const size_t l = end - start; - - m256 v = loadu256(d); - - if (noCase) { - v = and256(v, caseMask); - } - - u32 z = movemask256(eq256(mask1, v)); - - u32 buf_off = start - offset; - u32 mask = (u32)((u64a)(1ULL << l) - 1) << buf_off; - DEBUG_PRINTF("mask 0x%08x z 0x%08x\n", mask, z); - - z &= mask; - - SINGLE_ZSCAN(); - - return HWLM_SUCCESS; -} - -static really_inline + const u8 *d = buf + offset; + DEBUG_PRINTF("start %zu end %zu offset %zu\n", start, end, offset); + const size_t l = end - start; + + m256 v = loadu256(d); + + if (noCase) { + v = and256(v, caseMask); + } + + u32 z = movemask256(eq256(mask1, v)); + + u32 buf_off = start - offset; + u32 mask = (u32)((u64a)(1ULL << l) - 1) << buf_off; + DEBUG_PRINTF("mask 0x%08x z 0x%08x\n", mask, z); + + z &= mask; + + SINGLE_ZSCAN(); + + return HWLM_SUCCESS; +} + +static really_inline hwlm_error_t scanDoubleUnaligned(const struct noodTable *n, const u8 *buf, size_t len, size_t offset, bool noCase, m256 caseMask, m256 mask1, m256 mask2, const struct cb_info *cbi, size_t start, size_t end) { - const u8 *d = buf + offset; - DEBUG_PRINTF("start %zu end %zu offset %zu\n", start, end, offset); - size_t l = end - start; - - m256 v = loadu256(d); - - if (noCase) { - v = and256(v, caseMask); - } - - u32 z0 = movemask256(eq256(mask1, v)); - u32 z1 = movemask256(eq256(mask2, v)); - u32 z = (z0 << 1) & z1; - - // mask out where we can't match - u32 buf_off = start - offset; - u32 mask = (u32)((u64a)(1ULL << l) - 1) << buf_off; - DEBUG_PRINTF("mask 0x%08x z 0x%08x\n", mask, z); - z &= mask; - - DOUBLE_ZSCAN(); - - return HWLM_SUCCESS; -} - -// The short scan routine. It is used both to scan data up to an -// alignment boundary if needed and to finish off data that the aligned scan -// function can't handle (due to small/unaligned chunk at end) -static really_inline + const u8 *d = buf + offset; + DEBUG_PRINTF("start %zu end %zu offset %zu\n", start, end, offset); + size_t l = end - start; + + m256 v = loadu256(d); + + if (noCase) { + v = and256(v, caseMask); + } + + u32 z0 = movemask256(eq256(mask1, v)); + u32 z1 = movemask256(eq256(mask2, v)); + u32 z = (z0 << 1) & z1; + + // mask out where we can't match + u32 buf_off = start - offset; + u32 mask = (u32)((u64a)(1ULL << l) - 1) << buf_off; + DEBUG_PRINTF("mask 0x%08x z 0x%08x\n", mask, z); + z &= mask; + + DOUBLE_ZSCAN(); + + return HWLM_SUCCESS; +} + +// The short scan routine. It is used both to scan data up to an +// alignment boundary if needed and to finish off data that the aligned scan +// function can't handle (due to small/unaligned chunk at end) +static really_inline hwlm_error_t scanSingleShort(const struct noodTable *n, const u8 *buf, size_t len, bool noCase, m256 caseMask, m256 mask1, - const struct cb_info *cbi, size_t start, - size_t end) { - const u8 *d = buf + start; - size_t l = end - start; - DEBUG_PRINTF("l %zu\n", l); - assert(l <= 32); - if (!l) { - return HWLM_SUCCESS; - } - - m256 v; - - if (l < 4) { - u8 *vp = (u8*)&v; - switch (l) { + const struct cb_info *cbi, size_t start, + size_t end) { + const u8 *d = buf + start; + size_t l = end - start; + DEBUG_PRINTF("l %zu\n", l); + assert(l <= 32); + if (!l) { + return HWLM_SUCCESS; + } + + m256 v; + + if (l < 4) { + u8 *vp = (u8*)&v; + switch (l) { case 3: vp[2] = d[2]; // fallthrough case 2: vp[1] = d[1]; // fallthrough case 1: vp[0] = d[0]; // fallthrough - } - } else { - v = masked_move256_len(d, l); - } - - if (noCase) { - v = and256(v, caseMask); - } - - // mask out where we can't match - u32 mask = (0xFFFFFFFF >> (32 - l)); - - u32 z = mask & movemask256(eq256(mask1, v)); - - SINGLE_ZSCAN(); - - return HWLM_SUCCESS; -} - -static really_inline + } + } else { + v = masked_move256_len(d, l); + } + + if (noCase) { + v = and256(v, caseMask); + } + + // mask out where we can't match + u32 mask = (0xFFFFFFFF >> (32 - l)); + + u32 z = mask & movemask256(eq256(mask1, v)); + + SINGLE_ZSCAN(); + + return HWLM_SUCCESS; +} + +static really_inline hwlm_error_t scanDoubleShort(const struct noodTable *n, const u8 *buf, size_t len, bool noCase, m256 caseMask, m256 mask1, m256 mask2, const struct cb_info *cbi, size_t start, size_t end) { - const u8 *d = buf + start; - size_t l = end - start; - if (!l) { - return HWLM_SUCCESS; - } - assert(l <= 32); - m256 v; - - DEBUG_PRINTF("d %zu\n", d - buf); - if (l < 4) { - u8 *vp = (u8*)&v; - switch (l) { + const u8 *d = buf + start; + size_t l = end - start; + if (!l) { + return HWLM_SUCCESS; + } + assert(l <= 32); + m256 v; + + DEBUG_PRINTF("d %zu\n", d - buf); + if (l < 4) { + u8 *vp = (u8*)&v; + switch (l) { case 3: vp[2] = d[2]; // fallthrough case 2: vp[1] = d[1]; // fallthrough case 1: vp[0] = d[0]; // fallthrough - } - } else { - v = masked_move256_len(d, l); - } - if (noCase) { - v = and256(v, caseMask); - } - - u32 z0 = movemask256(eq256(mask1, v)); - u32 z1 = movemask256(eq256(mask2, v)); - u32 z = (z0 << 1) & z1; - - // mask out where we can't match - u32 mask = (0xFFFFFFFF >> (32 - l)); - z &= mask; - - DOUBLE_ZSCAN(); - - return HWLM_SUCCESS; -} - -static really_inline + } + } else { + v = masked_move256_len(d, l); + } + if (noCase) { + v = and256(v, caseMask); + } + + u32 z0 = movemask256(eq256(mask1, v)); + u32 z1 = movemask256(eq256(mask2, v)); + u32 z = (z0 << 1) & z1; + + // mask out where we can't match + u32 mask = (0xFFFFFFFF >> (32 - l)); + z &= mask; + + DOUBLE_ZSCAN(); + + return HWLM_SUCCESS; +} + +static really_inline hwlm_error_t scanSingleFast(const struct noodTable *n, const u8 *buf, size_t len, bool noCase, m256 caseMask, m256 mask1, - const struct cb_info *cbi, size_t start, - size_t end) { - const u8 *d = buf + start, *e = buf + end; - assert(d < e); - - for (; d < e; d += 32) { - m256 v = noCase ? and256(load256(d), caseMask) : load256(d); - - u32 z = movemask256(eq256(mask1, v)); - - // On large packet buffers, this prefetch appears to get us about 2%. - __builtin_prefetch(d + 128); - - SINGLE_ZSCAN(); - } - return HWLM_SUCCESS; -} - -static really_inline + const struct cb_info *cbi, size_t start, + size_t end) { + const u8 *d = buf + start, *e = buf + end; + assert(d < e); + + for (; d < e; d += 32) { + m256 v = noCase ? and256(load256(d), caseMask) : load256(d); + + u32 z = movemask256(eq256(mask1, v)); + + // On large packet buffers, this prefetch appears to get us about 2%. + __builtin_prefetch(d + 128); + + SINGLE_ZSCAN(); + } + return HWLM_SUCCESS; +} + +static really_inline hwlm_error_t scanDoubleFast(const struct noodTable *n, const u8 *buf, size_t len, bool noCase, m256 caseMask, m256 mask1, m256 mask2, const struct cb_info *cbi, size_t start, - size_t end) { - const u8 *d = buf + start, *e = buf + end; - DEBUG_PRINTF("start %zu end %zu \n", start, end); - assert(d < e); + size_t end) { + const u8 *d = buf + start, *e = buf + end; + DEBUG_PRINTF("start %zu end %zu \n", start, end); + assert(d < e); u32 lastz0 = 0; - - for (; d < e; d += 32) { - m256 v = noCase ? and256(load256(d), caseMask) : load256(d); - - // we have to pull the masks out of the AVX registers because we can't - // byte shift between the lanes - u32 z0 = movemask256(eq256(mask1, v)); - u32 z1 = movemask256(eq256(mask2, v)); - u32 z = (lastz0 | (z0 << 1)) & z1; + + for (; d < e; d += 32) { + m256 v = noCase ? and256(load256(d), caseMask) : load256(d); + + // we have to pull the masks out of the AVX registers because we can't + // byte shift between the lanes + u32 z0 = movemask256(eq256(mask1, v)); + u32 z1 = movemask256(eq256(mask2, v)); + u32 z = (lastz0 | (z0 << 1)) & z1; lastz0 = z0 >> 31; - - // On large packet buffers, this prefetch appears to get us about 2%. - __builtin_prefetch(d + 128); - - DOUBLE_ZSCAN(); - - } - return HWLM_SUCCESS; -} - + + // On large packet buffers, this prefetch appears to get us about 2%. + __builtin_prefetch(d + 128); + + DOUBLE_ZSCAN(); + + } + return HWLM_SUCCESS; +} + diff --git a/contrib/libs/hyperscan/src/hwlm/noodle_engine_sse.c b/contrib/libs/hyperscan/src/hwlm/noodle_engine_sse.c index 5bdc7389a5..7cd53d7ced 100644 --- a/contrib/libs/hyperscan/src/hwlm/noodle_engine_sse.c +++ b/contrib/libs/hyperscan/src/hwlm/noodle_engine_sse.c @@ -1,203 +1,203 @@ -/* +/* * 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: - * - * * 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. - */ - -/* noodle scan parts for SSE */ - -static really_inline m128 getMask(u8 c, bool noCase) { - u8 k = caseClear8(c, noCase); - return set16x8(k); -} - -static really_inline m128 getCaseMask(void) { - return set16x8(0xdf); -} - -static really_inline + * + * 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. + */ + +/* noodle scan parts for SSE */ + +static really_inline m128 getMask(u8 c, bool noCase) { + u8 k = caseClear8(c, noCase); + return set16x8(k); +} + +static really_inline m128 getCaseMask(void) { + return set16x8(0xdf); +} + +static really_inline hwlm_error_t scanSingleShort(const struct noodTable *n, const u8 *buf, size_t len, bool noCase, m128 caseMask, m128 mask1, - const struct cb_info *cbi, size_t start, - size_t end) { - const u8 *d = buf + start; - size_t l = end - start; - DEBUG_PRINTF("l %zu\n", l); - assert(l <= 16); - if (!l) { - return HWLM_SUCCESS; - } - m128 v = zeroes128(); - // we don't have a clever way of doing this move yet - memcpy(&v, d, l); - if (noCase) { - v = and128(v, caseMask); - } - - // mask out where we can't match - u32 mask = (0xFFFF >> (16 - l)); - - u32 z = mask & movemask128(eq128(mask1, v)); - - SINGLE_ZSCAN(); - - return HWLM_SUCCESS; -} - -static really_inline + const struct cb_info *cbi, size_t start, + size_t end) { + const u8 *d = buf + start; + size_t l = end - start; + DEBUG_PRINTF("l %zu\n", l); + assert(l <= 16); + if (!l) { + return HWLM_SUCCESS; + } + m128 v = zeroes128(); + // we don't have a clever way of doing this move yet + memcpy(&v, d, l); + if (noCase) { + v = and128(v, caseMask); + } + + // mask out where we can't match + u32 mask = (0xFFFF >> (16 - l)); + + u32 z = mask & movemask128(eq128(mask1, v)); + + SINGLE_ZSCAN(); + + return HWLM_SUCCESS; +} + +static really_inline hwlm_error_t scanSingleUnaligned(const struct noodTable *n, const u8 *buf, size_t len, size_t offset, bool noCase, m128 caseMask, m128 mask1, const struct cb_info *cbi, size_t start, size_t end) { - const u8 *d = buf + offset; - DEBUG_PRINTF("start %zu end %zu offset %zu\n", start, end, offset); - const size_t l = end - start; - - m128 v = loadu128(d); - - if (noCase) { - v = and128(v, caseMask); - } - - u32 buf_off = start - offset; - u32 mask = ((1 << l) - 1) << buf_off; - - u32 z = mask & movemask128(eq128(mask1, v)); - - DEBUG_PRINTF("mask 0x%08x z 0x%08x\n", mask, z); - - z &= mask; - - SINGLE_ZSCAN(); - - return HWLM_SUCCESS; -} - -static really_inline + const u8 *d = buf + offset; + DEBUG_PRINTF("start %zu end %zu offset %zu\n", start, end, offset); + const size_t l = end - start; + + m128 v = loadu128(d); + + if (noCase) { + v = and128(v, caseMask); + } + + u32 buf_off = start - offset; + u32 mask = ((1 << l) - 1) << buf_off; + + u32 z = mask & movemask128(eq128(mask1, v)); + + DEBUG_PRINTF("mask 0x%08x z 0x%08x\n", mask, z); + + z &= mask; + + SINGLE_ZSCAN(); + + return HWLM_SUCCESS; +} + +static really_inline hwlm_error_t scanDoubleShort(const struct noodTable *n, const u8 *buf, size_t len, bool noCase, m128 caseMask, m128 mask1, m128 mask2, const struct cb_info *cbi, size_t start, size_t end) { - const u8 *d = buf + start; - size_t l = end - start; - if (!l) { - return HWLM_SUCCESS; - } - assert(l <= 32); - - DEBUG_PRINTF("d %zu\n", d - buf); - m128 v = zeroes128(); - memcpy(&v, d, l); - if (noCase) { - v = and128(v, caseMask); - } - + const u8 *d = buf + start; + size_t l = end - start; + if (!l) { + return HWLM_SUCCESS; + } + assert(l <= 32); + + DEBUG_PRINTF("d %zu\n", d - buf); + m128 v = zeroes128(); + memcpy(&v, d, l); + if (noCase) { + v = and128(v, caseMask); + } + u32 z = movemask128(and128(lshiftbyte_m128(eq128(mask1, v), 1), eq128(mask2, v))); - - // mask out where we can't match - u32 mask = (0xFFFF >> (16 - l)); - z &= mask; - - DOUBLE_ZSCAN(); - - return HWLM_SUCCESS; -} - -static really_inline + + // mask out where we can't match + u32 mask = (0xFFFF >> (16 - l)); + z &= mask; + + DOUBLE_ZSCAN(); + + return HWLM_SUCCESS; +} + +static really_inline hwlm_error_t scanDoubleUnaligned(const struct noodTable *n, const u8 *buf, size_t len, size_t offset, bool noCase, m128 caseMask, m128 mask1, m128 mask2, const struct cb_info *cbi, size_t start, size_t end) { - const u8 *d = buf + offset; - DEBUG_PRINTF("start %zu end %zu offset %zu\n", start, end, offset); - size_t l = end - start; - - m128 v = loadu128(d); - - if (noCase) { - v = and128(v, caseMask); - } - + const u8 *d = buf + offset; + DEBUG_PRINTF("start %zu end %zu offset %zu\n", start, end, offset); + size_t l = end - start; + + m128 v = loadu128(d); + + if (noCase) { + v = and128(v, caseMask); + } + u32 z = movemask128(and128(lshiftbyte_m128(eq128(mask1, v), 1), eq128(mask2, v))); - - // mask out where we can't match - u32 buf_off = start - offset; - u32 mask = ((1 << l) - 1) << buf_off; - DEBUG_PRINTF("mask 0x%08x z 0x%08x\n", mask, z); - z &= mask; - - DOUBLE_ZSCAN(); - - return HWLM_SUCCESS; -} - -static really_inline + + // mask out where we can't match + u32 buf_off = start - offset; + u32 mask = ((1 << l) - 1) << buf_off; + DEBUG_PRINTF("mask 0x%08x z 0x%08x\n", mask, z); + z &= mask; + + DOUBLE_ZSCAN(); + + return HWLM_SUCCESS; +} + +static really_inline hwlm_error_t scanSingleFast(const struct noodTable *n, const u8 *buf, size_t len, bool noCase, m128 caseMask, m128 mask1, - const struct cb_info *cbi, size_t start, - size_t end) { - const u8 *d = buf + start, *e = buf + end; - assert(d < e); - - for (; d < e; d += 16) { - m128 v = noCase ? and128(load128(d), caseMask) : load128(d); - - u32 z = movemask128(eq128(mask1, v)); - - // On large packet buffers, this prefetch appears to get us about 2%. - __builtin_prefetch(d + 128); - - SINGLE_ZSCAN(); - } - return HWLM_SUCCESS; -} - -static really_inline + const struct cb_info *cbi, size_t start, + size_t end) { + const u8 *d = buf + start, *e = buf + end; + assert(d < e); + + for (; d < e; d += 16) { + m128 v = noCase ? and128(load128(d), caseMask) : load128(d); + + u32 z = movemask128(eq128(mask1, v)); + + // On large packet buffers, this prefetch appears to get us about 2%. + __builtin_prefetch(d + 128); + + SINGLE_ZSCAN(); + } + return HWLM_SUCCESS; +} + +static really_inline hwlm_error_t scanDoubleFast(const struct noodTable *n, const u8 *buf, size_t len, bool noCase, m128 caseMask, m128 mask1, m128 mask2, const struct cb_info *cbi, size_t start, - size_t end) { - const u8 *d = buf + start, *e = buf + end; - assert(d < e); - m128 lastz1 = zeroes128(); - - for (; d < e; d += 16) { - m128 v = noCase ? and128(load128(d), caseMask) : load128(d); - m128 z1 = eq128(mask1, v); - m128 z2 = eq128(mask2, v); + size_t end) { + const u8 *d = buf + start, *e = buf + end; + assert(d < e); + m128 lastz1 = zeroes128(); + + for (; d < e; d += 16) { + m128 v = noCase ? and128(load128(d), caseMask) : load128(d); + m128 z1 = eq128(mask1, v); + m128 z2 = eq128(mask2, v); u32 z = movemask128(and128(palignr(z1, lastz1, 15), z2)); lastz1 = z1; - - // On large packet buffers, this prefetch appears to get us about 2%. - __builtin_prefetch(d + 128); - DEBUG_PRINTF("z 0x%08x\n", z); - DOUBLE_ZSCAN(); - } - return HWLM_SUCCESS; -} + + // On large packet buffers, this prefetch appears to get us about 2%. + __builtin_prefetch(d + 128); + DEBUG_PRINTF("z 0x%08x\n", z); + DOUBLE_ZSCAN(); + } + return HWLM_SUCCESS; +} diff --git a/contrib/libs/hyperscan/src/hwlm/noodle_internal.h b/contrib/libs/hyperscan/src/hwlm/noodle_internal.h index 2c578c28f3..8f76f177e1 100644 --- a/contrib/libs/hyperscan/src/hwlm/noodle_internal.h +++ b/contrib/libs/hyperscan/src/hwlm/noodle_internal.h @@ -1,42 +1,42 @@ -/* +/* * 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: - * - * * 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 Data structures for Noodle literal matcher engine. - */ - + * + * 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 Data structures for Noodle literal matcher engine. + */ + #ifndef NOODLE_INTERNAL_H #define NOODLE_INTERNAL_H - -#include "ue2common.h" - -struct noodTable { - u32 id; + +#include "ue2common.h" + +struct noodTable { + u32 id; u64a msk; u64a cmp; u8 msk_len; @@ -45,7 +45,7 @@ struct noodTable { u8 single; u8 key0; u8 key1; -}; - +}; + #endif /* NOODLE_INTERNAL_H */ - + |