forked from M-Labs/artiq-zynq
cursor: prevent llvm-opt inserting memcpy in r/w
This commit is contained in:
parent
c0f508bb17
commit
1c739e81ab
@ -1,6 +1,8 @@
|
|||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
|
use core::arch::asm;
|
||||||
|
|
||||||
use crate::{Read, Write};
|
use crate::{Read, Write};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -49,6 +51,9 @@ impl<T: AsRef<[u8]>> Read for Cursor<T> {
|
|||||||
let len = buf.len().min(data.len());
|
let len = buf.len().min(data.len());
|
||||||
// ``copy_from_slice`` generates AXI bursts, use a regular loop instead
|
// ``copy_from_slice`` generates AXI bursts, use a regular loop instead
|
||||||
for i in 0..len {
|
for i in 0..len {
|
||||||
|
// HACK: On opt-level=2 or above, LLVM 18 may insert memcpy calls as an optimization pass,
|
||||||
|
// causing AXI bursts.
|
||||||
|
unsafe { asm!("", options(preserves_flags, nostack, readonly)); }
|
||||||
buf[i] = data[i];
|
buf[i] = data[i];
|
||||||
}
|
}
|
||||||
self.pos += len;
|
self.pos += len;
|
||||||
@ -64,6 +69,8 @@ impl Write for Cursor<&mut [u8]> {
|
|||||||
let data = &mut self.inner[self.pos..];
|
let data = &mut self.inner[self.pos..];
|
||||||
let len = buf.len().min(data.len());
|
let len = buf.len().min(data.len());
|
||||||
for i in 0..len {
|
for i in 0..len {
|
||||||
|
// HACK: On opt-level=2 or above, this is too fast and sends corrupted packets.
|
||||||
|
unsafe { asm!("", options(preserves_flags, nostack, readonly)); }
|
||||||
data[i] = buf[i];
|
data[i] = buf[i];
|
||||||
}
|
}
|
||||||
self.pos += len;
|
self.pos += len;
|
||||||
|
Loading…
Reference in New Issue
Block a user