How can i verify whether my Code is Vectorized or not?
I am using Automatic Vectorization of compiler to generate the vectorized Code.
For. e.g.
for (i = 0; i < 20; i++)
{
A[i] = i;
}
for (i = 0; i < 20; i++)
{
A[i] = A[i] + 5;
}
For the above code I am getting assembly code as below ? Is it vectorized or not ?
-------------------------------------------------------------------
8048380: 55 push %ebp
8048381: 89 e5 mov %esp,%ebp
8048383: 56 push %esi
8048384: 83 ec 64 sub $0x64,%esp
8048387: c7 45 ac 05 00 00 00 movl $0x5,-0x54(%ebp)
804838e: c7 45 b0 06 00 00 00 movl $0x6,-0x50(%ebp)
8048395: c7 45 b4 07 00 00 00 movl $0x7,-0x4c(%ebp)
804839c: c7 45 b8 08 00 00 00 movl $0x8,-0x48(%ebp)
80483a3: c7 45 bc 09 00 开发者_如何学编程00 00 movl $0x9,-0x44(%ebp)
80483aa: c7 45 c0 0a 00 00 00 movl $0xa,-0x40(%ebp)
80483b1: c7 45 c4 0b 00 00 00 movl $0xb,-0x3c(%ebp)
80483b8: c7 45 c8 0c 00 00 00 movl $0xc,-0x38(%ebp)
80483bf: c7 45 cc 0d 00 00 00 movl $0xd,-0x34(%ebp)
80483c6: c7 45 d0 0e 00 00 00 movl $0xe,-0x30(%ebp)
80483cd: c7 45 d4 0f 00 00 00 movl $0xf,-0x2c(%ebp)
80483d4: c7 45 d8 10 00 00 00 movl $0x10,-0x28(%ebp)
80483db: c7 45 dc 11 00 00 00 movl $0x11,-0x24(%ebp)
80483e2: c7 45 e0 12 00 00 00 movl $0x12,-0x20(%ebp)
80483e9: c7 45 e4 13 00 00 00 movl $0x13,-0x1c(%ebp)
80483f0: c7 45 e8 14 00 00 00 movl $0x14,-0x18(%ebp)
80483f7: c7 45 ec 15 00 00 00 movl $0x15,-0x14(%ebp)
80483fe: c7 45 f0 16 00 00 00 movl $0x16,-0x10(%ebp)
8048405: c7 45 f4 17 00 00 00 movl $0x17,-0xc(%ebp)
804840c: c7 45 f8 18 00 00 00 movl $0x18,-0x8(%ebp)
-----------------------------------------------------------------------
It is not vectorized.
It is however unrolled, and your first loop is removed.
精彩评论