summaryrefslogtreecommitdiff
path: root/third_party/gsm/add-test/add_test.dta
blob: fe7402d39f866c5a33cebca3a75ffc2e2572c917 (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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
;
; Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
; Universitaet Berlin.  See the accompanying file "COPYRIGHT" for
; details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
;
;
;	Lines starting with ' (in the first col) are echoed.
;	Lines starting with " (in the first col) are echoed to stderr.
;	Lines starting with ; or empty lines are ignored.
;
;	The part after (including) a trailing '=' is what you expect;
;	there will be output if the result is different.
;
;	-  and +  by itself mean MIN_WORD and MAX_WORD, respectively;
;	-- and ++ mean MIN_LONGWORD and MAX_LONGWORD.
;

'test the basic arithmetic operations used for the rpe-ltd filtering.
'
'add ================
'  basic

	add  0  0 	=  0
	add  7  4	= 11
	add  4  6 	= 10
	add  1  1 	=  2

'  negative operands

	add  -7  4	= -3
	add   4 -6 	= -2
	add  -1 -3 	= -4
	add   7 -4	=  3
	add  -4  6 	=  2

'  positive overflow
; (max-word = 32767)
	add  + 1	= +
	add  + +	= +
	add  -1 + 	= 32766
	add  32766 2	= +
	add  1 32766  	= +

'  underflow
; (min-word = 32768)

	add  - -1	= -
	add  - -	= -
	add  1 -	= -32767  
	add  -32767 -2	= -
	add  -1 -32766 	= -32767
	add  -32767 -1	= -
	add  - +	= -1
	add  + -	= -1
	add  0 -	= -
	add  0 +	= +
'

'L_add ================
'  basic 

	L_add  0  0 	=  0
	L_add  7  4	= 11
	L_add  4  6 	= 10
	L_add  1  1 	=  2

'  negative operands

	L_add  -7  4	= -3
	L_add   4 -6 	= -2
	L_add  -1 -3 	= -4
	L_add   7 -4	=  3
	L_add  -4  6 	=  2
	L_add   0 -1 	= -1

'  positive overflow
; (max-longword = 2147483647)
	L_add  ++ 1	= ++
	L_add  ++ ++	= ++
	L_add  -1 ++ 	= 2147483646
	L_add  2147483646 2 = ++
	L_add  1 2147483645 = 2147483646

'  underflow
; (min-longword = -2147483648)

	L_add  -- -1	= --
	L_add  -- --	= --
	L_add  1 --	= -2147483647
	L_add  -2147483647 -2	= --
	L_add  -1 -2147483646 	= -2147483647
	L_add  -2147483647 -1	= --
	L_add  -- ++	= -1
	L_add  ++ --	= -1
	L_add  0 --	= --
	L_add  0 ++	= ++
'

'sub ================
'  basic 

	sub  0  0 	=  0
	sub  7  4	=  3
	sub  4  6 	= -2
	sub  1  0 	=  1

'  negative operands

	sub  -7  4	= -11
	sub   4 -6 	=  10
	sub  -1 -3 	=  2
	sub   7 -4	=  11
	sub  -4  6 	= -10

'  positive overflow
; (max-word = 32767)
	sub  1 -	= +
	sub  + +	= 0
	sub  + 0	= +
	sub  + -1 	= +
	sub  + 1 	= 32766
	sub  1 + 	= -32766 
	sub  0 +  	= -32767

'  underflow
; (min-word = 32768)

	sub  - -1	= -32767
	sub  - 1	= -
	sub  - -	= 0
	sub  - +	= -
	sub  + -	= +
	sub  1 -	= +
	sub  -1 -	= +
	sub  -32767 2	= -
	sub  0 -	= +
' 

'L_sub ================
'  basic 

	L_sub  0  0 	=  0
	L_sub  7  4	=  3
	L_sub  4  6 	= -2
	L_sub  1  0 	=  1

'  negative operands

	L_sub  -7  4	= -11
	L_sub   4 -6 	=  10
	L_sub  -1 -3 	=  2
	L_sub   7 -4	=  11
	L_sub  -4  6 	= -10

'  positive overflow
	L_sub  1 --	= ++
	L_sub  ++ ++	= 0
	L_sub  ++ 0	= ++
	L_sub  ++ -1 	= ++
	L_sub  ++ 1 	=  2147483646
	L_sub  1 ++ 	= -2147483646
	L_sub  0 ++  	= -2147483647

'  underflow

	L_sub  -- -1	= -2147483647
	L_sub  -- 1	= --
	L_sub  -- --	= 0
	L_sub  -- ++	= --
	L_sub  + --	= ++
	L_sub  1 --	= ++
	L_sub  -1 --	= ++
	L_sub  -2147483647 2 = --
	L_sub  0 --	= ++

'
'abs ================
'  basic 

	abs	   0	=   0
	abs	   2	=   2
	abs	-459	= 459

'  overflow

	abs	 +	=   +
	abs	 -	=   +
	abs 	-32767  =   +
	abs 	 32766  = 32766
	abs 	-32766  = 32766

'
'mult ================
;  actually, a * b >> 15

'  basic 
	mult	0  0		= 0
	mult	0x100 0x100	= 2
	mult	4711 0x4000	= 2355

'  negative operands
	mult	-1  0		=  0

	mult	-0x100   0x100	= -2
	mult	 0x100  -0x100	= -2
	mult	-0x100  -0x100	=  2

	mult	-4711   0x4000	= -2356
	mult	 4711  -0x4000	= -2356
	mult	-4711  -0x4000	=  2355

'  overflow
	mult	+ + 	 = 32766
	mult	+ 0x4000 = 0x3fff
	mult	0x4000 + = 0x3fff
	mult	+ 1	 = 0
	mult	+ 2	 = 1
	mult	+ 3	 = 2

'  underflow
	mult	- - 	 = +
	mult	- + 	 = -32767
	mult	+ - 	 = -32767
	mult	- 1	 = -1
	mult	- 2	 = -2
	mult	- 3	 = -3

'
'mult_r ================
;  actually, (a * b + 16384) >> 15

'  basic 
	mult_r	0  0		= 0
	mult_r	0x100 0x100	= 2
	mult_r	4711 0x4000	= 2356

'  negative operands
	mult_r	-1  0		=  0

	mult_r	-0x100   0x100	= -2
	mult_r	 0x100  -0x100	= -2
	mult_r	-0x100  -0x100	=  2

	mult_r	-4711   0x4000	= -2355
	mult_r	 4711  -0x4000	= -2355
	mult_r	-4711  -0x4000	=  2356

'  overflow
	mult_r	+ + 	 = 32766
	mult_r	+ 32766	 = 32765
	mult_r	32766 +	 = 32765
	mult_r	+ 0x4000 = 0x4000
	mult_r	0x4000 + = 0x4000
	mult_r	+ 0x4001 = 0x4000
	mult_r	0x4001 + = 0x4000
	mult_r	+ 2	 = 2
	mult_r	+ 1	 = 1
	mult_r	1 +	 = 1
	mult_r	+ 0	 = 0
	mult_r	0 +	 = 0

'  underflow
	mult_r	- - 	 = +
	mult_r	- + 	 = -32767
	mult_r	+ - 	 = -32767
	mult_r	- 1	 = -1
	mult_r	- 2	 = -2
	mult_r	- 3	 = -3

'
'L_mult ================
;  actually, (a * b) << 1
;  assert (a != MIN_WORD && b != MIN_WORD)

'  basic 
	L_mult	0  0	= 0
	L_mult	2  3	= 12
	L_mult	4711 5	= 47110

'  negative operands

	L_mult	-2  3	= -12
	L_mult	 2 -3	= -12
	L_mult	-2 -3	=  12
	L_mult -4711  5	= -47110
	L_mult	4711 -5	= -47110
	L_mult -4711 -5	=  47110

'  overflow
	L_mult	+ + 	 = 2147352578
	L_mult	+ -32767 = -2147352578
	L_mult	-32767 + = -2147352578
	L_mult	+ 2	 = 131068
	L_mult	+ 1	 = 65534
	L_mult	1 +	 = 65534
	L_mult	+ 0	 = 0
	L_mult	0 +	 = 0

'
'div ================
;  actually, (32767 * a) / b
;  assert (a > 0 && b >= a)

'  basic 
	div	1 1		= +
	div	4711 4711 	= +
	div	5 10		= 0x4000
	div	5 20		= 0x2000
	div	5 40		= 0x1000

'  overflow
	div	+ + 		= +
	div	0x4000 +	= 0x4000
	div	1 +		= 1
	div	1 2		= 0x4000
'
'norm ================

'  positive
	norm	1		= 30
	norm	2		= 29
	norm	3		= 29
	norm	4		= 28
	norm	5		= 28
; etc, etc...
	norm	0x08000000	= 3
	norm	0x10000000	= 2
	norm	0x20000000	= 1
	norm	0x20000001	= 1
	norm	0x3fffffff	= 1
	norm	0x40000000	= 0
	norm	0x40000001	= 0
	norm	0x4ffffffe	= 0
	norm	++		= 0

'  negative
	norm	-1		= 31
	norm	-2		= 30
	norm	-3		= 29
	norm	-4		= 29
	norm	-5		= 28
; etc, etc...
	norm	0x4fffffff	= 0
	norm	--		= 0
'
'>> ================

'  basic 
	>>	1 1		= 0
	>>	4 2		= 1
	>>	0x1100 5	= 0x88

'  negative operand

	>>	1 -1		= 2
	>>	1 -2		= 4
	>>	0x88 -5		= 0x1100

'  overflow
	>>	-1 4711		= -1
	>>	1  4711		= 0
	>>	-4711 4711 	= -1
	>>	4711 4711 	= 0
	>>	+ 1		=  16383
	>>	- 1		= -16384
'
'L_>> ================

'  basic 
	L_>>	1 1		= 0
	L_>>	4 2		= 1
	L_>>	0x1100 5	= 0x88

'  negative operand

	L_>>	1 -1		= 2
	L_>>	1 -2		= 4
	L_>>	0x88 -5		= 0x1100

'  overflow
	L_>>	-1 4711		= -1
	L_>>	1  4711		= 0
	L_>>	-4711 4711 	= -1
	L_>>	4711 4711 	= 0
	L_>>	++ 1		=  1073741823
	L_>>	-- 1		= -1073741824

'
'<< ================

'  basic 
	<<	1 1		= 2
	<<	4 2		= 16
	<<	0x0088 5	= 0x1100

'  negative operand

	<<	1 -1		= 0
	<<	4 -2		= 1
	<<	0x1100 -5	= 0x0088

'  overflow
	<<	-1 4711		= 0
	<<	1  4711		= 0
	<<	-4711 4711 	= 0
	<<	4711 4711 	= 0
	<<	4711 -4711 	= 0
	<<	-4711 -4711 	= -1
	<<	+ 1		= 0xfffe
	<<	-1 1		= 0xfffe
	<<	- 1		= 0
'
'L_<< ================

'  basic 
	L_<<	1 1		= 2
	L_<<	4 2		= 16
	L_<<	0x0088 5	= 0x1100

'  negative operand

	L_<<	1 -1		= 0
	L_<<	4 -2		= 1
	L_<<	0x1100 -5	= 0x0088

'  overflow
	L_<<	-1 4711		= 0
	L_<<	1  4711		= 0
	L_<<	-4711 4711 	= 0
	L_<<	4711 4711 	= 0
	L_<<	4711 -4711 	= 0
	L_<<	-4711 -4711 	= -1
	L_<<	++ 1		= -2
	L_<<	-1 1		= -2
	L_<<	-- 1		= 0

'macros
'
'add ================
'  basic

	M_add  0  0 	=  0
	M_add  7  4	= 11
	M_add  4  6 	= 10
	M_add  1  1 	=  2

'  negative operands

	M_add  -7  4	= -3
	M_add   4 -6 	= -2
	M_add  -1 -3 	= -4
	M_add   7 -4	=  3
	M_add  -4  6 	=  2

'  positive overflow
; (max-word = 32767)
	M_add  + 1	= +
	M_add  + +	= +
	M_add  -1 + 	= 32766
	M_add  32766 2	= +
	M_add  1 32766  	= +

'  underflow
; (min-word = 32768)

	M_add  - -1	= -
	M_add  - -	= -
	M_add  1 -	= -32767  
	M_add  -32767 -2 = -
	M_add  -1 -32766 = -32767
	M_add  -32767 -1 = -
	M_add  - +	= -1
	M_add  + -	= -1
	M_add  0 -	= -
	M_add  0 +	= +
'

'L_add ================
'  basic 

	M_L_add  0  0 	=  0
	M_L_add  7  4	= 11
	M_L_add  4  6 	= 10
	M_L_add  1  1 	=  2

'  negative operands

	M_L_add  -7  4	= -3
	M_L_add   4 -6 	= -2
	M_L_add  -1 -3 	= -4
	M_L_add   7 -4	=  3
	M_L_add  -4  6 	=  2
	M_L_add   0 -1 	= -1

'  positive overflow
; (max-longword = 2147483647)
	M_L_add  ++ 1	= ++
	M_L_add  ++ ++	= ++
	M_L_add  -1 ++ 	= 2147483646
	M_L_add  2147483646 2 = ++
	M_L_add  1 2147483645 = 2147483646

'  underflow
; (min-longword = -2147483648)

	M_L_add  -- -1	= --
	M_L_add  -- --	= --
	M_L_add  1 --	= -2147483647
	M_L_add  -2147483647 -2	= --
	M_L_add  -1 -2147483646 	= -2147483647
	M_L_add  -2147483647 -1	= --
	M_L_add  -- ++	= -1
	M_L_add  ++ --	= -1
	M_L_add  0 --	= --
	M_L_add  0 ++	= ++
'

'sub ================
'  basic 

	M_sub  0  0 	=  0
	M_sub  7  4	=  3
	M_sub  4  6 	= -2
	M_sub  1  0 	=  1

'  negative operands

	M_sub  -7  4	= -11
	M_sub   4 -6 	=  10
	M_sub  -1 -3 	=  2
	M_sub   7 -4	=  11
	M_sub  -4  6 	= -10

'  positive overflow
; (max-word = 32767)
	M_sub  1 -	= +
	M_sub  + +	= 0
	M_sub  + 0	= +
	M_sub  + -1 	= +
	M_sub  + 1 	= 32766
	M_sub  1 + 	= -32766 
	M_sub  0 +  	= -32767

'  underflow
; (min-word = 32768)

	M_sub  - -1	= -32767
	M_sub  - 1	= -
	M_sub  - -	= 0
	M_sub  - +	= -
	M_sub  + -	= +
	M_sub  1 -	= +
	M_sub  -1 -	= +
	M_sub  -32767 2	= -
	M_sub  0 -	= +
' 
'
'abs ================
'  basic 

	M_abs	   0	=   0
	M_abs	   2	=   2
	M_abs	-459	= 459

'  overflow

	M_abs	 +	=   +
	M_abs	 -	=   +
	M_abs 	-32767  =   +
	M_abs 	 32766  = 32766
	M_abs 	-32766  = 32766

'
'mult ================
;  actually, a * b >> 15

'  basic 
	M_mult	0  0		= 0
	M_mult	0x100 0x100	= 2
	M_mult	4711 0x4000	= 2355

'  negative operands
	M_mult	-1  0		=  0

	M_mult	-0x100   0x100	= -2
	M_mult	 0x100  -0x100	= -2
	M_mult	-0x100  -0x100	=  2

	M_mult	-4711   0x4000	= -2356
	M_mult	 4711  -0x4000	= -2356
	M_mult	-4711  -0x4000	=  2355

'  overflow
	M_mult	+ + 	 = 32766
	M_mult	+ 0x4000 = 0x3fff
	M_mult	0x4000 + = 0x3fff
	M_mult	+ 1	 = 0
	M_mult	+ 2	 = 1
	M_mult	+ 3	 = 2

'  underflow
;	M_mult - - 	= +			assert !(a == b && b == MIN_WORD)
 	M_mult - -32767	= +
 	M_mult -32767 -	= +
	M_mult	- + 	= -32767
	M_mult	+ - 	= -32767
	M_mult	- 1	= -1
	M_mult	- 2	= -2
	M_mult	- 3	= -3

'
'mult_r ================
;  actually, (a * b + 16384) >> 15

'  basic 
	M_mult_r 0  0		= 0
	M_mult_r 0x100 0x100	= 2
	M_mult_r 4711 0x4000	= 2356

'  negative operands
	M_mult_r -1  0		=  0

	M_mult_r -0x100   0x100	= -2
	M_mult_r  0x100  -0x100	= -2
	M_mult_r -0x100  -0x100	=  2

	M_mult_r -4711   0x4000	= -2355
	M_mult_r  4711  -0x4000	= -2355
	M_mult_r -4711  -0x4000	=  2356

'  overflow
	M_mult_r + + 	 = 32766
	M_mult_r + 32766  = 32765
	M_mult_r 32766 +  = 32765
	M_mult_r + 0x4000 = 0x4000
	M_mult_r 0x4000 + = 0x4000
	M_mult_r + 0x4001 = 0x4000
	M_mult_r 0x4001 + = 0x4000
	M_mult_r + 2	 = 2
	M_mult_r + 1	 = 1
	M_mult_r 1 +	 = 1
	M_mult_r + 0	 = 0
	M_mult_r 0 +	 = 0

'  underflow
;	M_mult_r - - 	 = +			assert !(a == b && b == MIN_WORD)
 	M_mult_r - -32767 = +
 	M_mult_r -32767 - = +
	M_mult_r - + 	 = -32767
	M_mult_r + - 	 = -32767
	M_mult_r - 1	 = -1
	M_mult_r - 2	 = -2
	M_mult_r - 3	 = -3

'
'L_mult ================
;  actually, (a * b) << 1
;  assert (a != MIN_WORD && b != MIN_WORD)

'  basic 
	M_L_mult	0  0	= 0
	M_L_mult	2  3	= 12
	M_L_mult	4711 5	= 47110

'  negative operands

	M_L_mult	-2  3	= -12
	M_L_mult	 2 -3	= -12
	M_L_mult	-2 -3	=  12
	M_L_mult -4711  5	= -47110
	M_L_mult	4711 -5	= -47110
	M_L_mult -4711 -5	=  47110

'  overflow
 	M_L_mult	+ + 	 = 2147352578
	M_L_mult	+ -32767 = -2147352578
	M_L_mult	-32767 + = -2147352578
	M_L_mult	+ 2	 = 131068
	M_L_mult	+ 1	 = 65534
	M_L_mult	1 +	 = 65534
	M_L_mult	+ 0	 = 0
	M_L_mult	0 +	 = 0