More functions for reu library

This commit is contained in:
drmortalwombat 2023-02-25 21:02:06 +01:00
parent 0bb470939f
commit 4117c9a553
11 changed files with 285 additions and 2 deletions

View File

@ -65,11 +65,22 @@ int main(void)
testmuli( 1, -1, -1); testmuli( 1, -1, -1);
testmuli(5, 5, 25); testmuli(5, 5, 25);
testmuli( 127, 255, 32385); testmuli( 127, 255, 32385);
testmuli(-127, 255, -32385); testmuli(-127, 255, -32385);
testmuli( 127, -255, -32385); testmuli( 127, -255, -32385);
testmuli(-127, -255, 32385); testmuli(-127, -255, 32385);
testmuli( 1237, 1024, 1266688l);
testmuli(-1237, 1024, -1266688l);
testmuli( 1237, -1024, -1266688l);
testmuli(-1237, -1024, 1266688l);
testmuli( 1024, 1237, 1266688l);
testmuli( 1024,-1237, -1266688l);
testmuli( -1024, 1237, -1266688l);
testmuli( -1024,-1237, 1266688l);
testdivi( 1, 1, 1); testdivi( 1, 1, 1);
testdivi(-1, 1, -1); testdivi(-1, 1, -1);
testdivi( 1, -1, -1); testdivi( 1, -1, -1);
@ -119,5 +130,14 @@ int main(void)
d -= 10000; d -= 10000;
} }
long e = 0, f = 0;
for(long i=0; i<177000l; i += 1000)
{
assert( 1024 * i == e);
assert(-1024 * i == f);
e += 1024000l;
f -= 1024000l;
}
return 0; return 0;
} }

View File

@ -1,2 +1,97 @@
#include "reu.h" #include "reu.h"
int reu_count_pages(void)
{
volatile char c, d;
c = 0;
reu_store(0, &c, 1);
reu_load(0, &d, 1);
if (d == 0)
{
c = 0x47;
reu_store(0, &c, 1);
reu_load(0, &d, 1);
if (d == 0x47)
{
for(int i=1; i<256; i++)
{
long l = (long)i << 16;
c = 0x47;
reu_store(l, &c, 1);
c = 0x00;
reu_store(0, &c, 1);
reu_load(l, &d, 1);
if (d != 0x47)
return i;
}
return 256;
}
}
return 0;
}
inline void reu_store(unsigned long raddr, const volatile char * sp, unsigned length)
{
reu.laddr = (word)sp;
reu.raddr = raddr;
reu.rbank = raddr >> 16;
reu.length = length;
reu.ctrl = REU_CTRL_INCL | REU_CTRL_INCR;
reu.cmd = REU_CMD_EXEC | REU_CMD_FF00 | REU_CMD_STORE;
}
inline void reu_load(unsigned long raddr, volatile char * dp, unsigned length)
{
reu.laddr = (word)dp;
reu.raddr = raddr;
reu.rbank = raddr >> 16;
reu.length = length;
reu.ctrl = REU_CTRL_INCL | REU_CTRL_INCR;
reu.cmd = REU_CMD_EXEC | REU_CMD_FF00 | REU_CMD_LOAD;
}
inline void reu_fill(unsigned long raddr, char c, unsigned length)
{
reu.laddr = (word)&c;
reu.raddr = raddr;
reu.rbank = raddr >> 16;
reu.length = length;
reu.ctrl = REU_CTRL_FIXL | REU_CTRL_INCR;
reu.cmd = REU_CMD_EXEC | REU_CMD_FF00 | REU_CMD_STORE;
}
inline void reu_load2d(unsigned long raddr, volatile char * dp, char height, unsigned width, unsigned stride)
{
reu.ctrl = REU_CTRL_INCL | REU_CTRL_INCR;
reu.laddr = (word)dp;
for(char i=0; i<height; i++)
{
reu.length = width;
reu.raddr = raddr;
reu.rbank = raddr >> 16;
reu.cmd = REU_CMD_EXEC | REU_CMD_FF00 | REU_CMD_LOAD;
raddr += stride;
}
}
inline void reu_load2dpage(unsigned long raddr, volatile char * dp, char height, unsigned width, unsigned stride)
{
reu.ctrl = REU_CTRL_INCL | REU_CTRL_INCR;
reu.laddr = (word)dp;
reu.rbank = raddr >> 16;
for(char i=0; i<height; i++)
{
reu.length = width;
reu.raddr = raddr;
reu.cmd = REU_CMD_EXEC | REU_CMD_FF00 | REU_CMD_LOAD;
raddr += stride;
}
}

