OpenCores
URL https://opencores.org/ocsvn/forwardcom/forwardcom/trunk

Subversion Repositories forwardcom

[/] [forwardcom/] [testsuite/] [tests_bool_bit.as] - Blame information for rev 167

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 161 Agner
/**************************  tests_bool_bit.as  *******************************
2
* Author:        Agner Fog
3
* date created:  2021-06-27
4
* last modified: 2021-07-20
5
* Version:       1.11
6
* Project:       ForwardCom Test suite, assembly code
7
* Description:   Test boolean and bit manipulation instructions with general
8
*                purpose registers
9
*
10
* This test program will test boolean and bit manipulation instructions and
11
* output a list of which instructions are working for int8, int16, int32,
12
* and int64 operands.
13
*
14
* Copyright 2021 GNU General Public License v. 3 http://www.gnu.org/licenses
15
******************************************************************************/
16
 
17
// Library functions in libc_light.li
18
extern _puts:     function reguse=3,0            // write string + linefeed to stdout
19
extern _printf:   function reguse=0xF,0          // write formatted string to stdout
20
 
21
const section read ip                            // read-only data section
22
// Text strings:
23
 
24
text1: int8 "\nForwardCom test suite\nTest general purpose register bit manipulation instructions"  // intro text,
25
       int8 "\nPress Run to continue"
26
       int8 "\n                      int8   int16  int32  int64", 0                                 // and heading
27
newline: int8 "\n", 0                                                                               // newline
28
press_run: int8 "\nPress Run to continue", 0
29
 
30
format1: int8 "\n%-22s%3c%7c%7c%7c", 0           // format string for printing results
31
 
32
// text strings for each instruction:
33
text_and: int8 "and", 0
34
text_or:  int8 "or", 0
35
text_xor: int8 "xor", 0
36
 
37
text_shift_left: int8 "shift left", 0
38
text_shift_right_signed: int8 "shift right signed", 0
39
text_shift_right_unsigned: int8 "shift right unsigned", 0
40
text_funnel_shift: int8 "funnel shift", 0
41
text_rotate: int8 "rotate", 0
42
 
43
text_clear_bit: int8 "clear_bit", 0
44
text_set_bit: int8 "set_bit", 0
45
text_toggle_bit: int8 "toggle_bit", 0
46
 
47
text_test_bit: int8 "test_bit", 0
48
text_test_bits_and: int8 "test_bits_and", 0
49
text_test_bits_or: int8 "test_bits_or", 0
50
text_compare: int8 "compare", 0
51
 
52
text_bitscan: int8 "bitscan", 0
53
text_roundp2: int8 "roundp2", 0
54
text_popcount: int8 "popcount", 0
55
text_truthtab3: int8 "truth_tab3", 0
56
 
57
text_move_high: int8 "move high", 0
58
text_insert_high: int8 "insert high", 0
59
text_move_bits: int8 "move_bits", 0
60
 
61
const end
62
 
63
 
64
code section execute                             // code section
65
 
66
__entry_point function public
67
_main function public
68
 
69
/* register use:
70
r0:  bits indicating success for int8, int16, int32, int64
71
r1:  operand
72
r2:  operand
73
r3:  result
74
r4:  scratch
75
r6:  int64 supported
76
*/
77
 
78
// print intro text and heading
79
int64  r0 = address [text1]                      // calculate address of string
80
call   _puts                                     // call puts. parameter is in r0
81
 
82
breakpoint                                       // debug breakpoint
83
 
84
int    r1 = 1
85
int    capab2 = write_capabilities(r1, 0)        // disable error trap for unknown instructions
86
 
87
// arbitrary test data
88
% A = 0x12345555
89
% B = 0x5678CEFC
90
% C = 0xABCDF0F0
91
 
92
 
93
// Test and
94
 
95
int32  r1 = A
96
int32  r2 = B
97
 
98
int8   r3 = r1 & r2                              // int8 and
99
int32  r0 = r3 == (A & B & 0xFF)                 // check result, set bit 0 if success
100
 
101
int16  r3 = r1 & r2                              // int16 and
102
int32  r4 = r3 == (A & B & 0xFFFF)               // check result
103
int32  r0 |= 2, mask = r4                        // set bit 1 if success
104
 
105
int32  r3 = r1 & r2                              // int32 and
106
int32  r4 = r3 == (A & B)                         // check result
107
int32  r0 |= 4, mask = r4                        // set bit 2 if success
108
 
