Text file
src/runtime/memmove_riscv64.s
1 // Copyright 2016 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 // void runtime·memmove(void*, void*, uintptr)
10 TEXT runtime·memmove<ABIInternal>(SB),NOSPLIT,$-0-24
11 #ifndef GOEXPERIMENT_regabiargs
12 MOV to+0(FP), A0
13 MOV from+8(FP), A1
14 MOV n+16(FP), A2
15 #endif
16 ADD A1, A2, T5
17
18 // If the destination is ahead of the source, start at the end of the
19 // buffer and go backward.
20 BLTU A1, A0, b
21
22 // If less than eight bytes, do one byte at a time.
23 SLTU $8, A2, T3
24 BNE T3, ZERO, f_outcheck
25
26 // Do one byte at a time until from is eight-aligned.
27 JMP f_aligncheck
28 f_align:
29 MOVB (A1), T3
30 MOVB T3, (A0)
31 ADD $1, A0
32 ADD $1, A1
33 f_aligncheck:
34 AND $7, A1, T3
35 BNE T3, ZERO, f_align
36
37 // Do eight bytes at a time as long as there is room.
38 ADD $-7, T5, T6
39 JMP f_wordscheck
40 f_words:
41 MOV (A1), T3
42 MOV T3, (A0)
43 ADD $8, A0
44 ADD $8, A1
45 f_wordscheck:
46 SLTU T6, A1, T3
47 BNE T3, ZERO, f_words
48
49 // Finish off the remaining partial word.
50 JMP f_outcheck
51 f_out:
52 MOVB (A1), T3
53 MOVB T3, (A0)
54 ADD $1, A0
55 ADD $1, A1
56 f_outcheck:
57 BNE A1, T5, f_out
58
59 RET
60
61 b:
62 ADD A0, A2, T4
63 // If less than eight bytes, do one byte at a time.
64 SLTU $8, A2, T3
65 BNE T3, ZERO, b_outcheck
66
67 // Do one byte at a time until from+n is eight-aligned.
68 JMP b_aligncheck
69 b_align:
70 ADD $-1, T4
71 ADD $-1, T5
72 MOVB (T5), T3
73 MOVB T3, (T4)
74 b_aligncheck:
75 AND $7, T5, T3
76 BNE T3, ZERO, b_align
77
78 // Do eight bytes at a time as long as there is room.
79 ADD $7, A1, T6
80 JMP b_wordscheck
81 b_words:
82 ADD $-8, T4
83 ADD $-8, T5
84 MOV (T5), T3
85 MOV T3, (T4)
86 b_wordscheck:
87 SLTU T5, T6, T3
88 BNE T3, ZERO, b_words
89
90 // Finish off the remaining partial word.
91 JMP b_outcheck
92 b_out:
93 ADD $-1, T4
94 ADD $-1, T5
95 MOVB (T5), T3
96 MOVB T3, (T4)
97 b_outcheck:
98 BNE T5, A1, b_out
99
100 RET
101
View as plain text