View File

@ -44,6 +44,24 @@ struct REU
#define reu (*((struct REU *)0xdf00)) #define reu (*((struct REU *)0xdf00))
// Count the number of 64k pages in the REU, the test is destructive
int reu_count_pages(void);
// Copy an array of data from C64 memory to the REU memory
inline void reu_store(unsigned long raddr, const volatile char * sp, unsigned length);
// Copy an array of data from REU memory to the C64 memory
inline void reu_load(unsigned long raddr, volatile char * dp, unsigned length);
// Fill an array of data in the REU with a single value
inline void reu_fill(unsigned long raddr, char c, unsigned length);
// Copy a 2D array from REU memory to the C64 memory. The stride parameter
// is the distance of two rows in REU memory
inline void reu_load2d(unsigned long raddr, volatile char * dp, char height, unsigned width, unsigned stride);
inline void reu_load2dpage(unsigned long raddr, volatile char * dp, char height, unsigned width, unsigned stride);
#pragma compile("reu.c") #pragma compile("reu.c")

View File

@ -126,6 +126,7 @@ enum ExpressionType
EX_INDEX, EX_INDEX,
EX_QUALIFY, EX_QUALIFY,
EX_CALL, EX_CALL,
EX_INLINE,
EX_LIST, EX_LIST,
EX_RETURN, EX_RETURN,
EX_SEQUENCE, EX_SEQUENCE,

View File

@ -445,6 +445,7 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec)
Analyze(exp->mLeft, procDec); Analyze(exp->mLeft, procDec);
return exp->mDecValue->mBase; return exp->mDecValue->mBase;
case EX_CALL: case EX_CALL:
case EX_INLINE:
ldec = Analyze(exp->mLeft, procDec); ldec = Analyze(exp->mLeft, procDec);
if ((ldec->mFlags & DTF_INTRINSIC) && !ldec->mValue) if ((ldec->mFlags & DTF_INTRINSIC) && !ldec->mValue)
{ {

View File

@ -4383,6 +4383,18 @@ static void OptimizeAddress(InterInstruction * ins, const GrowingInstructionPtrA
} }
static bool ispow2(int64 v)
{
if (v > 0)
{
while (!(v & 1))
v >>= 1;
return v == 1;
}
return 0;
}
void InterCodeBasicBlock::CheckValueUsage(InterInstruction * ins, const GrowingInstructionPtrArray& tvalue, const GrowingVariableArray& staticVars, FastNumberSet& fsingle) void InterCodeBasicBlock::CheckValueUsage(InterInstruction * ins, const GrowingInstructionPtrArray& tvalue, const GrowingVariableArray& staticVars, FastNumberSet& fsingle)
{ {
switch (ins->mCode) switch (ins->mCode)
@ -4791,6 +4803,20 @@ void InterCodeBasicBlock::CheckValueUsage(InterInstruction * ins, const GrowingI
ins->mSrc[0].mTemp = -1; ins->mSrc[0].mTemp = -1;
ins->mSrc[0].mIntConst = 3; ins->mSrc[0].mIntConst = 3;
} }
else if (ins->mSrc[0].mType == IT_INT32 && ispow2(ins->mSrc[1].mIntConst))
{
__int64 s = ins->mSrc[1].mIntConst;
ins->mOperator = IA_SHL;
ins->mSrc[1].mTemp = ins->mSrc[0].mTemp;
ins->mSrc[1].mType = ins->mSrc[0].mType;
ins->mSrc[0].mTemp = -1;
ins->mSrc[0].mIntConst = 0;
while (s > 1)
{
ins->mSrc[0].mIntConst++;
s >>= 1;
}
}
} }
#endif #endif
@ -4834,6 +4860,17 @@ void InterCodeBasicBlock::CheckValueUsage(InterInstruction * ins, const GrowingI
ins->mOperator = IA_SHL; ins->mOperator = IA_SHL;
ins->mSrc[0].mIntConst = 3; ins->mSrc[0].mIntConst = 3;
} }
else if (ins->mSrc[1].mType == IT_INT32 && ispow2(ins->mSrc[0].mIntConst))
{
__int64 s = ins->mSrc[0].mIntConst;
ins->mOperator = IA_SHL;
ins->mSrc[0].mIntConst = 0;
while (s > 1)
{
ins->mSrc[0].mIntConst++;
s >>= 1;
}
}
} }
else if (ins->mOperator == IA_MODU && (ins->mSrc[0].mIntConst & (ins->mSrc[0].mIntConst - 1)) == 0) else if (ins->mOperator == IA_MODU && (ins->mSrc[0].mIntConst & (ins->mSrc[0].mIntConst - 1)) == 0)
{ {

View File

@ -2041,6 +2041,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
} }
case EX_CALL: case EX_CALL:
case EX_INLINE:
{ {
if (exp->mLeft->mType == EX_CONSTANT && exp->mLeft->mDecValue->mType == DT_CONST_FUNCTION && (exp->mLeft->mDecValue->mFlags & DTF_INTRINSIC)) if (exp->mLeft->mType == EX_CONSTANT && exp->mLeft->mDecValue->mType == DT_CONST_FUNCTION && (exp->mLeft->mDecValue->mFlags & DTF_INTRINSIC))
{ {
@ -2217,7 +2218,9 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
} }
} }
if (inlineConstexpr) if (exp->mType == EX_INLINE)
doInline = true;
else if (inlineConstexpr)
doInline = true; doInline = true;
else if (exp->mLeft->mDecValue->mFlags & DTF_INLINE) else if (exp->mLeft->mDecValue->mFlags & DTF_INLINE)
{ {

View File

@ -14726,6 +14726,49 @@ bool NativeCodeBasicBlock::ExpandADCToBranch(NativeCodeProcedure* proc)
iblock->mIns.Push(mIns[i + 6]); iblock->mIns.Push(mIns[i + 6]);
mIns.SetSize(i + 4);
iblock->mIns[0].mType = ASMIT_INC;
iblock->mTrueJump = fblock;
iblock->mBranch = ASMIT_JMP;
mTrueJump = fblock;
mFalseJump = iblock;
mBranch = ASMIT_BNE;
break;
}
if (mIns[i + 0].mType == ASMIT_TYA &&
mIns[i + 1].mType == ASMIT_CLC &&
mIns[i + 2].mType == ASMIT_ADC && mIns[i + 2].mMode == ASMIM_IMMEDIATE && mIns[i + 2].mAddress == 1 &&
mIns[i + 3].mType == ASMIT_TAY &&
mIns[i + 4].mType == ASMIT_LDA &&
mIns[i + 5].mType == ASMIT_ADC && mIns[i + 5].mMode == ASMIM_IMMEDIATE && mIns[i + 5].mAddress == 0 &&
mIns[i + 6].mType == ASMIT_STA && mIns[i + 4].SameEffectiveAddress(mIns[i + 6]) &&
HasAsmInstructionMode(ASMIT_INC, mIns[i + 6].mMode) &&
!(mIns[i + 6].mLive & (LIVE_CPU_REG_C | LIVE_CPU_REG_Z)))
{
changed = true;
NativeCodeBasicBlock* iblock = proc->AllocateBlock();
NativeCodeBasicBlock* fblock = proc->AllocateBlock();
fblock->mTrueJump = mTrueJump;
fblock->mFalseJump = mFalseJump;
fblock->mBranch = mBranch;
mIns[i + 0].mType = ASMIT_NOP; mIns[i + 1].mMode = ASMIM_IMPLIED;
mIns[i + 1].mType = ASMIT_NOP;
mIns[i + 2].mType = ASMIT_NOP; mIns[i + 2].mMode = ASMIM_IMPLIED;
mIns[i + 3].mType = ASMIT_INY; mIns[i + 3].mLive |= LIVE_CPU_REG_Z;
fblock->mIns.Push(mIns[i + 4]);
for (int j = i + 7; j < mIns.Size(); j++)
fblock->mIns.Push(mIns[j]);
iblock->mIns.Push(mIns[i + 6]);
mIns.SetSize(i + 4); mIns.SetSize(i + 4);
iblock->mIns[0].mType = ASMIT_INC; iblock->mIns[0].mType = ASMIT_INC;
@ -35581,7 +35624,7 @@ void NativeCodeProcedure::RebuildEntry(void)
void NativeCodeProcedure::Optimize(void) void NativeCodeProcedure::Optimize(void)
{ {
CheckFunc = !strcmp(mInterProc->mIdent->mString, "digger_decide"); CheckFunc = !strcmp(mInterProc->mIdent->mString, "rscreen_copy");
#if 1 #if 1
int step = 0; int step = 0;

View File

@ -15,6 +15,7 @@ Parser::Parser(Errors* errors, Scanner* scanner, CompilationUnits* compilationUn
mUnrollLoop = 0; mUnrollLoop = 0;
mUnrollLoopPage = false; mUnrollLoopPage = false;
mInlineCall = false;
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)
mCharMap[i] = i; mCharMap[i] = i;
@ -1666,6 +1667,10 @@ Expression* Parser::ParsePostfixExpression(void)
mScanner->NextToken(); mScanner->NextToken();
Expression* nexp = new Expression(mScanner->mLocation, EX_CALL); Expression* nexp = new Expression(mScanner->mLocation, EX_CALL);
if (mInlineCall)
nexp->mType = EX_INLINE;
mInlineCall = false;
nexp->mLeft = exp; nexp->mLeft = exp;
nexp->mDecType = exp->mDecType->mBase; nexp->mDecType = exp->mDecType->mBase;
if (mScanner->mToken != TK_CLOSE_PARENTHESIS) if (mScanner->mToken != TK_CLOSE_PARENTHESIS)
@ -3935,6 +3940,13 @@ void Parser::ParsePragma(void)
ConsumeToken(TK_CLOSE_PARENTHESIS); ConsumeToken(TK_CLOSE_PARENTHESIS);
} }
else if (!strcmp(mScanner->mTokenIdent->mString, "callinline"))
{
mScanner->NextToken();
ConsumeToken(TK_OPEN_PARENTHESIS);
ConsumeToken(TK_CLOSE_PARENTHESIS);
mInlineCall = true;
}
else else
{ {
mScanner->NextToken(); mScanner->NextToken();

View File

@ -26,6 +26,7 @@ protected:
char mCharMap[256]; char mCharMap[256];
int mUnrollLoop; int mUnrollLoop;
bool mUnrollLoopPage; bool mUnrollLoopPage;
bool mInlineCall;
uint8* ParseStringLiteral(int msize); uint8* ParseStringLiteral(int msize);

View File

@ -124,6 +124,12 @@
} }
"Entry" "Entry"
{ {
"MsmKey" = "8:_1EB5CE4736F1417ABD479DFD92E19FD2"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_1ED10FB93DDA4801BF72003E21B2CE55" "MsmKey" = "8:_1ED10FB93DDA4801BF72003E21B2CE55"
"OwnerKey" = "8:_UNDEFINED" "OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED"
@ -358,6 +364,12 @@
} }
"Entry" "Entry"
{ {
"MsmKey" = "8:_64C12019C1114C3282B32CD6B866C20A"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_65286F9E8B2F496B95A50DA63A1F0D5B" "MsmKey" = "8:_65286F9E8B2F496B95A50DA63A1F0D5B"
"OwnerKey" = "8:_UNDEFINED" "OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED"
@ -1427,6 +1439,26 @@
"IsDependency" = "11:FALSE" "IsDependency" = "11:FALSE"
"IsolateTo" = "8:" "IsolateTo" = "8:"
} }
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_1EB5CE4736F1417ABD479DFD92E19FD2"
{
"SourcePath" = "8:..\\include\\c64\\reu.c"
"TargetName" = "8:reu.c"
"Tag" = "8:"
"Folder" = "8:_247D4CAD3CB843B3A8A4DC2D90F47C28"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_1ED10FB93DDA4801BF72003E21B2CE55" "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_1ED10FB93DDA4801BF72003E21B2CE55"
{ {
"SourcePath" = "8:..\\samples\\games\\missile.c" "SourcePath" = "8:..\\samples\\games\\missile.c"
@ -2207,6 +2239,26 @@
"IsDependency" = "11:FALSE" "IsDependency" = "11:FALSE"
"IsolateTo" = "8:" "IsolateTo" = "8:"
} }
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_64C12019C1114C3282B32CD6B866C20A"
{
"SourcePath" = "8:..\\include\\c64\\reu.h"
"TargetName" = "8:reu.h"
"Tag" = "8:"
"Folder" = "8:_247D4CAD3CB843B3A8A4DC2D90F47C28"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_65286F9E8B2F496B95A50DA63A1F0D5B" "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_65286F9E8B2F496B95A50DA63A1F0D5B"
{ {
"SourcePath" = "8:..\\samples\\resources\\maze3dchars.bin" "SourcePath" = "8:..\\samples\\resources\\maze3dchars.bin"