That's very useful feedback. I suspect if the solution is irreducible it's OK, which in this case is close to true (this is for bit-unpacking integers):
// bytes are added to the buffer until a value of bitwidth is available
for _ in 0..<bitWidth {
let byte = try UInt8(parsing: &input)
buffer |= UInt64(byte) << bitsInBuffer
bitsInBuffer += 8
// Values of bitwidth are right-shifted off the buffer.
while bitsInBuffer >= bitWidth && outPos < numValues {
let value = Int(buffer & mask)
out[outPos + outOffset] = value
outPos += 1
buffer >>= bitWidth
bitsInBuffer -= bitWidth
}
}