-
Notifications
You must be signed in to change notification settings - Fork 7
Speedup compress #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Speedup compress #83
Conversation
for (((c1, c2), s1), s2) in b1.iter().zip(b2).zip(q1).zip(q2) { | ||
if c1 != c2 { | ||
return c1 > c2; | ||
} | ||
if s1 != s2 { | ||
return s1 > s2; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't yet found a good way to vectorize this part (tried some stuff with xor and leading_zeros
but I could not get it to be correct so far). at least it's out of the hot path, and the equality check will uses full-width loads/compares (even an avx one for the quadrant compare)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just documenting, I came up with this
let lc1 = u64::from_be_bytes(*b1.first_chunk().unwrap());
let lc2 = u64::from_be_bytes(*b2.first_chunk().unwrap());
#[inline(always)]
fn transform(slice: &[u16]) -> u128 {
let raw = unsafe { slice.as_ptr().cast::<u128>().read_unaligned().to_be() };
let mask = 0xFF00ff00_FF00ff00_FF00ff00_FF00ff00u128;
let upper = raw & mask;
let lower = raw & !mask;
(upper >> 8) | (lower << 8)
}
if b1 != b2 || q1 != q2 {
let lq1 = transform(q1);
let lq2 = transform(q2);
let first_bad_c = (lc1 ^ lc2).leading_zeros() / 8;
let first_bad_q = (lq1 ^ lq2).leading_zeros() / 16;
if first_bad_c <= first_bad_q {
return lc1 > lc2;
} else {
return lq1 > lq2;
}
}
which is OK, but for some reason won't use xmm
registers, so it's overall just too many instructions to be profitable.
Codecov ReportAttention: Patch coverage is
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with the profile change removed.
6182d2c
to
9b09dfa
Compare
Rewrite code so that it is easier to vectorize. With these changes we now beat stock bzip2 handsomely on the compression benchmarks that I looked at. e.g