@@ -8,13 +8,11 @@ pub fn part1(s: &str) -> u64 {
88 unsafe { part1_inner ( s) }
99}
1010
11- #[ cfg( not( test) ) ]
12- const SIZE : usize = 500 ;
13- #[ cfg( test) ]
14- const SIZE : usize = 5 ;
15-
1611const DS : usize = 7 * 6 + 1 ;
1712
13+ const ALL_BITS : i8 = 0b111 ;
14+ const KEPT_BITS : i8 = 0b011 ;
15+
1816#[ inline( always) ]
1917unsafe fn part1_inner ( s : & [ u8 ] ) -> u64 {
2018 let mut sum = 0 ;
@@ -36,23 +34,31 @@ unsafe fn part1_inner(s: &[u8]) -> u64 {
3634 let d = _mm256_and_si256 (
3735 d,
3836 _mm256_setr_epi8 (
39- - 1 , - 1 , - 1 , - 1 , - 1 , 0 , //
40- - 1 , - 1 , - 1 , - 1 , - 1 , 0 , //
41- - 1 , - 1 , - 1 , - 1 , - 1 , 0 , //
42- - 1 , - 1 , - 1 , - 1 , - 1 , 0 , //
43- - 1 , - 1 , - 1 , - 1 , - 1 , 0 , 0 , 0 ,
37+ ALL_BITS , ALL_BITS , ALL_BITS , ALL_BITS , ALL_BITS , 0 , //
38+ ALL_BITS , ALL_BITS , ALL_BITS , ALL_BITS , ALL_BITS , 0 , //
39+ ALL_BITS , ALL_BITS , ALL_BITS , ALL_BITS , ALL_BITS , 0 , //
40+ ALL_BITS , ALL_BITS , ALL_BITS , ALL_BITS , ALL_BITS , 0 , //
41+ ALL_BITS , ALL_BITS , ALL_BITS , ALL_BITS , ALL_BITS , 0 , 0 , 0 ,
4442 ) ,
4543 ) ;
4644
4745 let other = if is_key { & holes } else { & keys } ;
4846 for o in other {
49- let collisions = _mm256_cmpeq_epi8 (
50- _mm256_add_epi8 ( d, * o) ,
51- _mm256_set1_epi8 ( b'#' . wrapping_add ( b'#' ) as i8 ) ,
52- ) ;
47+ let collisions = _mm256_cmpeq_epi8 ( d, * o) ;
5348 let collisions = _mm256_movemask_epi8 ( collisions) ;
5449 sum += ( collisions == 0 ) as u64 ;
5550 }
51+ let d = _mm256_and_si256 ( d, _mm256_set1_epi8 ( KEPT_BITS ) ) ;
52+ let d = _mm256_or_si256 (
53+ d,
54+ _mm256_setr_epi8 (
55+ 0 , 0 , 0 , 0 , 0 , -1 , //
56+ 0 , 0 , 0 , 0 , 0 , -1 , //
57+ 0 , 0 , 0 , 0 , 0 , -1 , //
58+ 0 , 0 , 0 , 0 , 0 , -1 , //
59+ 0 , 0 , 0 , 0 , 0 , -1 , -1 , -1 ,
60+ ) ,
61+ ) ;
5662
5763 if is_key {
5864 keys. push_unchecked ( d) ;
0 commit comments