109
int64  r1 <<= 32
110
int64  r2 <<= 32
111
int64  r1 |= 0x12345
112
int64  r2 |= C
113
 
114
int64  r3 = r1 & r2                              // 64 bit and
115
int32  r4 = r3 == (0x12345 & C)                  // check lower half of result
116
uint64 r3 >>= 32                                 // shift down upper half
117
int64  r6 = r3 == (A & B) && r4                  // check upper half of result
118
int32  r0 |= 8, mask = r6                        // set bit 2 if success
119
 
120
int64  r1 = address [text_and]
121
call   print_result
122
 
123
 
124
// Test or
125
 
126
int32  r1 = A
127
int32  r2 = B
128
 
129
int8   r3 = r1 | r2                              // int8 or
130
int32  r0 = r3 == ((A | B) & 0xFF)               // check result, set bit 0 if success
131
 
132
int16  r3 = r1 | r2                              // int16 or
133
int32  r4 = r3 == ((A | B) & 0xFFFF)             // check result
134
int32  r0 |= 2, mask = r4                        // set bit 1 if success
135
 
136
int32  r3 = r1 | r2                              // int32 or
137
int32  r4 = r3 == (A | B)                        // check result
138
int32  r0 |= 4, mask = r4                        // set bit 2 if success
139
 
140
int64  r1 <<= 32
141
int64  r2 <<= 32
142
int64  r1 |= 0x12345
143
int64  r2 |= C
144
 
145
int64  r3 = r1 | r2                              // 64 bit or
146
int32  r4 = r3 == (0x12345 | C)                  // check lower half of result
147
uint64 r3 >>= 32                                 // shift down upper half
148
int64  r6 = r3 == (A | B) && r4                  // check upper half of result
149
int32  r0 |= 8, mask = r6                        // set bit 2 if success
150
 
151
int64  r1 = address [text_or]
152
call   print_result
153
 
154
 
155
// Test xor
156
 
157
int32  r1 = A
158
int32  r2 = B
159
 
160
int8   r3 = r1 ^ r2                              // int8 xor
161
int32  r0 = r3 == ((A ^ B) & 0xFF)               // check result, set bit 0 if success
162
 
163
int16  r3 = r1 ^ r2                              // int16 xor
164
int32  r4 = r3 == ((A ^ B) & 0xFFFF)             // check result
165
int32  r0 |= 2, mask = r4                        // set bit 1 if success
166
 
167
int32  r3 = r1 ^ r2                              // int32 xor
168
int32  r4 = r3 == (A ^ B)                        // check result
169
int32  r0 |= 4, mask = r4                        // set bit 2 if success
170
 
171
int64  r1 <<= 32
172
int64  r2 <<= 32
173
int64  r1 |= 0x12345
174
int64  r2 |= C
175
 
176
int64  r3 = r1 ^ r2                              // 64 bit xor
177
int32  r4 = r3 == (0x12345 ^ C)                  // check lower half of result
178
uint64 r3 >>= 32                                 // shift down upper half
179
int64  r6 = r3 == (A ^ B) && r4                  // check upper half of result
180
int32  r0 |= 8, mask = r6                        // set bit 2 if success
181
 
182
int64  r1 = address [text_xor]
183
call   print_result
184
 
185
 
186
// Test shift left
187
 
188
int32  r1 = A
189
 
190
int8   r3 = r1 << 3                              // int8 shift
191
int32  r0 = r3 == (A << 3 & 0xFF)                // check result, set bit 0 if success
192
int8   r3 = r1 << 0                              // int8 shift
193
int    r0 = r3 == (A & 0xFF) && r0
194
 
195
int16  r3 = r1 << 12                             // int16 shift
196
int32  r4 = r3 == (A << 12 & 0xFFFF)             // check result, set bit 0 if success
197
int16  r3 = r1 << -1                             // int16 shift overflow
198
int    r4 = (r3 == 0) && r4
199
int32  r0 |= 2, mask = r4                        // set bit 1 if success
200
 
201
int    r2 = 18
202
int32  r3 = r1 << r2                             // int32 shift
203
int32  r4 = r3 == (A << 18 & 0xFFFFFFFF)         // check result, set bit 0 if success
204
int32  r3 = r1 << 1                              // int32 shift
205
int32  r4 = (r3 == (A << 1 & 0xFFFFFFFF)) && r4
206
int32  r0 |= 4, mask = r4                        // set bit 2 if success
207
 
