The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Uros Bizjak <ubizjak@gmail.com>
To: x86@kernel.org, linux-kernel@vger.kernel.org
Cc: Uros Bizjak <ubizjak@gmail.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>
Subject: [PATCH -tip 2/3] x86/asm/32: Modernize __constant_memcpy()
Date: Tue,  6 May 2025 18:52:07 +0200	[thread overview]
Message-ID: <20250506165227.158932-2-ubizjak@gmail.com> (raw)
In-Reply-To: <20250506165227.158932-1-ubizjak@gmail.com>

Use inout "+" constraint modifier where appropriate and declare
temporary variables as unsigned long.

No functional changes intended.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
---
 arch/x86/include/asm/string_32.h | 51 +++++++++++++-------------------
 1 file changed, 21 insertions(+), 30 deletions(-)

diff --git a/arch/x86/include/asm/string_32.h b/arch/x86/include/asm/string_32.h
index 9152d2c0f60e..00d497837571 100644
--- a/arch/x86/include/asm/string_32.h
+++ b/arch/x86/include/asm/string_32.h
@@ -52,7 +52,7 @@ static __always_inline void *__memcpy(void *to, const void *from, size_t n)
 static __always_inline void *__constant_memcpy(void *to, const void *from,
 					       size_t n)
 {
-	long esi, edi;
+	unsigned long esi, edi;
 	if (!n)
 		return to;
 
@@ -84,60 +84,51 @@ static __always_inline void *__constant_memcpy(void *to, const void *from,
 		return to;
 	}
 
-	esi = (long)from;
-	edi = (long)to;
+	esi = (unsigned long)from;
+	edi = (unsigned long)to;
 	if (n >= 5 * 4) {
 		/* large block: use rep prefix */
-		int ecx;
+		unsigned long ecx = n >> 2;
 		asm volatile("rep movsl"
-			     : "=&c" (ecx), "=&D" (edi), "=&S" (esi)
-			     : "0" (n / 4), "1" (edi), "2" (esi)
-			     : "memory"
-		);
+			     : "+D" (edi), "+S" (esi), "+c" (ecx)
+			     : : "memory");
 	} else {
 		/* small block: don't clobber ecx + smaller code */
 		if (n >= 4 * 4)
 			asm volatile("movsl"
-				     : "=&D"(edi), "=&S"(esi)
-				     : "0"(edi), "1"(esi)
-				     : "memory");
+				     : "+D" (edi), "+S" (esi)
+				     : : "memory");
 		if (n >= 3 * 4)
 			asm volatile("movsl"
-				     : "=&D"(edi), "=&S"(esi)
-				     : "0"(edi), "1"(esi)
-				     : "memory");
+				     : "+D" (edi), "+S" (esi)
+				     : : "memory");
 		if (n >= 2 * 4)
 			asm volatile("movsl"
-				     : "=&D"(edi), "=&S"(esi)
-				     : "0"(edi), "1"(esi)
-				     : "memory");
+				     : "+D" (edi), "+S" (esi)
+				     : : "memory");
 		if (n >= 1 * 4)
 			asm volatile("movsl"
-				     : "=&D"(edi), "=&S"(esi)
-				     : "0"(edi), "1"(esi)
-				     : "memory");
+				     : "+D" (edi), "+S" (esi)
+				     : : "memory");
 	}
-	switch (n % 4) {
+	switch (n & 3) {
 		/* tail */
 	case 0:
 		return to;
 	case 1:
 		asm volatile("movsb"
-			     : "=&D"(edi), "=&S"(esi)
-			     : "0"(edi), "1"(esi)
-			     : "memory");
+			     : "+D" (edi), "+S" (esi)
+			     : : "memory");
 		return to;
 	case 2:
 		asm volatile("movsw"
-			     : "=&D"(edi), "=&S"(esi)
-			     : "0"(edi), "1"(esi)
-			     : "memory");
+			     : "+D" (edi), "+S" (esi)
+			     : : "memory");
 		return to;
 	default:
 		asm volatile("movsw\n\tmovsb"
-			     : "=&D"(edi), "=&S"(esi)
-			     : "0"(edi), "1"(esi)
-			     : "memory");
+			     : "+D" (edi), "+S" (esi)
+			     : : "memory");
 		return to;
 	}
 }
-- 
2.49.0


  reply	other threads:[~2025-05-06 16:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-06 16:52 [PATCH -tip 1/3] x86/asm/32: Modernize memset() functions Uros Bizjak
2025-05-06 16:52 ` Uros Bizjak [this message]
2025-05-06 16:52 ` [PATCH -tip 3/3] x86/asm/32: Modernize _memcpy() Uros Bizjak
2025-05-06 17:34   ` Uros Bizjak
2025-05-07 20:28     ` David Laight
2025-05-07 21:29       ` Uros Bizjak
2025-05-06 17:54 ` [PATCH -tip 1/3] x86/asm/32: Modernize memset() functions H. Peter Anvin
2025-05-06 18:22   ` Linus Torvalds
2025-05-07  0:31     ` H. Peter Anvin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250506165227.158932-2-ubizjak@gmail.com \
    --to=ubizjak@gmail.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox