1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <vector>
std::vector<int> v(100);
volatile int sink;
int main()
{
for(unsigned int i = 0; i < v.size(); i++)
{
sink += v[i];
}
}
// GCC loop:
.L6:
movl sink(%rip), %eax
addl $1, %edx
addl (%rdi,%rcx,4), %eax
movl %edx, %ecx
cmpq %rsi, %rcx
movl %eax, sink(%rip)
jb .L6
// CLang loop
.LBB1_2:
movl (%rax,%rsi,4), %esi
addl %esi, sink(%rip)
movl %edx, %esi
incl %edx
cmpq %rcx, %rsi
jb .LBB1_2
|
#include <vector>
std::vector<int> v(100);
volatile int sink;
int main()
{
for(unsigned int i = v.size(); i--; )
{
sink += v[i];
}
}
// GCC loop
.L8:
movl sink(%rip), %edx
movl %eax, %ecx
subl $1, %eax
addl (%rsi,%rcx,4), %edx
cmpl $-1, %eax
movl %edx, sink(%rip)
jne .L8
// Clang loop
.LBB1_2:
movl (%rcx), %edx
addl %edx, sink(%rip)
addq $-4, %rcx
incl %eax
jne .LBB1_2
| |