Text file
src/runtime/memmove_loong64.s
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<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-24
11 BNE R6, check
12 RET
13
14 check:
15 SGTU R4, R5, R7
16 BNE R7, backward
17
18 ADDV R4, R6, R9 // end pointer
19
20 // if the two pointers are not of same alignments, do byte copying
21 SUBVU R5, R4, R7
22 AND $7, R7
23 BNE R7, out
24
25 // if less than 8 bytes, do byte copying
26 SGTU $8, R6, R7
27 BNE R7, out
28
29 // do one byte at a time until 8-aligned
30 AND $7, R4, R8
31 BEQ R8, words
32 MOVB (R5), R7
33 ADDV $1, R5
34 MOVB R7, (R4)
35 ADDV $1, R4
36 JMP -6(PC)
37
38 words:
39 // do 8 bytes at a time if there is room
40 ADDV $-7, R9, R6 // R6 is end pointer-7
41
42 PCALIGN $16
43 SGTU R6, R4, R8
44 BEQ R8, out
45 MOVV (R5), R7
46 ADDV $8, R5
47 MOVV R7, (R4)
48 ADDV $8, R4
49 JMP -6(PC)
50
51 out:
52 BEQ R4, R9, done
53 MOVB (R5), R7
54 ADDV $1, R5
55 MOVB R7, (R4)
56 ADDV $1, R4
57 JMP -5(PC)
58 done:
59 RET
60
61 backward:
62 ADDV R6, R5 // from-end pointer
63 ADDV R4, R6, R9 // to-end pointer
64
65 // if the two pointers are not of same alignments, do byte copying
66 SUBVU R9, R5, R7
67 AND $7, R7
68 BNE R7, out1
69
70 // if less than 8 bytes, do byte copying
71 SGTU $8, R6, R7
72 BNE R7, out1
73
74 // do one byte at a time until 8-aligned
75 AND $7, R9, R8
76 BEQ R8, words1
77 ADDV $-1, R5
78 MOVB (R5), R7
79 ADDV $-1, R9
80 MOVB R7, (R9)
81 JMP -6(PC)
82
83 words1:
84 // do 8 bytes at a time if there is room
85 ADDV $7, R4, R6 // R6 is start pointer+7
86
87 PCALIGN $16
88 SGTU R9, R6, R8
89 BEQ R8, out1
90 ADDV $-8, R5
91 MOVV (R5), R7
92 ADDV $-8, R9
93 MOVV R7, (R9)
94 JMP -6(PC)
95
96 out1:
97 BEQ R4, R9, done1
98 ADDV $-1, R5
99 MOVB (R5), R7
100 ADDV $-1, R9
101 MOVB R7, (R9)
102 JMP -5(PC)
103 done1:
104 RET
105
View as plain text