about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-06-07 22:17:41 -0700
committerKartik Agaram <vc@akkartik.com>2019-06-08 11:51:47 -0700
commit21cb677f3b13ea9abbe7854ccfe8b9901f01492f (patch)
tree0749ae0173a4cdfeeec51e4cfd098039a4790d7f
parent0d0af0ab1f7e7a7554f9c0fcedc021445160d281 (diff)
downloadmu-21cb677f3b13ea9abbe7854ccfe8b9901f01492f.tar.gz
.
Simplify `string-equal`.
-rw-r--r--subx/054string-equal.subx39
-rwxr-xr-xsubx/apps/assortbin24092 -> 24089 bytes
-rwxr-xr-xsubx/apps/crenshaw2-1bin21319 -> 21316 bytes
-rwxr-xr-xsubx/apps/crenshaw2-1bbin21878 -> 21875 bytes
-rwxr-xr-xsubx/apps/factorialbin20235 -> 20232 bytes
-rwxr-xr-xsubx/apps/handlebin21041 -> 21038 bytes
-rwxr-xr-xsubx/apps/hexbin24328 -> 24325 bytes
-rwxr-xr-xsubx/apps/packbin39743 -> 39740 bytes
-rwxr-xr-xsubx/apps/surveybin21850 -> 22055 bytes
9 files changed, 17 insertions, 22 deletions
diff --git a/subx/054string-equal.subx b/subx/054string-equal.subx
index caeb0ea0..daaaa936 100644
--- a/subx/054string-equal.subx
+++ b/subx/054string-equal.subx
@@ -15,22 +15,20 @@ Entry:  # run all tests
 
 string-equal?:  # s : (address string), benchmark : (address string) -> EAX : boolean
     # pseudocode:
-    #   lens = s->length
-    #   if (lens != benchmark->length) return false
-    #   i = 0
+    #   if (s->length != benchmark->length) return false
     #   currs = s->data
     #   currb = benchmark->data
-    #   while i < s->length
+    #   maxs = s->data + s->length
+    #   while currs < maxs
     #     c1 = *currs
     #     c2 = *currb
     #     if (c1 != c2) return false
-    #     ++i, ++currs, ++currb
+    #     ++currs, ++currb
     #   return true
     #
     # registers:
-    #   i: ECX
-    #   lens: EDX
     #   currs: ESI
+    #   maxs: ECX
     #   currb: EDI
     #   c1: EAX
     #   c2: EBX
@@ -41,40 +39,38 @@ string-equal?:  # s : (address string), benchmark : (address string) -> EAX : bo
     # . save registers
     51/push-ECX
     52/push-EDX
-    53/push-EBX
     56/push-ESI
     57/push-EDI
     # ESI = s
     8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .             .           6/r32/ESI   8/disp8         .                 # copy *(EBP+8) to ESI
     # EDI = benchmark
     8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .             .           7/r32/EDI   0xc/disp8       .                 # copy *(EBP+12) to EDI
-    # lens/EDX = s->length
-    8b/copy                         0/mod/indirect  6/rm32/ESI    .           .             .           2/r32/EDX   .               .                 # copy *ESI to EDX
+    # ECX = s->length
+    8b/copy                         0/mod/indirect  6/rm32/ESI    .           .             .           1/r32/ECX   .               .                 # copy *ESI to ECX
 $string-equal?:lengths:
-    # if (lens != benchmark->length) return false
-    39/compare                      0/mod/indirect  7/rm32/EDI    .           .             .           2/r32/EDX   .               .                 # compare *EDI and EDX
+    # if (ECX != benchmark->length) return false
+    39/compare                      0/mod/indirect  7/rm32/EDI    .           .             .           1/r32/ECX   .               .                 # compare *EDI and ECX
     75/jump-if-not-equal  $string-equal?:false/disp8
     # currs/ESI = s->data
     81          0/subop/add         3/mod/direct    6/rm32/ESI    .           .             .           .           .               4/imm32           # add to ESI
+    # maxs/ECX = s->data + s->length
+    01/add                          3/mod/direct    1/rm32/ECX    .           .             .           6/r32/ESI   .               .                 # add ESI to ECX
     # currb/EDI = benchmark->data
     81          0/subop/add         3/mod/direct    7/rm32/EDI    .           .             .           .           .               4/imm32           # add to EDI
