From: maartenbrock Date: Tue, 12 Apr 2005 16:09:15 +0000 (+0000) Subject: * device/include/malloc.h: removed redundant __reentrant prototypes X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=8a3907b5a8101a4c272b4304654469217bd0d606;p=fw%2Fsdcc * device/include/malloc.h: removed redundant __reentrant prototypes * device/lib/_mullong.c: added working xstack variant in asm (C version doesn't pass regression tests) * device/lib/bpx.c: used __data and made bpx char for mcs51 * src/SDCCast.c (decorateType): removed unused GPTYPE_IDATA, (createFunction): fixed bug with xstackPtr * src/SDCCcse.c: corrected comments * src/SDCCopt.c (convertToFcall): fixed warning in MSVC, (killDeadCode, eBBlockFromiCode): removed unused code * src/SDCCsymt.h: removed unused GPTYPE_GPTR and GPTYPE_IDATA, corrected comments * src/mcs51/gen.c (aopForSym, aopPut, toBoolean, unsaveRegisters, assignResultValue, genCall, genFunction, genEndFunction, genAnd, genOr, genXor, genAddrOf): fixed several bugs concerning xstack (genModOneByte): fixed warning in MSVC * src/mcs51/main.c (): added comments * src/mcs51/peeph.def: changed 129 to 129.a, added 129.b, 129.c & 129.d git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3735 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 26e0f95d..509b8818 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2005-04-12 Maarten Brock + + * device/include/malloc.h: removed redundant __reentrant prototypes + * device/lib/_mullong.c: added working xstack variant in asm (C version + doesn't pass regression tests) + * device/lib/bpx.c: used __data and made bpx char for mcs51 + * src/SDCCast.c (decorateType): removed unused GPTYPE_IDATA, + (createFunction): fixed bug with xstackPtr + * src/SDCCcse.c: corrected comments + * src/SDCCopt.c (convertToFcall): fixed warning in MSVC, + (killDeadCode, eBBlockFromiCode): removed unused code + * src/SDCCsymt.h: removed unused GPTYPE_GPTR and GPTYPE_IDATA, + corrected comments + * src/mcs51/gen.c (aopForSym, aopPut, toBoolean, unsaveRegisters, + assignResultValue, genCall, genFunction, genEndFunction, genAnd, + genOr, genXor, genAddrOf): fixed several bugs concerning xstack + (genModOneByte): fixed warning in MSVC + * src/mcs51/main.c (): added comments + * src/mcs51/peeph.def: changed 129 to 129.a, added 129.b, 129.c & 129.d + 2005-04-12 Maarten Brock * src/SDCCmain.c (linkEdit): oops, changed one line too many diff --git a/device/include/malloc.h b/device/include/malloc.h index 79735105..718d1447 100644 --- a/device/include/malloc.h +++ b/device/include/malloc.h @@ -45,23 +45,12 @@ MEMHEADER unsigned char mem[]; }; -#ifdef SDCC_STACK_AUTO - -extern void init_dynamic_memory(void __xdata * heap, unsigned int size) __reentrant; -extern void __xdata * calloc (size_t nmemb, size_t size) __reentrant; -extern void __xdata * malloc (size_t size) __reentrant; -extern void __xdata * realloc (void * ptr, size_t size) __reentrant; -extern void free (void * ptr) __reentrant; - -#else - -extern void init_dynamic_memory(void __xdata * heap, unsigned int size); -extern void __xdata * calloc (size_t nmemb, size_t size); -extern void __xdata * malloc (size_t size); -extern void __xdata * realloc (void * ptr, size_t size); +extern void init_dynamic_memory(void xdata * heap, unsigned int size); +extern void xdata * calloc (size_t nmemb, size_t size); +extern void xdata * malloc (size_t size); +extern void xdata * realloc (void * ptr, size_t size); extern void free (void * ptr); -#endif #endif #endif diff --git a/device/lib/_mullong.c b/device/lib/_mullong.c index 6a0669ff..427ceddc 100644 --- a/device/lib/_mullong.c +++ b/device/lib/_mullong.c @@ -490,6 +490,141 @@ _mullong_dummy (void) _naked _endasm ; } +#elif defined(SDCC_USE_XSTACK) && defined(SDCC_STACK_AUTO) + +void +_mullong_dummy (void) _naked +{ + _asm + + __mullong: + + .globl __mullong + + ; the result c will be stored in r4...r7 + #define c0 r4 + #define c1 r5 + #define c2 r6 + #define c3 r7 + + #define a0 dpl + #define a1 dph + #define a2 r2 + #define a3 r3 + + #define b0 r1 + + ; c0 a0 * b0 + ; c1 a1 * b0 + a0 * b1 + ; c2 a2 * b0 + a1 * b1 + a0 * b2 + ; c3 a3 * b0 + a2 * b1 + a1 * b2 + a0 * b3 + + + ; parameter a comes in a, b, dph, dpl + mov r2,b ; save parameter a + mov r3,a + + mov a,#-4 ; 1 b 4 bytes + add a,_spx ; 1 + mov r0,a ; 1 r0 points to b0 + + ; Byte 0 + movx a,@r0 ; b0 + mov b0,a ; we need b0 several times + inc r0 ; r0 points to b1 + mov b,a0 + mul ab ; a0 * b0 + mov c0,a + mov c1,b + + ; Byte 1 + mov a,a1 + mov b,b0 + mul ab ; a1 * b0 + add a,c1 + mov c1,a + clr a + addc a,b + mov c2,a + + + mov b,a0 + movx a,@r0 ; b1 + mul ab ; a0 * b1 + add a,c1 + mov c1,a + mov a,b + addc a,c2 + mov c2,a + clr a + rlc a + mov c3,a + + ; Byte 2 + mov a,a2 + mov b,b0 + mul ab ; a2 * b0 + add a,c2 + mov c2,a + mov a,b + addc a,c3 + mov c3,a + + mov b,a1 + movx a,@r0 ; b1 + mul ab ; a1 * b1 + add a,c2 + mov c2,a + mov a,b + addc a,c3 + mov c3,a + + mov b,a0 + inc r0 + movx a,@r0 ; b2 + mul ab ; a0 * b2 + add a,c2 + mov c2,a + mov a,b + addc a,c3 + mov c3,a + + ; Byte 3 + mov a,a3 + mov b,b0 + mul ab ; a3 * b0 + add a,c3 + mov c3,a + + mov b,a1 + movx a,@r0 ; b2 + mul ab ; a1 * b2 + add a,c3 + mov c3,a + + mov b,a2 + dec r0 + movx a,@r0 ; b1 + mul ab ; a2 * b1 + add a,c3 + mov c3,a + + mov b,a0 + inc r0 + inc r0 + movx a,@r0 ; b3 + mul ab ; a0 * b3 + add a,c3 + + mov b,c2 + mov dph,c1 + mov dpl,c0 + + ret + + _endasm ; +} + #else // _MULLONG_ASM struct some_struct { diff --git a/device/lib/bpx.c b/device/lib/bpx.c index e234198d..d77829e8 100644 --- a/device/lib/bpx.c +++ b/device/lib/bpx.c @@ -22,5 +22,8 @@ You are forbidden to forbid anyone else to use, share and improve what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ - -data unsigned int bpx ; +#if defined(SDCC_mcs51) + __data unsigned char bpx ; +#else + __data unsigned int bpx ; +#endif diff --git a/src/SDCCast.c b/src/SDCCast.c index f9183db0..a00474c2 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -3581,10 +3581,8 @@ decorateType (ast * tree, RESULT_TYPE resultType) gptype = GPTYPE_FAR; break; case S_DATA: - gptype = GPTYPE_NEAR; - break; case S_IDATA: - gptype = GPTYPE_IDATA; + gptype = GPTYPE_NEAR; break; case S_PDATA: gptype = GPTYPE_XSTACK; @@ -5351,7 +5349,7 @@ createFunction (symbol * name, ast * body) /* set the stack pointer */ stackPtr = -port->stack.direction * port->stack.call_overhead; - xstackPtr = -port->stack.direction * port->stack.call_overhead; + xstackPtr = 0; if (IFFUNC_ISISR (name->type)) stackPtr -= port->stack.direction * port->stack.isr_overhead; diff --git a/src/SDCCcse.c b/src/SDCCcse.c index ad94b3a5..4b524b0b 100644 --- a/src/SDCCcse.c +++ b/src/SDCCcse.c @@ -1535,7 +1535,7 @@ constFold (iCode * ic, set * cseSet) ic->op != '-') return 0; - /* this check is a hueristic to prevent live ranges + /* this check is a heuristic to prevent live ranges from becoming too long */ if (IS_PTR (operandType (IC_RESULT (ic)))) return 0; @@ -1545,7 +1545,7 @@ constFold (iCode * ic, set * cseSet) return 0; /* check if we can find a definition for the - right hand side */ + left hand side */ if (!(applyToSet (cseSet, diCodeForSym, IC_LEFT (ic), &dic))) return 0; diff --git a/src/SDCCopt.c b/src/SDCCopt.c index b837e935..285b3563 100644 --- a/src/SDCCopt.c +++ b/src/SDCCopt.c @@ -561,7 +561,7 @@ convertToFcall (eBBlock ** ebbs, int count) if (ic->op == '%' && isOperandLiteral(IC_RIGHT(ic)) && IS_UNSIGNED(operandType(IC_LEFT(ic)))) { - unsigned litVal = abs(operandLitValue(IC_RIGHT(ic))); + unsigned litVal = abs((int)operandLitValue(IC_RIGHT(ic))); // See if literal value is a power of 2. while (litVal && !(litVal & 1)) @@ -941,11 +941,6 @@ killDeadCode (ebbIndex * ebbi) if (ic->op == ADDRESS_OF) volLeft = FALSE; - //if (ic->op == CAST && isOperandVolatile (IC_LEFT (ic), FALSE)) - // { - // volRight = IS_SYMOP (IC_RIGHT (ic)); - // } - if (ic->next && ic->seqPoint == ic->next->seqPoint && (ic->next->op == '+' || ic->next->op == '-')) { @@ -1170,9 +1165,6 @@ eBBlock ** eBBlockFromiCode (iCode * ic) { ebbIndex *ebbi = NULL; - //eBBlock **ebbs = NULL; - //int count = 0; - //int saveCount = 0; int change = 1; int lchange = 0; int kchange = 0; @@ -1182,7 +1174,6 @@ eBBlockFromiCode (iCode * ic) if (!ic) return NULL; - //count = 0; eBBNum = 0; /* optimize the chain for labels & gotos diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index 1dced6d0..37ab88cf 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -63,8 +63,6 @@ enum { #define GPTYPE_FAR 1 #define GPTYPE_CODE 2 #define GPTYPE_XSTACK 3 -#define GPTYPE_GPTR 4 // Never used? -#define GPTYPE_IDATA 5 #define HASHTAB_SIZE 256 @@ -152,13 +150,13 @@ typedef struct specifier int argreg; /* reg no for regparm */ union { /* Values if constant or enum */ - TYPE_WORD v_int; /* 2 bytes: int and char values */ - char *v_char; /* character string */ - TYPE_UWORD v_uint; /* 2 bytes: unsigned int const value */ - TYPE_DWORD v_long; /* 4 bytes: long constant value */ - TYPE_UDWORD v_ulong; /* 4 bytes: unsigned long constant val */ + TYPE_WORD v_int; /* 2 bytes: int and char values */ + char *v_char; /* character string */ + TYPE_UWORD v_uint; /* 2 bytes: unsigned int const value */ + TYPE_DWORD v_long; /* 4 bytes: long constant value */ + TYPE_UDWORD v_ulong; /* 4 bytes: unsigned long constant value */ double v_float; /* floating point constant value */ - struct symbol *v_enum; /* ptr 2 enum_list if enum==1 */ + struct symbol *v_enum; /* ptr to enum_list if enum==1 */ } const_val; struct structdef *v_struct; /* structure pointer */ @@ -223,7 +221,7 @@ typedef struct sym_link unsigned nonbanked:1; /* function has the nonbanked attribute */ unsigned banked:1; /* function has the banked attribute */ unsigned critical:1; /* critical function */ - unsigned intrtn:1; /* this is an interrupt routin */ + unsigned intrtn:1; /* this is an interrupt routine */ unsigned rbank:1; /* seperate register bank */ unsigned intno; /* 1=Interrupt svc routine */ short regbank; /* register bank 2b used */ @@ -281,7 +279,7 @@ typedef struct symbol unsigned noSpilLoc:1; /* cannot be assigned a spil location */ unsigned isstrlit; /* is a string literal and it's usage count */ unsigned accuse; /* can be left in the accumulator - On the Z80 accuse is devided into + On the Z80 accuse is divided into ACCUSE_A and ACCUSE_HL as the idea is quite similar. */ @@ -297,7 +295,7 @@ typedef struct symbol struct regs *regs[4]; /* can have at the most 4 registers */ struct asmop *aop; /* asmoperand for this symbol */ struct iCode *fuse; /* furthest use */ - struct iCode *rematiCode; /* rematerialse with which instruction */ + struct iCode *rematiCode; /* rematerialise with which instruction */ struct operand *reqv; /* register equivalent of a local variable */ struct symbol *prereqv; /* symbol before register equiv. substituion */ struct symbol *psbase; /* if pseudo symbol, the symbol it is based on */ @@ -313,8 +311,8 @@ typedef struct symbol int lineDef; /* defined line number */ char *fileDef; /* defined filename */ int lastLine; /* for functions the last line */ - struct sym_link *type; /* 1st link to declator chain */ - struct sym_link *etype; /* last link to declarator chn */ + struct sym_link *type; /* 1st link to declarator chain */ + struct sym_link *etype; /* last link to declarator chain */ struct symbol *next; /* crosslink to next symbol */ struct symbol *localof; /* local variable of which function */ struct initList *ival; /* ptr to initializer if any */ diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 20d12543..003afdfa 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -64,6 +64,8 @@ static char *accUse[] = static unsigned short rbank = -1; +#define SYM_BP(sym) (SPEC_OCLS (sym->etype)->paged ? "_bpx" : "_bp") + #define R0INB _G.bu.bs.r0InB #define R1INB _G.bu.bs.r1InB #define OPINB _G.bu.bs.OpInB @@ -514,17 +516,34 @@ aopForSym (iCode * ic, symbol * sym, bool result) if (sym->onStack) { + char offset = ((sym->stack < 0) ? + ((char) (sym->stack - _G.nRegsSaved)) : + ((char) sym->stack)) & 0xff; if (_G.accInUse || leftRightUseAcc (ic)) emitcode ("push", "acc"); - emitcode ("mov", "a,_bp"); - emitcode ("add", "a,#0x%02x", - ((sym->stack < 0) ? - ((char) (sym->stack - _G.nRegsSaved)) : - ((char) sym->stack)) & 0xff); - emitcode ("mov", "%s,a", - aop->aopu.aop_ptr->name); - + if ((offset >= -3) && (offset <= 3)) + { + emitcode ("mov", "%s,%s", + aop->aopu.aop_ptr->name, SYM_BP (sym)); + while (offset < 0) + { + emitcode ("dec", aop->aopu.aop_ptr->name); + offset++; + } + while (offset > 0) + { + emitcode ("inc", aop->aopu.aop_ptr->name); + offset--; + } + } + else + { + emitcode ("mov", "a,%s", SYM_BP (sym)); + emitcode ("add", "a,#0x%02x", offset); + emitcode ("mov", "%s,a", + aop->aopu.aop_ptr->name); + } if (_G.accInUse || leftRightUseAcc (ic)) emitcode ("pop", "acc"); } @@ -786,7 +805,7 @@ aopOp (operand * op, iCode * ic, bool result) } /* this is a temporary : this has - only four choices : + only five choices : a) register b) spillocation c) rematerialize @@ -1245,12 +1264,13 @@ aopGet (asmop * aop, int offset, bool bit16, bool dname) exit (1); } /*-----------------------------------------------------------------*/ -/* aopPut - puts a string for a aop */ +/* aopPut - puts a string for a aop and indicates if acc is in use */ /*-----------------------------------------------------------------*/ -static void +static bool aopPut (asmop * aop, const char *s, int offset, bool bvolatile) { char *d = buffer; + bool accuse = FALSE; if (aop->size && offset > (aop->size - 1)) { @@ -1265,6 +1285,7 @@ aopPut (asmop * aop, const char *s, int offset, bool bvolatile) { case AOP_DUMMY: MOVA (s); /* read s in case it was volatile */ + accuse = TRUE; break; case AOP_DIR: @@ -1277,6 +1298,8 @@ aopPut (asmop * aop, const char *s, int offset, bool bvolatile) if (strcmp (d, s) || bvolatile) emitcode ("mov", "%s,%s", d, s); + if (!strcmp (d, "acc")) + accuse = TRUE; break; @@ -1323,7 +1346,7 @@ aopPut (asmop * aop, const char *s, int offset, bool bvolatile) aop->coff = offset; - /* if not in accumulater */ + /* if not in accumulator */ MOVA (s); emitcode ("movx", "@dptr,a"); @@ -1387,11 +1410,13 @@ aopPut (asmop * aop, const char *s, int offset, bool bvolatile) break; case AOP_CRY: - /* if bit variable */ + /* if not bit variable */ if (!aop->aopu.aop_dir) { + /* inefficient: move carry into A and use jz/jnz */ emitcode ("clr", "a"); emitcode ("rlc", "a"); + accuse = TRUE; } else { @@ -1403,15 +1428,10 @@ aopPut (asmop * aop, const char *s, int offset, bool bvolatile) emitcode ("mov", "%s,c", aop->aopu.aop_dir); else { - if (strcmp (s, "a")) - { - MOVA (s); - } - { - /* set C, if a >= 1 */ - emitcode ("add", "a,#0xff"); - emitcode ("mov", "%s,c", aop->aopu.aop_dir); - } + MOVA (s); + /* set C, if a >= 1 */ + emitcode ("add", "a,#0xff"); + emitcode ("mov", "%s,c", aop->aopu.aop_dir); } } break; @@ -1424,6 +1444,7 @@ aopPut (asmop * aop, const char *s, int offset, bool bvolatile) break; case AOP_ACC: + accuse = TRUE; aop->coff = offset; if (!offset && (strcmp (s, "acc") == 0) && !bvolatile) @@ -1440,6 +1461,7 @@ aopPut (asmop * aop, const char *s, int offset, bool bvolatile) exit (1); } + return accuse; } @@ -1610,11 +1632,13 @@ toBoolean (operand * oper) { pushedB = pushB (); emitcode("mov", "b,a"); - while (size--) + while (--size) { MOVA (aopGet (AOP (oper), offset++, FALSE, FALSE)); emitcode ("orl", "b,a"); } + MOVA (aopGet (AOP (oper), offset++, FALSE, FALSE)); + emitcode ("orl", "a,b"); popB (pushedB); } else @@ -1963,7 +1987,7 @@ unsaveRegisters (iCode * ic) emitcode ("mov", "%s,a", mcs51_regWithIdx (i)->name); emitcode ("dec", "%s", spname); } - else + else if (count != 0) { emitcode ("mov", "r0,%s", spname); for (i = mcs51_nRegs; i >= 0; i--) @@ -1974,12 +1998,14 @@ unsaveRegisters (iCode * ic) emitcode ("movx", "a,@r0"); if (i != R0_IDX) emitcode ("mov", "%s,a", mcs51_regWithIdx (i)->name); + else + emitcode ("push", "acc"); } } emitcode ("mov", "%s,r0", spname); if (bitVectBitValue (rsave, R0_IDX)) { - emitcode ("mov", "r0,a"); + emitcode ("pop", "ar0"); } } } @@ -2015,18 +2041,21 @@ pushSide (operand * oper, int size) } /*-----------------------------------------------------------------*/ -/* assignResultValue - */ +/* assignResultValue - also indicates if acc is in use afterwards */ /*-----------------------------------------------------------------*/ -static void +static bool assignResultValue (operand * oper) { int offset = 0; int size = AOP_SIZE (oper); + bool accuse = FALSE; + while (size--) { - aopPut (AOP (oper), fReturn[offset], offset, isOperandVolatile (oper, FALSE)); + accuse |= aopPut (AOP (oper), fReturn[offset], offset, isOperandVolatile (oper, FALSE)); offset++; } + return accuse; } @@ -2075,7 +2104,7 @@ genXpush (iCode * ic) } /*-----------------------------------------------------------------*/ -/* genIpush - genrate code for pushing this gets a little complex */ +/* genIpush - generate code for pushing this gets a little complex */ /*-----------------------------------------------------------------*/ static void genIpush (iCode * ic) @@ -2350,6 +2379,8 @@ genCall (iCode * ic) sym_link *dtype; // bool restoreBank = FALSE; bool swapBanks = FALSE; + bool accuse = FALSE; + bool accPushed = FALSE; D(emitcode("; genCall","")); @@ -2410,7 +2441,7 @@ genCall (iCode * ic) aopOp (IC_RESULT (ic), ic, FALSE); _G.accInUse--; - assignResultValue (IC_RESULT (ic)); + accuse = assignResultValue (IC_RESULT (ic)); freeAsmop (IC_RESULT (ic), NULL, ic, TRUE); } @@ -2422,6 +2453,11 @@ genCall (iCode * ic) int i; if (ic->parmBytes > 3) { + if (accuse) + { + emitcode ("push", "acc"); + accPushed = TRUE; + } emitcode ("mov", "a,%s", spname); emitcode ("add", "a,#0x%02x", (-ic->parmBytes) & 0xff); emitcode ("mov", "%s,a", spname); @@ -2433,11 +2469,21 @@ genCall (iCode * ic) /* if we hade saved some registers then unsave them */ if (ic->regsSaved && !IFFUNC_CALLEESAVES(dtype)) - unsaveRegisters (ic); + { + if (accuse && !accPushed && options.useXstack) + { + emitcode ("push", "acc"); + accPushed = TRUE; + } + unsaveRegisters (ic); + } // /* if register bank was saved then pop them */ // if (restoreBank) // unsaveRBank (FUNC_REGBANK (dtype), ic, FALSE); + + if (accPushed) + emitcode ("pop", "acc"); } /*-----------------------------------------------------------------*/ @@ -2837,17 +2883,19 @@ genFunction (iCode * ic) { emitcode ("mov", "r0,%s", spname); emitcode ("inc", "%s", spname); - emitcode ("xch", "a,_bp"); + emitcode ("xch", "a,_bpx"); emitcode ("movx", "@r0,a"); emitcode ("inc", "r0"); emitcode ("mov", "a,r0"); - emitcode ("xch", "a,_bp"); + emitcode ("xch", "a,_bpx"); + emitcode ("push", "_bp"); /* save the callers stack */ + emitcode ("mov", "_bp,sp"); } else { /* set up the stack */ emitcode ("push", "_bp"); /* save the callers stack */ - emitcode ("mov", "_bp,%s", spname); + emitcode ("mov", "_bp,sp"); } } @@ -3028,40 +3076,20 @@ genEndFunction (iCode * ic) emitcode ("mov", "ea,c"); } - if ((IFFUNC_ISREENT (sym->type) || options.stackAuto) && !options.useXstack) + if ((IFFUNC_ISREENT (sym->type) || options.stackAuto))// && !options.useXstack) { - emitcode ("mov", "%s,_bp", spname); + emitcode ("mov", "sp,_bp"); } - - /* if use external stack but some variables were - added to the local stack then decrement the - local stack */ - if (options.useXstack && sym->stack) - { - char count = sym->stack; - - if ((count>3) && accIsFree) - { - emitcode ("mov", "a,sp"); - emitcode ("add", "a,#0x%02x", ((char) -count) & 0xff); - emitcode ("mov", "sp,a"); - } - else - { - while (count--) - emitcode ("dec", "sp"); - } - } - if ((IFFUNC_ISREENT (sym->type) || options.stackAuto)) { if (options.useXstack) { - emitcode ("xch", "a,_bp"); + emitcode ("pop", "_bp"); + emitcode ("xch", "a,_bpx"); emitcode ("mov", "r0,a"); emitcode ("dec", "r0"); emitcode ("movx", "a,@r0"); - emitcode ("xch", "a,_bp"); + emitcode ("xch", "a,_bpx"); emitcode ("mov", "%s,r0", spname); //read before freeing stack space (interrupts) } else @@ -4712,7 +4740,7 @@ genModOneByte (operand * left, /* if right is a literal, check it for 2^n */ if (AOP_TYPE(right) == AOP_LIT) { - unsigned char val = abs(operandLitValue(right)); + unsigned char val = abs((int) operandLitValue(right)); symbol *lbl2 = NULL; switch (val) @@ -5877,8 +5905,8 @@ genAnd (iCode * ic, iCode * ifx) } else if (IS_AOP_PREG (result)) { - MOVA (aopGet (AOP (right), offset, FALSE, FALSE)); - emitcode ("anl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE)); + MOVA (aopGet (AOP (left), offset, FALSE, TRUE)); + emitcode ("anl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE)); aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE)); } else @@ -6180,8 +6208,8 @@ genOr (iCode * ic, iCode * ifx) } else if (IS_AOP_PREG (left)) { - MOVA (aopGet (AOP (right), offset, FALSE, FALSE)); - emitcode ("orl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE)); + MOVA (aopGet (AOP (left), offset, FALSE, TRUE)); + emitcode ("orl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE)); aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE)); } else @@ -6458,8 +6486,8 @@ genXor (iCode * ic, iCode * ifx) } else if (IS_AOP_PREG (left)) { - MOVA (aopGet (AOP (right), offset, FALSE, FALSE)); - emitcode ("xrl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE)); + MOVA (aopGet (AOP (left), offset, FALSE, TRUE)); + emitcode ("xrl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE)); aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE)); } else @@ -9562,8 +9590,7 @@ genIfx (iCode * ic, iCode * popIc) genIpop (popIc); /* if the condition is a bit variable */ - if (isbit && IS_ITEMP (cond) && - SPIL_LOC (cond)) + if (isbit && IS_ITEMP (cond) && SPIL_LOC (cond)) genIfxJump (ic, SPIL_LOC (cond)->rname, NULL, NULL, NULL); else if (isbit && !IS_ITEMP (cond)) genIfxJump (ic, OP_SYMBOL (cond)->rname, NULL, NULL, NULL); @@ -9595,7 +9622,7 @@ genAddrOf (iCode * ic) it */ if (sym->stack) { - emitcode ("mov", "a,_bp"); + emitcode ("mov", "a,%s", SYM_BP (sym)); emitcode ("add", "a,#0x%02x", ((sym->stack < 0) ? ((char) (sym->stack - _G.nRegsSaved)) : ((char) sym->stack)) & 0xff); @@ -9604,7 +9631,7 @@ genAddrOf (iCode * ic) else { /* we can just move _bp */ - aopPut (AOP (IC_RESULT (ic)), "_bp", 0, isOperandVolatile (IC_RESULT (ic), FALSE)); + aopPut (AOP (IC_RESULT (ic)), SYM_BP (sym), 0, isOperandVolatile (IC_RESULT (ic), FALSE)); } /* fill the result with zero */ size = AOP_SIZE (IC_RESULT (ic)) - 1; @@ -9789,7 +9816,7 @@ release: } /*-----------------------------------------------------------------*/ -/* genJumpTab - genrates code for jump table */ +/* genJumpTab - generates code for jump table */ /*-----------------------------------------------------------------*/ static void genJumpTab (iCode * ic) diff --git a/src/mcs51/main.c b/src/mcs51/main.c index 0ea349c4..bddc63e0 100644 --- a/src/mcs51/main.c +++ b/src/mcs51/main.c @@ -727,10 +727,15 @@ PORT mcs51_port = }, { _mcs51_genExtraAreas, NULL }, { - +1, 0, 4, 1, 1, 0 + +1, /* direction (+1 = stack grows up) */ + 0, /* bank_overhead (switch between register banks) */ + 4, /* isr_overhead */ + 1, /* call_overhead (2 for return address - 1 for pre-incrementing push */ + 1, /* reent_overhead */ + 0 /* banked_overhead (switch between code banks) */ }, - /* mcs51 has an 8 bit mul */ { + /* mcs51 has an 8 bit mul */ 1, -1 }, { diff --git a/src/mcs51/peeph.def b/src/mcs51/peeph.def index 64742b9d..ca2caec2 100644 --- a/src/mcs51/peeph.def +++ b/src/mcs51/peeph.def @@ -603,15 +603,58 @@ replace { jnc %1 } +// applies to: bug-524691.c --model-large: while (uRight - uLeft > 1) replace { clr a rlc a - jnz %1 + jnz %0 } by { - ; Peephole 129 jump optimization - jc %1 + ; Peephole 129.a jump optimization + jc %0 } +// applies to: _fsdiv.c --xstack: if (mant1 < mant2) +replace { + clr a + rlc a + pop %1 + jnz %0 +} by { + ; Peephole 129.b optimized condition + pop %1 + jc %0 +} if notVolatile %1 + +// applies to: time.c --xstack: while((days += (LEAP_YEAR(year) ? 366 : 365)) <= epoch) +replace { + clr a + rlc a + pop %1 + pop %2 + jnz %0 +} by { + ; Peephole 129.c optimized condition + pop %1 + pop %2 + jc %0 +} if notVolatile %1 %2 + +// applies to: _memmove.c --xstack: if (((int)src < (int)dst) && ((((int)src)+acount) > (int)dst)) +replace { + clr a + rlc a + pop %1 + pop %2 + pop %3 + jnz %0 +} by { + ; Peephole 129.d optimized condition + pop %1 + pop %2 + pop %3 + jc %0 +} if notVolatile %1 %2 %3 + replace { mov r%1,@r%2 } by {