summaryrefslogtreecommitdiffstats
path: root/src/runtime/memmove_s390x.s
blob: f4c2b87d9297d48083370e2b9ed770ad89511158 (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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// Copyright 2016 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|NOFRAME,$0-24
	MOVD	to+0(FP), R6
	MOVD	from+8(FP), R4
	MOVD	n+16(FP), R5

	CMPBEQ	R6, R4, done

start:
	CMPBLE	R5, $3, move0to3
	CMPBLE	R5, $7, move4to7
	CMPBLE	R5, $11, move8to11
	CMPBLE	R5, $15, move12to15
	CMPBNE	R5, $16, movemt16
	MOVD	0(R4), R7
	MOVD	8(R4), R8
	MOVD	R7, 0(R6)
	MOVD	R8, 8(R6)
	RET

movemt16:
	CMPBGT	R4, R6, forwards
	ADD	R5, R4, R7
	CMPBLE	R7, R6, forwards
	ADD	R5, R6, R8
backwards:
	MOVD	-8(R7), R3
	MOVD	R3, -8(R8)
	MOVD	-16(R7), R3
	MOVD	R3, -16(R8)
	ADD	$-16, R5
	ADD	$-16, R7
	ADD	$-16, R8
	CMP	R5, $16
	BGE	backwards
	BR	start

forwards:
	CMPBGT	R5, $64, forwards_fast
	MOVD	0(R4), R3
	MOVD	R3, 0(R6)
	MOVD	8(R4), R3
	MOVD	R3, 8(R6)
	ADD	$16, R4
	ADD	$16, R6
	ADD	$-16, R5
	CMP	R5, $16
	BGE	forwards
	BR	start

forwards_fast:
	CMP	R5, $256
	BLE	forwards_small
	MVC	$256, 0(R4), 0(R6)
	ADD	$256, R4
	ADD	$256, R6
	ADD	$-256, R5
	BR	forwards_fast

forwards_small:
	CMPBEQ	R5, $0, done
	ADD	$-1, R5
	EXRL	$memmove_exrl_mvc<>(SB), R5
	RET

move0to3:
	CMPBEQ	R5, $0, done
move1:
	CMPBNE	R5, $1, move2
	MOVB	0(R4), R3
	MOVB	R3, 0(R6)
	RET
move2:
	CMPBNE	R5, $2, move3
	MOVH	0(R4), R3
	MOVH	R3, 0(R6)
	RET
move3:
	MOVH	0(R4), R3
	MOVB	2(R4), R7
	MOVH	R3, 0(R6)
	MOVB	R7, 2(R6)
	RET

move4to7:
	CMPBNE	R5, $4, move5
	MOVW	0(R4), R3
	MOVW	R3, 0(R6)
	RET
move5:
	CMPBNE	R5, $5, move6
	MOVW	0(R4), R3
	MOVB	4(R4), R7
	MOVW	R3, 0(R6)
	MOVB	R7, 4(R6)
	RET
move6:
	CMPBNE	R5, $6, move7
	MOVW	0(R4), R3
	MOVH	4(R4), R7
	MOVW	R3, 0(R6)
	MOVH	R7, 4(R6)
	RET
move7:
	MOVW	0(R4), R3
	MOVH	4(R4), R7
	MOVB	6(R4), R8
	MOVW	R3, 0(R6)
	MOVH	R7, 4(R6)
	MOVB	R8, 6(R6)
	RET

move8to11:
	CMPBNE	R5, $8, move9
	MOVD	0(R4), R3
	MOVD	R3, 0(R6)
	RET
move9:
	CMPBNE	R5, $9, move10
	MOVD	0(R4), R3
	MOVB	8(R4), R7
	MOVD	R3, 0(R6)
	MOVB	R7, 8(R6)
	RET
move10:
	CMPBNE	R5, $10, move11
	MOVD	0(R4), R3
	MOVH	8(R4), R7
	MOVD	R3, 0(R6)
	MOVH	R7, 8(R6)
	RET
move11:
	MOVD	0(R4), R3
	MOVH	8(R4), R7
	MOVB	10(R4), R8
	MOVD	R3, 0(R6)
	MOVH	R7, 8(R6)
	MOVB	R8, 10(R6)
	RET

move12to15:
	CMPBNE	R5, $12, move13
	MOVD	0(R4), R3
	MOVW	8(R4), R7
	MOVD	R3, 0(R6)
	MOVW	R7, 8(R6)
	RET
move13:
	CMPBNE	R5, $13, move14
	MOVD	0(R4), R3
	MOVW	8(R4), R7
	MOVB	12(R4), R8
	MOVD	R3, 0(R6)
	MOVW	R7, 8(R6)
	MOVB	R8, 12(R6)
	RET
move14:
	CMPBNE	R5, $14, move15
	MOVD	0(R4), R3
	MOVW	8(R4), R7
	MOVH	12(R4), R8
	MOVD	R3, 0(R6)
	MOVW	R7, 8(R6)
	MOVH	R8, 12(R6)
	RET
move15:
	MOVD	0(R4), R3
	MOVW	8(R4), R7
	MOVH	12(R4), R8
	MOVB	14(R4), R10
	MOVD	R3, 0(R6)
	MOVW	R7, 8(R6)
	MOVH	R8, 12(R6)
	MOVB	R10, 14(R6)
done:
	RET

// DO NOT CALL - target for exrl (execute relative long) instruction.
TEXT memmove_exrl_mvc<>(SB),NOSPLIT|NOFRAME,$0-0
	MVC	$1, 0(R4), 0(R6)
	MOVD	R0, 0(R0)
	RET