ssa: builtin copy

This commit is contained in:
visualfc
2024-05-19 19:33:41 +08:00
parent af4a0ffa21
commit cda572fd59
6 changed files with 98 additions and 0 deletions

View File

@@ -63,6 +63,9 @@ func Malloc(size uintptr) Pointer
//go:linkname Memcpy C.memcpy
func Memcpy(dst, src Pointer, n uintptr) Pointer
//go:linkname Memmove C.memmove
func Memmove(dst, src Pointer, n uintptr) Pointer
//go:linkname Memset C.memset
func Memset(s Pointer, c Int, n uintptr) Pointer

Binary file not shown.

View File

@@ -91,4 +91,16 @@ func SliceAppend(src Slice, data unsafe.Pointer, num, etSize int) Slice {
return src
}
// SliceCopy copy data to slice and returns a slice.
func SliceCopy(dst Slice, data unsafe.Pointer, num int, etSize int) int {
n := dst.len
if n > num {
n = num
}
if n > 0 {
c.Memmove(dst.data, data, uintptr(n*etSize))
}
return n
}
// -----------------------------------------------------------------------------