-3

Using SIMD instructions and pure assembly, make a function to add efficiently any size of integer vectors.

input: int v[] = {1, 2, 3, 4, 5} , j[] = {2, 3, 4, 5, 6}

output : int sum[] ={3, 5, 7, 9, 11}

code in C++:

int main() {

int v[10000], r[10000], sum[10000];

for (int i = 0; i < 10000; i++) {
    v[i] = i;
    r[i] = i;
    sum[i] = r[i] + v[i];

}
//Somatorio de dois vetores de inteiros 
printf("    Somatorio dos dois vetores : \n");
for (int i = 0; i < 10000; i++) {
    printf("    %d", sum[i]);
}

return 0; 
  • Did you try anything yet? – EJoshuaS - Stand with Ukraine May 10 '22 at 13:23
  • No, just in C++, i added de code in the question. – Luis Barros May 10 '22 at 13:31
  • 1
    Which SIMD instruction set? x86 SSE2 or AVX2? PowerPC Altivec? AArch64 ASIMD? Have you tried just compiling this code with optimization enabled and looking at the asm? Compilers should auto-vectorize this init loop. Or if you separate it to add separately, then vectorize an add loop, too. So there you go, working SIMD assembly. – Peter Cordes May 10 '22 at 13:32
  • Unfortunately, if you haven't attempted the ASM code yet, you're really not ready to post a Stack Overflow question yet. Users here are [expected](http://idownvotedbecau.se/noattempt/) to have attempted their problem on their own before posting here. – EJoshuaS - Stand with Ukraine May 10 '22 at 13:35
  • 1
    Since you didn't specify an ISA, the portable answer is to get GCC to vectorize and look at its asm output. Closed as duplicates of that. If you have a more specific question, [edit] to ask it. – Peter Cordes May 10 '22 at 13:40

0 Answers0