From mboxrd@z Thu Jan 1 00:00:00 1970 From: Leo Liang Date: Tue, 18 May 2021 08:46:16 +0800 Subject: [PATCH 1/2] riscv: Fix memmove and optimise memcpy when misalign In-Reply-To: <20210513084618.2161331-1-bmeng.cn@gmail.com> References: <20210513084618.2161331-1-bmeng.cn@gmail.com> Message-ID: <20210518004616.GA19537@andestech.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 > --- Reviewed-by: Leo Yu-Chi Liang