ptwrite intrinsic ordering guarantees

77 Views Asked by At

When using the Intel processor trace ptwrite logging instruction for tracing and possibly timestamping like this:

// compile with: -mptwrite

#include <x86gprintrin.h>

void foo()
{
    // ...
    _ptwrite64(a);
    // ...
    f();
    // ...
    _ptwrite64(b);
    // ...
}

What are the ordering guarantees gcc and clang provide for the _ptwrite64 intrnsic?

Does the ptwrite intrinsic (and/or the __builtin_ia32_ptwrite64 builtin it wraps, as of gcc 13) acts as a compiler barrier?

Or does gcc (or clang) allows itself to simply reorder the f() function call before _ptwrite64(a) (or after _ptwrite64(b))?

If ptwrite doesn't work as a compiler barrier, is switching to inline assembler (with the right annotations) the next best thing for creating a compiler barrier?

Otherwise, is there a way for a builtin/intrinsic to look up whether it acts as a compiler barrier?

0

There are 0 best solutions below