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