mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
rose: remove CHECK_LIT_MASK instruction
This commit is contained in:
parent
4ce306864e
commit
c8868fb9c7
@ -71,73 +71,6 @@ hwlmcb_rv_t roseRunProgram(const struct RoseEngine *t,
|
|||||||
|
|
||||||
/* Inline implementation follows. */
|
/* Inline implementation follows. */
|
||||||
|
|
||||||
static rose_inline
|
|
||||||
int roseCheckBenefits(const struct core_info *ci, u64a end, u32 mask_rewind,
|
|
||||||
const u8 *and_mask, const u8 *exp_mask) {
|
|
||||||
const u8 *data;
|
|
||||||
|
|
||||||
// If the check works over part of the history and part of the buffer, we
|
|
||||||
// create a temporary copy of the data in here so it's contiguous.
|
|
||||||
u8 temp[MAX_MASK2_WIDTH];
|
|
||||||
|
|
||||||
s64a buffer_offset = (s64a)end - ci->buf_offset;
|
|
||||||
DEBUG_PRINTF("rel offset %lld\n", buffer_offset);
|
|
||||||
if (buffer_offset >= mask_rewind) {
|
|
||||||
data = ci->buf + buffer_offset - mask_rewind;
|
|
||||||
DEBUG_PRINTF("all in one case data=%p buf=%p rewind=%u\n", data,
|
|
||||||
ci->buf, mask_rewind);
|
|
||||||
} else if (buffer_offset <= 0) {
|
|
||||||
data = ci->hbuf + ci->hlen + buffer_offset - mask_rewind;
|
|
||||||
DEBUG_PRINTF("all in one case data=%p buf=%p rewind=%u\n", data,
|
|
||||||
ci->buf, mask_rewind);
|
|
||||||
} else {
|
|
||||||
u32 shortfall = mask_rewind - buffer_offset;
|
|
||||||
DEBUG_PRINTF("shortfall of %u, rewind %u hlen %zu\n", shortfall,
|
|
||||||
mask_rewind, ci->hlen);
|
|
||||||
data = temp;
|
|
||||||
memcpy(temp, ci->hbuf + ci->hlen - shortfall, shortfall);
|
|
||||||
memcpy(temp + shortfall, ci->buf, mask_rewind - shortfall);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
DEBUG_PRINTF("DATA: ");
|
|
||||||
for (u32 i = 0; i < mask_rewind; i++) {
|
|
||||||
printf("%c", ourisprint(data[i]) ? data[i] : '?');
|
|
||||||
}
|
|
||||||
printf(" (len=%u)\n", mask_rewind);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
u32 len = mask_rewind;
|
|
||||||
while (len >= sizeof(u64a)) {
|
|
||||||
u64a a = unaligned_load_u64a(data);
|
|
||||||
a &= *(const u64a *)and_mask;
|
|
||||||
if (a != *(const u64a *)exp_mask) {
|
|
||||||
DEBUG_PRINTF("argh %016llx %016llx\n", a, *(const u64a *)exp_mask);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
data += sizeof(u64a);
|
|
||||||
and_mask += sizeof(u64a);
|
|
||||||
exp_mask += sizeof(u64a);
|
|
||||||
len -= sizeof(u64a);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (len) {
|
|
||||||
u8 a = *data;
|
|
||||||
a &= *and_mask;
|
|
||||||
if (a != *exp_mask) {
|
|
||||||
DEBUG_PRINTF("argh d%02hhx =%02hhx am%02hhx em%02hhx\n", a,
|
|
||||||
*data, *and_mask, *exp_mask);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
data++;
|
|
||||||
and_mask++;
|
|
||||||
exp_mask++;
|
|
||||||
len--;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static rose_inline
|
static rose_inline
|
||||||
void rosePushDelayedMatch(const struct RoseEngine *t,
|
void rosePushDelayedMatch(const struct RoseEngine *t,
|
||||||
struct hs_scratch *scratch, u32 delay,
|
struct hs_scratch *scratch, u32 delay,
|
||||||
@ -1157,7 +1090,7 @@ void updateSeqPoint(struct RoseContext *tctxt, u64a offset,
|
|||||||
static rose_inline
|
static rose_inline
|
||||||
hwlmcb_rv_t roseRunProgram_i(const struct RoseEngine *t,
|
hwlmcb_rv_t roseRunProgram_i(const struct RoseEngine *t,
|
||||||
struct hs_scratch *scratch, u32 programOffset,
|
struct hs_scratch *scratch, u32 programOffset,
|
||||||
u64a som, u64a end, size_t match_len,
|
u64a som, u64a end, UNUSED size_t match_len,
|
||||||
u8 prog_flags) {
|
u8 prog_flags) {
|
||||||
DEBUG_PRINTF("program=%u, offsets [%llu,%llu], flags=%u\n", programOffset,
|
DEBUG_PRINTF("program=%u, offsets [%llu,%llu], flags=%u\n", programOffset,
|
||||||
som, end, prog_flags);
|
som, end, prog_flags);
|
||||||
@ -1205,17 +1138,6 @@ hwlmcb_rv_t roseRunProgram_i(const struct RoseEngine *t,
|
|||||||
}
|
}
|
||||||
PROGRAM_NEXT_INSTRUCTION
|
PROGRAM_NEXT_INSTRUCTION
|
||||||
|
|
||||||
PROGRAM_CASE(CHECK_LIT_MASK) {
|
|
||||||
assert(match_len);
|
|
||||||
struct core_info *ci = &scratch->core_info;
|
|
||||||
if (!roseCheckBenefits(ci, end, match_len, ri->and_mask.a8,
|
|
||||||
ri->cmp_mask.a8)) {
|
|
||||||
DEBUG_PRINTF("halt: failed mask check\n");
|
|
||||||
return HWLM_CONTINUE_MATCHING;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PROGRAM_NEXT_INSTRUCTION
|
|
||||||
|
|
||||||
PROGRAM_CASE(CHECK_LIT_EARLY) {
|
PROGRAM_CASE(CHECK_LIT_EARLY) {
|
||||||
if (end < ri->min_offset) {
|
if (end < ri->min_offset) {
|
||||||
DEBUG_PRINTF("halt: before min_offset=%u\n",
|
DEBUG_PRINTF("halt: before min_offset=%u\n",
|
||||||
|
@ -193,7 +193,6 @@ public:
|
|||||||
|
|
||||||
const void *get() const {
|
const void *get() const {
|
||||||
switch (code()) {
|
switch (code()) {
|
||||||
case ROSE_INSTR_CHECK_LIT_MASK: return &u.checkLitMask;
|
|
||||||
case ROSE_INSTR_CHECK_LIT_EARLY: return &u.checkLitEarly;
|
case ROSE_INSTR_CHECK_LIT_EARLY: return &u.checkLitEarly;
|
||||||
case ROSE_INSTR_CHECK_GROUPS: return &u.checkGroups;
|
case ROSE_INSTR_CHECK_GROUPS: return &u.checkGroups;
|
||||||
case ROSE_INSTR_CHECK_ONLY_EOD: return &u.checkOnlyEod;
|
case ROSE_INSTR_CHECK_ONLY_EOD: return &u.checkOnlyEod;
|
||||||
@ -246,7 +245,6 @@ public:
|
|||||||
|
|
||||||
size_t length() const {
|
size_t length() const {
|
||||||
switch (code()) {
|
switch (code()) {
|
||||||
case ROSE_INSTR_CHECK_LIT_MASK: return sizeof(u.checkLitMask);
|
|
||||||
case ROSE_INSTR_CHECK_LIT_EARLY: return sizeof(u.checkLitEarly);
|
case ROSE_INSTR_CHECK_LIT_EARLY: return sizeof(u.checkLitEarly);
|
||||||
case ROSE_INSTR_CHECK_GROUPS: return sizeof(u.checkGroups);
|
case ROSE_INSTR_CHECK_GROUPS: return sizeof(u.checkGroups);
|
||||||
case ROSE_INSTR_CHECK_ONLY_EOD: return sizeof(u.checkOnlyEod);
|
case ROSE_INSTR_CHECK_ONLY_EOD: return sizeof(u.checkOnlyEod);
|
||||||
@ -298,7 +296,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
union {
|
union {
|
||||||
ROSE_STRUCT_CHECK_LIT_MASK checkLitMask;
|
|
||||||
ROSE_STRUCT_CHECK_LIT_EARLY checkLitEarly;
|
ROSE_STRUCT_CHECK_LIT_EARLY checkLitEarly;
|
||||||
ROSE_STRUCT_CHECK_GROUPS checkGroups;
|
ROSE_STRUCT_CHECK_GROUPS checkGroups;
|
||||||
ROSE_STRUCT_CHECK_ONLY_EOD checkOnlyEod;
|
ROSE_STRUCT_CHECK_ONLY_EOD checkOnlyEod;
|
||||||
@ -377,7 +374,6 @@ struct RoseResources {
|
|||||||
bool has_states = false;
|
bool has_states = false;
|
||||||
bool checks_groups = false;
|
bool checks_groups = false;
|
||||||
bool has_lit_delay = false;
|
bool has_lit_delay = false;
|
||||||
bool has_lit_mask = false;
|
|
||||||
bool has_anchored = false;
|
bool has_anchored = false;
|
||||||
bool has_eod = false;
|
bool has_eod = false;
|
||||||
};
|
};
|
||||||
@ -667,7 +663,6 @@ u8 pickRuntimeImpl(const RoseBuildImpl &build, const build_context &bc,
|
|||||||
DEBUG_PRINTF("has_states=%d\n", bc.resources.has_states);
|
DEBUG_PRINTF("has_states=%d\n", bc.resources.has_states);
|
||||||
DEBUG_PRINTF("checks_groups=%d\n", bc.resources.checks_groups);
|
DEBUG_PRINTF("checks_groups=%d\n", bc.resources.checks_groups);
|
||||||
DEBUG_PRINTF("has_lit_delay=%d\n", bc.resources.has_lit_delay);
|
DEBUG_PRINTF("has_lit_delay=%d\n", bc.resources.has_lit_delay);
|
||||||
DEBUG_PRINTF("has_lit_mask=%d\n", bc.resources.has_lit_mask);
|
|
||||||
DEBUG_PRINTF("has_anchored=%d\n", bc.resources.has_anchored);
|
DEBUG_PRINTF("has_anchored=%d\n", bc.resources.has_anchored);
|
||||||
DEBUG_PRINTF("has_eod=%d\n", bc.resources.has_eod);
|
DEBUG_PRINTF("has_eod=%d\n", bc.resources.has_eod);
|
||||||
|
|
||||||
@ -2948,9 +2943,6 @@ void recordResources(RoseResources &resources,
|
|||||||
case ROSE_INSTR_PUSH_DELAYED:
|
case ROSE_INSTR_PUSH_DELAYED:
|
||||||
resources.has_lit_delay = true;
|
resources.has_lit_delay = true;
|
||||||
break;
|
break;
|
||||||
case ROSE_INSTR_CHECK_LIT_MASK:
|
|
||||||
resources.has_lit_mask = true;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -244,16 +244,6 @@ void dumpProgram(ofstream &os, const RoseEngine *t, const char *pc) {
|
|||||||
}
|
}
|
||||||
PROGRAM_NEXT_INSTRUCTION
|
PROGRAM_NEXT_INSTRUCTION
|
||||||
|
|
||||||
PROGRAM_CASE(CHECK_LIT_MASK) {
|
|
||||||
os << " and_mask "
|
|
||||||
<< dumpStrMask(ri->and_mask.a8, sizeof(ri->and_mask.a8))
|
|
||||||
<< endl;
|
|
||||||
os << " cmp_mask "
|
|
||||||
<< dumpStrMask(ri->cmp_mask.a8, sizeof(ri->cmp_mask.a8))
|
|
||||||
<< endl;
|
|
||||||
}
|
|
||||||
PROGRAM_NEXT_INSTRUCTION
|
|
||||||
|
|
||||||
PROGRAM_CASE(CHECK_LIT_EARLY) {
|
PROGRAM_CASE(CHECK_LIT_EARLY) {
|
||||||
os << " min_offset " << ri->min_offset << endl;
|
os << " min_offset " << ri->min_offset << endl;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,6 @@
|
|||||||
/** \brief Role program instruction opcodes. */
|
/** \brief Role program instruction opcodes. */
|
||||||
enum RoseInstructionCode {
|
enum RoseInstructionCode {
|
||||||
ROSE_INSTR_ANCHORED_DELAY, //!< Delay until after anchored matcher.
|
ROSE_INSTR_ANCHORED_DELAY, //!< Delay until after anchored matcher.
|
||||||
ROSE_INSTR_CHECK_LIT_MASK, //!< Check and/cmp mask.
|
|
||||||
ROSE_INSTR_CHECK_LIT_EARLY, //!< Skip matches before floating min offset.
|
ROSE_INSTR_CHECK_LIT_EARLY, //!< Skip matches before floating min offset.
|
||||||
ROSE_INSTR_CHECK_GROUPS, //!< Check that literal groups are on.
|
ROSE_INSTR_CHECK_GROUPS, //!< Check that literal groups are on.
|
||||||
ROSE_INSTR_CHECK_ONLY_EOD, //!< Role matches only at EOD.
|
ROSE_INSTR_CHECK_ONLY_EOD, //!< Role matches only at EOD.
|
||||||
@ -120,18 +119,6 @@ struct ROSE_STRUCT_ANCHORED_DELAY {
|
|||||||
u32 done_jump; //!< Jump forward this many bytes if successful.
|
u32 done_jump; //!< Jump forward this many bytes if successful.
|
||||||
};
|
};
|
||||||
|
|
||||||
union RoseLiteralMask {
|
|
||||||
u64a a64[MAX_MASK2_WIDTH / sizeof(u64a)];
|
|
||||||
u8 a8[MAX_MASK2_WIDTH];
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Note: check failure will halt program. */
|
|
||||||
struct ROSE_STRUCT_CHECK_LIT_MASK {
|
|
||||||
u8 code; //!< From enum RoseInstructionCode.
|
|
||||||
union RoseLiteralMask and_mask;
|
|
||||||
union RoseLiteralMask cmp_mask;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Note: check failure will halt program. */
|
/** Note: check failure will halt program. */
|
||||||
struct ROSE_STRUCT_CHECK_LIT_EARLY {
|
struct ROSE_STRUCT_CHECK_LIT_EARLY {
|
||||||
u8 code; //!< From enum RoseInstructionCode.
|
u8 code; //!< From enum RoseInstructionCode.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user