aboutsummaryrefslogtreecommitdiff
path: root/sim/testsuite/pru/carry.s
blob: 43cae6f94c77b314d2300b1050d960832b657e5a (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
# Check that carry for addition and subtraction works.
# mach: pru

# Copyright (C) 2023-2024 Free Software Foundation, Inc.
# Contributed by Dimitar Dimitrov <dimitar@dinux.eu>
#
# 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/>.

.include "testutils.inc"

	# Helper macro to exercise three consecutive
	# instructions using the carry bit.
	.macro test_seq srcmode, dstmode, init0, init1, init2, init3, alu0, alu1, alu2, expected
	# In case srcmode>dstmode, "garbage" in the r20 MSB
	# bits could falsely be interpreted as carry.
	# So start with initialized destination to make tests consistent.
	ldi	r20, 0
	ldi32	r15, \init0
	ldi32	r16, \init1
	ldi32	r17, \init2
	ldi32	r18, \init3
	ldi32	r0, \expected
	\alu0	r20\dstmode, r15\srcmode, r16\srcmode
	\alu1	r20\dstmode, r20\srcmode, r17\srcmode
	\alu2	r20\dstmode, r20\srcmode, r18\srcmode
	qbeq	1f, r0, r20\dstmode
	jmp	EXIT_FAIL
1:
	.endm

	# Helper macro to verify one ALU instruction
	# using the carry bit.
	.macro test1 alu, dstmode, src0mode, src0init, src1mode, src1init, expected
	ldi32	r15, \src0init
	ldi32	r16, \src1init
	ldi32	r0, \expected
	\alu	r20\dstmode, r15\src0mode, r16\src1mode
	qbeq	1f, r0, r20\dstmode
	jmp	EXIT_FAIL
1:
	.endm

	start

	# ***** ADD 32-bit dst, 32-bit src *****
	# {add, clear carry}
	test1	add, "   ", "   ", 0x00000000, "   ", 0x00000000, 0x00000000
	# {add with carry=0, clear carry}
	test1	adc, "   ", "   ", 0x00000000, "   ", 0x00000000, 0x00000000
	# {add with carry=0, set carry}
	test1	adc, "   ", "   ", 0x00000001, "   ", 0xffffffff, 0x00000000
	# {add with carry=1, set carry}
	test1	adc, "   ", "   ", 0x00000010, "   ", 0xfffffffe, 0x0000000f
	# {add with carry=1, clear carry}
	test1	adc, "   ", "   ", 0x00000010, "   ", 0x0ffffffe, 0x1000000f
	# {add with carry=0, set carry}
	test1	adc, "   ", "   ", 0x00000001, "   ", 0xffffffff, 0x00000000
	# {add, set carry}
	test1	add, "   ", "   ", 0x00000001, "   ", 0xffffffff, 0x00000000
	# {add with carry=1, set carry}
	test1	adc, "   ", "   ", 0x00000010, "   ", 0xfffffffe, 0x0000000f

	# ***** ADD 32-bit dst, 16-bit src *****
	test1	add, "   ", ".w0", 0x00000000, ".w0", 0x00000000, 0x00000000
	test1	adc, "   ", ".w0", 0x00000000, ".w0", 0x00000000, 0x00000000
	test1	adc, "   ", ".w0", 0x00000003, ".w0", 0xffffffff, 0x00010002
	test1	adc, "   ", ".w0", 0x00000010, ".w0", 0x0000fffe, 0x0001000e

	# ***** ADD 32-bit dst, 8-bit src *****
	test1	add, "   ", ".b0", 0x00000000, ".b0", 0x00000000, 0x00000000
	test1	adc, "   ", ".b0", 0x00000000, ".b0", 0x00000000, 0x00000000
	test1	adc, "   ", ".b0", 0x00000003, ".b0", 0xffffffff, 0x00000102
	test1	adc, "   ", ".b0", 0x00000010, ".b0", 0x0000f0fe, 0x0000010e

	# ***** ADD 16-bit dst, 32-bit src *****
	test1	add, ".w0", "   ", 0x00000000, "   ", 0x00000000, 0x00000000
	test1	adc, ".w0", "   ", 0x00000000, "   ", 0x00000000, 0x00000000
	test1	adc, ".w0", "   ", 0x00000001, "   ", 0xfff0ffff, 0x00000000
	test1	adc, ".w0", "   ", 0x00000010, "   ", 0x0000fffe, 0x0000000f
	test1	adc, ".w0", "   ", 0x00000010, "   ", 0x00000ffe, 0x0000100f
	test1	adc, ".w0", "   ", 0x00000001, "   ", 0x0000ffff, 0x00000000
	test1	add, ".w0", "   ", 0x00000001, "   ", 0x0000ffff, 0x00000000
	test1	adc, ".w0", "   ", 0x00000010, "   ", 0x0000fffe, 0x0000000f
	# Test when intermediate sum sets the carry.
	test1	add, ".w0", "   ", 0x00010000, "   ", 0x00000000, 0x00000000
	test1	adc, ".w0", "   ", 0x00000000, "   ", 0x00000000, 0x00000001
	test1	add, ".w0", "   ", 0x00020000, "   ", 0x00000000, 0x00000000
	test1	adc, ".w0", "   ", 0x00000000, "   ", 0x00000000, 0x00000000

	# ***** ADD 16-bit dst, 16-bit src *****
	test1	add, ".w0", ".w0", 0x00000210, ".w0", 0x00000130, 0x00000340
	test1	adc, ".w0", ".w0", 0x00000000, ".w0", 0x00000000, 0x00000000
	test1	adc, ".w0", ".w0", 0x00000001, ".w0", 0xffffffff, 0x00000000
	test1	adc, ".w0", ".w0", 0x00000010, ".w0", 0xfffffffe, 0x0000000f
	test1	adc, ".w0", ".w0", 0x00000010, ".w0", 0x00000ffe, 0x0000100f
	test1	adc, ".w0", ".w0", 0x00000001, ".w0", 0xfff0ffff, 0x00000000
	test1	add, ".w0", ".w0", 0x00000001, ".w0", 0xfff0ffff, 0x00000000
	test1	adc, ".w0", ".w0", 0x00000010, ".w0", 0xfff1fffe, 0x0000000f

	# ***** ADD 16-bit dst, 8-bit src *****
	test1	add, ".w0", ".b0", 0x00000000, ".b0", 0x00000000, 0x00000000
	test1	adc, ".w0", ".b0", 0x00000000, ".b0", 0x00000000, 0x00000000
	test1	adc, ".w0", ".b0", 0x00000003, ".b0", 0xffffffff, 0x00000102
	test1	adc, ".w0", ".b0", 0x00000010, ".b0", 0x0000f0fe, 0x0000010e

	# ***** ADD 8-bit dst, 32-bit src *****
	test1	add, ".b0", "   ", 0x00000000, "   ", 0x00000000, 0x00000000
	test1	adc, ".b0", "   ", 0x00000000, "   ", 0x00000000, 0x00000000
	test1	adc, ".b0", "   ", 0x00000001, "   ", 0x000000ff, 0x00000000
	test1	adc, ".b0", "   ", 0x00000010, "   ", 0x000000fe, 0x0000000f
	test1	adc, ".b0", "   ", 0x00000021, "   ", 0x0000001e, 0x00000040
	test1	adc, ".b0", "   ", 0x00000001, "   ", 0x000000ff, 0x00000000
	test1	add, ".b0", "   ", 0x00000001, "   ", 0x000000ff, 0x00000000
	test1	adc, ".b0", "   ", 0x00000010, "   ", 0x000000fe, 0x0000000f
	# Test when intermediate sum sets the carry.
	test1	add, ".b0", "   ", 0x10000100, "   ", 0x00000000, 0x00000000
	test1	adc, ".b0", "   ", 0x00000000, "   ", 0x00000000, 0x00000001

	# ***** ADD 8-bit dst, 16-bit src *****
	test1	add, ".b0", ".w0", 0x10000000, ".w0", 0x00000000, 0x00000000
	test1	adc, ".b0", ".w0", 0x02000000, ".w0", 0x00000000, 0x00000000
	test1	adc, ".b0", ".w0", 0x00030001, ".w0", 0x000000ff, 0x00000000
	test1	adc, ".b0", ".w0", 0x00004010, ".w0", 0x000000fe, 0x0000000f
	test1	adc, ".b0", ".w0", 0x00000021, ".w0", 0x0000001e, 0x00000040
	test1	adc, ".b0", ".w0", 0x00000001, ".w0", 0x000000ff, 0x00000000
	test1	add, ".b0", ".w0", 0x00000001, ".w0", 0x000000ff, 0x00000000
	test1	adc, ".b0", ".w0", 0x00000010, ".w0", 0x000000fe, 0x0000000f
	# Test when intermediate sum sets the carry.
	test1	add, ".b0", ".w0", 0x10003100, ".w0", 0x00000000, 0x00000000
	test1	adc, ".b0", ".w0", 0x00000000, ".w0", 0x00000000, 0x00000001

	# ***** ADD 8-bit dst, 8-bit src  *****
	test1	add, ".b0", ".b0", 0x00000210, ".b0", 0x00000130, 0x00000040
	test1	adc, ".b0", ".b0", 0x00000000, ".b0", 0x00000000, 0x00000000
	test1	adc, ".b0", ".b0", 0x00000001, ".b0", 0xffffffff, 0x00000000
	test1	adc, ".b0", ".b0", 0x00000010, ".b0", 0xfffffffe, 0x0000000f
	test1	adc, ".b0", ".b0", 0x00000010, ".b0", 0x0000000e, 0x0000001f
	test1	adc, ".b0", ".b0", 0x00000001, ".b0", 0xfff0ffff, 0x00000000
	test1	add, ".b0", ".b0", 0x00000001, ".b0", 0xfff0ffff, 0x00000000
	test1	adc, ".b0", ".b0", 0x00000010, ".b0", 0xfff1fffe, 0x0000000f

	# ***** SUB 32-bit dst, 32-bit src *****
	# {sub, clear borrow}
	test1	sub, "   ", "   ", 0x00000000, "   ", 0x00000000, 0x00000000
	# {sub with borrow=0, clear borrow}
	test1	suc, "   ", "   ", 0x00000010, "   ", 0x00000001, 0x0000000f
	# {sub with borrow=0, set borrow}
	test1	suc, "   ", "   ", 0x00000008, "   ", 0x00000009, 0xffffffff
	# {sub with borrow=1, set borrow}
	test1	suc, "   ", "   ", 0x00000008, "   ", 0x00000009, 0xfffffffe
	# {sub with borrow=1, clear borrow}
	test1	suc, "   ", "   ", 0x00000008, "   ", 0x00000001, 0x00000006
	# {sub with borrow=0, set borrow}
	test1	suc, "   ", "   ", 0x80000000, "   ", 0x90000000, 0xf0000000
	# {sub, set borrow}
	test1	sub, "   ", "   ", 0x00000000, "   ", 0x00000001, 0xffffffff
	# {sub with borrow=1, set borrow}
	test1	suc, "   ", "   ", 0x80000000, "   ", 0x90000000, 0xefffffff

	# ***** SUB 32-bit dst, 16-bit src *****
	test1	sub, "   ", ".w0", 0x00000000, ".w0", 0x00000000, 0x00000000
	test1	suc, "   ", ".w0", 0x00000010, ".w0", 0x00000001, 0x0000000f
	test1	suc, "   ", ".w0", 0x00000008, ".w0", 0x00000009, 0xffffffff
	test1	suc, "   ", ".w0", 0x00000008, ".w0", 0x00000009, 0xfffffffe
	test1	suc, "   ", ".w0", 0x00000008, ".w0", 0x00000001, 0x00000006
	test1	suc, "   ", ".w0", 0x00108000, ".w0", 0x00009000, 0xfffff000
	test1	sub, "   ", ".w0", 0x00000000, ".w0", 0x00000001, 0xffffffff
	test1	suc, "   ", ".w0", 0x00008000, ".w0", 0x00009000, 0xffffefff

	# ***** SUB 32-bit dst, 8-bit src *****
	test1	sub, "   ", ".b0", 0x00000000, ".b0", 0x00000000, 0x00000000
	test1	suc, "   ", ".b0", 0x00000010, ".b0", 0x00000001, 0x0000000f
	test1	suc, "   ", ".b0", 0x00000008, ".b0", 0x00000009, 0xffffffff
	test1	suc, "   ", ".b0", 0x00000008, ".b0", 0x00000009, 0xfffffffe
	test1	suc, "   ", ".b0", 0x00000008, ".b0", 0x00000001, 0x00000006
	test1	suc, "   ", ".b0", 0x00108080, ".b0", 0x00009090, 0xfffffff0
	test1	sub, "   ", ".b0", 0x00000000, ".b0", 0x00000001, 0xffffffff
	test1	suc, "   ", ".b0", 0x00008080, ".b0", 0x00009090, 0xffffffef

	# ***** SUB 16-bit dst, 32-bit src *****
	test1	sub, ".w0", "   ", 0x00000000, "   ", 0x00000000, 0x00000000
	test1	suc, ".w0", "   ", 0x00000010, "   ", 0x00000001, 0x0000000f
	test1	suc, ".w0", "   ", 0x00000008, "   ", 0x00000009, 0x0000ffff
	test1	suc, ".w0", "   ", 0x00000008, "   ", 0x00000009, 0x0000fffe
	test1	suc, ".w0", "   ", 0x00000008, "   ", 0x00000001, 0x00000006
	test1	suc, ".w0", "   ", 0x00108000, "   ", 0x00009000, 0x0000f000
	test1	sub, ".w0", "   ", 0x00000000, "   ", 0x00000001, 0x0000ffff
	test1	suc, ".w0", "   ", 0x00008000, "   ", 0x00009000, 0x0000efff
	# Test when intermediate value sets the borrow.
	test1	sub, ".w0", "   ", 0x00010000, "   ", 0x00000000, 0x00000000
	test1	suc, ".w0", "   ", 0x00000002, "   ", 0x00000000, 0x00000001

	# ***** SUB 16-bit dst, 16-bit src *****
	test1	sub, ".w0", ".w0", 0x00000000, ".w0", 0x00000000, 0x00000000
	test1	suc, ".w0", ".w0", 0x00000010, ".w0", 0x00000001, 0x0000000f
	test1	suc, ".w0", ".w0", 0x00000008, ".w0", 0x00000009, 0x0000ffff
	test1	suc, ".w0", ".w0", 0x00000008, ".w0", 0x00000009, 0x0000fffe
	test1	suc, ".w0", ".w0", 0x00000008, ".w0", 0x00000001, 0x00000006
	test1	suc, ".w0", ".w0", 0x00108000, ".w0", 0x00009000, 0x0000f000
	test1	sub, ".w0", ".w0", 0x00000000, ".w0", 0x00000001, 0x0000ffff
	test1	suc, ".w0", ".w0", 0x00008000, ".w0", 0x00009000, 0x0000efff

	# ***** SUB 16-bit dst, 8-bit src *****
	test1	sub, ".w0", ".b0", 0x00000000, ".b0", 0x00000000, 0x00000000
	test1	suc, ".w0", ".b0", 0x00000010, ".b0", 0x00000001, 0x0000000f
	test1	suc, ".w0", ".b0", 0x00000008, ".b0", 0x00000009, 0x0000ffff
	test1	suc, ".w0", ".b0", 0x00000008, ".b0", 0x00000009, 0x0000fffe
	test1	suc, ".w0", ".b0", 0x00000008, ".b0", 0x00000001, 0x00000006
	test1	suc, ".w0", ".b0", 0x00108080, ".b0", 0x00009090, 0x0000fff0
	test1	sub, ".w0", ".b0", 0x00000000, ".b0", 0x00000001, 0x0000ffff
	test1	suc, ".w0", ".b0", 0x0000a080, ".b0", 0x0000c090, 0x0000ffef

	# ***** SUB 8-bit dst, 32-bit src *****
	test1	sub, ".b0", "   ", 0x00000000, "   ", 0x00000000, 0x00000000
	test1	suc, ".b0", "   ", 0x00000010, "   ", 0x00000001, 0x0000000f
	test1	suc, ".b0", "   ", 0x00000008, "   ", 0x00000009, 0x000000ff
	test1	suc, ".b0", "   ", 0x00000008, "   ", 0x00000009, 0x000000fe
	test1	suc, ".b0", "   ", 0x00000008, "   ", 0x00000001, 0x00000006
	test1	suc, ".b0", "   ", 0x00000080, "   ", 0x00000090, 0x000000f0
	test1	sub, ".b0", "   ", 0x00000000, "   ", 0x00000001, 0x000000ff
	test1	suc, ".b0", "   ", 0x00000080, "   ", 0x00000090, 0x000000ef
	# Test when intermediate value sets the borrow.
	test1	sub, ".b0", "   ", 0x00000100, "   ", 0x00000000, 0x00000000
	test1	suc, ".b0", "   ", 0x00000002, "   ", 0x00000000, 0x00000001
	test1	sub, ".b0", "   ", 0x00000100, "   ", 0x00000000, 0x00000000
	test1	rsc, ".b0", "   ", 0x00000000, "   ", 0x00000002, 0x00000001

	# ***** SUB 8-bit dst, 16-bit src *****
	test1	sub, ".b0", ".w0", 0x00000000, ".w0", 0x00000000, 0x00000000
	test1	suc, ".b0", ".w0", 0x00000010, ".w0", 0x00000001, 0x0000000f
	test1	suc, ".b0", ".w0", 0x00000008, ".w0", 0x00000009, 0x000000ff
	test1	suc, ".b0", ".w0", 0x00000008, ".w0", 0x00000009, 0x000000fe
	test1	suc, ".b0", ".w0", 0x00000008, ".w0", 0x00000001, 0x00000006
	test1	suc, ".b0", ".w0", 0x00000080, ".w0", 0x00000090, 0x000000f0
	test1	sub, ".b0", ".w0", 0x00000000, ".w0", 0x00000001, 0x000000ff
	test1	suc, ".b0", ".w0", 0x00000080, ".w0", 0x00000090, 0x000000ef
	# Test when intermediate value sets the borrow.
	test1	sub, ".b0", ".w0", 0x00000100, ".w0", 0x00000000, 0x00000000
	test1	suc, ".b0", ".w0", 0x00000002, ".w0", 0x00000000, 0x00000001
	test1	sub, ".b0", ".w0", 0x00000100, ".w0", 0x00000000, 0x00000000
	test1	rsc, ".b0", ".w0", 0x00000000, ".w0", 0x00000002, 0x00000001

	# ***** SUB 8-bit dst, 8-bit src *****
	test1	sub, ".b0", ".w0", 0x00000000, ".w0", 0x00000000, 0x00000000
	test1	suc, ".b0", ".w0", 0x00000010, ".w0", 0x00000001, 0x0000000f
	test1	suc, ".b0", ".w0", 0x00000008, ".w0", 0x00000009, 0x000000ff
	test1	suc, ".b0", ".w0", 0x00000008, ".w0", 0x00000009, 0x000000fe
	test1	suc, ".b0", ".w0", 0x00000008, ".w0", 0x00000001, 0x00000006
	test1	suc, ".b0", ".w0", 0x00000080, ".w0", 0x00000090, 0x000000f0
	test1	sub, ".b0", ".w0", 0x00000000, ".w0", 0x00000001, 0x000000ff
	test1	suc, ".b0", ".w0", 0x00000080, ".w0", 0x00000090, 0x000000ef

	# ***** Reverse SUB 32-bit dst, 32-bit src *****
	# {rsb, clear borrow}
	test1	rsb, "   ", "   ", 0x00000000, "   ", 0x00000000, 0x00000000
	# {rsb with borrow=0, clear borrow}
	test1	rsc, "   ", "   ", 0x00000001, "   ", 0x00000010, 0x0000000f
	# {rsb with borrow=0, set borrow}
	test1	rsc, "   ", "   ", 0x00000009, "   ", 0x00000008, 0xffffffff
	# {rsb with borrow=1, set borrow}
	test1	rsc, "   ", "   ", 0x00000009, "   ", 0x00000008, 0xfffffffe
	# {rsb with borrow=1, clear borrow}
	test1	rsc, "   ", "   ", 0x00000001, "   ", 0x00000008, 0x00000006
	# {rsb with borrow=0, set borrow}
	test1	rsc, "   ", "   ", 0x90000000, "   ", 0x80000000, 0xf0000000
	# {rsb, set borrow}
	test1	rsb, "   ", "   ", 0x00000001, "   ", 0x00000000, 0xffffffff
	# {rsb with borrow=1, set borrow}
	test1	rsc, "   ", "   ", 0x90000000, "   ", 0x80000000, 0xefffffff

	# ***** Reverse SUB 32-bit dst, 16-bit src *****
	test1	rsb, "   ", ".w0", 0x00000000, ".w0", 0x00000000, 0x00000000
	test1	rsc, "   ", ".w0", 0x00000001, ".w0", 0x00000010, 0x0000000f
	test1	rsc, "   ", ".w0", 0x00000009, ".w0", 0x00000008, 0xffffffff
	test1	rsc, "   ", ".w0", 0x00000009, ".w0", 0x00000008, 0xfffffffe
	test1	rsc, "   ", ".w0", 0x00000001, ".w0", 0x00000008, 0x00000006
	test1	rsc, "   ", ".w0", 0x00109000, ".w0", 0x00008000, 0xfffff000
	test1	rsb, "   ", ".w0", 0x00000001, ".w0", 0x00000000, 0xffffffff
	test1	rsc, "   ", ".w0", 0x00009000, ".w0", 0x00008000, 0xffffefff

	# ***** Reverse SUB 32-bit dst, 8-bit src *****
	test1	rsb, "   ", ".b0", 0x00000000, ".b0", 0x00000000, 0x00000000
	test1	rsc, "   ", ".b0", 0x00000001, ".b0", 0x00000010, 0x0000000f
	test1	rsc, "   ", ".b0", 0x00000009, ".b0", 0x00000008, 0xffffffff
	test1	rsc, "   ", ".b0", 0x00000009, ".b0", 0x00000008, 0xfffffffe
	test1	rsc, "   ", ".b0", 0x00000001, ".b0", 0x00000008, 0x00000006
	test1	rsc, "   ", ".b0", 0x00108090, ".b0", 0x00009080, 0xfffffff0
	test1	rsb, "   ", ".b0", 0x00000001, ".b0", 0x00000000, 0xffffffff
	test1	rsc, "   ", ".b0", 0x00008090, ".b0", 0x00009080, 0xffffffef

	# ***** Reverse SUB 16-bit dst, 32-bit src *****
	test1	rsb, ".w0", "   ", 0x00000000, "   ", 0x00000000, 0x00000000
	test1	rsc, ".w0", "   ", 0x00000001, "   ", 0x00000010, 0x0000000f
	test1	rsc, ".w0", "   ", 0x00000009, "   ", 0x00000008, 0x0000ffff
	test1	rsc, ".w0", "   ", 0x00000009, "   ", 0x00000008, 0x0000fffe
	test1	rsc, ".w0", "   ", 0x00000001, "   ", 0x00000008, 0x00000006
	test1	rsc, ".w0", "   ", 0x00109000, "   ", 0x00008000, 0x0000f000
	test1	rsb, ".w0", "   ", 0x00000001, "   ", 0x00000000, 0x0000ffff
	test1	rsc, ".w0", "   ", 0x00009000, "   ", 0x00008000, 0x0000efff
	# Test when intermediate value sets the borrow.
	test1	rsb, ".w0", "   ", 0x00000000, "   ", 0x00010000, 0x00000000
	test1	rsc, ".w0", "   ", 0x00000000, "   ", 0x00000002, 0x00000001

	# ***** Reverse SUB 16-bit dst, 16-bit src *****
	test1	rsb, ".w0", ".w0", 0x00000000, ".w0", 0x00000000, 0x00000000
	test1	rsc, ".w0", ".w0", 0x00000001, ".w0", 0x00000010, 0x0000000f
	test1	rsc, ".w0", ".w0", 0x00000009, ".w0", 0x00000008, 0x0000ffff
	test1	rsc, ".w0", ".w0", 0x00000009, ".w0", 0x00000008, 0x0000fffe
	test1	rsc, ".w0", ".w0", 0x00000001, ".w0", 0x00000008, 0x00000006
	test1	rsc, ".w0", ".w0", 0x00109000, ".w0", 0x00008000, 0x0000f000
	test1	rsb, ".w0", ".w0", 0x00000001, ".w0", 0x00000000, 0x0000ffff
	test1	rsc, ".w0", ".w0", 0x00009000, ".w0", 0x00008000, 0x0000efff

	# ***** Reverse SUB 16-bit dst, 8-bit src *****
	test1	rsb, ".w0", ".b0", 0x00000000, ".b0", 0x00000000, 0x00000000
	test1	rsc, ".w0", ".b0", 0x00000001, ".b0", 0x00000010, 0x0000000f
	test1	rsc, ".w0", ".b0", 0x00000009, ".b0", 0x00000008, 0x0000ffff
	test1	rsc, ".w0", ".b0", 0x00000009, ".b0", 0x00000008, 0x0000fffe
	test1	rsc, ".w0", ".b0", 0x00000001, ".b0", 0x00000008, 0x00000006
	test1	rsc, ".w0", ".b0", 0x00108090, ".b0", 0x00009080, 0x0000fff0
	test1	rsb, ".w0", ".b0", 0x00000001, ".b0", 0x00000000, 0x0000ffff
	test1	rsc, ".w0", ".b0", 0x0000a090, ".b0", 0x0000c080, 0x0000ffef

	# ***** Reverse SUB 8-bit dst, 32-bit src *****
	test1	rsb, ".b0", "   ", 0x00000000, "   ", 0x00000000, 0x00000000
	test1	rsc, ".b0", "   ", 0x00000001, "   ", 0x00000010, 0x0000000f
	test1	rsc, ".b0", "   ", 0x00000009, "   ", 0x00000008, 0x000000ff
	test1	rsc, ".b0", "   ", 0x00000009, "   ", 0x00000008, 0x000000fe
	test1	rsc, ".b0", "   ", 0x00000001, "   ", 0x00000008, 0x00000006
	test1	rsc, ".b0", "   ", 0x00000090, "   ", 0x00000080, 0x000000f0
	test1	rsb, ".b0", "   ", 0x00000001, "   ", 0x00000000, 0x000000ff
	test1	rsc, ".b0", "   ", 0x00000090, "   ", 0x00000080, 0x000000ef
	# Test when intermediate value sets the borrow.
	test1	rsb, ".b0", "   ", 0x00000000, "   ", 0x00000100, 0x00000000
	test1	rsc, ".b0", "   ", 0x00000000, "   ", 0x00000002, 0x00000001
	test1	rsb, ".b0", "   ", 0x00000000, "   ", 0x00000100, 0x00000000
	test1	suc, ".b0", "   ", 0x00000002, "   ", 0x00000000, 0x00000001

	# ***** Reverse SUB 8-bit dst, 16-bit src *****
	test1	rsb, ".b0", ".w0", 0x00000000, ".w0", 0x00000000, 0x00000000
	test1	rsc, ".b0", ".w0", 0x00000001, ".w0", 0x00000010, 0x0000000f
	test1	rsc, ".b0", ".w0", 0x00000009, ".w0", 0x00000008, 0x000000ff
	test1	rsc, ".b0", ".w0", 0x00000009, ".w0", 0x00000008, 0x000000fe
	test1	rsc, ".b0", ".w0", 0x00000001, ".w0", 0x00000008, 0x00000006
	test1	rsc, ".b0", ".w0", 0x00000090, ".w0", 0x00000080, 0x000000f0
	test1	rsb, ".b0", ".w0", 0x00000001, ".w0", 0x00000000, 0x000000ff
	test1	rsc, ".b0", ".w0", 0x00000090, ".w0", 0x00000080, 0x000000ef
	# Test when intermediate value sets the borrow.
	test1	rsb, ".b0", ".w0", 0x00000000, ".w0", 0x00000100, 0x00000000
	test1	rsc, ".b0", ".w0", 0x00000000, ".w0", 0x00000002, 0x00000001
	test1	rsb, ".b0", ".w0", 0x00000000, ".w0", 0x00000100, 0x00000000
	test1	suc, ".b0", ".w0", 0x00000002, ".w0", 0x00000000, 0x00000001

	# ***** Reverse SUB 8-bit dst, 8-bit src *****
	test1	rsb, ".b0", ".w0", 0x00000000, ".w0", 0x00000000, 0x00000000
	test1	rsc, ".b0", ".w0", 0x00000001, ".w0", 0x00000010, 0x0000000f
	test1	rsc, ".b0", ".w0", 0x00000009, ".w0", 0x00000008, 0x000000ff
	test1	rsc, ".b0", ".w0", 0x00000009, ".w0", 0x00000008, 0x000000fe
	test1	rsc, ".b0", ".w0", 0x00000001, ".w0", 0x00000008, 0x00000006
	test1	rsc, ".b0", ".w0", 0x00000090, ".w0", 0x00000080, 0x000000f0
	test1	rsb, ".b0", ".w0", 0x00000001, ".w0", 0x00000000, 0x000000ff
	test1	rsc, ".b0", ".w0", 0x00000090, ".w0", 0x00000080, 0x000000ef

	# ***** Mixed 32-bit *****
	test1	sub, "   ", " ", 0x00000000, " ", 0x00000000, 0x00000000
	test1	adc, "   ", " ", 0x00000000, " ", 0x00000000, 0x00000001
	test1	suc, "   ", " ", 0x00000001, " ", 0x00000001, 0xffffffff
	test1	adc, "   ", " ", 0x00000001, " ", 0x00000000, 0x00000001

	test_seq "", "", 0xffffffff, 0x00000001, 0x00000000, 0x00000000 add, suc, add, 0x00000000
	test_seq "", "", 0xffffffff, 0x00000001, 0x00000000, 0x00000000 add, rsc, add, 0x00000000
	test_seq "", "", 0xfffffffe, 0x00000001, 0x00000000, 0x00000000 add, suc, add, 0xfffffffe
	test_seq "", "", 0xffffffff, 0x00000001, 0x00000000, 0x00000000 add, suc, adc, 0x00000001
	test_seq "", "", 0xfffffffe, 0x00000001, 0x00000000, 0x00000000 add, suc, adc, 0xffffffff

	test_seq "", "", 0xffffffff, 0x00000010, 0x00000000, 0x00000000 sub, adc, add, 0xfffffff0
	test_seq "", "", 0x0fffffff, 0x00000010, 0x00000000, 0x00000000 sub, adc, add, 0x0ffffff0
	test_seq "", "", 0x00000000, 0x00000010, 0x00000000, 0x00000000 sub, adc, add, 0xfffffff0
	test_seq "", "", 0x00000000, 0x00000010, 0x00000000, 0x00000000 sub, adc, adc, 0xfffffff0
	test_seq "", "", 0x00000000, 0x00000010, 0x00000000, 0x00000000 sub, adc, suc, 0xffffffef


	# For coverage, also test sequences of ALU instructions
	# (i.e. no other instructions in between).
	test_seq "", "", 0x00000000, 0x00000000, 0x00000000, 0x00000000 add, adc, adc, 0x00000000
	test_seq "", "", 0x80000000, 0xfffffff0, 0xc0000000, 0x0000001a add, adc, adc, 0x4000000c
	test_seq "", ".b0", 0x00000000, 0x00000001, 0x000000ff, 0x00000000 add, adc, adc, 0x00000001
	test_seq "", ".b0", 0x00000000, 0x00000001, 0x000000ff, 0x00000000 add, adc, adc, 0x00000001
	test_seq ".b0", ".b0", 0x00000000, 0x00000001, 0x00000000, 0x0000ffff add, adc, adc, 0x00000000
	test_seq ".b0", ".w0", 0x00000001, 0x00000020, 0x00000400, 0x00008000 add, adc, adc, 0x00000021
	test_seq "", "", 0x00000010, 0x0000000f, 0x00000002, 0x00000020 sub, suc, suc, 0xffffffde
	test_seq "", ".b0", 0x00000202, 0x00000000, 0x00000000, 0x00000000 sub, suc, suc, 0x00000002
	test_seq ".w0", ".b0", 0x00000008, 0x00000000, 0x00000000, 0x00000000, sub, suc, suc, 0x00000008
	test_seq ".w0", ".b0", 0x00000008, 0x000000ff, 0x000000ff, 0x000000ff, sub, suc, suc, 0x00000009
	test_seq ".w0", ".b0", 0x00000008, 0x00000fff, 0x00000fff, 0x00000fff, sub, suc, suc, 0x0000000b
	test_seq "", "", 0x0000000f, 0x00000010, 0x00000002, 0x00000020 rsb, suc, suc, 0xffffffde
	test_seq "", "", 0xffffffff, 0x00000001, 0x00000000, 0x00000000 add, suc, adc, 0x00000001
	test_seq "", "", 0x00000000, 0x00000010, 0x00000000, 0x00000000 sub, adc, adc, 0xfffffff0
	test_seq "", "", 0x00000000, 0x00000010, 0x00000000, 0x00000000 sub, adc, suc, 0xffffffef

	pass
EXIT_FAIL:
	fail