-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxDialateThread.asm
More file actions
354 lines (286 loc) · 7.44 KB
/
Copy pathMaxDialateThread.asm
File metadata and controls
354 lines (286 loc) · 7.44 KB
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# My FIRST GPU assembly program
.include "vc4.qinc"
#
# The main code starts after the Definitions and Macros sections
#
############################################################
# Definitions
############################################################
.set M_FF000000, ra2
.set setup_indexed_final, rb0
.set gpuindex, ra1
.set gpuindex8, ra4
.set start_y, rb1
.set elem_offs, ra3
.set add_input_x, rb16
.set add_input_y, rb4
.set add_nexta, ra5
.set add_nextb, rb5
.set gpuindexjump, ra6
.set num_gpus, rb6
.set numreps, ra7
.set in_addr, ra0
.set M_00FFFFFF, ra8
.set out_addr, rb8
.set M_000000FF, ra9
.set temp_addr, rb9
.set M_FFFFFF00, ra10
.set setup_index_initial, rb10
.set in_addr2, ra11
.set offsstore, rb2
.set add_input_stride, ra31
.set add_input_height, ra29
.set add_output_stride, rb29
.set add_output_height, ra30
.set add_output_x, ra19
.set add_output_y, rb20
.set curx, ra25
.set cury, ra23
.set remx, rb24
.set remy, rb28
.macro write_full_calc
mov vpm, rb13
mov vpm, rb15
mov vpm, rb17
mov vpm, rb19
mov vpm, rb21
mov vpm, rb23
mov vpm, rb25
mov vpm, rb27
.endm
.macro write_horz_calc
mov vpm, rb14
mov vpm, ra16
mov vpm, rb18
mov vpm, ra20
mov vpm, rb22
mov vpm, ra24
mov vpm, rb26
mov vpm, ra28
.endm
.macro horz_dialate
.rep i, 4
mov r0, rb13+i*4
ror r1, r0, 8
and r1, r1, M_00FFFFFF
mov r2, r0<<1
ror r2, r2, 8
and r2, r2, M_FF000000
or rb12, r1, r2
ror r1, r0, 24
and r1, r1, M_FFFFFF00
mov r2, r0>>1
ror r2, r2, 24
and r2, r2, M_000000FF
or rb11, r1, r2
v8max r1, r0, rb12
v8max rb13+i*4, r1, rb11
mov r0, rb15+i*4
ror r1, r0, 8
and r1, r1, M_00FFFFFF
mov r2, r0<<1
ror r2, r2, 8
and r2, r2, M_FF000000
or rb12, r1, r2
ror r1, r0, 24
and r1, r1, M_FFFFFF00
mov r2, r0>>1
ror r2, r2, 24
and r2, r2, M_000000FF
or rb11, r1, r2
v8max r1, r0, rb12
v8max rb15+i*4, r1, rb11
.endr
.endm
.macro vert_dialate
v8max r1, ra12, rb14
v8max rb13, r1, ra16
v8max r1, rb14, ra16
v8max rb15, r1, rb18
v8max r1, ra16, rb18
v8max rb17, r1, ra20
v8max r1, rb18, ra20
v8max rb19, r1, rb22
v8max r1, ra20, rb22
v8max rb21, r1, ra24
v8max r1, rb22, ra24
v8max rb23, r1, rb26
v8max r1, ra24, rb26
v8max rb25, r1, ra28
v8max r1, rb26, ra28
v8max rb27, r1, rb30
.endm
.macro do_sub
mov vw_setup, setup_indexed_final
.rep i, 4
mov t1s, r3
add r3, r3, add_input_stride
mov t0s, r3
add r3, r3, add_input_stride
.endr
ldtmu1
ldtmu0; v8subs vpm, rb13, r4
ldtmu1; v8subs vpm, rb15, r4
ldtmu0; v8subs vpm, rb17, r4
ldtmu1; v8subs vpm, rb19, r4
ldtmu0; v8subs vpm, rb21, r4
ldtmu1; v8subs vpm, rb23, r4
ldtmu0; v8subs vpm, rb25, r4
v8subs vpm, rb27, r4
.endm
############################################################
# Main Code
############################################################
mov M_FF000000, 0xFF000000
mov M_000000FF, 0x000000FF
mov M_00FFFFFF, 0x00FFFFFF
mov M_FFFFFF00, 0xFFFFFF00
mov in_addr, unif # input base address
mov out_addr, unif # output base address
mov num_gpus, unif # number of additional gpus
mov gpuindex, unif # gpu index, but it's zero for the main loop
mov add_input_x, unif # input x start
mov add_input_y, unif # input y start
mov add_input_stride, unif # input x stride = m_w
mov add_input_height, unif # input height = m_h
mov add_output_stride, unif # output m_w
mov add_output_height, unif # output m_h
mov add_output_x, unif # where in the output file the bytes start
mov add_output_y, unif # being written (coordinate). Same as border
mov in_addr2, unif
# jump calculation for slave semaphore wait
mov r1, 48 # r1 = 48
sub r0, gpuindex, 1 # r0 = index - 1
mul24 gpuindexjump, r0, r1 # gpuindexjump = 48*(index-1)
nop
shl elem_offs, elem_num, 2 # elem_offsa = {0,1,2,3,4,5,6,7} * 8
#######################################
# Setup outer loop y
#######################################
mov cury, 0
mov r1, 64
sub r0, add_output_height, add_output_y
sub r0, r0, add_output_y
sub remy, r0, r1
:anotherloopy
#######################################
# Setup inner loop x
#######################################
mov curx, 0
sub r0, add_output_stride, add_output_x
sub r0, r0, add_output_x
mov r1, 56
sub remx, r0, r1
:anotherloopx
###############################################################################
# Set up the loop required for going through the entire bitmap. This loop
# These are byte aligned.
#
# this calculates where to store the result for the various threads
#
# It stores the result in rb0 (aliased to setup_indexed). It
# uses an index number from 1 to 7, multiplies it by 8 and then
# combines it with the vpm setup to tell the reader where to
# actually store the value in vpm memory
#
mov r0, vpm_setup(8,1,h32(0,0))
shl r3, gpuindex, 3
mov gpuindex8, r3
or setup_indexed_final, r0, r3
mov r2, add_input_x # tempbuf_addr initiaized to in_addr
sub r2, r2, 4 # we want to start at the border so there's an overlap
add r1, add_input_y, cury # add the current y
sub r1, r1, 1
add r1, r1, gpuindex8 # add the index to the input read
mul24 r0, add_input_stride, r1 # r0 = src.m_w * (src.m_borderh + cury);
add r0, r0, curx # r0 += curx;
add r2, r2, r0 # r1 = r2 + r0
add r2, r2, elem_offs
mov offsstore, r2
add r3, r2, in_addr
.rep i, 4
mov t0s, r3
add r3, r3, add_input_stride
mov t1s, r3
add r3, r3, add_input_stride
.endr
ldtmu0
ldtmu1; mov ra12, r4
ldtmu0; mov rb14, r4
ldtmu1; mov ra16, r4
ldtmu0; mov rb18, r4
ldtmu1; mov ra20, r4
ldtmu0; mov rb22, r4
mov t0s, r3
ldtmu1; mov ra24, r4
add t1s, r3, add_input_stride
ldtmu0; mov rb26, r4
ldtmu1; mov ra28, r4
mov rb30, r4
vert_dialate
horz_dialate
brr -, :sample_acq0, gpuindexjump # jump to sample_acq0[index-1]
nop
nop
nop
:sample_acq0
.rep i, 6
mov -, srel(i+1)
mov -, sacq(i+8)
brr -,:sacq_done0
nop
nop
nop
.endr
mov -, srel(7)
mov -, sacq(14)
:sacq_done0
# finally write all of the results!
mov r2, offsstore
add r3, r2, add_input_stride
add r3, r3, in_addr2
do_sub
# tell the master we're done
brr -, :sample_acq2, gpuindexjump # jump to sample_acq0[index-1]
nop
nop
nop
:sample_acq2
.rep i, 6
mov -, srel(i+1)
mov -, sacq(i+8)
brr -,:sacq_done2
nop
nop
nop
.endr
mov -, srel(7)
mov -, sacq(14)
:sacq_done2
#######################################
# Increment inner loop x
#######################################
mov r1, 56
or.setf r0, remx, remx # r0 = remx; // (set the flag too!)
add curx, curx, r1 # curx += r1;
brr.anynz -, :anotherloopx #
sub.setf r0, r0, r1 # r0 -= r1;
add.ifn curx, curx, r0; mov remx, r0 # if (r0<1) curx+=r0; remx=r0;
mov.ifn remx, 0 # if (r0<1) remx=0;
# if (r0!=0) goto :anotherloopx;
#######################################
# Increment inner loop y
#######################################
mov r1, 64
or.setf r0, remy, remy # r0 = remy; // (set the flag too!)
add cury, cury, r1 # cury += r1;
brr.anynz -, :anotherloopy #
sub.setf r0, r0, r1 # r0 -= r1;
add.ifn cury, cury, r0; mov remy, r0 # if (r0<1) curx+=r0; remy=r0;
mov.ifn remy, 0 # if (r0<1) remy=0;
# if (r0!=0) goto :anotherloopy
# exit the thread
:end
thrend
nop
nop