]> git.sur5r.net Git - cc65/commitdiff
Improved code generation, better tracking.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 1 Sep 2009 10:07:02 +0000 (10:07 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 1 Sep 2009 10:07:02 +0000 (10:07 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@4108 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/cc65/codeent.c
src/cc65/codegen.c

index aed401d88a0214e86c7424d309d39818ba88f7b9..546786b7ac99573fbf429550e7f9be3c2b09b277 100644 (file)
@@ -531,33 +531,36 @@ void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs)
 
        case OP65_AND:
                    if (RegValIsKnown (In->RegA)) {
-               if (CE_IsConstImm (E)) {
-                   Out->RegA = In->RegA & (short) E->Num;
-               } else if (E->AM == AM65_ZP) {
-                   switch (GetKnownReg (E->Use & REG_ZP, In)) {
-                       case REG_TMP1:
-                           Out->RegA = In->RegA & In->Tmp1;
-                           break;
-                       case REG_PTR1_LO:
-                           Out->RegA = In->RegA & In->Ptr1Lo;
-                           break;
-                       case REG_PTR1_HI:
-                           Out->RegA = In->RegA & In->Ptr1Hi;
-                           break;
-                       case REG_SREG_LO:
-                           Out->RegA = In->RegA & In->SRegLo;
-                           break;
-                       case REG_SREG_HI:
-                           Out->RegA = In->RegA & In->SRegHi;
-                           break;
-                       default:
-                           Out->RegA = UNKNOWN_REGVAL;
-                           break;
-                   }
-               } else {
-                   Out->RegA = UNKNOWN_REGVAL;
-               }
-           }
+               if (CE_IsConstImm (E)) {
+                   Out->RegA = In->RegA & (short) E->Num;
+               } else if (E->AM == AM65_ZP) {
+                   switch (GetKnownReg (E->Use & REG_ZP, In)) {
+                       case REG_TMP1:
+                           Out->RegA = In->RegA & In->Tmp1;
+                           break;
+                       case REG_PTR1_LO:
+                           Out->RegA = In->RegA & In->Ptr1Lo;
+                           break;
+                       case REG_PTR1_HI:
+                           Out->RegA = In->RegA & In->Ptr1Hi;
+                           break;
+                       case REG_SREG_LO:
+                           Out->RegA = In->RegA & In->SRegLo;
+                           break;
+                       case REG_SREG_HI:
+                           Out->RegA = In->RegA & In->SRegHi;
+                           break;
+                       default:
+                           Out->RegA = UNKNOWN_REGVAL;
+                           break;
+                   }
+                } else {
+                   Out->RegA = UNKNOWN_REGVAL;
+               }
+           } else if (CE_IsKnownImm (E, 0)) {
+                /* A and $00 does always give zero */
+                Out->RegA = 0;
+            }
            break;
 
        case OP65_ASL:
@@ -663,7 +666,7 @@ void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs)
                        break;
                    case REG_SREG_LO:
                        Out->SRegLo = (In->SRegLo - 1) & 0xFF;
-                       break;
+                       break;
                    case REG_SREG_HI:
                        Out->SRegHi = (In->SRegHi - 1) & 0xFF;
                        break;
@@ -822,7 +825,7 @@ void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs)
                if (In->RegA == 0xFF) {
                    Out->RegA = 0xFF;
                }
-               if (In->RegX == 0xFF) {
+               if (In->RegX == 0xFF) {
                     Out->RegX = 0xFF;
                 }
             } else if (FindBoolCmpCond (E->Arg) != CMP_INV) {
@@ -875,7 +878,7 @@ void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs)
                        Out->RegX = In->Tmp1;
                        break;
                    case REG_PTR1_LO:
-                       Out->RegX = In->Ptr1Lo;
+                       Out->RegX = In->Ptr1Lo;
                        break;
                    case REG_PTR1_HI:
                        Out->RegX = In->Ptr1Hi;
@@ -928,7 +931,7 @@ void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs)
 
        case OP65_LSR:
            if (E->AM == AM65_ACC && RegValIsKnown (In->RegA)) {
-               Out->RegA = (In->RegA >> 1) & 0xFF;
+               Out->RegA = (In->RegA >> 1) & 0xFF;
            } else if (E->AM == AM65_ZP) {
                switch (GetKnownReg (E->Chg & REG_ZP, In)) {
                    case REG_TMP1:
@@ -981,11 +984,14 @@ void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs)
                            Out->RegA = UNKNOWN_REGVAL;
                            break;
                    }
-               } else {
-                   /* A is now unknown */
-                   Out->RegA = UNKNOWN_REGVAL;
-               }
-           }
+               } else {
+                   /* A is now unknown */
+                   Out->RegA = UNKNOWN_REGVAL;
+               }
+           } else if (CE_IsKnownImm (E, 0xFF)) {
+                /* ORA with 0xFF does always give 0xFF */
+                Out->RegA = 0xFF;
+            }
            break;
 
        case OP65_PHA:
@@ -1034,7 +1040,7 @@ void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs)
                        Out->SRegLo = UNKNOWN_REGVAL;
                        break;
                    case REG_SREG_HI:
