public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/62642] New: x86 rdtsc is moved through barrier
@ 2014-09-01 18:16 M8R-ynb11d at mailinator dot com
  2014-09-01 18:24 ` [Bug target/62642] " pinskia at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: M8R-ynb11d at mailinator dot com @ 2014-09-01 18:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62642

            Bug ID: 62642
           Summary: x86 rdtsc is moved through barrier
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: M8R-ynb11d at mailinator dot com

given:

unsigned long long measure(void (*func)(void))
{
    unsigned long long before = __builtin_ia32_rdtsc();
    asm volatile("" ::: "memory");
    func();
    asm volatile("" ::: "memory");
    unsigned long long after = __builtin_ia32_rdtsc();
    return after - before;
}

On x86 linux with -O2, this results in the obviously useless:

measure:
    push    edi
    push    esi
    push    ebx
    call    [DWORD PTR [esp+16]]
    rdtsc
    mov    esi, eax
    mov    edi, edx
    rdtsc
    pop    ebx
    sub    esi, eax
    sbb    edi, edx
    mov    eax, esi
    mov    edx, edi
    pop    esi
    pop    edi
    ret

I can reproduce the problem on 32 bit x86 on Linux and MinGW with 4.8.2 and
4.9.1. (I guess 4.8.0 also exhibits the problem but I don't have that available
for testing, so I set the version to 4.8.2 in the report.)

4.7.x and 4.6.x work correctly, as does 64 bit on both platforms.

If this is not the proper sanctioned way to write this function, I'm all ears
to a better way.  I've tried also adding calls to __builtin_ia32_mfence() which
as I understand it should not be necessary, and it gets even more comical:

        ...
    mfence
    call    [DWORD PTR [esp+16]]
    mfence
    rdtsc
    mov    esi, eax
    mov    edi, edx
    rdtsc
        ...


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2015-06-12 11:58 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-01 18:16 [Bug target/62642] New: x86 rdtsc is moved through barrier M8R-ynb11d at mailinator dot com
2014-09-01 18:24 ` [Bug target/62642] " pinskia at gcc dot gnu.org
2014-11-19 13:28 ` [Bug target/62642] [4.8/4.9 Regression] " rguenth at gcc dot gnu.org
2014-12-10 13:10 ` [Bug target/62642] [4.8/4.9/5 " rguenth at gcc dot gnu.org
2014-12-13  4:09 ` vmakarov at gcc dot gnu.org
2014-12-15 20:04 ` vmakarov at gcc dot gnu.org
2014-12-17 10:35 ` M8R-ynb11d at mailinator dot com
2014-12-19 13:44 ` jakub at gcc dot gnu.org
2015-01-12 10:10 ` [Bug target/62642] [4.8/4.9 " rguenth at gcc dot gnu.org
2015-06-12  8:01 ` jakub at gcc dot gnu.org
2015-06-12 11:55 ` jakub at gcc dot gnu.org
2015-06-12 11:55 ` jakub at gcc dot gnu.org
2015-06-12 11:58 ` jakub at gcc dot gnu.org

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).