github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/src/pkg/runtime/memmove_amd64.s (about) 1 // Derived from Inferno's libkern/memmove-386.s (adapted for amd64) 2 // http://code.google.com/p/inferno-os/source/browse/libkern/memmove-386.s 3 // 4 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 // Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved. 6 // Portions Copyright 2009 The Go Authors. All rights reserved. 7 // 8 // Permission is hereby granted, free of charge, to any person obtaining a copy 9 // of this software and associated documentation files (the "Software"), to deal 10 // in the Software without restriction, including without limitation the rights 11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 // copies of the Software, and to permit persons to whom the Software is 13 // furnished to do so, subject to the following conditions: 14 // 15 // The above copyright notice and this permission notice shall be included in 16 // all copies or substantial portions of the Software. 17 // 18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 // THE SOFTWARE. 25 26 // void runtime·memmove(void*, void*, uintptr) 27 TEXT runtime·memmove(SB), 7, $0 28 29 MOVQ to+0(FP), DI 30 MOVQ fr+8(FP), SI 31 MOVQ n+16(FP), BX 32 33 /* 34 * check and set for backwards 35 */ 36 CMPQ SI, DI 37 JLS back 38 39 /* 40 * forward copy loop 41 */ 42 forward: 43 MOVQ BX, CX 44 SHRQ $3, CX 45 ANDQ $7, BX 46 47 REP; MOVSQ 48 MOVQ BX, CX 49 REP; MOVSB 50 51 MOVQ to+0(FP),AX 52 RET 53 back: 54 /* 55 * check overlap 56 */ 57 MOVQ SI, CX 58 ADDQ BX, CX 59 CMPQ CX, DI 60 JLS forward 61 62 /* 63 * whole thing backwards has 64 * adjusted addresses 65 */ 66 ADDQ BX, DI 67 ADDQ BX, SI 68 STD 69 70 /* 71 * copy 72 */ 73 MOVQ BX, CX 74 SHRQ $3, CX 75 ANDQ $7, BX 76 77 SUBQ $8, DI 78 SUBQ $8, SI 79 REP; MOVSQ 80 81 ADDQ $7, DI 82 ADDQ $7, SI 83 MOVQ BX, CX 84 REP; MOVSB 85 86 CLD 87 MOVQ to+0(FP),AX 88 RET 89