diff options
| author | Amos Onn <amosonn@gmail.com> | 2020-01-30 20:04:24 +0100 |
|---|---|---|
| committer | Amos Onn <amosonn@gmail.com> | 2020-02-03 01:03:33 +0100 |
| commit | e835d0d761945bb242d271f5ccedf0aee54a4ca8 (patch) | |
| tree | 2f054bb8a0d79bc522c03fc55d26a33e552086b9 /src/libcore/ptr | |
| parent | f43c34a134358471726f25fe5973b8c7e177c825 (diff) | |
| download | rust-e835d0d761945bb242d271f5ccedf0aee54a4ca8.tar.gz rust-e835d0d761945bb242d271f5ccedf0aee54a4ca8.zip | |
Optimize core::ptr::align_offset
- Stopping condition inside mod_inv can be >= instead of > - Remove intrinsics::unchecked_rem, we are working modulu powers-of-2 so we can simply mask
Diffstat (limited to 'src/libcore/ptr')
| -rw-r--r-- | src/libcore/ptr/mod.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libcore/ptr/mod.rs b/src/libcore/ptr/mod.rs index 9727e4face5..8d839378027 100644 --- a/src/libcore/ptr/mod.rs +++ b/src/libcore/ptr/mod.rs @@ -1083,7 +1083,7 @@ pub(crate) unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usize { // anyway. inverse = inverse.wrapping_mul(2usize.wrapping_sub(x.wrapping_mul(inverse))) & (going_mod - 1); - if going_mod > m { + if going_mod >= m { return inverse & (m - 1); } going_mod = going_mod.wrapping_mul(going_mod); @@ -1134,7 +1134,7 @@ pub(crate) unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usize { // to take the result $o mod lcm(s, a)$. We can replace $lcm(s, a)$ with just a $a / g$. let j = a.wrapping_sub(pmoda) >> gcdpow; let k = smoda >> gcdpow; - return intrinsics::unchecked_rem(j.wrapping_mul(mod_inv(k, a)), a >> gcdpow); + return (j.wrapping_mul(mod_inv(k, a))) & ((a >> gcdpow).wrapping_sub(1)); } // Cannot be aligned at all. |
