Click here to Skip to main content
15,915,019 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
where is the bug in these codes? the B3 output is wrong
C++
#include "stdafx.h"
#include "emmintrin.h"
#include <iostream>
#include <iomanip>
using namespace std;


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

        __asm{

          // computing b3-transformed matrix
          movq mm1, B2
          movq mm2, B2+8
          movq mm3, B2+16
          movq mm4, B2+24
          //add-sub register element
          paddw mm1,xmm4
          paddw xmm2,xmm3
          psubw mm1,xmm3
          psubw mm3,xmm4

          //move result in b3
          movq B3, mm1
          movq B3+8, mm2
          movq B3+16, mm1
          movq B3+24, mm3
          emms
       }

       for (int i = 0; i < 4; i++)
       {
          for (int j = 0; j < 4; j++)
             cout << B2[i][j] << " ";
          cout << endl;
       }
        cout << endl;

       for (int i = 0; i < 4; i++)
       {
          for (int j = 0; j < 4; j++)
             cout << B3[i][j] << " ";
          cout << endl;
       }
       return 0;
    }
Posted

1 solution

I don't know what you mean with transformed matrix, but I see that you are mixing mm registers and xmm registers (paddw mm1, xmm4, paddw xmm2, xmm3 and so on).

Try remove the x from that register names (the result you obtain will be completely different) and good luck!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900