208
int64  r3 = r1 << 36                             // int64 shift
209
int64  r4 = A << 36
210
int64  r4 = r3 == r4
211
uint64 r3 >>= 36
212
int32  r4 = r3 == (A & 0x0FFFFFFF) && r4
213
int32  r0 |= 8, mask = r4                        // set bit 3 if success
214
 
215
int64  r1 = address [text_shift_left]
216
call   print_result
217
 
218
 
219
// Test shift right signed
220
 
221
shiftrightsigned:
222
int32  r1 = A
223
 
224
%A1 = 0xA3
225
int8   r3 = r1 >> 3                              // int8 shift
226
int32  r0 = r3 == (A & 0xFF) >> 3                // check result, set bit 0 if success
227
int8   r3 = r1 >> 0                              // int8 shift
228
int    r0 = r3 == (A & 0xFF) && r0
229
int    r2 = A1                                   // negative number
230
int8   r3 = r2 >> 3                              // int8 shift
231
int32  r0 = r3 == (A1 >> 3 | 0xE0) && r0         // check result, set bit 0 if success
232
 
233
%A2 = 0xBC62
234
int16  r3 = r1 >> 9                              // int16 shift
235
int32  r4 = r3 == (A & 0xFFFF) >> 9              // check result, set bit 0 if success
236
int16  r3 = r1 >> 70                             // int16 shift overflow
237
int    r4 = (r3 == 0) && r4
238
int    r2 = A2
239
int16  r3 = r2 >> 3
240
int32  r4 = r3 == (A2 >> 3 | 0xE000) && r4       // check result, set bit 0 if success
241
int32  r0 |= 2, mask = r4                        // set bit 1 if success
242
 
243
%A3 = 0x81ABCD25
244
int32  r1 = A3
245
int    r2 = 18
246
int32  r3 = r1 >> r2                             // int32 shift
247
uint32 r4 = r3 == (A3 >> 18 & 0xFFFFFFFF | 0xFFFFC000)   // check result, set bit 0 if success
248
int32  r3 = r1 >> 33                             // overflow of signed shift
249
int32  r4 = (r3 == -1) && r4
250
int32  r0 |= 4, mask = r4                        // set bit 2 if success
251
 
252
%A4 = 0x81ABCD2512345678
253
int64  r1 = A4
254
int64  r3 = r1 >> 35                             // int64 shift
255
int64  r4 = A4 >> 35
256
int64  r4 = r3 == r4
257
int32  r0 |= 8, mask = r4                        // set bit 3 if success
258
 
259
int64  r1 = address [text_shift_right_signed]
260
call   print_result
261
 
262
 
263
// Test shift right unsigned
264
 
265
int32  r1 = A
266
 
267
%A1 = 0xA3
268
uint8  r3 = r1 >> 3                              // int8 shift
269
int32  r0 = r3 == (A & 0xFF) >> 3                // check result, set bit 0 if success
270
uint8  r3 = r1 >> 0                              // int8 shift
271
int    r0 = r3 == (A & 0xFF) && r0
272
int    r2 = A1                                   // negative number
273
uint8  r3 = r2 >> 3                              // int8 shift
274
int32  r0 = r3 == A1 >> 3 && r0                  // check result, set bit 0 if success
275
 
276
%A2 = 0xBC62
277
uint16 r3 = r1 >> 9                              // int16 shift
278
int32  r4 = r3 == (A & 0xFFFF) >> 9              // check result, set bit 0 if success
279
uint16 r3 = r1 >> 70                             // int16 shift overflow
280
int    r4 = (r3 == 0) && r4
281
int    r2 = A2
282
uint16 r3 = r2 >> 3
283
int32  r4 = r3 == A2 >> 3 && r4                  // check result, set bit 0 if success
284
int32  r0 |= 2, mask = r4                        // set bit 1 if success
285
 
286
%A3 = 0x81ABCD25
287
int32  r1 = A3
288
int    r2 = 18
289
uint32 r3 = r1 >> r2                             // int32 shift
290
uint32 r4 = r3 == (A3 >> 18 & 0xFFFFFFFF)        // check result, set bit 0 if success
291
uint32 r3 = r1 >> 33                             // overflow of unsigned shift
292
int32  r4 = (r3 == 0) && r4
293
int32  r0 |= 4, mask = r4                        // set bit 2 if success
294
 
295
%A4 = 0x81ABCD2512345678
296
int64  r1 = A4
297
uint64 r3 = r1 >> 35                             // int64 shift
298
int64  r4 = A4 >>> 35
299
int64  r4 = r3 == r4
300
int32  r0 |= 8, mask = r4                        // set bit 3 if success
301
 
