From: Alexander Monakov <amonakov@ispras.ru>
To: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Cc: Vineet Gupta <vineetg@rivosinc.com>,
Andreas Schwab <schwab@linux-m68k.org>,
libc-alpha@sourceware.org, Evan Green <evan@rivosinc.com>,
palmer@rivosinc.com, slewis@rivosinc.com
Subject: Re: [PATCH] riscv: Fix alignment-ignorant memcpy implementation
Date: Mon, 4 Mar 2024 23:13:22 +0300 (MSK) [thread overview]
Message-ID: <b7ac4948-4556-5857-cdd4-72e1e21b8e45@ispras.ru> (raw)
In-Reply-To: <f3220853-0b2f-45ca-846c-ac1cdfeefa0b@linaro.org>
On Mon, 4 Mar 2024, Adhemerval Zanella Netto wrote:
> >> How does gcc optimization and strict-align plays with __may_alias__ it
> >> would still tries to generated aligned access in this case?
may_alias does not imply reduced alignment: this is necessary to avoid
penalizing correct code that forms properly aligned aliased pointers.
Like with may_alias, you can typedef a reduced-alignment type:
typedef op_t misal_op_t __attribute__((aligned(1)));
> Right, so the question is whether compiler will really mess the unaligned
> code using __may_alias__ and if we really should keep the implementation as
> a assembly one.
As always, if you lie to the compiler, you get to keep the pieces.
The solution here, if you know that a particular instruction works fine
to perform a misaligned load, and the compiler doesn't expose it, is
to make a simple asm wrapper:
static inline
op_t load(void *p)
{
typedef op_t misal_op_t __attribute__((aligned(1)));
op_t r;
asm("lw %0, %1" : "=r"(r) : "m"(*(misal_op_t *)p));
return r;
}
Alexander
next prev parent reply other threads:[~2024-03-04 20:13 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-04 17:59 Adhemerval Zanella
2024-03-04 18:01 ` Adhemerval Zanella Netto
2024-03-04 18:24 ` Andreas Schwab
2024-03-04 18:28 ` Adhemerval Zanella Netto
2024-03-04 18:30 ` Adhemerval Zanella Netto
2024-03-04 18:35 ` Adhemerval Zanella Netto
2024-03-04 18:49 ` Palmer Dabbelt
2024-03-04 19:04 ` Vineet Gupta
2024-03-04 19:07 ` Adhemerval Zanella Netto
2024-03-04 19:30 ` Vineet Gupta
2024-03-04 19:53 ` Adhemerval Zanella Netto
2024-03-04 20:13 ` Alexander Monakov [this message]
2024-03-04 20:22 ` 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=b7ac4948-4556-5857-cdd4-72e1e21b8e45@ispras.ru \
--to=amonakov@ispras.ru \
--cc=adhemerval.zanella@linaro.org \
--cc=evan@rivosinc.com \
--cc=libc-alpha@sourceware.org \
--cc=palmer@rivosinc.com \
--cc=schwab@linux-m68k.org \
--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).