Skip to content

Commit 27f28b1

Browse files
gbaraldivtjnash
authored andcommitted
Make isbitstypes use memmove instead of the runtime function in copyto! (#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 <[email protected]> (cherry picked from commit fee8090)
1 parent 0f7f762 commit 27f28b1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

base/genericmemory.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,17 @@ function unsafe_copyto!(dest::MemoryRef{T}, src::MemoryRef{T}, n) where {T}
114114
@_terminates_globally_notaskstate_meta
115115
n == 0 && return dest
116116
@boundscheck memoryref(dest, n), memoryref(src, n)
117-
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))
117+
if isbitstype(T)
118+
tdest = @_gc_preserve_begin dest
119+
tsrc = @_gc_preserve_begin src
120+
pdest = unsafe_convert(Ptr{Cvoid}, dest)
121+
psrc = unsafe_convert(Ptr{Cvoid}, src)
122+
memmove(pdest, psrc, aligned_sizeof(T) * n)
123+
@_gc_preserve_end tdest
124+
@_gc_preserve_end tsrc
125+
else
126+
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))
127+
end
118128
return dest
119129
end
120130

0 commit comments

Comments
 (0)