Is there an equivalent instruction to rdtsc in ARM?(ARM中是否有与rdtsc等效的指令?)
问题描述
对于我的项目我必须使用rdtsc等内联汇编指令来计算一些C/C++指令的执行时间.
For my project I must use inline assembly instructions such as rdtsc to calculate the execution time of some C/C++ instructions.
以下代码似乎适用于 Intel,但不适用于 ARM 处理器:
The following code seems to work on Intel but not on ARM processors:
{unsigned a, d;asm volatile("rdtsc" : "=a" (a), "=d" (d)); t0 = ((unsigned long)a) | (((unsigned long)d) << 32);}
//The C++ statement to measure its execution time
{unsigned a, d;asm volatile("rdtsc" : "=a" (a), "=d" (d)); t1 = ((unsigned long)a) | (((unsigned long)d) << 32);}
time = t1-t0;
我的问题是:
如何编写类似于上述的内联汇编代码(计算一条指令的执行时间)在ARM处理器上工作?
How to write an inline assembly code similar to the above (to calculate the execution elapsed time of an instruction) to work on ARM processors?
推荐答案
你应该读取协处理器 p15 的 PMCCNTR 寄存器(不是真正的协处理器,只是 CPU 函数的入口点)来获取循环计数.请注意,只有在以下情况下,它才可用于非特权应用:
You should read the PMCCNTR register of a co-processor p15 (not an actual co-processor, just an entry point for CPU functions) to obtain a cycle count. Note that it is available to an unprivileged app only if:
允许非特权
PMCCNTR读取:
PMUSERENR 寄存器的位 0 必须设置为 1 (官方文档)
Bit 0 of PMUSERENR register must be set to 1 (official docs)
PMCCNTR 实际上是在计算周期:
PMCCNTR is actually counting cycles:
PMCNTENSET 寄存器的第 31 位必须设置为 1 (官方文档)
Bit 31 of PMCNTENSET register must be set to 1 (official docs)
这是一个真实的例子 它是如何完成的.
This is a real-world example of how it`s done.
这篇关于ARM中是否有与rdtsc等效的指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ARM中是否有与rdtsc等效的指令?
基础教程推荐
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- CString 到 char* 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
