-
Notifications
You must be signed in to change notification settings - Fork 12
/
kernel_m4n4k16.S
245 lines (203 loc) · 5.1 KB
/
kernel_m4n4k16.S
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
.text
.align 5
.global kernel_sub_m4n4k16
kernel_sub_m4n4k16:
// x0: sa
// x1: sb
// x2: sc
// x3: ldc
// x4: repeat
// preload sa and sb
prfm pldl1keep, [x0, #128]
prfm pldl1keep, [x1, #128]
#ld1 {v0.16b, v1.16b, v2.16b, v3.16b}, [x0], #64
#ld1 {v4.16b, v5.16b, v6.16b, v7.16b}, [x1], #64
ld1 {v0.16b}, [x0], #16
dup v16.4s, wzr
ld1 {v4.16b}, [x1], #16
dup v17.4s, wzr
ld1 {v1.16b}, [x0], #16
dup v18.4s, wzr
ld1 {v5.16b}, [x1], #16
dup v19.4s, wzr
ld1 {v2.16b}, [x0], #16
dup v20.4s, wzr
ld1 {v6.16b}, [x1], #16
dup v21.4s, wzr
ld1 {v3.16b}, [x0], #16
dup v22.4s, wzr
ld1 {v7.16b}, [x1], #16
dup v23.4s, wzr
// INIT RESULT
dup v24.4s, wzr
dup v25.4s, wzr
dup v26.4s, wzr
dup v27.4s, wzr
dup v28.4s, wzr
dup v29.4s, wzr
dup v30.4s, wzr
dup v31.4s, wzr
// design:
// sb | v4.16b v5.16b v6.16b v7.16b
//
// | v0.16b v8 v9 v10 v11
// sa| v1.16b v12 v13 v14 v15
// | v2.16b
// | v3.16b
//
// ||
// accumulate ||
// ||
//
// sb | v4.16b v5.16b v6.16b v7.16b
//
// | v0.16b v16 v17 v18 v19
// sa| v1.16b v20 v21 v22 v23
// | v2.16b ...
// | v3.16b .. v31
smull v8.8h, v0.8b, v4.8b
smull v9.8h, v0.8b, v5.8b
smull v10.8h, v0.8b, v6.8b
smull v11.8h, v0.8b, v7.8b
smull v12.8h, v1.8b, v4.8b
smull v13.8h, v1.8b, v5.8b
smull v14.8h, v1.8b, v6.8b
smull v15.8h, v1.8b, v7.8b
smlal2 v8.8h, v0.16b, v4.16b
smlal2 v9.8h, v0.16b, v5.16b
smlal2 v10.8h, v0.16b, v6.16b
smlal2 v11.8h, v0.16b, v7.16b
smlal2 v12.8h, v1.16b, v4.16b
smlal2 v13.8h, v1.16b, v5.16b
smlal2 v14.8h, v1.16b, v6.16b
smlal2 v15.8h, v1.16b, v7.16b
subs x4, x4, #1
beq .LLOOP_LAST
.LLOOP:
sadalp v16.4s, v8.8h
smull v8.8h, v2.8b, v4.8b
ld1 {v0.16b}, [x0], #16
ld1 {v1.16b}, [x0], #16
sadalp v17.4s, v9.8h
smull v9.8h, v2.8b, v5.8b
sadalp v18.4s, v10.8h
smull v10.8h, v2.8b, v6.8b
sadalp v19.4s, v11.8h
smull v11.8h, v2.8b, v7.8b
sadalp v20.4s, v12.8h
smull v12.8h, v3.8b, v4.8b
sadalp v21.4s, v13.8h
smull v13.8h, v3.8b, v5.8b
sadalp v22.4s, v14.8h
smull v14.8h, v3.8b, v6.8b
sadalp v23.4s, v15.8h
smull v15.8h, v3.8b, v7.8b
smlal2 v8.8h, v2.16b, v4.16b
smlal2 v9.8h, v2.16b, v5.16b
smlal2 v10.8h, v2.16b, v6.16b
smlal2 v11.8h, v2.16b, v7.16b
ld1 {v2.16b}, [x0], #16
smlal2 v12.8h, v3.16b, v4.16b
ld1 {v4.16b}, [x1], #16
smlal2 v13.8h, v3.16b, v5.16b
ld1 {v5.16b}, [x1], #16
smlal2 v14.8h, v3.16b, v6.16b
ld1 {v6.16b}, [x1], #16
smlal2 v15.8h, v3.16b, v7.16b
ld1 {v3.16b}, [x0], #16
ld1 {v7.16b}, [x1], #16
sadalp v24.4s, v8.8h
sadalp v25.4s, v9.8h
sadalp v26.4s, v10.8h
sadalp v27.4s, v11.8h
sadalp v28.4s, v12.8h
sadalp v29.4s, v13.8h
sadalp v30.4s, v14.8h
sadalp v31.4s, v15.8h
smull v8.8h, v0.8b, v4.8b
smull v9.8h, v0.8b, v5.8b
smull v10.8h, v0.8b, v6.8b
smull v11.8h, v0.8b, v7.8b
smull v12.8h, v1.8b, v4.8b
smull v13.8h, v1.8b, v5.8b
smull v14.8h, v1.8b, v6.8b
smull v15.8h, v1.8b, v7.8b
smlal2 v8.8h, v0.16b, v4.16b
smlal2 v9.8h, v0.16b, v5.16b
smlal2 v10.8h, v0.16b, v6.16b
smlal2 v11.8h, v0.16b, v7.16b
smlal2 v12.8h, v1.16b, v4.16b
smlal2 v13.8h, v1.16b, v5.16b
smlal2 v14.8h, v1.16b, v6.16b
smlal2 v15.8h, v1.16b, v7.16b
prfm pldl1keep, [x0, #128]
prfm pldl1keep, [x1, #128]
subs x4, x4, #1
bne .LLOOP
.LLOOP_LAST:
// proc first two lines
sadalp v16.4s, v8.8h
smull v8.8h, v2.8b, v4.8b
sadalp v17.4s, v9.8h
smull v9.8h, v2.8b, v5.8b
sadalp v18.4s, v10.8h
smull v10.8h, v2.8b, v6.8b
sadalp v19.4s, v11.8h
smull v11.8h, v2.8b, v7.8b
sadalp v20.4s, v12.8h
smull v12.8h, v3.8b, v4.8b
sadalp v21.4s, v13.8h
smull v13.8h, v3.8b, v5.8b
sadalp v22.4s, v14.8h
smull v14.8h, v3.8b, v6.8b
sadalp v23.4s, v15.8h
smull v15.8h, v3.8b, v7.8b
// proc last two lines
smlal2 v8.8h, v2.16b, v4.16b
sadalp v24.4s, v8.8h
smlal2 v9.8h, v2.16b, v5.16b
sadalp v25.4s, v9.8h
smlal2 v10.8h, v2.16b, v6.16b
sadalp v26.4s, v10.8h
smlal2 v11.8h, v2.16b, v7.16b
sadalp v27.4s, v11.8h
smlal2 v12.8h, v3.16b, v4.16b
sadalp v28.4s, v12.8h
smlal2 v13.8h, v3.16b, v5.16b
sadalp v29.4s, v13.8h
smlal2 v14.8h, v3.16b, v6.16b
sadalp v30.4s, v14.8h
smlal2 v15.8h, v3.16b, v7.16b
sadalp v31.4s, v15.8h
// add pairwise
addp v0.4s, v16.4s, v17.4s
addp v1.4s, v18.4s, v19.4s
addp v2.4s, v20.4s, v21.4s
addp v3.4s, v22.4s, v23.4s
addp v4.4s, v24.4s, v25.4s
addp v5.4s, v26.4s, v27.4s
addp v6.4s, v28.4s, v29.4s
addp v7.4s, v30.4s, v31.4s
addp v8.4s, v0.4s, v1.4s
addp v9.4s, v2.4s, v3.4s
addp v10.4s, v4.4s, v5.4s
addp v11.4s, v6.4s, v7.4s
//dup v8.4s, wzr
//dup v9.4s, wzr
//dup v10.4s, wzr
//dup v11.4s, wzr
// write C
mov x6, x2
ld1 {v12.16b}, [x2], x3
add v12.4s, v12.4s, v8.4s
st1 {v12.16b}, [x6], x3
ld1 {v13.16b}, [x2], x3
add v13.4s, v13.4s, v9.4s
st1 {v13.16b}, [x6], x3
ld1 {v14.16b}, [x2], x3
add v14.4s, v14.4s, v10.4s
st1 {v14.16b}, [x6], x3
ld1 {v15.16b}, [x2], x3
add v15.4s, v15.4s, v11.4s
st1 {v15.16b}, [x6], x3
ret