Skip to content

Commit a088099

Browse files
authored
Merge pull request #2066 from folkertdev/basic-miri-roundtrip
Basic miri store/load roundtrip
2 parents f0b7c56 + 27b22af commit a088099

7 files changed

Lines changed: 53 additions & 112 deletions

File tree

.github/workflows/main.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ jobs:
272272
intrinsic-test:
273273
needs: [style]
274274
name: Intrinsic Test
275-
runs-on: ubuntu-latest
275+
runs-on: ubuntu-latest
276276
strategy:
277277
matrix:
278278
target:
@@ -332,11 +332,33 @@ jobs:
332332
cargo run -p stdarch-gen-hexagon --release
333333
git diff --exit-code
334334
335+
# Run some tests with Miri. Most stdarch functions use platform-specific intrinsics
336+
# that Miri does not support. Also Miri is reltively slow.
337+
#
338+
# Below we run some tests where Miri might catch UB, for instance on intrinsics that read from
339+
# or write to pointers.
340+
miri:
341+
needs: [style]
342+
name: Run some tests with miri
343+
runs-on: ubuntu-latest
344+
steps:
345+
- uses: actions/checkout@v6
346+
- name: Install Rust
347+
run: rustup update nightly && rustup default nightly && rustup component add miri
348+
- name: Run miri tests
349+
env:
350+
TARGET: "aarch64-unknown-linux-gnu"
351+
run: |
352+
# read filters and join them with a space.
353+
FILTERS=$(cat aarch64-miri-tests.txt | tr '\n' ' ')
354+
cargo miri test -p core_arch --target aarch64-unknown-linux-gnu -- $FILTERS
355+
335356
conclusion:
336357
needs:
337358
- docs
338359
- verify
339360
- test
361+
- miri
340362
- intrinsic-test
341363
- check-stdarch-gen
342364
runs-on: ubuntu-latest

aarch64-miri-tests.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test_vld3q
2+
neon::load_tests
3+
neon::store_tests

crates/core_arch/src/aarch64/neon/generated.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12127,14 +12127,7 @@ pub unsafe fn vld3q_dup_u64(a: *const u64) -> uint64x2x3_t {
1212712127
#[stable(feature = "neon_intrinsics", since = "1.59.0")]
1212812128
#[cfg_attr(test, assert_instr(ld3))]
1212912129
pub unsafe fn vld3q_f64(a: *const f64) -> float64x2x3_t {
12130-
unsafe extern "unadjusted" {
12131-
#[cfg_attr(
12132-
any(target_arch = "aarch64", target_arch = "arm64ec"),
12133-
link_name = "llvm.aarch64.neon.ld3.v2f64.p0"
12134-
)]
12135-
fn _vld3q_f64(ptr: *const float64x2_t) -> float64x2x3_t;
12136-
}
12137-
_vld3q_f64(a as _)
12130+
crate::core_arch::macros::deinterleaving_load!(f64, 2, 3, a)
1213812131
}
1213912132
#[doc = "Load multiple 3-element structures to three registers"]
1214012133
#[doc = "[Arm's documentation](https://developer.arm.com/architectures/instruction-sets/intrinsics/vld3q_s64)"]
@@ -12145,14 +12138,7 @@ pub unsafe fn vld3q_f64(a: *const f64) -> float64x2x3_t {
1214512138
#[stable(feature = "neon_intrinsics", since = "1.59.0")]
1214612139
#[cfg_attr(test, assert_instr(ld3))]
1214712140
pub unsafe fn vld3q_s64(a: *const i64) -> int64x2x3_t {
12148-
unsafe extern "unadjusted" {
12149-
#[cfg_attr(
12150-
any(target_arch = "aarch64", target_arch = "arm64ec"),
12151-
link_name = "llvm.aarch64.neon.ld3.v2i64.p0"
12152-
)]
12153-
fn _vld3q_s64(ptr: *const int64x2_t) -> int64x2x3_t;
12154-
}
12155-
_vld3q_s64(a as _)
12141+
crate::core_arch::macros::deinterleaving_load!(i64, 2, 3, a)
1215612142
}
1215712143
#[doc = "Load multiple 3-element structures to three registers"]
1215812144
#[doc = "[Arm's documentation](https://developer.arm.com/architectures/instruction-sets/intrinsics/vld3q_lane_f64)"]

