@@ -31,14 +31,6 @@ using namespace llvm;
31
31
32
32
#define DEBUG_TYPE " apint"
33
33
34
- // / A utility function for allocating memory, checking for allocation failures,
35
- // / and ensuring the contents are zeroed.
36
- inline static uint64_t * getClearedMemory (unsigned numWords) {
37
- uint64_t *result = new uint64_t [numWords];
38
- memset (result, 0 , numWords * sizeof (uint64_t ));
39
- return result;
40
- }
41
-
42
34
// / A utility function for allocating memory and checking for allocation
43
35
// / failure. The content is not zeroed.
44
36
inline static uint64_t * getMemory (unsigned numWords) {
@@ -74,12 +66,15 @@ inline static unsigned getDigit(char cdigit, uint8_t radix) {
74
66
75
67
76
68
void APInt::initSlowCase (uint64_t val, bool isSigned) {
77
- U.pVal = getClearedMemory (getNumWords ());
78
- U.pVal [0 ] = val;
79
- if (isSigned && int64_t (val) < 0 )
80
- for (unsigned i = 1 ; i < getNumWords (); ++i)
81
- U.pVal [i] = WORDTYPE_MAX;
82
- clearUnusedBits ();
69
+ if (isSigned && int64_t (val) < 0 ) {
70
+ U.pVal = new WordType[getNumWords ()];
71
+ U.pVal [0 ] = val;
72
+ memset (&U.pVal [1 ], 0xFF , APINT_WORD_SIZE * (getNumWords () - 1 ));
73
+ clearUnusedBits ();
74
+ } else {
75
+ U.pVal = new WordType[getNumWords ()](/* default-initialization */ );
76
+ U.pVal [0 ] = val;
77
+ }
83
78
}
84
79
85
80
void APInt::initSlowCase (const APInt& that) {
@@ -93,7 +88,7 @@ void APInt::initFromArray(ArrayRef<uint64_t> bigVal) {
93
88
U.VAL = bigVal[0 ];
94
89
else {
95
90
// Get memory, cleared to 0
96
- U.pVal = getClearedMemory ( getNumWords ());
91
+ U.pVal = new WordType[ getNumWords ()]( /* default-initialization */ );
97
92
// Calculate the number of words to copy
98
93
unsigned words = std::min<unsigned >(bigVal.size (), getNumWords ());
99
94
// Copy the words from bigVal to pVal
@@ -2105,7 +2100,7 @@ void APInt::fromString(unsigned numbits, StringRef str, uint8_t radix) {
2105
2100
if (isSingleWord ())
2106
2101
U.VAL = 0 ;
2107
2102
else
2108
- U.pVal = getClearedMemory ( getNumWords ());
2103
+ U.pVal = new WordType[ getNumWords ()]( /* default-initialization */ );
2109
2104
2110
2105
// Figure out if we can shift instead of multiply
2111
2106
unsigned shift = (radix == 16 ? 4 : radix == 8 ? 3 : radix == 2 ? 1 : 0 );
0 commit comments