Skip to content

Instantly share code, notes, and snippets.

@awreece
Last active December 11, 2015 00:19
Show Gist options
  • Save awreece/4515720 to your computer and use it in GitHub Desktop.
Save awreece/4515720 to your computer and use it in GitHub Desktop.
Percent | Source code & Disassembly of a.out
------------------------------------------------
:
:
:
: Disassembly of section .text:
:
: 0000000000400869 <thread_scan>:
: size_t size;
: size_t* num_perfect_squares;
: mutex_t * num_perfect_squares_lock;
: } thread_arg_t;
:
: void* thread_scan(void* void_arg) {
0.00 : 400869: push %rbp
0.00 : 40086a: mov %rsp,%rbp
0.00 : 40086d: sub $0x28,%rsp
0.00 : 400871: mov %rdi,-0x28(%rbp)
: thread_arg_t* args = (thread_arg_t*) void_arg;
0.00 : 400875: mov -0x28(%rbp),%rax
0.00 : 400879: mov %rax,-0x10(%rbp)
: size_t i;
:
: for (i = 0; i < args->size; i++) {
0.00 : 40087d: movq $0x0,-0x8(%rbp)
0.00 : 400885: jmp 4008c9 <thread_scan+0x60>
: uint32_t val = args->input[i];
3.73 : 400887: mov -0x10(%rbp),%rax
0.00 : 40088b: mov (%rax),%rax
1.58 : 40088e: mov -0x8(%rbp),%rdx
0.00 : 400892: shl $0x2,%rdx
1.58 : 400896: add %rdx,%rax
0.53 : 400899: mov (%rax),%eax
14.17 : 40089b: mov %eax,-0x14(%rbp)
: uint32_t sqrt = integer_square_root(val);
1.82 : 40089e: mov -0x14(%rbp),%eax
8.09 : 4008a1: mov %eax,%edi
2.15 : 4008a3: callq 40080c <integer_square_root>
2.68 : 4008a8: mov %eax,-0x18(%rbp)
: if (sqrt * sqrt == val) {
1.96 : 4008ab: mov -0x18(%rbp),%eax
5.60 : 4008ae: imul -0x18(%rbp),%eax
6.65 : 4008b2: cmp -0x14(%rbp),%eax
0.00 : 4008b5: jne 4008c4 <thread_scan+0x5b>
: __sync_fetch_and_add(args->num_perfect_squares, 1)
3.59 : 4008b7: mov -0x10(%rbp),%rax
1.77 : 4008bb: mov 0x10(%rax),%rax
0.91 : 4008bf: lock addq $0x1,(%rax)
: void* thread_scan(void* void_arg) {
: // TODO(awreece) Copy locally so dont interfere with each ot
: thread_arg_t* args = (thread_arg_t*) void_arg;
: size_t i;
:
: for (i = 0; i < args->size; i++) {
38.10 : 4008c4: addq $0x1,-0x8(%rbp)
0.72 : 4008c9: mov -0x10(%rbp),%rax
0.29 : 4008cd: mov 0x8(%rax),%rax
4.07 : 4008d1: cmp -0x8(%rbp),%rax
0.00 : 4008d5: ja 400887 <thread_scan+0x1e>
: uint32_t sqrt = integer_square_root(val);
: if (sqrt * sqrt == val) {
: __sync_fetch_and_add(args->num_perfect_squares, 1)
: }
: }
: }
0.00 : 4008d7: leaveq
0.00 : 4008d8: retq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment