Remove shift amount masking
Unlike the old x75 backend, the new x64 backend masks the shift amount itself, matching the specified semantics.
This commit is contained in:
parent
4f45ea73ef
commit
c5f98b586f
26
src/num.rs
26
src/num.rs
@ -168,20 +168,12 @@ pub(crate) fn codegen_int_binop<'tcx>(
|
|||||||
BinOp::BitXor => b.bxor(lhs, rhs),
|
BinOp::BitXor => b.bxor(lhs, rhs),
|
||||||
BinOp::BitAnd => b.band(lhs, rhs),
|
BinOp::BitAnd => b.band(lhs, rhs),
|
||||||
BinOp::BitOr => b.bor(lhs, rhs),
|
BinOp::BitOr => b.bor(lhs, rhs),
|
||||||
BinOp::Shl => {
|
BinOp::Shl => fx.bcx.ins().ishl(lhs, rhs),
|
||||||
let lhs_ty = fx.bcx.func.dfg.value_type(lhs);
|
|
||||||
let actual_shift = fx.bcx.ins().band_imm(rhs, i64::from(lhs_ty.bits() - 1));
|
|
||||||
let actual_shift = clif_intcast(fx, actual_shift, types::I8, false);
|
|
||||||
fx.bcx.ins().ishl(lhs, actual_shift)
|
|
||||||
}
|
|
||||||
BinOp::Shr => {
|
BinOp::Shr => {
|
||||||
let lhs_ty = fx.bcx.func.dfg.value_type(lhs);
|
|
||||||
let actual_shift = fx.bcx.ins().band_imm(rhs, i64::from(lhs_ty.bits() - 1));
|
|
||||||
let actual_shift = clif_intcast(fx, actual_shift, types::I8, false);
|
|
||||||
if signed {
|
if signed {
|
||||||
fx.bcx.ins().sshr(lhs, actual_shift)
|
fx.bcx.ins().sshr(lhs, rhs)
|
||||||
} else {
|
} else {
|
||||||
fx.bcx.ins().ushr(lhs, actual_shift)
|
fx.bcx.ins().ushr(lhs, rhs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Compare binops handles by `codegen_binop`.
|
// Compare binops handles by `codegen_binop`.
|
||||||
@ -303,10 +295,7 @@ pub(crate) fn codegen_checked_int_binop<'tcx>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
BinOp::Shl => {
|
BinOp::Shl => {
|
||||||
let lhs_ty = fx.bcx.func.dfg.value_type(lhs);
|
let val = fx.bcx.ins().ishl(lhs, rhs);
|
||||||
let actual_shift = fx.bcx.ins().band_imm(rhs, i64::from(lhs_ty.bits() - 1));
|
|
||||||
let actual_shift = clif_intcast(fx, actual_shift, types::I8, false);
|
|
||||||
let val = fx.bcx.ins().ishl(lhs, actual_shift);
|
|
||||||
let ty = fx.bcx.func.dfg.value_type(val);
|
let ty = fx.bcx.func.dfg.value_type(val);
|
||||||
let max_shift = i64::from(ty.bits()) - 1;
|
let max_shift = i64::from(ty.bits()) - 1;
|
||||||
let has_overflow = fx
|
let has_overflow = fx
|
||||||
@ -316,13 +305,10 @@ pub(crate) fn codegen_checked_int_binop<'tcx>(
|
|||||||
(val, has_overflow)
|
(val, has_overflow)
|
||||||
}
|
}
|
||||||
BinOp::Shr => {
|
BinOp::Shr => {
|
||||||
let lhs_ty = fx.bcx.func.dfg.value_type(lhs);
|
|
||||||
let actual_shift = fx.bcx.ins().band_imm(rhs, i64::from(lhs_ty.bits() - 1));
|
|
||||||
let actual_shift = clif_intcast(fx, actual_shift, types::I8, false);
|
|
||||||
let val = if !signed {
|
let val = if !signed {
|
||||||
fx.bcx.ins().ushr(lhs, actual_shift)
|
fx.bcx.ins().ushr(lhs, rhs)
|
||||||
} else {
|
} else {
|
||||||
fx.bcx.ins().sshr(lhs, actual_shift)
|
fx.bcx.ins().sshr(lhs, rhs)
|
||||||
};
|
};
|
||||||
let ty = fx.bcx.func.dfg.value_type(val);
|
let ty = fx.bcx.func.dfg.value_type(val);
|
||||||
let max_shift = i64::from(ty.bits()) - 1;
|
let max_shift = i64::from(ty.bits()) - 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user