MCPcopy Create free account
hub / github.com/alecazam/kram / ArithmeticOpResultType

Function ArithmeticOpResultType

hlslparser/src/HLSLParser.cpp:1531–1579  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1529static bool _initIntrinsics = InitIntrinsics();
1530
1531HLSLBaseType ArithmeticOpResultType(HLSLBinaryOp binaryOp, HLSLBaseType t1, HLSLBaseType t2)
1532{
1533 // check that both are same numeric types
1534
1535 // add, sub, div are similar
1536 // mul is it's own test
1537
1538 // most mixing of types is invalid here
1539
1540 if (IsNumericTypeEqual(t1, t2)) {
1541 bool isSameDimensions = IsDimensionEqual(t1, t2);
1542
1543 if (IsScalarType(t1) && IsScalarType(t2)) {
1544 if (isSameDimensions) return t1;
1545 }
1546 else if (IsVectorType(t1) && IsVectorType(t2)) {
1547 if (isSameDimensions) return t1;
1548 }
1549 else if (IsMatrixType(t1) && IsMatrixType(t2)) {
1550 if (isSameDimensions) return t1;
1551 }
1552
1553 else if ((binaryOp == HLSLBinaryOp_Add || binaryOp == HLSLBinaryOp_Sub) &&
1554 (IsScalarType(t1) || IsScalarType(t2))) {
1555 // allow v + 1, and 1 - v
1556 return (IsVectorType(t1) || IsMatrixType(t1)) ? t1 : t2;
1557 }
1558
1559 else if ((binaryOp == HLSLBinaryOp_Mul || binaryOp == HLSLBinaryOp_Div) &&
1560 (IsScalarType(t1) || IsScalarType(t2))) {
1561 // v * s
1562 return (IsVectorType(t1) || IsMatrixType(t1)) ? t1 : t2;
1563 }
1564
1565 // this has to check dimension across the mul
1566 else if (binaryOp == HLSLBinaryOp_Mul) {
1567 bool isSameCrossDimension = IsCrossDimensionEqual(t1, t2);
1568
1569 if (IsMatrixType(t1) && IsVectorType(t2)) {
1570 if (isSameCrossDimension) return t2;
1571 }
1572 else if (IsVectorType(t1) && IsMatrixType(t2)) {
1573 if (isSameCrossDimension) return t1;
1574 }
1575 }
1576 }
1577
1578 return HLSLBaseType_Unknown;
1579}
1580
1581// Priority of the ? : operator.
1582const int _conditionalOpPriority = 1;

Callers 1

GetBinaryOpResultTypeFunction · 0.85

Calls 6

IsNumericTypeEqualFunction · 0.85
IsDimensionEqualFunction · 0.85
IsScalarTypeFunction · 0.85
IsVectorTypeFunction · 0.85
IsMatrixTypeFunction · 0.85
IsCrossDimensionEqualFunction · 0.85

Tested by

no test coverage detected