提交 9de60089 编写于 作者: R Ralf Jung

make bit_width return u64, consistently with other sizes in the compiler

上级 1ddbdc62
......@@ -1614,7 +1614,7 @@ pub fn name(self) -> Symbol {
}
}
pub fn bit_width(self) -> usize {
pub fn bit_width(self) -> u64 {
match self {
FloatTy::F32 => 32,
FloatTy::F64 => 64,
......@@ -1663,7 +1663,7 @@ pub fn val_to_string(&self, val: i128) -> String {
format!("{}{}", val as u128, self.name_str())
}
pub fn bit_width(&self) -> Option<usize> {
pub fn bit_width(&self) -> Option<u64> {
Some(match *self {
IntTy::Isize => return None,
IntTy::I8 => 8,
......@@ -1725,7 +1725,7 @@ pub fn val_to_string(&self, val: u128) -> String {
format!("{}{}", val, self.name_str())
}
pub fn bit_width(&self) -> Option<usize> {
pub fn bit_width(&self) -> Option<u64> {
Some(match *self {
UintTy::Usize => return None,
UintTy::U8 => 8,
......
......@@ -1172,8 +1172,8 @@ fn generic_simd_intrinsic(
let m_len = match in_ty.kind {
// Note that this `.unwrap()` crashes for isize/usize, that's sort
// of intentional as there's not currently a use case for that.
ty::Int(i) => i.bit_width().unwrap() as u64,
ty::Uint(i) => i.bit_width().unwrap() as u64,
ty::Int(i) => i.bit_width().unwrap(),
ty::Uint(i) => i.bit_width().unwrap(),
_ => return_error!("`{}` is not an integral type", in_ty),
};
require_simd!(arg_tys[1], "argument");
......@@ -1354,20 +1354,18 @@ fn generic_simd_intrinsic(
// trailing bits.
let expected_int_bits = in_len.max(8);
match ret_ty.kind {
ty::Uint(i) if i.bit_width() == Some(expected_int_bits as usize) => (),
ty::Uint(i) if i.bit_width() == Some(expected_int_bits) => (),
_ => return_error!("bitmask `{}`, expected `u{}`", ret_ty, expected_int_bits),
}
// Integer vector <i{in_bitwidth} x in_len>:
let (i_xn, in_elem_bitwidth) = match in_elem.kind {
ty::Int(i) => (
args[0].immediate(),
i.bit_width().unwrap_or(bx.data_layout().pointer_size.bits() as _),
),
ty::Uint(i) => (
args[0].immediate(),
i.bit_width().unwrap_or(bx.data_layout().pointer_size.bits() as _),
),
ty::Int(i) => {
(args[0].immediate(), i.bit_width().unwrap_or(bx.data_layout().pointer_size.bits()))
}
ty::Uint(i) => {
(args[0].immediate(), i.bit_width().unwrap_or(bx.data_layout().pointer_size.bits()))
}
_ => return_error!(
"vector argument `{}`'s element type `{}`, expected integer element type",
in_ty,
......@@ -1378,16 +1376,16 @@ fn generic_simd_intrinsic(
// Shift the MSB to the right by "in_elem_bitwidth - 1" into the first bit position.
let shift_indices =
vec![
bx.cx.const_int(bx.type_ix(in_elem_bitwidth as _), (in_elem_bitwidth - 1) as _);
bx.cx.const_int(bx.type_ix(in_elem_bitwidth), (in_elem_bitwidth - 1) as _);
in_len as _
];
let i_xn_msb = bx.lshr(i_xn, bx.const_vector(shift_indices.as_slice()));
// Truncate vector to an <i1 x N>
let i1xn = bx.trunc(i_xn_msb, bx.type_vector(bx.type_i1(), in_len as _));
let i1xn = bx.trunc(i_xn_msb, bx.type_vector(bx.type_i1(), in_len));
// Bitcast <i1 x N> to iN:
let i_ = bx.bitcast(i1xn, bx.type_ix(in_len as _));
let i_ = bx.bitcast(i1xn, bx.type_ix(in_len));
// Zero-extend iN to the bitmask type:
return Ok(bx.zext(i_, bx.type_ix(expected_int_bits as _)));
return Ok(bx.zext(i_, bx.type_ix(expected_int_bits)));
}
fn simd_simple_float_intrinsic(
......@@ -2099,7 +2097,7 @@ fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, boo
match ty.kind {
ty::Int(t) => Some((
match t {
ast::IntTy::Isize => cx.tcx.sess.target.ptr_width as u64,
ast::IntTy::Isize => u64::from(cx.tcx.sess.target.ptr_width),
ast::IntTy::I8 => 8,
ast::IntTy::I16 => 16,
ast::IntTy::I32 => 32,
......@@ -2110,7 +2108,7 @@ fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, boo
)),
ty::Uint(t) => Some((
match t {
ast::UintTy::Usize => cx.tcx.sess.target.ptr_width as u64,
ast::UintTy::Usize => u64::from(cx.tcx.sess.target.ptr_width),
ast::UintTy::U8 => 8,
ast::UintTy::U16 => 16,
ast::UintTy::U32 => 32,
......@@ -2127,7 +2125,7 @@ fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, boo
// Returns None if the type is not a float
fn float_type_width(ty: Ty<'_>) -> Option<u64> {
match ty.kind {
ty::Float(t) => Some(t.bit_width() as u64),
ty::Float(t) => Some(t.bit_width()),
_ => None,
}
}
......@@ -228,17 +228,16 @@ fn cast_from_float<F>(
match dest_ty.kind {
// float -> uint
Uint(t) => {
// FIXME: can we make `bit_width` return a type more compatible with `Size::bits`?
let width = t.bit_width().unwrap_or_else(|| self.pointer_size().bits() as usize);
let v = f.to_u128(width).value;
let width = t.bit_width().unwrap_or_else(|| self.pointer_size().bits());
let v = f.to_u128(usize::try_from(width).unwrap()).value;
// This should already fit the bit width
Ok(Scalar::from_uint(v, Size::from_bits(width as u64)))
Ok(Scalar::from_uint(v, Size::from_bits(width)))
}
// float -> int
Int(t) => {
let width = t.bit_width().unwrap_or_else(|| self.pointer_size().bits() as usize);
let v = f.to_i128(width).value;
Ok(Scalar::from_int(v, Size::from_bits(width as u64)))
let width = t.bit_width().unwrap_or_else(|| self.pointer_size().bits());
let v = f.to_i128(usize::try_from(width).unwrap()).value;
Ok(Scalar::from_int(v, Size::from_bits(width)))
}
// float -> f32
Float(FloatTy::F32) => Ok(Scalar::from_f32(f.convert(&mut false).value)),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册