What is the gcc cpu-type that includes support for RDTSCP?
Asked Answered
L

1

3

I am using RDTSCP to replace LFENCE;RDTSC sequences and also get the processor ID back so that I know when I'm comparing TSC values after the thread was rescheduled to another CPU.

To ensure I don't run RDTSCP on a too old machine I fallback to RDTSC after a CPUID check (using libcpuid). I'd like to try using the gcc multiple target attribute functionality instead of a CPUID call:

int core2_func (void) __attribute__ ((__target__ ("arch=core2")));

The gcc manual lists a number of cpu families (haswell, skylake, ...). How would I find which cpu family first introduced RDTSCP?

Lickspittle answered 7/6, 2016 at 15:2 Comment(5)
Intel's instruction-set manual (see the x86 tag wiki, or this HTML extract) only tells you what CPUID feature-bit to check for each instruction. (Only documenting things by microarchitecture for things that predate CPUID in p5). To find what CPU introduced what instruction, I normally check Wikipedia.Exultation
en.wikipedia.org/wiki/Time_Stamp_Counter hasn't been useful here, though. Maybe look in a table of CPUID dumps if one exists, and check the feature bit. Of course, if you're actually running a CPUID instruction in your program at runtime, you should just check the specified feature bit.Exultation
Using the ifunc attribute directly, you can specify your own resolver, in particular one testing the appropriate cpuid bit, instead of relying on the predefined targets.Grenadines
Looks like clang doesn't implement the gcc target attribute (nor does it implement the ifunc attribute that Marc mentioned in his comment), so I won't be able to exploit this even if I knew the right arch setting to use.Lickspittle
clang.llvm.org/docs/AttributeReference.html#target-gnu-target (the doc doesn't mention multiple targets, so I don't know if that's supported) clang.llvm.org/docs/AttributeReference.html#ifunc-gnu-ifunc (if you are using a Mac, too bad for you)Grenadines
S
1

All AMD processors since the K8 Hammer support RDTSCP.

On Intel processors, RDTSCP is supported on Nehalem and later, Silvermont and later, and Knights Landing and later.

Scourings answered 21/2, 2019 at 19:50 Comment(7)
I found this question while looking for duplicates for Detect if processor has RDTSCP at compile time as well. That's good info about what HW has what, but if you're doing this hopefully you can get GCC to dispatch based on a custom CPUID bit like Marc Glisse suggested.Exultation
But it will have to be a custom bit, because I don't think GCC "knows about" that feature bit. It doesn't stop you from using __builtin_ia32_rdtscp() / __rdtscp() (or rdpmc) the way it does for most other intrinsics, when compiling for -march=core2 or generic. I don't think GCC "knows" which CPUs support it, and definitely doesn't define any macros with -march=native vs. baseline.Exultation
@PeterCordes Right. I've posted an answer there.Scourings
@HadiBrais According to LIBC all processors since 2010 support it.Farhi
@Farhi Incorrect. There are a few x86 processors since 2010 that don't support RDTSCP, such as the Intel Saltwell (all models).Scourings
@HadiBrais Ahh, I'll fix the comment. Know where I can find the documentation on intel saltwell referencing rdtscp?Farhi
@Farhi Unlike the AMD docs, the Intel datasheets don't contain CPUID dumps. You can refer to InstLatx64 instead. RDTSCP support is indicated by CPUID[8000_0001].EDX[27] on Intel and AMD processors.Scourings

© 2022 - 2024 — McMap. All rights reserved.