302
int64  r1 = address [text_shift_right_unsigned]
303
call   print_result
304
 
305
 
306
// Test funnel shift
307
int    r1 = A
308
int    r2 = B
309
 
310
int8   r3 = funnel_shift(r1, r2, 5)              // int8 shift
311
int    r0 = r3 == ((A & 0xFF) >> 5 | (B << 3 & 0xFF)) // check result, set bit 0 if success
312
int8   r3 = funnel_shift(r1, r2, 0)              // int8 shift
313
int    r0 = r3 == (A & 0xFF) && r0
314
int8   r3 = funnel_shift(r1, r2, 8)              // int8 shift
315
int    r0 = r3 == 0 && r0
316
 
317
int16  r3 = funnel_shift(r1, r2, 10)             // int16 shift
318
int    r4 = r3 == ((A & 0xFFFF) >> 10 | (B << 6 & 0xFFFF)) // check result, set bit 0 if success
319
int32  r0 |= 2, mask = r4                        // set bit 1 if success
320
 
321
int32  r3 = funnel_shift(r1, r2, 21)             // int32 shift
322
int64  r4 = r3 == ((A & 0xFFFFFFFF) >> 21 | (B << 11 & 0xFFFFFFFF)) // check result, set bit 0 if success
323
int32  r0 |= 4, mask = r4                        // set bit 2 if success
324
 
325
int64  r3 = funnel_shift(r1, r2, 50)             // int64 shift
326
int64  r4 = r3 == (A >> 50 | B << 14)            // check result, set bit 0 if success
327
int32  r0 |= 8, mask = r4                        // set bit 3 if success
328
 
329
int64  r1 = address [text_funnel_shift]
330
call   print_result
331
 
332
 
333
// Test rotate
334
int    r1 = B
335
int8   r3 = rotate(r1, 2)                        // int8 rotate
336
int    r0 = r3 == ((B << 2 & 0xFF) | (B & 0xFF) >> 6)
337
int8   r3 = rotate(r1, 0)                        // int8 rotate
338
int    r0 = r3 == (B & 0xFF) && r0
339
int    r2 = 0x1234
340
int8   r3 = rotate(r1, r2)                       // int8 rotate
341
int    r0 = r3 == ((B << 4 & 0xFF) | (B & 0xFF) >> 4) && r0
342
 
343
int16  r3 = rotate(r1, 0xabcd)                   // int16 rotate
344
int    r4 = r3 == ((B << 13 & 0xFFFF) | (B & 0xFFFF) >> 3)
345
int32  r0 |= 2, mask = r4                        // set bit 1 if success
346
 
347
int32  r3 = rotate(r1, -21)                      // int32 rotate
348
int64  r4 = r3 == ((B << 11 & 0xFFFFFFFF) | (B & 0xFFFFFFFF) >> 21)
349
int32  r0 |= 4, mask = r4                        // set bit 2 if success
350
 
351
int64  r3 = rotate(r1, 34)                       // int64 rotate
352
int64  r4 = r3 == ((B << 34) | (B >> 30))
353
int32  r0 |= 8, mask = r4                        // set bit 3 if success
354
 
355
int64  r1 = address [text_rotate]
356
call   print_result
357
 
358
 
359
// Test clear bit
360
int64  r1 = -1
361
int8   r3 = clear_bit(r1, 2)                     // int8 clear_bit
362
int    r0 = r3 == 0xFB
363
 
364
int16  r3 = clear_bit(r1, 8)                     // int16 clear_bit
365
int    r4 = r3 == 0xFEFF
366
int32  r0 |= 2, mask = r4                        // set bit 1 if success
367
 
368
int32  r3 = r1 & ~ (1 << 30)
369
int32  r3 = clear_bit(r3, 31)                    // int32 clear_bit
370
int32  r4 = r3 == 0x3FFFFFFF
371
int32  r0 |= 4, mask = r4                        // set bit 2 if success
372
 
373
int64  r3 = clear_bit(r1, 41)                    // int64 clear_bit
374
int64  r3 = clear_bit(r3, 41)                    // int64 clear_bit
375
uint64 r3 >>= 32
376
int32  r4 = r3 == 0xFFFFFDFF
377
int32  r0 |= 8, mask = r4                        // set bit 3 if success
378
 
379
int64  r1 = address [text_clear_bit]
380
call   print_result
381
 
382
 
383
// Test set bit
384
int64  r1 = 0
385
int8   r3 = set_bit(r1, 2)                     // int8 set_bit
386
int    r0 = r3 == 4
387
 
