Skip to content

Commit 44b6811

Browse files
committed
rename and move read_vector_ty
1 parent 405866a commit 44b6811

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

src/librustc/ty/sty.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,20 +1814,30 @@ impl<'tcx> TyS<'tcx> {
18141814

18151815
pub fn simd_type(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
18161816
match self.kind {
1817-
Adt(def, substs) => {
1818-
def.non_enum_variant().fields[0].ty(tcx, substs)
1819-
}
1817+
Adt(def, substs) => def.non_enum_variant().fields[0].ty(tcx, substs),
18201818
_ => bug!("simd_type called on invalid type")
18211819
}
18221820
}
18231821

1824-
pub fn simd_size(&self, _cx: TyCtxt<'_>) -> usize {
1822+
pub fn simd_size(&self, _tcx: TyCtxt<'tcx>) -> usize {
1823+
// Parameter currently unused, but probably needed in the future to
1824+
// allow `#[repr(simd)] struct Simd<T, const N: usize>([T; N]);`.
18251825
match self.kind {
18261826
Adt(def, _) => def.non_enum_variant().fields.len(),
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>) {
1832+
match self.kind {
1833+
Adt(def, substs) => {
1834+
let variant = def.non_enum_variant();
1835+
(variant.fields.len(), variant.fields[0].ty(tcx, substs))
1836+
}
1837+
_ => bug!("simd_size_and_type called on invalid type")
1838+
}
1839+
}
1840+
18311841
#[inline]
18321842
pub fn is_region_ptr(&self) -> bool {
18331843
match self.kind {

src/librustc_mir/interpret/intrinsics.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
302302
self.copy_op_transmute(args[0], dest)?;
303303
}
304304
"simd_insert" => {
305-
let index = self.read_scalar(args[1])?.to_u32()? as u64;
306-
let scalar = args[2];
305+
let index = u64::from(self.read_scalar(args[1])?.to_u32()?);
306+
let elem = args[2];
307307
let input = args[0];
308-
let (len, e_ty) = self.read_vector_ty(input);
308+
let (len, e_ty) = input.layout.ty.simd_size_and_type(self.tcx.tcx);
309+
let len = len as u64;
309310
assert!(
310311
index < len,
311312
"Index `{}` must be in bounds of vector type `{}`: `[0, {})`",
@@ -317,26 +318,26 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
317318
dest.layout.ty, input.layout.ty
318319
);
319320
assert_eq!(
320-
scalar.layout.ty, e_ty,
321-
"Scalar type `{}` must match vector element type `{}`",
322-
scalar.layout.ty, e_ty
321+
elem.layout.ty, e_ty,
322+
"Scalar element type `{}` must match vector element type `{}`",
323+
elem.layout.ty, e_ty
323324
);
324325

325326
for i in 0..len {
326327
let place = self.place_field(dest, i)?;
327328
let value = if i == index {
328-
scalar
329+
elem
329330
} else {
330331
self.operand_field(input, i)?
331332
};
332333
self.copy_op(value, place)?;
333334
}
334335
}
335336
"simd_extract" => {
336-
let index = self.read_scalar(args[1])?.to_u32()? as _;
337-
let (len, e_ty) = self.read_vector_ty(args[0]);
337+
let index = u64::from(self.read_scalar(args[1])?.to_u32()?);
338+
let (len, e_ty) = args[0].layout.ty.simd_size_and_type(self.tcx.tcx);
338339
assert!(
339-
index < len,
340+
index < len as u64,
340341
"index `{}` is out-of-bounds of vector type `{}` with length `{}`",
341342
index, e_ty, len
342343
);

src/librustc_mir/interpret/operand.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -315,17 +315,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
315315
}
316316
}
317317

318-
/// Read vector length and element type
319-
pub fn read_vector_ty(
320-
&self, op: OpTy<'tcx, M::PointerTag>
321-
) -> (u64, &rustc::ty::TyS<'tcx>) {
322-
if let layout::Abi::Vector { .. } = op.layout.abi {
323-
(op.layout.ty.simd_size(*self.tcx) as _, op.layout.ty.simd_type(*self.tcx))
324-
} else {
325-
bug!("Type `{}` is not a SIMD vector type", op.layout.ty)
326-
}
327-
}
328-
329318
/// Read a scalar from a place
330319
pub fn read_scalar(
331320
&self,

0 commit comments

Comments
 (0)