[PATCH] riscv: Fix alignment-ignorant memcpy implementation

Palmer Dabbelt palmer@rivosinc.com
Mon Mar 4 18:49:09 GMT 2024


On Mon, 04 Mar 2024 10:30:10 PST (-0800), adhemerval.zanella@linaro.org wrote:
>
>
> On 04/03/24 15:28, Adhemerval Zanella Netto wrote:
>>
>>
>> On 04/03/24 15:24, Andreas Schwab wrote:
>>> On Mär 04 2024, Adhemerval Zanella wrote:
>>>
>>>> Also, there is no reason why the implementation can't be coded in C,
>>>> since it uses only normal registers and the compiler is able to
>>>> generate code as good as the assembly implementation.  I have not
>>>> checked the performance, but the C implementation uses the same
>>>> strategies, the generate code with gcc 13 seems straightforward, and
>>>> the tail code also avoid byte-operations.
>>>
>>> RISC-V is a strict-alignment target, and there is a non-zero chance that
>>> the C compiler messes this up.
>>>
>>
>> I am aware, but there is other project that successfully provides C
>> implementation (musl, for instance, where it optimizes for aligned
>> access) so I think if this implementation does have any mistake this
>> should not be considered a blocked for this change.
>
> Maybe we should force -mno-strict-align for the unaligned implementation.

I think that should do it, we'd had it as at outstanding TODO for a 
while but nobody had gotten around to benchmarking it.

>From your other email it looks like these are just broken, though, so 
maybe we just move to the C ones now?  Then anyone who wants to add 
assembly can benchmark it, but at least we'll have something correct.


More information about the Libc-alpha mailing list