Skip to content
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

Make all integer intrinsics generic #29316

Merged
merged 1 commit into from
Nov 1, 2015
Merged

Make all integer intrinsics generic #29316

merged 1 commit into from
Nov 1, 2015

Conversation

strega-nil
Copy link
Contributor

Similarly to the simd intrinsics. I believe this is a better solution than #29288, and I could implement it as well for overflowing_add/sub/mul. Also rename from udiv/sdiv to div, and same for rem.

@rust-highfive
Copy link
Collaborator

r? @alexcrichton

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

extern "rust-intrinsic" {
/// Performs an unchecked division, resulting in undefined behavior
/// where y = 0 or x = `T::min_value()` and y = -1
pub fn unchecked_div<T>(x: T, y: T) -> T;
Copy link
Member

Choose a reason for hiding this comment

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

I think these can be in the same place they were in above, the #[cfg] should work ok on the functions as well as the block itself.

@strega-nil
Copy link
Contributor Author

@alexcrichton alright, I made the changes you suggested.

@alexcrichton
Copy link
Member

Thanks! Could you also squash to one commit now? Otherwise r=me

@strega-nil
Copy link
Contributor Author

@alexcrichton this has blown up far more. I've replaced all integer intrinsics with generics, and do this same thing with all of them (And added two errors in the process, one for calling bswap with u/i8, and the other is the error you see in this PR).

ast::TyU64 => 64,
};
match c {
"ctlz" => count_zeros_intrinsic(bcx, &format!("llvm.ctlz.i{}", width),
Copy link
Member

Choose a reason for hiding this comment

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

It seems like the int/uint branches here share quite a bit of code, perhaps they could be deduplicated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately no, as they are two different types. The most I could do is unduplicate the target_pointer_width part.

Copy link
Member

Choose a reason for hiding this comment

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

Hm are you sure? It looks like everything is basically duplicated except for unsigned/signed in a few locations which could be a parameter to a shared function? For example the bswap intrinsic has exactly the same code in both branches here.

@strega-nil strega-nil changed the title Check unchecked_div|rem's specialisation Make all integer intrinsics generic Oct 28, 2015
@alexcrichton
Copy link
Member

@GBGamer looks good to me! I'll get the second opinion of someone else on the compilers team, however, as it's probably good to run this past others as well.

cc @rust-lang/compiler

r? @nrc (or anyone else really)

@rust-highfive rust-highfive assigned nrc and unassigned alexcrichton Oct 29, 2015
int_impl! { i8, u8, 8,
intrinsics::add_with_overflow,
intrinsics::sub_with_overflow,
intrinsics::mul_with_overflow }
Copy link
Member

Choose a reason for hiding this comment

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

Since these are all the same, can't the macro just not take them anymore when #[cfg(not(stage0))]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but the macro is 500 lines long. It's better to add it here until we get these into stage0, and then change the macro.

Copy link
Member

Choose a reason for hiding this comment

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

Did not realize that, makes sense.

@eddyb
Copy link
Member

eddyb commented Oct 29, 2015

LGTM modulo nits.

@strega-nil
Copy link
Contributor Author

Alright, I think I've covered all your nits @eddyb?

@eddyb
Copy link
Member

eddyb commented Oct 29, 2015

@bors r+

@bors
Copy link
Contributor

bors commented Oct 29, 2015

📌 Commit 29808c4 has been approved by eddyb

@bors
Copy link
Contributor

bors commented Oct 29, 2015

⌛ Testing commit 29808c4 with merge 10a4130...

@bors
Copy link
Contributor

bors commented Oct 29, 2015

💔 Test failed - auto-linux-64-opt

@strega-nil
Copy link
Contributor Author

Blargh, fixing.

@strega-nil
Copy link
Contributor Author

hopefully fixed :'(

@eddyb
Copy link
Member

eddyb commented Oct 31, 2015

@bors r+

@bors
Copy link
Contributor

bors commented Oct 31, 2015

📌 Commit 93ca0fa has been approved by eddyb

@bors
Copy link
Contributor

bors commented Oct 31, 2015

⌛ Testing commit 93ca0fa with merge 99ac88e...

bors added a commit that referenced this pull request Oct 31, 2015
Similarly to the simd intrinsics. I believe this is a better solution than #29288, and I could implement it as well for overflowing_add/sub/mul. Also rename from udiv/sdiv to div, and same for rem.
@bors
Copy link
Contributor

bors commented Oct 31, 2015

💔 Test failed - auto-mac-32-opt

Similarly to the simd intrinsics.
@strega-nil
Copy link
Contributor Author

alright should be fixed for reals this time :'(

@eddyb
Copy link
Member

eddyb commented Nov 1, 2015

@bors r+

@bors
Copy link
Contributor

bors commented Nov 1, 2015

📌 Commit 579420f has been approved by eddyb

bors added a commit that referenced this pull request Nov 1, 2015
Similarly to the simd intrinsics. I believe this is a better solution than #29288, and I could implement it as well for overflowing_add/sub/mul. Also rename from udiv/sdiv to div, and same for rem.
@bors
Copy link
Contributor

bors commented Nov 1, 2015

⌛ Testing commit 579420f with merge a5fbb3a...

@bors bors mentioned this pull request Nov 1, 2015
@bors bors merged commit 579420f into rust-lang:master Nov 1, 2015
@strega-nil strega-nil deleted the change-unchecked-div-generic branch November 2, 2015 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants