Skip to content

Instantly share code, notes, and snippets.

@eira-fransham
Last active May 7, 2018 11:45
Show Gist options
  • Save eira-fransham/2d180d83821fc4f129b176a9a0f1dc63 to your computer and use it in GitHub Desktop.
Save eira-fransham/2d180d83821fc4f129b176a9a0f1dc63 to your computer and use it in GitHub Desktop.
Comparison of assembly for a simple case
pub fn disassemble() {
let smallvec: SmallVec<[_; 16]> = smallvec![10; 100];
test::black_box(smallvec);
}
<T as core::any::Any>::get_type_id:
movabsq $1229646359891580772, %rax
retq
<T as core::any::Any>::get_type_id:
movabsq $7549865886324542212, %rax
retq
std::panicking::begin_panic:
subq $24, %rsp
movq %rdx, %rax
movq %rdi, 8(%rsp)
movq %rsi, 16(%rsp)
leaq .Lvtable.0(%rip), %rsi
leaq 8(%rsp), %rdi
xorl %edx, %edx
movq %rax, %rcx
callq std::panicking::rust_panic_with_hook@PLT
ud2
<alloc::raw_vec::RawVec<T, A>>::allocate_in::{{closure}}:
pushq %rax
callq alloc::raw_vec::capacity_overflow@PLT
ud2
core::ptr::drop_in_place:
retq
core::ptr::drop_in_place:
retq
core::ptr::drop_in_place:
retq
core::ptr::drop_in_place:
cmpl $0, 8(%rdi)
je .LBB7_3
movq 24(%rdi), %rsi
testq %rsi, %rsi
je .LBB7_2
movq 16(%rdi), %rdi
shlq $2, %rsi
movl $4, %edx
jmp __rust_dealloc@PLT
.LBB7_3:
movl $1, 8(%rdi)
addq $16, %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
retq
.LBB7_2:
retq
<std::panicking::begin_panic::PanicPayload<A> as core::panic::BoxMeUp>::get:
cmpq $0, (%rdi)
leaq .Lvtable.9(%rip), %rax
leaq .Lvtable.8(%rip), %rdx
cmoveq %rax, %rdx
leaq .Lbyte_str.2(%rip), %rax
cmovneq %rdi, %rax
retq
<std::panicking::begin_panic::PanicPayload<A> as core::panic::BoxMeUp>::box_me_up:
pushq %r14
pushq %rbx
pushq %rax
movq (%rdi), %rbx
movq 8(%rdi), %r14
movq $0, (%rdi)
testq %rbx, %rbx
je .LBB9_1
movl $16, %edi
movl $8, %esi
callq __rust_alloc@PLT
testq %rax, %rax
je .LBB9_5
movq %rbx, (%rax)
movq %r14, 8(%rax)
leaq .Lvtable.8(%rip), %rdx
addq $8, %rsp
popq %rbx
popq %r14
retq
.LBB9_1:
leaq .Lvtable.9(%rip), %rdx
movl $1, %eax
addq $8, %rsp
popq %rbx
popq %r14
retq
.LBB9_5:
callq alloc::alloc::oom@PLT
ud2
example::disassemble:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $320, %rsp
movq $0, 80(%rsp)
movl $0, 88(%rsp)
movl $400, %edi
movl $4, %esi
callq __rust_alloc@PLT
testq %rax, %rax
je .LBB10_1
movl $1, 88(%rsp)
movq %rax, 96(%rsp)
movq $100, 104(%rsp)
movups 112(%rsp), %xmm0
movups 128(%rsp), %xmm1
movups 144(%rsp), %xmm2
movaps %xmm0, 32(%rsp)
movaps %xmm1, 48(%rsp)
movaps %xmm2, 64(%rsp)
movups 80(%rsp), %xmm0
movaps %xmm0, (%rsp)
movups 96(%rsp), %xmm0
movaps %xmm0, 16(%rsp)
movq (%rsp), %r14
movl 8(%rsp), %eax
testl %eax, %eax
je .LBB10_4
movq 24(%rsp), %rcx
subq %r14, %rcx
cmpq $99, %rcx
jbe .LBB10_7
.LBB10_23:
testl %eax, %eax
je .LBB10_24
movq 16(%rsp), %rbx
jmp .LBB10_26
.LBB10_4:
movl $16, %ecx
subq %r14, %rcx
cmpq $99, %rcx
ja .LBB10_23
.LBB10_7:
addq $100, %r14
jb .LBB10_10
movq %r14, %rdi
callq core::num::<impl usize>::checked_next_power_of_two@PLT
movq %rdx, %r15
testq %rax, %rax
je .LBB10_10
movq (%rsp), %r14
cmpq %r15, %r14
ja .LBB10_12
movl $4, %ecx
movq %r15, %rax
mulq %rcx
jo .LBB10_14
testq %rax, %rax
je .LBB10_16
movl $4, %esi
movq %rax, %rdi
callq __rust_alloc@PLT
movq %rax, %rbx
testq %rbx, %rbx
jne .LBB10_17
callq alloc::alloc::oom@PLT
jmp .LBB10_2
.LBB10_24:
leaq 12(%rsp), %rbx
jmp .LBB10_26
.LBB10_16:
movl $4, %ebx
.LBB10_17:
movl 8(%rsp), %ebp
cmpl $0, %ebp
leaq 12(%rsp), %rsi
movq 16(%rsp), %r12
cmovneq %r12, %rsi
leaq (,%r14,4), %rdx
movq %rbx, %rdi
callq memcpy@PLT
cmpl $0, %ebp
je .LBB10_20
movq 24(%rsp), %rsi
testq %rsi, %rsi
je .LBB10_20
shlq $2, %rsi
movl $4, %edx
movq %r12, %rdi
callq __rust_dealloc@PLT
movq (%rsp), %r14
.LBB10_20:
movl $1, 8(%rsp)
movq %rbx, 16(%rsp)
movq %r15, 24(%rsp)
.LBB10_26:
leaq 400(%rbx), %r15
leaq (,%r14,4), %r12
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq memmove@PLT
movq $-100, %rax
.LBB10_27:
movl $10, 400(%rbx,%rax,4)
addq $1, (%rsp)
movl $10, 404(%rbx,%rax,4)
addq $1, (%rsp)
movl $10, 408(%rbx,%rax,4)
addq $1, (%rsp)
movl $10, 412(%rbx,%rax,4)
movq (%rsp), %rcx
addq $1, %rcx
movq %rcx, (%rsp)
addq $4, %rax
jne .LBB10_27
subq %r14, %rcx
cmpq $100, %rcx
jae .LBB10_30
leaq (%rbx,%rcx,4), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq memmove@PLT
.LBB10_30:
movaps 64(%rsp), %xmm0
movaps %xmm0, 224(%rsp)
movaps (%rsp), %xmm0
movaps 16(%rsp), %xmm1
movaps 32(%rsp), %xmm2
movaps 48(%rsp), %xmm3
movaps %xmm3, 208(%rsp)
movaps %xmm2, 192(%rsp)
movaps %xmm1, 176(%rsp)
movaps %xmm0, 160(%rsp)
movaps 224(%rsp), %xmm0
movaps %xmm0, 144(%rsp)
movaps 160(%rsp), %xmm0
movaps 176(%rsp), %xmm1
movaps 192(%rsp), %xmm2
movaps 208(%rsp), %xmm3
movaps %xmm3, 128(%rsp)
movaps %xmm2, 112(%rsp)
movaps %xmm1, 96(%rsp)
movaps %xmm0, 80(%rsp)
leaq 80(%rsp), %rax
movaps 80(%rsp), %xmm0
movaps 96(%rsp), %xmm1
movaps 112(%rsp), %xmm2
movaps %xmm0, 240(%rsp)
movaps 128(%rsp), %xmm0
movaps %xmm1, 256(%rsp)
movaps 144(%rsp), %xmm1
movaps %xmm1, 304(%rsp)
movaps %xmm0, 288(%rsp)
movaps %xmm2, 272(%rsp)
cmpl $0, 248(%rsp)
je .LBB10_31
movq 264(%rsp), %rsi
testq %rsi, %rsi
je .LBB10_37
movq 256(%rsp), %rdi
shlq $2, %rsi
movl $4, %edx
callq __rust_dealloc@PLT
jmp .LBB10_37
.LBB10_31:
leaq 256(%rsp), %rax
movl $1, 248(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
.LBB10_37:
addq $320, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
.LBB10_1:
callq alloc::alloc::oom@PLT
jmp .LBB10_2
.LBB10_10:
callq <alloc::raw_vec::RawVec<T, A>>::allocate_in::{{closure}}
jmp .LBB10_2
.LBB10_12:
leaq .Lbyte_str.c(%rip), %rdi
leaq .Lbyte_str.b(%rip), %rdx
movl $37, %esi
callq std::panicking::begin_panic
jmp .LBB10_2
.LBB10_14:
callq <alloc::raw_vec::RawVec<T, A>>::allocate_in::{{closure}}
.LBB10_2:
ud2
movq %rax, %rbx
leaq 80(%rsp), %rdi
callq core::ptr::drop_in_place
movq %rbx, %rdi
callq _Unwind_Resume@PLT
ud2
movq %rax, %rbx
movq %rsp, %rdi
callq core::ptr::drop_in_place
movq %rbx, %rdi
callq _Unwind_Resume@PLT
ud2
.Lvtable.0:
.quad core::ptr::drop_in_place
.quad 16
.quad 8
.quad <std::panicking::begin_panic::PanicPayload<A> as core::panic::BoxMeUp>::box_me_up
.quad <std::panicking::begin_panic::PanicPayload<A> as core::panic::BoxMeUp>::get
.Lbyte_str.2:
.Lvtable.8:
.quad core::ptr::drop_in_place
.quad 16
.quad 8
.quad <T as core::any::Any>::get_type_id
.Lvtable.9:
.quad core::ptr::drop_in_place
.quad 0
.quad 1
.quad <T as core::any::Any>::get_type_id
.Lbyte_str.a:
.ascii "/tmp/compiler-explorer-compiler11847-56-1nf7h2f.zfmdf/example.rs"
.Lbyte_str.b:
.quad .Lbyte_str.a
.asciz "@\000\000\000\000\000\000\000\351\001\000\000\t\000\000"
.Lbyte_str.c:
.ascii "assertion failed: new_cap >= self.len"
.LCPI0_0:
.long 10
.long 10
.long 10
.long 10
example::disassemble:
subq $216, %rsp
movl $400, %edi
movl $4, %esi
callq __rust_alloc@PLT
testq %rax, %rax
je .LBB0_6
movaps .LCPI0_0(%rip), %xmm0
movups %xmm0, (%rax)
movups %xmm0, 16(%rax)
movups %xmm0, 32(%rax)
movups %xmm0, 48(%rax)
movups %xmm0, 64(%rax)
movups %xmm0, 80(%rax)
movups %xmm0, 96(%rax)
movups %xmm0, 112(%rax)
movups %xmm0, 128(%rax)
movups %xmm0, 144(%rax)
movups %xmm0, 160(%rax)
movups %xmm0, 176(%rax)
movups %xmm0, 192(%rax)
movups %xmm0, 208(%rax)
movups %xmm0, 224(%rax)
movups %xmm0, 240(%rax)
movups %xmm0, 256(%rax)
movups %xmm0, 272(%rax)
movups %xmm0, 288(%rax)
movups %xmm0, 304(%rax)
movups %xmm0, 320(%rax)
movups %xmm0, 336(%rax)
movups %xmm0, 352(%rax)
movups %xmm0, 368(%rax)
movups %xmm0, 384(%rax)
movq $100, (%rsp)
movl $1, 8(%rsp)
movq %rax, 16(%rsp)
movq $100, 24(%rsp)
movups 168(%rsp), %xmm0
movups 184(%rsp), %xmm1
movups 200(%rsp), %xmm2
movups %xmm0, 32(%rsp)
movups %xmm1, 48(%rsp)
movups %xmm2, 64(%rsp)
movq %rsp, %rax
movups (%rsp), %xmm0
movups 16(%rsp), %xmm1
movups 32(%rsp), %xmm2
movaps %xmm0, 80(%rsp)
movups 48(%rsp), %xmm0
movaps %xmm1, 96(%rsp)
movups 64(%rsp), %xmm1
movaps %xmm1, 144(%rsp)
movaps %xmm0, 128(%rsp)
movaps %xmm2, 112(%rsp)
cmpl $0, 88(%rsp)
je .LBB0_2
movq 104(%rsp), %rsi
testq %rsi, %rsi
je .LBB0_5
movq 96(%rsp), %rdi
shlq $2, %rsi
movl $4, %edx
callq __rust_dealloc@PLT
.LBB0_5:
addq $216, %rsp
retq
.LBB0_2:
leaq 96(%rsp), %rax
movl $1, 88(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
addq $216, %rsp
retq
.LBB0_6:
callq alloc::alloc::oom@PLT
ud2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment