diff options
| author | Ken Thompson <ken@golang.org> | 2009-11-17 20:41:44 -0800 |
|---|---|---|
| committer | Ken Thompson <ken@golang.org> | 2009-11-17 20:41:44 -0800 |
| commit | c4606d05da2d4ae7bfb32def1e9df2092e4a9da4 (patch) | |
| tree | cc48862b2b903f5bacb744c888eb0a64d1642cc5 /src/pkg | |
| parent | a8ba40823c08508ca5f7562501a26bc2e85c88eb (diff) | |
| download | go-c4606d05da2d4ae7bfb32def1e9df2092e4a9da4.tar.xz | |
install copy predefined
did not test 386, but should work
shouldnt matter if copy is not used
R=rsc
https://golang.org/cl/156055
Diffstat (limited to 'src/pkg')
| -rw-r--r-- | src/pkg/runtime/Makefile | 1 | ||||
| -rw-r--r-- | src/pkg/runtime/memmove_386.s | 65 | ||||
| -rw-r--r-- | src/pkg/runtime/memmove_amd64.s | 65 | ||||
| -rw-r--r-- | src/pkg/runtime/slice.c | 33 |
4 files changed, 164 insertions, 0 deletions
diff --git a/src/pkg/runtime/Makefile b/src/pkg/runtime/Makefile index 08bf278ef4..3c97c495f6 100644 --- a/src/pkg/runtime/Makefile +++ b/src/pkg/runtime/Makefile @@ -68,6 +68,7 @@ OFILES=\ sys.$O\ thread.$O\ traceback.$O\ + memmove_$(GOARCH).$O\ $(OFILES_$(GOARCH))\ HFILES=\ diff --git a/src/pkg/runtime/memmove_386.s b/src/pkg/runtime/memmove_386.s new file mode 100644 index 0000000000..f7bc402590 --- /dev/null +++ b/src/pkg/runtime/memmove_386.s @@ -0,0 +1,65 @@ + TEXT memmove(SB), $0 + + MOVL to+0(FP), DI + MOVL fr+4(FP), SI + MOVL n+8(FP), BX + JLT fault + +/* + * check and set for backwards + * should we look closer for overlap? + */ + CMPL SI, DI + JLS back + +/* + * foreward copy loop + */ + MOVL BX, CX + SHRL $2, CX + ANDL $3, BX + + REP; MOVSL + MOVL BX, CX + REP; MOVSB + + MOVL to+0(FP),AX + RET +/* + * whole thing backwards has + * adjusted addresses + */ +back: + ADDL BX, DI + ADDL BX, SI + STD + +/* + * copy + */ + MOVL BX, CX + SHRL $2, CX + ANDL $3, BX + + SUBL $4, DI + SUBL $4, SI + REP; MOVSL + + ADDL $3, DI + ADDL $3, SI + MOVL BX, CX + REP; MOVSB + + CLD + MOVL to+0(FP),AX + RET + +/* + * if called with negative count, + * treat as error rather than + * rotating all of memory + */ +fault: + MOVL $0,SI + MOVL 0(SI), AX + RET diff --git a/src/pkg/runtime/memmove_amd64.s b/src/pkg/runtime/memmove_amd64.s new file mode 100644 index 0000000000..7444d3bdbf --- /dev/null +++ b/src/pkg/runtime/memmove_amd64.s @@ -0,0 +1,65 @@ + TEXT memmove(SB), $0 + + MOVQ to+0(FP), DI + MOVQ fr+8(FP), SI + MOVLQSX n+16(FP), BX + JLT fault + +/* + * check and set for backwards + * should we look closer for overlap? + */ + CMPQ SI, DI + JLS back + +/* + * foreward copy loop + */ + MOVQ BX, CX + SHRQ $3, CX + ANDQ $7, BX + + REP; MOVSQ + MOVQ BX, CX + REP; MOVSB + + MOVQ to+0(FP),AX + RET +/* + * whole thing backwards has + * adjusted addresses + */ +back: + ADDQ BX, DI + ADDQ BX, SI + STD + +/* + * copy + */ + MOVQ BX, CX + SHRQ $3, CX + ANDQ $7, BX + + SUBQ $8, DI + SUBQ $8, SI + REP; MOVSQ + + ADDQ $7, DI + ADDQ $7, SI + MOVQ BX, CX + REP; MOVSB + + CLD + MOVQ to+0(FP),AX + RET + +/* + * if called with negative count, + * treat as error rather than + * rotating all of memory + */ +fault: + MOVQ $0,SI + MOVQ 0(SI), AX + RET diff --git a/src/pkg/runtime/slice.c b/src/pkg/runtime/slice.c index 722802c004..00d9724fbe 100644 --- a/src/pkg/runtime/slice.c +++ b/src/pkg/runtime/slice.c @@ -177,6 +177,39 @@ runtime·arraytoslice(byte* old, uint32 nel, Slice ret) } } +// slicecopy(to any, fr any, wid uint32) int +void +runtime·slicecopy(Slice to, Slice fm, uintptr width, int32 ret) +{ + if(fm.array == nil || fm.len == 0 || + to.array == nil || to.len == 0 || + width == 0) { + ret = 0; + goto out; + } + + ret = fm.len; + if(to.len > ret) + ret = to.len; + + memmove(to.array, fm.array, ret*width); + +out: + FLUSH(&ret); + + if(debug) { + prints("main·copy: to="); + runtime·printslice(to); + prints("; fm="); + runtime·printslice(fm); + prints("; width="); + runtime·printint(width); + prints("; ret="); + runtime·printint(ret); + prints("\n"); + } +} + void runtime·printslice(Slice a) { |
