Skip to content

Commit fee8090

Browse files
gbaraldivtjnash
andauthored
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 <vtjnash@gmail.com>
1 parent a4a4b95 commit fee8090

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
@@ -118,7 +118,17 @@ function unsafe_copyto!(dest::MemoryRef{T}, src::MemoryRef{T}, n) where {T}
118118
@_terminates_globally_notaskstate_meta
119119
n == 0 && return dest
120120
@boundscheck memoryref(dest, n), memoryref(src, n)
121-
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))
121+
if isbitstype(T)
122+
tdest = @_gc_preserve_begin dest
123+
tsrc = @_gc_preserve_begin src
124+
pdest = unsafe_convert(Ptr{Cvoid}, dest)
125+
psrc = unsafe_convert(Ptr{Cvoid}, src)
126+
memmove(pdest, psrc, aligned_sizeof(T) * n)
127+
@_gc_preserve_end tdest
128+
@_gc_preserve_end tsrc
129+
else
130+
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))
131+
end
122132
return dest
123133
end
124134

0 commit comments

Comments
 (0)