github.com/tidwall/go@v0.0.0-20170415222209-6694a6888b7d/src/runtime/memmove_plan9_386.s (about) 1 // Inferno's libkern/memmove-386.s 2 // https://bitbucket.org/inferno-os/inferno-os/src/default/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 #include "textflag.h" 27 28 TEXT runtime·memmove(SB), NOSPLIT, $0-12 29 MOVL to+0(FP), DI 30 MOVL from+4(FP), SI 31 MOVL n+8(FP), BX 32 33 // REP instructions have a high startup cost, so we handle small sizes 34 // with some straightline code. The REP MOVSL instruction is really fast 35 // for large sizes. The cutover is approximately 1K. 36 tail: 37 TESTL BX, BX 38 JEQ move_0 39 CMPL BX, $2 40 JBE move_1or2 41 CMPL BX, $4 42 JB move_3 43 JE move_4 44 CMPL BX, $8 45 JBE move_5through8 46 CMPL BX, $16 47 JBE move_9through16 48 49 /* 50 * check and set for backwards 51 */ 52 CMPL SI, DI 53 JLS back 54 55 /* 56 * forward copy loop 57 */ 58 forward: 59 MOVL BX, CX 60 SHRL $2, CX 61 ANDL $3, BX 62 63 REP; MOVSL 64 JMP tail 65 /* 66 * check overlap 67 */ 68 back: 69 MOVL SI, CX 70 ADDL BX, CX 71 CMPL CX, DI 72 JLS forward 73 /* 74 * whole thing backwards has 75 * adjusted addresses 76 */ 77 78 ADDL BX, DI 79 ADDL BX, SI 80 STD 81 82 /* 83 * copy 84 */ 85 MOVL BX, CX 86 SHRL $2, CX 87 ANDL $3, BX 88 89 SUBL $4, DI 90 SUBL $4, SI 91 REP; MOVSL 92 93 CLD 94 ADDL $4, DI 95 ADDL $4, SI 96 SUBL BX, DI 97 SUBL BX, SI 98 JMP tail 99 100 move_1or2: 101 MOVB (SI), AX 102 MOVB -1(SI)(BX*1), CX 103 MOVB AX, (DI) 104 MOVB CX, -1(DI)(BX*1) 105 RET 106 move_0: 107 RET 108 move_3: 109 MOVW (SI), AX 110 MOVB 2(SI), CX 111 MOVW AX, (DI) 112 MOVB CX, 2(DI) 113 RET 114 move_4: 115 // We need a separate case for 4 to make sure we write pointers atomically. 116 MOVL (SI), AX 117 MOVL AX, (DI) 118 RET 119 move_5through8: 120 MOVL (SI), AX 121 MOVL -4(SI)(BX*1), CX 122 MOVL AX, (DI) 123 MOVL CX, -4(DI)(BX*1) 124 RET 125 move_9through16: 126 MOVL (SI), AX 127 MOVL 4(SI), CX 128 MOVL -8(SI)(BX*1), DX 129 MOVL -4(SI)(BX*1), BP 130 MOVL AX, (DI) 131 MOVL CX, 4(DI) 132 MOVL DX, -8(DI)(BX*1) 133 MOVL BP, -4(DI)(BX*1) 134 RET