func_matrix_simd.inl 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #if GLM_ARCH & GLM_ARCH_SSE2_BIT
  2. #include "type_mat4x4.hpp"
  3. #include "../geometric.hpp"
  4. #include "../simd/matrix.h"
  5. #include <cstring>
  6. namespace glm{
  7. namespace detail
  8. {
  9. # if GLM_CONFIG_ALIGNED_GENTYPES == GLM_ENABLE
  10. template<qualifier Q>
  11. struct compute_matrixCompMult<4, 4, float, Q, true>
  12. {
  13. GLM_STATIC_ASSERT(detail::is_aligned<Q>::value, "Specialization requires aligned");
  14. GLM_FUNC_QUALIFIER static mat<4, 4, float, Q> call(mat<4, 4, float, Q> const& x, mat<4, 4, float, Q> const& y)
  15. {
  16. mat<4, 4, float, Q> Result;
  17. glm_mat4_matrixCompMult(
  18. *static_cast<glm_vec4 const (*)[4]>(&x[0].data),
  19. *static_cast<glm_vec4 const (*)[4]>(&y[0].data),
  20. *static_cast<glm_vec4(*)[4]>(&Result[0].data));
  21. return Result;
  22. }
  23. };
  24. # endif
  25. template<qualifier Q>
  26. struct compute_transpose<4, 4, float, Q, true>
  27. {
  28. GLM_FUNC_QUALIFIER static mat<4, 4, float, Q> call(mat<4, 4, float, Q> const& m)
  29. {
  30. mat<4, 4, float, Q> Result;
  31. glm_mat4_transpose(&m[0].data, &Result[0].data);
  32. return Result;
  33. }
  34. };
  35. template<qualifier Q>
  36. struct compute_determinant<4, 4, float, Q, true>
  37. {
  38. GLM_FUNC_QUALIFIER static float call(mat<4, 4, float, Q> const& m)
  39. {
  40. return _mm_cvtss_f32(glm_mat4_determinant(&m[0].data));
  41. }
  42. };
  43. template<qualifier Q>
  44. struct compute_inverse<4, 4, float, Q, true>
  45. {
  46. GLM_FUNC_QUALIFIER static mat<4, 4, float, Q> call(mat<4, 4, float, Q> const& m)
  47. {
  48. mat<4, 4, float, Q> Result;
  49. glm_mat4_inverse(&m[0].data, &Result[0].data);
  50. return Result;
  51. }
  52. };
  53. }//namespace detail
  54. # if GLM_CONFIG_ALIGNED_GENTYPES == GLM_ENABLE
  55. template<>
  56. GLM_FUNC_QUALIFIER mat<4, 4, float, aligned_lowp> outerProduct<4, 4, float, aligned_lowp>(vec<4, float, aligned_lowp> const& c, vec<4, float, aligned_lowp> const& r)
  57. {
  58. __m128 NativeResult[4];
  59. glm_mat4_outerProduct(c.data, r.data, NativeResult);
  60. mat<4, 4, float, aligned_lowp> Result;
  61. std::memcpy(&Result[0], &NativeResult[0], sizeof(Result));
  62. return Result;
  63. }
  64. template<>
  65. GLM_FUNC_QUALIFIER mat<4, 4, float, aligned_mediump> outerProduct<4, 4, float, aligned_mediump>(vec<4, float, aligned_mediump> const& c, vec<4, float, aligned_mediump> const& r)
  66. {
  67. __m128 NativeResult[4];
  68. glm_mat4_outerProduct(c.data, r.data, NativeResult);
  69. mat<4, 4, float, aligned_mediump> Result;
  70. std::memcpy(&Result[0], &NativeResult[0], sizeof(Result));
  71. return Result;
  72. }
  73. template<>
  74. GLM_FUNC_QUALIFIER mat<4, 4, float, aligned_highp> outerProduct<4, 4, float, aligned_highp>(vec<4, float, aligned_highp> const& c, vec<4, float, aligned_highp> const& r)
  75. {
  76. __m128 NativeResult[4];
  77. glm_mat4_outerProduct(c.data, r.data, NativeResult);
  78. mat<4, 4, float, aligned_highp> Result;
  79. std::memcpy(&Result[0], &NativeResult[0], sizeof(Result));
  80. return Result;
  81. }
  82. # endif
  83. }//namespace glm
  84. #endif