Reputation: 845
#define M 20
#define N 20
void main()
{
int i,j;
int A[M][N] = {0};
for (i=0; i < M; i++)
{
for (j=0; j< N; j++)
{
//A[i][j +1] = A[i][j] + 5;
A[i][j] = 0;
}
}
printf("%d\n", A[2][3]);
}
Generated Assembly Code is
main:
pushl %ebp
xorl %eax, %eax
pxor %xmm0, %xmm0
movl %esp, %ebp
andl -16, %esp
pushl %edi
movl 400, %ecx
subl 1628, %esp
leal 16(%esp), %edi
rep stosl
leal 16(%esp), %edx
leal 1616(%esp), %eax
.p2align 4,,7
.p2align 3
.L2:
movdqa %xmm0, (%edx)
movdqa %xmm0, 16(%edx)
movdqa %xmm0, 32(%edx)
movdqa %xmm0, 48(%edx)
movdqa %xmm0, 64(%edx)
addl 80, %edx
cmpl %eax, %edx
jne .L2
movl 188(%esp), %eax
movl .LC0, (%esp)
movl %eax, 4(%esp)
call printf
addl 1628, %esp
popl %edi
movl %ebp, %esp
popl %ebp
ret
I am not able to understand the assembly Code from main upto label L2. This assembly code is optimized using auto-vectorization. Thanks in Advance.
Upvotes: 1
Views: 440
Reputation: 26930
pushl %ebp ; save the old %ebp value
xorl %eax, %eax ; clear %eax
pxor %xmm0, %xmm0 ; clear %xmm0
movl %esp, %ebp
andl -16, %esp
pushl %edi ; save edi ^--- you have to restore all these value on function return.
movl 400, %ecx
subl 1628, %esp ; allocate 1628 bytes from stack
leal 16(%esp), %edi ; load address of A to %edi
rep stosl ; repeat cx(400) time, clear the memory -- this initialize "A" as {0}
Upvotes: 5