github.com/twelsh-aw/go/src@v0.0.0-20230516233729-a56fe86a7c81/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 PCALIGN $16 46 SGTU R6, R4, R8 47 BEQ R8, out 48 MOVV (R5), R7 49 ADDV $8, R5 50 MOVV R7, (R4) 51 ADDV $8, R4 52 JMP -6(PC) 53 54 out: 55 BEQ R4, R9, done 56 MOVB (R5), R7 57 ADDV $1, R5 58 MOVB R7, (R4) 59 ADDV $1, R4 60 JMP -5(PC) 61 done: 62 RET 63 64 backward: 65 ADDV R6, R5 // from-end pointer 66 ADDV R4, R6, R9 // to-end pointer 67 68 // if the two pointers are not of same alignments, do byte copying 69 SUBVU R9, R5, R7 70 AND $7, R7 71 BNE R7, out1 72 73 // if less than 8 bytes, do byte copying 74 SGTU $8, R6, R7 75 BNE R7, out1 76 77 // do one byte at a time until 8-aligned 78 AND $7, R9, R8 79 BEQ R8, words1 80 ADDV $-1, R5 81 MOVB (R5), R7 82 ADDV $-1, R9 83 MOVB R7, (R9) 84 JMP -6(PC) 85 86 words1: 87 // do 8 bytes at a time if there is room 88 ADDV $7, R4, R6 // R6 is start pointer+7 89 90 PCALIGN $16 91 SGTU R9, R6, R8 92 BEQ R8, out1 93 ADDV $-8, R5 94 MOVV (R5), R7 95 ADDV $-8, R9 96 MOVV R7, (R9) 97 JMP -6(PC) 98 99 out1: 100 BEQ R4, R9, done1 101 ADDV $-1, R5 102 MOVB (R5), R7 103 ADDV $-1, R9 104 MOVB R7, (R9) 105 JMP -5(PC) 106 done1: 107 RET