【发布时间】:2019-12-23 10:25:23
【问题描述】:
我想计算简单递归 fibo 函数 O(2^n) 中的指令。我通过冒泡排序和矩阵乘法成功地做到了这一点,但在这种情况下,指令计数似乎忽略了我的 fibo 函数。以下是用于检测的代码:
// Insert a call at the entry point of a routine to increment the call count
RTN_InsertCall(rtn, IPOINT_BEFORE, (AFUNPTR)docount, IARG_PTR, &(rc->_rtnCount), IARG_END);
// For each instruction of the routine
for (INS ins = RTN_InsHead(rtn); INS_Valid(ins); ins = INS_Next(ins))
{
// Insert a call to docount to increment the instruction counter for this rtn
INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)docount, IARG_PTR, &(rc->_icount), IARG_END);
}
我开始想知道这个程序和以前的程序有什么区别,我的第一个想法是:这里我没有使用数组。
这是我在一些手动测试后意识到的:
a = 5; // instruction ignored by PIN and
// pretty much everything not using array
fibo[1] = 1 // instruction counted properly
a = fibo[1] // instruction ignored by PIN
所以看起来只有计数的指令是写入内存(这是我假设的)。在我将我的 fibo 函数更改为这个之后,它就可以工作了:
long fibonacciNumber(int n, long *fiboNumbers)
{
if (n < 2) {
fiboNumbers[n] = n;
return n;
}
fiboNumbers[n] = fiboNumbers[n-1] + fiboNumbers[n-2];
return fibonacciNumber(n - 1, fiboNumbers) + fibonacciNumber(n - 2, fiboNumbers);
}
但我也想计算不是我编写的程序的指令。有没有办法计算所有类型的指令?是否有任何特殊原因为什么只计算此指令?任何帮助表示赞赏。
//编辑
我在 Visual Studio 中使用了反汇编选项来检查它的外观,但对我来说仍然没有意义。我找不到为什么只有对数组的赋值被 PIN 解释为指令的原因。
这超出了我的所有预期,算作 2 条指令:
【问题讨论】:
-
你明白一条“指令”和一行源代码的区别吗?
-
@Sneftel 也许我没有。我想我们谈论的是汇编指令。但即便如此,这对我来说也没有任何意义。先生,如果您能解释您的想法并分享您的智慧,我将不胜感激。
标签: intel-pin