summaryrefslogtreecommitdiffstats
path: root/src/runtime/memmove_wasm.s
blob: 8525fea35ef4d558d67cf478444f7991b40861fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

#include "textflag.h"

// See memmove Go doc for important implementation constraints.

// func memmove(to, from unsafe.Pointer, n uintptr)
TEXT runtime·memmove(SB), NOSPLIT, $0-24
	MOVD to+0(FP), R0
	MOVD from+8(FP), R1
	MOVD n+16(FP), R2

	Get R0
	Get R1
	I64LtU
	If // forward
exit_forward_64:
		Block
loop_forward_64:
			Loop
				Get R2
				I64Const $8
				I64LtU
				BrIf exit_forward_64

				MOVD 0(R1), 0(R0)

				Get R0
				I64Const $8
				I64Add
				Set R0

				Get R1
				I64Const $8
				I64Add
				Set R1

				Get R2
				I64Const $8
				I64Sub
				Set R2

				Br loop_forward_64
			End
		End

loop_forward_8:
		Loop
			Get R2
			I64Eqz
			If
				RET
			End

			Get R0
			I32WrapI64
			I64Load8U (R1)
			I64Store8 $0

			Get R0
			I64Const $1
			I64Add
			Set R0

			Get R1
			I64Const $1
			I64Add
			Set R1

			Get R2
			I64Const $1
			I64Sub
			Set R2

			Br loop_forward_8
		End

	Else
		// backward
		Get R0
		Get R2
		I64Add
		Set R0

		Get R1
		Get R2
		I64Add
		Set R1

exit_backward_64:
		Block
loop_backward_64:
			Loop
				Get R2
				I64Const $8
				I64LtU
				BrIf exit_backward_64

				Get R0
				I64Const $8
				I64Sub
				Set R0

				Get R1
				I64Const $8
				I64Sub
				Set R1

				Get R2
				I64Const $8
				I64Sub
				Set R2

				MOVD 0(R1), 0(R0)

				Br loop_backward_64
			End
		End

loop_backward_8:
		Loop
			Get R2
			I64Eqz
			If
				RET
			End

			Get R0
			I64Const $1
			I64Sub
			Set R0

			Get R1
			I64Const $1
			I64Sub
			Set R1

			Get R2
			I64Const $1
			I64Sub
			Set R2

			Get R0
			I32WrapI64
			I64Load8U (R1)
			I64Store8 $0

			Br loop_backward_8
		End
	End

	UNDEF