Implemente overflowing_sh* with new unchecked_sh* intrinsics by TimNN · Pull Request #40521 · rust-lang/rust (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation18 Commits2 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

TimNN

Also update some 128 bit builtins to not rely on the constant evaluator to avoid checked operations.

Fixes #40508.

cc @nagisa, @alexcrichton

Note: I still have a build running to see if the 128 bit changes worked (unoptimized builds take forever to compile), however at least the overflowing builtins no longer reference core::panicking::panic.

@rust-highfive

r? @aturon

(rust_highfive has picked a reviewer for you, use r? to override)

nagisa

@@ -311,6 +311,8 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
} else {
bcx.urem(llargs[0], llargs[1])
},
"unchecked_shl" => bcx.shl(llargs[0], llargs[1]),
"unchecked_shr" => bcx.lshr(llargs[0], llargs[1]),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be either ashr when types are signed or lshr when types are unsigned.

See for example the rustc_trans::common::build_unchecked_rshift (you can’t reuse it sadly, because it tries to ensure the validity of RHS).

#[cfg(not(stage0))]
pub fn overflowing_shl(self, rhs: u32) -> (Self, bool) {
(unsafe {
intrinsics::unchecked_shl(self, (rhs & ($BITS - 1)) as $SelfT)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you’re already working around this code, it would be nice if you used this to implement wrapping_shl and used wrapping_shl to implement overflowing_shl instead of the inverse that we have today.

@@ -83,8 +83,8 @@ pub mod reimpls {
macro_rules! lshr {
($a: expr, b:expr,b: expr, b:expr,ty:ty) => {{
let (a, b) = ($a, $b);
let bits = (::core::mem::size_of::<$ty>() * 8) as $ty;
let half_bits = bits >> 1;
let bits = ::core::mem::size_of::<$ty>().overflowing_mul(8) as $ty;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/overflowing/wrapping/?

@nagisa

@alexcrichton

@bors r=nagisa delegate=nagisa

@bors

✌️ @nagisa can now approve this pull request

@bors

📌 Commit ceccedd has been approved by nagisa

@TimNN

I missed one of the i128 macros :(

Maybe leave this PR until tomorrow, I'll have a full unoptimized ARM build done by then to verify that actually all occurrences of panic are gone.

@TimNN

Good news! readelf no longer shows any references to panic. However run-pass/issue-28950.rs hanges somewhere, but I think that is a separate issue, so this is probably good to go to bors.

(The travis failure is about the mac bots being... broken.)

Do you want me to squash the commits?

@nagisa

@TimNN

Also update some 128 bit builtins to be panic-free without relying on the const evaluator.

@TimNN

Sure.

I assume this was regarding the squash? In that case: Done.

@nagisa

@bors

📌 Commit cc23d17 has been approved by nagisa

@est31 est31 mentioned this pull request

Mar 16, 2017

frewsxcv added a commit to frewsxcv/rust that referenced this pull request

Mar 17, 2017

@frewsxcv

Implemente overflowing_sh* with new unchecked_sh* intrinsics

Also update some 128 bit builtins to not rely on the constant evaluator to avoid checked operations.

Fixes rust-lang#40508.

cc @nagisa, @alexcrichton

Note: I still have a build running to see if the 128 bit changes worked (unoptimized builds take forever to compile), however at least the overflowing builtins no longer reference core::panicking::panic.

frewsxcv added a commit to frewsxcv/rust that referenced this pull request

Mar 17, 2017

@frewsxcv

Implemente overflowing_sh* with new unchecked_sh* intrinsics

Also update some 128 bit builtins to not rely on the constant evaluator to avoid checked operations.

Fixes rust-lang#40508.

cc @nagisa, @alexcrichton

Note: I still have a build running to see if the 128 bit changes worked (unoptimized builds take forever to compile), however at least the overflowing builtins no longer reference core::panicking::panic.

frewsxcv added a commit to frewsxcv/rust that referenced this pull request

Mar 17, 2017

@frewsxcv

Implemente overflowing_sh* with new unchecked_sh* intrinsics

Also update some 128 bit builtins to not rely on the constant evaluator to avoid checked operations.

Fixes rust-lang#40508.

cc @nagisa, @alexcrichton

Note: I still have a build running to see if the 128 bit changes worked (unoptimized builds take forever to compile), however at least the overflowing builtins no longer reference core::panicking::panic.

@alexcrichton

@bors: r-

This is likely the cause of this failure, I think maybe the methods just need to be #[inline]?

@TimNN

@TimNN

I have added the additional inline attributes and verified that this fixes the issue for i686-gnu.

@alexcrichton

@bors

📌 Commit e16d286 has been approved by alexcrichton

arielb1 pushed a commit to arielb1/rust that referenced this pull request

Mar 18, 2017

Implemente overflowing_sh* with new unchecked_sh* intrinsics

Also update some 128 bit builtins to not rely on the constant evaluator to avoid checked operations.

Fixes rust-lang#40508.

cc @nagisa, @alexcrichton

Note: I still have a build running to see if the 128 bit changes worked (unoptimized builds take forever to compile), however at least the overflowing builtins no longer reference core::panicking::panic.

bors added a commit that referenced this pull request

Mar 18, 2017

@bors

Rollup of 22 pull requests

arielb1 pushed a commit to arielb1/rust that referenced this pull request

Mar 19, 2017

Implemente overflowing_sh* with new unchecked_sh* intrinsics

Also update some 128 bit builtins to not rely on the constant evaluator to avoid checked operations.

Fixes rust-lang#40508.

cc @nagisa, @alexcrichton

Note: I still have a build running to see if the 128 bit changes worked (unoptimized builds take forever to compile), however at least the overflowing builtins no longer reference core::panicking::panic.

frewsxcv added a commit to frewsxcv/rust that referenced this pull request

Mar 20, 2017

@frewsxcv

Implemente overflowing_sh* with new unchecked_sh* intrinsics

Also update some 128 bit builtins to not rely on the constant evaluator to avoid checked operations.

Fixes rust-lang#40508.

cc @nagisa, @alexcrichton

Note: I still have a build running to see if the 128 bit changes worked (unoptimized builds take forever to compile), however at least the overflowing builtins no longer reference core::panicking::panic.

bors added a commit that referenced this pull request

Mar 20, 2017

@bors

@TimNN TimNN deleted the panic-free-shift branch

April 7, 2017 20:14