Created
February 15, 2017 12:15
-
-
Save PixelClear/4a4d6b6cfda845b4f4b8ea7772268236 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<intrin.h> | |
#include<Windows.h> | |
typedef struct matrix4X4d | |
{ | |
double matrix[4][4]; | |
}Matrix4x4D; | |
void M4x4MultM4x4 (Matrix4x4D *m1, Matrix4x4D *m2, | |
Matrix4x4D *m3) | |
{ | |
__m128 otherRow0; | |
__m128 otherRow1; | |
__m128 otherRow2; | |
__m128 otherRow3; | |
__m128 newRow0; | |
__m128 newRow1; | |
__m128 newRow2; | |
__m128 newRow3; | |
otherRow0 = _mm_loadu_ps(m2->matrix[0]); | |
otherRow1 = _mm_loadu_ps(m2->matrix[1]); | |
otherRow2 = _mm_loadu_ps(m2->matrix[2]); | |
otherRow3 = _mm_loadu_ps(m2->matrix[3]); | |
newRow0 = _mm_mul_ps(otherRow0, _mm_set1_ps(m1->matrix[0][0])); | |
newRow0 = _mm_add_ps(newRow0, _mm_mul_ps(otherRow1, _mm_set1_ps(m1->matrix[0][1]))); | |
newRow0 = _mm_add_ps(newRow0, _mm_mul_ps(otherRow2, _mm_set1_ps(m1->matrix[0][2]))); | |
newRow0 = _mm_add_ps(newRow0, _mm_mul_ps(otherRow3, _mm_set1_ps(m1->matrix[0][3]))); | |
newRow1 = _mm_mul_ps(otherRow0, _mm_set1_ps(m1->matrix[1][0])); | |
newRow1 = _mm_add_ps(newRow1, _mm_mul_ps(otherRow1, _mm_set1_ps(m1->matrix[1][1]))); | |
newRow1 = _mm_add_ps(newRow1, _mm_mul_ps(otherRow2, _mm_set1_ps(m1->matrix[1][2]))); | |
newRow1 = _mm_add_ps(newRow1, _mm_mul_ps(otherRow3, _mm_set1_ps(m1->matrix[1][3]))); | |
newRow2 = _mm_mul_ps(otherRow0, _mm_set1_ps(m1->matrix[2][0])); | |
newRow2 = _mm_add_ps(newRow2, _mm_mul_ps(otherRow1, _mm_set1_ps(m1->matrix[2][1]))); | |
newRow2 = _mm_add_ps(newRow2, _mm_mul_ps(otherRow2, _mm_set1_ps(m1->matrix[2][2]))); | |
newRow2 = _mm_add_ps(newRow2, _mm_mul_ps(otherRow3, _mm_set1_ps(m1->matrix[2][3]))); | |
newRow3 = _mm_mul_ps(otherRow0, _mm_set1_ps(m1->matrix[3][0])); | |
newRow3 = _mm_add_ps(newRow3, _mm_mul_ps(otherRow1, _mm_set1_ps(m1->matrix[3][1]))); | |
newRow3 = _mm_add_ps(newRow3, _mm_mul_ps(otherRow2, _mm_set1_ps(m1->matrix[3][2]))); | |
newRow3 = _mm_add_ps(newRow3, _mm_mul_ps(otherRow3, _mm_set1_ps(m1->matrix[3][3]))); | |
_mm_storeu_ps(m3->matrix[0], newRow0); | |
_mm_storeu_ps(m3->matrix[1], newRow1); | |
_mm_storeu_ps(m3->matrix[2], newRow2); | |
_mm_storeu_ps(m3->matrix[3], newRow3); | |
} | |
int main() | |
{ | |
//Initialize and call multiplication for matrix routine | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment