1 |
159 |
Agner |
/************************** tests_arithmetics.as ****************************
|
2 |
|
|
* Author: Agner Fog
|
3 |
|
|
* date created: 2021-06-06
|
4 |
|
|
* last modified: 2021-07-20
|
5 |
|
|
* Version: 1.11
|
6 |
|
|
* Project: ForwardCom Test suite, assembly code
|
7 |
|
|
* Description: Test arithmetic instructions with general purpose registers
|
8 |
|
|
*
|
9 |
|
|
* This test program will test arithmetic instructions and output a list of
|
10 |
|
|
* which instructions are working for int8, int16, int32, and int64 operands.
|
11 |
|
|
*
|
12 |
|
|
* Copyright 2021 GNU General Public License v.3 http://www.gnu.org/licenses
|
13 |
|
|
******************************************************************************/
|
14 |
|
|
|
15 |
|
|
// Library functions in libc_light.li
|
16 |
|
|
extern _puts: function reguse=3,0 // write string + linefeed to stdout
|
17 |
|
|
extern _printf: function reguse=0xF,0 // write formatted string to stdout
|
18 |
|
|
|
19 |
|
|
const section read ip // read-only data section
|
20 |
|
|
// Text strings:
|
21 |
|
|
|
22 |
|
|
text1: int8 "\nForwardCom test suite\nTest general purpose register arithmetic instructions" // intro text,
|
23 |
|
|
int8 "\nPress Run to continue"
|
24 |
|
|
int8 "\n int8 int16 int32 int64", 0 // and heading
|
25 |
|
|
newline: int8 "\n", 0 // newline
|
26 |
|
|
press_run: int8 "\nPress Run to continue", 0
|
27 |
|
|
|
28 |
|
|
format1: int8 "\n%-18s%3c%7c%7c%7c", 0 // format string for printing results
|
29 |
|
|
|
30 |
|
|
textadd: int8 "add", 0 // text strings for each instruction
|
31 |
|
|
textsub: int8 "sub", 0
|
32 |
|
|
textmul: int8 "mul", 0
|
33 |
|
|
|
34 |
|
|
textmulhisigned: int8 "mul_hi signed", 0
|
35 |
|
|
textmulhiunsigned: int8 "mul_hi unsigned", 0
|
36 |
|
|
|
37 |
|
|
textdivsigned: int8 "div signed", 0
|
38 |
|
|
textdivunsigned: int8 "div unsigned", 0
|
39 |
|
|
|
40 |
|
|
textremsigned: int8 "rem signed", 0
|
41 |
|
|
textremunsigned: int8 "rem unsigned", 0
|
42 |
|
|
|
43 |
|
|
textmaxsigned: int8 "max signed", 0
|
44 |
|
|
textmaxunsigned: int8 "max unsigned", 0
|
45 |
|
|
|
46 |
|
|
textminsigned: int8 "min signed", 0
|
47 |
|
|
textminunsigned: int8 "min unsigned", 0
|
48 |
|
|
|
49 |
|
|
textcompsigned: int8 "compare signed", 0
|
50 |
|
|
textcompunsigned: int8 "compare unsigned", 0
|
51 |
|
|
|
52 |
|
|
textabs: int8 "abs", 0
|
53 |
|
|
|
54 |
|
|
textsignx: int8 "sign_extend", 0
|
55 |
|
|
|
56 |
|
|
textroundp2: int8 "roundp2", 0
|
57 |
|
|
|
58 |
|
|
textaddadd: int8 "add_add", 0
|
59 |
|
|
|
60 |
|
|
textmuladd: int8 "mul_add", 0
|
61 |
|
|
|
62 |
|
|
textsignexadd: int8 "sign_extend_add", 0
|
63 |
|
|
|
64 |
|
|
const end
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
code section execute // code section
|
68 |
|
|
|
69 |
|
|
_main function public
|
70 |
|
|
|
71 |
|
|
/* register use:
|
72 |
|
|
r0: bits indicating success for int8, int16, int32, int64
|
73 |
|
|
r1: operand
|
74 |
|
|
r2: operand
|
75 |
|
|
r3: result
|
76 |
|
|
r4: scratch
|
77 |
|
|
r6: int64 supported
|
78 |
|
|
*/
|
79 |
|
|
|
80 |
|
|
// print intro text and heading
|
81 |
|
|
int64 r0 = address [text1] // calculate address of string
|
82 |
|
|
call _puts // call puts. parameter is in r0
|
83 |
|
|
|
84 |
|
|
breakpoint // debug breakpoint
|
85 |
|
|
|
86 |
|
|
int r1 = 1
|
87 |
|
|
int capab2 = write_capabilities(r1, 0) // disable error trap for unknown instructions
|
88 |
|
|
|
89 |
|
|
// Test addition
|
90 |
|
|
int32 r1 = 0x12345678
|
91 |
|
|
int32 r2 = 0x9abcdef0
|
92 |
|
|
|
93 |
|
|
int8 r3 = r1 + r2 // int8 addition
|
94 |
|
|
int32 r0 = r3 == ((0x78 + 0xf0) & 0xFF) // check result, set bit 0 if success
|
95 |
|
|
|
96 |
|
|
int16 r3 = r1 + r2 // int16 addition
|
97 |
|
|
int32 r4 = r3 == ((0x5678 + 0xdef0) & 0xFFFF) // check result
|
98 |
|
|
int32 r0 |= 2, mask = r4 // set bit 1 if success
|
99 |
|
|
|
100 |
|
|
int32 r3 = r1 + r2 // int32 addition
|
101 |
|
|
int32 r4 = r3 == (0x12345678 + 0x9abcdef0) // check result
|
102 |
|
|
int32 r0 |= 4, mask = r4 // set bit 2 if success
|
103 |
|
|
|
104 |
|
|
int64 r1 <<= 32
|
105 |
|
|
int64 r2 <<= 32
|
106 |
|
|
int64 r1 += 0x12345
|
107 |
|
|
int64 r3 = r1 + r2 // 64 bit addition
|
108 |
|
|
int32 r4 = r3 == 0x12345 // check lower half of result
|
109 |
|
|
uint64 r3 >>= 32 // shift down upper half
|
110 |
|
|
int64 r6 = (r3 == (0x12345678 + 0x9abcdef0)) && r4 // check upper half of result
|
111 |
|
|
int32 r0 |= 8, mask = r6 // set bit 2 if success
|
112 |
|
|
|
113 |
|
|
int64 r1 = address [textadd]
|
114 |
|
|
call print_result
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
// Test subtraction
|
118 |
|
|
int32 r1 = 0x12345678
|
119 |
|
|
int32 r2 = 0x9abcdef0
|
120 |
|
|
|
121 |
|
|
int8 r3 = r1 - r2 // int8 addition
|
122 |
|
|
int32 r0 = r3 == ((0x78 - 0xf0) & 0xFF) // check result, set bit 0 if success
|
123 |
|
|
|
124 |
|
|
int16 r3 = r1 - r2 // int16 addition
|
125 |
|
|
int32 r4 = r3 == ((0x5678 - 0xdef0) & 0xFFFF) // check result
|
126 |
|
|
int32 r0 |= 2, mask = r4 // set bit 1 if success
|
127 |
|
|
|
128 |
|
|
int32 r3 = r1 - r2 // int32 addition
|
129 |
|
|
int32 r4 = r3 == ((0x12345678 - 0x9abcdef0) & 0xFFFFFFFF) // check result
|
130 |
|
|
int32 r0 |= 4, mask = r4 // set bit 2 if success
|
131 |
|
|
|
132 |
|
|
int64 r1 <<= 32
|
133 |
|
|
int64 r2 <<= 32
|
134 |
|
|
int64 r1 += 0x12345
|
135 |
|
|
int64 r3 = r1 - r2 // 64 bit addition
|
136 |
|
|
int64 r4 = ((0x12345678 - 0x9abcdef0) << 32) + 0x12345
|
137 |
|
|
int64 r5 = r3 == r4 && r6
|
138 |
|
|
int32 r0 |= 8, mask = r5 // set bit 2 if success
|
139 |
|
|
|
140 |
|
|
int64 r1 = address [textsub]
|
141 |
|
|
call print_result
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
// Test multiplication
|
145 |
|
|
int32 r1 = 0x12345678
|
146 |
|
|
int32 r2 = 0x9abcdef0
|
147 |
|
|
|
148 |
|
|
int8 r3 = r1 * r2 // int8 multiplication
|
149 |
|
|
int32 r0 = r3 == ((0x78 * 0xf0) & 0xFF) // check result, set bit 0 if success
|
150 |
|
|
|
151 |
|
|
int16 r3 = r1 * r2 // int16 multiplication
|
152 |
|
|
int32 r4 = r3 == ((0x5678 * 0xdef0) & 0xFFFF) // check result
|
153 |
|
|
int32 r0 |= 2, mask = r4 // set bit 1 if success
|
154 |
|
|
|
155 |
|
|
int32 r3 = r1 * r2 // int32 multiplication
|
156 |
|
|
int32 r4 = r3 == ((0x12345678 * 0x9abcdef0) & 0xFFFFFFFF) // check result
|
157 |
|
|
int32 r0 |= 4, mask = r4 // set bit 2 if success
|
158 |
|
|
|
159 |
|
|
if (int r6 & 1) { // try only if 64 bits supported
|
160 |
|
|
int64 r1 <<= 32
|
161 |
|
|
int64 r2 <<= 32
|
162 |
|
|
int64 r1 += 0x00012345
|
163 |
|
|
int64 r2 += 0x6edc4321
|
164 |
|
|
int64 r3 = r1 * r2 // 64 bit multiplication
|
165 |
|
|
int64 r4 = (0x1234567800012345 * 0x9abcdef06edc4321) // expected result
|
166 |
|
|
int64 r5 = (r3 == r4)
|
167 |
|
|
int32 r0 |= 8, mask = r5 // set bit 2 if success
|
168 |
|
|
}
|
169 |
|
|
|
170 |
|
|
int64 r1 = address [textmul]
|
171 |
|
|
call print_result
|
172 |
|
|
|
173 |
|
|
|
174 |
|
|
// Test mul_hi: high part of product, signed
|
175 |
|
|
int32 r1 = 0xa1b2c3d4
|
176 |
|
|
int32 r2 = 0xe5f60718
|
177 |
|
|
|
178 |
|
|
int8 r3 = mul_hi(r1, r2)
|
179 |
|
|
int32 r0 = r3 == ((0xffd4 * 0x18) >> 8 & 0xFF) // check result, set bit 0 if success
|
180 |
|
|
|
181 |
|
|
int16 r3 = mul_hi(r1, r2)
|
182 |
|
|
int32 r4 = r3 == ((0xffffc3d4 * 0x0718) >> 16 & 0xFFFF) // check result, set bit 0 if success
|
183 |
|
|
int32 r0 |= 2, mask = r4 // set bit 1 if success
|
184 |
|
|
|
185 |
|
|
int32 r3 = mul_hi(r1, r2)
|
186 |
|
|
int32 r4 = r3 == ((0xffffffffa1b2c3d4 * 0xffffffffe5f60718) >> 32 & 0xFFFFFFFF) // check result, set bit 0 if success
|
187 |
|
|
int32 r0 |= 4, mask = r4 // set bit 2 if success
|
188 |
|
|
|
189 |
|
|
int64 r1 = 0x21b2c3d4e5f60718
|
190 |
|
|
int64 r2 = 0x46352958adbecef8
|
191 |
|
|
%prodhi = (((0xe5f60718 * 0xadbecef8 >>> 32) + 0x21b2c3d4 * 0xadbecef8 + 0x46352958 * 0xe5f60718) >>> 32) + 0x21b2c3d4 * 0x46352958
|
192 |
|
|
|
193 |
|
|
int64 r3 = mul_hi(r1, r2)
|
194 |
|
|
int64 r4 = r3 == prodhi // check result, set bit 0 if success
|
195 |
|
|
int32 r0 |= 8, mask = r4 // set bit 3 if success
|
196 |
|
|
|
197 |
|
|
int64 r1 = address [textmulhisigned]
|
198 |
|
|
call print_result
|
199 |
|
|
|
200 |
|
|
|
201 |
|
|
// Test mul_hi: high part of product, unsigned
|
202 |
|
|
int32 r1 = 0xa1b2c3d4
|
203 |
|
|
int32 r2 = 0xe5f60718
|
204 |
|
|
|
205 |
|
|
int8 r3 = mul_hi_u(r1, r2)
|
206 |
|
|
int32 r0 = r3 == ((0xd4 * 0x18) >> 8 & 0xFF) // check result, set bit 0 if success
|
207 |
|
|
|
208 |
|
|
int16 r3 = mul_hi_u(r1, r2)
|
209 |
|
|
int32 r4 = r3 == ((0xc3d4 * 0x0718) >> 16 & 0xFFFF) // check result, set bit 0 if success
|
210 |
|
|
int32 r0 |= 2, mask = r4 // set bit 1 if success
|
211 |
|
|
|
212 |
|
|
int32 r3 = mul_hi_u(r1, r2)
|
213 |
|
|
int32 r4 = r3 == ((0xa1b2c3d4 * 0xe5f60718) >> 32 & 0xFFFFFFFF) // check result, set bit 0 if success
|
214 |
|
|
int32 r0 |= 4, mask = r4 // set bit 2 if success
|
215 |
|
|
|
216 |
|
|
int64 r1 = 0x21b2c3d4e5f60718
|
217 |
|
|
int64 r2 = 0x46352958adbecef8
|
218 |
|
|
%prodhi = (((0xe5f60718 * 0xadbecef8 >>> 32) + 0x21b2c3d4 * 0xadbecef8 + 0x46352958 * 0xe5f60718) >>> 32) + 0x21b2c3d4 * 0x46352958
|
219 |
|
|
|
220 |
|
|
int64 r3 = mul_hi_u(r1, r2)
|
221 |
|
|
int64 r4 = r3 == prodhi // check result, set bit 0 if success
|
222 |
|
|
int32 r0 |= 8, mask = r4 // set bit 3 if success
|
223 |
|
|
|
224 |
|
|
int64 r1 = address [textmulhiunsigned]
|
225 |
|
|
call print_result
|
226 |
|
|
|
227 |
|
|
|
228 |
|
|
// Test signed division
|
229 |
|
|
int32 r1 = 0x12345678
|
230 |
|
|
int32 r2 = 0xab1d2f
|
231 |
|
|
|
232 |
|
|
int8 r3 = r1 / r2 // int8 division
|
233 |
|
|
int32 r0 = r3 == ((0x78 / 0x2f) & 0xFF) // check result, set bit 0 if success
|
234 |
|
|
|
235 |
|
|
int16 r3 = r1 / r2 // int16 division
|
236 |
|
|
int32 r4 = r3 == ((0x5678 / 0x1d2f) & 0xFFFF) // check result
|
237 |
|
|
int32 r0 |= 2, mask = r4 // set bit 1 if success
|
238 |
|
|
|
239 |
|
|
int32 r3 = r1 / r2 // int32 division
|
240 |
|
|
int32 r4 = r3 == ((0x12345678 / 0xab1d2f) & 0xFFFFFFFF) // check result
|
241 |
|
|
|
242 |
|
|
int32 r6 = -r2
|
243 |
|
|
int32 r3 = r1 / r6 // int32 division negative
|
244 |
|
|
int32 r5 = r3 == (-(0x12345678 / 0xab1d2f) & 0xFFFFFFFF) // check result
|
245 |
|
|
int r4 &= r5
|
246 |
|
|
int32 r0 |= 4, mask = r4 // set bit 2 if success
|
247 |
|
|
|
248 |
|
|
int64 r1 <<= 32
|
249 |
|
|
int64 r2 <<= 32
|
250 |
|
|
int64 r1 |= 0x22334455
|
251 |
|
|
int64 r2 |= 0x66778899
|
252 |
|
|
|
253 |
|
|
int64 r3 = r1 / r2
|
254 |
|
|
int32 r4 = r3 == 0x1234567822334455 / 0xab1d2f66778899 // check result
|
255 |
|
|
int32 r0 |= 8, mask = r4 // set bit 3 if success
|
256 |
|
|
|
257 |
|
|
int64 r1 = address [textdivsigned]
|
258 |
|
|
call print_result
|
259 |
|
|
|
260 |
|
|
|
261 |
|
|
// Test unsigned division
|
262 |
|
|
int32 r1 = 0x12345678
|
263 |
|
|
int32 r2 = 0xffabf2f3
|
264 |
|
|
|
265 |
|
|
uint8 r3 = r1 / r2 // int8 unsigned division
|
266 |
|
|
int r0 = r3 == 0 // check result, set bit 0 if success
|
267 |
|
|
uint8 r3 = r2 / r1 // int8 unsigned division
|
268 |
|
|
int r0 = r3 == 2 && r0 // check result, set bit 0 if success
|
269 |
|
|
|
270 |
|
|
uint16 r3 = r1 / r2 // int16 unsigned division
|
271 |
|
|
int32 r5 = r3 == 0 // check result, set bit 0 if success
|
272 |
|
|
uint16 r3 = r2 / r1 // int16 unsigned division
|
273 |
|
|
int32 r4 = r3 == 2 && r5
|
274 |
|
|
int r0 |= 2, mask = r4 // set bit 1 if success
|
275 |
|
|
|
276 |
|
|
uint32 r3 = r1 / r2 // int32 unsigned division
|
277 |
|
|
int32 r5 = r3 == 0 // check result, set bit 0 if success
|
278 |
|
|
uint32 r3 = r2 / r1 // int32 unsigned division
|
279 |
|
|
int32 r4 = r3 == 0xE // check result, set bit 0 if success
|
280 |
|
|
int r4 &= r5
|
281 |
|
|
int r0 |= 4, mask = r4 // set bit 2 if success
|
282 |
|
|
|
283 |
|
|
int64 r1 <<= 32
|
284 |
|
|
int64 r2 <<= 32
|
285 |
|
|
int64 r1 |= 0x22334455
|
286 |
|
|
int64 r2 |= 0x66778899
|
287 |
|
|
uint64 r3 = r2 / r1
|
288 |
|
|
int64 r4 = r3 == 0xffabf2f3 / 0x12345678
|
289 |
|
|
int r0 |= 8, mask = r4 // set bit 3 if success
|
290 |
|
|
|
291 |
|
|
int64 r1 = address [textdivunsigned]
|
292 |
|
|
call print_result
|
293 |
|
|
|
294 |
|
|
|
295 |
|
|
// Test rem, signed
|
296 |
|
|
%A = 0xcc5d8e9f
|
297 |
|
|
%B = 0x1c1d1e18
|
298 |
|
|
|
299 |
|
|
int32 r1 = A
|
300 |
|
|
int32 r2 = B
|
301 |
|
|
|
302 |
|
|
int8 r3 = r1 % r2 // int8 modulo
|
303 |
|
|
int32 r0 = r3 == (-((-A & 0xFF) % (B & 0xFF)) & 0xFF) // check result, set bit 0 if success
|
304 |
|
|
|
305 |
|
|
int16 r3 = r1 % r2 // int16 modulo
|
306 |
|
|
int32 r4 = r3 == (-((-A & 0xFFFF) % (B & 0xFFFF)) & 0xFFFF) // check result
|
307 |
|
|
int32 r0 |= 2, mask = r4 // set bit 1 if success
|
308 |
|
|
|
309 |
|
|
int32 r3 = r1 % r2 // int32 modulo
|
310 |
|
|
int32 r4 = r3 ==(-((-A & 0xFFFFFFFF) % (B & 0xFFFFFFFF)) & 0xFFFFFFFF) // check result
|
311 |
|
|
int32 r0 |= 4, mask = r4 // set bit 2 if success
|
312 |
|
|
|
313 |
|
|
int64 r1 <<= 32
|
314 |
|
|
int64 r1 |= r2
|
315 |
|
|
int64 r2 <<= 32
|
316 |
|
|
|
317 |
|
|
%A1 = (A << 32) + A
|
318 |
|
|
int64 r1 = A1
|
319 |
|
|
int64 r2 = B
|
320 |
|
|
int64 r3 = r1 % r2 // int64 modulo
|
321 |
|
|
%modulo1 = -(-A1 % B)
|
322 |
|
|
int64 r4 = r3 == modulo1 // check result
|
323 |
|
|
int32 r0 |= 8, mask = r4 // set bit 3 if success
|
324 |
|
|
|
325 |
|
|
int64 r1 = address [textremsigned]
|
326 |
|
|
call print_result
|
327 |
|
|
|
328 |
|
|
|
329 |
|
|
// Test rem, unsigned
|
330 |
|
|
int32 r1 = A
|
331 |
|
|
int32 r2 = B
|
332 |
|
|
|
333 |
|
|
uint8 r3 = r1 % r2 // int8 modulo
|
334 |
|
|
int32 r0 = r3 == (A & 0xFF) % (B & 0xFF) // check result, set bit 0 if success
|
335 |
|
|
|
336 |
|
|
uint16 r3 = r1 % r2 // int16 modulo
|
337 |
|
|
int32 r4 = r3 == (A & 0xFFFF) % (B & 0xFFFF) // check result
|
338 |
|
|
int32 r0 |= 2, mask = r4 // set bit 1 if success
|
339 |
|
|
|
340 |
|
|
uint32 r3 = r1 % r2 // int32 modulo
|
341 |
|
|
int32 r4 = r3 == (A & 0xFFFFFFFF) % (B & 0xFFFFFFFF) // check result
|
342 |
|
|
int32 r0 |= 4, mask = r4 // set bit 2 if success
|
343 |
|
|
|
344 |
|
|
int64 r1 = A1
|
345 |
|
|
uint64 r3 = r1 % r2 // int64 modulo
|
346 |
|
|
%modulo1 = 0x177FFA97
|
347 |
|
|
int64 r4 = r3 == modulo1 // check result
|
348 |
|
|
int32 r0 |= 8, mask = r4 // set bit 3 if success
|
349 |
|
|
|
350 |
|
|
int64 r1 = address [textremunsigned]
|
351 |
|
|
call print_result
|
352 |
|
|
|
353 |
|
|
|
354 |
|
|
int64 r0 = address [press_run] // press run to continue
|
355 |
|
|
call _printf // print string
|
356 |
|
|
|
357 |
|
|
breakpoint
|
358 |
|
|
|
359 |
|
|
|
360 |
|
|
// Test max signed
|
361 |
|
|
int32 r1 = A
|
362 |
|
|
int32 r2 = B
|
363 |
|
|
|
364 |
|
|
int8 r3 = max(r1, r2) // int8 max
|
365 |
|
|
int32 r0 = r3 == (B & 0xFF) // check result, set bit 0 if success
|
366 |
|
|
|
367 |
|
|
int16 r3 = max(r1, r2) // int16 max
|
368 |
|
|
int32 r4 = r3 == (B & 0xFFFF) // check result
|
369 |
|
|
int32 r0 |= 2, mask = r4 // set bit 1 if success
|
370 |
|
|
|
371 |
|
|
int32 r3 = max(r2, r1) // int32 max
|
372 |
|
|
int32 r4 = r3 == (B & 0xFFFFFFFF) // check result
|
373 |
|
|
int32 r0 |= 4, mask = r4 // set bit 2 if success
|
374 |
|
|
|
375 |
|
|
int64 r1 <<= 32
|
376 |
|
|
int64 r2 <<= 32
|
377 |
|
|
int64 r3 = max(r1, r2) // int64 max
|
378 |
|
|
int64 r3 >>= 32
|
379 |
|
|
int64 r4 = r3 == B // check result
|
380 |
|
|
|
381 |
|
|
int32 r0 |= 8, mask = r4 // set bit 3 if success
|
382 |
|
|
|
383 |
|
|
int64 r1 = address [textmaxsigned]
|
384 |
|
|
call print_result
|
385 |
|
|
|
386 |
|
|
|
387 |
|
|
// Test max unsigned
|
388 |
|
|
int32 r1 = A
|
389 |
|
|
int32 r2 = B
|
390 |
|
|
|
391 |
|
|
uint8 r3 = max(r1, r2) // int8 max
|
392 |
|
|
int32 r0 = r3 == (A & 0xFF) // check result, set bit 0 if success
|
393 |
|
|
|
394 |
|
|
uint16 r3 = max(r1, r2) // int16 max
|
395 |
|
|
int32 r4 = r3 == (A & 0xFFFF) // check result
|
396 |
|
|
int32 r0 |= 2, mask = r4 // set bit 1 if success
|
397 |
|
|
|
398 |
|
|
uint32 r3 = max(r2, r1) // int32 max
|
399 |
|
|
int32 r4 = r3 == (A & 0xFFFFFFFF) // check result
|
400 |
|
|
int32 r0 |= 4, mask = r4 // set bit 2 if success
|
401 |
|
|
|
402 |
|
|
int64 r1 <<= 32
|
403 |
|
|
int64 r2 <<= 32
|
404 |
|
|
uint64 r3 = max(r1, r2) // int64 max
|
405 |
|
|
uint64 r3 >>= 32
|
406 |
|
|
int64 r4 = r3 == A // check result
|
407 |
|
|
int32 r0 |= 8, mask = r4 // set bit 3 if success
|
408 |
|
|
|
409 |
|
|
int64 r1 = address [textmaxunsigned]
|
410 |
|
|
call print_result
|
411 |
|
|
|
412 |
|
|
|
413 |
|
|
// Test min signed
|
414 |
|
|
int32 r1 = A
|
415 |
|
|
int32 r2 = B
|
416 |
|
|
|
417 |
|
|
int8 r3 = min(r1, r2) // int8 max
|
418 |
|
|
int32 r0 = r3 == (A & 0xFF) // check result, set bit 0 if success
|
419 |
|
|
|
420 |
|
|
int16 r3 = min(r1, r2) // int16 max
|
421 |
|
|
int32 r4 = r3 == (A & 0xFFFF) // check result
|
422 |
|
|
int32 r0 |= 2, mask = r4 // set bit 1 if success
|
423 |
|
|
|
424 |
|
|
int32 r3 = min(r2, r1) // int32 max
|
425 |
|
|
int32 r4 = r3 == (A & 0xFFFFFFFF) // check result
|
426 |
|
|
int32 r0 |= 4, mask = r4 // set bit 2 if success
|
427 |
|
|
|
428 |
|
|
int64 r1 <<= 32
|
429 |
|
|
int64 r2 <<= 32
|
430 |
|
|
int64 r3 = min(r1, r2) // int64 max
|
431 |
|
|
int64 r3 >>= 32
|
432 |
|
|
int64 r4 = r3 == A - (1 << 32) // check result
|
433 |
|
|
int32 r0 |= 8, mask = r4 // set bit 3 if success
|
434 |
|
|
|
435 |
|
|
int64 r1 = address [textminsigned]
|
436 |
|
|
call print_result
|
437 |
|
|
|
438 |
|
|
|
439 |
|
|
// Test min unsigned
|
440 |
|
|
int32 r1 = A
|
441 |
|
|
int32 r2 = B
|
442 |
|
|
|
443 |
|
|
uint8 r3 = min(r1, r2) // int8 max
|
444 |
|
|
int32 r0 = r3 == (B & 0xFF) // check result, set bit 0 if success
|
445 |
|
|
|
446 |
|
|
uint16 r3 = min(r1, r2) // int16 max
|
447 |
|
|
int32 r4 = r3 == (B & 0xFFFF) // check result
|
448 |
|
|
int32 r0 |= 2, mask = r4 // set bit 1 if success
|
449 |
|
|
|
450 |
|
|
uint32 r3 = min(r2, r1) // int32 max
|
451 |
|
|
int32 r4 = r3 == (B & 0xFFFFFFFF) // check result
|
452 |
|
|
int32 r0 |= 4, mask = r4 // set bit 2 if success
|
453 |
|
|
|
454 |
|
|
int64 r1 <<= 32
|
455 |
|
|
int64 r2 <<= 32
|
456 |
|
|
uint64 r3 = min(r1, r2) // int64 max
|
457 |
|
|
uint64 r3 >>= 32
|
458 |
|
|
int64 r4 = r3 == B // check result
|
459 |
|
|
int32 r0 |= 8, mask = r4 // set bit 3 if success
|
460 |
|
|
|
461 |
|
|
int64 r1 = address [textminunsigned]
|
462 |
|
|
call print_result
|
463 |
|
|
|
464 |
|
|
|
465 |
|
|
// Test compare signed
|
466 |
|
|
int32 r1 = A
|
467 |
|
|
int32 r2 = B
|
468 |
|
|
|
469 |
|
|
int8 r0 = r1 < r2 // int8 compare
|
470 |
|
|
int8 r0 = r2 > r1 && r0 // int8 compare && last result
|
471 |
|
|
|
472 |
|
|
int16 r3 = r1 <= r2 // int16 compare
|
473 |
|
|
int16 r3 = r1 != r2 && r3 // int16 compare
|
474 |
|
|
int r0 |= 2, mask = r3 // set bit 1 if success
|
475 |
|
|
|
476 |
|
|
int32 r3 = r1 <= r2 // int32 compare
|
477 |
|
|
int32 r3 = r2 >= r1 && r3 // int32 compare
|
478 |
|
|
int32 r0 |= 4, mask = r3 // set bit 2 if success
|
479 |
|
|
|
480 |
|
|
int64 r1 <<= 32
|
481 |
|
|
int64 r2 <<= 32
|
482 |
|
|
int64 r3 = r1 < r2 // int64 compare
|
483 |
|
|
int64 r3 = r2 > r1 && r3 // int64 compare
|
484 |
|
|
int64 r3 = r2 == r2 && r3 // int64 compare
|
485 |
|
|
int64 r0 |= 8, mask = r3 // set bit 3 if success
|
486 |
|
|
|
487 |
|
|
int64 r1 = address [textcompsigned]
|
488 |
|
|
call print_result
|
489 |
|
|
|
490 |
|
|
|
491 |
|
|
// Test compare unsigned
|
492 |
|
|
int32 r1 = A
|
493 |
|
|
int32 r2 = B
|
494 |
|
|
|
495 |
|
|
uint8 r0 = r1 > r2 // int8 compare
|
496 |
|
|
uint8 r0 = r2 < r1 && r0 // int8 compare && last result
|
497 |
|
|
|
498 |
|
|
uint16 r3 = r1 >= r2 // int16 compare
|
499 |
|
|
uint16 r3 = r1 != r2 && r3 // int16 compare
|
500 |
|
|
int r0 |= 2, mask = r3 // set bit 1 if success
|
501 |
|
|
|
502 |
|
|
uint32 r3 = r1 >= r2 // int32 compare
|
503 |
|
|
uint32 r3 = r2 <= r1 && r3 // int32 compare
|
504 |
|
|
int32 r0 |= 4, mask = r3 // set bit 2 if success
|
505 |
|
|
|
506 |
|
|
int64 r1 <<= 32
|
507 |
|
|
int64 r2 <<= 32
|
508 |
|
|
uint64 r3 = r1 > r2 // int64 compare
|
509 |
|
|
uint64 r3 = r2 < r1 && r3 // int64 compare
|
510 |
|
|
uint64 r3 = r2 == r2 && r3 // int64 compare
|
511 |
|
|
int64 r0 |= 8, mask = r3 // set bit 3 if success
|
512 |
|
|
|
513 |
|
|
int64 r1 = address [textcompunsigned]
|
514 |
|
|
call print_result
|
515 |
|
|
|
516 |
|
|
|
517 |
|
|
// Test abs
|
518 |
|
|
int8 r1 = -20
|
519 |
|
|
int8 r3 = abs(r1, 0) // int8 abs
|
520 |
|
|
int r0 = r3 == 20
|
521 |
|
|
int8 r1 = 0x80
|
522 |
|
|
int8 r3 = abs(r1, 0) // overflow wrap around
|
523 |
|
|
int r0 = r3 == r1 && r0
|
524 |
|
|
int8 r3 = abs(r1, 1) // overflow saturates
|
525 |
|
|
int r0 = r3 == 0x7F && r0
|
526 |
|
|
int8 r3 = abs(r1, 2) // overflow gives zero
|
527 |
|
|
int r0 = r3 == 0 && r0
|
528 |
|
|
|
529 |
|
|
int16 r1 = 0x7fff
|
530 |
|
|
int16 r2 = abs(r1,0) // int16 abs
|
531 |
|
|
int r3 = r2 == r1
|
532 |
|
|
int16 r2 = r1 + 1 // 0x8000
|
533 |
|
|
int16 r2 = abs(r2, 1) // overflow saturates
|
534 |
|
|
int r3 = r2 == r1 && r3
|
535 |
|
|
int r0 |= 2, mask = r3 // set bit 1 if success
|
536 |
|
|
|
537 |
|
|
int32 r1 = 0x7fffffff
|
538 |
|
|
int32 r2 = abs(r1, 0) // int32 abs
|
539 |
|
|
int r3 = r2 == r1
|
540 |
|
|
int32 r2 = r1 + 1 // 0x80000000
|
541 |
|
|
int32 r2 = abs(r2, 1) // overflow saturates
|
542 |
|
|
int r3 = r2 == r1 && r3
|
543 |
|
|
int r0 |= 4, mask = r3 // set bit 2 if success
|
544 |
|
|
|
545 |
|
|
int64 r1 = -12345 - (1 << 40)
|
546 |
|
|
int64 r2 = abs(r1, 0) // int64 abs
|
547 |
|
|
int64 r3 = r2 == 12345 + (1 << 40)
|
548 |
|
|
int64 r2 >>= 32
|
549 |
|
|
int32 r3 = r2 == 1 << 8 && r3
|
550 |
|
|
int r0 |= 8, mask = r3 // set bit 3 if success
|
551 |
|
|
|
552 |
|
|
int64 r1 = address [textabs]
|
553 |
|
|
call print_result
|
554 |
|
|
|
555 |
|
|
|
556 |
|
|
// Test sign_extend
|
557 |
|
|
int32 r1 = 0x1234fe
|
558 |
|
|
int8 r2 = sign_extend(r1) // sign extend from 8 bits to 64 bits
|
559 |
|
|
int64 r0 = r2 == -2
|
560 |
|
|
int16 r2 = sign_extend(r1) // sign extend from 16 bits to 64 bits
|
561 |
|
|
int64 r3 = r2 == 0x34fe
|
562 |
|
|
int16 r2 = sign_extend(-20) // sign extend from 16 bits to 64 bits
|
563 |
|
|
int64 r3 = (r2 == -20) && r3
|
564 |
|
|
int r0 |= 2, mask = r3 // set bit 1 if success
|
565 |
|
|
int32 r1 = -r1
|
566 |
|
|
int32 r2 = sign_extend(r1) // sign extend from 32 bits to 64 bits
|
567 |
|
|
int64 r3 = r2 == -0x1234fe
|
568 |
|
|
int r0 |= 4, mask = r3 // set bit 2 if success
|
569 |
|
|
int r0 |= 1 << 7 // suppress 'N' for 64 bits
|
570 |
|
|
|
571 |
|
|
int64 r1 = address [textsignx]
|
572 |
|
|
call print_result
|
573 |
|
|
|
574 |
|
|
|
575 |
|
|
// Test roundp2
|
576 |
|
|
int32 r1 = 0x1234fe
|
577 |
|
|
int8 r2 = roundp2(r1, 0) // 8 bit round down to power of 2
|
578 |
|
|
int r0 = r2 == 0x80
|
579 |
|
|
int8 r2 = roundp2(r1, 0x21) // 8 bit round up to power of 2
|
580 |
|
|
int8 r0 = (r2 == -1) && r0 // overflow
|
581 |
|
|
|
582 |
|
|
int16 r2 = roundp2(r1, 0) // 16 bit round down to power of 2
|
583 |
|
|
int r3 = r2 == 0x2000
|
584 |
|
|
int16 r2 = roundp2(r1, 1) // 16 bit round up to power of 2
|
585 |
|
|
int r3 = (r2 == 0x4000) && r3
|
586 |
|
|
int r0 |= 2, mask = r3 // set bit 1 if success
|
587 |
|
|
|
588 |
|
|
int32 r2 = roundp2(r1, 0) // 32 bit round down to power of 2
|
589 |
|
|
int32 r3 = r2 == 0x100000
|
590 |
|
|
int32 r2 = roundp2(r1, 1) // 32 bit round up to power of 2
|
591 |
|
|
int32 r3 = (r2 == 0x200000) && r3
|
592 |
|
|
int32 r1 <<= 11
|
593 |
|
|
int32 r2 = roundp2(r1, 1) // 32 bit round up overflow
|
594 |
|
|
int32 r3 = (r2 == 0) && r3
|
595 |
|
|
int32 r2 = roundp2(r2, 0x10) // 32 bit down zero
|
596 |
|
|
int32 r3 = (r2 == -1) && r3
|
597 |
|
|
int r0 |= 4, mask = r3 // set bit 2 if success
|
598 |
|
|
|
599 |
|
|
int64 r2 = roundp2(r1, 0) // 64 bit round down to power of 2
|
600 |
|
|
uint64 r3 = r2 == 0x80000000
|
601 |
|
|
int64 r2 = roundp2(r1, 1) // 64 bit round up to power of 2
|
602 |
|
|
int64 r2 >>= 32
|
603 |
|
|
int64 r3 = r2 == 1 && r3
|
604 |
|
|
int r0 |= 8, mask = r3 // set bit 3 if success
|
605 |
|
|
|
606 |
|
|
int64 r1 = address [textroundp2]
|
607 |
|
|
call print_result
|
608 |
|
|
|
609 |
|
|
|
610 |
|
|
// Test add_add
|
611 |
|
|
%A = 0xcc5d8e9f
|
612 |
|
|
%B = 0x1c1d1e18
|
613 |
|
|
%C = 0x538e0c17
|
614 |
|
|
|
615 |
|
|
int r1 = A
|
616 |
|
|
int r2 = B
|
617 |
|
|
int r3 = C
|
618 |
|
|
|
619 |
|
|
int8 r4 = r1 + r2 + r3 // int8 add_add
|
620 |
|
|
int r0 = r4 == (A + B + C & 0xFF)
|
621 |
|
|
|
622 |
|
|
int16 r4 = -r1 + r2 + r3 // int16 add_add
|
623 |
|
|
int r5 = r4 == (- A + B + C & 0xFFFF)
|
624 |
|
|
int r0 |= 2, mask = r5 // set bit 1 if success
|
625 |
|
|
|
626 |
|
|
int32 r4 = r1 - r2 + r3 // int32 add_add
|
627 |
|
|
int r5 = r4 == (A - B + C & 0xFFFFFFFF)
|
628 |
|
|
int r0 |= 4, mask = r5 // set bit 2 if success
|
629 |
|
|
|
630 |
|
|
int64 r2 <<= 32
|
631 |
|
|
int64 r4 = r1 + r2 - r3 // int64 add_add
|
632 |
|
|
int64 r5 = r4 == A + (B << 32) - C
|
633 |
|
|
int64 r4 >>= 32
|
634 |
|
|
int32 r5 = r4 == (A - C >> 32) + B && r5
|
635 |
|
|
int r0 |= 8, mask = r5 // set bit 3 if success
|
636 |
|
|
|
637 |
|
|
int64 r1 = address [textaddadd]
|
638 |
|
|
call print_result
|
639 |
|
|
|
640 |
|
|
|
641 |
|
|
// Test mul_add
|
642 |
|
|
int r1 = A
|
643 |
|
|
int r2 = B
|
644 |
|
|
int r3 = C
|
645 |
|
|
|
646 |
|
|
int8 r4 = r1 * r2 + r3 // int8 mul_add
|
647 |
|
|
int r0 = r4 == ((A * B + C) & 0xFF)
|
648 |
|
|
|
649 |
|
|
int16 r4 = -r1 * r2 + r3 // int16 mul_add
|
650 |
|
|
int r5 = r4 == (-A * B + C & 0xFFFF)
|
651 |
|
|
int r0 |= 2, mask = r5 // set bit 1 if success
|
652 |
|
|
|
653 |
|
|
int32 r4 = r1 * 1234 - r3 // int32 mul_add2
|
654 |
|
|
int r5 = r4 == (A * 1234 - C & 0xFFFFFFFF )
|
655 |
|
|
int r0 |= 4, mask = r5 // set bit 2 if success
|
656 |
|
|
|
657 |
|
|
int64 r4 = r1 * r2 - (123 << 4) // int64 mul_add
|
658 |
|
|
int64 r5 = r4 == A * B - (123 << 4)
|
659 |
|
|
|
660 |
|
|
int r0 |= 8, mask = r5 // set bit 3 if success
|
661 |
|
|
|
662 |
|
|
int64 r1 = address [textmuladd]
|
663 |
|
|
call print_result
|
664 |
|
|
|
665 |
|
|
|
666 |
|
|
// Test sign_extend_add
|
667 |
|
|
int r1 = A
|
668 |
|
|
int r2 = B
|
669 |
|
|
|
670 |
|
|
int8 r4 = sign_extend_add(r2, r1)
|
671 |
|
|
int64 r0 = r4 == B + (A & 0xFF) - 0x100
|
672 |
|
|
|
673 |
|
|
int16 r4 = sign_extend_add(r2, r1), options = 2
|
674 |
|
|
int64 r5 = r4 == B + ((A & 0xFFFF) << 2) - (0x10000 << 2)
|
675 |
|
|
int r0 |= 2, mask = r5 // set bit 1 if success
|
676 |
|
|
|
677 |
|
|
int32 r4 = sign_extend_add(r1, r2), options = 3
|
678 |
|
|
int64 r5 = r4 == A + ((B & 0xFFFFFFFF) << 3) // - (0x100000000 << 3)
|
679 |
|
|
int r0 |= 4, mask = r5 // set bit 2 if success
|
680 |
|
|
|
681 |
|
|
int64 r4 = sign_extend_add(r2, r1), options = 3
|
682 |
|
|
int64 r5 = r4 == B + (A << 3)
|
683 |
|
|
uint64 r4 >>= 3
|
684 |
|
|
int32 r5 = r4 == (B >> 3) + A && r5
|
685 |
|
|
int r0 |= 8, mask = r5 // set bit 3 if success
|
686 |
|
|
|
687 |
|
|
|
688 |
|
|
int64 r1 = address [textsignexadd]
|
689 |
|
|
call print_result
|
690 |
|
|
|
691 |
|
|
|
692 |
|
|
int64 r0 = address [newline]
|
693 |
|
|
call _puts
|
694 |
|
|
|
695 |
|
|
breakpoint
|
696 |
|
|
|
697 |
|
|
int r0 = 0 // program return value
|
698 |
|
|
return // return from main
|
699 |
|
|
|
700 |
|
|
_main end
|
701 |
|
|
|
702 |
|
|
|
703 |
|
|
print_result function
|
704 |
|
|
// Print the result of a single test. Parameters:
|
705 |
|
|
// r0: 4 bits indicating success for for int8, int16, int32, int64. 4 additional bits for printing space (instruction not supported)
|
706 |
|
|
// r1: pointer to text string
|
707 |
|
|
|
708 |
|
|
// set up parameter list for printf
|
709 |
|
|
int64 sp -= 5*8 // allocate space on stack
|
710 |
|
|
int64 [sp] = r1 // text
|
711 |
|
|
int r4 = 'N'
|
712 |
|
|
int r2 = r0 ? 'Y' : r4 // Y or N
|
713 |
|
|
int r5 = test_bit(r0, 4)
|
714 |
|
|
int r2 = r5 ? ' ' : r2 // Y/N or space
|
715 |
|
|
int64 [sp+0x08] = r2 // result for int8
|
716 |
|
|
int r0 >>= 1
|
717 |
|
|
int r2 = r0 ? 'Y' : r4 // Y or N
|
718 |
|
|
int r5 = test_bit(r0, 4)
|
719 |
|
|
int r2 = r5 ? ' ' : r2 // Y/N or space
|
720 |
|
|
int64 [sp+0x10] = r2 // result for int16
|
721 |
|
|
int r0 >>= 1
|
722 |
|
|
int r2 = r0 ? 'Y' : r4 // Y or N
|
723 |
|
|
int r5 = test_bit(r0, 4)
|
724 |
|
|
int r2 = r5 ? ' ' : r2 // Y/N or space
|
725 |
|
|
int64 [sp+0x18] = r2 // result for int32
|
726 |
|
|
int r0 >>= 1
|
727 |
|
|
int r2 = r0 ? 'Y' : r4 // Y or N
|
728 |
|
|
int r5 = test_bit(r0, 4)
|
729 |
|
|
int r2 = r5 ? ' ' : r2 // Y/N or space
|
730 |
|
|
int64 [sp+0x20] = r2 // result for int64
|
731 |
|
|
|
732 |
|
|
int64 r0 = address [format1]
|
733 |
|
|
int64 r1 = sp
|
734 |
|
|
call _printf
|
735 |
|
|
int64 sp += 5*8 // release parameter list
|
736 |
|
|
return
|
737 |
|
|
|
738 |
|
|
print_result end
|
739 |
|
|
|
740 |
|
|
code end
|