///|
/// Marks the zero bytes of an eight-byte word with isolated high bits.
#inline
fn zero_lanes(word : UInt64) -> UInt64 {
  let low = 0x7F7F7F7F7F7F7F7FUL
  // The addition stays within each byte. OR keeps original high bits set.
  (((word & low) + low) | word).lnot() & 0x8080808080808080UL
}

///|
/// Scans eight bytes per scalar iteration and carries the last whitespace bit.
fn scan_scalar(
  data : BytesView,
  previous_space : Int32,
) -> (Int32, Int32, Int32) {
  let length = data.length()
  if length < 16 {
    return scan_bytes(data, previous_space)
  }
  let backing = data.data()
  let start = data.start_offset()
  let high = 0x8080808080808080UL
  for offset = 0, lines = 0, words = 0, previous = previous_space.to_uint64(); length -
     offset >=
     8; {
    // The view contains all eight bytes, and loads use little-endian lane order.
    let block = backing.unsafe_read_uint64_le(start + offset)
    let low = block & 0x7F7F7F7F7F7F7F7FUL
    // The two biases set the lane's high bit at 9 and 14, respectively.
    let controls = (low + 0x7777777777777777UL) &
      ((low + 0x7272727272727272UL) | block).lnot() &
      high
    let whitespace = controls | zero_lanes(block ^ 0x2020202020202020UL)
    let newlines = zero_lanes(block ^ 0x0A0A0A0A0A0A0A0AUL)
    let starts = (whitespace ^ high) & ((whitespace << 8) | (previous << 7))
    // Put each line flag in the upper nibble and each word flag in the lower.
    // Multiplication sums the eight bytes into the high byte, with each total <= 8.
    let flags = (starts >> 7) | (newlines >> 3)
    let totals = ((flags * 0x0101010101010101UL) >> 56).to_int()
    continue offset + 8,
      lines + (totals >> 4),
      words + (totals & 15),
      whitespace >> 63
  } nobreak {
    let (tail_lines, tail_words, final_space) = scan_bytes(
      data[offset:],
      previous.to_int(),
    )
    (lines + tail_lines, words + tail_words, final_space)
  }
}