388
int16  r3 = set_bit(r1, 8)                     // int16 set_bit
389
int    r4 = r3 == 0x100
390
int32  r0 |= 2, mask = r4                      // set bit 1 if success
391
 
392
int32  r3 = set_bit(r1, 31)                    // int32 set_bit
393
int32  r3 = set_bit(r3, 31)                    // int32 set_bit
394
int32  r4 = r3 == 0x80000000
395
int32  r0 |= 4, mask = r4                      // set bit 2 if success
396
 
397
int64  r3 = set_bit(r1, 41)                    // int64 set_bit
398
uint64 r3 >>= 32
399
int32  r4 = r3 == 0x200
400
int32  r0 |= 8, mask = r4                      // set bit 3 if success
401
 
402
int64  r1 = address [text_set_bit]
403
call   print_result
404
 
405
 
406
// Test toggle bit
407
int64  r1 = 0
408
int8   r3 = toggle_bit(r1, 2)                  // int8 toggle_bit
409
int    r0 = r3 == 4
410
 
411
int16  r3 = toggle_bit(r1, 8)                  // int16 toggle_bit
412
int    r4 = r3 == 0x100
413
int32  r0 |= 2, mask = r4                      // set bit 1 if success
414
 
415
int32  r3 = toggle_bit(r1, 31)                 // int32 toggle_bit
416
int32  r3 = toggle_bit(r3, 31)                 // int32 toggle_bit
417
int32  r4 = r3 == 0
418
int32  r0 |= 4, mask = r4                      // set bit 2 if success
419
 
420
int64  r3 = toggle_bit(r1, 41)                 // int64 toggle_bit
421
uint64 r3 >>= 32
422
int32  r4 = r3 == 0x200
423
int32  r0 |= 8, mask = r4                      // set bit 3 if success
424
 
425
int64  r1 = address [text_toggle_bit]
426
call   print_result
427
 
428
 
429
int64  r0 = address [press_run]                  // press run to continue
430
call   _printf                                   // print string
431
 
432
breakpoint
433
 
434
 
435
// Test test_bit
436
Test_test_bit:
437
int32  r1 = 0x12345678
438
int8   r3 = test_bit(r1, 4)                      // int8 test_bit
439
int    r0 = r3 == 1
440
int8   r2 = test_bit(r1, 2)
441
int    r0 = r2 == 0 && r0
442
 
443
int16  r3 = test_bit(r1, 9)                      // int16 test_bit
444
int    r4 = r3 == 1
445
int16  r3 = test_bit(r1, 9), fallback = r2, options = 1
446
int    r4 = r3 == 0 && r4
447
int16  r3 = test_bit(r1, 9), fallback = r2, options = 9
448
int    r4 = r3 == 1 && r4
449
int    r0 |= 2, mask = r4                        // set bit 1 if success
450
 
451
int32  r3 = test_bit(r1, 17)                     // int32 test_bit
452
int    r4 = r3 == 0
453
int32  r2 = 0xF0
454
int32  r3 = test_bit(r1, 18), mask = r2, options = 0x20
455
int    r4 = r3 == r2 && r4
456
int    r0 |= 4, mask = r4                        // set bit 2 if success
457
 
458
int64  r1 <<= 32
459
int64  r3 = test_bit(r1, 38)                     // int64 test_bit
460
int    r4 = r3 == 1
461
int32  r2 = 0x71
462
int32  r3 = test_bit(r1, 75), mask = r2, fallback = r2, options = 0x20
463
int    r4 = r3 == 0x70 && r4
464
int32  r3 = test_bit(r1, 75), mask = r2, fallback = r2, options = 0x24
465
int    r4 = r3 == 0x71 && r4
466
int    r0 |= 8, mask = r4                        // set bit 3 if success
467
 
468
int64  r1 = address [text_test_bit]
469
call   print_result
470
 
471
 
472
// Test test_bits_and
473
Test_test_bits_and:
474
int32  r1 = 0x12345678
475
int8   r3 = test_bits_and(r1, 0x58)              // int8 test_bits_and
476
int    r0 = r3 == 1
477
 
478
int16  r2 = test_bits_and(r1, 0x688)             // int16 test_bits_and
479
int    r4 = r2 == 0
480
int16  r3 = test_bits_and(r1, 0x688), fallback = r4, options = 2
481
int    r4 = r3 == 1 && r4
482
int16  r3 = test_bits_and(r1, 0x688), fallback = r4, options = 7
483
int    r4 = r3 == 0 && r4
484
int    r0 |= 2, mask = r4                        // set bit 1 if success
485
 
