From 808cca4a5e9817178003862a411ba23dc1986490 Mon Sep 17 00:00:00 2001 From: Dorje Gilfillan Date: Tue, 24 Dec 2024 18:43:42 +0200 Subject: [PATCH] try? --- src/day23.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/day23.rs b/src/day23.rs index 59a0061..00adecb 100644 --- a/src/day23.rs +++ b/src/day23.rs @@ -1,5 +1,8 @@ #![expect(clippy::cast_possible_truncation, static_mut_refs)] -use std::hint::{assert_unchecked, unreachable_unchecked}; +use std::{ + hint::{assert_unchecked, unreachable_unchecked}, + simd::{u8x32, Simd}, +}; use tinyvec::ArrayVec; #[inline(always)] @@ -82,6 +85,20 @@ static mut NODES: [ArrayVec<[u16; MAX_CONNECTIONS]>; 26 * 26] = unsafe fn parse(mut input: &[u8]) { NODES.fill(ArrayVec::from_array_empty([0; MAX_CONNECTIONS])); + while input.len() >= 32 { + let block = u8x32::from_array(input[..32].try_into().unwrap()); + let block = block - Simd::splat(b'a'); + for i in 0..5 { + let lhs = 26 * block[i * 6] as u16 + block[i * 6 + 1] as u16; + let rhs = 26 * block[i * 6 + 3] as u16 + block[i * 6 + 4] as u16; + + let None = NODES[lhs as usize].try_push(rhs) else { unreachable_unchecked() }; + let None = NODES[rhs as usize].try_push(lhs) else { unreachable_unchecked() }; + } + + input = &input[30..]; + } + while !input.is_empty() { assert_unchecked(input.len() >= 6); let lhs = 26 * (input[0] - b'a') as u16 + (input[1] - b'a') as u16;