Closed
Description
When using a loop and checking exact bounds upfront, vectorized instructions are used:
pub fn xorl(a: &[u8], b: &[u8], c: &mut [u8]) {
let (a_bound, b_bound, c_bound) = (&a[..1024], &b[..1024], &mut c[..1024]);
for i in 0..1024 {
c[i] = a[i] ^ b[i];
}
}
However when the upfront checks actually tests for a bigger slice size, the same optimizations are not applied:
pub fn xorl(a: &[u8], b: &[u8], c: &mut [u8]) {
let (a_bound, b_bound, c_bound) = (&a[..2048], &b[..2048], &mut c[..2048]);
for i in 0..1024 {
c[i] = a[i] ^ b[i];
}
}
Since slices of size 2048 are always also at least of size 1024, I would expect the generated code to be equivalent.
Meta
rustc --version --verbose
:
Happens on nightly as well as 1.40 - as seen in Godbolt