Make log and exp intrinsics for const evaluation

This commit is contained in:
drmortalwombat 2024-07-17 12:42:15 +02:00
parent c229a27992
commit d0fb062006
5 changed files with 59 additions and 6 deletions

View File

@ -34,6 +34,9 @@ bool isfinite(float f);
#pragma intrinsic(cos)
#pragma intrinsic(tan)
#pragma intrinsic(log)
#pragma intrinsic(exp)
#pragma compile("math.c")

View File

@ -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);
}

View File

@ -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;

View File

@ -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:

View File

@ -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;