Skip to content

Commit 9bdc5b2

Browse files
committed
Improve documentation
1 parent 86158f5 commit 9bdc5b2

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,15 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
480480
}
481481

482482
_ if name.as_str().starts_with("simd_") => {
483-
// Unpack non-power-of-2 #[repr(packed)]
483+
// Unpack non-power-of-2 #[repr(packed, simd)] arguments.
484+
// This gives them the expected layout of a regular #[repr(simd)] vector.
484485
let mut loaded_args = Vec::new();
485486
for (ty, arg) in arg_tys.iter().zip(args) {
486487
loaded_args.push(
488+
// #[repr(packed, simd)] vectors are passed like arrays (as references,
489+
// with reduced alignment and no padding) rather than as immediates.
490+
// We can use a vector load to fix the layout and turn the argument
491+
// into an immediate.
487492
if ty.is_simd()
488493
&& let OperandValue::Ref(place) = arg.val
489494
{

tests/ui/simd/repr_packed.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ fn main() {
3636
check_ty::<f64>();
3737

3838
unsafe {
39-
// powers-of-two have no padding and work as usual
39+
// powers-of-two have no padding and have the same layout as #[repr(simd)]
4040
let x: Simd<f64, 4> =
4141
simd_add(Simd::<f64, 4>([0., 1., 2., 3.]), Simd::<f64, 4>([2., 2., 2., 2.]));
4242
assert_eq!(std::mem::transmute::<_, [f64; 4]>(x), [2., 3., 4., 5.]);
4343

44-
// non-powers-of-two have padding and lesser alignment, but the intrinsic handles it
44+
// non-powers-of-two should have padding (which is removed by #[repr(packed)]),
45+
// but the intrinsic handles it
4546
let x: Simd<f64, 3> = simd_add(Simd::<f64, 3>([0., 1., 2.]), Simd::<f64, 3>([2., 2., 2.]));
4647
let arr: [f64; 3] = x.0;
4748
assert_eq!(arr, [2., 3., 4.]);

0 commit comments

Comments
 (0)