Commit 26ea8f5e by Alexis Hetu Committed by Alexis Hétu

Fixed not equal folding

The not equal folding logic was wrong. It would end the loop as soon as it found equal components, which was checking if ALL components are not equal, but that's not how not equal works, it should return true if ANY component is not equal. I also refactored it because it was hard to follow, with the boolNodeFlag variable being used upside down of the result. Change-Id: I704f26f2fd31a1cc637f5d7601409de8161c5b80 Reviewed-on: https://swiftshader-review.googlesource.com/5211Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 049a187a
......@@ -1278,7 +1278,6 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
ConstantUnion* tempConstArray = 0;
TIntermConstantUnion *tempNode;
bool boolNodeFlag = false;
switch(op) {
case EOpAdd:
tempConstArray = new ConstantUnion[objectSize];
......@@ -1561,24 +1560,19 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
returnType = TType(EbtBool, EbpUndefined, EvqConstExpr, objectSize);
break;
case EOpEqual:
if (getType().getBasicType() == EbtStruct) {
if (!CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray))
boolNodeFlag = true;
tempConstArray = new ConstantUnion[1];
if(getType().getBasicType() == EbtStruct) {
tempConstArray->setBConst(CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray));
} else {
bool boolNodeFlag = true;
for (size_t i = 0; i < objectSize; i++) {
if (unionArray[i] != rightUnionArray[i]) {
boolNodeFlag = true;
boolNodeFlag = false;
break; // break out of for loop
}
}
}
tempConstArray = new ConstantUnion[1];
if (!boolNodeFlag) {
tempConstArray->setBConst(true);
}
else {
tempConstArray->setBConst(false);
tempConstArray->setBConst(boolNodeFlag);
}
tempNode = new TIntermConstantUnion(tempConstArray, TType(EbtBool, EbpUndefined, EvqConstExpr));
......@@ -1587,24 +1581,19 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
return tempNode;
case EOpNotEqual:
if (getType().getBasicType() == EbtStruct) {
if (CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray))
boolNodeFlag = true;
tempConstArray = new ConstantUnion[1];
if(getType().getBasicType() == EbtStruct) {
tempConstArray->setBConst(!CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray));
} else {
bool boolNodeFlag = false;
for (size_t i = 0; i < objectSize; i++) {
if (unionArray[i] == rightUnionArray[i]) {
if (unionArray[i] != rightUnionArray[i]) {
boolNodeFlag = true;
break; // break out of for loop
}
}
}
tempConstArray = new ConstantUnion[1];
if (!boolNodeFlag) {
tempConstArray->setBConst(true);
}
else {
tempConstArray->setBConst(false);
tempConstArray->setBConst(boolNodeFlag);
}
tempNode = new TIntermConstantUnion(tempConstArray, TType(EbtBool, EbpUndefined, EvqConstExpr));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment