Re: [PATCH v3 2/3] riscv: optimized memmove

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Στις 2021-06-17 18:27, Matteo Croce έγραψε:
+
+/*
+ * Simply check if the buffer overlaps an call memcpy() in case,
+ * otherwise do a simple one byte at time backward copy.
+ */
+void *__memmove(void *dest, const void *src, size_t count)
+{
+	if (dest < src || src + count <= dest)
+		return memcpy(dest, src, count);
+
+	if (dest > src) {
+		const char *s = src + count;
+		char *tmp = dest + count;
+
+		while (count--)
+			*--tmp = *--s;
+	}
+	return dest;
+}
+EXPORT_SYMBOL(__memmove);
+

Copying backwards byte-per-byte is suboptimal, I understand this is not a very common scenario but you could at least check if they are both word-aligned e.g. (((src + len) | (dst + len)) & mask), or missaligned by the same offset e.g. (((src + len) ^ (dst + len)) & mask) and still end up doing word-by-word copying. Ideally it would be great if you re-used the same technique you used for forwards copying on your memcpy.

+void *memmove(void *dest, const void *src, size_t count) __weak
__alias(__memmove);
+EXPORT_SYMBOL(memmove);

As I mentioned on your memcpy patch, if you implement memmove, you can just alias memcpy to memmove and we won't have to worry about memcpy being used on overlapping regions.



[Index of Archives]     [Linux Kernel]     [Kernel Newbies]     [x86 Platform Driver]     [Netdev]     [Linux Wireless]     [Netfilter]     [Bugtraq]     [Linux Filesystems]     [Yosemite Discussion]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]

  Powered by Linux