From: uz Date: Sat, 29 Aug 2009 21:58:06 +0000 (+0000) Subject: Code improvements X-Git-Tag: V2.13.0rc1~175 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b098d8045e36b202bf166cb90976686530b01f1b;p=cc65 Code improvements git-svn-id: svn://svn.cc65.org/cc65/trunk@4081 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c index 168f8e5ad..212a07fb4 100644 --- a/src/cc65/codegen.c +++ b/src/cc65/codegen.c @@ -2855,7 +2855,9 @@ void g_and (unsigned Flags, unsigned long Val) case CF_CHAR: if (Flags & CF_FORCECHAR) { - if ((Val & 0xFF) != 0xFF) { + if ((Val & 0xFF) == 0x00) { + AddCodeLine ("lda #$00"); + } else if ((Val & 0xFF) != 0xFF) { AddCodeLine ("and #$%02X", (unsigned char)Val); } return; @@ -2866,26 +2868,30 @@ void g_and (unsigned Flags, unsigned long Val) if (Val <= 0xFF) { ldxconst (0); if (Val == 0) { - ldaconst (0); + AddCodeLine ("lda #$00"); } else if (Val != 0xFF) { AddCodeLine ("and #$%02X", (unsigned char)Val); } - } else if ((Val & 0xFF00) == 0xFF00) { + } else if ((Val & 0xFFFF) == 0xFF00) { + AddCodeLine ("lda #$00"); + } else if ((Val & 0xFF00) == 0xFF00) { AddCodeLine ("and #$%02X", (unsigned char)Val); } else if ((Val & 0x00FF) == 0x0000) { AddCodeLine ("txa"); AddCodeLine ("and #$%02X", (unsigned char)(Val >> 8)); AddCodeLine ("tax"); - ldaconst (0); + AddCodeLine ("lda #$00"); } else { AddCodeLine ("tay"); AddCodeLine ("txa"); AddCodeLine ("and #$%02X", (unsigned char)(Val >> 8)); AddCodeLine ("tax"); AddCodeLine ("tya"); - if ((Val & 0x00FF) != 0x00FF) { + if ((Val & 0x00FF) == 0x0000) { + AddCodeLine ("lda #$00"); + } else if ((Val & 0x00FF) != 0x00FF) { AddCodeLine ("and #$%02X", (unsigned char)Val); - } + } } } return; diff --git a/src/cc65/coptind.c b/src/cc65/coptind.c index 6746e0613..95022e6c1 100644 --- a/src/cc65/coptind.c +++ b/src/cc65/coptind.c @@ -1845,8 +1845,9 @@ unsigned OptPrecalc (CodeSeg* S) /* Get next entry */ CodeEntry* E = CS_GetEntry (S, I); - /* Get a pointer to the output registers of the insn */ + /* Get pointers to the input and output registers of the insn */ const RegContents* Out = &E->RI->Out; + const RegContents* In = &E->RI->In; /* Argument for LDn and flag */ const char* Arg = 0; @@ -1894,9 +1895,16 @@ unsigned OptPrecalc (CodeSeg* S) /* AND with 0xFF, remove */ CS_DelEntry (S, I); ++Changes; + } else if (CE_IsKnownImm (E, 0x00)) { + /* AND with 0x00, replace by lda #$00 */ + Arg = MakeHexArg (0x00); } else if (RegValIsKnown (Out->RegA)) { /* Accu AND zp with known contents */ Arg = MakeHexArg (Out->RegA); + } else if (In->RegA == 0xFF) { + /* AND but A contains 0xFF - replace by lda */ + CE_ReplaceOPC (E, OP65_LDA); + ++Changes; } break; @@ -1905,9 +1913,16 @@ unsigned OptPrecalc (CodeSeg* S) /* ORA with zero, remove */ CS_DelEntry (S, I); ++Changes; + } else if (CE_IsKnownImm (E, 0xFF)) { + /* ORA with 0xFF, replace by lda #$ff */ + Arg = MakeHexArg (0xFF); } else if (RegValIsKnown (Out->RegA)) { /* Accu AND zp with known contents */ Arg = MakeHexArg (Out->RegA); + } else if (In->RegA == 0) { + /* ORA but A contains 0x00 - replace by lda */ + CE_ReplaceOPC (E, OP65_LDA); + ++Changes; } break;