Which inline assembly code is correct for rdtscp?

后端 未结 2 762
时光说笑
时光说笑 2020-12-01 14:40

Disclaimer: Words cannot describe how much I detest AT&T style syntax

I have a problem that I hope is caused by register clobbering. If not, I have a much bigger

相关标签:
2条回答
  • 2020-12-01 15:23

    According to this, this operation clobbers EDX and ECX. You need to mark those registers as clobbered which is what the second one does. BTW, is this the link where you got the above code or did you find it elsewhere? It also shows a few other variaitions for timings as well which is pretty neat.

    0 讨论(0)
  • 2020-12-01 15:35

    Here's C++ code that will return the TSC and store the auxiliary 32-bits into the reference parameter

    static inline uint64_t rdtscp( uint32_t & aux )
    {
        uint64_t rax,rdx;
        asm volatile ( "rdtscp\n" : "=a" (rax), "=d" (rdx), "=c" (aux) : : );
        return (rdx << 32) + rax;
    }
    

    It is better to do the shift and add to merge both 32-bit halves in C++ statement rather than inline, this allows the compiler to schedule those instructions as it sees fit.

    0 讨论(0)
提交回复
热议问题