i128 and u128 support by est31 · Pull Request #37900 · rust-lang/rust

· GitHub

3 min read Original article ↗

frewsxcv

@est31 est31 mentioned this pull request

Nov 21, 2016

@est31

@est31

@est31

@est31

nagisa

@est31

@est31 est31 changed the title [WIP] i128 and u128 support i128 and u128 support

Nov 25, 2016

@est31

@est31

just as ceil(log10(2^64)) == 20
Current stage0 with version "1.14.0-beta.1 (d4aea2d 2016-11-15)"
suffers from issue 37686. You can confirm this on master by running

./x.py test --stage 0 src/test/run-pass --test-args 37686

Add this workaround until there is a fix. No idea how it works,
but it does work.
The check inside compiler-rt file int_types.h to #define CRT_HAS_128BIT
looks like:

 #if (defined(__LP64__) || defined(__wasm__)) && \
     !(defined(__mips__) && defined(__clang__))
 #define CRT_HAS_128BIT
 #endif

Windows uses LLP64 instead of LP64, so it doesn't ship with the C based
intrinsics.

Also, add libcompiler_builtins to the list of crates that may have platform
specific checks (like the ones we just added).
* shift so that no panics are generated (otherwise results in linker error)
* no_std as insurance to not get into issues with errors like "cannot satisfy dependencies so `rustc_i128` only shows up once" (pure guessing here, but it doesn't hurt...)
There was a linker error on 32 bit platforms with optimisations turned off,
complaining that there was an undefined reference to "rust_eh_personality",
when compiling the rustc_const_math as stage1 artifact.

Apparently the compiler_builtins crate includes a call to "rust_eh_personality".
If compiled for 64 bits, this call doesn't appear, which explains why the linker
error only happens on 32 bit platforms, and optimisations will get it removed
on 32 bit as well.

There were two origins of the call:
    1. A for loop where apparently the compiler wasn't sure
       whether next() could panic or not, and therefore generated a landing
       pad for the worst case. The minimal reproducible example is "for _ in 0..sr { }".
    2. A default impl of uabs where the compiler apparently wasn't sure either
       whether iabs() could panic or not. Many thanks to nagisa for
       contributing the fix.

This commit also puts extern "C" to the intrinsics, as this is generally a
good thing to do.

@est31

Otherwise, we codegen panic calls which create problems with debug assertions turned on.

@est31

@est31

@est31

...this time with the float intrinsics.

@est31

@est31

@est31 est31 mentioned this pull request

Dec 20, 2016

bors added a commit that referenced this pull request

Dec 31, 2016
i128 and u128 support

Brings i128 and u128 support to nightly rust, behind a feature flag. The goal of this PR is to do the bulk of the work for 128 bit integer support. Smaller but just as tricky features needed for stabilisation like 128 bit enum discriminants are left for future PRs.

Rebased version of  #37900, which in turn was a rebase + improvement of #35954 . Sadly I couldn't reopen #37900 due to github. There goes my premium position in the homu queue...

[plugin-breaking-change]

cc #35118 (tracking issue)