Front-end: Implement compile-time constant folding for any() and all().

This commit is contained in:
John Kessenich 2016-07-12 01:26:43 -06:00
parent 91b7533d70
commit d8509b3367
3 changed files with 54 additions and 5 deletions

View file

@ -399,6 +399,27 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType)
break;
}
case EOpAny:
{
bool result = false;
for (int i = 0; i < objectSize; i++) {
if (unionArray[i].getBConst())
result = true;
}
newConstArray[0].setBConst(result);
break;
}
case EOpAll:
{
bool result = true;
for (int i = 0; i < objectSize; i++) {
if (! unionArray[i].getBConst())
result = false;
}
newConstArray[0].setBConst(result);
break;
}
// TODO: 3.0 Functionality: unary constant folding: the rest of the ops have to be fleshed out
case EOpPackSnorm2x16:
@ -412,11 +433,8 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType)
case EOpDeterminant:
case EOpMatrixInverse:
case EOpTranspose:
case EOpAny:
case EOpAll:
return 0;
default:
assert(componentWise);
break;