Skip to content

Commit 09180d7

Browse files
committed
make simd_size return a u64
1 parent 44b6811 commit 09180d7

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

src/librustc/ty/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
697697
// SIMD vector types.
698698
ty::Adt(def, ..) if def.repr.simd() => {
699699
let element = self.layout_of(ty.simd_type(tcx))?;
700-
let count = ty.simd_size(tcx) as u64;
700+
let count = ty.simd_size(tcx);
701701
assert!(count > 0);
702702
let scalar = match element.abi {
703703
Abi::Scalar(ref scalar) => scalar.clone(),

src/librustc/ty/sty.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1819,20 +1819,20 @@ impl<'tcx> TyS<'tcx> {
18191819
}
18201820
}
18211821

1822-
pub fn simd_size(&self, _tcx: TyCtxt<'tcx>) -> usize {
1822+
pub fn simd_size(&self, _tcx: TyCtxt<'tcx>) -> u64 {
18231823
// Parameter currently unused, but probably needed in the future to
18241824
// allow `#[repr(simd)] struct Simd<T, const N: usize>([T; N]);`.
18251825
match self.kind {
1826-
Adt(def, _) => def.non_enum_variant().fields.len(),
1826+
Adt(def, _) => def.non_enum_variant().fields.len() as u64,
18271827
_ => bug!("simd_size called on invalid type")
18281828
}
18291829
}
18301830

1831-
pub fn simd_size_and_type(&self, tcx: TyCtxt<'tcx>) -> (usize, Ty<'tcx>) {
1831+
pub fn simd_size_and_type(&self, tcx: TyCtxt<'tcx>) -> (u64, Ty<'tcx>) {
18321832
match self.kind {
18331833
Adt(def, substs) => {
18341834
let variant = def.non_enum_variant();
1835-
(variant.fields.len(), variant.fields[0].ty(tcx, substs))
1835+
(variant.fields.len() as u64, variant.fields[0].ty(tcx, substs))
18361836
}
18371837
_ => bug!("simd_size_and_type called on invalid type")
18381838
}

src/librustc_codegen_llvm/intrinsic.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use syntax_pos::Span;
2828

2929
use std::cmp::Ordering;
3030
use std::{iter, i128, u128};
31+
use std::convert::TryFrom;
3132

3233
fn get_simple_intrinsic(cx: &CodegenCx<'ll, '_>, name: &str) -> Option<&'ll Value> {
3334
let llvm_name = match name {
@@ -1105,8 +1106,8 @@ fn generic_simd_intrinsic(
11051106
let m_len = match in_ty.kind {
11061107
// Note that this `.unwrap()` crashes for isize/usize, that's sort
11071108
// of intentional as there's not currently a use case for that.
1108-
ty::Int(i) => i.bit_width().unwrap(),
1109-
ty::Uint(i) => i.bit_width().unwrap(),
1109+
ty::Int(i) => i.bit_width().unwrap() as u64,
1110+
ty::Uint(i) => i.bit_width().unwrap() as u64,
11101111
_ => return_error!("`{}` is not an integral type", in_ty),
11111112
};
11121113
require_simd!(arg_tys[1], "argument");
@@ -1116,7 +1117,7 @@ fn generic_simd_intrinsic(
11161117
m_len, v_len
11171118
);
11181119
let i1 = bx.type_i1();
1119-
let i1xn = bx.type_vector(i1, m_len as u64);
1120+
let i1xn = bx.type_vector(i1, m_len);
11201121
let m_i1s = bx.bitcast(args[0].immediate(), i1xn);
11211122
return Ok(bx.select(m_i1s, args[1].immediate(), args[2].immediate()));
11221123
}
@@ -1166,7 +1167,7 @@ fn generic_simd_intrinsic(
11661167
require_simd!(ret_ty, "return");
11671168

11681169
let out_len = ret_ty.simd_size(tcx);
1169-
require!(out_len == n,
1170+
require!(out_len == n as u64,
11701171
"expected return type of length {}, found `{}` with length {}",
11711172
n, ret_ty, out_len);
11721173
require!(in_elem == ret_ty.simd_type(tcx),
@@ -1251,7 +1252,7 @@ fn generic_simd_intrinsic(
12511252
// trailing bits.
12521253
let expected_int_bits = in_len.max(8);
12531254
match ret_ty.kind {
1254-
ty::Uint(i) if i.bit_width() == Some(expected_int_bits) => (),
1255+
ty::Uint(i) if i.bit_width() == Some(expected_int_bits as usize) => (),
12551256
_ => return_error!(
12561257
"bitmask `{}`, expected `u{}`",
12571258
ret_ty, expected_int_bits
@@ -1276,7 +1277,8 @@ fn generic_simd_intrinsic(
12761277

12771278
// Shift the MSB to the right by "in_elem_bitwidth - 1" into the first bit position.
12781279
let shift_indices = vec![
1279-
bx.cx.const_int(bx.type_ix(in_elem_bitwidth as _), (in_elem_bitwidth - 1) as _); in_len
1280+
bx.cx.const_int(bx.type_ix(in_elem_bitwidth as _), (in_elem_bitwidth - 1) as _);
1281+
in_len as _
12801282
];
12811283
let i_xn_msb = bx.lshr(i_xn, bx.const_vector(shift_indices.as_slice()));
12821284
// Truncate vector to an <i1 x N>
@@ -1291,7 +1293,7 @@ fn generic_simd_intrinsic(
12911293
name: &str,
12921294
in_elem: &::rustc::ty::TyS<'_>,
12931295
in_ty: &::rustc::ty::TyS<'_>,
1294-
in_len: usize,
1296+
in_len: u64,
12951297
bx: &mut Builder<'a, 'll, 'tcx>,
12961298
span: Span,
12971299
args: &[OperandRef<'tcx, &'ll Value>],
@@ -1506,11 +1508,12 @@ fn generic_simd_intrinsic(
15061508
// Truncate the mask vector to a vector of i1s:
15071509
let (mask, mask_ty) = {
15081510
let i1 = bx.type_i1();
1509-
let i1xn = bx.type_vector(i1, in_len as u64);
1511+
let i1xn = bx.type_vector(i1, in_len);
15101512
(bx.trunc(args[2].immediate(), i1xn), i1xn)
15111513
};
15121514

15131515
// Type of the vector of pointers:
1516+
let in_len = usize::try_from(in_len).unwrap();
15141517
let llvm_pointer_vec_ty = llvm_vector_ty(bx, underlying_ty, in_len, pointer_count);
15151518
let llvm_pointer_vec_str = llvm_vector_str(underlying_ty, in_len, pointer_count);
15161519

@@ -1606,13 +1609,14 @@ fn generic_simd_intrinsic(
16061609
// Truncate the mask vector to a vector of i1s:
16071610
let (mask, mask_ty) = {
16081611
let i1 = bx.type_i1();
1609-
let i1xn = bx.type_vector(i1, in_len as u64);
1612+
let i1xn = bx.type_vector(i1, in_len);
16101613
(bx.trunc(args[2].immediate(), i1xn), i1xn)
16111614
};
16121615

16131616
let ret_t = bx.type_void();
16141617

16151618
// Type of the vector of pointers:
1619+
let in_len = usize::try_from(in_len).unwrap();
16161620
let llvm_pointer_vec_ty = llvm_vector_ty(bx, underlying_ty, in_len, pointer_count);
16171621
let llvm_pointer_vec_str = llvm_vector_str(underlying_ty, in_len, pointer_count);
16181622

src/librustc_mir/interpret/intrinsics.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
306306
let elem = args[2];
307307
let input = args[0];
308308
let (len, e_ty) = input.layout.ty.simd_size_and_type(self.tcx.tcx);
309-
let len = len as u64;
310309
assert!(
311310
index < len,
312311
"Index `{}` must be in bounds of vector type `{}`: `[0, {})`",
@@ -337,7 +336,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
337336
let index = u64::from(self.read_scalar(args[1])?.to_u32()?);
338337
let (len, e_ty) = args[0].layout.ty.simd_size_and_type(self.tcx.tcx);
339338
assert!(
340-
index < len as u64,
339+
index < len,
341340
"index `{}` is out-of-bounds of vector type `{}` with length `{}`",
342341
index, e_ty, len
343342
);

0 commit comments

Comments
 (0)