diff --git a/src/libio/cursor.rs b/src/libio/cursor.rs index b07ed4d..7ed2271 100644 --- a/src/libio/cursor.rs +++ b/src/libio/cursor.rs @@ -1,6 +1,8 @@ #[cfg(feature = "alloc")] use alloc::vec::Vec; +use core::arch::asm; + use crate::{Read, Write}; #[derive(Debug, Clone)] @@ -49,6 +51,9 @@ impl> Read for Cursor { let len = buf.len().min(data.len()); // ``copy_from_slice`` generates AXI bursts, use a regular loop instead 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]; } self.pos += len; @@ -64,6 +69,8 @@ impl Write for Cursor<&mut [u8]> { let data = &mut self.inner[self.pos..]; let len = buf.len().min(data.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]; } self.pos += len;