-    # i/ECX = c1/EAX = c2/EBX = 0
-    31/xor                          3/mod/direct    1/rm32/ECX    .           .             .           1/r32/ECX   .               .                 # clear ECX
+    # c1/EAX = c2/EDX = 0
     31/xor                          3/mod/direct    0/rm32/EAX    .           .             .           0/r32/EAX   .               .                 # clear EAX
-    31/xor                          3/mod/direct    3/rm32/EBX    .           .             .           3/r32/EBX   .               .                 # clear EBX
+    31/xor                          3/mod/direct    2/rm32/EDX    .           .             .           2/r32/EDX   .               .                 # clear EDX
 $string-equal?:loop:
-    # if (i >= lens) return true
-    39/compare                      3/mod/direct    1/rm32/ECX    .           .             .           2/r32/EDX   .               .                 # compare ECX with EDX
+    # if (currs >= maxs) return true
+    39/compare                      3/mod/direct    6/rm32/ESI    .           .             .           1/r32/ECX   .               .                 # compare ESI with ECX
     7d/jump-if-greater-or-equal  $string-equal?:true/disp8
     # c1 = *currs
     8a/copy-byte                    0/mod/indirect  6/rm32/ESI    .           .             .           0/r32/AL    .               .                 # copy byte at *ESI to AL
     # c2 = *currb
-    8a/copy-byte                    0/mod/indirect  7/rm32/EDI    .           .             .           3/r32/BL    .               .                 # copy byte at *EDI to BL
+    8a/copy-byte                    0/mod/indirect  7/rm32/EDI    .           .             .           2/r32/DL    .               .                 # copy byte at *EDI to DL
     # if (c1 != c2) return false
-    39/compare                      3/mod/direct    0/rm32/EAX    .           .             .           3/r32/EBX   .               .                 # compare EAX and EBX
+    39/compare                      3/mod/direct    0/rm32/EAX    .           .             .           2/r32/EDX   .               .                 # compare EAX and EDX
     75/jump-if-not-equal  $string-equal?:false/disp8
-    # ++i
-    41/increment-ECX
     # ++currs
     46/increment-ESI
     # ++currb
@@ -89,7 +85,6 @@ $string-equal?:end:
     # . restore registers
     5f/pop-to-EDI
     5e/pop-to-ESI
-    5b/pop-to-EBX
     5a/pop-to-EDX
     59/pop-to-ECX
     # . epilog
diff --git a/subx/apps/assort b/subx/apps/assort
index b9ba016b..e6926dd8 100755
--- a/subx/apps/assort
+++ b/subx/apps/assort
Binary files differdiff --git a/subx/apps/crenshaw2-1 b/subx/apps/crenshaw2-1
index 43fae481..d9b1a274 100755
--- a/subx/apps/crenshaw2-1
+++ b/subx/apps/crenshaw2-1
Binary files differdiff --git a/subx/apps/crenshaw2-1b b/subx/apps/crenshaw2-1b
index 0a3c2c44..aa4a43ab 100755
--- a/subx/apps/crenshaw2-1b
+++ b/subx/apps/crenshaw2-1b
Binary files differdiff --git a/subx/apps/factorial b/subx/apps/factorial
index 3439987b..f6636272 100755
--- a/subx/apps/factorial
+++ b/subx/apps/factorial
Binary files differdiff --git a/subx/apps/handle b/subx/apps/handle
index b6b806d5..dc69f189 100755
--- a/subx/apps/handle
+++ b/subx/apps/handle
Binary files differdiff --git a/subx/apps/hex b/subx/apps/hex
index 3eb6a5b7..b634eb31 100755
--- a/subx/apps/hex
+++ b/subx/apps/hex
Binary files differdiff --git a/subx/apps/pack b/subx/apps/pack
index b8bd13aa..7d47ad2c 100755
--- a/subx/apps/pack
+++ b/subx/apps/pack
Binary files differdiff --git a/subx/apps/survey b/subx/apps/survey
index 9578a1d6..477d476f 100755
--- a/subx/apps/survey
+++ b/subx/apps/survey
Binary files differ
href='#n487'>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 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709