Intel® ISA Extensions
Use hardware-based isolation and memory encryption to provide more code protection in your solutions.
1093 Discussions

how to display output in sse intrinsic codes

Smart_Lubobya
Beginner
344 Views
i seem to have trouble in using the cout << output code: here are my codes, please help

#include "stdafx.h"

#include

#include

#include

#include

#include

#include

using namespace std;

int _tmain(int argc, _TCHAR* argv[])

{

int j;

__m128 s0, s1, s2, s3;

__declspec(align (16))float block[4][4]={1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4};

for(j = 0; j < 16; j += 4)

{

__m128 v = _mm_load_ps(block);

__m128 w = _mm_load_ps(block[j+1]);

__m128 x = _mm_load_ps(block[j+2]);

__m128 y = _mm_load_ps(block[j+3]);

s0 = _mm_add_ps(v,y);

s3 = _mm_sub_ps(v,y);

s1 = _mm_add_ps(w,x);

s2 = _mm_sub_ps(w,x);

}

cout << s0 << endl;//error C2679: binary '<<' : no operator found which takes a right-hand operand of type '__m128' (or there is no acceptable conversion)

return 0;

}

0 Kudos
4 Replies
bronxzv
New Contributor II
344 Views
here is one implementation of operator << for quad floats that you can usein your project :


ostream & operator << (ostream &out, const __m128 &m)
{
float v[4]; _mm_storeu_ps(v,m);
out << v[3] << " | " << v[2] << " | " << v[1] << " | " << v[0];
return out;
}


it's a simple, albeit valuable tool for learning these things or to debug your code

btw there is a bug in your loop, it should be :

for (int j=0; j<4; j++)

isn't it?


0 Kudos
kaletinkle
Beginner
344 Views
i seem to have trouble in using the cout << output code: here are my codes, please help

#include "stdafx.h"

#include

#include

#include

#include

#include

#include

using namespace std;

int _tmain(int argc, _TCHAR* argv[])

{

int j;

__m128 s0, s1, s2, s3;

__declspec(align (16))float block[4][4]={1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4};

for(j = 0; j < 16; j += 4)

{

__m128 v = _mm_load_ps(block);

__m128 w = _mm_load_ps(block[j+1]);

__m128 x = _mm_load_ps(block[j+2]);

__m128 y = _mm_load_ps(block[j+3]);

s0 = _mm_add_ps(v,y);

s3 = _mm_sub_ps(v,y);

s1 = _mm_add_ps(w,x);

s2 = _mm_sub_ps(w,x);

}

cout << s0 << endl;//error C2679: binary '<<' : no operator found which takes a right-hand operand of type '__m128' (or there is no acceptable conversion)

return 0;

}

ostream & operator << (ostream &out, const __m128 &m)
{
float v[4]; _mm_storeu_ps(v,m);
out << v[3] << " | " << v[2] << " | " << v[1] << " | " << v[0];
return out;
}
0 Kudos
Smart_Lubobya
Beginner
344 Views

after puting the output codes i now get the error

#include "stdafx.h"

#include

#include

#include

#include

#include

#include

using namespace std;

int _tmain(int argc, _TCHAR* argv[])

{

int j;

__m128 s0, s1, s2, s3;

__declspec(align (16))float block[4][4]={1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4};

for(j = 0; j < 16; j += 4)

{

__m128 v = _mm_load_ps(block);

__m128 w = _mm_load_ps(block[j+1]);

__m128 x = _mm_load_ps(block[j+2]);

__m128 y = _mm_load_ps(block[j+3]);

s0 = _mm_add_ps(v,y);

s3 = _mm_sub_ps(v,y);

s1 = _mm_add_ps(w,x);

s2 = _mm_sub_ps(w,x);

}

ostream & operator << (ostream &out, const __m128 &m)

{ //error C2601: 'operator <<' : local function definitions are illegal

float v[4]; _mm_storeu_ps(v,m);

out << v[3] << " | " << v[2] << " | " << v[1] << " | " << v[0];

return out;

}

}

please i want to see the output s0,s1,s2 and s3. help

0 Kudos
bronxzv
New Contributor II
344 Views
Smart, you must (obviously?) declarethe__m128 operator << freefunction before"_tmain"

Then you can write thinks like : cout << "s0 = " << s0 << " s1 = " << s1 << endl;


Please also note my fix for your buggyloopcontrol in my old post

0 Kudos
Reply