From fdf85614dcb6d9a0d2134f2d2c82ff85ea185b44 Mon Sep 17 00:00:00 2001 From: Arthur Heymans Date: Wed, 25 Oct 2023 08:22:49 +0200 Subject: arch/x86/memcpy.c: Optimize code for 64bit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In 64bit movsq is available which moves memory in chunks of 8 bytes rather than 4 bytes. Linux uses the same code. Signed-off-by: Arthur Heymans Change-Id: I65f178d2ed3aae54b0c1ce739c2b4af8738b9fcc Reviewed-on: https://review.coreboot.org/c/coreboot/+/78646 Tested-by: build bot (Jenkins) Reviewed-by: Felix Held Reviewed-by: Martin Roth Reviewed-by: Jérémy Compostella Reviewed-by: Eric Lai --- src/arch/x86/memcpy.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/arch/x86/memcpy.c b/src/arch/x86/memcpy.c index 93002cdd27..d96a93cd93 100644 --- a/src/arch/x86/memcpy.c +++ b/src/arch/x86/memcpy.c @@ -14,19 +14,26 @@ void *memcpy(void *dest, const void *src, size_t n) check_memory_region((unsigned long)dest, n, true, _RET_IP_); #endif - asm volatile( #if ENV_X86_64 - "rep ; movsd\n\t" + asm volatile( + "rep ; movsq\n\t" "mov %4,%%rcx\n\t" + "rep ; movsb\n\t" + : "=&c" (d0), "=&D" (d1), "=&S" (d2) + : "0" (n >> 3), "g" (n & 7), "1" (dest), "2" (src) + : "memory" + ); #else + asm volatile( "rep ; movsl\n\t" "movl %4,%%ecx\n\t" -#endif "rep ; movsb\n\t" : "=&c" (d0), "=&D" (d1), "=&S" (d2) : "0" (n >> 2), "g" (n & 3), "1" (dest), "2" (src) : "memory" ); +#endif + return dest; } -- cgit v1.2.3