なぜ遅い?
ふらふらしていたら見かけました。
http://dev.ariel-networks.com/Members/matsuyama/30ed30fc30eb59096570306f90453044
ここを読むような人ならこの方面に明るい人もいそうなので。
比較のポイントは2つのループ。
1つめは(速い方)
24: 89 02 mov %eax,(%edx) 26: 83 c2 04 add $0x4,%edx 29: 48 dec %eax 2a: 79 f8 jns 24 <main+0x24>
と(遅い方)
18: 89 c8 mov %ecx,%eax 1a: 29 d0 sub %edx,%eax 1c: 89 14 85 00 00 00 00 mov %edx,0x0(,%eax,4) 23: 4a dec %edx 24: 79 f2 jns 18 <main+0x18>
2つめは(速い方)
2e: 8d 7b 01 lea 0x1(%ebx),%edi 31: 89 f8 mov %edi,%eax 33: 81 ff ff 7c 00 00 cmp $0x7cff,%edi 39: eb 16 jmp 51 <main+0x51> 3b: 8b 0c 9e mov (%esi,%ebx,4),%ecx 3e: 8b 14 86 mov (%esi,%eax,4),%edx 41: 39 d1 cmp %edx,%ecx 43: 7e 06 jle 4b <main+0x4b> 45: 89 14 9e mov %edx,(%esi,%ebx,4) 48: 89 0c 86 mov %ecx,(%esi,%eax,4) 4b: 40 inc %eax 4c: 3d ff 7c 00 00 cmp $0x7cff,%eax 51: 7e e8 jle 3b <main+0x3b> 53: 81 ff fe 7c 00 00 cmp $0x7cfe,%edi 59: 89 fb mov %edi,%ebx 5b: 7e d1 jle 2e <main+0x2e>
と(遅い方)
28: 8d 73 01 lea 0x1(%ebx),%esi 2b: 89 f0 mov %esi,%eax 2d: 81 fe ff 7c 00 00 cmp $0x7cff,%esi 33: eb 26 jmp 5b <main+0x5b> 35: 8b 0c 9d 00 00 00 00 mov 0x0(,%ebx,4),%ecx 3c: 8b 14 85 00 00 00 00 mov 0x0(,%eax,4),%edx 43: 39 d1 cmp %edx,%ecx 45: 7e 0e jle 55 <main+0x55> 47: 89 14 9d 00 00 00 00 mov %edx,0x0(,%ebx,4) 4e: 89 0c 85 00 00 00 00 mov %ecx,0x0(,%eax,4) 55: 40 inc %eax 56: 3d ff 7c 00 00 cmp $0x7cff,%eax 5b: 7e d8 jle 35 <main+0x35> 5d: 81 fe fe 7c 00 00 cmp $0x7cfe,%esi 63: 89 f3 mov %esi,%ebx 65: 7e c1 jle 28 <main+0x28>
ざっと見て、違いは「(%esi,%eax,4)」と「0x0(,%eax,4)」の部分でしょうか。