* src/pic/pcode.c: changed inverted ops for DECFSZ/DECFSZW and
authortecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 20 Nov 2006 22:04:40 +0000 (22:04 +0000)
committertecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 20 Nov 2006 22:04:40 +0000 (22:04 +0000)
  INCFSZ/INCFSZW and declared them as changing Z bit,
  (insertPCodeInstruction): correctly invert the above instructions,
  fixes #1599333,
  (DoBankSelect): don't panic on po_immediates

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4473 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/pic/pcode.c

index f4154efc8508eb3cc0ed0eed1de457f77d9bf365..c83c79fe0763d3e19dd76d28534badcfd8413229 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-11-20 Raphael Neider <rneider AT web.de>
+
+       * src/pic/pcode.c: changed inverted ops for DECFSZ/DECFSZW and
+         INCFSZ/INCFSZW and declared them as changing Z bit,
+         (insertPCodeInstruction): correctly invert the above instructions,
+         fixes #1599333,
+         (DoBankSelect): don't panic on po_immediates
+
 2006-11-14 Maarten Brock <sourceforge.brock AT dse.nl>
 
        * as/link/aslink.h,
index 245385a0c1cbf61e01b7a3baf9c37a238cd61955..c1dd7d392bf28ba5fc9af81fbe7d28e3a116d3bd 100644 (file)
@@ -543,9 +543,9 @@ pCodeInstruction pciDECFSZ = {
                1,0,  // dest, bit instruction
                1,1,  // branch, skip
                0,    // literal operand
-               POC_NOP,
-               PCC_REGISTER,   // inCond
-               PCC_REGISTER    // outCond
+               POC_DECF,               // followed by BTFSC STATUS, Z --> also kills STATUS
+               PCC_REGISTER,           // inCond
+               PCC_REGISTER | PCC_Z    // outCond
 };
 
 pCodeInstruction pciDECFSZW = {
@@ -565,9 +565,9 @@ pCodeInstruction pciDECFSZW = {
                0,0,  // dest, bit instruction
                1,1,  // branch, skip
                0,    // literal operand
-               POC_NOP,
+               POC_DECFW,      // followed by BTFSC STATUS, Z --> also kills STATUS
                PCC_REGISTER,   // inCond
-               PCC_W           // outCond
+               PCC_W | PCC_Z   // outCond
 };
 
 pCodeInstruction pciGOTO = {
@@ -653,9 +653,9 @@ pCodeInstruction pciINCFSZ = {
                1,0,  // dest, bit instruction
                1,1,  // branch, skip
                0,    // literal operand
-               POC_NOP,
-               PCC_REGISTER,   // inCond
-               PCC_REGISTER    // outCond
+               POC_INCF,               // followed by BTFSC STATUS, Z --> also kills STATUS
+               PCC_REGISTER,           // inCond
+               PCC_REGISTER | PCC_Z    // outCond
 };
 
 pCodeInstruction pciINCFSZW = {
@@ -675,9 +675,9 @@ pCodeInstruction pciINCFSZW = {
                0,0,  // dest, bit instruction
                1,1,  // branch, skip
                0,    // literal operand
-               POC_NOP,
+               POC_INCFW,      // followed by BTFSC STATUS, Z --> also kills STATUS
                PCC_REGISTER,   // inCond
-               PCC_W           // outCond
+               PCC_W | PCC_Z   // outCond
 };
 
 pCodeInstruction pciIORWF = {
@@ -4538,6 +4538,21 @@ static void insertPCodeInstruction(pCodeInstruction *pci, pCodeInstruction *new_
 
                pCodeInsertAfter (pcprev, jump);
 
+               // Yuck: Cannot simply replace INCFSZ/INCFSZW/DECFSZ/DECFSZW
+               // We replace them with INCF/INCFW/DECF/DECFW followed by 'BTFSS STATUS, Z'
+               switch (PCI(pcprev)->op) {
+               case POC_INCFSZ:
+               case POC_INCFSZW:
+               case POC_DECFSZ:
+               case POC_DECFSZW:
+                   // These are turned into non-skipping instructions, so
+                   // insert 'BTFSC STATUS, Z' after pcprev
+                   pCodeInsertAfter (pcprev, newpCode(POC_BTFSC, popCopyGPR2Bit(PCOP(&pc_status), PIC_Z_BIT)));
+                   break;
+               default:
+                   // no special actions required
+                   break;
+               }
                pCodeReplace (pcprev, pCodeInstructionCopy (PCI(pcprev), 1));
                pcprev = NULL;
                pCodeInsertAfter((pCode*)pci, label);
@@ -4592,6 +4607,9 @@ static int BankSelect(pCodeInstruction *pci, int cur_bank, regs *reg)
 #if 1
        /* Always insert BANKSELs rather than try to be clever:
         * Too many bugs in optimized banksels... */
+
+       // possible optimizations:
+       // * do not emit BANKSELs for SFRs that are present in all banks (bankmsk == regmap for this register)
        insertBankSel(pci, reg->name); // Let linker choose the bank selection
        return 'L';
 #else
@@ -4763,7 +4781,11 @@ static int DoBankSelect(pCode *pc, int cur_bank) {
        if (!reg && isPCI(pc) &&
                ((PCI(pc)->inCond | PCI(pc)->outCond) & PCC_REGISTER))
        {
-           assert(!"Could not get register from instruction.");
+           if (PCI(pc)->pcop && PCI(pc)->pcop->type == PO_IMMEDIATE) {
+               // fine, this should be low(variable) --> no BANKING required
+           } else {
+               assert(!"Could not get register from instruction.");
+           }
        }
        if (reg) {
                if (IsBankChange(pc,reg,&cur_bank))