This is the mail archive of the
mailing list for the GCC project.
AW: basic asm and memory clobbers - Proposed solution
- From: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- To: David Wohlferd <dw at LimeGreenSocks dot com>, "Paul_Koning at Dell dot com" <Paul_Koning at Dell dot com>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Wed, 2 Dec 2015 07:51:01 +0000
- Subject: AW: basic asm and memory clobbers - Proposed solution
- Authentication-results: sourceware.org; auth=none
- Authentication-results: gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=none action=none header.from=hotmail.de;
- References: <56552209 dot 1020306 at LimeGreenSocks dot com> <56592801 dot 9010606 at LimeGreenSocks dot com> <HE1PR07MB09050E30BB6C251DBB454790E4020 at HE1PR07MB0905 dot eurprd07 dot prod dot outlook dot com> <9EAD225F-1323-439F-B697-C90F86F1D959 at dell dot com> <565B8FE2 dot 7000500 at LimeGreenSocks dot com> <2C1A50C8-AC7B-4E9E-BE5D-8CAB7AB8BDDC at dell dot com>,<565E1ED6 dot 6060505 at LimeGreenSocks dot com>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:23
On 1.12.2015, David Wohlferd wrote:
On 12/1/2015 10:10 AM, Bernd Edlinger wrote:
> > But IMHO asm("bla":) isn't any better than asm("bla").
> > I think _any_ asm with non-empty assembler string, that
> > claims to clobber _nothing_ is highly suspicious, and worth to be
> > warned about. I don't see any exceptions from this rule.
> There's one right now in the basic asm docs: asm("int $3");
> And I've seen others: asm volatile ("nop"), asm(".byte 0xf1\n"). I've
> seen a bunch more, but you get the idea.
Consider this example where "nop" should be injected
to guarantee a minimum pulse length:
x = 1;
asm volatile ("nop");
x = 0;
resulting code at -O2 is something like this:
That is because this asm statement allows
gcc to move the assembler code anywhere.
It is only guaranteed to be executed once,
but it not guaranteed to be executed between
the two assignments. To avoid that we have
to use a "memory" clobber.