@@ -1716,9 +1716,10 @@ IEEEFloat::opStatus IEEEFloat::remainder(const IEEEFloat &rhs) {
1716
1716
int parts = partCount ();
1717
1717
integerPart *x = new integerPart[parts];
1718
1718
bool ignored;
1719
- fs = V.convertToInteger (x, parts * integerPartWidth, true ,
1720
- rmNearestTiesToEven, &ignored);
1721
- if (fs==opInvalidOp) {
1719
+ fs = V.convertToInteger (makeMutableArrayRef (x, parts),
1720
+ parts * integerPartWidth, true , rmNearestTiesToEven,
1721
+ &ignored);
1722
+ if (fs == opInvalidOp) {
1722
1723
delete[] x;
1723
1724
return fs;
1724
1725
}
@@ -1756,9 +1757,10 @@ IEEEFloat::opStatus IEEEFloat::mod(const IEEEFloat &rhs) {
1756
1757
int parts = partCount ();
1757
1758
integerPart *x = new integerPart[parts];
1758
1759
bool ignored;
1759
- fs = V.convertToInteger (x, parts * integerPartWidth, true ,
1760
- rmTowardZero, &ignored);
1761
- if (fs==opInvalidOp) {
1760
+ fs = V.convertToInteger (makeMutableArrayRef (x, parts),
1761
+ parts * integerPartWidth, true , rmTowardZero,
1762
+ &ignored);
1763
+ if (fs == opInvalidOp) {
1762
1764
delete[] x;
1763
1765
return fs;
1764
1766
}
@@ -2051,7 +2053,7 @@ IEEEFloat::opStatus IEEEFloat::convert(const fltSemantics &toSemantics,
2051
2053
Note that for conversions to integer type the C standard requires
2052
2054
round-to-zero to always be used. */
2053
2055
IEEEFloat::opStatus IEEEFloat::convertToSignExtendedInteger (
2054
- integerPart * parts, unsigned int width, bool isSigned,
2056
+ MutableArrayRef< integerPart> parts, unsigned int width, bool isSigned,
2055
2057
roundingMode rounding_mode, bool *isExact) const {
2056
2058
lostFraction lost_fraction;
2057
2059
const integerPart *src;
@@ -2064,9 +2066,10 @@ IEEEFloat::opStatus IEEEFloat::convertToSignExtendedInteger(
2064
2066
return opInvalidOp;
2065
2067
2066
2068
dstPartsCount = partCountForBits (width);
2069
+ assert (dstPartsCount <= parts.size () && " Integer too big" );
2067
2070
2068
2071
if (category == fcZero) {
2069
- APInt::tcSet (parts, 0 , dstPartsCount);
2072
+ APInt::tcSet (parts. data () , 0 , dstPartsCount);
2070
2073
// Negative zero can't be represented as an int.
2071
2074
*isExact = !sign;
2072
2075
return opOK;
@@ -2078,7 +2081,7 @@ IEEEFloat::opStatus IEEEFloat::convertToSignExtendedInteger(
2078
2081
the destination. */
2079
2082
if (exponent < 0 ) {
2080
2083
/* Our absolute value is less than one; truncate everything. */
2081
- APInt::tcSet (parts, 0 , dstPartsCount);
2084
+ APInt::tcSet (parts. data () , 0 , dstPartsCount);
2082
2085
/* For exponent -1 the integer bit represents .5, look at that.
2083
2086
For smaller exponents leftmost truncated bit is 0. */
2084
2087
truncatedBits = semantics->precision -1U - exponent;
@@ -2094,11 +2097,13 @@ IEEEFloat::opStatus IEEEFloat::convertToSignExtendedInteger(
2094
2097
if (bits < semantics->precision ) {
2095
2098
/* We truncate (semantics->precision - bits) bits. */
2096
2099
truncatedBits = semantics->precision - bits;
2097
- APInt::tcExtract (parts, dstPartsCount, src, bits, truncatedBits);
2100
+ APInt::tcExtract (parts. data () , dstPartsCount, src, bits, truncatedBits);
2098
2101
} else {
2099
2102
/* We want at least as many bits as are available. */
2100
- APInt::tcExtract (parts, dstPartsCount, src, semantics->precision , 0 );
2101
- APInt::tcShiftLeft (parts, dstPartsCount, bits - semantics->precision );
2103
+ APInt::tcExtract (parts.data (), dstPartsCount, src, semantics->precision ,
2104
+ 0 );
2105
+ APInt::tcShiftLeft (parts.data (), dstPartsCount,
2106
+ bits - semantics->precision );
2102
2107
truncatedBits = 0 ;
2103
2108
}
2104
2109
}
@@ -2110,15 +2115,15 @@ IEEEFloat::opStatus IEEEFloat::convertToSignExtendedInteger(
2110
2115
truncatedBits);
2111
2116
if (lost_fraction != lfExactlyZero &&
2112
2117
roundAwayFromZero (rounding_mode, lost_fraction, truncatedBits)) {
2113
- if (APInt::tcIncrement (parts, dstPartsCount))
2118
+ if (APInt::tcIncrement (parts. data () , dstPartsCount))
2114
2119
return opInvalidOp; /* Overflow. */
2115
2120
}
2116
2121
} else {
2117
2122
lost_fraction = lfExactlyZero;
2118
2123
}
2119
2124
2120
2125
/* Step 3: check if we fit in the destination. */
2121
- unsigned int omsb = APInt::tcMSB (parts, dstPartsCount) + 1 ;
2126
+ unsigned int omsb = APInt::tcMSB (parts. data () , dstPartsCount) + 1 ;
2122
2127
2123
2128
if (sign) {
2124
2129
if (!isSigned) {
@@ -2129,15 +2134,16 @@ IEEEFloat::opStatus IEEEFloat::convertToSignExtendedInteger(
2129
2134
/* It takes omsb bits to represent the unsigned integer value.
2130
2135
We lose a bit for the sign, but care is needed as the
2131
2136
maximally negative integer is a special case. */
2132
- if (omsb == width && APInt::tcLSB (parts, dstPartsCount) + 1 != omsb)
2137
+ if (omsb == width &&
2138
+ APInt::tcLSB (parts.data (), dstPartsCount) + 1 != omsb)
2133
2139
return opInvalidOp;
2134
2140
2135
2141
/* This case can happen because of rounding. */
2136
2142
if (omsb > width)
2137
2143
return opInvalidOp;
2138
2144
}
2139
2145
2140
- APInt::tcNegate (parts, dstPartsCount);
2146
+ APInt::tcNegate (parts. data () , dstPartsCount);
2141
2147
} else {
2142
2148
if (omsb >= width + !isSigned)
2143
2149
return opInvalidOp;
@@ -2159,11 +2165,10 @@ IEEEFloat::opStatus IEEEFloat::convertToSignExtendedInteger(
2159
2165
the original value. This is almost equivalent to result==opOK,
2160
2166
except for negative zeroes.
2161
2167
*/
2162
- IEEEFloat::opStatus IEEEFloat::convertToInteger (integerPart *parts,
2163
- unsigned int width,
2164
- bool isSigned,
2165
- roundingMode rounding_mode,
2166
- bool *isExact) const {
2168
+ IEEEFloat::opStatus
2169
+ IEEEFloat::convertToInteger (MutableArrayRef<integerPart> parts,
2170
+ unsigned int width, bool isSigned,
2171
+ roundingMode rounding_mode, bool *isExact) const {
2167
2172
opStatus fs;
2168
2173
2169
2174
fs = convertToSignExtendedInteger (parts, width, isSigned, rounding_mode,
@@ -2173,6 +2178,7 @@ IEEEFloat::opStatus IEEEFloat::convertToInteger(integerPart *parts,
2173
2178
unsigned int bits, dstPartsCount;
2174
2179
2175
2180
dstPartsCount = partCountForBits (width);
2181
+ assert (dstPartsCount <= parts.size () && " Integer too big" );
2176
2182
2177
2183
if (category == fcNaN)
2178
2184
bits = 0 ;
@@ -2181,9 +2187,9 @@ IEEEFloat::opStatus IEEEFloat::convertToInteger(integerPart *parts,
2181
2187
else
2182
2188
bits = width - isSigned;
2183
2189
2184
- APInt::tcSetLeastSignificantBits (parts, dstPartsCount, bits);
2190
+ APInt::tcSetLeastSignificantBits (parts. data () , dstPartsCount, bits);
2185
2191
if (sign && isSigned)
2186
- APInt::tcShiftLeft (parts, dstPartsCount, width - 1 );
2192
+ APInt::tcShiftLeft (parts. data () , dstPartsCount, width - 1 );
2187
2193
}
2188
2194
2189
2195
return fs;
@@ -4293,11 +4299,10 @@ APFloat::opStatus DoubleAPFloat::next(bool nextDown) {
4293
4299
return Ret;
4294
4300
}
4295
4301
4296
- APFloat::opStatus DoubleAPFloat::convertToInteger (integerPart *Input,
4297
- unsigned int Width,
4298
- bool IsSigned,
4299
- roundingMode RM,
4300
- bool *IsExact) const {
4302
+ APFloat::opStatus
4303
+ DoubleAPFloat::convertToInteger (MutableArrayRef<integerPart> Input,
4304
+ unsigned int Width, bool IsSigned,
4305
+ roundingMode RM, bool *IsExact) const {
4301
4306
assert (Semantics == &semPPCDoubleDouble && " Unexpected Semantics" );
4302
4307
return APFloat (semPPCDoubleDoubleLegacy, bitcastToAPInt ())
4303
4308
.convertToInteger (Input, Width, IsSigned, RM, IsExact);
@@ -4511,7 +4516,7 @@ APFloat::opStatus APFloat::convertToInteger(APSInt &result,
4511
4516
bool *isExact) const {
4512
4517
unsigned bitWidth = result.getBitWidth ();
4513
4518
SmallVector<uint64_t , 4 > parts (result.getNumWords ());
4514
- opStatus status = convertToInteger (parts. data () , bitWidth, result.isSigned (),
4519
+ opStatus status = convertToInteger (parts, bitWidth, result.isSigned (),
4515
4520
rounding_mode, isExact);
4516
4521
// Keeps the original signed-ness.
4517
4522
result = APInt (bitWidth, parts);
0 commit comments