crates/core_arch/src/aarch64/neon/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,12 @@ mod tests {
10221022
($elem_ty:ty, $len:expr, $vec_ty:ty, $store:expr, $load:expr) => {
10231023
let vals: [$elem_ty; $len] = crate::array::from_fn(|i| i as $elem_ty);
10241024
let a: $vec_ty = transmute(vals);
1025-
let mut tmp = [0 as $elem_ty; $len];
1025+
let mut tmp = core::mem::MaybeUninit::<[$elem_ty; $len]>::uninit();
10261026
$store(tmp.as_mut_ptr().cast(), a);
1027+
1028+
// With Miri this will check that all elements were initialized.
1029+
let tmp = tmp.assume_init();
1030+
10271031
let r: $vec_ty = $load(tmp.as_ptr().cast());
10281032
let out: [$elem_ty; $len] = transmute(r);
10291033
assert_eq!(out, vals);

crates/core_arch/src/arm_shared/neon/generated.rs

Lines changed: 8 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -67158,14 +67158,7 @@ pub unsafe fn vst3q_s32(a: *mut i32, b: int32x4x3_t) {
6715867158
#[stable(feature = "neon_intrinsics", since = "1.59.0")]
6715967159
#[cfg_attr(test, assert_instr(st3))]
6716067160
pub unsafe fn vst3_f32(a: *mut f32, b: float32x2x3_t) {
67161-
unsafe extern "unadjusted" {
67162-
#[cfg_attr(
67163-
any(target_arch = "aarch64", target_arch = "arm64ec"),
67164-
link_name = "llvm.aarch64.neon.st3.v2f32.p0"
67165-
)]
67166-
fn _vst3_f32(a: float32x2_t, b: float32x2_t, c: float32x2_t, ptr: *mut i8);
67167-
}
67168-
_vst3_f32(b.0, b.1, b.2, a as _)
67161+
crate::core_arch::macros::interleaving_store!(f32, 2, 3, a, b)
6716967162
}
6717067163
#[doc = "Store multiple 3-element structures from three registers"]
6717167164
#[doc = "[Arm's documentation](https://developer.arm.com/architectures/instruction-sets/intrinsics/vst3q_f32)"]
@@ -67177,14 +67170,7 @@ pub unsafe fn vst3_f32(a: *mut f32, b: float32x2x3_t) {
6717767170
#[stable(feature = "neon_intrinsics", since = "1.59.0")]
6717867171
#[cfg_attr(test, assert_instr(st3))]
6717967172
pub unsafe fn vst3q_f32(a: *mut f32, b: float32x4x3_t) {
67180-
unsafe extern "unadjusted" {
67181-
#[cfg_attr(
67182-
any(target_arch = "aarch64", target_arch = "arm64ec"),
67183-
link_name = "llvm.aarch64.neon.st3.v4f32.p0"
67184-
)]
67185-
fn _vst3q_f32(a: float32x4_t, b: float32x4_t, c: float32x4_t, ptr: *mut i8);
67186-
}
67187-
_vst3q_f32(b.0, b.1, b.2, a as _)
67173+
crate::core_arch::macros::interleaving_store!(f32, 4, 3, a, b)
6718867174
}
6718967175
#[doc = "Store multiple 3-element structures from three registers"]
6719067176
#[doc = "[Arm's documentation](https://developer.arm.com/architectures/instruction-sets/intrinsics/vst3_s8)"]
@@ -67196,14 +67182,7 @@ pub unsafe fn vst3q_f32(a: *mut f32, b: float32x4x3_t) {
6719667182
#[stable(feature = "neon_intrinsics", since = "1.59.0")]
6719767183
#[cfg_attr(test, assert_instr(st3))]
6719867184
pub unsafe fn vst3_s8(a: *mut i8, b: int8x8x3_t) {
67199-
unsafe extern "unadjusted" {
67200-
#[cfg_attr(
67201-
any(target_arch = "aarch64", target_arch = "arm64ec"),
67202-
link_name = "llvm.aarch64.neon.st3.v8i8.p0"
67203-
)]
67204-
fn _vst3_s8(a: int8x8_t, b: int8x8_t, c: int8x8_t, ptr: *mut i8);
67205-
}
67206-
_vst3_s8(b.0, b.1, b.2, a as _)
67185+
crate::core_arch::macros::interleaving_store!(i8, 8, 3, a, b)
6720767186
}
6720867187
#[doc = "Store multiple 3-element structures from three registers"]
6720967188
#[doc = "[Arm's documentation](https://developer.arm.com/architectures/instruction-sets/intrinsics/vst3q_s8)"]
@@ -67215,14 +67194,7 @@ pub unsafe fn vst3_s8(a: *mut i8, b: int8x8x3_t) {
6721567194
#[stable(feature = "neon_intrinsics", since = "1.59.0")]
6721667195
#[cfg_attr(test, assert_instr(st3))]
6721767196
pub unsafe fn vst3q_s8(a: *mut i8, b: int8x16x3_t) {
67218-
unsafe extern "unadjusted" {
67219-
#[cfg_attr(
67220-
any(target_arch = "aarch64", target_arch = "arm64ec"),
67221-
link_name = "llvm.aarch64.neon.st3.v16i8.p0"
67222-
)]
67223-
fn _vst3q_s8(a: int8x16_t, b: int8x16_t, c: int8x16_t, ptr: *mut i8);
67224-
}
67225-
_vst3q_s8(b.0, b.1, b.2, a as _)
67197+
crate::core_arch::macros::interleaving_store!(i8, 16, 3, a, b)
6722667198
}
6722767199
#[doc = "Store multiple 3-element structures from three registers"]
6722867200
#[doc = "[Arm's documentation](https://developer.arm.com/architectures/instruction-sets/intrinsics/vst3_s16)"]
@@ -67234,14 +67206,7 @@ pub unsafe fn vst3q_s8(a: *mut i8, b: int8x16x3_t) {
6723467206
#[stable(feature = "neon_intrinsics", since = "1.59.0")]
6723567207
#[cfg_attr(test, assert_instr(st3))]
6723667208
pub unsafe fn vst3_s16(a: *mut i16, b: int16x4x3_t) {
67237-
unsafe extern "unadjusted" {
67238-
#[cfg_attr(
67239-
any(target_arch = "aarch64", target_arch = "arm64ec"),
67240-
link_name = "llvm.aarch64.neon.st3.v4i16.p0"
67241-
)]
67242-
fn _vst3_s16(a: int16x4_t, b: int16x4_t, c: int16x4_t, ptr: *mut i8);
67243-
}
67244-
_vst3_s16(b.0, b.1, b.2, a as _)
67209+
crate::core_arch::macros::interleaving_store!(i16, 4, 3, a, b)
6724567210
}
6724667211
#[doc = "Store multiple 3-element structures from three registers"]
6724767212
#[doc = "[Arm's documentation](https://developer.arm.com/architectures/instruction-sets/intrinsics/vst3q_s16)"]
@@ -67253,14 +67218,7 @@ pub unsafe fn vst3_s16(a: *mut i16, b: int16x4x3_t) {
6725367218
#[stable(feature = "neon_intrinsics", since = "1.59.0")]
6725467219
#[cfg_attr(test, assert_instr(st3))]
6725567220
pub unsafe fn vst3q_s16(a: *mut i16, b: int16x8x3_t) {
67256-
unsafe extern "unadjusted" {
67257-
#[cfg_attr(
67258-
any(target_arch = "aarch64", target_arch = "arm64ec"),
67259-
link_name = "llvm.aarch64.neon.st3.v8i16.p0"
67260-
)]
67261-
fn _vst3q_s16(a: int16x8_t, b: int16x8_t, c: int16x8_t, ptr: *mut i8);
67262-
}
67263-
_vst3q_s16(b.0, b.1, b.2, a as _)
67221+
crate::core_arch::macros::interleaving_store!(i16, 8, 3, a, b)
6726467222
}
6726567223
#[doc = "Store multiple 3-element structures from three registers"]
6726667224
#[doc = "[Arm's documentation](https://developer.arm.com/architectures/instruction-sets/intrinsics/vst3_s32)"]
@@ -67272,14 +67230,7 @@ pub unsafe fn vst3q_s16(a: *mut i16, b: int16x8x3_t) {
6727267230
#[stable(feature = "neon_intrinsics", since = "1.59.0")]
6727367231
#[cfg_attr(test, assert_instr(st3))]
6727467232
pub unsafe fn vst3_s32(a: *mut i32, b: int32x2x3_t) {
67275-
unsafe extern "unadjusted" {
67276-
#[cfg_attr(
67277-
any(target_arch = "aarch64", target_arch = "arm64ec"),
67278-
link_name = "llvm.aarch64.neon.st3.v2i32.p0"
67279-
)]
67280-
fn _vst3_s32(a: int32x2_t, b: int32x2_t, c: int32x2_t, ptr: *mut i8);
67281-
}
67282-
_vst3_s32(b.0, b.1, b.2, a as _)
67233+
crate::core_arch::macros::interleaving_store!(i32, 2, 3, a, b)
6728367234
}
6728467235
#[doc = "Store multiple 3-element structures from three registers"]
6728567236
#[doc = "[Arm's documentation](https://developer.arm.com/architectures/instruction-sets/intrinsics/vst3q_s32)"]
@@ -67291,14 +67242,7 @@ pub unsafe fn vst3_s32(a: *mut i32, b: int32x2x3_t) {
6729167242
#[stable(feature = "neon_intrinsics", since = "1.59.0")]
6729267243
#[cfg_attr(test, assert_instr(st3))]
6729367244
pub unsafe fn vst3q_s32(a: *mut i32, b: int32x4x3_t) {
67294-
unsafe extern "unadjusted" {
67295-
#[cfg_attr(
67296-
any(target_arch = "aarch64", target_arch = "arm64ec"),
67297-
link_name = "llvm.aarch64.neon.st3.v4i32.p0"
67298-
)]
67299-
fn _vst3q_s32(a: int32x4_t, b: int32x4_t, c: int32x4_t, ptr: *mut i8);
67300-
}
67301-
_vst3q_s32(b.0, b.1, b.2, a as _)
67245+
crate::core_arch::macros::interleaving_store!(i32, 4, 3, a, b)
6730267246
}
6730367247
#[doc = "Store multiple 3-element structures from three registers"]
6730467248
#[doc = "[Arm's documentation](https://developer.arm.com/architectures/instruction-sets/intrinsics/vst3_lane_f16)"]

