Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Smart_Lubobya
Beginner
43 Views

psubw code gave wrong result

why is my result on psubw not correct?expected -4,-4,-4,-4 for movq B3+16, mm2 and -12,-12,-12,-12 for movq B3+24, mm3
#include "stdafx.h"
#include "emmintrin.h"
#include
#include
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
short B2[4][4];//input 2-D array
short B3[4][4]; // output
int n=0;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++, n++)
B2 = n;

__asm{


movq mm0, B2
movq mm1, B2+8
movq mm2, B2+16
movq mm3, B2+24
//add-sub register element
paddw mm0,mm3 // mm0+mm3, result correct
paddw mm1,mm2//mm1+mm2, result correct
psubw mm2,mm1// mm1-mm2, result not correct
psubw mm3,mm0//mm0-mm3, result not correct

//move result in B3
movq B3, mm0
movq B3+8, mm1
movq B3+16, mm2
movq B3+24, mm3
emms
}
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
cout << B2 << " ";
cout << endl;
}
cout << endl;

for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
cout << B3 << " ";
cout << endl;
}
return 0;
}
0 Kudos
1 Reply
neni
New Contributor II
43 Views

psubw mm2,mm1 is mm2 <- mm2 - mm1 (not mm1 - mm2 like the comment suggests)
Reply