"Simple" Vector SIMD operations in Assembly ( v1 + v2 -> v3 ) called from C#

85 views Asked by At

I am having thought time performing - i believe - simple operation in Assembly, its required for me to use SIMD operation in Assembly for my Uni project.

I have Windows Forms Application in which i import the function from Assembly:

   [DllImport(@"C:\Neon\x64\Debug\JANeonLib.dll")]
   public static extern void AsmAdd(ref int[] a, ref int[] b, ref int[] result);

In the C# caller I have:

   int[] Toned = new int[width * height * 3];
   int[] Bumped = new int[width * height * 3];
   int[] Final = new int[width * height * 3];

   // ... ( filling the Toned and Bumped with data )

   AsmAdd(ref Toned, ref Bumped, ref Final); // <- running the assembly code through dll library, here is where the code fails

In assembly itself i have simple:

.code

AsmAdd proc
    push rbp
    mov rbp, rsp

    mov rax, rsi
    movaps xmm0, [rax]  

    mov rax, rdi 
    movaps xmm1, [rax] ; <- debugger here says i access memory?

    addps xmm0, xmm1 

    mov rax, r8
    movaps [rax], xmm0    

    pop rbp
    ret

AsmAdd endp

end

What im trying to achive is kinda: for( i from 0 to size ) result[i] = a[i] + b[i];

I am not good with Assembly, i will be honesty here, it might be issue with byte/word/dword/qword sizes? I have no clue.

Don't want to make it too long, but i could also use subtraction and multiplying each element of vector, also on the other note, multiplying each value in vector by constant.

0

There are 0 answers