How to comprehend this code snippet: __asm__ __volatile__("rdtsc" : "=A"(t))?

Jeffrey Walton noloader at gmail.com
Thu Jul 16 08:52:11 EDT 2020


On Thu, Jul 16, 2020 at 8:22 AM 孙世龙 sunshilong <sunshilong369 at gmail.com> wrote:
>
> Here is the code snippet:
> #define ipipe_read_tsc(t)              \
> __asm__ __volatile__("rdtsc" : "=A"(t))

I hope that is i386 only, and not x86_64.

> I found that the rdtsc (Read Time-Stamp Counter) instruction is used
> to determine how many CPU ticks took place since the processor was
> reset.
>
> But what does
> "=A"(t)
> mean?

The '=A' is a GCC machine constraint for i386 and an output operand.
The 'A' is the constraint EAX:RDX register pair. The '=' means it is
being written to.

Also see https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html
and https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html.

Also read the note in the Machine Constraints for:

    unsigned long long rdtsc (void)
    {
      unsigned long long tick;
      __asm__ __volatile__("rdtsc":"=A"(tick));
      return tick;
    }

The manual says the pattern is wrong for x86_64.

Jeff



More information about the Kernelnewbies mailing list