Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 6d6c574

Browse files
committed
Fix rotate_left and rotate_right with 128bit shift amount
Fixes rust-lang#1114
1 parent 9443080 commit 6d6c574

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

example/std_example.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ fn main() {
8484
assert_eq!(houndred_i128 as f64, 100.0);
8585
assert_eq!(houndred_f32 as i128, 100);
8686
assert_eq!(houndred_f64 as i128, 100);
87+
assert_eq!(1u128.rotate_left(2), 4);
8788

8889
// Test signed 128bit comparing
8990
let max = usize::MAX as i128;

src/intrinsics/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,11 +632,21 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
632632
};
633633
rotate_left, <T>(v x, v y) {
634634
let layout = fx.layout_of(T);
635+
let y = if fx.bcx.func.dfg.value_type(y) == types::I128 {
636+
fx.bcx.ins().ireduce(types::I64, y)
637+
} else {
638+
y
639+
};
635640
let res = fx.bcx.ins().rotl(x, y);
636641
ret.write_cvalue(fx, CValue::by_val(res, layout));
637642
};
638643
rotate_right, <T>(v x, v y) {
639644
let layout = fx.layout_of(T);
645+
let y = if fx.bcx.func.dfg.value_type(y) == types::I128 {
646+
fx.bcx.ins().ireduce(types::I64, y)
647+
} else {
648+
y
649+
};
640650
let res = fx.bcx.ins().rotr(x, y);
641651
ret.write_cvalue(fx, CValue::by_val(res, layout));
642652
};

0 commit comments

Comments
 (0)