diff options
author | Quan Yong Zhai <qyzhai@gmail.com> | 2011-06-09 16:49:47 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2011-06-09 16:49:47 -0400 |
commit | 439694125f980fc0c96e99b347fa9742633f4757 (patch) | |
tree | 4a8a603ef69afff7463e8bf44887dc87e778389e | |
parent | 17ca32e9db2f58a6ed431c4502f6ab031147673f (diff) | |
download | go-439694125f980fc0c96e99b347fa9742633f4757.tar.gz go-439694125f980fc0c96e99b347fa9742633f4757.zip |
runtime: improve memmove
check memory overlap
R=rsc, r, ken, edsrzf
CC=golang-dev
https://golang.org/cl/4602047
-rw-r--r-- | src/pkg/runtime/386/memmove.s | 12 | ||||
-rw-r--r-- | src/pkg/runtime/amd64/memmove.s | 12 |
2 files changed, 20 insertions, 4 deletions
diff --git a/src/pkg/runtime/386/memmove.s b/src/pkg/runtime/386/memmove.s index 38a0652b5d..471553ba21 100644 --- a/src/pkg/runtime/386/memmove.s +++ b/src/pkg/runtime/386/memmove.s @@ -32,7 +32,6 @@ TEXT runtime·memmove(SB), 7, $0 /* * check and set for backwards - * should we look closer for overlap? */ CMPL SI, DI JLS back @@ -40,6 +39,7 @@ TEXT runtime·memmove(SB), 7, $0 /* * forward copy loop */ +forward: MOVL BX, CX SHRL $2, CX ANDL $3, BX @@ -51,10 +51,18 @@ TEXT runtime·memmove(SB), 7, $0 MOVL to+0(FP),AX RET /* + * check overlap + */ +back: + MOVL SI, CX + ADDL BX, CX + CMPL CX, DI + JLS forward +/* * whole thing backwards has * adjusted addresses */ -back: + ADDL BX, DI ADDL BX, SI STD diff --git a/src/pkg/runtime/amd64/memmove.s b/src/pkg/runtime/amd64/memmove.s index 9966b0ba7a..fc9573f72e 100644 --- a/src/pkg/runtime/amd64/memmove.s +++ b/src/pkg/runtime/amd64/memmove.s @@ -33,7 +33,6 @@ TEXT runtime·memmove(SB), 7, $0 /* * check and set for backwards - * should we look closer for overlap? */ CMPQ SI, DI JLS back @@ -41,6 +40,7 @@ TEXT runtime·memmove(SB), 7, $0 /* * forward copy loop */ +forward: MOVQ BX, CX SHRQ $3, CX ANDQ $7, BX @@ -51,11 +51,19 @@ TEXT runtime·memmove(SB), 7, $0 MOVQ to+0(FP),AX RET +back: +/* + * check overlap + */ + MOVQ SI, CX + ADDQ BX, CX + CMPQ CX, DI + JLS forward + /* * whole thing backwards has * adjusted addresses */ -back: ADDQ BX, DI ADDQ BX, SI STD |