486
int32  r3 = test_bits_and(r1, 0x12340678)        // int32 test_bits_and
487
int    r4 = r3 == 1
488
int32  r3 = test_bits_and(r1, 0x12346678)
489
int    r4 = r3 == 0 && r4
490
int    r0 |= 4, mask = r4                        // set bit 2 if success
491
 
492
int64  r1 <<= 32
493
int64  r3 = test_bits_and(r1, 0x67 << 36)        // int64 test_bits_and
494
int    r4 = r3 == 1
495
int64  r3 = test_bits_and(r1, 0x6F << 36)
496
int    r4 = r3 == 0 && r4
497
int    r0 |= 8, mask = r4                        // set bit 3 if success
498
 
499
int64  r1 = address [text_test_bits_and]
500
call   print_result
501
 
502
 
503
// Test test_bits_or
504
Test_test_bits_or:
505
int32  r1 = 0x12345678
506
int8   r3 = test_bits_or(r1, 0xF0)               // int8 test_bits_or
507
int    r0 = r3 == 1
508
 
509
int16  r2 = test_bits_or(r1, 0x982)              // int16 test_bits_or
510
int    r4 = r2 == 0
511
 
512
int16  r3 = test_bits_or(r1, 0x982), fallback = r4, options = 3
513
int    r4 = r3 == 1 && r4
514
int16  r3 = test_bits_or(r1, 0x688), fallback = r4, options = 3
515
int    r4 = r3 == 0 && r4
516
int    r0 |= 2, mask = r4                        // set bit 1 if success
517
 
518
int32  r3 = test_bits_or(r1, 0x10000000)         // int32 test_bits_or
519
int    r4 = r3 == 1
520
int32  r3 = test_bits_or(r1, 0)
521
int    r4 = r3 == 0 && r4
522
int    r0 |= 4, mask = r4                        // set bit 2 if success
523
 
524
int64  r1 <<= 32
525
int64  r3 = test_bits_or(r1, 0xF << 36)          // int64 test_bits_or
526
int    r4 = r3 == 1
527
int    r0 |= 8, mask = r4                        // set bit 3 if success
528
 
529
int64  r1 = address [text_test_bits_or]
530
call   print_result
531
 
532
 
533
// test compare with mask and fallback
534
test_compare:
535
int32  r1 = 5
536
int32  r2 = 0x56
537
int8   r3 = compare(r1, r2), options=0, mask = r1// int8 compare
538
int    r0 = r3 == 4
539
 
540
int16  r3 = compare(r1, r2), options=2, mask = r1, fallback = r1 // int16 compare
541
int    r4 = r3 == r1
542
int16  r3 = compare(r1, r2), options=0x12, mask = r2, fallback = r1
543
int    r4 = r3 == r2 && r4
544
int16  r3 = compare(r1, r2), options=0x20, mask = r1, fallback = r1
545
int    r4 = r3 == r1 && r4
546
int    r0 |= 2, mask = r4                        // set bit 1 if success
547
 
548
int32  r3 = compare(r1, r2), options=0x31, fallback = r1 // int32 compare
549
int    r4 = r3 == 0
550
int    r0 |= 4, mask = r4                        // set bit 2 if success
551
 
552
int64  r3 = compare(r1, r2), options=0x21, fallback = r1 // int64 compare
553
int    r4 = r3 == 1
554
int64  r2 = r1 | 1 << 60
555
int64  r3 = r1 == r2
556
int    r4 = r3 == 0 && r4
557
int    r0 |= 8, mask = r4                        // set bit 3 if success
558
 
559
int64  r1 = address [text_compare]
560
call   print_result
561
 
562
 
563
// test bitscan
564
int    r1 = 0x23412345
565
int8   r3 = bitscan(r1, 0)                       // int8 bitscan
566
int    r0 = r3 == 0
567
int8   r3 = bitscan(r1, 1)
568
int    r0 = r3 == 6 && r0
569
 
570
int    r2 = 0
571
int16  r3 = bitscan(r1, 1)                       // int16 bitscan
572
int    r4 = r3 == 13
573
int16  r3 = bitscan(r2, 1)                       // zero input
574
int    r4 = r3 == 0 && r4
575
int16  r3 = bitscan(r2, 0x11)
576
int    r4 = r3 == 0xFFFF && r4
577
int    r0 |= 2, mask = r4                        // set bit 1 if success
578
 