-                       Out->SRegHi = UNKNOWN_REGVAL;
+                       Out->SRegHi = UNKNOWN_REGVAL;
                        break;
                }
            } else if (E->AM == AM65_ZPX) {
index 6756cf853f3c896265a81232e3d794d81fb13e79..2f67a07fcce5bc338c8f05f6032543268a3ca470 100644 (file)
@@ -814,22 +814,22 @@ void g_getstatic (unsigned flags, unsigned long label, long offs)
 
 
 
-void g_getlocal (unsigned flags, int offs)
+void g_getlocal (unsigned Flags, int Offs)
 /* Fetch specified local object (local var). */
 {
-    offs -= StackPtr;
-    CheckLocalOffs (offs);
-    switch (flags & CF_TYPE) {
+    Offs -= StackPtr;
+    switch (Flags & CF_TYPE) {
 
         case CF_CHAR:
-            if ((flags & CF_FORCECHAR) || (flags & CF_TEST)) {
-                ldyconst (offs);
+            CheckLocalOffs (Offs);
+            if ((Flags & CF_FORCECHAR) || (Flags & CF_TEST)) {
+                ldyconst (Offs);
                 AddCodeLine ("lda (sp),y");
             } else {
-                ldyconst (offs);
+                ldyconst (Offs);
                 AddCodeLine ("ldx #$00");
                 AddCodeLine ("lda (sp),y");
-               if ((flags & CF_UNSIGNED) == 0) {
+               if ((Flags & CF_UNSIGNED) == 0) {
                     unsigned L = GetLocalLabel();
                    AddCodeLine ("bpl %s", LocalLabelName (L));
                    AddCodeLine ("dex");
@@ -839,34 +839,39 @@ void g_getlocal (unsigned flags, int offs)
             break;
 
         case CF_INT:
-            CheckLocalOffs (offs + 1);
-            if (flags & CF_TEST) {
-               ldyconst (offs + 1);
+            CheckLocalOffs (Offs + 1);
+            AddCodeLine ("ldy #$%02X", (unsigned char) (Offs+1));
+            if (Flags & CF_TEST) {
                AddCodeLine ("lda (sp),y");
                 AddCodeLine ("dey");
                 AddCodeLine ("ora (sp),y");
-            } else {
-                ldyconst (offs+1);
+            } else if (IS_Get (&CodeSizeFactor) < 165) {
                 AddCodeLine ("jsr ldaxysp");
+            } else {
+               AddCodeLine ("lda (sp),y");
+                AddCodeLine ("tax");
+                AddCodeLine ("dey");
+                AddCodeLine ("lda (sp),y");
             }
             break;
 
         case CF_LONG:
-            ldyconst (offs+3);
+            CheckLocalOffs (Offs + 3);
+            AddCodeLine ("ldy #$%02X", (unsigned char) (Offs+3));
             AddCodeLine ("jsr ldeaxysp");
-            if (flags & CF_TEST) {
-               g_test (flags);
+            if (Flags & CF_TEST) {
+               g_test (Flags);
             }
             break;
 
         default:
-            typeerror (flags);
+            typeerror (Flags);
     }
 }
 
 
 
-void g_getind (unsigned flags, unsigned offs)
+void g_getind (unsigned Flags, unsigned Offs)
 /* Fetch the specified object type indirect through the primary register
  * into the primary register
  */
@@ -875,46 +880,46 @@ void g_getind (unsigned flags, unsigned offs)
      * the primary. This way we get an easy addition and use the low byte
      * as the offset
      */
-    offs = MakeByteOffs (flags, offs);
+    Offs = MakeByteOffs (Flags, Offs);
 
     /* Handle the indirect fetch */
-    switch (flags & CF_TYPE) {
+    switch (Flags & CF_TYPE) {
 
         case CF_CHAR:
             /* Character sized */
-            if (flags & CF_UNSIGNED) {
-                ldyconst (offs);
+            if (Flags & CF_UNSIGNED) {
+                ldyconst (Offs);
                 AddCodeLine ("jsr ldauidx");
             } else {
-                ldyconst (offs);
+                ldyconst (Offs);
                 AddCodeLine ("jsr ldaidx");
             }
             break;
 
         case CF_INT:
-            if (flags & CF_TEST) {
-               ldyconst (offs);
+            if (Flags & CF_TEST) {
+               ldyconst (Offs);
                 AddCodeLine ("sta ptr1");
                 AddCodeLine ("stx ptr1+1");
                 AddCodeLine ("lda (ptr1),y");
                 AddCodeLine ("iny");
                 AddCodeLine ("ora (ptr1),y");
             } else {
-                ldyconst (offs+1);
+                ldyconst (Offs+1);
                 AddCodeLine ("jsr ldaxidx");
             }
             break;
 
         case CF_LONG:
-            ldyconst (offs+3);
+            ldyconst (Offs+3);
             AddCodeLine ("jsr ldeaxidx");
-            if (flags & CF_TEST) {
-                g_test (flags);
+            if (Flags & CF_TEST) {
+                g_test (Flags);
             }
             break;
 
         default:
-            typeerror (flags);
+            typeerror (Flags);
 
     }
 }