Skip to content

Commit

Permalink
Correctly block further access to aligned_index
Browse files Browse the repository at this point in the history
Dropping it did nothing since it was a Copy type. Now we place it in a scope to
make sure it's not used by accident afterwards.
  • Loading branch information
mqudsi committed Jan 22, 2024
1 parent 350469a commit 5a34734
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/tac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,26 +213,29 @@ unsafe fn search256<W: Write>(bytes: &[u8], mut output: &mut W) -> Result<(), st
// Regardless of whether or not the base pointer is aligned to a 32-byte address, we are
// reading from an arbitrary offset (determined by the length of the lines) and so we must
// first calculate a safe place to begin using SIMD operations from.
let align_offset = unsafe { ptr.offset(index as isize).align_offset(32) };
let aligned_index = index as usize + align_offset - 32;
debug_assert!(
aligned_index <= index as usize && aligned_index < last_printed && aligned_index > 0
);
debug_assert!(
(ptr as usize + aligned_index as usize) % 32 == 0,
"Adjusted index is still not at 256-bit boundary!"
);

// eprintln!("Unoptimized search from {} to {}", aligned_index, last_printed);
slow_search_and_print(
bytes,
aligned_index,
last_printed,
&mut last_printed,
&mut output,
)?;
index = aligned_index;
drop(aligned_index);
index = {
let align_offset = unsafe { ptr.offset(index as isize).align_offset(32) };
let aligned_index = index as usize + align_offset - 32;
debug_assert!(
aligned_index <= index as usize
&& aligned_index < last_printed
&& aligned_index > 0
);
debug_assert!(
(ptr as usize + aligned_index as usize) % 32 == 0,
"Adjusted index is still not at 256-bit boundary!"
);

// eprintln!("Unoptimized search from {} to {}", aligned_index, last_printed);
slow_search_and_print(
bytes,
aligned_index,
last_printed,
&mut last_printed,
&mut output,
)?;
aligned_index
};

let pattern256 = unsafe { _mm256_set1_epi8(SEARCH as i8) };
while index >= 64 {
Expand Down

0 comments on commit 5a34734

Please sign in to comment.