Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions library/core/src/num/imp/int_bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,26 @@ macro_rules! uint_impl {
// [0; n], [X; a], [0; n], [0; b] // q
// [0; n], [0; a + n], [Y; b] // x ^= q
// [0; n + n], [X; a], [0; b] // q >> n
// [0; n], [0; n], [X; a], [Y; b] // x ^= q << n
// [0; n], [0; n], [X; a], [Y; b] // x ^= q >> n
// ```
// Only zeros are shifted out, satisfying the assumption
// for the next group.

// In effect, the upper run of data is swapped with the
// group of `n` zeros below it.
let q = x & masks[stage];
x ^= q;
x ^= q >> n;

if cfg!(all(target_arch = "aarch64", target_feature = "neon")) && $U::BITS <= 64
{
// `q >> n` has no set bits in common with `x ^ q`, so addition
// is equivalent to XOR here. For widths up to 64 bits this
// allows AArch64 to use `usra`. For `u128`, this add may introduce
// a slower cross-limb carry chain.
x = (x & !masks[stage]).wrapping_add(q >> n);
} else {
x ^= q;
x ^= q >> n;
}
stage += 1;
}
x
Expand Down
Loading