RDTSCP from dlang

Basile B. via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 30 02:04:41 PDT 2016


On Tuesday, 30 August 2016 at 02:04:55 UTC, kookman wrote:
> I need to access the x86_64 RDTSCP assembly instruction from D.
>
> I found this for C++:
> http://stackoverflow.com/questions/14783782/which-inline-assembly-code-is-correct-for-rdtscp
>
> Does anyone here know how (if?) I can do this from D?

ALternatively to Rikki K's solution, you can do this to mimic the 
rdtscp behavior:

asm
{
   cpuid;
   rdtsc;
   // store time in locals
}
// bench
{
   rdtsc;
   // store time in locals
}
// compute delta


explanations here:
- 
http://www.intel.com/content/dam/www/public/us/en/documents/white-papers/ia-32-ia-64-benchmark-code-execution-paper.pdf
- http://stackoverflow.com/a/14214220

But according to the first link, this solution, while better than 
rdtsc alone, is not as good as rdtscp.


More information about the Digitalmars-d-learn mailing list