Last active
August 29, 2015 13:57
-
-
Save fujidig/9713392 to your computer and use it in GitHub Desktop.
gcc -S; gcc -c & objdump -S (http://d.hatena.ne.jp/nishiohirokazu/20080919/1221810268)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:\users\user>gcc -g -O0 -S -std=c99 mt-benchmark.c | |
C:\users\user>type mt-benchmark.s | |
(omitted) | |
C:\users\user>gcc -g -O0 -c -std=c99 mt-benchmark.c | |
C:\users\user>objdump -S mt-benchmark.o | |
mt-benchmark.o: file format pe-i386 | |
Disassembly of section .text: | |
00000000 <_printf>: | |
return __retval; | |
} | |
__mingw_stdio_redirect__ | |
int printf (const char *__format, ...) | |
{ | |
0: 55 push %ebp | |
1: 89 e5 mov %esp,%ebp | |
3: 53 push %ebx | |
4: 83 ec 24 sub $0x24,%esp | |
register int __retval; | |
__builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format ); | |
7: 8d 45 0c lea 0xc(%ebp),%eax | |
a: 89 45 f4 mov %eax,-0xc(%ebp) | |
__retval = __mingw_vprintf( __format, __local_argv ); | |
d: 8b 45 f4 mov -0xc(%ebp),%eax | |
10: 89 44 24 04 mov %eax,0x4(%esp) | |
14: 8b 45 08 mov 0x8(%ebp),%eax | |
17: 89 04 24 mov %eax,(%esp) | |
1a: e8 00 00 00 00 call 1f <_printf+0x1f> | |
1f: 89 c3 mov %eax,%ebx | |
__builtin_va_end( __local_argv ); | |
return __retval; | |
21: 89 d8 mov %ebx,%eax | |
} | |
23: 83 c4 24 add $0x24,%esp | |
26: 5b pop %ebx | |
27: c9 leave | |
28: c3 ret | |
00000029 <_next_mt_elem>: | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
typedef uint32_t u32; | |
u32 next_mt_elem(u32 a, u32 i) { | |
29: 55 push %ebp | |
2a: 89 e5 mov %esp,%ebp | |
return 1812433253 * (a ^ (a >> 30)) + i; | |
2c: 8b 45 08 mov 0x8(%ebp),%eax | |
2f: c1 e8 1e shr $0x1e,%eax | |
32: 89 c2 mov %eax,%edx | |
34: 33 55 08 xor 0x8(%ebp),%edx | |
37: 89 d0 mov %edx,%eax | |
39: d1 e0 shl %eax | |
3b: 01 d0 add %edx,%eax | |
3d: 89 c1 mov %eax,%ecx | |
3f: c1 e1 0c shl $0xc,%ecx | |
42: 01 c8 add %ecx,%eax | |
44: c1 e0 02 shl $0x2,%eax | |
47: 01 d0 add %edx,%eax | |
49: c1 e0 02 shl $0x2,%eax | |
4c: 01 d0 add %edx,%eax | |
4e: d1 e0 shl %eax | |
50: 01 d0 add %edx,%eax | |
52: c1 e0 03 shl $0x3,%eax | |
55: 01 d0 add %edx,%eax | |
57: d1 e0 shl %eax | |
59: 01 d0 add %edx,%eax | |
5b: 8d 0c c5 00 00 00 00 lea 0x0(,%eax,8),%ecx | |
62: 01 c8 add %ecx,%eax | |
64: c1 e0 03 shl $0x3,%eax | |
67: 01 d0 add %edx,%eax | |
69: c1 e0 02 shl $0x2,%eax | |
6c: 01 d0 add %edx,%eax | |
6e: 03 45 0c add 0xc(%ebp),%eax | |
} | |
71: c9 leave | |
72: c3 ret | |
00000073 <_genrand>: | |
u32 genrand(u32 mt0, u32 mt1, u32 mt397) { | |
73: 55 push %ebp | |
74: 89 e5 mov %esp,%ebp | |
76: 83 ec 10 sub $0x10,%esp | |
u32 v; | |
v = (mt0 & 0x80000000) | (mt1 & 0x7fffffff); | |
79: 8b 45 08 mov 0x8(%ebp),%eax | |
7c: 89 c2 mov %eax,%edx | |
7e: 81 e2 00 00 00 80 and $0x80000000,%edx | |
84: 8b 45 0c mov 0xc(%ebp),%eax | |
87: 25 ff ff ff 7f and $0x7fffffff,%eax | |
8c: 09 d0 or %edx,%eax | |
8e: 89 45 fc mov %eax,-0x4(%ebp) | |
v = mt397 ^ (v >> 1) ^ ((v & 1) ? 0x9908b0df : 0); | |
91: 8b 45 fc mov -0x4(%ebp),%eax | |
94: d1 e8 shr %eax | |
96: 89 c2 mov %eax,%edx | |
98: 33 55 10 xor 0x10(%ebp),%edx | |
9b: 8b 45 fc mov -0x4(%ebp),%eax | |
9e: 83 e0 01 and $0x1,%eax | |
a1: 84 c0 test %al,%al | |
a3: 74 07 je ac <_genrand+0x39> | |
a5: b8 df b0 08 99 mov $0x9908b0df,%eax | |
aa: eb 05 jmp b1 <_genrand+0x3e> | |
ac: b8 00 00 00 00 mov $0x0,%eax | |
b1: 31 d0 xor %edx,%eax | |
b3: 89 45 fc mov %eax,-0x4(%ebp) | |
v ^= v >> 11; | |
b6: 8b 45 fc mov -0x4(%ebp),%eax | |
b9: c1 e8 0b shr $0xb,%eax | |
bc: 31 45 fc xor %eax,-0x4(%ebp) | |
v ^= (v << 7) & 0x9d2c5680; | |
bf: 8b 45 fc mov -0x4(%ebp),%eax | |
c2: c1 e0 07 shl $0x7,%eax | |
c5: 25 80 56 2c 9d and $0x9d2c5680,%eax | |
ca: 31 45 fc xor %eax,-0x4(%ebp) | |
v ^= (v << 15) & 0xefc60000; | |
cd: 8b 45 fc mov -0x4(%ebp),%eax | |
d0: c1 e0 0f shl $0xf,%eax | |
d3: 25 00 00 c6 ef and $0xefc60000,%eax | |
d8: 31 45 fc xor %eax,-0x4(%ebp) | |
v ^= v >> 18; | |
db: 8b 45 fc mov -0x4(%ebp),%eax | |
de: c1 e8 12 shr $0x12,%eax | |
e1: 31 45 fc xor %eax,-0x4(%ebp) | |
return v; | |
e4: 8b 45 fc mov -0x4(%ebp),%eax | |
} | |
e7: c9 leave | |
e8: c3 ret | |
000000e9 <_get_first_mt_result>: | |
u32 get_first_mt_result(u32 seed) { | |
e9: 55 push %ebp | |
ea: 89 e5 mov %esp,%ebp | |
ec: 83 ec 2c sub $0x2c,%esp | |
u32 mt, mt0, mt1, mt397; | |
int i; | |
mt0 = seed; | |
ef: 8b 45 08 mov 0x8(%ebp),%eax | |
f2: 89 45 f4 mov %eax,-0xc(%ebp) | |
mt1 = next_mt_elem(mt0, 1); | |
f5: c7 44 24 04 01 00 00 movl $0x1,0x4(%esp) | |
fc: 00 | |
fd: 8b 45 f4 mov -0xc(%ebp),%eax | |
100: 89 04 24 mov %eax,(%esp) | |
103: e8 21 ff ff ff call 29 <_next_mt_elem> | |
108: 89 45 f0 mov %eax,-0x10(%ebp) | |
mt = mt1; | |
10b: 8b 45 f0 mov -0x10(%ebp),%eax | |
10e: 89 45 fc mov %eax,-0x4(%ebp) | |
for (i = 2; i <= 397; i++) { | |
111: c7 45 f8 02 00 00 00 movl $0x2,-0x8(%ebp) | |
118: eb 18 jmp 132 <_get_first_mt_result+0x49> | |
mt = next_mt_elem(mt, i); | |
11a: 8b 45 f8 mov -0x8(%ebp),%eax | |
11d: 89 44 24 04 mov %eax,0x4(%esp) | |
121: 8b 45 fc mov -0x4(%ebp),%eax | |
124: 89 04 24 mov %eax,(%esp) | |
127: e8 fd fe ff ff call 29 <_next_mt_elem> | |
12c: 89 45 fc mov %eax,-0x4(%ebp) | |
u32 mt, mt0, mt1, mt397; | |
int i; | |
mt0 = seed; | |
mt1 = next_mt_elem(mt0, 1); | |
mt = mt1; | |
for (i = 2; i <= 397; i++) { | |
12f: ff 45 f8 incl -0x8(%ebp) | |
132: 81 7d f8 8d 01 00 00 cmpl $0x18d,-0x8(%ebp) | |
139: 7e df jle 11a <_get_first_mt_result+0x31> | |
mt = next_mt_elem(mt, i); | |
} | |
mt397 = mt; | |
13b: 8b 45 fc mov -0x4(%ebp),%eax | |
13e: 89 45 ec mov %eax,-0x14(%ebp) | |
return genrand(mt0, mt1, mt397); | |
141: 8b 45 ec mov -0x14(%ebp),%eax | |
144: 89 44 24 08 mov %eax,0x8(%esp) | |
148: 8b 45 f0 mov -0x10(%ebp),%eax | |
14b: 89 44 24 04 mov %eax,0x4(%esp) | |
14f: 8b 45 f4 mov -0xc(%ebp),%eax | |
152: 89 04 24 mov %eax,(%esp) | |
155: e8 19 ff ff ff call 73 <_genrand> | |
} | |
15a: c9 leave | |
15b: c3 ret | |
0000015c <_main>: | |
int main(int argc, char **argv) { | |
15c: 55 push %ebp | |
15d: 89 e5 mov %esp,%ebp | |
15f: 83 e4 f0 and $0xfffffff0,%esp | |
162: 83 ec 20 sub $0x20,%esp | |
165: e8 00 00 00 00 call 16a <_main+0xe> | |
int N; | |
if (argc == 2) { | |
16a: 83 7d 08 02 cmpl $0x2,0x8(%ebp) | |
16e: 75 16 jne 186 <_main+0x2a> | |
N = atoi(argv[1]); | |
170: 8b 45 0c mov 0xc(%ebp),%eax | |
173: 83 c0 04 add $0x4,%eax | |
176: 8b 00 mov (%eax),%eax | |
178: 89 04 24 mov %eax,(%esp) | |
17b: e8 00 00 00 00 call 180 <_main+0x24> | |
180: 89 44 24 1c mov %eax,0x1c(%esp) | |
184: eb 08 jmp 18e <_main+0x32> | |
} else { | |
N = 1000000; | |
186: c7 44 24 1c 40 42 0f movl $0xf4240,0x1c(%esp) | |
18d: 00 | |
} | |
u32 result = 0; | |
18e: c7 44 24 18 00 00 00 movl $0x0,0x18(%esp) | |
195: 00 | |
for (int i = 0; i < N; i ++) { | |
196: c7 44 24 14 00 00 00 movl $0x0,0x14(%esp) | |
19d: 00 | |
19e: eb 14 jmp 1b4 <_main+0x58> | |
result += get_first_mt_result(i); | |
1a0: 8b 44 24 14 mov 0x14(%esp),%eax | |
1a4: 89 04 24 mov %eax,(%esp) | |
1a7: e8 3d ff ff ff call e9 <_get_first_mt_result> | |
1ac: 01 44 24 18 add %eax,0x18(%esp) | |
N = atoi(argv[1]); | |
} else { | |
N = 1000000; | |
} | |
u32 result = 0; | |
for (int i = 0; i < N; i ++) { | |
1b0: ff 44 24 14 incl 0x14(%esp) | |
1b4: 8b 44 24 14 mov 0x14(%esp),%eax | |
1b8: 3b 44 24 1c cmp 0x1c(%esp),%eax | |
1bc: 7c e2 jl 1a0 <_main+0x44> | |
result += get_first_mt_result(i); | |
} | |
printf("%u\n", result); | |
1be: 8b 44 24 18 mov 0x18(%esp),%eax | |
1c2: 89 44 24 04 mov %eax,0x4(%esp) | |
1c6: c7 04 24 00 00 00 00 movl $0x0,(%esp) | |
1cd: e8 2e fe ff ff call 0 <_printf> | |
return 0; | |
1d2: b8 00 00 00 00 mov $0x0,%eax | |
} | |
1d7: c9 leave | |
1d8: c3 ret | |
1d9: 90 nop | |
1da: 90 nop | |
1db: 90 nop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment