For MIRI, cfg out the swap logic from 94212
This commit is contained in:
parent
10cc7a6d03
commit
b582bd388f
3 changed files with 64 additions and 13 deletions
|
|
@ -39,6 +39,9 @@ pub fn swap_std(x: &mut KeccakBuffer, y: &mut KeccakBuffer) {
|
|||
swap(x, y)
|
||||
}
|
||||
|
||||
// Verify that types with usize alignment are swapped via vectored usizes,
|
||||
// not falling back to byte-level code.
|
||||
|
||||
// CHECK-LABEL: @swap_slice
|
||||
#[no_mangle]
|
||||
pub fn swap_slice(x: &mut [KeccakBuffer], y: &mut [KeccakBuffer]) {
|
||||
|
|
@ -50,6 +53,8 @@ pub fn swap_slice(x: &mut [KeccakBuffer], y: &mut [KeccakBuffer]) {
|
|||
}
|
||||
}
|
||||
|
||||
// But for a large align-1 type, vectorized byte copying is what we want.
|
||||
|
||||
type OneKilobyteBuffer = [u8; 1024];
|
||||
|
||||
// CHECK-LABEL: @swap_1kb_slices
|
||||
|
|
@ -62,3 +67,25 @@ pub fn swap_1kb_slices(x: &mut [OneKilobyteBuffer], y: &mut [OneKilobyteBuffer])
|
|||
x.swap_with_slice(y);
|
||||
}
|
||||
}
|
||||
|
||||
// This verifies that the 2×read + 2×write optimizes to just 3 memcpys
|
||||
// for an unusual type like this. It's not clear whether we should do anything
|
||||
// smarter in Rust for these, so for now it's fine to leave these up to the backend.
|
||||
// That's not as bad as it might seem, as for example, LLVM will lower the
|
||||
// memcpys below to VMOVAPS on YMMs if one enables the AVX target feature.
|
||||
// Eventually we'll be able to pass `align_of::<T>` to a const generic and
|
||||
// thus pick a smarter chunk size ourselves without huge code duplication.
|
||||
|
||||
#[repr(align(64))]
|
||||
pub struct BigButHighlyAligned([u8; 64 * 3]);
|
||||
|
||||
// CHECK-LABEL: @swap_big_aligned
|
||||
#[no_mangle]
|
||||
pub fn swap_big_aligned(x: &mut BigButHighlyAligned, y: &mut BigButHighlyAligned) {
|
||||
// CHECK-NOT: call void @llvm.memcpy
|
||||
// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noundef nonnull align 64 dereferenceable(192)
|
||||
// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noundef nonnull align 64 dereferenceable(192)
|
||||
// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noundef nonnull align 64 dereferenceable(192)
|
||||
// CHECK-NOT: call void @llvm.memcpy
|
||||
swap(x, y)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue