Skip to content

Commit d9a647b

Browse files
committed
Remove some casts
1 parent f8eeaf5 commit d9a647b

File tree

5 files changed

+32
-34
lines changed

5 files changed

+32
-34
lines changed

src/aarch64.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl Vector for uint8x16_t {
4949
}
5050

5151
#[inline]
52-
unsafe fn to_bitmask(a: Self) -> i32 {
52+
unsafe fn to_bitmask(a: Self) -> u32 {
5353
let extended = vreinterpretq_u8_s8(vshrq_n_s8(vreinterpretq_s8_u8(a), 7));
5454
let masked = vandq_u8(vld1q_u8(MD.as_ptr()), extended);
5555
let maskedhi = vextq_u8(masked, masked, 8);
@@ -82,7 +82,7 @@ impl Vector for uint8x8_t {
8282
}
8383

8484
#[inline]
85-
unsafe fn to_bitmask(a: Self) -> i32 {
85+
unsafe fn to_bitmask(a: Self) -> u32 {
8686
vaddv_u8(vand_u8(
8787
vreinterpret_u8_s8(vshr_n_s8(vreinterpret_s8_u8(a), 7)),
8888
vld1_u8(MD.as_ptr()),
@@ -121,7 +121,7 @@ impl Vector for uint8x4_t {
121121
}
122122

123123
#[inline]
124-
unsafe fn to_bitmask(a: Self) -> i32 {
124+
unsafe fn to_bitmask(a: Self) -> u32 {
125125
uint8x8_t::to_bitmask(a.0) & 0xF
126126
}
127127
}
@@ -162,7 +162,7 @@ impl Vector for uint8x2_t {
162162
}
163163

164164
#[inline]
165-
unsafe fn to_bitmask(a: Self) -> i32 {
165+
unsafe fn to_bitmask(a: Self) -> u32 {
166166
uint8x8_t::to_bitmask(a.0) & 0x3
167167
}
168168
}

src/lib.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ trait Vector: Copy {
166166

167167
unsafe fn bitwise_and(a: Self::Mask, b: Self::Mask) -> Self::Mask;
168168

169-
unsafe fn to_bitmask(a: Self::Mask) -> i32;
169+
unsafe fn to_bitmask(a: Self::Mask) -> u32;
170170
}
171171

172172
/// Hash of the first and "last" bytes in the needle for use with the SIMD
@@ -209,10 +209,9 @@ trait Searcher<N: NeedleWithSize + ?Sized> {
209209
#[clone(target = "aarch64+neon")]
210210
unsafe fn vector_search_in_chunk<V: Vector>(
211211
&self,
212-
haystack: &[u8],
213212
hash: &VectorHash<V>,
214213
start: *const u8,
215-
mask: i32,
214+
mask: u32,
216215
) -> bool {
217216
let first = V::load(start);
218217
let last = V::load(start.add(self.position()));
@@ -221,10 +220,9 @@ trait Searcher<N: NeedleWithSize + ?Sized> {
221220
let eq_last = V::lanes_eq(hash.last, last);
222221

223222
let eq = V::bitwise_and(eq_first, eq_last);
224-
let mut eq = (V::to_bitmask(eq) & mask) as u32;
223+
let mut eq = V::to_bitmask(eq) & mask;
225224

226-
let start = start as usize - haystack.as_ptr() as usize;
227-
let chunk = haystack.as_ptr().add(start + 1);
225+
let chunk = start.add(1);
228226
let needle = self.needle().as_bytes().as_ptr().add(1);
229227

230228
while eq != 0 {
@@ -273,17 +271,17 @@ trait Searcher<N: NeedleWithSize + ?Sized> {
273271

274272
let mut chunks = haystack[..end].chunks_exact(V::LANES);
275273
for chunk in &mut chunks {
276-
if dispatch!(self.vector_search_in_chunk(haystack, hash, chunk.as_ptr(), -1)) {
274+
if dispatch!(self.vector_search_in_chunk(hash, chunk.as_ptr(), u32::MAX)) {
277275
return true;
278276
}
279277
}
280278

281279
let remainder = chunks.remainder().len();
282280
if remainder > 0 {
283281
let start = haystack.as_ptr().add(end - V::LANES);
284-
let mask = -1 << (V::LANES - remainder);
282+
let mask = u32::MAX << (V::LANES - remainder);
285283

286-
if dispatch!(self.vector_search_in_chunk(haystack, hash, start, mask)) {
284+
if dispatch!(self.vector_search_in_chunk(hash, start, mask)) {
287285
return true;
288286
}
289287
}

src/stdsimd.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ where
3030

3131
#[inline]
3232
unsafe fn splat(a: u8) -> Self {
33-
Simd::splat(a as u8)
33+
Simd::splat(a)
3434
}
3535

3636
#[inline]
@@ -49,8 +49,8 @@ where
4949
}
5050

5151
#[inline]
52-
unsafe fn to_bitmask(a: Self::Mask) -> i32 {
53-
std::mem::transmute(a.to_fixed_bitmask())
52+
unsafe fn to_bitmask(a: Self::Mask) -> u32 {
53+
a.to_fixed_bitmask()
5454
}
5555
}
5656

src/wasm32.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ impl Vector for v128 {
3434

3535
#[inline]
3636
#[target_feature(enable = "simd128")]
37-
unsafe fn to_bitmask(a: Self) -> i32 {
38-
u8x16_bitmask(a) as i32
37+
unsafe fn to_bitmask(a: Self) -> u32 {
38+
u8x16_bitmask(a).into()
3939
}
4040
}
4141

@@ -74,8 +74,8 @@ impl Vector for v64 {
7474

7575
#[inline]
7676
#[target_feature(enable = "simd128")]
77-
unsafe fn to_bitmask(a: Self) -> i32 {
78-
(u8x16_bitmask(a.0) & 0xFF) as i32
77+
unsafe fn to_bitmask(a: Self) -> u32 {
78+
(u8x16_bitmask(a.0) & 0xFF).into()
7979
}
8080
}
8181

@@ -120,8 +120,8 @@ impl Vector for v32 {
120120

121121
#[inline]
122122
#[target_feature(enable = "simd128")]
123-
unsafe fn to_bitmask(a: Self) -> i32 {
124-
(u8x16_bitmask(a.0) & 0xF) as i32
123+
unsafe fn to_bitmask(a: Self) -> u32 {
124+
(u8x16_bitmask(a.0) & 0xF).into()
125125
}
126126
}
127127

@@ -166,8 +166,8 @@ impl Vector for v16 {
166166

167167
#[inline]
168168
#[target_feature(enable = "simd128")]
169-
unsafe fn to_bitmask(a: Self) -> i32 {
170-
(u8x16_bitmask(a.0) & 0x3) as i32
169+
unsafe fn to_bitmask(a: Self) -> u32 {
170+
(u8x16_bitmask(a.0) & 0x3).into()
171171
}
172172
}
173173

src/x86.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ impl Vector for __m16i {
5858

5959
#[inline]
6060
#[target_feature(enable = "avx2")]
61-
unsafe fn to_bitmask(a: Self) -> i32 {
62-
_mm_movemask_epi8(a.0) & 0x3
61+
unsafe fn to_bitmask(a: Self) -> u32 {
62+
std::mem::transmute(_mm_movemask_epi8(a.0) & 0x3)
6363
}
6464
}
6565

@@ -105,8 +105,8 @@ impl Vector for __m32i {
105105

106106
#[inline]
107107
#[target_feature(enable = "avx2")]
108-
unsafe fn to_bitmask(a: Self) -> i32 {
109-
_mm_movemask_epi8(a.0) & 0xF
108+
unsafe fn to_bitmask(a: Self) -> u32 {
109+
std::mem::transmute(_mm_movemask_epi8(a.0) & 0xF)
110110
}
111111
}
112112

@@ -152,8 +152,8 @@ impl Vector for __m64i {
152152

153153
#[inline]
154154
#[target_feature(enable = "avx2")]
155-
unsafe fn to_bitmask(a: Self) -> i32 {
156-
_mm_movemask_epi8(a.0) & 0xFF
155+
unsafe fn to_bitmask(a: Self) -> u32 {
156+
std::mem::transmute(_mm_movemask_epi8(a.0) & 0xFF)
157157
}
158158
}
159159

@@ -194,8 +194,8 @@ impl Vector for __m128i {
194194

195195
#[inline]
196196
#[target_feature(enable = "avx2")]
197-
unsafe fn to_bitmask(a: Self) -> i32 {
198-
_mm_movemask_epi8(a)
197+
unsafe fn to_bitmask(a: Self) -> u32 {
198+
std::mem::transmute(_mm_movemask_epi8(a))
199199
}
200200
}
201201

@@ -229,8 +229,8 @@ impl Vector for __m256i {
229229

230230
#[inline]
231231
#[target_feature(enable = "avx2")]
232-
unsafe fn to_bitmask(a: Self) -> i32 {
233-
_mm256_movemask_epi8(a)
232+
unsafe fn to_bitmask(a: Self) -> u32 {
233+
std::mem::transmute(_mm256_movemask_epi8(a))
234234
}
235235
}
236236

0 commit comments

Comments
 (0)