Skip to content

Commit

Permalink
Vectorize part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
alion02 committed Dec 2, 2024
1 parent 7cbffa0 commit 6985653
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/day1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,16 @@ unsafe fn inner2(s: &str) -> impl Display {
let mut sum = 0u32;

for _ in 0..1000 {
while *left.get_unchecked(i) == 0 {
i += 1;
loop {
let left_chunk = (left.get_unchecked(i) as *const _ as *const u8x32).read_unaligned();
if left_chunk.reduce_or() != 0 {
i += left_chunk
.simd_ne(Simd::splat(0))
.to_bitmask()
.trailing_zeros() as usize;
break;
}
i += 32;
}

sum += (i as u32 + 10000) * *right.get_unchecked(i) as u32;
Expand Down

0 comments on commit 6985653

Please sign in to comment.