【发布时间】:2014-04-18 18:28:15
【问题描述】:
我正在尝试使用 SSE Intrinsic 对矩阵乘法进行编程。我不确定我的代码是否正确,也无法编译它,因为我收到错误:
Error 1 error C2440: 'type cast' : cannot convert from 'float' to '__m128 *
有人可以仔细检查我的程序以确保我的矩阵乘法正确吗?另请注意,这是针对方阵的。
这是我的代码。
void Intrinsics (float * matrix_a, float * matrix_b, float * matrix_result, const int num_row, const int num_col) {
__declspec(align(16)) float * a = matrix_a;
__declspec(align(16)) float * b = matrix_b;
__declspec(align(16)) float * c = matrix_result;
for(int i = 0; i < num_row; ++i)
{
for(int j = 0; j < num_col; ++j)
{
__m128 *m3 = (__m128*)a[i]; // The error is here.
__m128 *m4 = (__m128*)b[j];
float* res;
*(c + (j * num_col + i)) = 0;
for(int k = 0; k < num_col; k += 4)
{
__m128 m5 = _mm_mul_ps(*m3,*m4);
res = (float*)&m5;
*(c + (j * num_col + i)) += res[0]+res[1]+res[2]+res[3];
m3++;
m4++;
}
}
}
}
【问题讨论】:
-
当代码行错误归因于?
-
用错误行更新代码