public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: Evan Green <evan@rivosinc.com>, libc-alpha@sourceware.org
Cc: slewis@rivosinc.com, vineetg@rivosinc.com, palmer@rivosinc.com
Subject: Re: [PATCH 2/2] riscv: Add and use alignment-ignorant memcpy
Date: Mon, 6 Feb 2023 12:05:59 -1000	[thread overview]
Message-ID: <085bfca3-cacd-ea57-bde3-1d84f07aaeda@linaro.org> (raw)
In-Reply-To: <20230206194819.1679472-3-evan@rivosinc.com>

On 2/6/23 09:48, Evan Green wrote:
> +	/* Remainder is smaller than a page, compute native word count */
> +	beqz a2, 6f
> +	andi a5, a2, ~(SZREG-1)
> +	andi a2, a2, (SZREG-1)
> +	add a3, a1, a5
> +	/* Jump directly to byte copy if no words. */
> +	beqz a5, 4f
> +
> +3:
> +	/* Use single native register copy */
> +	REG_L a4, 0(a1)
> +	addi a1, a1, SZREG
> +	REG_S a4, 0(t6)
> +	addi t6, t6, SZREG
> +	bltu a1, a3, 3b
> +
> +	/* Jump directly out if no more bytes */
> +	beqz a2, 6f
> +
> +4:
> +	/* Copy the last few individual bytes */
> +	add a3, a1, a2
> +5:
> +	lb a4, 0(a1)
> +	addi a1, a1, 1
> +	sb a4, 0(t6)
> +	addi t6, t6, 1
> +	bltu a1, a3, 5b
> +6:
> +	ret

If you know there are at least SZREG bytes in the range, you can avoid the byte loop by 
copying the last word unaligned.  That may copy some bytes twice, but that's ok too. 
Similarly, you can redundantly copy a few bytes at the beginning to align the destination 
(there's usually some cost for unaligned stores, even if it's generally "fast").

For memcpy < SZREG, you don't need a loop; just test the final few bits of len.
Have a look at the tricks in sysdeps/x86_64/multiarch/memmove-ssse3.S for ideas.


r~

  reply	other threads:[~2023-02-06 22:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-06 19:48 [PATCH 0/2] RISC-V: ifunced memcpy using new kernel hwprobe interface Evan Green
2023-02-06 19:48 ` [PATCH 1/2] riscv: Add Linux hwprobe syscall support Evan Green
2023-02-07 13:05   ` Adhemerval Zanella Netto
2023-02-09 20:55     ` Evan Green
2023-02-12 16:58     ` Jeff Law
2023-02-06 19:48 ` [PATCH 2/2] riscv: Add and use alignment-ignorant memcpy Evan Green
2023-02-06 22:05   ` Richard Henderson [this message]
2023-02-09 21:04     ` Evan Green
2023-02-06 21:28 ` [PATCH 0/2] RISC-V: ifunced memcpy using new kernel hwprobe interface Richard Henderson
2023-02-07 12:49   ` Adhemerval Zanella Netto

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=085bfca3-cacd-ea57-bde3-1d84f07aaeda@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=evan@rivosinc.com \
    --cc=libc-alpha@sourceware.org \
    --cc=palmer@rivosinc.com \
    --cc=slewis@rivosinc.com \
    --cc=vineetg@rivosinc.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).