From b2751d94f5aa42a4c50ba4d227d533be0fb0b674 Mon Sep 17 00:00:00 2001 From: michaelh Date: Sun, 25 Nov 2001 19:06:14 +0000 Subject: [PATCH] * 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. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1642 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 12 ++++- src/z80/gen.c | 53 ++++++++++++++++++-- src/z80/peeph-gbz80.def | 10 ++++ src/z80/peeph.def | 14 ++++++ support/regression/tests/bug-485362.c | 21 ++++++++ support/regression/tests/simplefloat.c | 67 ++++++++++++++++++++++++++ 6 files changed, 171 insertions(+), 6 deletions(-) create mode 100644 support/regression/tests/bug-485362.c create mode 100644 support/regression/tests/simplefloat.c diff --git a/ChangeLog b/ChangeLog index 024e28e8..5a546548 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ -2001-11-25 Bernhard Held +2001-11-25 Michael Hope + * 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 * sim/ucsim/s51.src/glob.cc: DS390 SFRs and bits added. * sim/ucsim/s51.src/port.cc: Port 4 and 5 added. diff --git a/src/z80/gen.c b/src/z80/gen.c index d2af3cd5..ee1ddaad 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -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; } diff --git a/src/z80/peeph-gbz80.def b/src/z80/peeph-gbz80.def index b96b64c7..cccda960 100644 --- a/src/z80/peeph-gbz80.def +++ b/src/z80/peeph-gbz80.def @@ -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 diff --git a/src/z80/peeph.def b/src/z80/peeph.def index fdf65c5f..d865c3a9 100644 --- a/src/z80/peeph.def +++ b/src/z80/peeph.def @@ -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 index 00000000..66ca3602 --- /dev/null +++ b/support/regression/tests/bug-485362.c @@ -0,0 +1,21 @@ +/** Shows segfault. + type: int + */ +#include + +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 index 00000000..deffb239 --- /dev/null +++ b/support/regression/tests/simplefloat.c @@ -0,0 +1,67 @@ +/** Simple set of tests for floating pt. + */ +#include + +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(); + } +} -- 2.30.2