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 ...@@ -1278,7 +1278,6 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
ConstantUnion* tempConstArray = 0; ConstantUnion* tempConstArray = 0;
TIntermConstantUnion *tempNode; TIntermConstantUnion *tempNode;
bool boolNodeFlag = false;
switch(op) { switch(op) {
case EOpAdd: case EOpAdd:
tempConstArray = new ConstantUnion[objectSize]; tempConstArray = new ConstantUnion[objectSize];
...@@ -1561,24 +1560,19 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1561,24 +1560,19 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
returnType = TType(EbtBool, EbpUndefined, EvqConstExpr, objectSize); returnType = TType(EbtBool, EbpUndefined, EvqConstExpr, objectSize);
break; break;
case EOpEqual: case EOpEqual:
if (getType().getBasicType() == EbtStruct) { tempConstArray = new ConstantUnion[1];
if (!CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray))
boolNodeFlag = true; if(getType().getBasicType() == EbtStruct) {
tempConstArray->setBConst(CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray));
} else { } else {
bool boolNodeFlag = true;
for (size_t i = 0; i < objectSize; i++) { for (size_t i = 0; i < objectSize; i++) {
if (unionArray[i] != rightUnionArray[i]) { if (unionArray[i] != rightUnionArray[i]) {
boolNodeFlag = true; boolNodeFlag = false;
break; // break out of for loop break; // break out of for loop
} }
} }
} tempConstArray->setBConst(boolNodeFlag);
tempConstArray = new ConstantUnion[1];
if (!boolNodeFlag) {
tempConstArray->setBConst(true);
}
else {
tempConstArray->setBConst(false);
} }
tempNode = new TIntermConstantUnion(tempConstArray, TType(EbtBool, EbpUndefined, EvqConstExpr)); tempNode = new TIntermConstantUnion(tempConstArray, TType(EbtBool, EbpUndefined, EvqConstExpr));
...@@ -1587,24 +1581,19 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1587,24 +1581,19 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
return tempNode; return tempNode;
case EOpNotEqual: case EOpNotEqual:
if (getType().getBasicType() == EbtStruct) { tempConstArray = new ConstantUnion[1];
if (CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray))
boolNodeFlag = true; if(getType().getBasicType() == EbtStruct) {
tempConstArray->setBConst(!CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray));
} else { } else {
bool boolNodeFlag = false;
for (size_t i = 0; i < objectSize; i++) { for (size_t i = 0; i < objectSize; i++) {
if (unionArray[i] == rightUnionArray[i]) { if (unionArray[i] != rightUnionArray[i]) {
boolNodeFlag = true; boolNodeFlag = true;
break; // break out of for loop break; // break out of for loop
} }
} }
} tempConstArray->setBConst(boolNodeFlag);
tempConstArray = new ConstantUnion[1];
if (!boolNodeFlag) {
tempConstArray->setBConst(true);
}
else {
tempConstArray->setBConst(false);
} }
tempNode = new TIntermConstantUnion(tempConstArray, TType(EbtBool, EbpUndefined, EvqConstExpr)); 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