1 ; 2 ; Copyright 1992 by Jutta Degener and Carsten Bormann, Technische 3 ; Universitaet Berlin. See the accompanying file "COPYRIGHT" for 4 ; details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. 5 ; 6 ; 7 ; Lines starting with ' (in the first col) are echoed. 8 ; Lines starting with " (in the first col) are echoed to stderr. 9 ; Lines starting with ; or empty lines are ignored. 10 ; 11 ; The part after (including) a trailing '=' is what you expect; 12 ; there will be output if the result is different. 13 ; 14 ; - and + by itself mean MIN_WORD and MAX_WORD, respectively; 15 ; -- and ++ mean MIN_LONGWORD and MAX_LONGWORD. 16 ; 17 18 'test the basic arithmetic operations used for the rpe-ltd filtering. 19 ' 20 'add ================ 21 ' basic 22 23 add 0 0 = 0 24 add 7 4 = 11 25 add 4 6 = 10 26 add 1 1 = 2 27 28 ' negative operands 29 30 add -7 4 = -3 31 add 4 -6 = -2 32 add -1 -3 = -4 33 add 7 -4 = 3 34 add -4 6 = 2 35 36 ' positive overflow 37 ; (max-word = 32767) 38 add + 1 = + 39 add + + = + 40 add -1 + = 32766 41 add 32766 2 = + 42 add 1 32766 = + 43 44 ' underflow 45 ; (min-word = 32768) 46 47 add - -1 = - 48 add - - = - 49 add 1 - = -32767 50 add -32767 -2 = - 51 add -1 -32766 = -32767 52 add -32767 -1 = - 53 add - + = -1 54 add + - = -1 55 add 0 - = - 56 add 0 + = + 57 ' 58 59 'L_add ================ 60 ' basic 61 62 L_add 0 0 = 0 63 L_add 7 4 = 11 64 L_add 4 6 = 10 65 L_add 1 1 = 2 66 67 ' negative operands 68 69 L_add -7 4 = -3 70 L_add 4 -6 = -2 71 L_add -1 -3 = -4 72 L_add 7 -4 = 3 73 L_add -4 6 = 2 74 L_add 0 -1 = -1 75 76 ' positive overflow 77 ; (max-longword = 2147483647) 78 L_add ++ 1 = ++ 79 L_add ++ ++ = ++ 80 L_add -1 ++ = 2147483646 81 L_add 2147483646 2 = ++ 82 L_add 1 2147483645 = 2147483646 83 84 ' underflow 85 ; (min-longword = -2147483648) 86 87 L_add -- -1 = -- 88 L_add -- -- = -- 89 L_add 1 -- = -2147483647 90 L_add -2147483647 -2 = -- 91 L_add -1 -2147483646 = -2147483647 92 L_add -2147483647 -1 = -- 93 L_add -- ++ = -1 94 L_add ++ -- = -1 95 L_add 0 -- = -- 96 L_add 0 ++ = ++ 97 ' 98 99 'sub ================ 100 ' basic 101 102 sub 0 0 = 0 103 sub 7 4 = 3 104 sub 4 6 = -2 105 sub 1 0 = 1 106 107 ' negative operands 108 109 sub -7 4 = -11 110 sub 4 -6 = 10 111 sub -1 -3 = 2 112 sub 7 -4 = 11 113 sub -4 6 = -10 114 115 ' positive overflow 116 ; (max-word = 32767) 117 sub 1 - = + 118 sub + + = 0 119 sub + 0 = + 120 sub + -1 = + 121 sub + 1 = 32766 122 sub 1 + = -32766 123 sub 0 + = -32767 124 125 ' underflow 126 ; (min-word = 32768) 127 128 sub - -1 = -32767 129 sub - 1 = - 130 sub - - = 0 131 sub - + = - 132 sub + - = + 133 sub 1 - = + 134 sub -1 - = + 135 sub -32767 2 = - 136 sub 0 - = + 137 ' 138 139 'L_sub ================ 140 ' basic 141 142 L_sub 0 0 = 0 143 L_sub 7 4 = 3 144 L_sub 4 6 = -2 145 L_sub 1 0 = 1 146 147 ' negative operands 148 149 L_sub -7 4 = -11 150 L_sub 4 -6 = 10 151 L_sub -1 -3 = 2 152 L_sub 7 -4 = 11 153 L_sub -4 6 = -10 154 155 ' positive overflow 156 L_sub 1 -- = ++ 157 L_sub ++ ++ = 0 158 L_sub ++ 0 = ++ 159 L_sub ++ -1 = ++ 160 L_sub ++ 1 = 2147483646 161 L_sub 1 ++ = -2147483646 162 L_sub 0 ++ = -2147483647 163 164 ' underflow 165 166 L_sub -- -1 = -2147483647 167 L_sub -- 1 = -- 168 L_sub -- -- = 0 169 L_sub -- ++ = -- 170 L_sub + -- = ++ 171 L_sub 1 -- = ++ 172 L_sub -1 -- = ++ 173 L_sub -2147483647 2 = -- 174 L_sub 0 -- = ++ 175 176 ' 177 'abs ================ 178 ' basic 179 180 abs 0 = 0 181 abs 2 = 2 182 abs -459 = 459 183 184 ' overflow 185 186 abs + = + 187 abs - = + 188 abs -32767 = + 189 abs 32766 = 32766 190 abs -32766 = 32766 191 192 ' 193 'mult ================ 194 ; actually, a * b >> 15 195 196 ' basic 197 mult 0 0 = 0 198 mult 0x100 0x100 = 2 199 mult 4711 0x4000 = 2355 200 201 ' negative operands 202 mult -1 0 = 0 203 204 mult -0x100 0x100 = -2 205 mult 0x100 -0x100 = -2 206 mult -0x100 -0x100 = 2 207 208 mult -4711 0x4000 = -2356 209 mult 4711 -0x4000 = -2356 210 mult -4711 -0x4000 = 2355 211 212 ' overflow 213 mult + + = 32766 214 mult + 0x4000 = 0x3fff 215 mult 0x4000 + = 0x3fff 216 mult + 1 = 0 217 mult + 2 = 1 218 mult + 3 = 2 219 220 ' underflow 221 mult - - = + 222 mult - + = -32767 223 mult + - = -32767 224 mult - 1 = -1 225 mult - 2 = -2 226 mult - 3 = -3 227 228 ' 229 'mult_r ================ 230 ; actually, (a * b + 16384) >> 15 231 232 ' basic 233 mult_r 0 0 = 0 234 mult_r 0x100 0x100 = 2 235 mult_r 4711 0x4000 = 2356 236 237 ' negative operands 238 mult_r -1 0 = 0 239 240 mult_r -0x100 0x100 = -2 241 mult_r 0x100 -0x100 = -2 242 mult_r -0x100 -0x100 = 2 243 244 mult_r -4711 0x4000 = -2355 245 mult_r 4711 -0x4000 = -2355 246 mult_r -4711 -0x4000 = 2356 247 248 ' overflow 249 mult_r + + = 32766 250 mult_r + 32766 = 32765 251 mult_r 32766 + = 32765 252 mult_r + 0x4000 = 0x4000 253 mult_r 0x4000 + = 0x4000 254 mult_r + 0x4001 = 0x4000 255 mult_r 0x4001 + = 0x4000 256 mult_r + 2 = 2 257 mult_r + 1 = 1 258 mult_r 1 + = 1 259 mult_r + 0 = 0 260 mult_r 0 + = 0 261 262 ' underflow 263 mult_r - - = + 264 mult_r - + = -32767 265 mult_r + - = -32767 266 mult_r - 1 = -1 267 mult_r - 2 = -2 268 mult_r - 3 = -3 269 270 ' 271 'L_mult ================ 272 ; actually, (a * b) << 1 273 ; assert (a != MIN_WORD && b != MIN_WORD) 274 275 ' basic 276 L_mult 0 0 = 0 277 L_mult 2 3 = 12 278 L_mult 4711 5 = 47110 279 280 ' negative operands 281 282 L_mult -2 3 = -12 283 L_mult 2 -3 = -12 284 L_mult -2 -3 = 12 285 L_mult -4711 5 = -47110 286 L_mult 4711 -5 = -47110 287 L_mult -4711 -5 = 47110 288 289 ' overflow 290 L_mult + + = 2147352578 291 L_mult + -32767 = -2147352578 292 L_mult -32767 + = -2147352578 293 L_mult + 2 = 131068 294 L_mult + 1 = 65534 295 L_mult 1 + = 65534 296 L_mult + 0 = 0 297 L_mult 0 + = 0 298 299 ' 300 'div ================ 301 ; actually, (32767 * a) / b 302 ; assert (a > 0 && b >= a) 303 304 ' basic 305 div 1 1 = + 306 div 4711 4711 = + 307 div 5 10 = 0x4000 308 div 5 20 = 0x2000 309 div 5 40 = 0x1000 310 311 ' overflow 312 div + + = + 313 div 0x4000 + = 0x4000 314 div 1 + = 1 315 div 1 2 = 0x4000 316 ' 317 'norm ================ 318 319 ' positive 320 norm 1 = 30 321 norm 2 = 29 322 norm 3 = 29 323 norm 4 = 28 324 norm 5 = 28 325 ; etc, etc... 326 norm 0x08000000 = 3 327 norm 0x10000000 = 2 328 norm 0x20000000 = 1 329 norm 0x20000001 = 1 330 norm 0x3fffffff = 1 331 norm 0x40000000 = 0 332 norm 0x40000001 = 0 333 norm 0x4ffffffe = 0 334 norm ++ = 0 335 336 ' negative 337 norm -1 = 31 338 norm -2 = 30 339 norm -3 = 29 340 norm -4 = 29 341 norm -5 = 28 342 ; etc, etc... 343 norm 0x4fffffff = 0 344 norm -- = 0 345 ' 346 '>> ================ 347 348 ' basic 349 >> 1 1 = 0 350 >> 4 2 = 1 351 >> 0x1100 5 = 0x88 352 353 ' negative operand 354 355 >> 1 -1 = 2 356 >> 1 -2 = 4 357 >> 0x88 -5 = 0x1100 358 359 ' overflow 360 >> -1 4711 = -1 361 >> 1 4711 = 0 362 >> -4711 4711 = -1 363 >> 4711 4711 = 0 364 >> + 1 = 16383 365 >> - 1 = -16384 366 ' 367 'L_>> ================ 368 369 ' basic 370 L_>> 1 1 = 0 371 L_>> 4 2 = 1 372 L_>> 0x1100 5 = 0x88 373 374 ' negative operand 375 376 L_>> 1 -1 = 2 377 L_>> 1 -2 = 4 378 L_>> 0x88 -5 = 0x1100 379 380 ' overflow 381 L_>> -1 4711 = -1 382 L_>> 1 4711 = 0 383 L_>> -4711 4711 = -1 384 L_>> 4711 4711 = 0 385 L_>> ++ 1 = 1073741823 386 L_>> -- 1 = -1073741824 387 388 ' 389 '<< ================ 390 391 ' basic 392 << 1 1 = 2 393 << 4 2 = 16 394 << 0x0088 5 = 0x1100 395 396 ' negative operand 397 398 << 1 -1 = 0 399 << 4 -2 = 1 400 << 0x1100 -5 = 0x0088 401 402 ' overflow 403 << -1 4711 = 0 404 << 1 4711 = 0 405 << -4711 4711 = 0 406 << 4711 4711 = 0 407 << 4711 -4711 = 0 408 << -4711 -4711 = -1 409 << + 1 = 0xfffe 410 << -1 1 = 0xfffe 411 << - 1 = 0 412 ' 413 'L_<< ================ 414 415 ' basic 416 L_<< 1 1 = 2 417 L_<< 4 2 = 16 418 L_<< 0x0088 5 = 0x1100 419 420 ' negative operand 421 422 L_<< 1 -1 = 0 423 L_<< 4 -2 = 1 424 L_<< 0x1100 -5 = 0x0088 425 426 ' overflow 427 L_<< -1 4711 = 0 428 L_<< 1 4711 = 0 429 L_<< -4711 4711 = 0 430 L_<< 4711 4711 = 0 431 L_<< 4711 -4711 = 0 432 L_<< -4711 -4711 = -1 433 L_<< ++ 1 = -2 434 L_<< -1 1 = -2 435 L_<< -- 1 = 0 436 437 'macros 438 ' 439 'add ================ 440 ' basic 441 442 M_add 0 0 = 0 443 M_add 7 4 = 11 444 M_add 4 6 = 10 445 M_add 1 1 = 2 446 447 ' negative operands 448 449 M_add -7 4 = -3 450 M_add 4 -6 = -2 451 M_add -1 -3 = -4 452 M_add 7 -4 = 3 453 M_add -4 6 = 2 454 455 ' positive overflow 456 ; (max-word = 32767) 457 M_add + 1 = + 458 M_add + + = + 459 M_add -1 + = 32766 460 M_add 32766 2 = + 461 M_add 1 32766 = + 462 463 ' underflow 464 ; (min-word = 32768) 465 466 M_add - -1 = - 467 M_add - - = - 468 M_add 1 - = -32767 469 M_add -32767 -2 = - 470 M_add -1 -32766 = -32767 471 M_add -32767 -1 = - 472 M_add - + = -1 473 M_add + - = -1 474 M_add 0 - = - 475 M_add 0 + = + 476 ' 477 478 'L_add ================ 479 ' basic 480 481 M_L_add 0 0 = 0 482 M_L_add 7 4 = 11 483 M_L_add 4 6 = 10 484 M_L_add 1 1 = 2 485 486 ' negative operands 487 488 M_L_add -7 4 = -3 489 M_L_add 4 -6 = -2 490 M_L_add -1 -3 = -4 491 M_L_add 7 -4 = 3 492 M_L_add -4 6 = 2 493 M_L_add 0 -1 = -1 494 495 ' positive overflow 496 ; (max-longword = 2147483647) 497 M_L_add ++ 1 = ++ 498 M_L_add ++ ++ = ++ 499 M_L_add -1 ++ = 2147483646 500 M_L_add 2147483646 2 = ++ 501 M_L_add 1 2147483645 = 2147483646 502 503 ' underflow 504 ; (min-longword = -2147483648) 505 506 M_L_add -- -1 = -- 507 M_L_add -- -- = -- 508 M_L_add 1 -- = -2147483647 509 M_L_add -2147483647 -2 = -- 510 M_L_add -1 -2147483646 = -2147483647 511 M_L_add -2147483647 -1 = -- 512 M_L_add -- ++ = -1 513 M_L_add ++ -- = -1 514 M_L_add 0 -- = -- 515 M_L_add 0 ++ = ++ 516 ' 517 518 'sub ================ 519 ' basic 520 521 M_sub 0 0 = 0 522 M_sub 7 4 = 3 523 M_sub 4 6 = -2 524 M_sub 1 0 = 1 525 526 ' negative operands 527 528 M_sub -7 4 = -11 529 M_sub 4 -6 = 10 530 M_sub -1 -3 = 2 531 M_sub 7 -4 = 11 532 M_sub -4 6 = -10 533 534 ' positive overflow 535 ; (max-word = 32767) 536 M_sub 1 - = + 537 M_sub + + = 0 538 M_sub + 0 = + 539 M_sub + -1 = + 540 M_sub + 1 = 32766 541 M_sub 1 + = -32766 542 M_sub 0 + = -32767 543 544 ' underflow 545 ; (min-word = 32768) 546 547 M_sub - -1 = -32767 548 M_sub - 1 = - 549 M_sub - - = 0 550 M_sub - + = - 551 M_sub + - = + 552 M_sub 1 - = + 553 M_sub -1 - = + 554 M_sub -32767 2 = - 555 M_sub 0 - = + 556 ' 557 ' 558 'abs ================ 559 ' basic 560 561 M_abs 0 = 0 562 M_abs 2 = 2 563 M_abs -459 = 459 564 565 ' overflow 566 567 M_abs + = + 568 M_abs - = + 569 M_abs -32767 = + 570 M_abs 32766 = 32766 571 M_abs -32766 = 32766 572 573 ' 574 'mult ================ 575 ; actually, a * b >> 15 576 577 ' basic 578 M_mult 0 0 = 0 579 M_mult 0x100 0x100 = 2 580 M_mult 4711 0x4000 = 2355 581 582 ' negative operands 583 M_mult -1 0 = 0 584 585 M_mult -0x100 0x100 = -2 586 M_mult 0x100 -0x100 = -2 587 M_mult -0x100 -0x100 = 2 588 589 M_mult -4711 0x4000 = -2356 590 M_mult 4711 -0x4000 = -2356 591 M_mult -4711 -0x4000 = 2355 592 593 ' overflow 594 M_mult + + = 32766 595 M_mult + 0x4000 = 0x3fff 596 M_mult 0x4000 + = 0x3fff 597 M_mult + 1 = 0 598 M_mult + 2 = 1 599 M_mult + 3 = 2 600 601 ' underflow 602 ; M_mult - - = + assert !(a == b && b == MIN_WORD) 603 M_mult - -32767 = + 604 M_mult -32767 - = + 605 M_mult - + = -32767 606 M_mult + - = -32767 607 M_mult - 1 = -1 608 M_mult - 2 = -2 609 M_mult - 3 = -3 610 611 ' 612 'mult_r ================ 613 ; actually, (a * b + 16384) >> 15 614 615 ' basic 616 M_mult_r 0 0 = 0 617 M_mult_r 0x100 0x100 = 2 618 M_mult_r 4711 0x4000 = 2356 619 620 ' negative operands 621 M_mult_r -1 0 = 0 622 623 M_mult_r -0x100 0x100 = -2 624 M_mult_r 0x100 -0x100 = -2 625 M_mult_r -0x100 -0x100 = 2 626 627 M_mult_r -4711 0x4000 = -2355 628 M_mult_r 4711 -0x4000 = -2355 629 M_mult_r -4711 -0x4000 = 2356 630 631 ' overflow 632 M_mult_r + + = 32766 633 M_mult_r + 32766 = 32765 634 M_mult_r 32766 + = 32765 635 M_mult_r + 0x4000 = 0x4000 636 M_mult_r 0x4000 + = 0x4000 637 M_mult_r + 0x4001 = 0x4000 638 M_mult_r 0x4001 + = 0x4000 639 M_mult_r + 2 = 2 640 M_mult_r + 1 = 1 641 M_mult_r 1 + = 1 642 M_mult_r + 0 = 0 643 M_mult_r 0 + = 0 644 645 ' underflow 646 ; M_mult_r - - = + assert !(a == b && b == MIN_WORD) 647 M_mult_r - -32767 = + 648 M_mult_r -32767 - = + 649 M_mult_r - + = -32767 650 M_mult_r + - = -32767 651 M_mult_r - 1 = -1 652 M_mult_r - 2 = -2 653 M_mult_r - 3 = -3 654 655 ' 656 'L_mult ================ 657 ; actually, (a * b) << 1 658 ; assert (a != MIN_WORD && b != MIN_WORD) 659 660 ' basic 661 M_L_mult 0 0 = 0 662 M_L_mult 2 3 = 12 663 M_L_mult 4711 5 = 47110 664 665 ' negative operands 666 667 M_L_mult -2 3 = -12 668 M_L_mult 2 -3 = -12 669 M_L_mult -2 -3 = 12 670 M_L_mult -4711 5 = -47110 671 M_L_mult 4711 -5 = -47110 672 M_L_mult -4711 -5 = 47110 673 674 ' overflow 675 M_L_mult + + = 2147352578 676 M_L_mult + -32767 = -2147352578 677 M_L_mult -32767 + = -2147352578 678 M_L_mult + 2 = 131068 679 M_L_mult + 1 = 65534 680 M_L_mult 1 + = 65534 681 M_L_mult + 0 = 0 682 M_L_mult 0 + = 0 683 684