From 4010ec16975ed368963fc9f5bb689f1dbe4c23c4 Mon Sep 17 00:00:00 2001 From: tecodev Date: Mon, 16 May 2005 19:11:21 +0000 Subject: [PATCH] * src/pic16/gen.{c,h}: s/mov2f/pic16_mov2f made public * src/pic16/genarith.c (genAddit): fixed bug 1202480 * src/pic16/pcode.{c,h} (pic16_newpCodeOpBit_simple): NEW convenience function for bit access git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3763 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 6 ++++ src/pic16/gen.c | 23 +++++++------ src/pic16/gen.h | 1 + src/pic16/genarith.c | 78 ++++++++++++++++++++++++++++++++++++++++++-- src/pic16/pcode.c | 8 +++++ src/pic16/pcode.h | 1 + 6 files changed, 103 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index ff698de0..06c3be88 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-05-16 Raphael Neider + * src/pic16/gen.{c,h}: s/mov2f/pic16_mov2f made public + * src/pic16/genarith.c (genAddit): fixed bug 1202480 + * src/pic16/pcode.{c,h} (pic16_newpCodeOpBit_simple): NEW + convenience function for bit access + 2005-05-15 Maarten Brock * device/lib/printf_large.c: fixed bug 1193299 diff --git a/src/pic16/gen.c b/src/pic16/gen.c index 5b678647..5e31af41 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -68,7 +68,6 @@ extern void pic16_printpBlock(FILE *of, pBlock *pb); static asmop *newAsmop (short type); static pCodeOp *pic16_popRegFromString(char *str, int size, int offset, operand *op); extern pCode *pic16_newpCodeAsmDir(char *asdir, char *argfmt, ...); -static void mov2f(asmop *dst, asmop *src, int offset); static void mov2fp(pCodeOp *dst, asmop *src, int offset); static pCodeOp *pic16_popRegFromIdx(int rIdx); @@ -2383,7 +2382,7 @@ void pic16_mov2w (asmop *aop, int offset) pic16_emitpcode(POC_MOVFW,pic16_popGet(aop,offset)); } -static void mov2f(asmop *dst, asmop *src, int offset) +void pic16_mov2f(asmop *dst, asmop *src, int offset) { if(is_LitAOp(src)) { pic16_emitpcode(POC_MOVLW, pic16_popGet(src, offset)); @@ -2791,7 +2790,7 @@ static void genUminusFloat(operand *op,operand *result) size = AOP_SIZE(op); while(size--) { - mov2f(AOP(result), AOP(op), offset); + pic16_mov2f(AOP(result), AOP(op), offset); offset++; } @@ -5818,7 +5817,7 @@ static void genCmp (operand *left,operand *right, pctemp = pic16_popGetTempReg(1); pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),size)); - pic16_emitpcode(POC_MOVWF, pctemp); //pic16_pic16_popRegFromIdx(pic16_Gstack_base_addr)); + pic16_emitpcode(POC_MOVWF, pctemp); //pic16_popRegFromIdx(pic16_Gstack_base_addr)); pic16_emitpcode(POC_MOVLW, pic16_popGetLit(0x80)); pic16_emitpcode(POC_XORWF, pctemp); //pic16_popRegFromIdx(pic16_Gstack_base_addr)); pic16_emitpcode(POC_XORFW, pic16_popGet(AOP(right),size)); @@ -9551,7 +9550,7 @@ static void genLeftShift (iCode *ic) #endif { /* we don't know if left is a literal or a register, take care -- VR */ - mov2f(AOP(result), AOP(left), offset); + pic16_mov2f(AOP(result), AOP(left), offset); } offset++; } @@ -9583,7 +9582,7 @@ static void genLeftShift (iCode *ic) #if 1 /* this is already done, why change it? */ if (!pic16_sameRegs(AOP(left),AOP(result))) { - mov2f(AOP(result), AOP(left), 0); + pic16_mov2f(AOP(result), AOP(left), 0); } #endif @@ -9734,7 +9733,7 @@ static void genLeftShift (iCode *ic) } else { /* we don't know if left is a literal or a register, take care -- VR */ - mov2f(AOP(result), AOP(left), offset); + pic16_mov2f(AOP(result), AOP(left), offset); } offset++; } @@ -9763,7 +9762,7 @@ static void genLeftShift (iCode *ic) tlbl = newiTempLabel(NULL); if (!pic16_sameRegs(AOP(left),AOP(result))) { - mov2f(AOP(result), AOP(left), 0); + pic16_mov2f(AOP(result), AOP(left), 0); // pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0)); // pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),0)); @@ -10050,7 +10049,7 @@ static void genRightShiftLiteral (operand *left, if(shCount == 0){ assert (res_size <= lsize); while (res_size--) { - mov2f (AOP(result), AOP(left), res_size); + pic16_mov2f (AOP(result), AOP(left), res_size); } // for } @@ -10429,7 +10428,7 @@ static void genGenericShift (iCode *ic, int isShiftLeft) { // (e.g. char c = 0x100 << -3 will become c = 0x00 >> 3 == 0x00 instad of 0x20) // This is fine, as it only occurs for left shifting with negative count which is not standardized! for (offset=0; offset < min(AOP_SIZE(left), AOP_SIZE(result)); offset++) { - mov2f (AOP(result),AOP(left), offset); + pic16_mov2f (AOP(result),AOP(left), offset); } // for // if result is longer than left, fill with zeros (or sign) @@ -13012,7 +13011,7 @@ static void genCast (iCode *ic) while (size--) { if(offset < AOP_SIZE(right)) { DEBUGpic16_emitcode("; ***","%s %d - pointer cast3 ptype = 0x%x",__FUNCTION__,__LINE__, p_type); - mov2f(AOP(result), AOP(right), offset); + pic16_mov2f(AOP(result), AOP(right), offset); /* if ((AOP_TYPE(right) == AOP_PCODE) && AOP(right)->aopu.pcop->type == PO_IMMEDIATE) { @@ -13103,7 +13102,7 @@ static void genCast (iCode *ic) while (size--) { if(!_G.resDirect) - mov2f(AOP(result), AOP(right), offset); + pic16_mov2f(AOP(result), AOP(right), offset); offset++; } diff --git a/src/pic16/gen.h b/src/pic16/gen.h index 497b2999..9f2d6059 100644 --- a/src/pic16/gen.h +++ b/src/pic16/gen.h @@ -203,6 +203,7 @@ const char *pic16_pCodeOpType( pCodeOp *pcop); int pic16_my_powof2 (unsigned long num); void pic16_mov2w (asmop *aop, int offset); +void pic16_mov2f(asmop *dst, asmop *src, int offset); void dumpiCode(iCode *lic); diff --git a/src/pic16/genarith.c b/src/pic16/genarith.c index 318aa298..1a556baf 100644 --- a/src/pic16/genarith.c +++ b/src/pic16/genarith.c @@ -416,6 +416,7 @@ static void adjustArithmeticResult(iCode *ic) } #endif +#if 0 /*-----------------------------------------------------------------*/ /* genAddlit - generates code for addition */ /*-----------------------------------------------------------------*/ @@ -438,6 +439,7 @@ static void genAddLit2byte (operand *result, int offr, int lit) } } +#endif static void emitMOVWF(operand *reg, int offset) { @@ -456,19 +458,90 @@ static void emitMOVWF(operand *reg, int offset) static void genAddLit (iCode *ic, int lit) { - int size,same; - int lo; + int size,sizeL,same; + int i, llit; operand *result; operand *left; + sym_link *lleft; FENTRY; left = IC_LEFT(ic); + lleft = operandType (left); result = IC_RESULT(ic); same = pic16_sameRegs(AOP(left), AOP(result)); size = pic16_getDataSize(result); + sizeL = pic16_getDataSize(left); + llit = lit; + +#define MIN(a,b) (((a) < (b)) ? (a) : (b)) + /* move left to result -- possibly sign extend */ + for (i=0; i < MIN(size, sizeL); i++) { + pic16_mov2f (AOP(result), AOP(left), i); + } // for i +#undef MIN + + /* extend to result size */ + if (IS_UNSIGNED(lleft)) { + /* zero-extend */ + for (i = sizeL; i < size; i++) { + pic16_emitpcode (POC_CLRF, pic16_popGet (AOP(result), i)); + } // for i + } else { + /* sign-extend */ + if (size == sizeL + 1) { + pic16_emitpcode (POC_CLRF, pic16_popGet (AOP(result), sizeL)); + pic16_emitpcode (POC_BTFSC, pic16_newpCodeOpBit_simple (AOP(left),sizeL-1,7)); + pic16_emitpcode (POC_SETF, pic16_popGet (AOP(result), sizeL)); + } else { + pic16_emitpcode (POC_CLRF, pic16_popCopyReg (&pic16_pc_wreg)); + pic16_emitpcode (POC_BTFSC, pic16_newpCodeOpBit_simple (AOP(left),sizeL-1,7)); + pic16_emitpcode (POC_SETF, pic16_popCopyReg (&pic16_pc_wreg)); + + for (i=sizeL; i < size; i++) { + pic16_emitpcode (POC_MOVWF, pic16_popGet (AOP(result), i)); + } // for i + } // if + } // if (SIGNED) + + /* special cases */ + if (lit == 0) { + /* nothing to do */ + } else if (lit == 1) { + switch (size) { + case 1: + /* handled below */ + break; + case 2: + pic16_emitpcode (POC_INFSNZ, pic16_popGet (AOP(result), 0)); + break; + default: + assert (size > 2); + pic16_emitpcode (POC_INCF, pic16_popGet(AOP(result), 0)); + for (i=1; i < size-1; i++) { + emitSKPNC; /* a jump here saves up to 2(size-2)cycles */ + pic16_emitpcode (POC_INCF, pic16_popGet(AOP(result), i)); + } // for i + emitSKPNC; + break; + } // switch + + pic16_emitpcode (POC_INCF, pic16_popGet (AOP(result), size-1)); + } else { + /* general case */ + + /* add literal to result */ + for (i=0; i < size; i++) { + pic16_emitpcode (POC_MOVLW, pic16_popGetLit (llit)); + llit >>= 8; /* FIXME: arithmetic right shift for signed literals? */ + pic16_emitpcode (i == 0 ? POC_ADDWF : POC_ADDWFC, + pic16_popGet (AOP(result), i)); + } + } + +#if 0 if(same) { @@ -739,6 +812,7 @@ static void genAddLit (iCode *ic, int lit) } } } +#endif } /*-----------------------------------------------------------------*/ diff --git a/src/pic16/pcode.c b/src/pic16/pcode.c index c2f6ae2e..9f77d9d6 100644 --- a/src/pic16/pcode.c +++ b/src/pic16/pcode.c @@ -32,6 +32,8 @@ #include "ralloc.h" #include "device.h" +extern char *pic16_aopGet (struct asmop *aop, int offset, bool bit16, bool dname); + #if defined(__BORLANDC__) || defined(_MSC_VER) #define STRCASECMP stricmp #define inline @@ -4224,6 +4226,12 @@ pCodeOp *pic16_newpCodeOpBit(char *s, int bit, int inBitSpace, PIC_OPTYPE subt) return pcop; } +pCodeOp *pic16_newpCodeOpBit_simple (struct asmop *op, int offs, int bit) +{ + return pic16_newpCodeOpBit (pic16_aopGet(op,offs,FALSE,FALSE), + bit, 0, PO_GPR_REGISTER); +} + /*-----------------------------------------------------------------* * pCodeOp *pic16_newpCodeOpReg(int rIdx) - allocate a new register diff --git a/src/pic16/pcode.h b/src/pic16/pcode.h index c14840e1..b0820479 100644 --- a/src/pic16/pcode.h +++ b/src/pic16/pcode.h @@ -1019,6 +1019,7 @@ pCodeOp *pic16_newpCodeOpImmd(char *name, int offset, int index, int code_space) pCodeOp *pic16_newpCodeOpLit(int lit); pCodeOp *pic16_newpCodeOpLit2(int lit, pCodeOp *arg2); pCodeOp *pic16_newpCodeOpBit(char *name, int bit,int inBitSpace, PIC_OPTYPE subt); +pCodeOp *pic16_newpCodeOpBit_simple (struct asmop *op, int offs, int bit); pCodeOp *pic16_newpCodeOpRegFromStr(char *name); pCodeOp *pic16_newpCodeOpReg(int rIdx); pCodeOp *pic16_newpCodeOp(char *name, PIC_OPTYPE p); -- 2.47.2