Make log and exp intrinsics for const evaluation
This commit is contained in:
parent
c229a27992
commit
d0fb062006
|
@ -34,6 +34,9 @@ bool isfinite(float f);
|
||||||
#pragma intrinsic(cos)
|
#pragma intrinsic(cos)
|
||||||
#pragma intrinsic(tan)
|
#pragma intrinsic(tan)
|
||||||
|
|
||||||
|
#pragma intrinsic(log)
|
||||||
|
#pragma intrinsic(exp)
|
||||||
|
|
||||||
#pragma compile("math.c")
|
#pragma compile("math.c")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1104,6 +1104,16 @@ ConstexprInterpreter::Value ConstexprInterpreter::EvalCall(Expression* exp, Cons
|
||||||
mResult = Value(exp->mLocation, TheFloatTypeDeclaration);
|
mResult = Value(exp->mLocation, TheFloatTypeDeclaration);
|
||||||
mResult.PutFloat(tan(mParams[0].GetFloat()));
|
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
|
else
|
||||||
mErrors->Error(exp->mLeft->mDecValue->mLocation, EERR_OBJECT_NOT_FOUND, "Unknown intrinsic function", iname);
|
mErrors->Error(exp->mLeft->mDecValue->mLocation, EERR_OBJECT_NOT_FOUND, "Unknown intrinsic function", iname);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1060,6 +1060,10 @@ Expression* Expression::ConstantFold(Errors * errors, LinkerSection * dataSectio
|
||||||
d = cos(d);
|
d = cos(d);
|
||||||
else if (!strcmp(iname->mString, "tan"))
|
else if (!strcmp(iname->mString, "tan"))
|
||||||
d = tan(d);
|
d = tan(d);
|
||||||
|
else if (!strcmp(iname->mString, "log"))
|
||||||
|
d = log(d);
|
||||||
|
else if (!strcmp(iname->mString, "exp"))
|
||||||
|
d = exp(d);
|
||||||
else
|
else
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
|
|
|
@ -6945,12 +6945,15 @@ bool InterCodeBasicBlock::PropagateVariableCopy(const GrowingInstructionPtrArray
|
||||||
|
|
||||||
|
|
||||||
case IC_COPY:
|
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];
|
if (SameMemAndSize(ltemps[k]->mSrc[1], ins->mSrc[0]))
|
||||||
changed = true;
|
{
|
||||||
|
ins->mSrc[0] = ltemps[k]->mSrc[0];
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6962,8 +6965,11 @@ bool InterCodeBasicBlock::PropagateVariableCopy(const GrowingInstructionPtrArray
|
||||||
ltemps[j++] = ltemps[k];
|
ltemps[j++] = ltemps[k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ltemps.SetSize(j);
|
if (!ins->mVolatile)
|
||||||
ltemps.Push(ins);
|
{
|
||||||
|
ltemps.SetSize(j);
|
||||||
|
ltemps.Push(ins);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IC_CALL:
|
case IC_CALL:
|
||||||
|
|
|
@ -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
|
// Single element structs are copied as individual value
|
||||||
if (ne == 1 && mdec->mSize == vl.mType->mSize)
|
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->mSrc[1].mStride = vl.mType->mStripe;
|
||||||
|
|
||||||
cins->mConst.mOperandSize = vl.mType->mSize;
|
cins->mConst.mOperandSize = vl.mType->mSize;
|
||||||
|
cins->mVolatile = cvol;
|
||||||
block->Append(cins);
|
block->Append(cins);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3403,6 +3425,12 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
||||||
else if (!strcmp(iname->mString, "tan"))
|
else if (!strcmp(iname->mString, "tan"))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
else if (!strcmp(iname->mString, "log"))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else if (!strcmp(iname->mString, "exp"))
|
||||||
|
{
|
||||||
|
}
|
||||||
else if (!strcmp(iname->mString, "malloc"))
|
else if (!strcmp(iname->mString, "malloc"))
|
||||||
{
|
{
|
||||||
vr = TranslateExpression(procType, proc, block, exp->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper);
|
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[0].mOperandSize = int(nex->mDecValue->mInteger);
|
||||||
ins->mSrc[1].mOperandSize = int(nex->mDecValue->mInteger);
|
ins->mSrc[1].mOperandSize = int(nex->mDecValue->mInteger);
|
||||||
ins->mConst.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);
|
block->Append(ins);
|
||||||
|
|
||||||
return vl;
|
return vl;
|
||||||
|
|
Loading…
Reference in New Issue