Part Number:TMS320F2800157
sTmpUint32_3 = sTmpUint32_1 – sTmpUint32_2;
上面一行代码,编译后的汇编代码如下,
测试发现,运行这些汇编代码,需要6个CPU周期
这些指令都是单周期的指令,按理应该只需要4个CPU周期,为什么实际上花费了6个CPU周期
0849dc: 761F0262 MOVW DP, #0x262
0849de: 0606 MOVL ACC, @0x6
0849df: 0308 SUBL ACC, @0x8
0849e0: 1E0A MOVL @0xa, ACC
Yale Li:
能描述一下测试的方法吗?
,
John Pan:
如下代码,在减法的前后分别获取timer的计数值,然后计数值相减,就得到了这个减法运算用掉了多少个CPU周期
// 测试uint32 减 uint32 需要花费的CPU cycle数 timerCountPrev = CPUTimer_getTimerCount(CPUTIMER2_BASE); sTmpUint32_3 = sTmpUint32_1 – sTmpUint32_2; timerCount = CPUTimer_getTimerCount(CPUTIMER2_BASE); uint32SubUint32Cycles = timerCountPrev – timerCount – gtimerCountDiff0us;
,
John Pan:
或者就在下面的代码设置断点,然后执行到这里,比较一下这一行代码前后的timer的计数值,就可以算出用掉了多少个CPU周期
sTmpUint32_3 = sTmpUint32_1 – sTmpUint32_2;
,
John Pan:
,
Yale Li:
能用CCS自带的周期计数器看一下吗?
有两种方法,
1. https://software-dl.ti.com/ccs/esd/documents/ccs_counting_cycles.html
2.
,
John Pan:
这个方法用用过,在右下角有一个时钟的小图标,测试结果也是6个CPU周期
,
Yale Li:
我已经咨询了相关工程师,请关注下方链接:
https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1313957/tms320f2800157-cpu-cycles-required-to-execute-the-instruction