From: Usama Arif <usama.arif@linux.dev>
To: david.laight.linux@gmail.com, bp@alien8.de,
dave.hansen@linux.intel.com, dsterba@suse.com, hpa@zytor.com,
linux-kernel@vger.kernel.org, mingo@redhat.com, terrelln@fb.com,
tglx@kernel.org, usama.arif@linux.dev, x86@kernel.org,
torvalds@linux-foundation.org, kas@kernel.org,
hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev,
kernel-team@meta.com
Subject: [PATCH v3 1/2] x86/lib: Keep the scalar memcpy() count in RCX
Date: Wed, 11 Nov 2026 05:20:52 -0800 [thread overview]
Message-ID: <20261111132214.2979125-2-usama.arif@linux.dev> (raw)
In-Reply-To: <20261111132214.2979125-1-usama.arif@linux.dev>
Use RCX for the scalar loop count and tail indexing, and RDX for the
small-copy data temporary. Initialize RCX from the incoming RDX count in
memcpy_orig().
This prepares the ERMS size check to use RDX as scratch while preserving
the REP MOVSB count in RCX. The FSRM path and copy policy stay the same.
No functional change.
Signed-off-by: Usama Arif <usama.arif@linux.dev>
---
arch/x86/lib/memcpy_64.S | 59 ++++++++++++++++++++--------------------
1 file changed, 30 insertions(+), 29 deletions(-)
diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
index 12a23fa7c44c5..7bb146c811029 100644
--- a/arch/x86/lib/memcpy_64.S
+++ b/arch/x86/lib/memcpy_64.S
@@ -46,8 +46,9 @@ EXPORT_SYMBOL(memcpy)
SYM_FUNC_START_LOCAL(memcpy_orig)
movq %rdi, %rax
+ movq %rdx, %rcx
- cmpq $0x20, %rdx
+ cmpq $0x20, %rcx
jb .Lhandle_tail
/*
@@ -56,9 +57,9 @@ SYM_FUNC_START_LOCAL(memcpy_orig)
*/
cmp %dil, %sil
jl .Lcopy_backward
- subq $0x20, %rdx
+ subq $0x20, %rcx
.Lcopy_forward_loop:
- subq $0x20, %rdx
+ subq $0x20, %rcx
/*
* Move in blocks of 4x8 bytes:
@@ -75,23 +76,23 @@ SYM_FUNC_START_LOCAL(memcpy_orig)
movq %r11, 3*8(%rdi)
leaq 4*8(%rdi), %rdi
jae .Lcopy_forward_loop
- addl $0x20, %edx
+ addl $0x20, %ecx
jmp .Lhandle_tail
.Lcopy_backward:
/*
* Calculate copy position to tail.
*/
- addq %rdx, %rsi
- addq %rdx, %rdi
- subq $0x20, %rdx
+ addq %rcx, %rsi
+ addq %rcx, %rdi
+ subq $0x20, %rcx
/*
* At most 3 ALU operations in one cycle,
* so append NOPS in the same 16 bytes trunk.
*/
.p2align 4
.Lcopy_backward_loop:
- subq $0x20, %rdx
+ subq $0x20, %rcx
movq -1*8(%rsi), %r8
movq -2*8(%rsi), %r9
movq -3*8(%rsi), %r10
@@ -107,11 +108,11 @@ SYM_FUNC_START_LOCAL(memcpy_orig)
/*
* Calculate copy position to head.
*/
- addl $0x20, %edx
- subq %rdx, %rsi
- subq %rdx, %rdi
+ addl $0x20, %ecx
+ subq %rcx, %rsi
+ subq %rcx, %rdi
.Lhandle_tail:
- cmpl $16, %edx
+ cmpl $16, %ecx
jb .Lless_16bytes
/*
@@ -119,53 +120,53 @@ SYM_FUNC_START_LOCAL(memcpy_orig)
*/
movq 0*8(%rsi), %r8
movq 1*8(%rsi), %r9
- movq -2*8(%rsi, %rdx), %r10
- movq -1*8(%rsi, %rdx), %r11
+ movq -2*8(%rsi, %rcx), %r10
+ movq -1*8(%rsi, %rcx), %r11
movq %r8, 0*8(%rdi)
movq %r9, 1*8(%rdi)
- movq %r10, -2*8(%rdi, %rdx)
- movq %r11, -1*8(%rdi, %rdx)
+ movq %r10, -2*8(%rdi, %rcx)
+ movq %r11, -1*8(%rdi, %rcx)
RET
.p2align 4
.Lless_16bytes:
- cmpl $8, %edx
+ cmpl $8, %ecx
jb .Lless_8bytes
/*
* Move data from 8 bytes to 15 bytes.
*/
movq 0*8(%rsi), %r8
- movq -1*8(%rsi, %rdx), %r9
+ movq -1*8(%rsi, %rcx), %r9
movq %r8, 0*8(%rdi)
- movq %r9, -1*8(%rdi, %rdx)
+ movq %r9, -1*8(%rdi, %rcx)
RET
.p2align 4
.Lless_8bytes:
- cmpl $4, %edx
+ cmpl $4, %ecx
jb .Lless_3bytes
/*
* Move data from 4 bytes to 7 bytes.
*/
- movl (%rsi), %ecx
- movl -4(%rsi, %rdx), %r8d
- movl %ecx, (%rdi)
- movl %r8d, -4(%rdi, %rdx)
+ movl (%rsi), %edx
+ movl -4(%rsi, %rcx), %r8d
+ movl %edx, (%rdi)
+ movl %r8d, -4(%rdi, %rcx)
RET
.p2align 4
.Lless_3bytes:
- subl $1, %edx
+ subl $1, %ecx
jb .Lend
/*
* Move data from 1 bytes to 3 bytes.
*/
- movzbl (%rsi), %ecx
+ movzbl (%rsi), %edx
jz .Lstore_1byte
movzbq 1(%rsi), %r8
- movzbq (%rsi, %rdx), %r9
+ movzbq (%rsi, %rcx), %r9
movb %r8b, 1(%rdi)
- movb %r9b, (%rdi, %rdx)
+ movb %r9b, (%rdi, %rcx)
.Lstore_1byte:
- movb %cl, (%rdi)
+ movb %dl, (%rdi)
.Lend:
RET
--
2.53.0-Meta
next prev parent reply other threads:[~2026-11-11 13:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 13:20 [PATCH v3 0/2] x86/lib: Use REP MOVSB for large memcpy() on ERMS CPUs without FSRM Usama Arif
2026-11-11 13:20 ` Usama Arif [this message]
2026-11-11 13:20 ` [PATCH v3 2/2] " Usama Arif
2026-11-11 13:56 ` Peter Zijlstra
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=20261111132214.2979125-2-usama.arif@linux.dev \
--to=usama.arif@linux.dev \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=david.laight.linux@gmail.com \
--cc=dsterba@suse.com \
--cc=hannes@cmpxchg.org \
--cc=hpa@zytor.com \
--cc=kas@kernel.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=riel@surriel.com \
--cc=shakeel.butt@linux.dev \
--cc=terrelln@fb.com \
--cc=tglx@kernel.org \
--cc=torvalds@linux-foundation.org \
--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
all inboxes | Powered by JetHome®