* support/regression/tests/bug-485362.c: Added.
authormichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 25 Nov 2001 19:06:14 +0000 (19:06 +0000)
committermichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 25 Nov 2001 19:06:14 +0000 (19:06 +0000)
* support/regression/tests/simplefloat.c (testDivNearOne): Added.

* src/z80/gen.c (aopOp): Fixed case where left and result are in the same spill loc and they have different sizes.

* src/z80/peeph.def: Added rules for optimising two byte compares on the same thing, and to optimise two ptr assign.

* src/z80/gen.c (aopDump): Added a dump function.

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1642 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/z80/gen.c
src/z80/peeph-gbz80.def
src/z80/peeph.def
support/regression/tests/bug-485362.c [new file with mode: 0644]
support/regression/tests/simplefloat.c [new file with mode: 0644]

index 024e28e8160673be685b6ff970488e28e840bb17..5a54654898920d43e98fb08c202a43dc45a704d3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
-2001-11-25  Bernhard Held  <bernhard@bernhardheld.de>
+2001-11-25  Michael Hope  <michaelh@juju.net.nz>
+       * support/regression/tests/bug-485362.c: Added.
+
+       * support/regression/tests/simplefloat.c (testDivNearOne): Added.
+
+       * src/z80/gen.c (aopOp): Fixed case where left and result are in the same spill loc and they have different sizes.
 
+       * src/z80/peeph.def: Added rules for optimising two byte compares on the same thing, and to optimise two ptr assign.
+
+       * src/z80/gen.c (aopDump): Added a dump function.
+
+2001-11-25  Bernhard Held  <bernhard@bernhardheld.de>
        * sim/ucsim/s51.src/glob.cc: DS390 SFRs and bits added.
 
        * sim/ucsim/s51.src/port.cc: Port 4 and 5 added.
index d2af3cd5dc735fdd44eda630b804cfb7a5ec7538..ee1ddaad71e88253258135f64ec117fb261f6337 100644 (file)
@@ -233,6 +233,25 @@ static struct
 
 static const char *aopGet (asmop * aop, int offset, bool bit16);
 
+static const char *aopNames[] = {
+  "AOP_INVALID",
+  "AOP_LIT",
+  "AOP_REG",
+  "AOP_DIR",
+  "AOP_SFR",
+  "AOP_STK",
+  "AOP_IMMD",
+  "AOP_STR",
+  "AOP_CRY",
+  "AOP_IY",
+  "AOP_HL",
+  "AOP_ACC",
+  "AOP_HLREG",
+  "AOP_SIMPLELIT",
+  "AOP_EXSTK",
+  "AOP_PAIRPT"
+};
+
 static PAIR_ID
 _getTempPairId(void)
 {
@@ -392,6 +411,20 @@ _emitMove(const char *to, const char *from)
     }
 }
 
+static void
+aopDump(const char *plabel, asmop *aop)
+{
+  emitDebug("; Dump of %s: type %s size %u", plabel, aopNames[aop->type], aop->size);
+  switch (aop->type)
+    {
+    case AOP_STK:
+      emitDebug(";  aop_stk %d", aop->aopu.aop_stk);
+      break;
+    default:
+      /* No information. */
+    }
+}
+
 static void
 _moveA(const char *moveFrom)
 {
@@ -554,7 +587,9 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool requires_a)
 
   /* if already has one */
   if (sym->aop)
-    return sym->aop;
+    {
+      return sym->aop;
+    }
 
   /* Assign depending on the storage class */
   if (sym->onStack || sym->iaccess)
@@ -791,7 +826,9 @@ aopOp (operand * op, iCode * ic, bool result, bool requires_a)
 
   /* if already has a asmop then continue */
   if (op->aop)
-    return;
+    {
+      return;
+    }
 
   /* if the underlying symbol has a aop */
   if (IS_SYMOP (op) && OP_SYMBOL (op)->aop)
@@ -883,9 +920,12 @@ aopOp (operand * op, iCode * ic, bool result, bool requires_a)
        }
 
       /* else spill location  */
-      sym->aop = op->aop = aop =
+      op->aop = aop =
        aopForSym (ic, sym->usl.spillLoc, result, requires_a);
+      wassertl (aop->size >= getSize (sym->type), "Operand doesn't fit in the spill location");
       aop->size = getSize (sym->type);
