On 6/15/26 11:09, Gavin Shan wrote:
I guess it's also worth asking if this copy is also used for copying *from* device
memory. The commit that added memmove (4a73aee8814) suggests that dma from the device
uses these paths. In which case you'll either want a separate function for that, or
both source and destination must be aligned.
I think it's a valid case. Lets handle this by limiting the 'step' based on
src/dest/n, something like below. atomic_read() instead of ldxxx_he_p() is
used for loads. Please take a look if there are anything we can improve
further.
// Not compiled and tested yet
static void qemu_ram_copy_unaligned(void *dest, const void *src, size_t n)
{
uintptr_t test, step;
while (n != 0) {
test = (uintptr_t)src | n; /* alignment enforced by source */
step = test & -test;
test = (uintptr_t)dest | n; /* alignment enforced by destination
*/
step = MIN(step, test & -test);
while (n) {
uintptr_t test = (uintptr_t)src | (uintptr_t)dst | n;
uintptr_t step = test & -test;
Otherwise it looks good.
r~