public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* undocumented rdtsc functions
@ 2021-07-25 21:44 NightStrike
  2021-07-25 22:41 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: NightStrike @ 2021-07-25 21:44 UTC (permalink / raw)
  To: gcc-help

Where does GCC document how to use the builtin rdtsc and rdtscp functions?

Looking at ia32intrin.h, I can see it defined as:

/* rdtsc */
#define __rdtsc() __builtin_ia32_rdtsc ()

...

/* rdtscp */
#define __rdtscp(a) __builtin_ia32_rdtscp (a)

But the top of that file states:

#ifndef _X86GPRINTRIN_H_INCLUDED
# error "Never use <ia32intrin.h> directly; include <x86gprintrin.h> instead."
#endif

Namely, I'm interesting in knowing:

1) What the return type of the two functions are
2) What the 'a' arg is to the second
3) If using these includes serializing calls to lfence or similar

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

* Re: undocumented rdtsc functions
  2021-07-25 21:44 undocumented rdtsc functions NightStrike
@ 2021-07-25 22:41 ` Jonathan Wakely
  2021-07-26  0:39   ` NightStrike
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2021-07-25 22:41 UTC (permalink / raw)
  To: NightStrike; +Cc: gcc-help

On Sun, 25 Jul 2021, 22:46 NightStrike via Gcc-help, <gcc-help@gcc.gnu.org>
wrote:

> Where does GCC document how to use the builtin rdtsc and rdtscp functions?
>

It doesn't, see the Intel Intrinsics Guide:
https://software.intel.com/sites/landingpage/IntrinsicsGuide/

Search for __rdtscp there.


> Looking at ia32intrin.h, I can see it defined as:
>
> /* rdtsc */
> #define __rdtsc() __builtin_ia32_rdtsc ()
>
> ...
>
> /* rdtscp */
> #define __rdtscp(a) __builtin_ia32_rdtscp (a)
>
> But the top of that file states:
>
> #ifndef _X86GPRINTRIN_H_INCLUDED
> # error "Never use <ia32intrin.h> directly; include <x86gprintrin.h>
> instead."
> #endif
>
> Namely, I'm interesting in knowing:
>
> 1) What the return type of the two functions are
> 2) What the 'a' arg is to the second
> 3) If using these includes serializing calls to lfence or similar
>

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

* Re: undocumented rdtsc functions
  2021-07-25 22:41 ` Jonathan Wakely
@ 2021-07-26  0:39   ` NightStrike
  0 siblings, 0 replies; 3+ messages in thread
From: NightStrike @ 2021-07-26  0:39 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help

On Sun, Jul 25, 2021 at 6:41 PM Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On Sun, 25 Jul 2021, 22:46 NightStrike via Gcc-help, <gcc-help@gcc.gnu.org> wrote:
>>
>> Where does GCC document how to use the builtin rdtsc and rdtscp functions?
>
> It doesn't, see the Intel Intrinsics Guide:
> https://software.intel.com/sites/landingpage/IntrinsicsGuide/
>
> Search for __rdtscp there.

Interesting, thanks!

Strangely:

__int64 _rdtsc (void)
#include <immintrin.h>

unsigned __int64 __rdtscp (unsigned int * mem_addr)
#include <immintrin.h>

Any idea why rdtsc would return a signed value?

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

end of thread, other threads:[~2021-07-26  0:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-25 21:44 undocumented rdtsc functions NightStrike
2021-07-25 22:41 ` Jonathan Wakely
2021-07-26  0:39   ` NightStrike

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 read-only IMAP folder(s) and NNTP newsgroup(s).