0

我知道 unsigned long long 存储在 eax/edx 中,但我想知道如何找出执行单个 rdtsc 指令需要多少个时钟周期?

编辑:这样的东西有用吗?

.globl rdtsc

rdtsc:

rdtsc

movl %eax, %ecx

movl %edx, %ebx

rdtsc

subl %ecx, %eax

subl %ebx, %edx

ret

4

2 回答 2

1

You could execute rdtsc repeatedly, and look at the difference between consecutive return values. Of course you need to bear in mind things like context switches etc, which will cause massive spikes.

See rdtsc, too many cycles for a discussion.

于 2012-11-07T01:57:49.413 回答
1

尽管您应该多次运行它并使用出现的最短值,但您的代码看起来是正确的。

我认为应该重申这个问题:在代码序列期间使用 rdtsc 计算经过的时钟周期的开销是多少。所以计数代码本质上是(32位示例):

rdtsc
mov dword ptr [mem64],eax
mov dword ptr [mem64+4],edx

; the code sequence to clock would go here when you're clocking it

rdtsc
sub eax,dword ptr [mem64]
sbb edx,dword ptr [mem64+4]    ; I always mix up sbb and sub so this may be incorrect

结果是对代码序列进行计时时“rdtsc 开销”的实际经过时间。

减去 rdtsc 开销后,您需要考虑流水线以及重叠处理是否已完成。对我来说,我假设如果定时序列在少于 30 个周期内运行,则可能需要考虑未完成的流水线问题。如果序列需要超过 100 个循环,则可能会出现问题,但可能会被忽略。

那么30到100之间呢?肯定是灰色的。

于 2012-12-08T19:11:21.817 回答