]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: use runtime's memmove instead of its own
authorKeith Randall <khr@golang.org>
Wed, 10 Sep 2014 19:37:28 +0000 (12:37 -0700)
committerKeith Randall <khr@golang.org>
Wed, 10 Sep 2014 19:37:28 +0000 (12:37 -0700)
They will both need write barriers at some point.
But until then, no reason why we shouldn't share.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/141330043

src/reflect/value.go
src/runtime/thunk.s

index 368116a507cd2b77439b0a63b35992aa03093ff6..20d0e92ed120bbe577285a8d89471b82e3c23b0f 100644 (file)
@@ -15,32 +15,6 @@ const bigEndian = false // can be smarter if we find a big-endian machine
 const ptrSize = unsafe.Sizeof((*byte)(nil))
 const cannotSet = "cannot set value obtained from unexported struct field"
 
-// TODO: This will have to go away when
-// the new gc goes in.
-func memmove(adst, asrc unsafe.Pointer, n uintptr) {
-       dst := uintptr(adst)
-       src := uintptr(asrc)
-       switch {
-       case src < dst && src+n > dst:
-               // byte copy backward
-               // careful: i is unsigned
-               for i := n; i > 0; {
-                       i--
-                       *(*byte)(unsafe.Pointer(dst + i)) = *(*byte)(unsafe.Pointer(src + i))
-               }
-       case (n|src|dst)&(ptrSize-1) != 0:
-               // byte copy forward
-               for i := uintptr(0); i < n; i++ {
-                       *(*byte)(unsafe.Pointer(dst + i)) = *(*byte)(unsafe.Pointer(src + i))
-               }
-       default:
-               // word copy forward
-               for i := uintptr(0); i < n; i += ptrSize {
-                       *(*uintptr)(unsafe.Pointer(dst + i)) = *(*uintptr)(unsafe.Pointer(src + i))
-               }
-       }
-}
-
 // Value is the reflection interface to a Go value.
 //
 // Not all methods apply to all kinds of values.  Restrictions,
@@ -2703,6 +2677,9 @@ func call(fn, arg unsafe.Pointer, n uint32, retoffset uint32)
 
 func ifaceE2I(t *rtype, src interface{}, dst unsafe.Pointer)
 
+//go:noescape
+func memmove(adst, asrc unsafe.Pointer, n uintptr)
+
 // Dummy annotation marking that the value x escapes,
 // for use in cases where the reflect code is so clever that
 // the compiler cannot follow.
index 7ba22d705e5341a534f9e2e0d0327aa0ea8876a9..3b66cf47d31c6b29c477108bfc50ce286ee3687b 100644 (file)
@@ -74,6 +74,9 @@ TEXT reflect·chansend(SB), NOSPLIT, $0-0
 TEXT reflect·chanrecv(SB), NOSPLIT, $0-0
        JMP     runtime·reflect_chanrecv(SB)
 
+TEXT reflect·memmove(SB), NOSPLIT, $0-0
+       JMP     runtime·memmove(SB)
+
 TEXT runtime∕debug·freeOSMemory(SB), NOSPLIT, $0-0
        JMP     runtime·freeOSMemory(SB)