579
int32  r3 = bitscan(r1, 1)                       // int32 bitscan
580
int    r4 = r3 == 29
581
int    r0 |= 4, mask = r4                        // set bit 2 if success
582
 
583
int64  r1 <<= 10
584
int64  r3 = bitscan(r1, 1)                       // int64 bitscan
585
int    r4 = r3 == 29 + 10
586
int64  r3 = bitscan(r2, 0x10)                    // zero input
587
int64  r4 = r3 == -1 && r4
588
int    r0 |= 8, mask = r4                        // set bit 3 if success
589
 
590
int64  r1 = address [text_bitscan]
591
call   print_result
592
 
593
 
594
// test roundp2
595
int    r1 = 0x23412345
596
int8   r3 = roundp2(r1, 0)                       // int8 roundp2
597
int    r0 = r3 == 0x40
598
int8   r3 = roundp2(r1, 1)
599
int    r0 = r3 == 0x80
600
 
601
int16  r3 = roundp2(r1, 0)                       // int16 roundp2
602
int    r4 = r3 == 0x2000
603
int    r2 = 0
604
int16  r3 = roundp2(r2, 0)                       // zero input
605
int    r4 = r3 == 0 && r4
606
int16  r3 = roundp2(r2, 0x10)                    // zero input
607
int    r4 = r3 == 0xFFFF && r4
608
int    r2 = 0x8001
609
int16  r3 = roundp2(r2, 0)
610
int    r4 = r3 == 0x8000 && r4
611
int16  r3 = roundp2(r2, 1)                       // overflow
612
int    r4 = r3 == 0 && r4
613
int16  r3 = roundp2(r2, 0x21)
614
int    r4 = r3 == 0xFFFF && r4
615
int    r0 |= 2, mask = r4                        // set bit 1 if success
616
 
617
int32  r3 = roundp2(r1, 0)                       // int32 roundp2
618
int32  r4 = r3 == 0x20000000
619
int32  r3 = roundp2(r1, 1)
620
int32  r4 = r3 == 0x40000000 && r4
621
int    r0 |= 4, mask = r4                        // set bit 2 if success
622
 
623
int64  r1 |= 1 << 40
624
int64  r3 = roundp2(r1, 0)                       // int64 roundp2
625
int64  r4 = r3 == 1 << 40
626
int64  r3 = roundp2(r1, 1)
627
int64  r4 = r3 == 1 << 41
628
int    r0 |= 8, mask = r4                        // set bit 3 if success
629
 
630
int64  r1 = address [text_roundp2]
631
call   print_result
632
 
633
 
634
// Test popcount
635
int    r1 = 0x23412345
636
int8   r3 = popcount(r1)                         // int8 popcount
637
int    r0 = r3 == 3
638
 
639
int16  r3 = popcount(r1)                         // int16 popcount
640
int    r4 = r3 == 6
641
int    r0 |= 2, mask = r4                        // set bit 1 if success
642
 
643
int64  r1 |= 1 << 40
644
int32  r3 = popcount(r1)                         // int32 popcount
645
int    r4 = r3 == 11
646
int    r0 |= 4, mask = r4                        // set bit 2 if success
647
 
648
int64  r3 = popcount(r1)                         // int64 popcount
649
int    r4 = r3 == 12
650
int    r0 |= 8, mask = r4                        // set bit 3 if success
651
 
652
int64  r1 = address [text_popcount]
653
call   print_result
654
 
655
 
656
// Test truth_tab3
657
int32  r1 = 0xAAAAAAAA
658
int32  r2 = 0xCCCCCCCC
659
int32  r3 = 0xF0F0F0F0
660
int8   r4 = truth_tab3(r1, r2, r3, 0xF2)         // A & ~ B | C
661
int    r0 = r4 == 0xF2
662
 
663
int16  r4 = truth_tab3(r1, r2, r3, 0xD8)         // A ? B : C
664
int    r5 = r4 == 0xD8D8
665
int    r6 = 0x12345
666
int16  r4 = truth_tab3(r1, r2, r3, 0xD8), options = 1, mask = r6
667
int    r5 = r4 == 0 && r5
668
int16  r4 = truth_tab3(r1, r2, r3, 0xD8), options = 2, mask = r6
669
int    r5 = r4 == 0x2344 && r5
670
int    r0 |= 2, mask = r5                        // set bit 1 if success
671
 
672
int32  r4 = truth_tab3(r1, r2, r3, 0x72)         // A ? ~B : C
673
int32  r5 = r4 == 0x72727272
674
int    r0 |= 4, mask = r5                        // set bit 2 if success
675
 
