From: Simon Kagstrom <simon.kagstrom@netinsight.net>
To: Nicolas Pitre <nico@cam.org>
Cc: linux-mtd@lists.infradead.org
Subject: Re: [PATCH] Orion NAND: Make dword load asm volatile to avoid GCC optimizing it away
Date: Wed, 19 Aug 2009 09:45:35 +0200 [thread overview]
Message-ID: <20090819094535.558dc0df@marrow.netinsight.se> (raw)
In-Reply-To: <alpine.LFD.2.00.0907141236160.3138@xanadu.home>
On Tue, 14 Jul 2009 12:40:33 -0400 (EDT)
Nicolas Pitre <nico@cam.org> wrote:
> On Tue, 14 Jul 2009, Simon Kagstrom wrote:
>
> > GCC 4.3.3 happily removes the dword load instruction in
> > orion_nand_read_buf. This patch makes the inline assembly volatile to
> > avoid this situation.
>
> If GCC does optimize away this inline asm then this is a serious GCC
> bug. The inline asm uses an output operand for which a dependency
> exists on the very next line.
I've been away on vacation, sorry for not replying until now.
Anyway, I spoke to the GCC people at gcc-help, and they insist that the
inlined assembly is wrong. The problem is that GCC doesn't infer from
the instruction that it accesses memory, and it can thereby move it out
of the loop.
So here comes an updated patch.
// Simon
--
Orion NAND: Clobber memory to make sure that GCC does not move ldrd
GCC 4.3.3 happily removes the dword load instruction in
orion_nand_read_buf. This patch clobbers memory, and makes the
instruction volatile to avoid the issue. I've discussed this at
gcc-help, refer to the thread at
http://gcc.gnu.org/ml/gcc-help/2009-08/msg00187.html
Signed-off-by: Simon Kagstrom <simon.kagstrom@netinsight.net>
---
drivers/mtd/nand/orion_nand.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
index 7ad9722..845f9a9 100644
--- a/drivers/mtd/nand/orion_nand.c
+++ b/drivers/mtd/nand/orion_nand.c
@@ -61,7 +61,7 @@ static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
buf64 = (uint64_t *)buf;
while (i < len/8) {
uint64_t x;
- asm ("ldrd\t%0, [%1]" : "=r" (x) : "r" (io_base));
+ asm volatile ("ldrd\t%0, [%1]" : "=&r" (x) : "r" (io_base) : "memory");
buf64[i++] = x;
}
i *= 8;
--
1.6.0.4
next prev parent reply other threads:[~2009-08-19 7:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-14 14:41 [PATCH] Orion NAND: Make dword load asm volatile to avoid GCC optimizing it away Simon Kagstrom
2009-07-14 16:40 ` Nicolas Pitre
2009-08-19 7:45 ` Simon Kagstrom [this message]
2009-08-19 14:47 ` Nicolas Pitre
2009-08-20 7:19 ` Simon Kagstrom
2009-08-20 16:14 ` Nicolas Pitre
2009-08-21 6:07 ` Simon Kagstrom
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=20090819094535.558dc0df@marrow.netinsight.se \
--to=simon.kagstrom@netinsight.net \
--cc=linux-mtd@lists.infradead.org \
--cc=nico@cam.org \
/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