SIMD 4x4 Matrix Multiplication on Android with C++ - Stack Overflow

I am trying to speed up C++ row-major matrix multiplication on Android, but the SIMD instructions I imp

I am trying to speed up C++ row-major matrix multiplication on Android, but the SIMD instructions I implemented seem to be far from ideal and they fail to outperform the computation time of a naive implementation (I tested that with Samsung S21 and Xiaomi Poco F1). I'd be really grateful if you could point out what I am doing wrong. Thanks!

Here are minimal representations of my Matrix44f and Vector4f classes:

class alignas(16) Matrix44f {
public:
    Vector4f mRows[4];
};

class alignas(16) Vector4f {
public:
    float x, y, z, w;
};

The SIMD implementation:

Matrix44f operator*(const Matrix44f& pM1, const Matrix44f& pM2)
{
    Matrix44f matRes;
    float32x4_t m2_row0 = vld1q_f32(&pM2.mRows[0][0]);
    float32x4_t m2_row1 = vld1q_f32(&pM2.mRows[1][0]);
    float32x4_t m2_row2 = vld1q_f32(&pM2.mRows[2][0]);
    float32x4_t m2_row3 = vld1q_f32(&pM2.mRows[3][0]);

    float32x4_t m1_row, result;
    for (int i = 0; i < 4; ++i)
    {
        m1_row = vld1q_f32(&pM1.mRows[i][0]);
        result = vmulq_n_f32(m2_row0, vgetq_lane_f32(m1_row, 0));
        result = vfmaq_n_f32(result, m2_row1, vgetq_lane_f32(m1_row, 1));
        result = vfmaq_n_f32(result, m2_row2, vgetq_lane_f32(m1_row, 2));
        result = vfmaq_n_f32(result, m2_row3, vgetq_lane_f32(m1_row, 3));
        vst1q_f32(&matRes.mRows[i][0], result);
    }

   return matRes;
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742361132a4429414.html

相关推荐

  • SIMD 4x4 Matrix Multiplication on Android with C++ - Stack Overflow

    I am trying to speed up C++ row-major matrix multiplication on Android, but the SIMD instructions I imp

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信