1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| #include "Matrix.hpp"
#ifdef __ARM_NEON__
#define LOAD_MATRIX(q0, q1, q2, q3, r) \
"vld1.32 {"#q0", "#q1"}, ["#r"]! \n" \
"vld1.32 {"#q2", "#q3"}, ["#r"]! \n"
#define SAVE_MATRIX(q0, q1, q2, q3, r) \
"vst1.32 {"#q0", "#q1"}, ["#r"]! \n" \
"vst1.32 {"#q2", "#q3"}, ["#r"]! \n"
template<>
Matrix4<float> Matrix4<float>::operator*(const Matrix4<float> &m) const{
Matrix4<float> result;
const float *idata1 = this->data();
const float *idata2 = m.data();
float *odata = result.data();
__asm__ volatile(
LOAD_MATRIX(q0, q1, q2, q3, %0)
LOAD_MATRIX(q4, q5, q6, q7, %1)
"vmul.f32 q8, q4, d0[0] \n"
"vmul.f32 q9, q4, d2[0] \n"
"vmul.f32 q10, q4, d4[0] \n"
"vmul.f32 q11, q4, d6[0] \n"
"vmla.f32 q8, q5, d0[1] \n"
"vmla.f32 q9, q5, d2[1] \n"
"vmla.f32 q10, q5, d4[1] \n"
"vmla.f32 q11, q5, d6[1] \n"
"vmla.f32 q8, q6, d1[0] \n"
"vmla.f32 q9, q6, d3[0] \n"
"vmla.f32 q10, q6, d5[0] \n"
"vmla.f32 q11, q6, d7[0] \n"
"vmla.f32 q8, q7, d1[1] \n"
"vmla.f32 q9, q7, d3[1] \n"
"vmla.f32 q10, q7, d5[1] \n"
"vmla.f32 q11, q7, d7[1] \n"
SAVE_MATRIX(q8, q9, q10, q11, %2)
:
: "r"(idata1), "r"(idata2), "r"(odata)
);
return result;
}
#endif |
Partager