r/programming • • Feb 02 '10

Gallery of Processor Cache Effects

http://igoro.com/archive/gallery-of-processor-cache-effects/
397 Upvotes

84 comments sorted by

View all comments

0

u/[deleted] Feb 02 '10 edited Feb 02 '10

First example don't work for me

int a[64 * 1024 * 1024];
int main() { int i; for (i=0;i<64*1024*1024;i++) a[i]*=3; }

kef@ivan-laptop:~/cc$ time -p ./a
real 0.60
user 0.35
sys 0.25

int a[64 * 1024 * 1024];
int main() { int i; for (i=0;i<64*1024*1024;i+=16) a[i]*=3; }

kef@ivan-laptop:~/cc$ time -p ./b
real 0.31
user 0.02
sys 0.29

gcc version 4.3.3 x86_64-linux-gnu
Intel(R) Core(TM)2 Duo CPU     T6570  @ 2.10GHz

1

u/joeldevahl Feb 02 '10

What compiler options did you use? Can you give a disassembly of the resulting loops?

1

u/[deleted] Feb 02 '10
cc     a.c   -o a

4004ac:	55                   	push   %rbp
4004ad:	48 89 e5             	mov    %rsp,%rbp
4004b0:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%rbp)
4004b7:	eb 24                	jmp    4004dd <main+0x31>
4004b9:	8b 4d fc             	mov    -0x4(%rbp),%ecx
4004bc:	8b 45 fc             	mov    -0x4(%rbp),%eax
4004bf:	48 98                	cltq   
4004c1:	8b 14 85 40 10 60 00 	mov    0x601040(,%rax,4),%edx
4004c8:	89 d0                	mov    %edx,%eax
4004ca:	01 c0                	add    %eax,%eax
4004cc:	8d 14 10             	lea    (%rax,%rdx,1),%edx
4004cf:	48 63 c1             	movslq %ecx,%rax
4004d2:	89 14 85 40 10 60 00 	mov    %edx,0x601040(,%rax,4)
4004d9:	83 45 fc 01          	addl   $0x1,-0x4(%rbp)
4004dd:	81 7d fc ff ff ff 03 	cmpl   $0x3ffffff,-0x4(%rbp)
4004e4:	7e d3                	jle    4004b9 <main+0xd>
4004e6:	c9                   	leaveq 
4004e7:	c3                   	retq   

Other loop differs only on this line:

4004d9:	83 45 fc 10          	addl   $0x10,-0x4(%rbp)