digitalmars.D.learn - RDTSCP from dlang
- kookman (4/4) Aug 29 2016 I need to access the x86_64 RDTSCP assembly instruction from D.
- rikki cattermole (10/14) Aug 29 2016 It appears dmd's inline assembler does not support it.
- Basile B. (21/25) Aug 30 2016 ALternatively to Rikki K's solution, you can do this to mimic the
- kookman (8/28) Aug 31 2016 Indeed, I want to use rdtscp to get access to the core ID it
- rikki cattermole (2/34) Aug 31 2016 http://dlang.org/spec/abi.html#register_conventions
- kookman (6/7) Aug 31 2016 That link talks about for functions defined extern(C) and
- rikki cattermole (7/13) Aug 31 2016 That link describes extern(D) for x86(_64) for all platforms. Keep in
- Basile B. (6/12) Aug 31 2016 Never mind, I know Rikki's solution is better but since I've read
- kookman (3/5) Aug 31 2016 Someone beat me to it, but see here:
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?
Aug 29 2016
On 30/08/2016 2:04 PM, 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?It appears dmd's inline assembler does not support it. So a workaround: asm { // rdtscp db 0x0F; db 0x01; db 0xF9; } http://dlang.org/spec/iasm.html
Aug 29 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.
Aug 30 2016
On Tuesday, 30 August 2016 at 09:04:41 UTC, Basile B. wrote: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.Indeed, I want to use rdtscp to get access to the core ID it makes available (to at least know when tsc is from different cores/packages). I guess in the meantime I can use Rikki's solution. Sorry I'm a DMD asm newbie: DO i need to worry about which registers I clobber here? I couldn't find any info about this on the Inline Assembly doco page on dlang.org.
Aug 31 2016
On 31/08/2016 7:34 PM, kookman wrote:On Tuesday, 30 August 2016 at 09:04:41 UTC, Basile B. wrote:http://dlang.org/spec/abi.html#register_conventionsALternatively 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.Indeed, I want to use rdtscp to get access to the core ID it makes available (to at least know when tsc is from different cores/packages). I guess in the meantime I can use Rikki's solution. Sorry I'm a DMD asm newbie: DO i need to worry about which registers I clobber here? I couldn't find any info about this on the Inline Assembly doco page on dlang.org.
Aug 31 2016
On Wednesday, 31 August 2016 at 07:36:16 UTC, rikki cattermole wrote:http://dlang.org/spec/abi.html#register_conventionsThat link talks about for functions defined extern(C) and extern(D), and gives specific info for win32. I'm using linux x86_64, does that mean I can assume standard x86_64 ABI? ie even if the function is not extern?
Aug 31 2016
On 31/08/2016 7:49 PM, kookman wrote:On Wednesday, 31 August 2016 at 07:36:16 UTC, rikki cattermole wrote:That link describes extern(D) for x86(_64) for all platforms. Keep in mind if a function body does not have an extern(X) supplied, the default is extern(D). C is listed there as we have first class C interaction via extern(C). The listing of DLL's on that page really should be changed to dynamic libraries. Since that covers linuxes.http://dlang.org/spec/abi.html#register_conventionsThat link talks about for functions defined extern(C) and extern(D), and gives specific info for win32. I'm using linux x86_64, does that mean I can assume standard x86_64 ABI? ie even if the function is not extern?
Aug 31 2016
On Wednesday, 31 August 2016 at 07:34:14 UTC, kookman wrote:On Tuesday, 30 August 2016 at 09:04:41 UTC, Basile B. wrote: Indeed, I want to use rdtscp to get access to the core ID it makes available (to at least know when tsc is from different cores/packages). I guess in the meantime I can use Rikki's solution. Sorry [...]Never mind, I know Rikki's solution is better but since I've read a bit of doc and found this alternative I've just posted the alternative. By the way maybe someone could post an ER in bugzilla to get RDTSCP available in iasm w/o using the byte code trick.
Aug 31 2016
On Wednesday, 31 August 2016 at 08:23:57 UTC, Basile B. wrote:By the way maybe someone could post an ER in bugzilla to get RDTSCP available in iasm w/o using the byte code trick.Someone beat me to it, but see here: https://issues.dlang.org/show_bug.cgi?id=16449
Aug 31 2016