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

constants in SIMD inline assembly

Smart_Lubobya
Beginner
314 Views
how do i add a constant toeach elementin an array?see snipet codes

#include "stdafx.h"

#include

#include

#include "xmmintrin.h"

using namespace std;

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

{

int x[4][4]={1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4}; //source or input

int y[4][4];//destination or output

int b[4] ={5,5,5,5};// constants to be added

int f0,f1,f2,f3;

__asm

{

mov eax,x

mov ecx,b

mov edi,y

//stage one

movq mm0,[eax]

movq mm7,[ecx]

paddw mm0,mm7

movq [f0],mm0

movq mm1,[eax+8]

paddw mm1,mm7

movq [f1],mm1

movq mm2,[eax+16]

paddw mm2,mm7

movq [f2],mm2

movq mm3,[eax+24]

paddw mm3,mm7

movq [f3],mm3

//stage two

movq mm0,[f0]

psraw mm0,6

movq [edi],mm0

movq mm1,[f1]

psraw mm1,6

movq [edi+8],mm1

movq mm2,[f2]

psraw mm2,6

movq [edi+16],mm2

movq mm3,[f3]

psraw mm3,6

movq [edi+24],mm3

}

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

{

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

cout << y << " ";

cout << endl;

}

return 0;

}

0 Kudos
1 Reply
Max_L
Employee
314 Views
Hello, I suggest you to use SSE2 with 128-bit XMM registers instead of ancient 64-bit MMX (mm0-mm7),try using intrinsics instead of assembly (e.g. you will need _mm_add_epi32() in your case) to minimize efforts or use compiler, like Intel C/C++ Compiler,which can easily auto-vectorize such constructs.I'm not sure I understand what the snippet shown is trying to achieve ... but please note that type 'int' is 32-bit, i.e. requires 4-byteof mem,and PADDD instruction to add.

Regards,
-Max
0 Kudos
Reply