这是我在 64 位 linux 机器上编写的函数。
void myfunc(unsigned char* arr) //array of 8 bytes is passed by reference
{
unsigned long a = 0; //8 bytes
unsigned char* LL = (unsigned char*) &a;
LL[0] = arr[6];
LL[1] = arr[3];
LL[2] = arr[1];
LL[3] = arr[7];
LL[4] = arr[5];
LL[5] = arr[4];
LL[6] = arr[0];
LL[7] = arr[2];
}
现在我的问题是:
- 变量“a”是否会存储在寄存器中,这样就不会从 RAM 或 chache 一次又一次地访问它?
- 在 64 位架构上工作,我是否应该假设“arr”数组将存储在寄存器中,因为函数参数存储在 64 位架构的寄存器中?
- 指针类型转换的效率如何?我的猜测是它应该是低效的吗?
任何帮助都将不胜感激。
问候