]> git.lizzy.rs Git - rust.git/commitdiff
Fix rotate_left and rotate_right with 128bit shift amount
authorbjorn3 <bjorn3@users.noreply.github.com>
Fri, 16 Apr 2021 12:02:57 +0000 (14:02 +0200)
committerbjorn3 <bjorn3@users.noreply.github.com>
Fri, 16 Apr 2021 12:08:10 +0000 (14:08 +0200)
Fixes #1114

example/std_example.rs
src/intrinsics/mod.rs

index 015bbdfed4648ee106cb18d47f2e7217d7f30cd9..437b7726980bf02633868fc6f359ccf13cd64643 100644 (file)
@@ -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;
index d08271f853b50eb62d63e2ab4de882ce53d7ec25..c42ad4337c1f2ee10cbd642d5e1eeb2cff9d454f 100644 (file)
@@ -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));
         };