From d0fb062006a057a7675b10b19f39a3662d5b7e93 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Wed, 17 Jul 2024 12:42:15 +0200 Subject: [PATCH] Make log and exp intrinsics for const evaluation --- include/math.h | 3 +++ oscar64/Constexpr.cpp | 10 ++++++++++ oscar64/Declaration.cpp | 4 ++++ oscar64/InterCode.cpp | 18 ++++++++++++------ oscar64/InterCodeGenerator.cpp | 30 ++++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/include/math.h b/include/math.h index ac4f42e..8ad34db 100644 --- a/include/math.h +++ b/include/math.h @@ -34,6 +34,9 @@ bool isfinite(float f); #pragma intrinsic(cos) #pragma intrinsic(tan) +#pragma intrinsic(log) +#pragma intrinsic(exp) + #pragma compile("math.c") diff --git a/oscar64/Constexpr.cpp b/oscar64/Constexpr.cpp index 77555be..fe92fb8 100644 --- a/oscar64/Constexpr.cpp +++ b/oscar64/Constexpr.cpp @@ -1104,6 +1104,16 @@ ConstexprInterpreter::Value ConstexprInterpreter::EvalCall(Expression* exp, Cons mResult = Value(exp->mLocation, TheFloatTypeDeclaration); mResult.PutFloat(tan(mParams[0].GetFloat())); } + else if (!strcmp(iname->mString, "log")) + { + mResult = Value(exp->mLocation, TheFloatTypeDeclaration); + mResult.PutFloat(log(mParams[0].GetFloat())); + } + else if (!strcmp(iname->mString, "exp")) + { + mResult = Value(exp->mLocation, TheFloatTypeDeclaration); + mResult.PutFloat(::exp(mParams[0].GetFloat())); + } else mErrors->Error(exp->mLeft->mDecValue->mLocation, EERR_OBJECT_NOT_FOUND, "Unknown intrinsic function", iname); } diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 4fcc64c..60d93c6 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -1060,6 +1060,10 @@ Expression* Expression::ConstantFold(Errors * errors, LinkerSection * dataSectio d = cos(d); else if (!strcmp(iname->mString, "tan")) d = tan(d); + else if (!strcmp(iname->mString, "log")) + d = log(d); + else if (!strcmp(iname->mString, "exp")) + d = exp(d); else return this; diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index 706acb7..aada95a 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -6945,12 +6945,15 @@ bool InterCodeBasicBlock::PropagateVariableCopy(const GrowingInstructionPtrArray case IC_COPY: - for (int k = 0; k < ltemps.Size(); k++) + if (!ins->mVolatile) { - if (SameMemAndSize(ltemps[k]->mSrc[1], ins->mSrc[0])) + for (int k = 0; k < ltemps.Size(); k++) { - ins->mSrc[0] = ltemps[k]->mSrc[0]; - changed = true; + if (SameMemAndSize(ltemps[k]->mSrc[1], ins->mSrc[0])) + { + ins->mSrc[0] = ltemps[k]->mSrc[0]; + changed = true; + } } } @@ -6962,8 +6965,11 @@ bool InterCodeBasicBlock::PropagateVariableCopy(const GrowingInstructionPtrArray ltemps[j++] = ltemps[k]; } } - ltemps.SetSize(j); - ltemps.Push(ins); + if (!ins->mVolatile) + { + ltemps.SetSize(j); + ltemps.Push(ins); + } break; case IC_CALL: diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index a350188..68af5a1 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -1626,6 +1626,27 @@ void InterCodeGenerator::CopyStructSimple(InterCodeProcedure* proc, Expression * } } + bool cvol = false; + if ((vl.mType->mFlags & DTF_VOLATILE) || (vr.mType->mFlags & DTF_VOLATILE)) + cvol = true; + else + { + Declaration* dec = vl.mType->mParams; + while (!cvol && dec) + { + if (dec->mType == DT_ELEMENT && (dec->mBase->mFlags & DTF_VOLATILE)) + cvol = true; + dec = dec->mNext; + } + dec = vr.mType->mParams; + while (!cvol && dec) + { + if (dec->mType == DT_ELEMENT && (dec->mBase->mFlags & DTF_VOLATILE)) + cvol = true; + dec = dec->mNext; + } + } + // Single element structs are copied as individual value if (ne == 1 && mdec->mSize == vl.mType->mSize) { @@ -1672,6 +1693,7 @@ void InterCodeGenerator::CopyStructSimple(InterCodeProcedure* proc, Expression * cins->mSrc[1].mStride = vl.mType->mStripe; cins->mConst.mOperandSize = vl.mType->mSize; + cins->mVolatile = cvol; block->Append(cins); } } @@ -3403,6 +3425,12 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* else if (!strcmp(iname->mString, "tan")) { } + else if (!strcmp(iname->mString, "log")) + { + } + else if (!strcmp(iname->mString, "exp")) + { + } else if (!strcmp(iname->mString, "malloc")) { vr = TranslateExpression(procType, proc, block, exp->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper); @@ -3516,6 +3544,8 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* ins->mSrc[0].mOperandSize = int(nex->mDecValue->mInteger); ins->mSrc[1].mOperandSize = int(nex->mDecValue->mInteger); ins->mConst.mOperandSize = int(nex->mDecValue->mInteger); + if ((vl.mType->mBase->mFlags & DTF_VOLATILE) || (vr.mType->mBase->mFlags & DTF_VOLATILE)) + ins->mVolatile = true; block->Append(ins); return vl;