crates/stdarch-gen-arm/spec/neon/aarch64.spec.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4031,17 +4031,10 @@ intrinsics:
40314031
unsafe: [neon]
40324032
assert_instr: [ld3]
40334033
types:
4034-
- ['*const i64', int64x2x3_t, '*const int64x2_t', i64]
4035-
- ['*const f64', float64x2x3_t, '*const float64x2_t', f64]
4034+
- ['*const i64', int64x2x3_t, i64, "2"]
4035+
- ['*const f64', float64x2x3_t, f64, "2"]
40364036
compose:
4037-
- LLVMLink:
4038-
name: 'vld3{neon_type[1].nox}'
4039-
arguments:
4040-
- 'ptr: {type[2]}'
4041-
links:
4042-
- link: 'llvm.aarch64.neon.ld3.v{neon_type[1].lane}{type[3]}.p0'
4043-
arch: aarch64,arm64ec
4044-
- FnCall: ['_vld3{neon_type[1].nox}', ['a as _']]
4037+
- FnCall: ["crate::core_arch::macros::deinterleaving_load!", [{ Type: "{type[2]}" }, "{type[3]}", "3", a], [], true]
40454038

40464039
- name: "vld3{neon_type[1].nox}"
40474040
doc: Load multiple 3-element structures to three registers

