diff --git a/src/encoder/colortype.rs b/src/encoder/colortype.rs index 0811ef3..189d80c 100644 --- a/src/encoder/colortype.rs +++ b/src/encoder/colortype.rs @@ -22,42 +22,11 @@ macro_rules! fp_predict { result.resize(start_len + byte_count, 0); let output = &mut result[start_len..]; - // Step 1 & 2: Convert to big-endian and shuffle bytes - // All first bytes, then all second bytes, etc. - // - // We process the input in chunks of 4 floats/doubles at a time. - // For each chunk we shuffle the bytes into a stack buffer, then - // copy each byte-lane's portion into the output. This turns - // single-byte pushes into 16-byte (for f32) or 32-byte (for f64) - // memcpy-like stores that the compiler can vectorize. - const CHUNK: usize = 4; - let chunks = num_values / CHUNK; - let remainder = num_values % CHUNK; - - let mut scratch = [[0u8; CHUNK]; BYTE_SIZE]; - for c in 0..chunks { - let src = &row[c * CHUNK..][..CHUNK]; - for j in 0..CHUNK { - let bytes = src[j].to_be_bytes(); - for b in 0..BYTE_SIZE { - scratch[b][j] = bytes[b]; - } - } + // Step 1 & 2: Convert to big-endian and scatter bytes + for (i, &value) in row.iter().enumerate() { + let bytes = value.to_be_bytes(); for b in 0..BYTE_SIZE { - let dest_offset = b * num_values + c * CHUNK; - output[dest_offset..dest_offset + CHUNK] - .copy_from_slice(&scratch[b]); - } - } - - // Handle the remaining elements that don't fill a full chunk - if remainder > 0 { - let src = &row[chunks * CHUNK..]; - for (j, &value) in src.iter().enumerate() { - let bytes = value.to_be_bytes(); - for b in 0..BYTE_SIZE { - output[b * num_values + chunks * CHUNK + j] = bytes[b]; - } + output[b * num_values + i] = bytes[b]; } }