Skip to content

Commit 35e97a6

Browse files
committed
Use type alias for intrinsic SIMD lane
This also fixes a slight issue where the wrong type (of the right size) was being used in the `size_of` calls.
1 parent 5b7b47e commit 35e97a6

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

core/src/defaults/lexer.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -567,26 +567,28 @@ unsafe fn find_identifier_end_avx2(input: &str, mut offset: usize) -> usize {
567567
use core::mem::size_of;
568568
use std::arch::x86_64::*;
569569

570-
unsafe fn range_mask(x: __m256i, range: RangeInclusive<u8>) -> __m256i {
570+
type Chunk = __m256i;
571+
572+
unsafe fn range_mask(x: Chunk, range: RangeInclusive<u8>) -> Chunk {
571573
unsafe {
572574
let lower = _mm256_cmpgt_epi8(_mm256_set1_epi8(*range.end() as i8 + 1), x);
573575
let upper = _mm256_cmpgt_epi8(x, _mm256_set1_epi8(*range.start() as i8 - 1));
574576
_mm256_and_si256(upper, lower)
575577
}
576578
}
577579

578-
unsafe fn any_non_ascii(chunk: std::arch::x86_64::__m256i) -> bool {
580+
unsafe fn any_non_ascii(chunk: Chunk) -> bool {
579581
unsafe { _mm256_testz_si256(_mm256_set1_epi8(i8::MIN), chunk) == 0 }
580582
}
581583

582-
while (offset + size_of::<__m256>()) <= input.len() {
584+
while (offset + size_of::<Chunk>()) <= input.len() {
583585
// SAFETY: requires that a 32-byte load from `input.as_ptr() + offset` does not touch uninitialised memory.
584586
// The above length check guarantees this.
585587
let ident_mask = unsafe {
586588
let chunk = _mm256_loadu_si256(
587589
// the `loadu` variant of this intrinsic doesn't require aligned addresses
588590
#[allow(clippy::cast_ptr_alignment)]
589-
input.as_ptr().add(offset).cast(),
591+
input.as_ptr().add(offset).cast::<Chunk>(),
590592
);
591593
if any_non_ascii(chunk) {
592594
break;
@@ -609,7 +611,7 @@ unsafe fn find_identifier_end_avx2(input: &str, mut offset: usize) -> usize {
609611
offset += ident_mask.trailing_ones() as usize;
610612
return offset;
611613
}
612-
offset += size_of::<__m256>();
614+
offset += size_of::<Chunk>();
613615
}
614616

615617
find_identifier_end_generic(input, offset)

0 commit comments

Comments
 (0)