* src/z80/gen.c (genCmp): Fixed compare on unsigned.
authormichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 19 Nov 2001 05:38:44 +0000 (05:38 +0000)
committermichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 19 Nov 2001 05:38:44 +0000 (05:38 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1621 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/z80/gen.c
support/regression/tests/compare.c

index 966497fd5a5622d6022899b683c12613b4e3d8c3..32f70621a9a39253a3d91bd6690c5fe05141ace9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2001-11-18  Michael Hope  <michaelh@juju.net.nz>
 
+       * src/z80/gen.c (genCmp): Fixed compare on unsigned.
+
        * src/z80/ralloc.c (packRegsForHLUse3): Created and optimised.
        (packRegsForIYUse): Created and optimised.
 
index 5652ea6b69f50cf6b5ce6ac0b776e9e525a54ae5..4572471a53ccc7a58b21dc5d3de29cf895285652 100644 (file)
@@ -3272,13 +3272,13 @@ genPlus (iCode * ic)
           emit2 ("add hl,%s", _pairs[left].name);
           goto release;
         }
-      else if (right != PAIR_INVALID)
+      else if (right != PAIR_INVALID && right != PAIR_HL)
         {
           fetchPair (PAIR_HL, AOP (IC_LEFT (ic)));
           emit2 ("add hl,%s", getPairName (AOP (IC_RIGHT (ic))));
           goto release;
         }
-      else if (left != PAIR_INVALID)
+      else if (left != PAIR_INVALID && left != PAIR_HL)
         { 
           fetchPair (PAIR_HL, AOP (IC_RIGHT (ic)));
           emit2 ("add hl,%s", getPairName (AOP (IC_LEFT (ic))));
@@ -3290,10 +3290,10 @@ genPlus (iCode * ic)
         }
     }
 
-  if (isPair (AOP (IC_RIGHT (ic))) && AOP_TYPE (IC_LEFT (ic)) == AOP_IMMD)
+  if (isPair (AOP (IC_RIGHT (ic))) && AOP_TYPE (IC_LEFT (ic)) == AOP_IMMD && getPairId (AOP (IC_RIGHT (ic))) != PAIR_HL)
     {
       fetchPair (PAIR_HL, AOP (IC_LEFT (ic)));
-      emit2 ("add hl,%s", getPairName (AOP (IC_RIGHT (ic))));
+      emit2 ("add hl,%s ; 2", getPairName (AOP (IC_RIGHT (ic))));
       spillCached();
       commitPair ( AOP (IC_RESULT (ic)), PAIR_HL);
       goto release;
@@ -4112,14 +4112,21 @@ release:
          code a little differently */
       if (ifx)
         {
-          if (IS_GB)
+          if (sign)
             {
-              emit2 ("rlca");
-              genIfxJump (ifx, swap_sense ? "nc" : "c");
+              if (IS_GB)
+                {
+                  emit2 ("rlca");
+                  genIfxJump (ifx, swap_sense ? "nc" : "c");
+                }
+              else
+                {
+                  genIfxJump (ifx, swap_sense ? "p" : "m");
+                }
             }
           else
             {
-              genIfxJump (ifx, swap_sense ? "p" : "m");
+              genIfxJump (ifx, swap_sense ? "nc" : "c");
             }
         }
       else
index f6e9ee6c5c47283ac304c56dfd22e97660d25a17..f058c3a649c63c4c17625ef3fbde12f248d09f0b 100644 (file)
@@ -88,6 +88,19 @@ testCompareVariables(void)
     ASSERT(left >= right);
 }
 
+static void
+testUnsignedCompare(void)
+{
+    {attr} {storage} unsigned {type} left, right;
+
+    left = 0;
+    right = (unsigned {type})-1;
+
+    ASSERT(left < right);
+    ASSERT(left <= right);
+    ASSERT(right > left);
+    ASSERT(right >= left);
+}
 /*
                 Common cases:
                         Around zero