676
int64  r3 |= 1 << 63
677
int64  r4 = truth_tab3(r1, r2, r3, 0xFE)         // A | B | C
678
int64  r5 = r4 == 0x80000000FEFEFEFE
679
int64  r5 = test_bit(r4, 63), options = 1, fallback = r5
680
int    r0 |= 8, mask = r5                        // set bit 3 if success
681
 
682
 
683
int64  r1 = address [text_truthtab3]
684
call   print_result
685
 
686
 
687
// Test move_bits
688
int32  r1 = 0
689
int32  r2 = 0x12345678
690
int8   r3 = move_bits(r1, r2, 2, 4, 3)           // int8 move_bits
691
int    r0 = r3 == 0x60
692
 
693
int16  r3 = move_bits(r1, r2, 8, 0, 6)           // int16 move_bits
694
int    r4 = r3 == 0x16
695
int    r0 |= 2, mask = r4                        // set bit 1 if success
696
 
697
int32  r3 = move_bits(r1, r2, 0, 20, 12)         // int32 move_bits
698
int32  r3 = move_bits(r3, r2, 16, 0, 8)
699
int    r4 = r3 == 0x67800034
700
int    r0 |= 4, mask = r4                        // set bit 1 if success
701
 
702
int64  r3 = move_bits(r1, r2, 20, 48, 8)         // int64 move_bits
703
int64  r4 = r3 == 0x23000000000000
704
int64  r3 = move_bits(r1, r3, 48, 0, 8)
705
int64  r4 = r3 == 0x23 && r4
706
int    r0 |= 8, mask = r4                        // set bit 3 if success
707
 
708
int64  r1 = address [text_move_bits]
709
call   print_result
710
 
711
 
712
// Test move high
713
int64  r1 = 0xabcd1234 << 32
714
int32  r4 = r1 == 0
715
uint64 r1 >>= 32
716
int32  r4 = r1 == 0xabcd1234 && r0
717
int    r0 = 0x70
718
int    r0 |= 8, mask = r4
719
int64  r1 = address [text_move_high]
720
call   print_result
721
 
722
 
723
// Test insert high
724
int64  r1 = 0x12345678
725
int64  r1 = insert_hi(r1, 0xabcdef98)
726
int64  r4 = r1 == 0xabcdef9812345678
727
int64  r1 >>= 32
728
int32  r4 = (r1 == 0xabcdef98) && r4
729
int    r0 = 0x70
730
int    r0 |= 8, mask = r4
731
int64  r1 = address [text_insert_high]
732
call   print_result
733
 
734
 
735
int64 r0 = address [newline]
736
call _puts
737
 
738
breakpoint
739
 
740
int r0 = 0                                       // program return value
741
return                                           // return from main
742
 
743
_main end
744
 
745
 
746
print_result function
747
// Print the result of a single test. Parameters:
748
// r0:  4 bits indicating success for for int8, int16, int32, int64. 4 additional bits for printing space (instruction not supported)
749
// r1:  pointer to text string
750
 
751
// set up parameter list for printf
752
int64 sp -= 5*8              // allocate space on stack
753
int64 [sp] = r1              // text
754
int r4 = 'N'
755
int r2 = r0 ? 'Y' : r4       // Y or N
756
int r5 = test_bit(r0, 4)
757
int r2 = r5 ? ' ' : r2       // Y/N or space
758
int64 [sp+0x08] = r2         // result for int8
759
int r0 >>= 1
760
int r2 = r0 ? 'Y' : r4       // Y or N
761
int r5 = test_bit(r0, 4)
762
int r2 = r5 ? ' ' : r2       // Y/N or space
763
int64 [sp+0x10] = r2         // result for int16
764
int r0 >>= 1
765
int r2 = r0 ? 'Y' : r4       // Y or N
766
int r5 = test_bit(r0, 4)
767
int r2 = r5 ? ' ' : r2       // Y/N or space
768
int64 [sp+0x18] = r2         // result for int32
769
int r0 >>= 1
770
int r2 = r0 ? 'Y' : r4       // Y or N
771
int r5 = test_bit(r0, 4)
772
int r2 = r5 ? ' ' : r2       // Y/N or space
773
int64 [sp+0x20] = r2         // result for int64
774
 
775
int64 r0 = address [format1]
776
int64 r1 = sp
777
call _printf
778
int64 sp += 5*8              // release parameter list
779
return
780
 
781
print_result end
782
 
783
 
784
code end

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.