mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-29 19:24:25 +03:00
rose/hwlm: limit literals to eight bytes
Rework HWLM to work over literals of eight bytes ("medium length"), doing confirm in the Rose interpreter.
This commit is contained in:
committed by
Matthew Barr
parent
5c9c540424
commit
07a6b6510c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016, Intel Corporation
|
||||
* Copyright (c) 2015-2017, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "hwlm.h"
|
||||
#include "hwlm_build.h"
|
||||
#include "hwlm_internal.h"
|
||||
#include "hwlm_literal.h"
|
||||
#include "noodle_engine.h"
|
||||
#include "noodle_build.h"
|
||||
#include "scratch.h"
|
||||
@@ -512,7 +513,6 @@ bool everyoneHasGroups(const vector<hwlmLiteral> &lits) {
|
||||
|
||||
static
|
||||
bool isNoodleable(const vector<hwlmLiteral> &lits,
|
||||
const hwlmStreamingControl *stream_control,
|
||||
const CompileContext &cc) {
|
||||
if (!cc.grey.allowNoodle) {
|
||||
return false;
|
||||
@@ -523,19 +523,6 @@ bool isNoodleable(const vector<hwlmLiteral> &lits,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (stream_control) { // nullptr if in block mode
|
||||
if (lits.front().s.length() > stream_control->history_max + 1) {
|
||||
DEBUG_PRINTF("length of %zu too long for history max %zu\n",
|
||||
lits.front().s.length(),
|
||||
stream_control->history_max);
|
||||
return false;
|
||||
}
|
||||
if (2 * lits.front().s.length() - 2 > FDR_TEMP_BUF_SIZE) {
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!lits.front().msk.empty()) {
|
||||
DEBUG_PRINTF("noodle can't handle supplementary masks\n");
|
||||
return false;
|
||||
@@ -545,22 +532,11 @@ bool isNoodleable(const vector<hwlmLiteral> &lits,
|
||||
}
|
||||
|
||||
aligned_unique_ptr<HWLM> hwlmBuild(const vector<hwlmLiteral> &lits,
|
||||
hwlmStreamingControl *stream_control,
|
||||
bool make_small, const CompileContext &cc,
|
||||
hwlm_group_t expected_groups) {
|
||||
assert(!lits.empty());
|
||||
dumpLits(lits);
|
||||
|
||||
if (stream_control) {
|
||||
assert(stream_control->history_min <= stream_control->history_max);
|
||||
|
||||
// We should not have been passed any literals that are too long to
|
||||
// match with a maximally-sized history buffer.
|
||||
assert(all_of(begin(lits), end(lits), [&](const hwlmLiteral &lit) {
|
||||
return lit.s.length() <= stream_control->history_max + 1;
|
||||
}));
|
||||
}
|
||||
|
||||
// Check that we haven't exceeded the maximum number of literals.
|
||||
if (lits.size() > cc.grey.limitLiteralCount) {
|
||||
throw ResourceLimitError();
|
||||
@@ -595,7 +571,7 @@ aligned_unique_ptr<HWLM> hwlmBuild(const vector<hwlmLiteral> &lits,
|
||||
|
||||
assert(everyoneHasGroups(lits));
|
||||
|
||||
if (isNoodleable(lits, stream_control, cc)) {
|
||||
if (isNoodleable(lits, cc)) {
|
||||
DEBUG_PRINTF("build noodle table\n");
|
||||
engType = HWLM_ENGINE_NOOD;
|
||||
const hwlmLiteral &lit = lits.front();
|
||||
@@ -603,19 +579,11 @@ aligned_unique_ptr<HWLM> hwlmBuild(const vector<hwlmLiteral> &lits,
|
||||
if (noodle) {
|
||||
engSize = noodSize(noodle.get());
|
||||
}
|
||||
if (stream_control) {
|
||||
// For now, a single literal still goes to noodle and asks
|
||||
// for a great big history
|
||||
stream_control->literal_history_required = lit.s.length() - 1;
|
||||
assert(stream_control->literal_history_required
|
||||
<= stream_control->history_max);
|
||||
}
|
||||
eng = move(noodle);
|
||||
} else {
|
||||
DEBUG_PRINTF("building a new deal\n");
|
||||
engType = HWLM_ENGINE_FDR;
|
||||
auto fdr = fdrBuildTable(lits, make_small, cc.target_info, cc.grey,
|
||||
stream_control);
|
||||
auto fdr = fdrBuildTable(lits, make_small, cc.target_info, cc.grey);
|
||||
if (fdr) {
|
||||
engSize = fdrSize(fdr.get());
|
||||
}
|
||||
@@ -640,14 +608,6 @@ aligned_unique_ptr<HWLM> hwlmBuild(const vector<hwlmLiteral> &lits,
|
||||
buildForwardAccel(h.get(), lits, expected_groups);
|
||||
}
|
||||
|
||||
if (stream_control) {
|
||||
DEBUG_PRINTF("requires %zu (of max %zu) bytes of history\n",
|
||||
stream_control->literal_history_required,
|
||||
stream_control->history_max);
|
||||
assert(stream_control->literal_history_required
|
||||
<= stream_control->history_max);
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016, Intel Corporation
|
||||
* Copyright (c) 2015-2017, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -34,7 +34,6 @@
|
||||
#define HWLM_BUILD_H
|
||||
|
||||
#include "hwlm.h"
|
||||
#include "hwlm_literal.h"
|
||||
#include "ue2common.h"
|
||||
#include "util/alloc.h"
|
||||
|
||||
@@ -47,30 +46,12 @@ namespace ue2 {
|
||||
|
||||
struct CompileContext;
|
||||
struct Grey;
|
||||
struct target_t;
|
||||
|
||||
/** \brief Structure gathering together the input/output parameters related to
|
||||
* streaming mode operation. */
|
||||
struct hwlmStreamingControl {
|
||||
/** \brief IN parameter: Upper limit on the amount of history that can be
|
||||
* requested. */
|
||||
size_t history_max;
|
||||
|
||||
/** \brief IN parameter: History already known to be used before literal
|
||||
* analysis. */
|
||||
size_t history_min;
|
||||
|
||||
/** \brief OUT parameter: History required by the literal matcher to
|
||||
* correctly match all literals. */
|
||||
size_t literal_history_required;
|
||||
};
|
||||
struct hwlmLiteral;
|
||||
|
||||
/** \brief Build an \ref HWLM literal matcher runtime structure for a group of
|
||||
* literals.
|
||||
*
|
||||
* \param lits The group of literals.
|
||||
* \param stream_control Streaming control parameters. If the matcher will
|
||||
* operate in non-streaming (block) mode, this pointer should be NULL.
|
||||
* \param make_small Optimise matcher for small size.
|
||||
* \param cc Compile context.
|
||||
* \param expected_groups FIXME: document me!
|
||||
@@ -80,8 +61,7 @@ struct hwlmStreamingControl {
|
||||
* thrown.
|
||||
*/
|
||||
aligned_unique_ptr<HWLM>
|
||||
hwlmBuild(const std::vector<hwlmLiteral> &lits,
|
||||
hwlmStreamingControl *stream_control, bool make_small,
|
||||
hwlmBuild(const std::vector<hwlmLiteral> &lits, bool make_small,
|
||||
const CompileContext &cc,
|
||||
hwlm_group_t expected_groups = HWLM_ALL_GROUPS);
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016, Intel Corporation
|
||||
* Copyright (c) 2015-2017, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -42,7 +42,7 @@
|
||||
namespace ue2 {
|
||||
|
||||
/** \brief Max length of the literal passed to HWLM. */
|
||||
#define HWLM_LITERAL_MAX_LEN 255
|
||||
#define HWLM_LITERAL_MAX_LEN 8
|
||||
|
||||
/** \brief Max length of the hwlmLiteral::msk and hwlmLiteral::cmp vectors. */
|
||||
#define HWLM_MASKLEN 8
|
||||
|
Reference in New Issue
Block a user