kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* How to comprehend this code snippet: __asm__ __volatile__("rdtsc" : "=A"(t))?
@ 2020-07-16 12:20 孙世龙 sunshilong
  2020-07-16 12:52 ` Jeffrey Walton
  0 siblings, 1 reply; 4+ messages in thread
From: 孙世龙 sunshilong @ 2020-07-16 12:20 UTC (permalink / raw)
  To: kernelnewbies

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to comprehend this code snippet: __asm__ __volatile__("rdtsc" : "=A"(t))?
  2020-07-16 12:20 How to comprehend this code snippet: __asm__ __volatile__("rdtsc" : "=A"(t))? 孙世龙 sunshilong
@ 2020-07-16 12:52 ` Jeffrey Walton
  2020-07-16 13:24   ` 孙世龙 sunshilong
  0 siblings, 1 reply; 4+ messages in thread
From: Jeffrey Walton @ 2020-07-16 12:52 UTC (permalink / raw)
  To: 孙世龙 sunshilong; +Cc: kernelnewbies

On Thu, Jul 16, 2020 at 8:22 AM 孙世龙 sunshilong <sunshilong369@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

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to comprehend this code snippet: __asm__ __volatile__("rdtsc" : "=A"(t))?
  2020-07-16 12:52 ` Jeffrey Walton
@ 2020-07-16 13:24   ` 孙世龙 sunshilong
  2020-07-16 13:42     ` Jeffrey Walton
  0 siblings, 1 reply; 4+ messages in thread
From: 孙世龙 sunshilong @ 2020-07-16 13:24 UTC (permalink / raw)
  To: noloader; +Cc: kernelnewbies

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 <noloader@gmail.com> wrote:
>
> On Thu, Jul 16, 2020 at 8:22 AM 孙世龙 sunshilong <sunshilong369@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

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to comprehend this code snippet: __asm__ __volatile__("rdtsc" : "=A"(t))?
  2020-07-16 13:24   ` 孙世龙 sunshilong
@ 2020-07-16 13:42     ` Jeffrey Walton
  0 siblings, 0 replies; 4+ messages in thread
From: Jeffrey Walton @ 2020-07-16 13:42 UTC (permalink / raw)
  To: 孙世龙 sunshilong; +Cc: kernelnewbies

On Thu, Jul 16, 2020 at 9:25 AM 孙世龙 sunshilong <sunshilong369@gmail.com> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-16 13:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-16 12:20 How to comprehend this code snippet: __asm__ __volatile__("rdtsc" : "=A"(t))? 孙世龙 sunshilong
2020-07-16 12:52 ` Jeffrey Walton
2020-07-16 13:24   ` 孙世龙 sunshilong
2020-07-16 13:42     ` Jeffrey Walton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).