Rename amt variables to shift

This commit is contained in:
Oliver Schneider 2018-05-24 14:20:45 +02:00
parent 5c8741f32e
commit 85de4efdd8
6 changed files with 22 additions and 22 deletions

View File

@ -1910,8 +1910,8 @@ pub fn print_miri_value<W: Write>(value: Value, ty: Ty, f: &mut W) -> fmt::Resul
let ty = tcx.lift_to_global(&ty).unwrap();
tcx.layout_of(ty::ParamEnv::empty().and(ty)).unwrap().size.bits()
});
let amt = 128 - bit_width;
write!(f, "{:?}{}", ((bits as i128) << amt) >> amt, i)
let shift = 128 - bit_width;
write!(f, "{:?}{}", ((bits as i128) << shift) >> shift, i)
},
(Value::Scalar(Scalar::Bits { bits, .. }), &TyChar) =>
write!(f, "{:?}", ::std::char::from_u32(bits as u32).unwrap()),

View File

@ -1827,8 +1827,8 @@ impl<'tcx> Const<'tcx> {
let size = tcx.layout_of(ty).unwrap_or_else(|e| {
panic!("could not compute layout for {:?}: {:?}", ty, e)
}).size;
let amt = 128 - size.bits();
let truncated = (bits << amt) >> amt;
let shift = 128 - size.bits();
let truncated = (bits << shift) >> shift;
assert_eq!(truncated, bits, "from_bits called with untruncated value");
Self::from_scalar(tcx, Scalar::Bits { bits, defined: size.bits() as u8 }, ty.value)
}

View File

@ -68,14 +68,14 @@ impl<'tcx> Discr<'tcx> {
};
let bit_size = int.size().bits();
let amt = 128 - bit_size;
let shift = 128 - bit_size;
if signed {
let sext = |u| {
let i = u as i128;
(i << amt) >> amt
(i << shift) >> shift
};
let min = sext(1_u128 << (bit_size - 1));
let max = i128::max_value() >> amt;
let max = i128::max_value() >> shift;
let val = sext(self.val);
assert!(n < (i128::max_value() as u128));
let n = n as i128;
@ -87,13 +87,13 @@ impl<'tcx> Discr<'tcx> {
};
// zero the upper bits
let val = val as u128;
let val = (val << amt) >> amt;
let val = (val << shift) >> shift;
(Self {
val: val as u128,
ty: self.ty,
}, oflo)
} else {
let max = u128::max_value() >> amt;
let max = u128::max_value() >> shift;
let val = self.val;
let oflo = val > max - n;
let val = if oflo {

View File

@ -158,9 +158,9 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
let trunc = |n| {
let param_ty = self.param_env.and(self.tcx.lift_to_global(&ty).unwrap());
let bit_width = self.tcx.layout_of(param_ty).unwrap().size.bits();
trace!("trunc {} with size {} and amt {}", n, bit_width, 128 - bit_width);
let amt = 128 - bit_width;
let result = (n << amt) >> amt;
trace!("trunc {} with size {} and shift {}", n, bit_width, 128 - bit_width);
let shift = 128 - bit_width;
let result = (n << shift) >> shift;
trace!("trunc result: {}", result);
ConstValue::Scalar(Scalar::Bits {
bits: result,

View File

@ -930,17 +930,17 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
let i = raw_discr.to_bits(discr.size)? as i128;
// going from layout tag type to typeck discriminant type
// requires first sign extending with the layout discriminant
let amt = 128 - discr.size.bits();
let sexted = (i << amt) >> amt;
let shift = 128 - discr.size.bits();
let sexted = (i << shift) >> shift;
// and then zeroing with the typeck discriminant type
let discr_ty = ty
.ty_adt_def().expect("tagged layout corresponds to adt")
.repr
.discr_type();
let discr_ty = layout::Integer::from_attr(self.tcx.tcx, discr_ty);
let amt = 128 - discr_ty.size().bits();
let shift = 128 - discr_ty.size().bits();
let truncatee = sexted as u128;
(truncatee << amt) >> amt
(truncatee << shift) >> shift
} else {
raw_discr.to_bits(discr.size)?
}
@ -1005,8 +1005,8 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
// their computation, but the in-memory tag is the smallest possible
// representation
let size = tag.value.size(self.tcx.tcx).bits();
let amt = 128 - size;
let discr_val = (discr_val << amt) >> amt;
let shift = 128 - size;
let discr_val = (discr_val << shift) >> shift;
let (discr_dest, tag) = self.place_field(dest, mir::Field::new(0), layout)?;
self.write_scalar(discr_dest, Scalar::Bits {

View File

@ -43,17 +43,17 @@ pub fn sign_extend<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, value: u128, ty: Ty<'t
let size = layout.size.bits();
assert!(layout.abi.is_signed());
// sign extend
let amt = 128 - size;
let shift = 128 - size;
// shift the unsigned value to the left
// and back to the right as signed (essentially fills with FF on the left)
Ok((((value << amt) as i128) >> amt) as u128)
Ok((((value << shift) as i128) >> shift) as u128)
}
pub fn truncate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, value: u128, ty: Ty<'tcx>) -> EvalResult<'tcx, u128> {
let param_env = ParamEnv::empty();
let layout = tcx.layout_of(param_env.and(ty)).map_err(|layout| EvalErrorKind::Layout(layout))?;
let size = layout.size.bits();
let amt = 128 - size;
let shift = 128 - size;
// truncate (shift left to drop out leftover values, shift right to fill with zeroes)
Ok((value << amt) >> amt)
Ok((value << shift) >> shift)
}