All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: Borislav Petkov <bp@alien8.de>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Usama Arif <usama.arif@linux.dev>,
	dave.hansen@linux.intel.com, dsterba@suse.com,
	linux-kernel@vger.kernel.org, mingo@redhat.com, terrelln@fb.com,
	tglx@kernel.org, x86@kernel.org, kas@kernel.org,
	hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev,
	kernel-team@meta.com
Subject: Re: [PATCH v3 2/2] x86/lib: Use REP MOVSB for large memcpy() on ERMS CPUs without FSRM
Date: Sat, 14 Nov 2026 22:45:04 +0000	[thread overview]
Message-ID: <20261114224504.7574f7f0@pumpkin> (raw)
In-Reply-To: <628BDCC5-B599-4B70-B512-E13DEE926DFA@zytor.com>

On Fri, 13 Nov 2026 18:21:23 -0800
"H. Peter Anvin" <hpa@zytor.com> wrote:

> On November 13, 2026 3:37:03 PM PST, Borislav Petkov <bp@alien8.de> wrote:
> >On Fri, Nov 13, 2026 at 10:36:30AM -0800, H. Peter Anvin wrote:  
> >> Well, we can put a request in for compiler support. This equally applies to
> >> other compiler runtime functions, for that matter...  
> >
> >I was going to suggest that too. Lemme know if I should ping my gcc folks...
> >  
> 
> Seems like a good idea to me. Presumably it would be using the rep movsb convention.

You probably want at least two scratch registers and to leave any value in
rdi, rsi and rcx.
Otherwise you'll need to spill to stack for even a simple byte copy loop.
But yes, you want to be able to patch 'rep movsb; nop; nop' over the call.

Two registers might even be enough, one to hold a 'remainder' length and
one for the value being copied.
I think this loop should run at 1 write per clock (two clocks per
iteration):
void _memcpy(void *dst, const void *src, u64 len)
{
	u64 val, rem = len & 15;
	len &= ~15;
	if (len == 0)
		goto short_copy;
	dst += len;
	src += len;
	len = -len;
	do {
		val = src[len];
		dst[len] = val;
		val = src[len + 8];
		dst[len + 8] = val;
	} while (len += 16);
	/* copy trailing bytes */
	val = src[rem - 16];
	dst[rem - 16] = val;
	val = src[rem - 8];
	dst[rem - 8] = val;
	return;
short_copy:
	...
}

I really need to dig out my memcpy() cycle counting code again.

David


		

  reply	other threads:[~2026-11-14 22:45 UTC|newest]

Thread overview: 16+ 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 ` [PATCH v3 1/2] x86/lib: Keep the scalar memcpy() count in RCX Usama Arif
2026-11-11 13:20 ` [PATCH v3 2/2] x86/lib: Use REP MOVSB for large memcpy() on ERMS CPUs without FSRM Usama Arif
2026-11-11 13:56   ` Peter Zijlstra
2026-11-11 23:46   ` Borislav Petkov
2026-11-12  9:37     ` David Laight
2026-11-13 14:31       ` Usama Arif
2026-11-13 14:11     ` Usama Arif
2026-11-13 16:03       ` David Laight
2026-11-13 17:34         ` Linus Torvalds
2026-11-13 18:36           ` H. Peter Anvin
2026-11-13 23:37             ` Borislav Petkov
2026-11-14  2:21               ` H. Peter Anvin
2026-11-14 22:45                 ` David Laight [this message]
2026-11-13 19:42           ` David Laight
2026-11-11 18:19 ` [PATCH v3 0/2] " Kiryl Shutsemau

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=20261114224504.7574f7f0@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.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=usama.arif@linux.dev \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.