diff --git a/include/c64/cia.h b/include/c64/cia.h index 0578fd3..e4cd00c 100644 --- a/include/c64/cia.h +++ b/include/c64/cia.h @@ -14,8 +14,8 @@ struct CIA byte cra, crb; }; -#define cia1 (*((CIA *)0xdc00)) -#define cia2 (*((CIA *)0xdd00)) +#define cia1 (*((struct CIA *)0xdc00)) +#define cia2 (*((struct CIA *)0xdd00)) #endif diff --git a/include/c64/rasterirq.h b/include/c64/rasterirq.h index 1fb9f65..6ec4171 100644 --- a/include/c64/rasterirq.h +++ b/include/c64/rasterirq.h @@ -26,11 +26,11 @@ enum RIRQCodeIndex RIRQ_SIZE = 31 }; -struct RIRQCode +typedef struct RIRQCode { byte size; byte code[RIRQ_SIZE]; -}; +} RIRQCode; void rirq_build(RIRQCode * ic, byte size); diff --git a/include/c64/vic.h b/include/c64/vic.h index a245d32..4d8b3ff 100644 --- a/include/c64/vic.h +++ b/include/c64/vic.h @@ -75,7 +75,7 @@ struct VIC void vic_setbank(char bank); -#define vic (*((VIC *)0xd000)) +#define vic (*((struct VIC *)0xd000)) #pragma compile("vic.c") diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index cac281c..65524e0 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -7068,6 +7068,29 @@ bool NativeCodeBasicBlock::MoveAbsoluteLoadStoreUp(int at) return false; } +bool NativeCodeBasicBlock::MoveStoreXUp(int at) +{ + bool done = false; + + while (at > 0) + { + if (mIns[at - 1].ChangesXReg()) + return done; + if ((mIns[at - 1].mMode == ASMIM_ZERO_PAGE || mIns[at - 1].mMode == ASMIM_INDIRECT_Y) && mIns[at - 1].mAddress == mIns[at].mAddress) + return done; + if (mIns[at - 1].mMode == ASMIM_INDIRECT_Y && mIns[at - 1].mAddress == mIns[at].mAddress + 1) + return done; + + NativeCodeInstruction ins = mIns[at - 1]; + mIns[at - 1] = mIns[at]; + mIns[at] = ins; + at--; + done = true; + } + + return done; +} + bool NativeCodeBasicBlock::MoveLoadStoreUp(int at) { int j = at; @@ -7621,6 +7644,9 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(void) // shorten x/y register livetime #if 1 + // + // move ldy down + for (int i = 0; i + 1 < mIns.Size(); i++) { if (mIns[i].mType == ASMIT_LDY && mIns[i].mMode == ASMIM_IMMEDIATE) @@ -7635,6 +7661,19 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(void) } #endif +#if 1 + // move stx up + + for (int i = 1; i + 1 < mIns.Size(); i++) + { + if (mIns[i].mType == ASMIT_STX && mIns[i].mMode == ASMIM_ZERO_PAGE) + { + if (MoveStoreXUp(i)) + changed = true; + } + } +#endif + bool progress = false; do { progress = false; @@ -7853,6 +7892,34 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(void) mIns[i + 0].mLive |= LIVE_CPU_REG_A; progress = true; } + else if ( + mIns[i + 0].mType == ASMIT_TXA && + mIns[i + 1].mType == ASMIT_STA && mIns[i + 1].mMode == ASMIM_ZERO_PAGE) + { + mIns[i + 1].mType = ASMIT_STX; + progress = true; + } + else if ( + mIns[i + 0].mType == ASMIT_TYA && + mIns[i + 1].mType == ASMIT_STA && mIns[i + 1].mMode == ASMIM_ZERO_PAGE) + { + mIns[i + 1].mType = ASMIT_STY; + progress = true; + } + else if ( + mIns[i + 0].mType == ASMIT_TAX && + mIns[i + 1].mType == ASMIT_STX && mIns[i + 1].mMode == ASMIM_ZERO_PAGE) + { + mIns[i + 1].mType = ASMIT_STA; + progress = true; + } + else if ( + mIns[i + 0].mType == ASMIT_TAY && + mIns[i + 1].mType == ASMIT_STY && mIns[i + 1].mMode == ASMIM_ZERO_PAGE) + { + mIns[i + 1].mType = ASMIT_STA; + progress = true; + } else if ( (mIns[i + 0].mType == ASMIT_ASL || mIns[i + 0].mType == ASMIT_LSR || mIns[i + 0].mType == ASMIT_ROL || mIns[i + 0].mType == ASMIT_ROR) && mIns[i + 0].mMode == ASMIM_ZERO_PAGE && mIns[i + 1].mType == ASMIT_LDA && mIns[i + 1].mMode == ASMIM_ZERO_PAGE && mIns[i + 1].mAddress == mIns[i + 0].mAddress && !(mIns[i + 1].mLive & LIVE_MEM)) diff --git a/oscar64/NativeCodeGenerator.h b/oscar64/NativeCodeGenerator.h index 65c7c46..8132610 100644 --- a/oscar64/NativeCodeGenerator.h +++ b/oscar64/NativeCodeGenerator.h @@ -166,6 +166,7 @@ public: bool FindAddressSumY(int at, int reg, int & apos, int& breg, int& ireg); bool FindGlobalAddress(int at, int reg, int& apos); bool FindGlobalAddressSumY(int at, int reg, bool direct, int& apos, const NativeCodeInstruction * & ains, int& ireg); + bool MoveStoreXUp(int at); bool ValueForwarding(const NativeRegisterDataSet& data); diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index c2ed6a0..3a04a23 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -33,16 +33,24 @@ Declaration* Parser::ParseStructDeclaration(uint32 flags, DecType dt) { structName = mScanner->mTokenIdent; mScanner->NextToken(); - Declaration* pdec = mScope->Insert(structName, dec); - if (pdec) + Declaration* edec = mScope->Lookup(structName); + if (edec && mScanner->mToken != TK_OPEN_BRACE) { - if (pdec->mType == dt && (pdec->mFlags & DTF_DEFINED)) + dec = edec; + } + else + { + Declaration* pdec = mScope->Insert(structName, dec); + if (pdec) { - dec = pdec; - } - else - { - mErrors->Error(mScanner->mLocation, EERR_DUPLICATE_DEFINITION, "Error duplicate struct declaration", structName->mString); + if (pdec->mType == dt && (pdec->mFlags & DTF_DEFINED)) + { + dec = pdec; + } + else + { + mErrors->Error(mScanner->mLocation, EERR_DUPLICATE_DEFINITION, "Error duplicate struct declaration", structName->mString); + } } } } @@ -745,7 +753,7 @@ Declaration* Parser::ParseDeclaration(bool variable) if (ndec->mIdent) { Declaration* pdec = mScope->Insert(ndec->mIdent, ndec->mBase); - if (pdec) + if (pdec && pdec != ndec->mBase) mErrors->Error(ndec->mLocation, EERR_DUPLICATE_DEFINITION, "Duplicate type declaration", ndec->mIdent->mString); } }