-3

I have to interpret some c-code as a kind of homework and I don't really understand this macro:

#define rdtscll(val)__asm__ __volatile__("rdtsc":"=A"(val))

I know it's some kind of static function named rdtscll which receives one parameter val. But what about the rest?

  • What are __asm__ and __volatile__ and why those underscores?
  • are those 2 different constants separated by a space?
Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
Hansi Zimmrer
  • 249
  • 1
  • 4
  • 17

1 Answers1

2

In this case __asm__ and __volatile__ are compiler extensions for embedding assembly statements into a C file. The two leading underscores are to prevent clashes with identifiers in user code, and the trailing are pure choice. __volatile__ is just an "anti-optimization" directive.

rdtsc is an x86 instruction for reading the Time-Stamp Counter, a very high-speed counter based on clock cycles. "=A" is part of the GCC inline assembly syntax - there are plenty of references explaining more about it.

Drew McGowen
  • 11,471
  • 1
  • 31
  • 57