Skip to content

Commit

Permalink
Make isbitstypes use memmove instead of the runtime function in copyt…
Browse files Browse the repository at this point in the history
…o! (#56237)

This might help llvm understand whats going on. Also enzyme really wants
this to look like this to trace through it better.
---------

Co-authored-by: Jameson Nash <vtjnash@gmail.com>
  • Loading branch information
gbaraldi and vtjnash authored Oct 21, 2024
1 parent a4a4b95 commit fee8090
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion base/genericmemory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,17 @@ function unsafe_copyto!(dest::MemoryRef{T}, src::MemoryRef{T}, n) where {T}
@_terminates_globally_notaskstate_meta
n == 0 && return dest
@boundscheck memoryref(dest, n), memoryref(src, n)
ccall(:jl_genericmemory_copyto, Cvoid, (Any, Ptr{Cvoid}, Any, Ptr{Cvoid}, Int), dest.mem, dest.ptr_or_offset, src.mem, src.ptr_or_offset, Int(n))
if isbitstype(T)
tdest = @_gc_preserve_begin dest
tsrc = @_gc_preserve_begin src
pdest = unsafe_convert(Ptr{Cvoid}, dest)
psrc = unsafe_convert(Ptr{Cvoid}, src)
memmove(pdest, psrc, aligned_sizeof(T) * n)
@_gc_preserve_end tdest
@_gc_preserve_end tsrc
else
ccall(:jl_genericmemory_copyto, Cvoid, (Any, Ptr{Cvoid}, Any, Ptr{Cvoid}, Int), dest.mem, dest.ptr_or_offset, src.mem, src.ptr_or_offset, Int(n))
end
return dest
end

Expand Down

0 comments on commit fee8090

Please sign in to comment.