Skip to content

Commit a0b63e3

Browse files
committed
Move VectorHash generic struct to lib.rs
1 parent 4522ec8 commit a0b63e3

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,24 @@ trait Vector: Copy {
164164
unsafe fn movemask_epi8(a: Self) -> i32;
165165
}
166166

167+
/// Hash of the first and "last" bytes in the needle for use with the SIMD
168+
/// algorithm implemented by `Avx2Searcher::vector_search_in`. As explained, any
169+
/// byte can be chosen to represent the "last" byte of the hash to prevent
170+
/// worst-case attacks.
171+
struct VectorHash<V: Vector> {
172+
first: V,
173+
last: V,
174+
}
175+
176+
impl<V: Vector> VectorHash<V> {
177+
unsafe fn new(first: u8, last: u8) -> Self {
178+
Self {
179+
first: Vector::set1_epi8(first as i8),
180+
last: Vector::set1_epi8(last as i8),
181+
}
182+
}
183+
}
184+
167185
#[cfg(test)]
168186
mod tests {
169187
use super::{MemchrSearcher, Needle};

src/x86.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(clippy::missing_safety_doc)]
22

3-
use crate::{bits, memcmp, MemchrSearcher, Needle, NeedleWithSize, Vector};
3+
use crate::{bits, memcmp, MemchrSearcher, Needle, NeedleWithSize, Vector, VectorHash};
44
use seq_macro::seq;
55
#[cfg(target_arch = "x86")]
66
use std::arch::x86::*;
@@ -192,25 +192,6 @@ impl Vector for __m256i {
192192
}
193193
}
194194

195-
/// Hash of the first and "last" bytes in the needle for use with the SIMD
196-
/// algorithm implemented by `Avx2Searcher::vector_search_in`. As explained, any
197-
/// byte can be chosen to represent the "last" byte of the hash to prevent
198-
/// worst-case attacks.
199-
struct VectorHash<V: Vector> {
200-
first: V,
201-
last: V,
202-
}
203-
204-
impl<V: Vector> VectorHash<V> {
205-
#[target_feature(enable = "avx2")]
206-
unsafe fn new(first: u8, last: u8) -> Self {
207-
Self {
208-
first: Vector::set1_epi8(first as i8),
209-
last: Vector::set1_epi8(last as i8),
210-
}
211-
}
212-
}
213-
214195
impl From<&VectorHash<__m128i>> for VectorHash<__m64i> {
215196
#[inline]
216197
fn from(hash: &VectorHash<__m128i>) -> Self {

0 commit comments

Comments
 (0)