Skip to content

Support 128bit numbers #627

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

Merged
merged 26 commits into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 40 additions & 40 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ gimli = { git = "https://github.com/gimli-rs/gimli.git" }
indexmap = "1.0.2"
object = "0.12.0"

[patch."https://github.com/CraneStation/cranelift.git"]
cranelift = { git = "https://github.com/bjorn3/cretonne.git", branch = "do_not_remove_cg_clif_i128" }
cranelift-module = { git = "https://github.com/bjorn3/cretonne.git", branch = "do_not_remove_cg_clif_i128" }
cranelift-simplejit = { git = "https://github.com/bjorn3/cretonne.git", branch = "do_not_remove_cg_clif_i128" }
cranelift-faerie = { git = "https://github.com/bjorn3/cretonne.git", branch = "do_not_remove_cg_clif_i128" }

# Uncomment to use local checkout of cranelift
#[patch."https://github.com/CraneStation/cranelift.git"]
#cranelift = { path = "../cranelift/cranelift-umbrella" }
Expand Down
3 changes: 1 addition & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ $ RUSTFLAGS="-Cpanic=abort -Zcodegen-backend=$cg_clif_dir/target/debug/librustc_

## Not yet supported

* Good non-rust abi support ([scalar pair and vector are passed by-ref](https://github.com/bjorn3/rustc_codegen_cranelift/issues/10))
* Good non-rust abi support ([vectors are passed by-ref](https://github.com/bjorn3/rustc_codegen_cranelift/issues/10))
* Checked binops ([some missing instructions in cranelift](https://github.com/CraneStation/cranelift/issues/460))
* Inline assembly ([no cranelift support](https://github.com/CraneStation/cranelift/issues/444))
* u128 and i128 ([no cranelift support](https://github.com/CraneStation/cranelift/issues/354))
* SIMD ([tracked here](https://github.com/bjorn3/rustc_codegen_cranelift/issues/171))

## Troubleshooting
Expand Down
1 change: 0 additions & 1 deletion build_sysroot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ alloc_system = { path = "./alloc_system" }
[patch.crates-io]
rustc-std-workspace-core = { path = "./sysroot_src/src/tools/rustc-std-workspace-core" }
rustc-std-workspace-alloc = { path = "./rustc-std-workspace-alloc" }
compiler_builtins = { path = "./compiler_builtins" }

[profile.release]
debug = true
Expand Down
20 changes: 0 additions & 20 deletions build_sysroot/compiler_builtins/Cargo.toml

This file was deleted.

9 changes: 0 additions & 9 deletions build_sysroot/compiler_builtins/lib.rs

This file was deleted.

48 changes: 48 additions & 0 deletions example/mini_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ impl Add for u8 {
}
}

impl Add for i8 {
type Output = Self;

fn add(self, rhs: Self) -> Self {
self + rhs
}
}

impl Add for usize {
type Output = Self;

Expand All @@ -151,6 +159,30 @@ impl Sub for usize {
}
}

impl Sub for u8 {
type Output = Self;

fn sub(self, rhs: Self) -> Self {
self - rhs
}
}

impl Sub for i8 {
type Output = Self;

fn sub(self, rhs: Self) -> Self {
self - rhs
}
}

impl Sub for i16 {
type Output = Self;

fn sub(self, rhs: Self) -> Self {
self - rhs
}
}

#[lang = "bitor"]
pub trait BitOr<RHS = Self> {
type Output;
Expand Down Expand Up @@ -270,6 +302,22 @@ pub trait Neg {
fn neg(self) -> Self::Output;
}

impl Neg for i8 {
type Output = i8;

fn neg(self) -> i8 {
-self
}
}

impl Neg for i16 {
type Output = i16;

fn neg(self) -> i16 {
self
}
}

impl Neg for isize {
type Output = isize;

Expand Down
13 changes: 13 additions & 0 deletions example/std_example.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![feature(core_intrinsics)]

use std::io::Write;
use std::intrinsics;

fn main() {
let _ = ::std::iter::repeat('a' as u8).take(10).collect::<Vec<_>>();
Expand Down Expand Up @@ -29,6 +30,18 @@ fn main() {
println!("{}", 2.3f32.ceil());
println!("{}", 2.3f32.min(1.0));
println!("{}", 2.3f32.max(1.0));

assert_eq!(0b0000000000000000000000000010000010000000000000000000000000000000_0000000000100000000000000000000000001000000000000100000000000000u128.leading_zeros(), 26);
assert_eq!(0b0000000000000000000000000010000000000000000000000000000000000000_0000000000000000000000000000000000001000000000000000000010000000u128.trailing_zeros(), 7);

0i128.checked_div(2i128);
0u128.checked_div(2u128);
assert_eq!(1u128 + 2, 3);

assert_eq!(0b100010000000000000000000000000000u128 >> 10, 0b10001000000000000000000u128);
assert_eq!(0xFEDCBA987654321123456789ABCDEFu128 >> 64, 0xFEDCBA98765432u128);
assert_eq!(0xFEDCBA987654321123456789ABCDEFu128 as i128 >> 64, 0xFEDCBA98765432i128);
assert_eq!(353985398u128 * 932490u128, 330087843781020u128);
}

#[derive(PartialEq)]
Expand Down
Loading