21 using namespace llvm::ScaledNumbers;
26 auto getU = [](uint64_t
N) {
return N >> 32; };
27 auto getL = [](uint64_t
N) {
return N & UINT32_MAX; };
28 uint64_t UL =
getU(LHS), LL = getL(LHS), UR =
getU(RHS), LR = getL(RHS);
31 uint64_t P1 = UL * UR, P2 = UL * LR, P3 = LL * UR, P4 = LL * LR;
35 auto addWithCarry = [&](uint64_t
N) {
36 uint64_t NewLower = Lower + (getL(
N) << 32);
37 Upper +=
getU(
N) + (NewLower < Lower);
45 return std::make_pair(Lower, 0);
49 int Shift = 64 - LeadingZeros;
51 Upper = Upper << LeadingZeros | Lower >> Shift;
53 Shift && (Lower & UINT64_C(1) << (Shift - 1)));
56 static uint64_t
getHalf(uint64_t
N) {
return (N >> 1) + (N & 1); }
60 assert(Dividend &&
"expected non-zero dividend");
61 assert(Divisor &&
"expected non-zero divisor");
64 uint64_t Dividend64 = Dividend;
70 uint64_t Quotient = Dividend64 / Divisor;
71 uint64_t Remainder = Dividend64 % Divisor;
74 if (Quotient > UINT32_MAX)
75 return getAdjusted<uint32_t>(Quotient, Shift);
78 return getRounded<uint32_t>(Quotient, Shift, Remainder >=
getHalf(Divisor));
83 assert(Dividend &&
"expected non-zero dividend");
84 assert(Divisor &&
"expected non-zero divisor");
95 return std::make_pair(Dividend, Shift);
104 uint64_t Quotient = Dividend / Divisor;
108 while (!(Quotient >> 63) && Dividend) {
110 bool IsOverflow = Dividend >> 63;
116 if (IsOverflow || Divisor <= Dividend) {
126 assert(ScaleDiff >= 0 &&
"wrong argument order");
127 assert(ScaleDiff < 64 &&
"numbers too far apart");
129 uint64_t L_adjusted = L >> ScaleDiff;
135 return L > L_adjusted << ScaleDiff ? 1 : 0;
170 int Shift = 63 - (NewE -
E);
171 assert(Shift <= LeadingZeros);
173 assert(Shift >= 0 && Shift < 64 &&
"undefined behavior");
178 unsigned AdjustedE = E + 16383;
185 uint64_t RawBits[2] = {
D, AdjustedE};
188 Float.
toString(Chars, Precision, 0);
189 return std::string(Chars.
begin(), Chars.
end());
193 size_t NonZero = Float.find_last_not_of(
'0');
194 assert(NonZero != std::string::npos &&
"no . in floating point string");
196 if (Float[NonZero] ==
'.')
199 return Float.substr(0, NonZero + 1);
203 unsigned Precision) {
215 if (
int Shift =
std::min(int16_t(countLeadingZeros64(D)), E)) {
222 }
else if (E > -64) {
224 Below0 = D << (64 +
E);
225 }
else if (E == -64) {
228 }
else if (E > -120) {
229 Below0 = D >> (-E - 64);
230 Extra = D << (128 +
E);
231 ExtraShift = -64 -
E;
235 if (!Above0 && !Below0)
240 size_t DigitsOut = 0;
243 DigitsOut = Str.size();
254 uint64_t
Error = UINT64_C(1) << (64 - Width);
258 Extra = (Below0 & 0xf) << 56 | (Extra >> 8);
261 size_t AfterDot = Str.size();
271 Below0 += (Extra >> 60);
272 Extra = Extra & (UINT64_MAX >> 4);
274 Below0 = Below0 & (UINT64_MAX >> 4);
275 if (DigitsOut || Str.back() !=
'0')
278 }
while (Error && (Below0 << 4 | Extra >> 60) >= Error / 2 &&
279 (!Precision || DigitsOut <= Precision || SinceDot < 2));
282 if (!Precision || DigitsOut <= Precision)
287 std::max(Str.size() - (DigitsOut - Precision), AfterDot + 1);
290 if (Truncate >= Str.size())
298 for (std::string::reverse_iterator
I(Str.begin() + Truncate), E = Str.rend();
317 int Width,
unsigned Precision) {
318 return OS <<
toString(D, E, Width, Precision);
322 print(
dbgs(), D, E, Width, 0) <<
"[" << Width <<
":" << D <<
"*2^" << E
static void appendNumber(std::string &Str, uint64_t N)
static void dump(uint64_t D, int16_t E, int Width)
static bool doesRoundUp(char Digit)
std::size_t countLeadingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the most significant bit to the least stopping at the first 1...
const int32_t MaxScale
Maximum scale; same as APFloat for easy debug printing.
std::string toString(Error E)
Write all error messages (if any) in E to a string.
static const fltSemantics & x87DoubleExtended()
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3) const
static GCRegistry::Add< StatepointGC > D("statepoint-example","an example strategy for statepoint")
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
static int countLeadingZeros64(uint64_t N)
std::pair< DigitsT, int16_t > getRounded(DigitsT Digits, int16_t Scale, bool ShouldRound)
Conditionally round up a scaled number.
static uint64_t getHalf(uint64_t N)
static std::string toStringAPFloat(uint64_t D, int E, unsigned Precision)
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with etc Experimental Use value profile to guide fuzzing Number of simultaneous worker processes to run the jobs If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
static std::string stripTrailingZeros(const std::string &Float)
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
static std::string toString(uint64_t D, int16_t E, int Width, unsigned Precision)
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
This file declares a class to represent arbitrary precision floating point values and provide a varie...
int compareImpl(uint64_t L, uint64_t R, int ScaleDiff)
Implementation for comparing scaled numbers.
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.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Class for arbitrary precision integers.
static void appendDigit(std::string &Str, unsigned D)
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_ATTRIBUTE_ALWAYS_INLINE iterator end()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
This class implements an extremely fast bulk output stream that can only output to a stream...
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 MinScale
Maximum scale; same as APFloat for easy debug printing.
static raw_ostream & print(raw_ostream &OS, uint64_t D, int16_t E, int Width, unsigned Precision)