Re: How to comprehend this code snippet: __asm__ __volatile__("rdtsc" : "=A"(t))?
On Thu, Jul 16, 2020 at 9:25 AM 孙世龙 sunshilong wrote: > > >The 'A' is the constraint EAX:RDX register pair. > >Also see https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html > >and https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html. > Thanks to your attached document, I find a lot of useful information. > BTW, What does "The A register", "The B register" and etc mean? > I googled but didn't get any useful information. > Could you please give me a few brief explanations or suggest some > documents for me to go through? See the docs for the various constraints. Also see https://gcc.gnu.org/onlinedocs/gcc/Constraints.html#Constraints. Jeff ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: How to comprehend this code snippet: __asm__ __volatile__("rdtsc" : "=A"(t))?
Hi, Jeff Thank you for taking the time to respond to my question. Thanks to your help, I have a deeper understanding of this matter. >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. Thank you for your notification. I check it and find it's for X86_32. I didn't notice such differences before. Here is the full related code snippet: #ifdef CONFIG_X86_32 #define ipipe_read_tsc(t) \ __asm__ __volatile__("rdtsc" : "=A"(t)) #else /* X86_64 */ #define ipipe_read_tsc(t) do {\ unsigned int __a,__d; \ asm volatile("rdtsc" : "=a" (__a), "=d" (__d)); \ (t) = ((unsigned long)__a) | (((unsigned long)__d)<<32); \ } while(0) #endif >The 'A' is the constraint EAX:RDX register pair. >Also see https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html >and https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html. Thanks to your attached document, I find a lot of useful information. BTW, What does "The A register", "The B register" and etc mean? I googled but didn't get any useful information. Could you please give me a few brief explanations or suggest some documents for me to go through? Thank you for your attention to this matter. Looking forward to hearing from you. Best Wishes. sunshilong On Thu, Jul 16, 2020 at 8:52 PM Jeffrey Walton wrote: > > On Thu, Jul 16, 2020 at 8:22 AM 孙世龙 sunshilong > 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 ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: How to comprehend this code snippet: __asm__ __volatile__("rdtsc" : "=A"(t))?
On Thu, Jul 16, 2020 at 8:22 AM 孙世龙 sunshilong 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 ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
How to comprehend this code snippet: __asm__ __volatile__("rdtsc" : "=A"(t))?
Hi, list Here is the code snippet: #define ipipe_read_tsc(t) \ __asm__ __volatile__("rdtsc" : "=A"(t)) 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? Thank you for your attention to this matter. ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies