Skip to content

Commit

Permalink
fix two bugs and add commented out debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
alion02 committed Dec 19, 2024
1 parent 4358395 commit c4a9901
Showing 1 changed file with 51 additions and 3 deletions.
54 changes: 51 additions & 3 deletions src/day18.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Write;

use super::*;

static LUT: [i8x16; 512] = unsafe {
Expand Down Expand Up @@ -153,7 +155,7 @@ unsafe fn inner2(s: &[u8]) -> &str {
let mut i = 0;
while i < goal.len() {
if i % 9 == 8 {
goal[i] = -128;
goal[i] = -64;
}
if i / 9 == 1 {
goal[i] = -1;
Expand Down Expand Up @@ -190,10 +192,12 @@ unsafe fn inner2(s: &[u8]) -> &str {
.add(69 * 72 / 8)
.cast::<i8x32>()
.write_unaligned(i8x32::from_array([
1, 0, 0, 0, 0, 0, 0, 0, -128, 1, 0, 0, 0, 0, 0, 0, 0, -128, -1, -1, -1, -1, -1, -1, -1, -1, -128, -1, -1,
-1, -1, -1,
1, 0, 0, 0, 0, 0, 0, 0, -128, 1, 0, 0, 0, 0, 0, 0, 0, -128, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1,
]));

// let mut prev_at_count = 0;

loop {
let chunk = ptr.read_unaligned();
let chunk = chunk - Simd::splat(b'0' as _);
Expand Down Expand Up @@ -286,6 +290,50 @@ unsafe fn inner2(s: &[u8]) -> &str {
saved_rsp = out(reg) _,
ret = inout(reg) 0usize => ret,
);

// let str = &mut String::new();
// let mut curr_at_count = 0;
// for y in 1..72 {
// for x in 0..9 {
// for bit_idx in 0..8 {
// if x == 8 && bit_idx == 7 {
// continue;
// }
// let i = y * 9 + x;
// let bit = 1 << bit_idx;
// let front = *front.add(i) & bit != 0;
// let map = *map.add(i) & bit != 0;
// if front {
// curr_at_count += 1;
// }
// write!(
// str,
// "{}",
// if y * 72 + x * 8 + bit_idx == pos as _ {
// '+'
// } else if front && !map {
// '?'
// } else if front {
// '@'
// } else if map {
// '#'
// } else {
// '.'
// }
// )
// .unwrap();
// }
// }
// writeln!(str).unwrap();
// }
// if curr_at_count > prev_at_count {
// prev_at_count = curr_at_count;
// println!(
// "{str}coords:{}\n",
// std::str::from_utf8_unchecked(std::slice::from_raw_parts(ptr.cast(), len))
// );
// }

if ret > 0 {
return std::str::from_utf8_unchecked(std::slice::from_raw_parts(ptr.cast(), len));
}
Expand Down

0 comments on commit c4a9901

Please sign in to comment.