Function aoc::year2018::day14::writer

source ·
fn writer<'a>(tx: Sender<&'a [u8]>, done: &AtomicBool, recipes: &'a mut [u8])
Expand description

Generates recipes then sends them to the reader thread for checking in batches. Processing is broken into alternating “cold” and “hot” loops. An outer enclosing loop checks periodically for the done signal from the reader thread.

The “cold” loop processes recipes serially one by one but can handle input corner cases. It’s used when either:

  • One or both elves are within the first 23 recipes.
  • One or both elves are within the last 16 recipes.

The “hot” loop processes recipes efficiently in chunks of 16. The vast majority of recipes are calculated in this loop. As much as possible is parallelized using techniques similar to SIMD but using regular instructions instead of SIMD instrinsics or Rust’s portable SIMD API.

Interestingly on an Apple M2 Max this “poor man’s SIMD” has the same performance as using the portable SIMD API. This is probably due to the fact that the serial loops that write new recipes take the majority of the time.