我需要在我的应用程序中执行快速伽罗华域运算。我有一个用汇编语言编写的乘法函数,它针对我的平台(一个 MSP430 微 Controller )进行了优化。该函数计算两个任意大小的大数的乘积,但每个数必须表示为一个 16 位整数数组。但是,在我的项目中,Galois 域元素表示为 16 个 64 位整数的数组。如何将我的 16 个 64 位整数数组转换为我优化的、基于汇编的乘法函数所需的表示(即 64 个 16 位整数数组)?当然,简单地将数组转换为 (UInt16 *) 是行不通的。
MSP430 是小端架构。提前感谢您的任何建议。
最佳答案
我不确定这是否是您想要的,而且这个解决方案在某种意义上是不完整的,因为它只是作为一个示例。此外,它是高度平台依赖的。它适用于我的机器(little_endian)。我在 windows 下使用 Code:Blocks。
typedef struct {
uint16_t lo_word0;
uint16_t hi_word0;
uint16_t lo_word1;
uint16_t hi_word1;
}struct_t;
int main()
{
uint64_t buff_64[4]={0xaaaabbbbccccdddd,0xbbbbccccddddeeee,0x1111222233334444,0x8888aaaabbbbcccc};
uint16_t buff_16[16];
/*Please note that you may use simply:
memcpy(buff_16,buff_64,32);
however that would result in reverse order
with respect to the code below */
struct_t *ptr = (struct_t *)buff_64;
for(int j=0; j<16; ptr++)
{
buff_16[(j++)%16]=ptr->hi_word1;
buff_16[(j++)%16]=ptr->lo_word1;
buff_16[(j++)%16]=ptr->hi_word0;
buff_16[(j++)%16]=ptr->lo_word0;
}
// The check
for(int j=0;j<16;j++)
printf("%x\n",buff_16[j]);
return 0;
}
关于c - 如何将 UInt64 数组转换为 UInt16 数组以执行多精度乘法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42011382/