From 670bb6fb5c7996b6eb0e3412f12ada73f2c2635b Mon Sep 17 00:00:00 2001 From: tecodev Date: Thu, 16 Mar 2006 09:32:20 +0000 Subject: [PATCH] * src/pic16/genarith.c (genAddLit): simplified and fixed case where the left operand is shorter than the result (c* = lit-c* + int), fixes bug #1450796 * src/pic16/gen.c (genRightShift): check IS_SYMOP before accessing OP_SYMBOL git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4064 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 8 ++++++++ src/pic16/gen.c | 4 ++-- src/pic16/genarith.c | 34 ++++++++++++---------------------- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1fc24424..b4c509ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-03-16 Raphael Neider + + * src/pic16/genarith.c (genAddLit): simplified and fixed case where + the left operand is shorter than the result (c* = lit-c* + int), + fixes bug #1450796 + * src/pic16/gen.c (genRightShift): check IS_SYMOP before accessing + OP_SYMBOL + 2006-03-14 Vangelis Rokas * src/.version: increased version number to 2.5.5 diff --git a/src/pic16/gen.c b/src/pic16/gen.c index 2e76a461..d2c7f036 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -10511,10 +10511,10 @@ static void genRightShift (iCode *ic) { /* load FSR0 with address of/from op according to is_LitOp() or if lit is 1 */ void pic16_loadFSR0(operand *op, int lit) { - if(OP_SYMBOL(op)->remat || is_LitOp( op )) { + if((IS_SYMOP(op) && OP_SYMBOL(op)->remat) || is_LitOp( op )) { pic16_emitpcode(POC_LFSR, pic16_popGetLit2(0, pic16_popGet(AOP(op), 0))); } else { - assert (!OP_SYMBOL(op)->remat); + assert (!IS_SYMOP(op) || !OP_SYMBOL(op)->remat); // set up FSR0 with address of result pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(op),0), pic16_popCopyReg(&pic16_pc_fsr0l))); pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(op),1), pic16_popCopyReg(&pic16_pc_fsr0h))); diff --git a/src/pic16/genarith.c b/src/pic16/genarith.c index e8ada618..7766ae7d 100644 --- a/src/pic16/genarith.c +++ b/src/pic16/genarith.c @@ -654,7 +654,6 @@ static void genAddLit (iCode *ic, int lit) } } - } */ } @@ -716,30 +715,21 @@ static void genAddLit (iCode *ic, int lit) //pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),0,FALSE,FALSE)); emitMOVWF(result,0); while(--size) { - lit >>= 8; - if(lit & 0xff) { - if(clear_carry) { - /* The ls byte of the lit must've been zero - that - means we don't have to deal with carry */ - - pic16_emitpcode(POC_MOVLW, pic16_popGetLit(lit & 0xff)); - pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(left),offset)); - pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offset)); - - clear_carry = 0; - - } else { - pic16_emitpcode(POC_MOVLW, pic16_popGetLit(lit & 0xff)); - pic16_emitpcode(POC_ADDFWC, pic16_popGet(AOP(left),offset)); - pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offset)); - } - + pic16_emitpcode(POC_MOVLW, pic16_popGetLit(lit & 0xff)); + if (offset < AOP_SIZE(left)) { + pic16_emitpcode(clear_carry ? POC_ADDFW : POC_ADDFWC, pic16_popGet(AOP(left),offset)); + pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offset)); } else { - pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result),offset)); - pic16_mov2w(AOP(left),offset); - pic16_emitpcode(POC_ADDWFC, pic16_popGet(AOP(result),offset)); + pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result),offset)); + if (!SPEC_USIGN(operandType(IC_LEFT(ic)))) { + /* sign-extend left (in result) */ + pic16_emitpcode (POC_BTFSC, pic16_newpCodeOpBit_simple(AOP(left),AOP_SIZE(left)-1,7)); + pic16_emitpcode(POC_SETF, pic16_popGet(AOP(result),offset)); + } + pic16_emitpcode(clear_carry ? POC_ADDWF : POC_ADDWFC, pic16_popGet(AOP(result),offset)); } + clear_carry = 0; offset++; } } -- 2.30.2