From b4bb47d88fa95a587b73c936eeb373348dab9f15 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 7 Apr 2020 21:39:39 -0700 Subject: [PATCH] runtime: simplify typedmemmovepartial The offset is always a multiple of the pointer size. Change-Id: I790e087e89a081044a3ec35d99880533a4c929bd Reviewed-on: https://go-review.googlesource.com/c/go/+/227540 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall Reviewed-by: Austin Clements --- src/runtime/mbarrier.go | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/runtime/mbarrier.go b/src/runtime/mbarrier.go index 264376da9b..0199053183 100644 --- a/src/runtime/mbarrier.go +++ b/src/runtime/mbarrier.go @@ -193,32 +193,18 @@ func reflectlite_typedmemmove(typ *_type, dst, src unsafe.Pointer) { // typedmemmovepartial is like typedmemmove but assumes that // dst and src point off bytes into the value and only copies size bytes. +// off must be a multiple of sys.PtrSize. //go:linkname reflect_typedmemmovepartial reflect.typedmemmovepartial func reflect_typedmemmovepartial(typ *_type, dst, src unsafe.Pointer, off, size uintptr) { - if writeBarrier.needed && typ.ptrdata != 0 && size >= sys.PtrSize { - // Pointer-align start address for bulk barrier. - adst, asrc, asize := dst, src, size - ptrdata := typ.ptrdata - if ptrdata > off { - ptrdata -= off - } else { - ptrdata = 0 + if writeBarrier.needed && typ.ptrdata > off && size >= sys.PtrSize { + if off&(sys.PtrSize-1) != 0 { + panic("reflect: internal error: misaligned offset") } - if frag := -off & (sys.PtrSize - 1); frag != 0 { - adst = add(dst, frag) - asrc = add(src, frag) - asize -= frag - if ptrdata > frag { - ptrdata -= frag - } else { - ptrdata = 0 - } + pwsize := alignDown(size, sys.PtrSize) + if poff := typ.ptrdata - off; pwsize > poff { + pwsize = poff } - pwsize := asize &^ (sys.PtrSize - 1) - if pwsize > ptrdata { - pwsize = ptrdata - } - bulkBarrierPreWrite(uintptr(adst), uintptr(asrc), pwsize) + bulkBarrierPreWrite(uintptr(dst), uintptr(src), pwsize) } memmove(dst, src, size) -- 2.50.0