From 23b0b8c39dc72b043dcf8f376bc720649296c90f Mon Sep 17 00:00:00 2001 From: kvigor Date: Thu, 10 Feb 2000 21:44:58 +0000 Subject: [PATCH] Some new peephole optimizations, primarily for 24 bit flat mode; also use dpx for parameters in 24 bit mode. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@98 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCpeeph.c | 11 ++++++- src/mcs51/Makefile | 2 ++ src/mcs51/gen.c | 21 +++++++++---- src/mcs51/peeph.def | 72 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 6 deletions(-) diff --git a/src/SDCCpeeph.c b/src/SDCCpeeph.c index aa923fbb..d64619ab 100644 --- a/src/SDCCpeeph.c +++ b/src/SDCCpeeph.c @@ -64,6 +64,14 @@ int pcDistance (lineNode *cpos, char *lbl, bool back) return 0; } +/*-----------------------------------------------------------------*/ +/* flat24bitMode - will check to see if we are in flat24 mode */ +/*-----------------------------------------------------------------*/ +FBYNAME(flat24bitMode) +{ + return (options.model == MODEL_FLAT24); +} + /*-----------------------------------------------------------------*/ /* labelInRange - will check to see if label %5 is within range */ /*-----------------------------------------------------------------*/ @@ -125,7 +133,8 @@ int callFuncByName ( char *fname, int (*func)(hTab *,lineNode *,lineNode *) ; } ftab[] = { {"labelInRange", labelInRange }, - {"operandsNotSame", operandsNotSame } + {"operandsNotSame", operandsNotSame }, + {"24bitMode", flat24bitMode }, }; int i; diff --git a/src/mcs51/Makefile b/src/mcs51/Makefile index a248555c..0b687514 100644 --- a/src/mcs51/Makefile +++ b/src/mcs51/Makefile @@ -10,6 +10,8 @@ CFLAGS += -I.. -I. -I../.. all: $(LIB) +main.o: main.c peeph.rul + $(LIB): peeph.rul $(OBJ) rm -f $(LIB) ar r $(LIB) $(OBJ) diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 62773542..57fe38fc 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -60,7 +60,11 @@ char *aopLiteral (value *val, int offset); static char *zero = "#0x00"; static char *one = "#0x01"; static char *spname ; -static char *fReturn[] = {"dpl","dph","b","a" }; + +static char *fReturn8051[] = {"dpl","dph","b","a" }; +static char *fReturn390[] = {"dpl","dph","dpx", "b","a" }; +static unsigned fReturnSize = 4; +static char **fReturn = fReturn8051; static char *accUse[] = {"a","b"}; static short rbank = -1; @@ -551,7 +555,7 @@ static void aopOp (operand *op, iCode *ic, bool result) int i; aop = op->aop = sym->aop = newAsmop(AOP_STR); aop->size = getSize(sym->type); - for ( i = 0 ; i < 4 ; i++ ) + for ( i = 0 ; i < fReturnSize ; i++ ) aop->aopu.aop_str[i] = fReturn[i]; return; } @@ -7170,10 +7174,10 @@ static void genReceive (iCode *ic) IS_TRUE_SYMOP(IC_RESULT(ic))) ) { int size = getSize(operandType(IC_RESULT(ic))); - int offset = 4 - size; + int offset = fReturnSize - size; while (size--) { - emitcode ("push","%s", (strcmp(fReturn[3 - offset],"a") ? - fReturn[3 - offset] : "acc")); + emitcode ("push","%s", (strcmp(fReturn[fReturnSize - offset - 1],"a") ? + fReturn[fReturnSize - offset - 1] : "acc")); offset++; } aopOp(IC_RESULT(ic),ic,FALSE); @@ -7202,6 +7206,13 @@ void gen51Code (iCode *lic) iCode *ic; int cln = 0; + /* Hack-o-matic: change fReturn based on model. */ + if (options.model == MODEL_FLAT24) + { + fReturn = fReturn390; + fReturnSize = 5; + } + lineHead = lineCurr = NULL; /* if debug information required */ diff --git a/src/mcs51/peeph.def b/src/mcs51/peeph.def index 9ae5acff..24018204 100644 --- a/src/mcs51/peeph.def +++ b/src/mcs51/peeph.def @@ -536,6 +536,20 @@ replace { orl a,r%2 } +replace { + mov %1,a + mov dpl,%2 + mov dph,%3 + mov dpx,%4 + mov a,%1 +} by { + ; Peephole 136a removed redundant moves + mov %1,a + mov dpl,%2 + mov dph,%3 + mov dpx,%4 +} if 24bitMode + replace { mov %1,a mov dpl,%2 @@ -1019,6 +1033,15 @@ replace { clr a } +replace { + mov dpl,#0x00 + mov dph,#0x00 + mov dpx,#0x00 +} by { + ; Peephole 181a used 24 bit load of dptr + mov dptr,#0x0000 +} if 24bitMode + // saving 3 byte, 2 cycles, return(NULL) profits here replace { mov dpl,#0x00 @@ -1028,6 +1051,16 @@ replace { mov dptr,#0x0000 } +// saves 2 bytes, ?? cycles. +replace { + mov dpl,#%1 + mov dph,#(%1 >> 8) + mov dpx,#(%1 >> 16) +} by { + ; Peephole 182a used 24 bit load of dptr + mov dptr,#%1 +} if 24bitMode + // saving 3 byte, 2 cycles, return(float_constant) profits here replace { mov dpl,#%1 @@ -1507,6 +1540,13 @@ replace { inc %1 } +replace { + mov dptr,#((((%1 >> 16)) <<16) + (((%1 >> 8)) <<8) + %1) +} by { + ; Peephole 210a simplified expression + mov dptr,#%1 +} if 24bitMode + replace { mov dptr,#((((%1 >> 8)) <<8) + %1) } by { @@ -1626,4 +1666,36 @@ replace { mov @r%1,a inc r%1 mov @r%1,a +} + +replace { + clr a + movx @dptr,a + mov dptr,%1 + clr a + movx @dptr,a +} by { + ; Peephole 219 removed redundant clear + clr a + movx @dptr,a + mov dptr,%1 + movx @dptr,a +} + +replace { + clr a + movx @dptr,a + mov dptr,%1 + movx @dptr,a + mov dptr,%2 + clr a + movx @dptr,a +} by { + ; Peephole 219a removed redundant clear + clr a + movx @dptr,a + mov dptr,%1 + movx @dptr,a + mov dptr,%2 + movx @dptr,a } \ No newline at end of file -- 2.39.5