From b1176539b41432fec283cb2d21b77efda04b3780 Mon Sep 17 00:00:00 2001 From: michaelh Date: Mon, 22 Oct 2001 01:14:16 +0000 Subject: [PATCH] 2001-10-21 Michael Hope * src/z80/ralloc.c: Turned off faulty pack for one use. * src/z80/peeph-gbz80.def: Removed redundent restart options. * src/z80/gen.c (genMult): Added native mul for constants on the z80 and gbz80. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1429 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 18 +++++ src/SDCCopt.c | 17 ++++- src/SDCCpeeph.c | 5 +- src/avr/main.c | 1 + src/ds390/main.c | 1 + src/izt/i186.c | 1 + src/izt/tlcs900h.c | 1 + src/mcs51/main.c | 1 + src/pic/main.c | 1 + src/port.h | 7 ++ src/z80/gen.c | 114 ++++++++++++++++++++++++++++--- src/z80/main.c | 36 ++++++++++ src/z80/peeph-gbz80.def | 24 +++---- src/z80/peeph.def | 4 +- src/z80/ralloc.c | 23 ++----- support/tests/dhrystone/Makefile | 2 +- support/tests/dhrystone/dhry.c | 4 +- 17 files changed, 209 insertions(+), 51 deletions(-) diff --git a/ChangeLog b/ChangeLog index df6a9108..bff727d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2001-10-21 Michael Hope + + * src/z80/ralloc.c: Turned off faulty pack for one use. + + * src/z80/peeph-gbz80.def: Removed redundent restart options. + + * src/z80/gen.c (genMult): Added native mul for constants on the z80 and gbz80. + 2001-10-21 Bernhard Held * support/regression/Makefile: Improved clean @@ -12,6 +20,13 @@ * support/regression/ports/mcs51/timeout.c: little improvements +2001-10-17 Michael Hope + + * device/lib/malloc.c (MEMHEADER): Fixed against new pedantic pointers. + + * support/regression/fwk/include/testfwk.h: Fixed up to use function pts correctly. + + * support/regression/generate-cases.py: Fixed up to use function pts correctly. 2001-10-16 Bernhard Held @@ -20,6 +35,9 @@ * support/regression/port/mcs51/timeout.c: add timeout for uCsim 2001-10-13 Michael Hope + * src/z80/gen.c (emitCall): Fixed up missing spill of HL when used to assign the result value. + + * src/z80/ralloc.c: Turned off pack for one use as it's quite broken. * src/SDCCmain.c (linkEdit): Added support for passing a legacy command line through the processor. diff --git a/src/SDCCopt.c b/src/SDCCopt.c index 1fd2e6cb..9d390292 100644 --- a/src/SDCCopt.c +++ b/src/SDCCopt.c @@ -464,10 +464,21 @@ convertToFcall (eBBlock ** ebbs, int count) /* if long / int mult or divide or mod */ if (ic->op == '*' || ic->op == '/' || ic->op == '%') { - sym_link *type = operandType (IC_LEFT (ic)); - if (IS_INTEGRAL (type) && getSize (type) > port->support.muldiv) + sym_link *leftType = operandType (IC_LEFT (ic)); + + if (IS_INTEGRAL (leftType) && getSize (leftType) > port->support.muldiv) { - convilong (ic, ebbs[i], type, ic->op); + sym_link *rightType = operandType (IC_RIGHT (ic)); + + if (port->hasNativeMulFor != NULL && + port->hasNativeMulFor (ic, leftType, rightType)) + { + /* Leave as native */ + } + else + { + convilong (ic, ebbs[i], leftType, ic->op); + } } } diff --git a/src/SDCCpeeph.c b/src/SDCCpeeph.c index ada11ff9..8797ce6c 100644 --- a/src/SDCCpeeph.c +++ b/src/SDCCpeeph.c @@ -748,6 +748,7 @@ replaceRule (lineNode ** shead, lineNode * stail, peepRule * pr) lbp = lb; l = pl->line; + while (*l) { /* if the line contains a variable */ @@ -982,8 +983,6 @@ peepHole (lineNode ** pls) /* for all rules */ for (pr = rootRules; pr; pr = pr->next) { - fflush(stdout); - for (spl = *pls; spl; spl = spl->next) { /* if inline assembler then no peep hole */ @@ -991,7 +990,7 @@ peepHole (lineNode ** pls) continue; mtail = NULL; - + /* Tidy up any data stored in the hTab */ /* if it matches */ diff --git a/src/avr/main.c b/src/avr/main.c index 1be9c7f5..b097d093 100644 --- a/src/avr/main.c +++ b/src/avr/main.c @@ -209,6 +209,7 @@ PORT avr_port = { _avr_regparm, NULL, NULL, + NULL, FALSE, 0, /* leave lt */ 1, /* transform gt ==> not le */ diff --git a/src/ds390/main.c b/src/ds390/main.c index 5693c821..94fd18d4 100644 --- a/src/ds390/main.c +++ b/src/ds390/main.c @@ -275,6 +275,7 @@ PORT ds390_port = _ds390_regparm, NULL, NULL, + NULL, FALSE, 0, /* leave lt */ 0, /* leave gt */ diff --git a/src/izt/i186.c b/src/izt/i186.c index ba4742e4..0b3a6b17 100644 --- a/src/izt/i186.c +++ b/src/izt/i186.c @@ -200,6 +200,7 @@ PORT i186_port = { _i186_regparm, NULL, NULL, + NULL, FALSE, 0, /* leave lt */ 0, /* leave gt */ diff --git a/src/izt/tlcs900h.c b/src/izt/tlcs900h.c index b06c141c..8cfc5161 100644 --- a/src/izt/tlcs900h.c +++ b/src/izt/tlcs900h.c @@ -199,6 +199,7 @@ PORT tlcs900h_port = _tlcs900h_regparm, NULL, NULL, + NULL, FALSE, 0, /* leave lt */ 0, /* leave gt */ diff --git a/src/mcs51/main.c b/src/mcs51/main.c index 8731cfb7..c20e8037 100644 --- a/src/mcs51/main.c +++ b/src/mcs51/main.c @@ -207,6 +207,7 @@ PORT mcs51_port = _mcs51_regparm, NULL, NULL, + NULL, FALSE, 0, /* leave lt */ 0, /* leave gt */ diff --git a/src/pic/main.c b/src/pic/main.c index b127324a..60443f66 100644 --- a/src/pic/main.c +++ b/src/pic/main.c @@ -290,6 +290,7 @@ PORT pic_port = _pic14_regparm, NULL, NULL, + NULL, FALSE, 0, /* leave lt */ 0, /* leave gt */ diff --git a/src/port.h b/src/port.h index d01887c8..ef0d4518 100644 --- a/src/port.h +++ b/src/port.h @@ -5,6 +5,8 @@ #ifndef PORT_INCLUDE #define PORT_INCLUDE +#include "SDCCicode.h" + #define TARGET_ID_MCS51 1 #define TARGET_ID_GBZ80 2 #define TARGET_ID_Z80 3 @@ -206,6 +208,11 @@ typedef struct */ char *(*getMangledFunctionName) (char *szOrginial); + /** Returns true if the port can multiply the two types nativly + without using support functions. + */ + bool (*hasNativeMulFor) (iCode *ic, sym_link *left, sym_link *right); + /** If TRUE, then tprintf and !dw will be used for some initalisers */ bool use_dw_for_init; diff --git a/src/z80/gen.c b/src/z80/gen.c index 2f1f0e21..6719b734 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -485,6 +485,14 @@ isPtrPair (asmop * aop) return FALSE; } } + +static void +spillPair (PAIR_ID pairId) +{ + _G.pairs[pairId].last_type = AOP_INVALID; + _G.pairs[pairId].base = NULL; +} + /** Push a register pair onto the stack */ void genPairPush (asmop * aop) @@ -504,6 +512,7 @@ _pop (PAIR_ID pairId) { emit2 ("pop %s", _pairs[pairId].name); _G.stack.pushed -= 2; + spillPair (pairId); } /*-----------------------------------------------------------------*/ @@ -1037,13 +1046,6 @@ adjustPair (const char *pair, int *pold, int new) } } -static void -spillPair (PAIR_ID pairId) -{ - _G.pairs[pairId].last_type = AOP_INVALID; - _G.pairs[pairId].base = NULL; -} - static void spillCached (void) { @@ -2403,10 +2405,11 @@ emitCall (iCode * ic, bool ispcall) if (i) emit2 ("inc sp"); } - spillCached (); } } + spillCached (); + if (_G.stack.pushedDE) { bool dInUse = bitVectBitValue(rInUse, D_IDX); @@ -3037,6 +3040,15 @@ genPlus (iCode * ic) goto release; } + if (isPair (AOP (IC_RIGHT (ic))) && AOP_TYPE (IC_LEFT (ic)) == AOP_IMMD) + { + fetchPair (PAIR_HL, AOP (IC_LEFT (ic))); + emit2 ("add hl,%s", getPairName (AOP (IC_RIGHT (ic)))); + spillCached(); + commitPair ( AOP (IC_RESULT (ic)), PAIR_HL); + goto release; + } + /* Special case: ld hl,sp+n trashes C so we cant afford to do it during an add with stack based varibles. Worst case is: @@ -3348,8 +3360,92 @@ release: static void genMult (iCode * ic) { + int val; + int count, i; + /* If true then the final operation should be a subtract */ + bool active = FALSE; + /* Shouldn't occur - all done through function calls */ - wassertl (0, "Multiplication is handled through support function calls"); + aopOp (IC_LEFT (ic), ic, FALSE, FALSE); + aopOp (IC_RIGHT (ic), ic, FALSE, FALSE); + aopOp (IC_RESULT (ic), ic, TRUE, FALSE); + + if (AOP_SIZE (IC_LEFT (ic)) > 2 || + AOP_SIZE (IC_RIGHT (ic)) > 2 || + AOP_SIZE (IC_RESULT (ic)) > 2) + { + wassertl (0, "Multiplication is handled through support function calls"); + } + + /* Swap left and right such that right is a literal */ + if ((AOP_TYPE (IC_LEFT (ic)) == AOP_LIT)) + { + operand *t = IC_RIGHT (ic); + IC_RIGHT (ic) = IC_LEFT (ic); + IC_LEFT (ic) = t; + } + + wassertl (AOP_TYPE (IC_RIGHT (ic)) == AOP_LIT, "Right must be a literal"); + + val = (int)floatFromVal ( AOP (IC_RIGHT (ic))->aopu.aop_lit); + // wassertl (val > 0, "Multiply must be positive"); + wassertl (val != 1, "Can't multiply by 1"); + + if (IS_Z80) { + _push (PAIR_DE); + } + + if ( AOP_SIZE (IC_LEFT (ic)) == 1 && !SPEC_USIGN (getSpec (operandType ( IC_LEFT (ic))))) + { + emit2 ("ld e,%s", aopGet (AOP (IC_LEFT (ic)), LSB, FALSE)); + emit2 ("ld a,e"); + emit2 ("rlc a"); + emit2 ("sbc a,a"); + emit2 ("ld d,a"); + } + else + { + fetchPair (PAIR_DE, AOP (IC_LEFT (ic))); + } + + i = val; + + /* Fully unroled version of mul.s. Not the most efficient. + */ + for (count = 0; count < 16; count++) + { + if (count != 0 && active) + { + emit2 ("add hl,hl"); + } + if (i & 0x8000U) + { + if (active == FALSE) + { + emit2 ("ld l,e"); + emit2 ("ld h,d"); + } + else + { + emit2 ("add hl,de"); + } + active = TRUE; + } + i <<= 1; + } + + spillCached(); + + if (IS_Z80) + { + _pop (PAIR_DE); + } + + commitPair ( AOP (IC_RESULT (ic)), PAIR_HL); + + freeAsmop (IC_LEFT (ic), NULL, ic); + freeAsmop (IC_RIGHT (ic), NULL, ic); + freeAsmop (IC_RESULT (ic), NULL, ic); } /*-----------------------------------------------------------------*/ diff --git a/src/z80/main.c b/src/z80/main.c index 8db371fd..a3d70ca9 100644 --- a/src/z80/main.c +++ b/src/z80/main.c @@ -386,6 +386,40 @@ _getRegName (struct regs *reg) return "err"; } +static bool +_hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right) +{ + sym_link *test = NULL; + value *val; + + if ( ic->op != '*') + { + return FALSE; + } + + if ( IS_LITERAL (left)) + { + test = left; + val = OP_VALUE (IC_LEFT (ic)); + } + else if ( IS_LITERAL (right)) + { + test = left; + val = OP_VALUE (IC_RIGHT (ic)); + } + else + { + return FALSE; + } + + if ( getSize (test) <= 2) + { + return TRUE; + } + + return FALSE; +} + #define LINKCMD \ "{bindir}{sep}link-{port} -n -c -- {z80bases} -m -j" \ " {z80libspec}" \ @@ -468,6 +502,7 @@ PORT z80_port = _reg_parm, _process_pragma, _mangleSupportFunctionName, + _hasNativeMulFor, TRUE, 0, /* leave lt */ 0, /* leave gt */ @@ -549,6 +584,7 @@ PORT gbz80_port = _reg_parm, _process_pragma, _mangleSupportFunctionName, + _hasNativeMulFor, TRUE, 0, /* leave lt */ 0, /* leave gt */ diff --git a/src/z80/peeph-gbz80.def b/src/z80/peeph-gbz80.def index 178a3fb4..846e49c9 100644 --- a/src/z80/peeph-gbz80.def +++ b/src/z80/peeph-gbz80.def @@ -1,40 +1,40 @@ -replace restart { +replace { + ld (hl),a + dec hl +} by { + ld (hl-),a +} +replace { ld (hl),a inc hl } by { ld (hl+),a } -replace restart { +replace { ld a,(hl) inc hl } by { ld a,(hl+) } -replace restart { - ld (hl),a - dec hl -} by { - ld (hl-),a -} -replace restart { +replace { ld a,[hl] inc hl } by { ld a,[hl+] } -replace restart { +replace { ld a,[hl] inc hl } by { ld a,[hl+] } -replace restart { +replace { ld [hl],a inc hl } by { ld [hl+],a } -replace restart { +replace { ld [hl],a dec hl } by { diff --git a/src/z80/peeph.def b/src/z80/peeph.def index 6b144b33..5090d4b8 100644 --- a/src/z80/peeph.def +++ b/src/z80/peeph.def @@ -1,9 +1,9 @@ -replace restart { +replace { ld (hl),(hl) } by { ERROR - peephole - caught (hl),(hl) } -replace restart { +replace { ld %1,%1 } by { ; Removed redundent load diff --git a/src/z80/ralloc.c b/src/z80/ralloc.c index fbd12bec..bc1c337e 100644 --- a/src/z80/ralloc.c +++ b/src/z80/ralloc.c @@ -51,7 +51,8 @@ enum { DISABLE_PACK_ACC = 0, DISABLE_PACK_ASSIGN = 0, - DISABLE_PACK_ONE_USE = 0, + /* Pack for one use is quite broken. */ + DISABLE_PACK_ONE_USE = 1, DISABLE_PACK_HL = 0, }; @@ -2485,14 +2486,6 @@ packRegisters (eBBlock * ebp) packRegsForSupport (ic, ebp); #endif -#if 0 - /* some cases the redundant moves can - can be eliminated for return statements */ - if ((ic->op == RETURN || ic->op == SEND) && - !isOperandInFarSpace (IC_LEFT (ic)) && - !options.model) - packRegsForOneuse (ic, IC_LEFT (ic), ebp); -#endif /* if pointer set & left has a size more than one and right is not in far space */ if (!DISABLE_PACK_ONE_USE && @@ -2519,6 +2512,7 @@ packRegisters (eBBlock * ebp) packRegsForOneuse (ic, IC_LEFT (ic), ebp); } + /* pack registers for accumulator use, when the result of an arithmetic or bit wise operation has only one use, that use is immediately following the defintion and the using iCode has @@ -2530,21 +2524,12 @@ packRegisters (eBBlock * ebp) { packRegsForHLUse (ic); } -#if 0 - if ((IS_ARITHMETIC_OP (ic) - || IS_BITWISE_OP (ic) - || ic->op == LEFT_OP || ic->op == RIGHT_OP - ) && - IS_ITEMP (IC_RESULT (ic)) && - getSize (operandType (IC_RESULT (ic))) <= 2) - packRegsForAccUse (ic); -#else + if (!DISABLE_PACK_ACC && IS_ITEMP (IC_RESULT (ic)) && getSize (operandType (IC_RESULT (ic))) == 1) { packRegsForAccUse2 (ic); } -#endif } } diff --git a/support/tests/dhrystone/Makefile b/support/tests/dhrystone/Makefile index 4361f5e2..62d194fa 100644 --- a/support/tests/dhrystone/Makefile +++ b/support/tests/dhrystone/Makefile @@ -21,7 +21,7 @@ dhry.gb: dhry.c dhry.c: dhry.h dhry.bin: dhry.ihx - cat $< | ../../makebin/makebin > $@ + cat $< | $(TOPDIR)/bin/makebin > $@ native: gcc -g -O2 -DREG= -DNOSTRUCTASSIGN -DNOENUM -o dhry dhry.c diff --git a/support/tests/dhrystone/dhry.c b/support/tests/dhrystone/dhry.c index 52cdb647..9154e357 100644 --- a/support/tests/dhrystone/dhry.c +++ b/support/tests/dhrystone/dhry.c @@ -274,9 +274,9 @@ int main(void) printf (" should be: %d\n", (int)7); printf ("Enum_Loc: %d\n", Enum_Loc); printf (" should be: %d\n", (int)1); - printf ("Str_1_Loc: %s\n", (char _generic *)Str_1_Loc); + printf ("Str_1_Loc: %s\n", (char *)Str_1_Loc); printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n"); - printf ("Str_2_Loc: %s\n", (char _generic *)Str_2_Loc); + printf ("Str_2_Loc: %s\n", (char *)Str_2_Loc); printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n"); printf ("\n"); #endif -- 2.30.2