25#if defined(__SIZEOF_INT128__) || \
26 (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
27 auto Product = __uint128_t(LHS) * RHS;
32 auto getU = [](
uint64_t N) {
return N >> 32; };
33 auto getL = [](
uint64_t N) {
return N & UINT32_MAX; };
34 uint64_t UL = getU(LHS), LL = getL(LHS), UR = getU(RHS), LR = getL(RHS);
37 uint64_t P1 = UL * UR, P2 = UL * LR, P3 = LL * UR, P4 = LL * LR;
57 int Shift = 64 - LeadingZeros;
61 Shift && (
Lower & UINT64_C(1) << (Shift - 1)));
68 assert(Dividend &&
"expected non-zero dividend");
69 assert(Divisor &&
"expected non-zero divisor");
78 uint64_t Quotient = Dividend64 / Divisor;
79 uint64_t Remainder = Dividend64 % Divisor;
82 if (Quotient > UINT32_MAX)
91 assert(Dividend &&
"expected non-zero dividend");
92 assert(Divisor &&
"expected non-zero divisor");
103 return {Dividend, Shift};
112 uint64_t Quotient = Dividend / Divisor;
116 while (!(Quotient >> 63) && Dividend) {
118 bool IsOverflow = Dividend >> 63;
124 if (IsOverflow || Divisor <= Dividend) {
134 assert(ScaleDiff >= 0 &&
"wrong argument order");
135 assert(ScaleDiff < 64 &&
"numbers too far apart");
137 uint64_t L_adjusted = L >> ScaleDiff;
143 return L > L_adjusted << ScaleDiff ? 1 : 0;
178 int Shift = 63 - (NewE -
E);
179 assert(Shift <= LeadingZeros);
181 assert(Shift >= 0 && Shift < 64 &&
"undefined behavior");
186 unsigned AdjustedE =
E + 16383;
196 Float.toString(Chars, Precision, 0);
197 return std::string(Chars.
begin(), Chars.
end());
201 size_t NonZero = Float.find_last_not_of(
'0');
202 assert(NonZero != std::string::npos &&
"no . in floating point string");
204 if (Float[NonZero] ==
'.')
207 return Float.substr(0, NonZero + 1);
211 unsigned Precision) {
230 }
else if (E > -64) {
232 Below0 =
D << (64 + E);
233 }
else if (E == -64) {
236 }
else if (E > -120) {
237 Below0 =
D >> (-E - 64);
238 Extra =
D << (128 + E);
239 ExtraShift = -64 - E;
243 if (!Above0 && !Below0)
248 size_t DigitsOut = 0;
251 DigitsOut = Str.size();
255 std::reverse(Str.begin(), Str.end());
267 Extra = (Below0 & 0xf) << 56 | (Extra >> 8);
270 size_t AfterDot = Str.size();
281 Below0 += (Extra >> 60);
285 if (DigitsOut || Str.back() !=
'0')
288 }
while (
Error && (Below0 << 4 | Extra >> 60) >=
Error / 2 &&
289 (!Precision || DigitsOut <= Precision || SinceDot < 2));
292 if (!Precision || DigitsOut <= Precision)
297 std::max(Str.size() - (DigitsOut - Precision), AfterDot + 1);
300 if (Truncate >= Str.size())
308 for (std::string::reverse_iterator
I(Str.begin() + Truncate), E = Str.rend();
327 int Width,
unsigned Precision) {
328 return OS <<
toString(
D, E, Width, Precision);
332 print(
dbgs(),
D, E, Width, 0) <<
"[" << Width <<
":" <<
D <<
"*2^" << E
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares a class to represent arbitrary precision floating point values and provide a varie...
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static uint64_t getHalf(uint64_t N)
static bool doesRoundUp(char Digit)
static std::string toStringAPFloat(uint64_t D, int E, unsigned Precision)
static void appendDigit(std::string &Str, unsigned D)
static std::string stripTrailingZeros(const std::string &Float)
static void appendNumber(std::string &Str, uint64_t N)
static const fltSemantics & x87DoubleExtended()
Class for arbitrary precision integers.
Lightweight error class with error context and mandatory checking.
static int countLeadingZeros64(uint64_t N)
static LLVM_ABI raw_ostream & print(raw_ostream &OS, uint64_t D, int16_t E, int Width, unsigned Precision)
static LLVM_ABI std::string toString(uint64_t D, int16_t E, int Width, unsigned Precision)
static LLVM_ABI void dump(uint64_t D, int16_t E, int Width)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This class implements an extremely fast bulk output stream that can only output to a stream.
LLVM_ABI std::pair< uint64_t, int16_t > divide64(uint64_t Dividend, uint64_t Divisor)
Divide two 64-bit integers to create a 64-bit scaled number.
LLVM_ABI std::pair< uint64_t, int16_t > multiply64(uint64_t LHS, uint64_t RHS)
Multiply two 64-bit integers to create a 64-bit scaled number.
const int32_t MinScale
Maximum scale; same as APFloat for easy debug printing.
std::pair< DigitsT, int16_t > getAdjusted(uint64_t Digits, int16_t Scale=0)
Adjust a 64-bit scaled number down to the appropriate width.
std::pair< DigitsT, int16_t > getRounded(DigitsT Digits, int16_t Scale, bool ShouldRound)
Conditionally round up a scaled number.
LLVM_ABI std::pair< uint32_t, int16_t > divide32(uint32_t Dividend, uint32_t Divisor)
Divide two 32-bit integers to create a 32-bit scaled number.
const int32_t MaxScale
Maximum scale; same as APFloat for easy debug printing.
LLVM_ABI int compareImpl(uint64_t L, uint64_t R, int ScaleDiff)
Implementation for comparing scaled numbers.
This is an optimization pass for GlobalISel generic memory operations.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
int countl_zero(T Val)
Count number of 0's from the most significant bit to the least stopping at the first 1.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.