我正在编写一个基于SSE的Matrix类,并且在乘法时遇到了一些奇怪的问题 . 最奇怪的部分是它似乎以前工作,但现在它没有 . 即使乘以两个恒等式,我乘以的任何矩阵也会变成全零矩阵 .

矩阵是4x4,列主要,内部定义为 __m128 col0, col1, col2, col3; .

这是我的乘法函数:

inline static mat4 multiply(const mat4& lhs, const mat4& rhs)
{
    mat4 result;

    for (int i = 0; i < 4; ++i)
    {
        result.col[i] = _mm_add_ps(
            _mm_add_ps(
                _mm_mul_ps(_mm_shuffle_ps(rhs.col[i], rhs.col[i], _MM_SHUFFLE(0, 0, 0, 0)), lhs.col0),
                _mm_mul_ps(_mm_shuffle_ps(rhs.col[i], rhs.col[i], _MM_SHUFFLE(1, 1, 1, 1)), lhs.col1)),
            _mm_add_ps(
                _mm_mul_ps(_mm_shuffle_ps(rhs.col[i], rhs.col[i], _MM_SHUFFLE(2, 2, 2, 2)), lhs.col2),
                _mm_mul_ps(_mm_shuffle_ps(rhs.col[i], rhs.col[i], _MM_SHUFFLE(3, 3, 3, 3)), lhs.col3)));
    }

    return result;
}

最奇怪的是,它在2天前工作时工作,现在却没有 . 有没有搞错?

(编辑:在有人要求之前,他们使用工会,所以 col[i] == coli

这是一个例子:

mat4 C, D;
C.identity(); // mat4::identity() correctly sets the matrix to be an identity matrix.
D.identity();
C = mat4::multiply(C, D); // C now contains all 0's, when it should be an identity matrix.