crates/stdarch-gen-arm/spec/neon/arm_shared.spec.yml

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5642,27 +5642,16 @@ intrinsics:
56425642
safety:
56435643
unsafe: [neon]
56445644
types:
5645-
- [i8, int8x8x3_t, int8x8_t]
5646-
- [i16, int16x4x3_t, int16x4_t]
5647-
- [i32, int32x2x3_t, int32x2_t]
5648-
- [i8, int8x16x3_t, int8x16_t]
5649-
- [i16, int16x8x3_t, int16x8_t]
5650-
- [i32, int32x4x3_t, int32x4_t]
5651-
- [f32, float32x2x3_t, float32x2_t]
5652-
- [f32, float32x4x3_t, float32x4_t]
5645+
- [i8, int8x8x3_t, "8"]
5646+
- [i16, int16x4x3_t, "4"]
5647+
- [i32, int32x2x3_t, "2"]
5648+
- [i8, int8x16x3_t, "16"]
5649+
- [i16, int16x8x3_t, "8"]
5650+
- [i32, int32x4x3_t, "4"]
5651+
- [f32, float32x2x3_t, "2"]
5652+
- [f32, float32x4x3_t, "4"]
56535653
compose:
5654-
- LLVMLink:
5655-
name: 'vst3.{neon_type[1]}'
5656-
arguments:
5657-
- 'a: {type[2]}'
5658-
- 'b: {type[2]}'
5659-
- 'c: {type[2]}'
5660-
- 'ptr: *mut i8'
5661-
links:
5662-
- link: 'llvm.aarch64.neon.st3.v{neon_type[1].lane}{type[0]}.p0'
5663-
arch: aarch64,arm64ec
5664-
- FnCall: ['_vst3{neon_type[1].nox}', ['b.0', 'b.1', 'b.2', 'a as _']]
5665-
5654+
- FnCall: ["crate::core_arch::macros::interleaving_store!", [{ Type: "{type[0]}" }, "{type[2]}", "3", a, b], [], true]
56665655

56675656
- name: "vst3{neon_type[1].nox}"
56685657
doc: "Store multiple 3-element structures from three registers"

0 commit comments

Comments
 (0)