Question: This is a continuation of a question from : https: / / www . chegg.com / homework - help / questions - and - answers

This is a continuation of a question from :
https://www.chegg.com/homework-help/questions-and-answers/complete-col-major-column-major-code-simd-using-c--1-vectcolsimdh-ifndef-vectcolsimdh-defi-q181928410?share=7e25e242-ec96-4c53-8800-6a156d6c8871.
I modified the code to look like below.
//4. Matrix_Col_SIMD.cpp
#include "Vect_Col_SIMD.h"
#include "Matrix_Col_SIMD.h"
Matrix_Col_SIMD::Matrix_Col_SIMD(const Vect_Col_SIMD &tV0, const Vect_Col_SIMD &tV1, const Vect_Col_SIMD &tV2, const Vect_Col_SIMD &tV3)
: v0(tV0), v1(tV1), v2(tV2), v3(tV3)
{
}
Vect_Col_SIMD Matrix_Col_SIMD::operator *(const Vect_Col_SIMD &vb)
{
__m128 col0=_mm_load_ps(&v0.x);
__m128 col1=_mm_load_ps(&v1.x);
__m128 col2=_mm_load_ps(&v2.x);
__m128 col3=_mm_load_ps(&v3.x);
__m128 vec =_mm_set_ps(vb.w, vb.z, vb.y, vb.x);
__m128 result =_mm_add_ps(
_mm_add_ps(
_mm_mul_ps(_mm_shuffle_ps(vec, vec, 0x00), col0),
_mm_mul_ps(_mm_shuffle_ps(vec, vec, 0x55), col1)),
_mm_add_ps(
_mm_mul_ps(_mm_shuffle_ps(vec, vec, 0xAA), col2),
_mm_mul_ps(_mm_shuffle_ps(vec, vec, 0xFF), col3)));
Vect_Col_SIMD res;
_mm_store_ps(&res.x, result);
return res;
}
Matrix_Col_SIMD Matrix_Col_SIMD::operator *(const Matrix_Col_SIMD &mb)
{
__m128 ma0=_mm_load_ps(&v0.x);
__m128 ma1=_mm_load_ps(&v1.x);
__m128 ma2=_mm_load_ps(&v2.x);
__m128 ma3=_mm_load_ps(&v3.x);
__m128 mb0=_mm_load_ps(&mb.v0.x);
__m128 mb1=_mm_load_ps(&mb.v1.x);
__m128 mb2=_mm_load_ps(&mb.v2.x);
__m128 mb3=_mm_load_ps(&mb.v3.x);
__m128 mc0=_mm_add_ps(
_mm_add_ps(
_mm_mul_ps(_mm_shuffle_ps(mb0, mb0,0x00), ma0),
_mm_mul_ps(_mm_shuffle_ps(mb1, mb1,0x55), ma1)),
_mm_add_ps(
_mm_mul_ps(_mm_shuffle_ps(mb2, mb2,0xAA), ma2),
_mm_mul_ps(_mm_shuffle_ps(mb3, mb3,0xFF), ma3)));
//...repeat mc1, mc2, mc3
Matrix_Col_SIMD result;
_mm_store_ps(&result.v0.x, mc0);
_mm_store_ps(&result.v1.x, mc1);
_mm_store_ps(&result.v2.x, mc2);
_mm_store_ps(&result.v3.x, mc3);
return result;
}
//--- End of File -----
But when I run the test
Matrix_Col_SIMD Rx(Vect_Col_SIMD(1.000000f,0.000000f,0.000000f,0.000000f),
Vect_Col_SIMD(0.000000f,-0.500000f,-0.866025f,0.000000f),
Vect_Col_SIMD(0.000000f,0.866025f,-0.500000f,0.000000f),
Vect_Col_SIMD(0.000000f,0.000000f,0.000000f,1.000000f));
Matrix_Col_SIMD Ry(Vect_Col_SIMD(0.707107f,0.000000f,0.707107f,0.000000f),
Vect_Col_SIMD(0.000000f,1.000000f,0.000000f,0.000000f),
Vect_Col_SIMD(-0.707107f,0.000000f,0.707107f,0.000000f),
Vect_Col_SIMD(0.000000f,0.000000f,0.000000f,1.000000f));
Matrix_Col_SIMD Rz(Vect_Col_SIMD(0.500000f,0.866025f,0.000000f,0.000000f),
Vect_Col_SIMD(-0.866025f,0.500000f,0.000000f,0.000000f),
Vect_Col_SIMD(0.000000f,0.000000f,1.000000f,0.000000f),

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!