Second prepass is faster on this input

This commit is contained in:
Luke Hubmayer-Werner 2022-12-07 21:12:16 +10:30
parent e2a9d5be3a
commit 688e4a7eaa
1 changed files with 6 additions and 8 deletions

View File

@ -51,11 +51,13 @@ fn find_first_unique_runs(s: &Vec<u8>) -> (Int, Int) {
for i in 0..(4096-1) { for i in 0..(4096-1) {
masks[i] |= masks[i+1]; masks[i] |= masks[i+1];
} }
// Turn masks2 into masks4. Indices are now +3.
for i in 0..(4096-3) {
masks[i] |= masks[i+2];
}
'four_loop: for batch in 1..(BATCH_NUM) { 'four_loop: for batch in 1..(BATCH_NUM) {
for i in 0..BATCH_SIZE { for i in 0..BATCH_SIZE {
let idx = batch*BATCH_SIZE + i; scratch_masks_bits[i] = masks[batch*BATCH_SIZE + i].count_ones() as u8;
scratch_masks[i] = masks[idx] | masks[idx-2];
scratch_masks_bits[i] = scratch_masks[i].count_ones() as u8;
} }
for i in 0..BATCH_SIZE { for i in 0..BATCH_SIZE {
if scratch_masks_bits[i] == 4 { if scratch_masks_bits[i] == 4 {
@ -64,10 +66,6 @@ fn find_first_unique_runs(s: &Vec<u8>) -> (Int, Int) {
} }
} }
} }
// Turn masks2 into masks4. Indices are now +3.
for i in four..(4096-3) {
masks[i] |= masks[i+2];
}
// Turn masks4 into masks8. Indices are now +7. // Turn masks4 into masks8. Indices are now +7.
for i in four..(4096-7) { for i in four..(4096-7) {
masks[i] |= masks[i+4]; masks[i] |= masks[i+4];
@ -86,7 +84,7 @@ fn find_first_unique_runs(s: &Vec<u8>) -> (Int, Int) {
} }
} }
} }
return (four+2, fourteen+8); return (four+4, fourteen+8);
} }
fn main() { fn main() {