Skip to content

Commit

Permalink
refactor: move bumping algorithm to its own module for testability an…
Browse files Browse the repository at this point in the history
…d readability
  • Loading branch information
bluurryy committed Aug 24, 2024
1 parent 02aed02 commit 89a241d
Show file tree
Hide file tree
Showing 7 changed files with 329 additions and 218 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ let mut bump: Bump = Bump::new();
bump.scoped(|mut bump| {
let hello = bump.alloc_str("hello");
assert_eq!(bump.stats().allocated(), 5);

bump.scoped(|bump| {
let world = bump.alloc_str("world");

println!("{hello} and {world} are both live");
assert_eq!(bump.stats().allocated(), 10);
});

println!("{hello} is still live");
assert_eq!(bump.stats().allocated(), 5);
});
Expand All @@ -86,7 +86,7 @@ assert_eq!(bump.stats().allocated(), 0);

let hello = bump.alloc_str("hello");
assert_eq!(bump.stats().allocated(), 5);

{
let mut guard = bump.scope_guard();
let bump = guard.scope();
Expand All @@ -96,7 +96,7 @@ assert_eq!(bump.stats().allocated(), 0);
println!("{hello} and {world} are both live");
assert_eq!(bump.stats().allocated(), 10);
}

println!("{hello} is still live");
assert_eq!(bump.stats().allocated(), 5);
}
Expand Down
63 changes: 32 additions & 31 deletions crates/inspect-asm/out/x86-64/alloc_iter_u32/exact_down.asm
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
inspect_asm::alloc_iter_u32::exact_down:
push r15
push r14
push rbx
push rax
mov rax, rdx
shr rax, 61
jne .LBB0_7
lea rbx, [4*rdx]
lea r8, [4*rdx]
mov rcx, qword ptr [rdi]
mov rax, qword ptr [rcx]
mov r8, rax
sub r8, qword ptr [rcx + 8]
cmp rbx, r8
mov r9, rax
sub r9, qword ptr [rcx + 8]
cmp r8, r9
ja .LBB0_5
sub rax, rbx
sub rax, r8
and rax, -4
mov qword ptr [rcx], rax
test rdx, rdx
je .LBB0_4
.LBB0_0:
add rbx, -4
shr rbx, 2
cmp rdx, rbx
cmovb rbx, rdx
lea rcx, [rdx - 1]
movabs r8, 4611686018427387903
and r8, rcx
cmp rdx, r8
cmovb r8, rdx
mov rcx, rsi
mov rdi, rax
cmp rbx, 8
cmp r8, 8
jb .LBB0_2
mov r8, rax
sub r8, rsi
mov r9, rax
sub r9, rsi
mov rcx, rsi
mov rdi, rax
cmp r8, 31
cmp r9, 31
jbe .LBB0_2
inc rbx
mov ecx, ebx
inc r8
mov ecx, r8d
and ecx, 7
mov edi, 8
cmovne rdi, rcx
sub rbx, rdi
lea rcx, [rsi + 4*rbx]
lea rdi, [rax + 4*rbx]
xor r8d, r8d
sub r8, rdi
lea rcx, [rsi + 4*r8]
lea rdi, [rax + 4*r8]
xor r9d, r9d
.LBB0_1:
movups xmm0, xmmword ptr [rsi + 4*r8]
movups xmm1, xmmword ptr [rsi + 4*r8 + 16]
movups xmmword ptr [rax + 4*r8], xmm0
movups xmmword ptr [rax + 4*r8 + 16], xmm1
add r8, 8
cmp rbx, r8
movups xmm0, xmmword ptr [rsi + 4*r9]
movups xmm1, xmmword ptr [rsi + 4*r9 + 16]
movups xmmword ptr [rax + 4*r9], xmm0
movups xmmword ptr [rax + 4*r9 + 16], xmm1
add r9, 8
cmp r8, r9
jne .LBB0_1
.LBB0_2:
lea rsi, [rsi + 4*rdx]
Expand All @@ -62,17 +63,17 @@ inspect_asm::alloc_iter_u32::exact_down:
cmp rdi, r8
jne .LBB0_3
.LBB0_4:
add rsp, 8
pop rbx
pop r14
pop r15
ret
.LBB0_5:
mov r14, rsi
mov rbx, rsi
mov rsi, rdx
mov r15, rdx
mov r14, rdx
call bump_scope::bump_scope::BumpScope<A,_,_,_>::do_alloc_slice_in_another_chunk
mov rsi, r14
mov rdx, r15
mov rsi, rbx
mov rdx, r14
test rdx, rdx
jne .LBB0_0
jmp .LBB0_4
Expand Down
69 changes: 35 additions & 34 deletions crates/inspect-asm/out/x86-64/alloc_iter_u32/exact_down_a.asm
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
inspect_asm::alloc_iter_u32::exact_down_a:
push r15
push r14
push rbx
push rax
mov rax, rdx
shr rax, 61
jne .LBB0_7
lea rbx, [4*rdx]
mov rcx, qword ptr [rdi]
mov rax, qword ptr [rcx]
mov r8, rax
sub r8, qword ptr [rcx + 8]
cmp rbx, r8
lea rcx, [4*rdx]
mov r8, qword ptr [rdi]
mov rax, qword ptr [r8]
mov r9, rax
sub r9, qword ptr [r8 + 8]
cmp rcx, r9
ja .LBB0_5
sub rax, rbx
mov qword ptr [rcx], rax
sub rax, rcx
mov qword ptr [r8], rax
test rdx, rdx
je .LBB0_4
.LBB0_0:
add rbx, -4
shr rbx, 2
cmp rdx, rbx
cmovb rbx, rdx
lea rcx, [rdx - 1]
movabs r8, 4611686018427387903
and r8, rcx
cmp rdx, r8
cmovb r8, rdx
mov rcx, rsi
mov rdi, rax
cmp rbx, 8
cmp r8, 8
jb .LBB0_2
mov r8, rax
sub r8, rsi
mov r9, rax
sub r9, rsi
mov rcx, rsi
mov rdi, rax
cmp r8, 31
cmp r9, 31
jbe .LBB0_2
inc rbx
mov ecx, ebx
inc r8
mov ecx, r8d
and ecx, 7
mov edi, 8
cmovne rdi, rcx
sub rbx, rdi
lea rcx, [rsi + 4*rbx]
lea rdi, [rax + 4*rbx]
xor r8d, r8d
sub r8, rdi
lea rcx, [rsi + 4*r8]
lea rdi, [rax + 4*r8]
xor r9d, r9d
.LBB0_1:
movups xmm0, xmmword ptr [rsi + 4*r8]
movups xmm1, xmmword ptr [rsi + 4*r8 + 16]
movups xmmword ptr [rax + 4*r8], xmm0
movups xmmword ptr [rax + 4*r8 + 16], xmm1
add r8, 8
cmp rbx, r8
movups xmm0, xmmword ptr [rsi + 4*r9]
movups xmm1, xmmword ptr [rsi + 4*r9 + 16]
movups xmmword ptr [rax + 4*r9], xmm0
movups xmmword ptr [rax + 4*r9 + 16], xmm1
add r9, 8
cmp r8, r9
jne .LBB0_1
.LBB0_2:
lea rsi, [rsi + 4*rdx]
Expand All @@ -61,17 +62,17 @@ inspect_asm::alloc_iter_u32::exact_down_a:
cmp rdi, r8
jne .LBB0_3
.LBB0_4:
add rsp, 8
pop rbx
pop r14
pop r15
ret
.LBB0_5:
mov r14, rsi
mov rbx, rsi
mov rsi, rdx
mov r15, rdx
mov r14, rdx
call bump_scope::bump_scope::BumpScope<A,_,_,_>::do_alloc_slice_in_another_chunk
mov rsi, r14
mov rdx, r15
mov rsi, rbx
mov rdx, r14
test rdx, rdx
jne .LBB0_0
jmp .LBB0_4
Expand Down
Loading

0 comments on commit 89a241d

Please sign in to comment.