How to add all the elements of an array using MMX?

231 Views Asked by At

I use an assembler insert and cannot complete the task. I need to add all the elements of the array using MMX

int32_t matr1[10] = { 3,10,100,1000,2,40,200,3}; // first matrix
 int32_t matr2[6] = { 1,0,4,6, 3,7}; // second matrix
 int32_t result[10] = {}; //result
...
__asm{
     lea esi, matr1
    //xor ecx,ecx
    movq mm0,[esi]
      add esi,8
     metka:
     paddw mm0,[esi]
     add ecx,4
     add esi,8
     cmp ecx,8
     jb metka

         movq [result],mm0
         movzx eax, [result]
         movzx edx, [result + 2]
         add eax, edx
         movzx edx, [result + 4]
         add eax, edx
         movzx edx, [result + 6]
         add eax, edx
         mov [b],eax
    }

I tried to rewrite another mmx code in c++. It writes all variables to a register, and then to the result array. And theoretically adds up. But the addition of variables comes out wrong

0

There are 0 best solutions below