Skip to content

Instantly share code, notes, and snippets.

@udoprog
Created January 4, 2018 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save udoprog/0437276b7ec3f0bb1b5ec07c3f83bf19 to your computer and use it in GitHub Desktop.
Save udoprog/0437276b7ec3f0bb1b5ec07c3f83bf19 to your computer and use it in GitHub Desktop.
heap:
.Lfunc_begin2:
.loc 1 21 0
.cfi_startproc
.cfi_personality 155, DW.ref.rust_eh_personality
.cfi_lsda 27, .Lexception0
pushq %rbp
.Lcfi6:
.cfi_def_cfa_offset 16
.Lcfi7:
.cfi_offset %rbp, -16
movq %rsp, %rbp
.Lcfi8:
.cfi_def_cfa_register %rbp
subq $240, %rsp
leaq -152(%rbp), %rdi
xorps %xmm0, %xmm0
movl $1000, %eax
movl %eax, %esi
.Ltmp39:
.loc 1 22 0 prologue_end
movb $0, -17(%rbp)
callq _ZN5alloc3vec9from_elem17hf07d28c2b6531c94E
.Ltmp40:
jmp .LBB2_2
.LBB2_1:
.loc 1 21 0
movq -16(%rbp), %rdi
callq _Unwind_Resume@PLT
ud2
.LBB2_2:
.Ltmp41:
.loc 1 23 0
.Ltmp18:
movl $1000, %eax
movl %eax, %esi
leaq -128(%rbp), %rdi
xorps %xmm0, %xmm0
callq _ZN5alloc3vec9from_elem17hf07d28c2b6531c94E
.Ltmp19:
jmp .LBB2_3
.LBB2_3:
.Ltmp42:
.loc 1 24 0
.Ltmp20:
movl $1000, %eax
movl %eax, %esi
leaq -104(%rbp), %rdi
xorps %xmm0, %xmm0
callq _ZN5alloc3vec9from_elem17hf07d28c2b6531c94E
.Ltmp21:
jmp .LBB2_5
.Ltmp43:
.LBB2_4:
.loc 1 0 0 is_stmt 0
leaq -152(%rbp), %rdi
.loc 1 27 0 is_stmt 1
callq _ZN4core3ptr13drop_in_place17h7df5d8de652fcb5cE
jmp .LBB2_1
.LBB2_5:
.Ltmp44:
.loc 1 25 0
movb $1, -17(%rbp)
.Ltmp23:
leaq -104(%rbp), %rdi
callq _ZN71_$LT$alloc..vec..Vec$LT$T$GT$$u20$as$u20$core..ops..deref..DerefMut$GT$9deref_mut17h14dab19f420b34d0E
.Ltmp24:
movq %rdx, -160(%rbp)
movq %rax, -168(%rbp)
jmp .LBB2_7
.Ltmp45:
.LBB2_6:
.loc 1 0 0 is_stmt 0
leaq -128(%rbp), %rdi
.loc 1 27 0 is_stmt 1
callq _ZN4core3ptr13drop_in_place17h7df5d8de652fcb5cE
jmp .LBB2_4
.LBB2_7:
.Ltmp46:
.loc 1 25 0
movq -168(%rbp), %rax
movq -160(%rbp), %rcx
.Ltmp25:
leaq -152(%rbp), %rdi
movq %rax, -176(%rbp)
movq %rcx, -184(%rbp)
callq _ZN68_$LT$alloc..vec..Vec$LT$T$GT$$u20$as$u20$core..ops..deref..Deref$GT$5deref17h451c13c331adf9e9E
.Ltmp26:
movq %rdx, -192(%rbp)
movq %rax, -200(%rbp)
jmp .LBB2_8
.LBB2_8:
movq -200(%rbp), %rax
movq -192(%rbp), %rcx
.Ltmp27:
leaq -128(%rbp), %rdi
movq %rax, -208(%rbp)
movq %rcx, -216(%rbp)
callq _ZN68_$LT$alloc..vec..Vec$LT$T$GT$$u20$as$u20$core..ops..deref..Deref$GT$5deref17h451c13c331adf9e9E
.Ltmp28:
movq %rdx, -224(%rbp)
movq %rax, -232(%rbp)
jmp .LBB2_9
.LBB2_9:
.Ltmp29:
movq -176(%rbp), %rdi
movq -184(%rbp), %rsi
movq -208(%rbp), %rdx
movq -216(%rbp), %rcx
movq -232(%rbp), %r8
movq -224(%rbp), %r9
callq _ZN7example11calculation17h734046dd54cac3eeE
.Ltmp30:
jmp .LBB2_10
.LBB2_10:
.loc 1 26 0
movb $0, -17(%rbp)
movq -88(%rbp), %rax
movq %rax, -32(%rbp)
movups -104(%rbp), %xmm0
movaps %xmm0, -48(%rbp)
.Ltmp31:
leaq -80(%rbp), %rdi
leaq -48(%rbp), %rsi
callq _ZN77_$LT$alloc..vec..Vec$LT$T$GT$$u20$as$u20$core..iter..traits..IntoIterator$GT$9into_iter17he5319b04ad223892E
.Ltmp32:
jmp .LBB2_11
.LBB2_11:
.Ltmp33:
leaq -80(%rbp), %rdi
callq _ZN4core4iter8iterator8Iterator3sum17h36c2230aec254670E
.Ltmp34:
movss %xmm0, -236(%rbp)
jmp .LBB2_12
.Ltmp47:
.LBB2_12:
.loc 1 27 0
movb $0, -17(%rbp)
.Ltmp48:
.loc 1 27 0 is_stmt 0
.Ltmp36:
leaq -128(%rbp), %rdi
callq _ZN4core3ptr13drop_in_place17h7df5d8de652fcb5cE
.Ltmp37:
jmp .LBB2_13
.Ltmp49:
.LBB2_13:
.loc 1 0 0
leaq -152(%rbp), %rdi
.loc 1 27 0
callq _ZN4core3ptr13drop_in_place17h7df5d8de652fcb5cE
movss -236(%rbp), %xmm0
addq $240, %rsp
popq %rbp
retq
#![feature(test)]
extern crate test;
fn calculation(r: &mut [f32], x: &[f32], y: &[f32]) {
for i in 0..x.len() {
r[i] = x[i] + y[i];
}
}
#[no_mangle]
pub fn stack() -> f32 {
let x = [0.; 1000];
let y = [0.; 1000];
let mut r = [0.; 1000];
calculation(&mut r, &x, &y);
r.into_iter().sum()
}
#[no_mangle]
pub fn heap() -> f32 {
let x = vec![0.; 1000];
let y = vec![0.; 1000];
let mut r = vec![0.; 1000];
calculation(&mut r, &x, &y);
r.into_iter().sum()
}
#[cfg(test)]
mod tests {
use super::calculation;
use test::Bencher;
#[bench]
fn stack(b: &mut Bencher) {
let x = [0.; 1000];
let y = [0.; 1000];
let mut r = [0.; 1000];
b.iter(|| {
calculation(&mut r, &x, &y);
});
}
#[bench]
fn heap(b: &mut Bencher) {
let x = vec![0.; 1000];
let y = vec![0.; 1000];
let mut r = vec![0.; 1000];
b.iter(|| {
calculation(&mut r, &x, &y);
});
}
}
stack:
.Lfunc_begin1:
.loc 1 12 0
.cfi_startproc
pushq %rbp
.Lcfi3:
.cfi_def_cfa_offset 16
.Lcfi4:
.cfi_offset %rbp, -16
movq %rsp, %rbp
.Lcfi5:
.cfi_def_cfa_register %rbp
movl $12128, %eax
callq __rust_probestack
subq %rax, %rsp
leaq -12000(%rbp), %rax
.Ltmp10:
.loc 1 13 0 prologue_end
movq %rax, %rcx
addq $4000, %rcx
movq %rcx, -12008(%rbp)
movq %rax, -12016(%rbp)
jmp .LBB1_4
.Ltmp11:
.LBB1_1:
.loc 1 0 0 is_stmt 0
movl $1000, %eax
movl %eax, %esi
leaq -4000(%rbp), %rcx
.Ltmp12:
.loc 1 17 0 is_stmt 1
movq %rcx, %rdi
callq _ZN4core5slice89_$LT$impl$u20$core..iter..traits..IntoIterator$u20$for$u20$$RF$$u27$a$u20$$u5b$T$u5d$$GT$9into_iter17hd50b5a9759cf0ab4E
movq %rax, -12024(%rbp)
movq %rdx, -12032(%rbp)
movq -12024(%rbp), %rdi
movq -12032(%rbp), %rsi
callq _ZN4core4iter8iterator8Iterator3sum17hf93627ac8622b805E
movss %xmm0, -12036(%rbp)
.Ltmp13:
.loc 1 18 0
movss -12036(%rbp), %xmm0
addq $12128, %rsp
popq %rbp
retq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment