All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leo Liang <ycliang@andestech.com>
To: u-boot@lists.denx.de
Subject: [PATCH 1/2] riscv: Fix memmove and optimise memcpy when misalign
Date: Tue, 18 May 2021 08:46:16 +0800	[thread overview]
Message-ID: <20210518004616.GA19537@andestech.com> (raw)
In-Reply-To: <20210513084618.2161331-1-bmeng.cn@gmail.com>

On Thu, May 13, 2021 at 04:46:17PM +0800, Bin Meng wrote:
> At present U-Boot SPL fails to boot on SiFive Unleashed board, due
> to a load address misaligned exception happens when loading the FIT
> image in spl_load_simple_fit(). The exception happens in memmove()
> which is called by fdt_splice_().
> 
> Commit 8f0dc4cfd106 introduces an assembly version of memmove but
> it does take misalignment into account (it checks if length is a
> multiple of machine word size but pointers need also be aligned).
> As a result it will generate misaligned load/store for the majority
> of cases and causes significant performance regression on hardware
> that traps misaligned load/store and emulate them using firmware.
> 
> The current behaviour of memcpy is that it checks if both src and
> dest pointers are co-aligned (aka congruent modular SZ_REG). If
> aligned, it will copy data word-by-word after first aligning
> pointers to word boundary. If src and dst are not co-aligned,
> however, byte-wise copy will be performed.
> 
> This patch was taken from the Linux kernel patch [1], which has not
> been applied at the time being. It fixes the memmove and optimises
> memcpy for misaligned cases. It will first align destination pointer
> to word-boundary regardless whether src and dest are co-aligned or
> not. If they indeed are, then wordwise copy is performed. If they
> are not co-aligned, then it will load two adjacent words from src
> and use shifts to assemble a full machine word. Some additional
> assembly level micro-optimisation is also performed to ensure more
> instructions can be compressed (e.g. prefer a0 to t6).
> 
> With this patch, U-Boot boots again on SiFive Unleashed board.
> 
> [1] https://patchwork.kernel.org/project/linux-riscv/patch/20210216225555.4976-1-gary at garyguo.net/
> 
> Fixes: 8f0dc4cfd106 ("riscv: assembler versions of memcpy, memmove, memset")
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> ---

Reviewed-by: Leo Yu-Chi Liang <ycliang@cs.nctu.edu.tw>

      parent reply	other threads:[~2021-05-18  0:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-13  8:46 [PATCH 1/2] riscv: Fix memmove and optimise memcpy when misalign Bin Meng
2021-05-13  8:46 ` [PATCH 2/2] riscv: Group assembly optimized implementation of memory routines into a submenu Bin Meng
2021-05-18  0:48   ` Leo Liang
2021-05-17  2:07 ` [PATCH 1/2] riscv: Fix memmove and optimise memcpy when misalign Bin Meng
2021-05-18  0:46 ` Leo Liang [this message]

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=20210518004616.GA19537@andestech.com \
    --to=ycliang@andestech.com \
    --cc=u-boot@lists.denx.de \
    /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.