多少个CPU周期都需要每一个汇编指令? [英] How many CPU cycles are needed for each assembly instruction?

查看:175
本文介绍了多少个CPU周期都需要每一个汇编指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说有描述所需的特定的汇编指令的CPU周期英特尔网上预订,但我不能找到它(努力之后)。谁能告诉我如何找到CPU周期吗?

I heard there is Intel book online which describes the CPU cycles needed for a specific assembly instruction, but I can not find it out (after trying hard). Could anyone show me how to find CPU cycle please?

下面是一个例子,在下面的code,MOV /锁是1个CPU周期,XCHG 3的CPU周期。

Here is an example, in the below code, mov/lock is 1 CPU cycle, and xchg is 3 CPU cycles.

// This part is Platform dependent!
#ifdef WIN32
inline int CPP_SpinLock::TestAndSet(int* pTargetAddress, 
                                              int nValue)
{
    __asm
    {
        mov edx, dword ptr [pTargetAddress]
        mov eax, nValue
        lock xchg eax, dword ptr [edx]
    }
    // mov = 1 CPU cycle
    // lock = 1 CPU cycle
    // xchg = 3 CPU cycles
}

#endif // WIN32

BTW:这里是为code我贴的网址:<一href=\"http://www.$c$cproject.com/KB/threads/spinlocks.aspx\">http://www.$c$cproject.com/KB/threads/spinlocks.aspx

推荐答案

由于流水线,从订单处理,微code,多核处理​​器等没有保证装配code的特定部分将采取精确的x CPU周期/时钟周期/不管周期。

Given pipelining, out of order processing, microcode, multi-core processors, etc there's no guarantee that a particular section of assembly code will take exactly x CPU cycles/clock cycle/whatever cycles.

如果这样的提法存在,它只能提供泛泛赋予了特定的架构,并取决于如何在微code实现,你可能会发现奔腾M比Core 2 Duo处理器的不同而比AMD双核等不同。

If such a reference exists, it will only be able to provide broad generalizations given a particular architecture, and depending on how the microcode is implemented you may find that the Pentium M is different than the Core 2 Duo which is different than the AMD dual core, etc.

请注意,这篇文章是在2000年的更新,和之前版本编写。甚至奔腾4是很难牵制关于指令定时 - PIII,PII,和原来的奔腾较容易,并且所引用的文本可能是基于这些早期的处理器即有一个更明确定义的指令定时

Note that this article was updated in 2000, and written earlier. Even the Pentium 4 is hard to pin down regarding instruction timing - PIII, PII, and the original pentium were easier, and the texts referenced were probably based on those earlier processors that had a more well-defined instruction timing.

这些天人们普遍使用code定时估计的统计分析。

These days people generally use statistical analysis for code timing estimation.

这篇关于多少个CPU周期都需要每一个汇编指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