From: Chung-Ju Wu <jasonwucj@gmail.com>
To: dw <limegreensocks@yahoo.com>, Ian Lance Taylor <iant@google.com>
Cc: "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
Subject: Re: Question about __builtin_ia32_mfence and memory barriers
Date: Thu, 13 Jun 2013 03:01:00 -0000 [thread overview]
Message-ID: <CADj25HMLDCnega78z56y_MtzE3r7XuDDwYgAHQu5dBBPnmNxiQ@mail.gmail.com> (raw)
In-Reply-To: <CAKOQZ8yhsN2pfitYUdrvbPpAXtPFZYiGGfAkj+N61DzO5tryGw@mail.gmail.com>
2013/6/13 Ian Lance Taylor <iant@google.com>:
> On Wed, Jun 12, 2013 at 1:15 AM, dw <limegreensocks@yahoo.com> wrote:
[deleted]
>> In fact, I *can* generate failure cases if I comment the
>> __builtin_ia32_mfence() call out of _mm_mfence and replace it with something
>> else (like asm("mfence")). But as soon as I put the __builtin_ia32_mfence
>> call back in, my "failure scenario" clears right up.
>>
>> In short, it looks like __builtin_ia32_mfence *does* generate a barrier.
>> But so do other builtins (like __builtin_ia32_pause). Does that even seem
>> possible? It would be weird if every builtin (or even every ia32 builtin)
>> implied a barrier.
[deleted]
>
> So when I say that as far as I know __builtin_ia32_mfence does not
> generate a barrier, what I mean is that as far as I know after it is
> expanded to RTL there is no barrier. But I could be wrong.
>
> Ian
I just noticed there is a statement "MEM_VOLATILE_P(operands[0]=1"
for mfence pattern in gcc/config/i386/sync.md:
(define_expand "sse2_mfence"
[(set (match_dup 0)
(unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))]
"TARGET_SSE2"
{
operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
MEM_VOLATILE_P (operands[0]) = 1;
})
And so does "pause" pattern in gcc/config/i386/i386.md:
(define_expand "pause"
[(set (match_dup 0)
(unspec:BLK [(match_dup 0)] UNSPEC_PAUSE))]
""
{
operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
MEM_VOLATILE_P (operands[0]) = 1;
})
According to GCC Internal 10.5, the description says that
"Volatile memory references may not be deleted, reordered or combined."
I think that is why __builtin_ia32_mfence and __builtin_ia32_pause *do*
generate a barrier in dw's experiment.
Best regards,
jasonwucj
next prev parent reply other threads:[~2013-06-13 3:01 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-04 22:58 dw
2013-06-04 23:52 ` Ian Lance Taylor
2013-06-05 2:45 ` dw
2013-06-05 4:30 ` Ian Lance Taylor
2013-06-12 8:15 ` dw
2013-06-12 19:01 ` Ian Lance Taylor
2013-06-13 2:55 ` dw
2013-06-13 3:01 ` Chung-Ju Wu [this message]
2013-06-13 3:25 ` Ian Lance Taylor
2013-06-13 3:44 ` dw
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=CADj25HMLDCnega78z56y_MtzE3r7XuDDwYgAHQu5dBBPnmNxiQ@mail.gmail.com \
--to=jasonwucj@gmail.com \
--cc=gcc-help@gcc.gnu.org \
--cc=iant@google.com \
--cc=limegreensocks@yahoo.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).