Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are the memcpys still done with Rust 2018/2021 without using this crate? #22

Closed
jaques-sam opened this issue Mar 27, 2022 · 1 comment
Closed

Comments

@jaques-sam
Copy link

No description provided.

@jaques-sam jaques-sam changed the title Are the memcpys still done with Rust 2018/2021? Are the memcpys still done with Rust 2018/2021 without using this crate? Mar 27, 2022
@kvark
Copy link
Owner

kvark commented Mar 28, 2022

Not seeing the copy any more on Rust playground:

#[inline(never)]
fn foo() -> Box<Foo> {
    Box::new(Foo::Small(4)) // this has 1 memcopy
    //Box::alloc().init(Foo::Small(4)) // this has 0 memcopies
}

LLVM:

; playground::foo
; Function Attrs: noinline nounwind nonlazybind uwtable
define internal fastcc noalias nonnull align 4 %Foo* @_ZN10playground3foo17h5e126e6c87b576a8E() unnamed_addr #2 personality i32 (i32, i32, i64, %"unwind::libunwind::_Unwind_Exception"*, %"unwind::libunwind::_Unwind_Context"*)* @rust_eh_personality {
start:
  %0 = tail call dereferenceable_or_null(404) i8* @__rust_alloc(i64 404, i64 4) #11, !noalias !7
  %1 = icmp eq i8* %0, null
  br i1 %1, label %bb3.i.i, label %"_ZN5alloc5boxed12Box$LT$T$GT$3new17hab47e76bc0e39a63E.exit"

bb3.i.i:                                          ; preds = %start
; call alloc::alloc::handle_alloc_error
  tail call void @_ZN5alloc5alloc18handle_alloc_error17h0ece3c434a8e0eb4E(i64 404, i64 4) #12, !noalias !7
  unreachable

"_ZN5alloc5boxed12Box$LT$T$GT$3new17hab47e76bc0e39a63E.exit": ; preds = %start
  %2 = bitcast i8* %0 to %Foo*
  store i8 0, i8* %0, align 4
  %_1.sroa.4.0..sroa_raw_idx = getelementptr inbounds i8, i8* %0, i64 1
  store i8 4, i8* %_1.sroa.4.0..sroa_raw_idx, align 1
  ret %Foo* %2
}

Asm:

playground::foo:
	pushq	%rax
	movl	$404, %edi
	movl	$4, %esi
	callq	*__rust_alloc@GOTPCREL(%rip)
	testq	%rax, %rax
	je	.LBB2_1
	movw	$1024, (%rax)
	popq	%rcx
	retq

Added the "[deprecated]" to crate description now.

@kvark kvark closed this as completed Mar 28, 2022
bors bot pushed a commit to bevyengine/bevy that referenced this issue Sep 27, 2022
# Objective
Remove copyless
copyless apparently isn't needed anymore to prevent extraneous memcopies and therefore got deprecated: kvark/copyless#22
james7132 pushed a commit to james7132/bevy that referenced this issue Oct 19, 2022
# Objective
Remove copyless
copyless apparently isn't needed anymore to prevent extraneous memcopies and therefore got deprecated: kvark/copyless#22
james7132 pushed a commit to james7132/bevy that referenced this issue Oct 28, 2022
# Objective
Remove copyless
copyless apparently isn't needed anymore to prevent extraneous memcopies and therefore got deprecated: kvark/copyless#22
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective
Remove copyless
copyless apparently isn't needed anymore to prevent extraneous memcopies and therefore got deprecated: kvark/copyless#22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants