Which inline assembly code is correct for rdtscp?

后端 未结 2 769
时光说笑
时光说笑 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: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.

提交回复
热议问题