Skip to content

Commit 63fde15

Browse files
committed
Fix cg_clif implementation
1 parent 3e9b6bd commit 63fde15

File tree

1 file changed

+12
-14
lines changed
  • compiler/rustc_codegen_cranelift/src/intrinsics

1 file changed

+12
-14
lines changed

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
659659
intrinsic_args!(fx, args => (x, y, z); intrinsic);
660660
let layout = x.layout();
661661

662-
let width_bits = layout.size.bits() as u64;
663-
let width_bits = fx.bcx.ins().iconst(types::I32, width_bits as i64);
662+
let width_bits = layout.size.bits() as i64;
664663

665664
let lhs_bits = x.load_scalar(fx);
666665
let rhs_bits = y.load_scalar(fx);
@@ -669,17 +668,17 @@ fn codegen_regular_intrinsic_call<'tcx>(
669668
let ty = fx.bcx.func.dfg.value_type(lhs_bits);
670669
let zero = fx.bcx.ins().iconst(ty, 0);
671670

672-
let shift_bits = fx.bcx.ins().urem(raw_shift_bits, width_bits);
671+
let shift_bits = fx.bcx.ins().band_imm(raw_shift_bits, width_bits - 1);
673672

674673
// lhs_bits << shift_bits
675674
let shl = fx.bcx.ins().ishl(lhs_bits, shift_bits);
676675

677-
let inv_shift_bits = fx.bcx.ins().isub(width_bits, shift_bits);
676+
let inv_shift_bits = fx.bcx.ins().irsub_imm(shift_bits, width_bits);
678677

679-
// rhs_bits.bounded_shr(inv_shift_bits)
680-
let inv_shift_bits_mod = fx.bcx.ins().urem(inv_shift_bits, width_bits);
678+
// rhs_bits.unbounded_shr(inv_shift_bits)
679+
let inv_shift_bits_mod = fx.bcx.ins().band_imm(inv_shift_bits, width_bits - 1);
681680
let shr = fx.bcx.ins().ushr(rhs_bits, inv_shift_bits_mod);
682-
let is_zero = fx.bcx.ins().icmp(IntCC::Equal, inv_shift_bits_mod, zero);
681+
let is_zero = fx.bcx.ins().icmp_imm(IntCC::Equal, shift_bits, 0);
683682
let shr = fx.bcx.ins().select(is_zero, zero, shr);
684683

685684
let res = fx.bcx.ins().bor(shr, shl);
@@ -689,8 +688,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
689688
intrinsic_args!(fx, args => (x, y, z); intrinsic);
690689
let layout = x.layout();
691690

692-
let width_bits = layout.size.bits() as u64;
693-
let width_bits = fx.bcx.ins().iconst(types::I32, width_bits as i64);
691+
let width_bits = layout.size.bits() as i64;
694692

695693
let lhs_bits = x.load_scalar(fx);
696694
let rhs_bits = y.load_scalar(fx);
@@ -699,17 +697,17 @@ fn codegen_regular_intrinsic_call<'tcx>(
699697
let ty = fx.bcx.func.dfg.value_type(lhs_bits);
700698
let zero = fx.bcx.ins().iconst(ty, 0);
701699

702-
let shift_bits = fx.bcx.ins().urem(raw_shift_bits, width_bits);
700+
let shift_bits = fx.bcx.ins().band_imm(raw_shift_bits, width_bits - 1);
703701

704702
// rhs_bits >> shift_bits
705703
let shr = fx.bcx.ins().ushr(rhs_bits, shift_bits);
706704

707-
let inv_shift_bits = fx.bcx.ins().isub(width_bits, shift_bits);
705+
let inv_shift_bits = fx.bcx.ins().irsub_imm(shift_bits, width_bits);
708706

709-
// lhs_bits.bounded_shl(inv_shift_bits)
710-
let inv_shift_bits_mod = fx.bcx.ins().urem(inv_shift_bits, width_bits);
707+
// lhs_bits.unbounded_shl(inv_shift_bits)
708+
let inv_shift_bits_mod = fx.bcx.ins().band_imm(inv_shift_bits, width_bits - 1);
711709
let shl = fx.bcx.ins().ishl(lhs_bits, inv_shift_bits_mod);
712-
let is_zero = fx.bcx.ins().icmp(IntCC::Equal, inv_shift_bits_mod, zero);
710+
let is_zero = fx.bcx.ins().icmp_imm(IntCC::Equal, shift_bits, 0);
713711
let shl = fx.bcx.ins().select(is_zero, zero, shl);
714712

715713
let res = fx.bcx.ins().bor(shr, shl);

0 commit comments

Comments
 (0)