+      /* PENDING: HACK.  Can have different sizes in the same AOP. */
+      sym->usl.spillLoc->aop = NULL;
       return;
     }
 
@@ -1278,6 +1318,7 @@ setupPair (PAIR_ID pairId, asmop * aop, int offset)
       {
        /* Doesnt include _G.stack.pushed */
        int abso = aop->aopu.aop_stk + offset + _G.stack.offset;
+
        if (aop->aopu.aop_stk > 0)
          {
            abso += _G.stack.param_offset;
@@ -5127,6 +5168,7 @@ genGetHbit (iCode * ic)
   operand *left, *result;
   left = IC_LEFT (ic);
   result = IC_RESULT (ic);
+
   aopOp (left, ic, FALSE, FALSE);
   aopOp (result, ic, FALSE, FALSE);
 
@@ -5141,8 +5183,7 @@ genGetHbit (iCode * ic)
   else
     {
       emit2 ("rlc a");
-      /* PENDING: For re-target. */
-      emit2 ("and a,#1");
+      emit2 ("and a,!one");
       outAcc (result);
     }
 
@@ -5865,6 +5906,8 @@ genGenPointerGet (operand * left,
           aopPut (AOP (result), at, offset);
           offset++;
         }
+      freeAsmop (left, NULL, ic);
       goto release;
     }
 
index b96b64c72ff3b7dd377af7033c4b20c9cd717179..cccda960d297a6b39555d53133627e7b64e5a33b 100644 (file)
@@ -61,3 +61,13 @@ replace {
         ld      (hl),a
         ld      %1,a
 }
+replace {
+       ld      (hl),a
+       inc     de
+       ld      a,(de)
+       inc     hl
+} by {
+       ld      (hl+),a
+       inc     de
+       ld      a,(de)
+}
\ No newline at end of file
index fdf65c5fd6a418949ae6b6dc203a9a170b1eae69..d865c3a93031f86ea982e4c0951466745d992bac 100644 (file)
@@ -178,3 +178,17 @@ replace {
         push    de
         inc     sp
 }
+replace {
+       ld      a,%1
+       sub     a,#%2
+       jp      m,%3
+       ld      a,%1
+       sub     a,#%4
+       jp      p,%5
+} by {
+       ld      a,%1
+       cp      a,#%2
+       jp      m,%3
+       cp      a,#%4
+       jp      p,%5
+}
diff --git a/support/regression/tests/bug-485362.c b/support/regression/tests/bug-485362.c
new file mode 100644 (file)
index 0000000..66ca360
--- /dev/null
@@ -0,0 +1,21 @@
+/** Shows segfault.
+    type: int
+ */
+#include <testfwk.h>
+
+void
+spoil({type} f)
+{
+  UNUSED(f);
+}
+
+void
+testDivBySelf(void)
+{
+  volatile {type} left, result;
+
+  left = 17;
+  result = left/left;
+
+  spoil(result);
+}
diff --git a/support/regression/tests/simplefloat.c b/support/regression/tests/simplefloat.c
new file mode 100644 (file)
index 0000000..deffb23
--- /dev/null
@@ -0,0 +1,67 @@
+/** Simple set of tests for floating pt.
+ */
+#include <testfwk.h>
+
+void
+testCmp(void)
+{
+  volatile float left, right;
+
+  left = 5;
+  right = 13;
+  ASSERT(left + right == 18);
+  ASSERT(left + right <= 18);
+  ASSERT(left + right >= 18);
+  ASSERT(left + right > 17.9);
+  ASSERT(left + right < 18.1);
+}
+
+void
+testDiv(void)
+{
+  volatile float left, right;
+
+  left = 17;
+  right = 343;
+
+  ASSERT(left/right == (17.0/343.0));
+  ASSERT(right/left == (343.0/17.0));
+
+  right = 17;
+  ASSERT(left/right == 1.0);
+}
+
+void
+testDivNearOne(void)
+{
+  volatile float left, right, result;
+
+  left = 12392.4;
+  right = 12392.4;
+  result = left / right;
+
+  if (result > 0.999999)
+    {
+      /* Fine */
+    }
+  else
+    {
+      FAIL();
+    }
+  if (result < 1.00001)
+    {
+      /* Fine */
+    }
+  else
+    {
+      FAIL();
+    }
+  if (result > 0.999999 && result < 1.00001)
+    {
+      /* Fine */
+    }
+  else
+    {
+      FAIL();
+    }
+}