@@ -1050,33 +1050,32 @@ static LogicalResult buildAllocOp(ComponentLoweringState &componentState,
1050
1050
llvm::json::Array result;
1051
1051
result.reserve (std::max (static_cast <int >(shape.size ()), 1 ));
1052
1052
1053
- bool isSignlessOrUnsigned = memtype.getElementType ().isSignlessInteger () ||
1054
- memtype.getElementType ().isUnsignedInteger ();
1053
+ Type elemType = memtype.getElementType ();
1054
+ bool isSigned =
1055
+ !elemType.isSignlessInteger () && !elemType.isUnsignedInteger ();
1055
1056
for (uint64_t bitValue : flattenedVals) {
1056
1057
llvm::json::Value value = 0 ;
1057
1058
if (isFloat) {
1058
- // we cast to `double` and let downstream calyx to deal with the actual
1059
- // value's precision handling
1059
+ // We cast to `double` and let downstream calyx to deal with the actual
1060
+ // value's precision handling.
1060
1061
value = bit_cast<double >(bitValue);
1061
1062
} else {
1062
- APInt apInt (/* numBits=*/ elmTyBitWidth, bitValue,
1063
- /* isSigned=*/ !isSignlessOrUnsigned);
1064
- if (!isSignlessOrUnsigned) {
1065
- // need to explicitly assign it to an int variable before storing to a
1066
- // json Value, otherwise it will interpret the raw data
1067
- int64_t signedValue = apInt.getSExtValue ();
1068
- value = signedValue;
1069
- } else
1063
+ APInt apInt (/* numBits=*/ elmTyBitWidth, bitValue, isSigned);
1064
+ // The conditional ternary operation will cause the `value` to interpret
1065
+ // the underlying data as unsigned regardless `isSigned` or not.
1066
+ if (isSigned)
1067
+ value = static_cast <int64_t >(apInt.getSExtValue ());
1068
+ else
1070
1069
value = apInt.getZExtValue ();
1071
1070
}
1072
- result.push_back (value);
1071
+ result.push_back (std::move ( value) );
1073
1072
}
1074
1073
1075
1074
componentState.setDataField (memoryOp.getName (), result);
1076
1075
std::string numType =
1077
1076
memtype.getElementType ().isInteger () ? " bitnum" : " ieee754_float" ;
1078
- componentState.setFormat (memoryOp.getName (), numType,
1079
- /* isSigned= */ !isSignlessOrUnsigned, elmTyBitWidth);
1077
+ componentState.setFormat (memoryOp.getName (), numType, isSigned,
1078
+ elmTyBitWidth);
1080
1079
1081
1080
return success ();
1082
1081
}
0 commit comments