Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upi128 and u128 support #37900
Conversation
rust-highfive
assigned
aturon
Nov 20, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
rust-highfive
Nov 20, 2016
Collaborator
r? @aturon
(rust_highfive has picked a reviewer for you, use r? to override)
|
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
| //! The 128-bit signed integer type. | ||
| //! | ||
| //! *[See also the `i128` primitive type](../../std/primitive.i128.html).* |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
frewsxcv
Nov 20, 2016
Member
This should maybe be:
[See also the `i128` primitive type](../primitive.i128.html)
frewsxcv
Nov 20, 2016
Member
This should maybe be:
[See also the `i128` primitive type](../primitive.i128.html)
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
est31
Nov 20, 2016
Contributor
@frewsxcv I think this wouldn't work. The other integer primitive types link via ../../std/primitive.$name.html as well, and I can't see generated doc files for them in libcore.
est31
Nov 20, 2016
•
Contributor
@frewsxcv I think this wouldn't work. The other integer primitive types link via ../../std/primitive.$name.html as well, and I can't see generated doc files for them in libcore.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ollie27
Nov 20, 2016
Contributor
I think the problem is that the primitive.i128.html isn't being generated at all so changing this won't help.
ollie27
Nov 20, 2016
Contributor
I think the problem is that the primitive.i128.html isn't being generated at all so changing this won't help.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
est31
Nov 20, 2016
Contributor
@ollie27 yes, that is consistent with my observations, I can find primitive.i64.html at the linked path, but none for i128.
est31
Nov 20, 2016
Contributor
@ollie27 yes, that is consistent with my observations, I can find primitive.i64.html at the linked path, but none for i128.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ollie27
Nov 20, 2016
Contributor
Investigate and fix linkcheck failure:
By the looks of it the files won't be generated. You'll need to add entries to src/libstd/primitive_docs.rs and update rustdoc a bit more. At least here and here will need to be updated.
By the looks of it the files won't be generated. You'll need to add entries to |
est31
referenced this pull request
Nov 21, 2016
Closed
rustbuild: linker error during 32 bit compilation #37906
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bors
Nov 21, 2016
Contributor
|
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
aturon
removed their assignment
Nov 22, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
est31
Nov 22, 2016
Contributor
Okay, running on 32 bit into a linker error of the form:
rust/src/librustc_const_math/int.rs:545: Nicht definierter Verweis auf `core::panicking::panic::hdb3be1030a0e450d'
rust/build/i686-unknown-linux-gnu/stage1-rustc/i686-unknown-linux-gnu/release/deps/rustc_const_math-fb45b0b7ff405aab.0.o: In Funktion `rustc_const_math::int::{{impl}}::rem':
rust/src/librustc_const_math/int.rs:577: Nicht definierter Verweis auf `core::panicking::panic::hdb3be1030a0e450d'
/tmp/rustc.8pXinEKP9SgF/libcompiler_builtins-83f89429e0eb597e.rlib(compiler_builtins-83f89429e0eb597e.0.o): In Funktion `compiler_builtins::reimpls::u128_div_mod':
rust/src/libcompiler_builtins/lib.rs:132: Nicht definierter Verweis auf `core::panicking::panic::hdb3be1030a0e450d'
collect2: error: ld returned 1 exit status
Apparently the __udivmodti4 intrinsic may panic. According to readelf, its the only one in the libcompiler_builtin library that calls panic. I've localized the error to the ashl and ashr macros inside the src/libcompiler_builtins/lib.rs file, and the error messages of the panics are "attempt to calculate the remainder with a divisor of zero" and "attempt to divide by zero" (found out with a very reliable and robust method involving a strings invocation and grepping for "rustc version" xD)...
I'm not sure whether or not I should panic here, and how to fix the linker issue if I should indeed panic.
Setting panic=abort for the libcompiler_builtin crate does not remove the panic invocations for some reason, nor the linker failure...
|
Okay, running on 32 bit into a linker error of the form:
Apparently the I'm not sure whether or not I should panic here, and how to fix the linker issue if I should indeed panic. Setting panic=abort for the libcompiler_builtin crate does not remove the panic invocations for some reason, nor the linker failure... |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
eddyb
Nov 22, 2016
Member
@est31 -C panic=abort is a red herring, forget about it, it changes the runtime, not code generation. Sounds like all we have to do is either always compile libcompiler_builtins with -Z force-overflow-checks=off or explicitly use Wrapping and/or wrapping_add etc.
|
@est31 |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bors
Nov 23, 2016
Contributor
|
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mattico
Nov 23, 2016
Contributor
The approach we've used so far in compiler-builtins is to use explicit wrapping operations everywhere. Given that we're mostly translating C code it may make sense to just use -Z force-overflow-checks=off.
Using the Wrapping type is annoying due to #23545 (see https://github.com/rust-lang/rust/blob/master/src/libcore/num/wrapping.rs#L103-L118), so if you want to use Wrapping everywhere you have to do things like x << y.0 as usize where x and y are both Wrapping(_).
cc @japaric
|
The approach we've used so far in compiler-builtins is to use explicit wrapping operations everywhere. Given that we're mostly translating C code it may make sense to just use Using the cc @japaric |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
est31
Nov 23, 2016
Contributor
Progress update: I've been able to eliminate the linker errors by substituting the operations that could fail with unchecked_ versions of them. It makes sense as the C intrinsics do the same and we do the checking afterwards.
I've right now arrived at debugging the functionality of the actual intrinsics themselves... Right now the failure is with the i128 unit tests, when parsing the literals for very large integers, apparently it overflows which it shouldn't.
|
Progress update: I've been able to eliminate the linker errors by substituting the operations that could fail with I've right now arrived at debugging the functionality of the actual intrinsics themselves... Right now the failure is with the i128 unit tests, when parsing the literals for very large integers, apparently it overflows which it shouldn't. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bors
Nov 24, 2016
Contributor
|
|
est31
changed the title from
[WIP] i128 and u128 support
to
i128 and u128 support
Nov 25, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
est31
Nov 25, 2016
Contributor
Okay, the PR is ready for review. I've finished the work on intrinsics and wouldn't know of anything broken or which needs to be done. The tests succeed for both 64 bit and 32 bit platforms.
|
Okay, the PR is ready for review. I've finished the work on intrinsics and wouldn't know of anything broken or which needs to be done. The tests succeed for both 64 bit and 32 bit platforms. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
leonardo-m
Nov 25, 2016
I am quite happy for the future availability of 128 bit numbers in Rust. The "mul_mod" operation is used by "pow_mod" (modular pow), that is sufficiently common:
fn mul_mod(a: u64, b: u64, m: u64) -> (u64, u64);
fn mul_mod(a: u128, b: u128, m: u128) -> (u128, u128);
If you have 128 bits you can perform the 64 bit mul_mod using 128 bit values, but it's more efficient to use the "divq" instruction and work on 64 bit values. And you can probably perform the 128 bit mul_mod more efficiently without 256 bit numbers.
Are you going to support those mul_mod (or something similar), or should this enhancement request be moved elsewhere?
leonardo-m
commented
Nov 25, 2016
•
|
I am quite happy for the future availability of 128 bit numbers in Rust. The "mul_mod" operation is used by "pow_mod" (modular pow), that is sufficiently common:
If you have 128 bits you can perform the 64 bit mul_mod using 128 bit values, but it's more efficient to use the "divq" instruction and work on 64 bit values. And you can probably perform the 128 bit mul_mod more efficiently without 256 bit numbers. Are you going to support those mul_mod (or something similar), or should this enhancement request be moved elsewhere? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
est31
Nov 25, 2016
Contributor
@leonardo-m I think providing modular pow is outside of the scope of this PR. Feel free to open an issue or RFC at https://github.com/rust-lang/rfcs . Also, you might be interested in https://github.com/rust-num/num
|
@leonardo-m I think providing modular pow is outside of the scope of this PR. Feel free to open an issue or RFC at https://github.com/rust-lang/rfcs . Also, you might be interested in https://github.com/rust-num/num |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
leonardo-m
Nov 25, 2016
My suggestion was about mul_mod (not about pow_mod), and I think it needs a low-level implementation with intrinsics or asm to be efficient. I'll probably open an issue here.
leonardo-m
commented
Nov 25, 2016
•
|
My suggestion was about mul_mod (not about pow_mod), and I think it needs a low-level implementation with intrinsics or asm to be efficient. I'll probably open an issue here. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
r? @eddyb (feel free to transfer) |
rust-highfive
assigned
eddyb
Nov 25, 2016
eddyb
added
the
S-waiting-on-crater
label
Nov 27, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Started crater run. |
eddyb
reviewed
Nov 28, 2016
LGTM, only 2 minor nits. I assume FIXMEs are left for later.
| }); | ||
| let const_err = common::const_to_opt_u128(len, false) | ||
| .and_then(|len| common::const_to_opt_u128(index, false) | ||
| .map(|index| ErrKind::IndexOutOfBounds { |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nagisa
Nov 28, 2016
Contributor
Currently we do not have any platform that supports isize larger than i64 so its not really important. Would be good to add a FIXME, though.
nagisa
Nov 28, 2016
Contributor
Currently we do not have any platform that supports isize larger than i64 so its not really important. Would be good to add a FIXME, though.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
est31
Nov 28, 2016
Contributor
The index is assured by typecheck to be usize and therefore can't exceed the range of 64 bits, can it? Would it be an idea to re-add const_to_opt_uint for cases like this and the one you mentioned above?
est31
Nov 28, 2016
Contributor
The index is assured by typecheck to be usize and therefore can't exceed the range of 64 bits, can it? Would it be an idea to re-add const_to_opt_uint for cases like this and the one you mentioned above?
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
est31
Nov 28, 2016
Contributor
Hmm, the function was removed because it would cause bad behaviour in cross compilation situations...
I guess I'll add a const_to_opt_u64 function instead, as there are no 128 bit targets nor hosts neither in existence nor on the horizon.
est31
Nov 28, 2016
Contributor
Hmm, the function was removed because it would cause bad behaviour in cross compilation situations...
I guess I'll add a const_to_opt_u64 function instead, as there are no 128 bit targets nor hosts neither in existence nor on the horizon.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
eddyb
Nov 28, 2016
Member
Oh, the assumption that pointers are always 64-bit or less is interesting (but not explicit?). The code is fine as-is in that case.
eddyb
Nov 28, 2016
Member
Oh, the assumption that pointers are always 64-bit or less is interesting (but not explicit?). The code is fine as-is in that case.
| @@ -281,7 +281,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { | ||
| mir::TerminatorKind::Assert { ref cond, expected, ref msg, target, cleanup } => { | ||
| let cond = self.trans_operand(&bcx, cond).immediate(); | ||
| let mut const_cond = common::const_to_opt_uint(cond).map(|c| c == 1); | ||
| let mut const_cond = common::const_to_opt_u128(cond, false).map(|c| c == 1); |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
eddyb
Nov 28, 2016
Member
Heh, this only wants one bit (cond has type i1). Not sure if there's a nicer way to do this though.
eddyb
Nov 28, 2016
Member
Heh, this only wants one bit (cond has type i1). Not sure if there's a nicer way to do this though.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
est31
Nov 28, 2016
Contributor
There is none without re-adding const_to_opt_uint and you agreed on IRC that that shouldn't be done.
est31
Nov 28, 2016
•
Contributor
There is none without re-adding const_to_opt_uint and you agreed on IRC that that shouldn't be done.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
rebased. ping @eddyb |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bors
Nov 30, 2016
Contributor
|
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
brson
Nov 30, 2016
Contributor
Crater's been having a hard time lately. Latest run failed again. I'm trying again.
|
Crater's been having a hard time lately. Latest run failed again. I'm trying again. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bors
Nov 30, 2016
Contributor
|
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
est31
Dec 1, 2016
Contributor
Seems I'm running into a problem here...
When attempting to rebase this PR from basing on 5a02480 to base on dc81742 (compare changes), I can't bootstrap it anymore.
The error I'm running into (note its with stage0 still used as compiler so its not fault of this PR!) seems like a genuine zombie issue, a revival of issue #37686. Its fix (commit 84239df) is only present on the master branch, but not on the beta branch (at least not on the beta branch of commit d4aea2d on which the new bootstrap compiler as of #37800 bases on).
I'd like to hear your opinions on how to resolve this issue. I'm almost certain that other PRs in the future will run into this problem as well.
|
Seems I'm running into a problem here... When attempting to rebase this PR from basing on 5a02480 to base on dc81742 (compare changes), I can't bootstrap it anymore. The error I'm running into (note its with stage0 still used as compiler so its not fault of this PR!) seems like a genuine zombie issue, a revival of issue #37686. Its fix (commit 84239df) is only present on the master branch, but not on the beta branch (at least not on the beta branch of commit d4aea2d on which the new bootstrap compiler as of #37800 bases on). I'd like to hear your opinions on how to resolve this issue. I'm almost certain that other PRs in the future will run into this problem as well. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
est31
Dec 1, 2016
Contributor
Note: you can reproduce the issue on current master by doing ./x.py test --stage 0 src/test/run-pass --test-args 37686.
|
Note: you can reproduce the issue on current master by doing |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
est31
Dec 1, 2016
Contributor
Okay, figured out how to workaround the issue, see the last commit. So its not required anymore for this PR to get stage0 updated.
|
Okay, figured out how to workaround the issue, see the last commit. So its not required anymore for this PR to get |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Still working on crater. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
brson
Dec 2, 2016
Contributor
My crater run failed because nightly cargo is broken. I think we have to wait until nightly cargo works again.
|
My crater run failed because nightly cargo is broken. I think we have to wait until nightly cargo works again. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bors
Dec 3, 2016
Contributor
|
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bors
Dec 3, 2016
Contributor
|
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Crater report shows a single regression (from changing the AST). @bors r+ |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
|
eddyb
removed
the
S-waiting-on-crater
label
Dec 4, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nagisa
and others
added some commits
Sep 27, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Rebased. r? @eddyb |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
leonardo-m
commented
Dec 15, 2016
|
Keep going! :-) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
est31
Dec 15, 2016
Contributor
Release is close, and this may cause regressions. It'd be better to have it at the start of a release period, not that it gets reverted before release because of the regressions it caused. Gonna reopen once the release is over.
|
Release is close, and this may cause regressions. It'd be better to have it at the start of a release period, not that it gets reverted before release because of the regressions it caused. Gonna reopen once the release is over. |
est31
closed this
Dec 15, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
See #38482 for the continuation |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
And #37900 was such a rememberable number too |
est31 commentedNov 20, 2016
•
edited
Edited 1 time
-
est31
edited Nov 25, 2016 (most recent)
Adds support for 128-bit integers. Rebased version of #35954 , with additional improvements.
Thanks @nagisa for mentoring this PR!
Some of the problems that were resolved:
Confirm that intrinsics work on 32 bit platforms and fix them if needed
Wait for #37906 to get fixed, so that work on intrinsics can be completed (worked around by merging the PR on my local setup)
Investigate and fix linkcheck failure
[plugin-breaking-change]
cc #35118