github.com/mtsmfm/go/src@v0.0.0-20221020090648-44bdcb9f8fde/runtime/memmove_loong64.s (about) 1 // Copyright 2022 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 #include "textflag.h" 6 7 // See memmove Go doc for important implementation constraints. 8 9 // func memmove(to, from unsafe.Pointer, n uintptr) 10 TEXT runtime·memmove(SB), NOSPLIT|NOFRAME, $0-24 11 MOVV to+0(FP), R4 12 MOVV from+8(FP), R5 13 MOVV n+16(FP), R6 14 BNE R6, check 15 RET 16 17 check: 18 SGTU R4, R5, R7 19 BNE R7, backward 20 21 ADDV R4, R6, R9 // end pointer 22 23 // if the two pointers are not of same alignments, do byte copying 24 SUBVU R5, R4, R7 25 AND $7, R7 26 BNE R7, out 27 28 // if less than 8 bytes, do byte copying 29 SGTU $8, R6, R7 30 BNE R7, out 31 32 // do one byte at a time until 8-aligned 33 AND $7, R4, R8 34 BEQ R8, words 35 MOVB (R5), R7 36 ADDV $1, R5 37 MOVB R7, (R4) 38 ADDV $1, R4 39 JMP -6(PC) 40 41 words: 42 // do 8 bytes at a time if there is room 43 ADDV $-7, R9, R6 // R6 is end pointer-7 44 45 SGTU R6, R4, R8 46 BEQ R8, out 47 MOVV (R5), R7 48 ADDV $8, R5 49 MOVV R7, (R4) 50 ADDV $8, R4 51 JMP -6(PC) 52 53 out: 54 BEQ R4, R9, done 55 MOVB (R5), R7 56 ADDV $1, R5 57 MOVB R7, (R4) 58 ADDV $1, R4 59 JMP -5(PC) 60 done: 61 RET 62 63 backward: 64 ADDV R6, R5 // from-end pointer 65 ADDV R4, R6, R9 // to-end pointer 66 67 // if the two pointers are not of same alignments, do byte copying 68 SUBVU R9, R5, R7 69 AND $7, R7 70 BNE R7, out1 71 72 // if less than 8 bytes, do byte copying 73 SGTU $8, R6, R7 74 BNE R7, out1 75 76 // do one byte at a time until 8-aligned 77 AND $7, R9, R8 78 BEQ R8, words1 79 ADDV $-1, R5 80 MOVB (R5), R7 81 ADDV $-1, R9 82 MOVB R7, (R9) 83 JMP -6(PC) 84 85 words1: 86 // do 8 bytes at a time if there is room 87 ADDV $7, R4, R6 // R6 is start pointer+7 88 89 SGTU R9, R6, R8 90 BEQ R8, out1 91 ADDV $-8, R5 92 MOVV (R5), R7 93 ADDV $-8, R9 94 MOVV R7, (R9) 95 JMP -6(PC) 96 97 out1: 98 BEQ R4, R9, done1 99 ADDV $-1, R5 100 MOVB (R5), R7 101 ADDV $-1, R9 102 MOVB R7, (R9) 103 JMP -5(PC) 104 done1: 105 RET