diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2021-04-16 14:02:57 +0200 |
|---|---|---|
| committer | bjorn3 <bjorn3@users.noreply.github.com> | 2021-04-16 14:08:10 +0200 |
| commit | 6d6c5742896fab93788b4dabb6ba2fcf1881f5e2 (patch) | |
| tree | 3a7b905b8509a262f393e1485a0e94c3294e676f | |
| parent | 944308089f4cc8f1384df80d00f735609358e550 (diff) | |
| download | rust-6d6c5742896fab93788b4dabb6ba2fcf1881f5e2.tar.gz rust-6d6c5742896fab93788b4dabb6ba2fcf1881f5e2.zip | |
Fix rotate_left and rotate_right with 128bit shift amount
Fixes #1114
| -rw-r--r-- | example/std_example.rs | 1 | ||||
| -rw-r--r-- | src/intrinsics/mod.rs | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/example/std_example.rs b/example/std_example.rs index 015bbdfed46..437b7726980 100644 --- a/example/std_example.rs +++ b/example/std_example.rs @@ -84,6 +84,7 @@ fn main() { assert_eq!(houndred_i128 as f64, 100.0); assert_eq!(houndred_f32 as i128, 100); assert_eq!(houndred_f64 as i128, 100); + assert_eq!(1u128.rotate_left(2), 4); // Test signed 128bit comparing let max = usize::MAX as i128; diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index d08271f853b..c42ad4337c1 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -632,11 +632,21 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( }; rotate_left, <T>(v x, v y) { let layout = fx.layout_of(T); + let y = if fx.bcx.func.dfg.value_type(y) == types::I128 { + fx.bcx.ins().ireduce(types::I64, y) + } else { + y + }; let res = fx.bcx.ins().rotl(x, y); ret.write_cvalue(fx, CValue::by_val(res, layout)); }; rotate_right, <T>(v x, v y) { let layout = fx.layout_of(T); + let y = if fx.bcx.func.dfg.value_type(y) == types::I128 { + fx.bcx.ins().ireduce(types::I64, y) + } else { + y + }; let res = fx.bcx.ins().rotr(x, y); ret.write_cvalue(fx, CValue::by_val(res, layout)); }; |
