aboutsummaryrefslogtreecommitdiff
path: root/sim/testsuite/mips/utils-dsp.inc
blob: 4e7a8dcda3f1d2ee57486df67e6fc3a86439707c (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
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# MIPS DSP ASE simulator testsuite utility functions.
# Copyright (C) 2005-2024 Free Software Foundation, Inc.
# Contributed by MIPS Technologies, Inc.  Written by Chao-ying Fu.
#
# This file is part of the GNU simulators.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

# $4, $5, $6, $7, $ac0, $ac1, $ac2, $ac3 are used as temps by the macros
# defined here.

	# If a != b, jump to _fail.
	# Otherwise, fall through.
	.macro dsp_assert a, b
	beq	\a, \b, 1f
	nop
	j	_fail
	nop
1: 
	.endm

	# Set dsp control register <= crin
	# Check if d == (inst ?, s, t)
	# Check if crout == dsp control register
	.macro dspck_dstio inst, d, s, t, crin, crout
	li	$4, \crin
	wrdsp	$4
	li	$4, \s
	li	$5, \t
	\inst	$6, $4, $5
	li	$7, \d
	dsp_assert	$6, $7
	li	$4, \crout
	rddsp	$5
	dsp_assert	$4, $5
	.endm

	# Set dsp control register <= crin
	# (inst s, t)
	# Check if crout == dsp control register
	.macro dspck_stio inst, s, t, crin, crout
	li	$4, \crin
	wrdsp	$4
	li	$4, \s
	li	$5, \t
	\inst	$4, $5
	li	$4, \crout
	rddsp	$5
	dsp_assert	$4, $5
	.endm

	# Set dsp control register <= crin
	# Check if d == (inst ?, s, t)
	.macro dspck_dsti inst, d, s, t, crin
	li	$4, \crin
	wrdsp	$4
	li	$4, \s
	li	$5, \t
	\inst	$6, $4, $5
	li	$7, \d
	dsp_assert	$6, $7
	.endm

	# Set dsp control register <= crin
	# Check if tou == (inst tin, s)
	.macro dspck_tsi inst, tou, tin, s, crin
	li	$4, \crin
	wrdsp	$4
	li	$4, \s
	li	$5, \tin
	\inst	$5, $4
	li	$6, \tou
	dsp_assert	$5, $6
	.endm

	# Set dsp control register <= crin
	# Check if d == (inst ?, imm)
	# Check if crout == dsp control register
	.macro dspck_dIio inst, d, imm, crin, crout
	li	$4, \crin
	wrdsp	$4
	\inst	$5, \imm
	li	$6, \d
	dsp_assert	$5, $6
	li	$4, \crout
	rddsp	$5
	dsp_assert	$4, $5
	.endm

	# Set dsp control register <= crin
	# Check if d == (inst ?, s)
	# Check if crout == dsp control register
	.macro dspck_dsio inst, d, s, crin, crout
	li	$4, \crin
	wrdsp	$4
	li	$4, \s
	\inst	$6, $4
	li	$7, \d
	dsp_assert	$6, $7
	li	$4, \crout
	rddsp	$5
	dsp_assert	$4, $5
	.endm

	# Set dsp control register <= crin
	# Check if d == (inst ?, t, sa)
	# Check if crout == dsp control register
	.macro dspck_dtsaio inst, d, t, sa, crin, crout
	li	$4, \crin
	wrdsp	$4
	li	$4, \t
	\inst	$6, $4, \sa
	li	$7, \d
	dsp_assert	$6, $7
	li	$4, \crout
	rddsp	$5
	dsp_assert	$4, $5
	.endm

	# Set dsp control register <= crin
	# Check if d == (inst ?, t, sa)
	.macro dspck_dtsai inst, d, t, sa, crin
	li	$4, \crin
	wrdsp	$4
	li	$4, \t
	\inst	$6, $4, \sa
	li	$7, \d
	dsp_assert	$6, $7
	.endm

	# Set dsp control register <= crin
	# Set $ac3 <= {hiin, loin}
	# (inst $ac3, s, t)
	# Check if {hiou, loou} == $ac3
	# Check if (crout & 0x80000) == (dsp control register & 0x80000)
	.macro dspck_astio inst, hiin, loin, hiou, loou, s, t, crin, crout
	li	$4, \crin
	wrdsp	$4
	li	$4, \hiin
	mthi	$4, $ac3
	li	$4, \loin
	mtlo	$4, $ac3
	li	$4, \s
	li	$5, \t
	\inst	$ac3, $4, $5
	li	$4, \hiou
	mfhi	$5, $ac3
	dsp_assert	$4, $5
	li	$4, \loou
	mflo	$5, $ac3
	dsp_assert	$4, $5
	li	$4, \crout
	and	$4, $4, 0x80000
	rddsp	$5
	and	$5, $5, 0x80000
	dsp_assert	$4, $5
	.endm

	# Set dsp control register <= crin
	# Set $ac1 <= {hi, lo}
	# Check if t == (inst ? $ac1, sa)
	# Check if crout == dsp control register
	.macro dspck_atsaio inst, hi, lo, t, sa, crin, crout
	li	$4, \crin
	wrdsp	$4
	li	$4, \hi
	mthi	$4, $ac1
	li	$4, \lo
	mtlo	$4, $ac1
	\inst	$5, $ac1, \sa
	li	$6, \t
	dsp_assert	$5, $6
	li	$4, \crout
	rddsp	$5
	dsp_assert	$4, $5
	.endm

	# Set dsp control register <= crin
	# Set acc <= {hiin, loin}
	# (inst acc, s, t)
	# Check if {hiou, loou} == acc
	# Check if (crout & 0x80000) == (dsp control register & 0x80000)
	.macro dspckacc_astio inst, acc, hiin, loin, hiou, loou, s, t, crin, crout
	li	$4, \crin
	wrdsp	$4
	li	$4, \hiin
	mthi	$4, \acc
	li	$4, \loin
	mtlo	$4, \acc
	li	$4, \s
	li	$5, \t
	\inst	\acc, $4, $5
	li	$4, \hiou
	mfhi	$5, \acc
	dsp_assert	$4, $5
	li	$4, \loou
	mflo	$5, \acc
	dsp_assert	$4, $5
	li	$4, \crout
	and	$4, $4, 0x80000
	rddsp	$5
	and	$5, $5, 0x80000
	dsp_assert	$4, $5
	.endm

	# Set dsp control register <= crin
	# Set $ac1 <= {hi, lo}
	# Check if t == (inst ? $ac1, s)
	# Check if crout == dsp control register
	.macro dspck_atsio inst, hi, lo, t, s, crin, crout
	li	$4, \crin
	wrdsp	$4
	li	$4, \hi
	mthi	$4, $ac1
	li	$4, \lo
	mtlo	$4, $ac1
	li	$4, \s
	\inst	$5, $ac1, $4
	li	$6, \t
	dsp_assert	$5, $6
	li	$4, \crout
	rddsp	$5
	dsp_assert	$4, $5
	.endm

	# Set dsp control register <= (crin & crinmask)
	# Set $ac2 <= {hi, lo}
	# Check if t == (inst ? $ac2, size)
	# Check if (crout & croutmask) == (dsp control register & croutmask)
	.macro dspck_tasiimom inst, hi, lo, t, size, crin, crinmask, crout, croutmask
	li	$4, \crin
	and	$4, \crinmask
	wrdsp	$4
	li	$4, \hi
	mthi	$4, $ac2
	li	$4, \lo
	mtlo	$4, $ac2
	\inst	$5, $ac2, \size
	li	$6, \t
	dsp_assert	$5, $6
	li	$4, \crout
	and	$4, \croutmask
	rddsp	$5
	and	$5, \croutmask
	dsp_assert	$4, $5
	.endm

	# Set dsp control register <= (crin & crinmask)
	# Set $ac2 <= {hi, lo}
	# Check if t == (inst ? $ac2, size)
	.macro dspck_tasiim inst, hi, lo, t, size, crin, crinmask
	li	$4, \crin
	and	$4, \crinmask
	wrdsp	$4
	li	$4, \hi
	mthi	$4, $ac2
	li	$4, \lo
	mtlo	$4, $ac2
	\inst	$5, $ac2, \size
	li	$6, \t
	dsp_assert	$5, $6
	.endm

	# Set dsp control register <= (crin & crinmask)
	# Set $ac2 <= {hi, lo}
	# Check if t == (inst ? $ac2, s)
	# Check if (crout & croutmask) == (dsp control register & croutmask)
	.macro dspck_tasimom inst, hi, lo, t, s, crin, crinmask, crout, croutmask
	li	$4, \crin
	and	$4, \crinmask
	wrdsp	$4
	li	$4, \hi
	mthi	$4, $ac2
	li	$4, \lo
	mtlo	$4, $ac2
	li	$4, \s
	\inst	$5, $ac2, $4
	li	$6, \t
	dsp_assert	$5, $6
	li	$4, \crout
	and	$4, \croutmask
	rddsp	$5
	and	$5, \croutmask
	dsp_assert	$4, $5
	.endm

	# Set dsp control register <= (crin & crinmask)
	# Set $ac2 <= {hi, lo}
	# Check if t == (inst ? $ac2, s)
	.macro dspck_tasim inst, hi, lo, t, s, crin, crinmask
	li	$4, \crin
	and	$4, \crinmask
	wrdsp	$4
	li	$4, \hi
	mthi	$4, $ac2
	li	$4, \lo
	mtlo	$4, $ac2
	li	$4, \s
	\inst	$5, $ac2, $4
	li	$6, \t
	dsp_assert	$5, $6
	.endm

	# Set dsp control register <= crin
	# Set $ac0 <= {hi, lo}
	# (inst $ac0, shift)
	# Check if $ac0 == {hio, loo}
	# Check if crout == dsp control register
	.macro dspck_asaio inst, hi, lo, hio, loo, shift, crin, crout
	li	$4, \crin
	wrdsp	$4
	li	$4, \hi
	mthi	$4, $ac0
	li	$4, \lo
	mtlo	$4, $ac0
	\inst	$ac0, \shift
	mfhi	$5, $ac0
	li	$6, \hio
	dsp_assert	$5, $6
	mflo	$5, $ac0
	li	$6, \loo
	dsp_assert	$5, $6
	li	$4, \crout
	rddsp	$5
	dsp_assert	$4, $5
	.endm

	# Set dsp control register <= crin
	# Set $ac0 <= {hi, lo}
	# (inst $ac0, s)
	# Check if $ac0 == {hio, loo}
	# Check if crout == dsp control register
	.macro dspck_asio inst, hi, lo, hio, loo, s, crin, crout
	li	$4, \crin
	wrdsp	$4
	li	$4, \hi
	mthi	$4, $ac0
	li	$4, \lo
	mtlo	$4, $ac0
	li	$4, \s
	\inst	$ac0, $4
	mfhi	$5, $ac0
	li	$6, \hio
	dsp_assert	$5, $6
	mflo	$5, $ac0
	li	$6, \loo
	dsp_assert	$5, $6
	li	$4, \crout
	rddsp	$5
	dsp_assert	$4, $5
	.endm

	# Set dsp control register <= crin
	# Set $ac3 <= {hi, lo}
	# Check if s == (inst ? $ac3)
	# Check if $ac3 == {hio, loo}
	# Check if crout == dsp control register
	.macro dspck_saio inst, hi, lo, hio, loo, s, crin, crout
	li	$4, \crin
	wrdsp	$4
	li	$4, \hi
	mthi	$4, $ac3
	li	$4, \lo
	mtlo	$4, $ac3
	li	$5, \s
	\inst	$5, $ac3
	mfhi	$5, $ac3
	li	$6, \hio
	dsp_assert	$5, $6
	mflo	$5, $ac3
	li	$6, \loo
	dsp_assert	$5, $6
	li	$4, \crout
	rddsp	$5
	dsp_assert	$4, $5
	.endm

	# Set dsp control register <= crin
	# (wrdsp s, m)
	# Check if crout == dsp control register
	.macro dspck_wrdsp s, m, crin, crout
	li	$4, \crin
	wrdsp	$4
	li	$5, \s
	wrdsp	$5, \m
	li	$6, \crout
	rddsp	$7
	dsp_assert	$6, $7
	.endm

	# Set dsp control register <= crin
	# Check if d == (rddsp ?, m)
	.macro dspck_rddsp d, m, crin
	li	$4, \crin
	wrdsp	$4
	rddsp	$5, \m
	li	$6, \d
	dsp_assert	$5, $6
	.endm

	# Check if d == (inst i(b))
	.macro dspck_load inst, d, i, b
	li	$4, \i
	la	$5, \b
	\inst	$6, $4($5)
	li	$7, \d
	dsp_assert	$6, $7
	.endm

	# Set dsp control register <= crin
	# Check if bposge32 is taken or not as expected in r
	# (1 => taken, 0 => not taken)
	.macro dspck_bposge32 crin, r
	li	$4, \crin
	wrdsp	$4
	li	$5, 1
	bposge32	1f
	nop
	li	$5, 0
1:
	li	$6, \r
	dsp_assert	$5, $6
	.endm

	# Check if tou == (inst tin, s)
	.macro dspck_tsimm inst, tou, tin, s, sa
	li	$4, \s
	li	$5, \tin
	\inst	$5, $4, \sa
	li	$6, \tou
	dsp_assert	$5, $6
	.endm