@@ -2118,7 +2118,7 @@ llvm::LogicalResult tosa::ReshapeOp::verify() {
21182118// return failure if val is not a constant
21192119// set zp to -1 if val is non-zero float or val is not integer nor float
21202120// otherwise set zp to val's constant value
2121- static FailureOr<int64_t > getZeroPoint (Value val) {
2121+ static FailureOr<int64_t > getZeroPoint (Value val, bool signExtend ) {
21222122 ElementsAttr zpAttr;
21232123 if (!matchPattern (val, m_Constant (&zpAttr))) {
21242124 return failure ();
@@ -2135,7 +2135,10 @@ static FailureOr<int64_t> getZeroPoint(Value val) {
21352135 }
21362136
21372137 if (llvm::isa<IntegerType>(zpElemType)) {
2138- return zpAttr.getValues <APInt>()[0 ].getSExtValue ();
2138+ if (signExtend)
2139+ return zpAttr.getValues <APInt>()[0 ].getSExtValue ();
2140+ else
2141+ return zpAttr.getValues <APInt>()[0 ].getZExtValue ();
21392142 }
21402143
21412144 // return non-zero value to trigger error check
@@ -2175,8 +2178,7 @@ static LogicalResult verifyZeroPoint(tosa::RescaleOp op, Value zpVal,
21752178 return op.emitOpError ()
21762179 << " expect " << tensorName << " _zp of 0, got " << zp;
21772180 }
2178- if (zpElemType.isInteger (16 ) && tensorUnsigned &&
2179- zp != static_cast <int16_t >(32768 )) {
2181+ if (zpElemType.isInteger (16 ) && tensorUnsigned && zp != 32768 ) {
21802182 return op.emitOpError () << " expect " << tensorName
21812183 << " _zp of 0 or 32768 for unsigned int16 "
21822184 << tensorName << " , got " << zp;
@@ -2186,30 +2188,30 @@ static LogicalResult verifyZeroPoint(tosa::RescaleOp op, Value zpVal,
21862188 return success ();
21872189}
21882190
2189- #define ZERO_POINT_HELPER (OP, OPERAND_NAME ) \
2191+ #define ZERO_POINT_HELPER (OP, OPERAND_NAME, SIGN_EXTEND ) \
21902192 FailureOr<int64_t > tosa::OP::get##OPERAND_NAME##ZeroPoint() { \
2191- return getZeroPoint (get##OPERAND_NAME##Zp ()); \
2193+ return getZeroPoint (get##OPERAND_NAME##Zp (), SIGN_EXTEND); \
21922194 } \
21932195 LogicalResult tosa::OP::verify##OPERAND_NAME##ZeroPoint(int64_t zp) { \
21942196 return verifyZeroPoint (*this , get##OPERAND_NAME##Zp (), zp, #OPERAND_NAME); \
21952197 }
21962198
2197- ZERO_POINT_HELPER (Conv2DOp, Input)
2198- ZERO_POINT_HELPER(Conv2DOp, Weight)
2199- ZERO_POINT_HELPER(Conv3DOp, Input)
2200- ZERO_POINT_HELPER(Conv3DOp, Weight)
2201- ZERO_POINT_HELPER(DepthwiseConv2DOp, Input)
2202- ZERO_POINT_HELPER(DepthwiseConv2DOp, Weight)
2203- ZERO_POINT_HELPER(TransposeConv2DOp, Input)
2204- ZERO_POINT_HELPER(TransposeConv2DOp, Weight)
2205- ZERO_POINT_HELPER(AvgPool2dOp, Input)
2206- ZERO_POINT_HELPER(AvgPool2dOp, Output)
2207- ZERO_POINT_HELPER(MatMulOp, A)
2208- ZERO_POINT_HELPER(MatMulOp, B)
2209- ZERO_POINT_HELPER(NegateOp, Input1)
2210- ZERO_POINT_HELPER(NegateOp, Output)
2211- ZERO_POINT_HELPER(RescaleOp, Input)
2212- ZERO_POINT_HELPER(RescaleOp, Output)
2199+ ZERO_POINT_HELPER (Conv2DOp, Input, true )
2200+ ZERO_POINT_HELPER(Conv2DOp, Weight, true )
2201+ ZERO_POINT_HELPER(Conv3DOp, Input, true )
2202+ ZERO_POINT_HELPER(Conv3DOp, Weight, true )
2203+ ZERO_POINT_HELPER(DepthwiseConv2DOp, Input, true )
2204+ ZERO_POINT_HELPER(DepthwiseConv2DOp, Weight, true )
2205+ ZERO_POINT_HELPER(TransposeConv2DOp, Input, true )
2206+ ZERO_POINT_HELPER(TransposeConv2DOp, Weight, true )
2207+ ZERO_POINT_HELPER(AvgPool2dOp, Input, true )
2208+ ZERO_POINT_HELPER(AvgPool2dOp, Output, true )
2209+ ZERO_POINT_HELPER(MatMulOp, A, true )
2210+ ZERO_POINT_HELPER(MatMulOp, B, true )
2211+ ZERO_POINT_HELPER(NegateOp, Input1, true )
2212+ ZERO_POINT_HELPER(NegateOp, Output, true )
2213+ ZERO_POINT_HELPER(RescaleOp, Input, !getInputUnsigned() )
2214+ ZERO_POINT_HELPER(RescaleOp, Output, !getOutputUnsigned() )
22132215#undef ZERO_POINT_HELPER
22142216
22152217LogicalResult tosa::TransposeOp::inferReturnTypeComponents (
0 commit comments