Commit 43969412 authored by Quan Yong Zhai's avatar Quan Yong Zhai Committed by Russ Cox

runtime: improve memmove

check memory overlap

R=rsc, r, ken, edsrzf
CC=golang-dev
https://golang.org/cl/4602047
parent 17ca32e9
...@@ -32,7 +32,6 @@ TEXT runtime·memmove(SB), 7, $0 ...@@ -32,7 +32,6 @@ TEXT runtime·memmove(SB), 7, $0
/* /*
* check and set for backwards * check and set for backwards
* should we look closer for overlap?
*/ */
CMPL SI, DI CMPL SI, DI
JLS back JLS back
...@@ -40,6 +39,7 @@ TEXT runtime·memmove(SB), 7, $0 ...@@ -40,6 +39,7 @@ TEXT runtime·memmove(SB), 7, $0
/* /*
* forward copy loop * forward copy loop
*/ */
forward:
MOVL BX, CX MOVL BX, CX
SHRL $2, CX SHRL $2, CX
ANDL $3, BX ANDL $3, BX
...@@ -50,11 +50,19 @@ TEXT runtime·memmove(SB), 7, $0 ...@@ -50,11 +50,19 @@ TEXT runtime·memmove(SB), 7, $0
MOVL to+0(FP),AX MOVL to+0(FP),AX
RET RET
/*
* check overlap
*/
back:
MOVL SI, CX
ADDL BX, CX
CMPL CX, DI
JLS forward
/* /*
* whole thing backwards has * whole thing backwards has
* adjusted addresses * adjusted addresses
*/ */
back:
ADDL BX, DI ADDL BX, DI
ADDL BX, SI ADDL BX, SI
STD STD
......
...@@ -33,7 +33,6 @@ TEXT runtime·memmove(SB), 7, $0 ...@@ -33,7 +33,6 @@ TEXT runtime·memmove(SB), 7, $0
/* /*
* check and set for backwards * check and set for backwards
* should we look closer for overlap?
*/ */
CMPQ SI, DI CMPQ SI, DI
JLS back JLS back
...@@ -41,6 +40,7 @@ TEXT runtime·memmove(SB), 7, $0 ...@@ -41,6 +40,7 @@ TEXT runtime·memmove(SB), 7, $0
/* /*
* forward copy loop * forward copy loop
*/ */
forward:
MOVQ BX, CX MOVQ BX, CX
SHRQ $3, CX SHRQ $3, CX
ANDQ $7, BX ANDQ $7, BX
...@@ -51,11 +51,19 @@ TEXT runtime·memmove(SB), 7, $0 ...@@ -51,11 +51,19 @@ TEXT runtime·memmove(SB), 7, $0
MOVQ to+0(FP),AX MOVQ to+0(FP),AX
RET RET
back:
/*
* check overlap
*/
MOVQ SI, CX
ADDQ BX, CX
CMPQ CX, DI
JLS forward
/* /*
* whole thing backwards has * whole thing backwards has
* adjusted addresses * adjusted addresses
*/ */
back:
ADDQ BX, DI ADDQ BX, DI
ADDQ BX, SI ADDQ BX, SI
STD STD
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment