mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-11-19 02:30:35 +03:00
masked version of dverm
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Intel Corporation
|
||||
* Copyright (c) 2015-2016, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -172,6 +172,27 @@ const u8 *dvermSearchAlignedNocase(m128 chars1, m128 chars2, u8 c1, u8 c2,
|
||||
return buf;
|
||||
}
|
||||
|
||||
static really_inline
|
||||
const u8 *dvermSearchAlignedMasked(m128 chars1, m128 chars2,
|
||||
m128 mask1, m128 mask2, u8 c1, u8 c2, u8 m1,
|
||||
u8 m2, const u8 *buf, const u8 *buf_end) {
|
||||
assert((size_t)buf % 16 == 0);
|
||||
|
||||
for (; buf + 16 < buf_end; buf += 16) {
|
||||
m128 data = load128(buf);
|
||||
u32 z = movemask128(and128(eq128(chars1, and128(data, mask1)),
|
||||
shiftRight8Bits(eq128(chars2, and128(data, mask2)))));
|
||||
if ((buf[15] & m1) == c1 && (buf[16] & m2) == c2) {
|
||||
z |= (1 << 15);
|
||||
}
|
||||
if (unlikely(z)) {
|
||||
u32 pos = ctz32(z);
|
||||
return buf + pos;
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
// returns NULL if not found
|
||||
static really_inline
|
||||
const u8 *dvermPrecondition(m128 chars1, m128 chars2, const u8 *buf) {
|
||||
@@ -205,6 +226,22 @@ const u8 *dvermPreconditionNocase(m128 chars1, m128 chars2, const u8 *buf) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// returns NULL if not found
|
||||
static really_inline
|
||||
const u8 *dvermPreconditionMasked(m128 chars1, m128 chars2,
|
||||
m128 mask1, m128 mask2, const u8 *buf) {
|
||||
m128 data = loadu128(buf); // unaligned
|
||||
u32 z = movemask128(and128(eq128(chars1, and128(data, mask1)),
|
||||
shiftRight8Bits(eq128(chars2, and128(data, mask2)))));
|
||||
|
||||
/* no fixup of the boundary required - the aligned run will pick it up */
|
||||
if (unlikely(z)) {
|
||||
u32 pos = ctz32(z);
|
||||
return buf + pos;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static really_inline
|
||||
const u8 *lastMatchOffset(const u8 *buf_end, u32 z) {
|
||||
assert(z);
|
||||
|
||||
Reference in New Issue
Block a user