LLVM 24.0.0git
APFloat.h
Go to the documentation of this file.
1//===- llvm/ADT/APFloat.h - Arbitrary Precision Floating Point ---*- C++ -*-==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file declares a class to represent arbitrary precision floating point
11/// values and provide a variety of arithmetic operations on them.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_ADT_APFLOAT_H
16#define LLVM_ADT_APFLOAT_H
17
18#include "llvm/ADT/APInt.h"
19#include "llvm/ADT/ArrayRef.h"
24#include <memory>
25#include <optional>
26
27#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL) \
28 do { \
29 if (usesLayout<IEEEFloat>(getSemantics())) \
30 return U.IEEE.METHOD_CALL; \
31 if (usesLayout<DoubleAPFloat>(getSemantics())) \
32 return U.Double.METHOD_CALL; \
33 llvm_unreachable("Unexpected semantics"); \
34 } while (false)
35
36namespace llvm {
37
38struct fltSemantics;
39class APSInt;
40class StringRef;
41class APFloat;
42class raw_ostream;
43
44template <typename T> class Expected;
45template <typename T> class SmallVectorImpl;
46
47/// Enum that represents what fraction of the LSB truncated bits of an fp number
48/// represent.
49///
50/// This essentially combines the roles of guard and sticky bits.
51enum lostFraction { // Example of truncated bits:
52 lfExactlyZero, // 000000
53 lfLessThanHalf, // 0xxxxx x's not all zero
54 lfExactlyHalf, // 100000
55 lfMoreThanHalf // 1xxxxx x's not all zero
56};
57
58/// A self-contained host- and target-independent arbitrary-precision
59/// floating-point software implementation.
60///
61/// APFloat uses bignum integer arithmetic as provided by static functions in
62/// the APInt class. The library will work with bignum integers whose parts are
63/// any unsigned type at least 16 bits wide, but 64 bits is recommended.
64///
65/// Written for clarity rather than speed, in particular with a view to use in
66/// the front-end of a cross compiler so that target arithmetic can be correctly
67/// performed on the host. Performance should nonetheless be reasonable,
68/// particularly for its intended use. It may be useful as a base
69/// implementation for a run-time library during development of a faster
70/// target-specific one.
71///
72/// All 5 rounding modes in the IEEE-754R draft are handled correctly for all
73/// implemented operations. Currently implemented operations are add, subtract,
74/// multiply, divide, fused-multiply-add, conversion-to-float,
75/// conversion-to-integer and conversion-from-integer. New rounding modes
76/// (e.g. away from zero) can be added with three or four lines of code.
77///
78/// Four formats are built-in: IEEE single precision, double precision,
79/// quadruple precision, and x87 80-bit extended double (when operating with
80/// full extended precision). Adding a new format that obeys IEEE semantics
81/// only requires adding two lines of code: a declaration and definition of the
82/// format.
83///
84/// All operations return the status of that operation as an exception bit-mask,
85/// so multiple operations can be done consecutively with their results or-ed
86/// together. The returned status can be useful for compiler diagnostics; e.g.,
87/// inexact, underflow and overflow can be easily diagnosed on constant folding,
88/// and compiler optimizers can determine what exceptions would be raised by
89/// folding operations and optimize, or perhaps not optimize, accordingly.
90///
91/// At present, underflow tininess is detected after rounding; it should be
92/// straight forward to add support for the before-rounding case too.
93///
94/// The library reads hexadecimal floating point numbers as per C99, and
95/// correctly rounds if necessary according to the specified rounding mode.
96/// Syntax is required to have been validated by the caller. It also converts
97/// floating point numbers to hexadecimal text as per the C99 %a and %A
98/// conversions. The output precision (or alternatively the natural minimal
99/// precision) can be specified; if the requested precision is less than the
100/// natural precision the output is correctly rounded for the specified rounding
101/// mode.
102///
103/// It also reads decimal floating point numbers and correctly rounds according
104/// to the specified rounding mode.
105///
106/// Conversion to decimal text is not currently implemented.
107///
108/// Non-zero finite numbers are represented internally as a sign bit, a 16-bit
109/// signed exponent, and the significand as an array of integer parts. After
110/// normalization of a number of precision P the exponent is within the range of
111/// the format, and if the number is not denormal the P-th bit of the
112/// significand is set as an explicit integer bit. For denormals the most
113/// significant bit is shifted right so that the exponent is maintained at the
114/// format's minimum, so that the smallest denormal has just the least
115/// significant bit of the significand set. The sign of zeroes and infinities
116/// is significant; the exponent and significand of such numbers is not stored,
117/// but has a known implicit (deterministic) value: 0 for the significands, 0
118/// for zero exponent, all 1 bits for infinity exponent. For NaNs the sign and
119/// significand are deterministic, although not really meaningful, and preserved
120/// in non-conversion operations. The exponent is implicitly all 1 bits.
121///
122/// APFloat does not provide any exception handling beyond default exception
123/// handling. We represent Signaling NaNs via IEEE-754R 2008 6.2.1 should clause
124/// by encoding Signaling NaNs with the first bit of its trailing significand as
125/// 0.
126///
127/// TODO
128/// ====
129///
130/// Some features that may or may not be worth adding:
131///
132/// Binary to decimal conversion (hard).
133///
134/// Optional ability to detect underflow tininess before rounding.
135///
136/// New formats: x87 in single and double precision mode (IEEE apart from
137/// extended exponent range) (hard).
138///
139/// New operations: sqrt, IEEE remainder, C90 fmod, nexttoward.
140///
141
142namespace detail {
143class IEEEFloat;
144class DoubleAPFloat;
145} // namespace detail
146
147// This is the common type definitions shared by APFloat and its internal
148// implementation classes. This struct should not define any non-static data
149// members.
151public:
153 static constexpr unsigned integerPartWidth = APInt::APINT_BITS_PER_WORD;
154
155 /// A signed type to represent a floating point numbers unbiased exponent.
156 using ExponentType = int32_t;
157
158 /// \name Floating Point Semantics.
159 /// @{
166 // The IBM double-double semantics. Such a number consists of a pair of
167 // IEEE 64-bit doubles (Hi, Lo), where |Hi| > |Lo|, and if normal,
168 // (double)(Hi + Lo) == Hi. The numeric value it's modeling is Hi + Lo.
169 // Therefore it has two 53-bit mantissa parts that aren't necessarily
170 // adjacent to each other, and two 11-bit exponents.
171 //
172 // Note: we need to make the value different from semBogus as otherwise
173 // an unsafe optimization may collapse both values to a single address,
174 // and we heavily rely on them having distinct addresses.
176 // These are legacy semantics for the fallback, inaccurate implementation
177 // of IBM double-double, if the accurate semPPCDoubleDouble doesn't handle
178 // the operation. It's equivalent to having an IEEE number with consecutive
179 // 106 bits of mantissa and 11 bits of exponent.
180 //
181 // It's not equivalent to IBM double-double. For example, a legit IBM
182 // double-double, 1 + epsilon:
183 //
184 // 1 + epsilon = 1 + (1 >> 1076)
185 //
186 // is not representable by a consecutive 106 bits of mantissa.
187 //
188 // Currently, these semantics are used in the following way:
189 //
190 // semPPCDoubleDouble -> (IEEEdouble, IEEEdouble) ->
191 // (64-bit APInt, 64-bit APInt) -> (128-bit APInt) ->
192 // semPPCDoubleDoubleLegacy -> IEEE operations
193 //
194 // We use bitcastToAPInt() to get the bit representation (in APInt) of the
195 // underlying IEEEdouble, then use the APInt constructor to construct the
196 // legacy IEEE float.
197 //
198 // TODO: Implement all operations in semPPCDoubleDouble, and delete these
199 // semantics.
201 // 8-bit floating point number following IEEE-754 conventions with bit
202 // layout S1E5M2 as described in https://arxiv.org/abs/2209.05433.
204 // 8-bit floating point number mostly following IEEE-754 conventions
205 // and bit layout S1E5M2 described in https://arxiv.org/abs/2206.02915,
206 // with expanded range and with no infinity or signed zero.
207 // NaN is represented as negative zero. (FN -> Finite, UZ -> unsigned zero).
208 // This format's exponent bias is 16, instead of the 15 (2 ** (5 - 1) - 1)
209 // that IEEE precedent would imply.
211 // 8-bit floating point number following IEEE-754 conventions with bit
212 // layout S1E4M3.
214 // 8-bit floating point number mostly following IEEE-754 conventions with
215 // bit layout S1E4M3 as described in https://arxiv.org/abs/2209.05433.
216 // Unlike IEEE-754 types, there are no infinity values, and NaN is
217 // represented with the exponent and mantissa bits set to all 1s.
219 // 8-bit floating point number mostly following IEEE-754 conventions
220 // and bit layout S1E4M3 described in https://arxiv.org/abs/2206.02915,
221 // with expanded range and with no infinity or signed zero.
222 // NaN is represented as negative zero. (FN -> Finite, UZ -> unsigned zero).
223 // This format's exponent bias is 8, instead of the 7 (2 ** (4 - 1) - 1)
224 // that IEEE precedent would imply.
226 // 8-bit floating point number mostly following IEEE-754 conventions
227 // and bit layout S1E4M3 with expanded range and with no infinity or signed
228 // zero.
229 // NaN is represented as negative zero. (FN -> Finite, UZ -> unsigned zero).
230 // This format's exponent bias is 11, instead of the 7 (2 ** (4 - 1) - 1)
231 // that IEEE precedent would imply.
233 // 8-bit floating point number following IEEE-754 conventions with bit
234 // layout S1E3M4.
236 // Floating point number that occupies 32 bits or less of storage, providing
237 // improved range compared to half (16-bit) formats, at (potentially)
238 // greater throughput than single precision (32-bit) formats.
240 // 8-bit floating point number with (all the) 8 bits for the exponent
241 // like in FP32. There are no zeroes, no infinities, and no denormal values.
242 // This format has unsigned representation only. (U -> Unsigned only).
243 // NaN is represented with all bits set to 1. Bias is 127.
244 // This format represents the scale data type in the MX specification from:
245 // https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf
247 // 6-bit floating point number with bit layout S1E3M2. Unlike IEEE-754
248 // types, there are no infinity or NaN values. The format is detailed in
249 // https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf
251 // 6-bit floating point number with bit layout S1E2M3. Unlike IEEE-754
252 // types, there are no infinity or NaN values. The format is detailed in
253 // https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf
255 // 4-bit floating point number with bit layout S1E2M1. Unlike IEEE-754
256 // types, there are no infinity or NaN values. The format is detailed in
257 // https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf
259 // 8-bit floating point number mostly following IEEE-754 conventions with
260 // bit layout S0E5M3 as described in PTX ISA page.
261 // https://docs.nvidia.com/cuda/developer-preview/13.4/parallel-thread-execution/index.html#alternate-floating-point-data-formats
262 // Unlike IEEE-754 types, there are no infinity values, and NaN is
263 // represented with the exponent and mantissa bits set to all 1s.
265 // TODO: Documentation is missing.
268 };
269
272
273private:
274 LLVM_ABI static const fltSemantics semIEEEhalf;
275 LLVM_ABI static const fltSemantics semBFloat;
276 LLVM_ABI static const fltSemantics semIEEEsingle;
277 LLVM_ABI static const fltSemantics semIEEEdouble;
278 LLVM_ABI static const fltSemantics semIEEEquad;
279 LLVM_ABI static const fltSemantics semFloat8E5M2;
280 LLVM_ABI static const fltSemantics semFloat8E5M2FNUZ;
281 LLVM_ABI static const fltSemantics semFloat8E4M3;
282 LLVM_ABI static const fltSemantics semFloat8E4M3FN;
283 LLVM_ABI static const fltSemantics semFloat8E4M3FNUZ;
284 LLVM_ABI static const fltSemantics semFloat8E4M3B11FNUZ;
285 LLVM_ABI static const fltSemantics semFloat8E3M4;
286 LLVM_ABI static const fltSemantics semFloatTF32;
287 LLVM_ABI static const fltSemantics semFloat8E8M0FNU;
288 LLVM_ABI static const fltSemantics semFloat8E5M3FNU;
289 LLVM_ABI static const fltSemantics semFloat6E3M2FN;
290 LLVM_ABI static const fltSemantics semFloat6E2M3FN;
291 LLVM_ABI static const fltSemantics semFloat4E2M1FN;
292 LLVM_ABI static const fltSemantics semX87DoubleExtended;
293 LLVM_ABI static const fltSemantics semBogus;
294 LLVM_ABI static const fltSemantics semPPCDoubleDouble;
295 LLVM_ABI static const fltSemantics semPPCDoubleDoubleLegacy;
296
297 friend class detail::IEEEFloat;
299 friend class APFloat;
300
301public:
302 static const fltSemantics &IEEEhalf() { return semIEEEhalf; }
303 static const fltSemantics &BFloat() { return semBFloat; }
304 static const fltSemantics &IEEEsingle() { return semIEEEsingle; }
305 static const fltSemantics &IEEEdouble() { return semIEEEdouble; }
306 static const fltSemantics &IEEEquad() { return semIEEEquad; }
307 static const fltSemantics &PPCDoubleDouble() { return semPPCDoubleDouble; }
309 return semPPCDoubleDoubleLegacy;
310 }
311 static const fltSemantics &Float8E5M2() { return semFloat8E5M2; }
312 static const fltSemantics &Float8E5M2FNUZ() { return semFloat8E5M2FNUZ; }
313 static const fltSemantics &Float8E4M3() { return semFloat8E4M3; }
314 static const fltSemantics &Float8E4M3FN() { return semFloat8E4M3FN; }
315 static const fltSemantics &Float8E4M3FNUZ() { return semFloat8E4M3FNUZ; }
317 return semFloat8E4M3B11FNUZ;
318 }
319 static const fltSemantics &Float8E3M4() { return semFloat8E3M4; }
320 static const fltSemantics &FloatTF32() { return semFloatTF32; }
321 static const fltSemantics &Float8E8M0FNU() { return semFloat8E8M0FNU; }
322 static const fltSemantics &Float8E5M3FNU() { return semFloat8E5M3FNU; }
323 static const fltSemantics &Float6E3M2FN() { return semFloat6E3M2FN; }
324 static const fltSemantics &Float6E2M3FN() { return semFloat6E2M3FN; }
325 static const fltSemantics &Float4E2M1FN() { return semFloat4E2M1FN; }
327 return semX87DoubleExtended;
328 }
329
330 /// A Pseudo fltsemantic used to construct APFloats that cannot conflict with
331 /// anything real.
332 static const fltSemantics &Bogus() { return semBogus; }
333
334 // Returns true if any number described by this semantics can be precisely
335 // represented by the specified semantics. Does not take into account
336 // the value of fltNonfiniteBehavior, hasZero, hasSignedRepr.
337 LLVM_ABI static bool isRepresentableBy(const fltSemantics &A,
338 const fltSemantics &B);
339
340 /// Returns whether converting a value from \p From to \p To is known to
341 /// preserve all information. If \p IgnoreNaNs is true, differences between
342 /// NaN representations are ignored, but NaNs must remain NaNs and infinities
343 /// must remain infinities.
344 LLVM_ABI static bool isLosslesslyConvertibleTo(const fltSemantics &From,
345 const fltSemantics &To,
346 bool IgnoreNaNs = false);
347
348 /// @}
349
350 /// IEEE-754R 5.11: Floating Point Comparison Relations.
357
358 /// IEEE-754R 4.3: Rounding-direction attributes.
360
368
369 /// IEEE-754R 7: Default exception handling.
370 ///
371 /// opUnderflow or opOverflow are always returned or-ed with opInexact.
372 ///
373 /// APFloat models this behavior specified by IEEE-754:
374 /// "For operations producing results in floating-point format, the default
375 /// result of an operation that signals the invalid operation exception
376 /// shall be a quiet NaN."
377 enum opStatus {
378 opOK = 0x00,
384 };
385
386 /// Category of internally-represented number.
393
394 /// Convenience enum used to construct an uninitialized APFloat.
398
399 /// Enumeration of \c ilogb error results.
401 IEK_Zero = INT_MIN + 1,
402 IEK_NaN = INT_MIN,
403 IEK_Inf = INT_MAX
404 };
405
406 LLVM_ABI static unsigned int semanticsPrecision(const fltSemantics &);
409 LLVM_ABI static unsigned int semanticsSizeInBits(const fltSemantics &);
410 LLVM_ABI static unsigned int semanticsIntSizeInBits(const fltSemantics &,
411 bool);
412 LLVM_ABI static bool semanticsHasZero(const fltSemantics &);
413 LLVM_ABI static bool semanticsHasSignedRepr(const fltSemantics &);
414 LLVM_ABI static bool semanticsHasInf(const fltSemantics &);
415 LLVM_ABI static bool semanticsHasNaN(const fltSemantics &);
416 LLVM_ABI static bool isIEEELikeFP(const fltSemantics &);
417 LLVM_ABI static bool hasSignBitInMSB(const fltSemantics &);
418
419 // Returns true if any number described by \p Src can be precisely represented
420 // by a normal (not subnormal) value in \p Dst.
421 LLVM_ABI static bool isRepresentableAsNormalIn(const fltSemantics &Src,
422 const fltSemantics &Dst);
423
424 /// Returns the size of the floating point number (in bits) in the given
425 /// semantics.
426 LLVM_ABI static unsigned getSizeInBits(const fltSemantics &Sem);
427
428 /// Returns true if the given string is a valid arbitrary floating-point
429 /// format interpretation for llvm.convert.to.arbitrary.fp and
430 /// llvm.convert.from.arbitrary.fp intrinsics.
432
433 /// Returns the size in bits of a valid arbitrary floating-point format
434 /// string, or 0 if the string is not a valid format. Covers every format
435 /// accepted by isValidArbitraryFPFormat, not only those
436 /// getArbitraryFPSemantics can currently lower.
438
439 /// Returns the fltSemantics for a given arbitrary FP format string,
440 /// or nullptr if invalid.
442};
443
444namespace detail {
445
466static constexpr opStatus opOK = APFloatBase::opOK;
476
477class IEEEFloat final {
478public:
479 /// \name Constructors
480 /// @{
481
482 LLVM_ABI IEEEFloat(const fltSemantics &); // Default construct to +0.0
485 LLVM_ABI IEEEFloat(const fltSemantics &, const APInt &);
486 LLVM_ABI explicit IEEEFloat(double d);
487 LLVM_ABI explicit IEEEFloat(float f);
491
492 /// @}
493
494 /// Returns whether this instance allocated memory.
495 bool needsCleanup() const { return partCount() > 1; }
496
497 /// \name Convenience "constructors"
498 /// @{
499
500 /// @}
501
502 /// \name Arithmetic
503 /// @{
504
509 /// IEEE remainder.
511 /// C fmod, or llvm frem.
516 /// IEEE-754R 5.3.1: nextUp/nextDown.
517 LLVM_ABI opStatus next(bool nextDown);
518
519 /// @}
520
521 /// \name Sign operations.
522 /// @{
523
524 LLVM_ABI void changeSign();
525
526 /// @}
527
528 /// \name Conversions
529 /// @{
530
533 bool, roundingMode, bool *) const;
537 LLVM_ABI double convertToDouble() const;
538#ifdef HAS_IEE754_FLOAT128
539 LLVM_ABI float128 convertToQuad() const;
540#endif
541 LLVM_ABI float convertToFloat() const;
542
543 /// @}
544
545 /// The definition of equality is not straightforward for floating point, so
546 /// we won't use operator==. Use one of the following, or write whatever it
547 /// is you really mean.
548 bool operator==(const IEEEFloat &) const = delete;
549
550 /// IEEE comparison with another floating point number (NaNs compare
551 /// unordered, 0==-0).
552 LLVM_ABI cmpResult compare(const IEEEFloat &) const;
553
554 /// Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
555 LLVM_ABI bool bitwiseIsEqual(const IEEEFloat &) const;
556
557 /// Write out a hexadecimal representation of the floating point value to DST,
558 /// which must be of sufficient size, in the C99 form [-]0xh.hhhhp[+-]d.
559 /// Return the number of characters written, excluding the terminating NUL.
560 LLVM_ABI unsigned int convertToHexString(char *dst, unsigned int hexDigits,
561 bool upperCase, roundingMode) const;
562
563 /// \name IEEE-754R 5.7.2 General operations.
564 /// @{
565
566 /// IEEE-754R isSignMinus: Returns true if and only if the current value is
567 /// negative.
568 ///
569 /// This applies to zeros and NaNs as well.
570 bool isNegative() const { return sign; }
571
572 /// IEEE-754R isNormal: Returns true if and only if the current value is normal.
573 ///
574 /// This implies that the current value of the float is not zero, subnormal,
575 /// infinite, or NaN following the definition of normality from IEEE-754R.
576 bool isNormal() const { return !isDenormal() && isFiniteNonZero(); }
577
578 /// Returns true if and only if the current value is zero, subnormal, or
579 /// normal.
580 ///
581 /// This means that the value is not infinite or NaN.
582 bool isFinite() const { return !isNaN() && !isInfinity(); }
583
584 /// Returns true if and only if the float is plus or minus zero.
585 bool isZero() const { return category == fltCategory::fcZero; }
586
587 /// IEEE-754R isSubnormal(): Returns true if and only if the float is a
588 /// denormal.
589 LLVM_ABI bool isDenormal() const;
590
591 /// IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
592 bool isInfinity() const { return category == fcInfinity; }
593
594 /// Returns true if and only if the float is a quiet or signaling NaN.
595 bool isNaN() const { return category == fcNaN; }
596
597 /// Returns true if and only if the float is a signaling NaN.
598 LLVM_ABI bool isSignaling() const;
599
600 /// @}
601
602 /// \name Simple Queries
603 /// @{
604
605 fltCategory getCategory() const { return category; }
606 const fltSemantics &getSemantics() const { return *semantics; }
607 bool isNonZero() const { return category != fltCategory::fcZero; }
608 bool isFiniteNonZero() const { return isFinite() && !isZero(); }
609 bool isPosZero() const { return isZero() && !isNegative(); }
610 bool isNegZero() const { return isZero() && isNegative(); }
611
612 /// Returns true if and only if the number has the smallest possible non-zero
613 /// magnitude in the current semantics.
614 LLVM_ABI bool isSmallest() const;
615
616 /// Returns true if this is the smallest (by magnitude) normalized finite
617 /// number in the given semantics.
618 LLVM_ABI bool isSmallestNormalized() const;
619
620 /// Returns true if and only if the number has the largest possible finite
621 /// magnitude in the current semantics.
622 LLVM_ABI bool isLargest() const;
623
624 /// Returns true if and only if the number is an exact integer.
625 LLVM_ABI bool isInteger() const;
626
627 /// @}
628
631
632 /// Overload to compute a hash code for an APFloat value.
633 ///
634 /// Note that the use of hash codes for floating point values is in general
635 /// frought with peril. Equality is hard to define for these values. For
636 /// example, should negative and positive zero hash to different codes? Are
637 /// they equal or not? This hash value implementation specifically
638 /// emphasizes producing different codes for different inputs in order to
639 /// be used in canonicalization and memoization. As such, equality is
640 /// bitwiseIsEqual, and 0 != -0.
641 LLVM_ABI friend hash_code hash_value(const IEEEFloat &Arg);
642
643 /// Converts this value into a decimal string.
644 ///
645 /// \param FormatPrecision The maximum number of digits of
646 /// precision to output. If there are fewer digits available,
647 /// zero padding will not be used unless the value is
648 /// integral and small enough to be expressed in
649 /// FormatPrecision digits. 0 means to use the natural
650 /// precision of the number.
651 /// \param FormatMaxPadding The maximum number of zeros to
652 /// consider inserting before falling back to scientific
653 /// notation. 0 means to always use scientific notation.
654 ///
655 /// \param TruncateZero Indicate whether to remove the trailing zero in
656 /// fraction part or not. Also setting this parameter to false forcing
657 /// producing of output more similar to default printf behavior.
658 /// Specifically the lower e is used as exponent delimiter and exponent
659 /// always contains no less than two digits.
660 ///
661 /// Number Precision MaxPadding Result
662 /// ------ --------- ---------- ------
663 /// 1.01E+4 5 2 10100
664 /// 1.01E+4 4 2 1.01E+4
665 /// 1.01E+4 5 1 1.01E+4
666 /// 1.01E-2 5 2 0.0101
667 /// 1.01E-2 4 2 0.0101
668 /// 1.01E-2 4 1 1.01E-2
670 unsigned FormatPrecision = 0,
671 unsigned FormatMaxPadding = 3,
672 bool TruncateZero = true) const;
673
675
676 LLVM_ABI friend int ilogb(const IEEEFloat &Arg);
677
679
680 LLVM_ABI friend IEEEFloat frexp(const IEEEFloat &X, int &Exp, roundingMode);
681
682 /// \name Special value setters.
683 /// @{
684
685 LLVM_ABI void makeLargest(bool Neg = false);
686 LLVM_ABI void makeSmallest(bool Neg = false);
687 LLVM_ABI void makeNaN(bool SNaN = false, bool Neg = false,
688 const APInt *fill = nullptr);
689 LLVM_ABI void makeInf(bool Neg = false);
690 LLVM_ABI void makeZero(bool Neg = false);
691 LLVM_ABI void makeQuiet();
692
693 /// Returns the smallest (by magnitude) normalized finite number in the given
694 /// semantics.
695 ///
696 /// \param Negative - True iff the number should be negative
697 LLVM_ABI void makeSmallestNormalized(bool Negative = false);
698
699 /// @}
700
702
704
705private:
706 /// \name Simple Queries
707 /// @{
708
709 integerPart *significandParts();
710 const integerPart *significandParts() const;
711 LLVM_ABI unsigned int partCount() const;
712
713 /// @}
714
715 /// \name Significand operations.
716 /// @{
717
718 integerPart addSignificand(const IEEEFloat &);
719 integerPart subtractSignificand(const IEEEFloat &, integerPart);
720 // Exported for IEEEFloatUnitTestHelper.
721 LLVM_ABI lostFraction addOrSubtractSignificand(const IEEEFloat &,
722 bool subtract);
723 lostFraction multiplySignificand(const IEEEFloat &, IEEEFloat,
724 bool ignoreAddend = false);
725 lostFraction multiplySignificand(const IEEEFloat&);
726 lostFraction divideSignificand(const IEEEFloat &);
727 void incrementSignificand();
728 void initialize(const fltSemantics *);
729 void shiftSignificandLeft(unsigned int);
730 lostFraction shiftSignificandRight(unsigned int);
731 unsigned int significandLSB() const;
732 unsigned int significandMSB() const;
733 void zeroSignificand();
734 unsigned int getNumHighBits() const;
735 /// Return true if the significand excluding the integral bit is all ones.
736 bool isSignificandAllOnes() const;
737 bool isSignificandAllOnesExceptLSB() const;
738 /// Return true if the significand excluding the integral bit is all zeros.
739 bool isSignificandAllZeros() const;
740 bool isSignificandAllZerosExceptMSB() const;
741
742 /// @}
743
744 /// \name Arithmetic on special values.
745 /// @{
746
747 opStatus addOrSubtractSpecials(const IEEEFloat &, bool subtract);
748 opStatus divideSpecials(const IEEEFloat &);
749 opStatus multiplySpecials(const IEEEFloat &);
750 opStatus modSpecials(const IEEEFloat &);
751 opStatus remainderSpecials(const IEEEFloat&);
752
753 /// @}
754
755 /// \name Miscellany
756 /// @{
757
758 bool convertFromStringSpecials(StringRef str);
760 opStatus addOrSubtract(const IEEEFloat &, roundingMode, bool subtract);
761 opStatus handleOverflow(roundingMode);
762 bool roundAwayFromZero(roundingMode, lostFraction, unsigned int) const;
763 opStatus convertToSignExtendedInteger(MutableArrayRef<integerPart>,
764 unsigned int, bool, roundingMode,
765 bool *) const;
766 opStatus convertFromUnsignedParts(const integerPart *, unsigned int,
768 Expected<opStatus> convertFromHexadecimalString(StringRef, roundingMode);
769 Expected<opStatus> convertFromDecimalString(StringRef, roundingMode);
770 char *convertNormalToHexString(char *, unsigned int, bool,
771 roundingMode) const;
772 opStatus roundSignificandWithExponent(const integerPart *, unsigned int, int,
777
778 /// @}
779
780 template <const fltSemantics &S> APInt convertIEEEFloatToAPInt() const;
781 APInt convertHalfAPFloatToAPInt() const;
782 APInt convertBFloatAPFloatToAPInt() const;
783 APInt convertFloatAPFloatToAPInt() const;
784 APInt convertDoubleAPFloatToAPInt() const;
785 APInt convertQuadrupleAPFloatToAPInt() const;
786 APInt convertF80LongDoubleAPFloatToAPInt() const;
787 APInt convertPPCDoubleDoubleLegacyAPFloatToAPInt() const;
788 APInt convertFloat8E5M2APFloatToAPInt() const;
789 APInt convertFloat8E5M2FNUZAPFloatToAPInt() const;
790 APInt convertFloat8E4M3APFloatToAPInt() const;
791 APInt convertFloat8E4M3FNAPFloatToAPInt() const;
792 APInt convertFloat8E4M3FNUZAPFloatToAPInt() const;
793 APInt convertFloat8E4M3B11FNUZAPFloatToAPInt() const;
794 APInt convertFloat8E3M4APFloatToAPInt() const;
795 APInt convertFloatTF32APFloatToAPInt() const;
796 APInt convertFloat8E8M0FNUAPFloatToAPInt() const;
797 APInt convertFloat8E5M3FNUAPFloatToAPInt() const;
798 APInt convertFloat6E3M2FNAPFloatToAPInt() const;
799 APInt convertFloat6E2M3FNAPFloatToAPInt() const;
800 APInt convertFloat4E2M1FNAPFloatToAPInt() const;
801 void initFromAPInt(const fltSemantics *Sem, const APInt &api);
802 template <const fltSemantics &S> void initFromIEEEAPInt(const APInt &api);
803 void initFromHalfAPInt(const APInt &api);
804 void initFromBFloatAPInt(const APInt &api);
805 void initFromFloatAPInt(const APInt &api);
806 void initFromDoubleAPInt(const APInt &api);
807 void initFromQuadrupleAPInt(const APInt &api);
808 void initFromF80LongDoubleAPInt(const APInt &api);
809 void initFromPPCDoubleDoubleLegacyAPInt(const APInt &api);
810 void initFromFloat8E5M2APInt(const APInt &api);
811 void initFromFloat8E5M2FNUZAPInt(const APInt &api);
812 void initFromFloat8E4M3APInt(const APInt &api);
813 void initFromFloat8E4M3FNAPInt(const APInt &api);
814 void initFromFloat8E4M3FNUZAPInt(const APInt &api);
815 void initFromFloat8E4M3B11FNUZAPInt(const APInt &api);
816 void initFromFloat8E3M4APInt(const APInt &api);
817 void initFromFloatTF32APInt(const APInt &api);
818 void initFromFloat8E8M0FNUAPInt(const APInt &api);
819 void initFromFloat8E5M3FNUAPInt(const APInt &api);
820 void initFromFloat6E3M2FNAPInt(const APInt &api);
821 void initFromFloat6E2M3FNAPInt(const APInt &api);
822 void initFromFloat4E2M1FNAPInt(const APInt &api);
823
824 void assign(const IEEEFloat &);
825 void copySignificand(const IEEEFloat &);
826 void freeSignificand();
827
828 /// Note: this must be the first data member.
829 /// The semantics that this value obeys.
830 const fltSemantics *semantics;
831
832 /// A binary fraction with an explicit integer bit.
833 ///
834 /// The significand must be at least one bit wider than the target precision.
835 union Significand {
836 integerPart part;
837 integerPart *parts;
838 } significand;
839
840 /// The signed unbiased exponent of the value.
841 ExponentType exponent;
842
843 /// What kind of floating point number this is.
844 ///
845 /// Only 2 bits are required, but VisualStudio incorrectly sign extends it.
846 /// Using the extra bit keeps it from failing under VisualStudio.
847 fltCategory category : 3;
848
849 /// Sign bit of the number.
850 unsigned int sign : 1;
851
853};
854
856LLVM_ABI int ilogb(const IEEEFloat &Arg);
858LLVM_ABI IEEEFloat frexp(const IEEEFloat &Val, int &Exp, roundingMode RM);
859
860// This mode implements more precise float in terms of two APFloats.
861// The interface and layout is designed for arbitrary underlying semantics,
862// though currently only PPCDoubleDouble semantics are supported, whose
863// corresponding underlying semantics are IEEEdouble.
864class DoubleAPFloat final {
865 // Note: this must be the first data member.
866 const fltSemantics *Semantics;
867 APFloat *Floats;
868
869 opStatus addImpl(const APFloat &a, const APFloat &aa, const APFloat &c,
870 const APFloat &cc, roundingMode RM);
871
872 opStatus addWithSpecial(const DoubleAPFloat &LHS, const DoubleAPFloat &RHS,
873 DoubleAPFloat &Out, roundingMode RM);
874 opStatus convertToSignExtendedInteger(MutableArrayRef<integerPart> Input,
875 unsigned int Width, bool IsSigned,
876 roundingMode RM, bool *IsExact) const;
877
878 // Convert an unsigned integer Src to a floating point number,
879 // rounding according to RM. The sign of the floating point number is not
880 // modified.
881 opStatus convertFromUnsignedParts(const integerPart *Src,
882 unsigned int SrcCount, roundingMode RM);
883
884 // Handle overflow. Sign is preserved. We either become infinity or
885 // the largest finite number.
886 opStatus handleOverflow(roundingMode RM);
887
888public:
892 LLVM_ABI DoubleAPFloat(const fltSemantics &S, const APInt &I);
894 APFloat &&Second);
898
901
902 bool needsCleanup() const { return Floats != nullptr; }
903
904 inline APFloat &getFirst();
905 inline const APFloat &getFirst() const;
906 inline APFloat &getSecond();
907 inline const APFloat &getSecond() const;
908
916 const DoubleAPFloat &Addend,
917 roundingMode RM);
919 LLVM_ABI void changeSign();
921
923 LLVM_ABI bool isNegative() const;
924
925 LLVM_ABI void makeInf(bool Neg);
926 LLVM_ABI void makeZero(bool Neg);
927 LLVM_ABI void makeLargest(bool Neg);
928 LLVM_ABI void makeSmallest(bool Neg);
929 LLVM_ABI void makeSmallestNormalized(bool Neg);
930 LLVM_ABI void makeNaN(bool SNaN, bool Neg, const APInt *fill);
931
933 LLVM_ABI bool bitwiseIsEqual(const DoubleAPFloat &RHS) const;
936 LLVM_ABI opStatus next(bool nextDown);
937
939 unsigned int Width, bool IsSigned,
940 roundingMode RM, bool *IsExact) const;
941 LLVM_ABI opStatus convertFromAPInt(const APInt &Input, bool IsSigned,
942 roundingMode RM);
943 LLVM_ABI unsigned int convertToHexString(char *DST, unsigned int HexDigits,
944 bool UpperCase,
945 roundingMode RM) const;
946
947 LLVM_ABI bool isDenormal() const;
948 LLVM_ABI bool isSmallest() const;
949 LLVM_ABI bool isSmallestNormalized() const;
950 LLVM_ABI bool isLargest() const;
951 LLVM_ABI bool isInteger() const;
952
954
955 LLVM_ABI void toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision,
956 unsigned FormatMaxPadding,
957 bool TruncateZero = true) const;
958
960
961 LLVM_ABI friend int ilogb(const DoubleAPFloat &X);
964 LLVM_ABI friend DoubleAPFloat frexp(const DoubleAPFloat &X, int &Exp,
966 LLVM_ABI friend hash_code hash_value(const DoubleAPFloat &Arg);
967};
968
970LLVM_ABI DoubleAPFloat scalbn(const DoubleAPFloat &Arg, int Exp,
971 roundingMode RM);
973
974} // End detail namespace
975
976// How the nonfinite values Inf and NaN are represented.
978 // Represents standard IEEE 754 behavior. A value is nonfinite if the
979 // exponent field is all 1s. In such cases, a value is Inf if the
980 // significand bits are all zero, and NaN otherwise
982
983 // This behavior is present in the Float8ExMyFN* types (Float8E4M3FN,
984 // Float8E5M2FNUZ, Float8E4M3FNUZ, and Float8E4M3B11FNUZ). There is no
985 // representation for Inf, and operations that would ordinarily produce Inf
986 // produce NaN instead.
987 // The details of the NaN representation(s) in this form are determined by the
988 // `fltNanEncoding` enum. We treat all NaNs as quiet, as the available
989 // encodings do not distinguish between signalling and quiet NaN.
991
992 // This behavior is present in Float6E3M2FN, Float6E2M3FN, and
993 // Float4E2M1FN types, which do not support Inf or NaN values.
995};
996
997// How NaN values are represented. This is curently only used in combination
998// with fltNonfiniteBehavior::NanOnly, and using a variant other than IEEE
999// while having IEEE non-finite behavior is liable to lead to unexpected
1000// results.
1001enum class fltNanEncoding {
1002 // Represents the standard IEEE behavior where a value is NaN if its
1003 // exponent is all 1s and the significand is non-zero.
1005
1006 // Represents the behavior in the Float8E4M3FN floating point type where NaN
1007 // is represented by having the exponent and mantissa set to all 1s.
1008 // This behavior matches the FP8 E4M3 type described in
1009 // https://arxiv.org/abs/2209.05433. We treat both signed and unsigned NaNs
1010 // as non-signalling, although the paper does not state whether the NaN
1011 // values are signalling or not.
1013
1014 // Represents the behavior in Float8E{5,4}E{2,3}FNUZ floating point types
1015 // where NaN is represented by a sign bit of 1 and all 0s in the exponent
1016 // and mantissa (i.e. the negative zero encoding in a IEEE float). Since
1017 // there is only one NaN value, it is treated as quiet NaN. This matches the
1018 // behavior described in https://arxiv.org/abs/2206.02915 .
1020};
1021
1022/* Represents floating point arithmetic semantics. */
1024 /* The largest E such that 2^E is representable; this matches the
1025 definition of IEEE 754. */
1027
1028 /* The smallest E such that 2^E is a normalized number; this
1029 matches the definition of IEEE 754. */
1031
1032 /* Number of bits in the significand. This includes the integer
1033 bit. */
1034 unsigned int precision;
1035
1036 /* Number of bits actually used in the semantics. */
1037 unsigned int sizeInBits;
1038
1040
1042
1043 /* Whether this semantics has an encoding for Zero */
1044 bool hasZero = true;
1045
1046 /* Whether this semantics can represent signed values */
1047 bool hasSignedRepr = true;
1048
1049 /* Whether the sign bit of this semantics is the most significant bit */
1050 bool hasSignBitInMSB = true;
1051
1052 /* Whether the format supports IEEE754 denormal representation.
1053 If both hasDenormals and hasZero are false exponent 0 is assumed to be a
1054 regular exponent instead of being reserved. This changes the bias by +1. */
1055 bool hasDenormals = true;
1056
1057 /* Whether the integer bit is explicitly represented between significant and
1058 exponent, for example as specified by the x86 double extended precision
1059 format.
1060
1061 For bit patterns designated as undefined under the standard the following
1062 conversions will happen when converting from bits. These follow x87
1063 behaviour:
1064 - exponent = all 1's, integer bit 0, significand 0 ("pseudoinfinity")
1065 - exponent = all 1's, integer bit 0, significand nonzero ("pseudoNaN")
1066 - exponent!=0 nor all 1's, integer bit 0 ("unnormal")
1067 - exponent = 0, integer bit 1 ("pseudodenormal")
1068 The first three are treated as NaNs, the last one as Normal */
1070};
1071
1072// This is a interface class that is currently forwarding functionalities from
1073// detail::IEEEFloat.
1074class APFloat : public APFloatBase {
1075 using IEEEFloat = detail::IEEEFloat;
1076 using DoubleAPFloat = detail::DoubleAPFloat;
1077
1078 static_assert(std::is_standard_layout<IEEEFloat>::value);
1079
1080 union Storage {
1081 const fltSemantics *semantics;
1082 IEEEFloat IEEE;
1083 DoubleAPFloat Double;
1084
1085 LLVM_ABI explicit Storage(IEEEFloat F, const fltSemantics &S);
1086 explicit Storage(DoubleAPFloat F, const fltSemantics &S)
1087 : Double(std::move(F)) {
1088 assert(&S == &PPCDoubleDouble());
1089 }
1090
1091 template <typename... ArgTypes>
1092 Storage(const fltSemantics &Semantics, ArgTypes &&... Args) {
1093 if (usesLayout<IEEEFloat>(Semantics)) {
1094 new (&IEEE) IEEEFloat(Semantics, std::forward<ArgTypes>(Args)...);
1095 return;
1096 }
1097 if (usesLayout<DoubleAPFloat>(Semantics)) {
1098 new (&Double) DoubleAPFloat(Semantics, std::forward<ArgTypes>(Args)...);
1099 return;
1100 }
1101 llvm_unreachable("Unexpected semantics");
1102 }
1103
1104 LLVM_ABI ~Storage();
1105 LLVM_ABI Storage(const Storage &RHS);
1106 LLVM_ABI Storage(Storage &&RHS);
1107 LLVM_ABI Storage &operator=(const Storage &RHS);
1108 LLVM_ABI Storage &operator=(Storage &&RHS);
1109 } U;
1110
1111 template <typename T> static bool usesLayout(const fltSemantics &Semantics) {
1112 static_assert(std::is_same<T, IEEEFloat>::value ||
1113 std::is_same<T, DoubleAPFloat>::value);
1114 if (std::is_same<T, DoubleAPFloat>::value) {
1115 return &Semantics == &PPCDoubleDouble();
1116 }
1117 return &Semantics != &PPCDoubleDouble();
1118 }
1119
1120 IEEEFloat &getIEEE() {
1121 if (usesLayout<IEEEFloat>(*U.semantics))
1122 return U.IEEE;
1123 if (usesLayout<DoubleAPFloat>(*U.semantics))
1124 return U.Double.getFirst().U.IEEE;
1125 llvm_unreachable("Unexpected semantics");
1126 }
1127
1128 const IEEEFloat &getIEEE() const {
1129 if (usesLayout<IEEEFloat>(*U.semantics))
1130 return U.IEEE;
1131 if (usesLayout<DoubleAPFloat>(*U.semantics))
1132 return U.Double.getFirst().U.IEEE;
1133 llvm_unreachable("Unexpected semantics");
1134 }
1135
1136 void makeZero(bool Neg) { APFLOAT_DISPATCH_ON_SEMANTICS(makeZero(Neg)); }
1137
1138 void makeInf(bool Neg) { APFLOAT_DISPATCH_ON_SEMANTICS(makeInf(Neg)); }
1139
1140 void makeNaN(bool SNaN, bool Neg, const APInt *fill) {
1141 APFLOAT_DISPATCH_ON_SEMANTICS(makeNaN(SNaN, Neg, fill));
1142 }
1143
1144 void makeLargest(bool Neg) {
1145 APFLOAT_DISPATCH_ON_SEMANTICS(makeLargest(Neg));
1146 }
1147
1148 void makeSmallest(bool Neg) {
1149 APFLOAT_DISPATCH_ON_SEMANTICS(makeSmallest(Neg));
1150 }
1151
1152 void makeSmallestNormalized(bool Neg) {
1153 APFLOAT_DISPATCH_ON_SEMANTICS(makeSmallestNormalized(Neg));
1154 }
1155
1156 explicit APFloat(IEEEFloat F, const fltSemantics &S) : U(std::move(F), S) {}
1157 explicit APFloat(DoubleAPFloat F, const fltSemantics &S)
1158 : U(std::move(F), S) {}
1159
1160public:
1164 template <typename T,
1165 typename = std::enable_if_t<std::is_floating_point<T>::value>>
1166 APFloat(const fltSemantics &Semantics, T V) = delete;
1167 // TODO: Remove this constructor. This isn't faster than the first one.
1171 explicit APFloat(double d) : U(IEEEFloat(d), IEEEdouble()) {}
1172 explicit APFloat(float f) : U(IEEEFloat(f), IEEEsingle()) {}
1173 APFloat(const APFloat &RHS) = default;
1174 APFloat(APFloat &&RHS) = default;
1175
1176 ~APFloat() = default;
1177
1179
1180 /// Factory for Positive and Negative Zero.
1181 ///
1182 /// \param Negative True iff the number should be negative.
1183 static APFloat getZero(const fltSemantics &Sem, bool Negative = false) {
1184 APFloat Val(Sem, uninitialized);
1185 Val.makeZero(Negative);
1186 return Val;
1187 }
1188
1189 /// Factory for Positive and Negative One.
1190 ///
1191 /// \param Negative True iff the number should be negative.
1192 static APFloat getOne(const fltSemantics &Sem, bool Negative = false) {
1193 APFloat Val(Sem, 1U);
1194 if (Negative)
1195 Val.changeSign();
1196 return Val;
1197 }
1198
1199 /// Factory for Positive and Negative Infinity.
1200 ///
1201 /// \param Negative True iff the number should be negative.
1202 static APFloat getInf(const fltSemantics &Sem, bool Negative = false) {
1203 APFloat Val(Sem, uninitialized);
1204 Val.makeInf(Negative);
1205 return Val;
1206 }
1207
1208 /// Factory for NaN values.
1209 ///
1210 /// \param Negative - True iff the NaN generated should be negative.
1211 /// \param payload - The unspecified fill bits for creating the NaN, 0 by
1212 /// default. The value is truncated as necessary.
1213 static APFloat getNaN(const fltSemantics &Sem, bool Negative = false,
1214 uint64_t payload = 0) {
1215 if (payload) {
1216 APInt intPayload(64, payload);
1217 return getQNaN(Sem, Negative, &intPayload);
1218 } else {
1219 return getQNaN(Sem, Negative, nullptr);
1220 }
1221 }
1222
1223 /// Factory for QNaN values.
1224 static APFloat getQNaN(const fltSemantics &Sem, bool Negative = false,
1225 const APInt *payload = nullptr) {
1226 APFloat Val(Sem, uninitialized);
1227 Val.makeNaN(false, Negative, payload);
1228 return Val;
1229 }
1230
1231 /// Factory for SNaN values.
1232 static APFloat getSNaN(const fltSemantics &Sem, bool Negative = false,
1233 const APInt *payload = nullptr) {
1234 APFloat Val(Sem, uninitialized);
1235 Val.makeNaN(true, Negative, payload);
1236 return Val;
1237 }
1238
1239 /// Returns the largest finite number in the given semantics.
1240 ///
1241 /// \param Negative - True iff the number should be negative
1242 static APFloat getLargest(const fltSemantics &Sem, bool Negative = false) {
1243 APFloat Val(Sem, uninitialized);
1244 Val.makeLargest(Negative);
1245 return Val;
1246 }
1247
1248 /// Returns the smallest (by magnitude) finite number in the given semantics.
1249 /// Might be denormalized, which implies a relative loss of precision.
1250 ///
1251 /// \param Negative - True iff the number should be negative
1252 static APFloat getSmallest(const fltSemantics &Sem, bool Negative = false) {
1253 APFloat Val(Sem, uninitialized);
1254 Val.makeSmallest(Negative);
1255 return Val;
1256 }
1257
1258 /// Returns the smallest (by magnitude) normalized finite number in the given
1259 /// semantics.
1260 ///
1261 /// \param Negative - True iff the number should be negative
1262 static APFloat getSmallestNormalized(const fltSemantics &Sem,
1263 bool Negative = false) {
1264 APFloat Val(Sem, uninitialized);
1265 Val.makeSmallestNormalized(Negative);
1266 return Val;
1267 }
1268
1269 /// Returns a float which is bitcasted from an all one value int.
1270 ///
1271 /// \param Semantics - type float semantics
1273
1274 /// Returns true if the given semantics has actual significand.
1275 ///
1276 /// \param Sem - type float semantics
1277 static bool hasSignificand(const fltSemantics &Sem) {
1278 return &Sem != &Float8E8M0FNU();
1279 }
1280
1281 /// Used to insert APFloat objects, or objects that contain APFloat objects,
1282 /// into FoldingSets.
1283 LLVM_ABI void Profile(FoldingSetNodeID &NID) const;
1284
1285 opStatus add(const APFloat &RHS, roundingMode RM) {
1286 assert(&getSemantics() == &RHS.getSemantics() &&
1287 "Should only call on two APFloats with the same semantics");
1288 if (usesLayout<IEEEFloat>(getSemantics()))
1289 return U.IEEE.add(RHS.U.IEEE, RM);
1290 if (usesLayout<DoubleAPFloat>(getSemantics()))
1291 return U.Double.add(RHS.U.Double, RM);
1292 llvm_unreachable("Unexpected semantics");
1293 }
1294 opStatus subtract(const APFloat &RHS, roundingMode RM) {
1295 assert(&getSemantics() == &RHS.getSemantics() &&
1296 "Should only call on two APFloats with the same semantics");
1297 if (usesLayout<IEEEFloat>(getSemantics()))
1298 return U.IEEE.subtract(RHS.U.IEEE, RM);
1299 if (usesLayout<DoubleAPFloat>(getSemantics()))
1300 return U.Double.subtract(RHS.U.Double, RM);
1301 llvm_unreachable("Unexpected semantics");
1302 }
1303 opStatus multiply(const APFloat &RHS, roundingMode RM) {
1304 assert(&getSemantics() == &RHS.getSemantics() &&
1305 "Should only call on two APFloats with the same semantics");
1306 if (usesLayout<IEEEFloat>(getSemantics()))
1307 return U.IEEE.multiply(RHS.U.IEEE, RM);
1308 if (usesLayout<DoubleAPFloat>(getSemantics()))
1309 return U.Double.multiply(RHS.U.Double, RM);
1310 llvm_unreachable("Unexpected semantics");
1311 }
1312 opStatus divide(const APFloat &RHS, roundingMode RM) {
1313 assert(&getSemantics() == &RHS.getSemantics() &&
1314 "Should only call on two APFloats with the same semantics");
1315 if (usesLayout<IEEEFloat>(getSemantics()))
1316 return U.IEEE.divide(RHS.U.IEEE, RM);
1317 if (usesLayout<DoubleAPFloat>(getSemantics()))
1318 return U.Double.divide(RHS.U.Double, RM);
1319 llvm_unreachable("Unexpected semantics");
1320 }
1321 opStatus remainder(const APFloat &RHS) {
1322 assert(&getSemantics() == &RHS.getSemantics() &&
1323 "Should only call on two APFloats with the same semantics");
1324 if (usesLayout<IEEEFloat>(getSemantics()))
1325 return U.IEEE.remainder(RHS.U.IEEE);
1326 if (usesLayout<DoubleAPFloat>(getSemantics()))
1327 return U.Double.remainder(RHS.U.Double);
1328 llvm_unreachable("Unexpected semantics");
1329 }
1330 opStatus mod(const APFloat &RHS) {
1331 assert(&getSemantics() == &RHS.getSemantics() &&
1332 "Should only call on two APFloats with the same semantics");
1333 if (usesLayout<IEEEFloat>(getSemantics()))
1334 return U.IEEE.mod(RHS.U.IEEE);
1335 if (usesLayout<DoubleAPFloat>(getSemantics()))
1336 return U.Double.mod(RHS.U.Double);
1337 llvm_unreachable("Unexpected semantics");
1338 }
1339 opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend,
1340 roundingMode RM) {
1341 assert(&getSemantics() == &Multiplicand.getSemantics() &&
1342 "Should only call on APFloats with the same semantics");
1343 assert(&getSemantics() == &Addend.getSemantics() &&
1344 "Should only call on APFloats with the same semantics");
1345 if (usesLayout<IEEEFloat>(getSemantics()))
1346 return U.IEEE.fusedMultiplyAdd(Multiplicand.U.IEEE, Addend.U.IEEE, RM);
1347 if (usesLayout<DoubleAPFloat>(getSemantics()))
1348 return U.Double.fusedMultiplyAdd(Multiplicand.U.Double, Addend.U.Double,
1349 RM);
1350 llvm_unreachable("Unexpected semantics");
1351 }
1355
1356 // TODO: bool parameters are not readable and a source of bugs.
1357 // Do something.
1358 opStatus next(bool nextDown) {
1360 }
1361
1362 /// Negate an APFloat.
1363 APFloat operator-() const {
1364 APFloat Result(*this);
1365 Result.changeSign();
1366 return Result;
1367 }
1368
1369 /// Add two APFloats, rounding ties to the nearest even.
1370 /// No error checking.
1371 APFloat operator+(const APFloat &RHS) const {
1372 APFloat Result(*this);
1373 (void)Result.add(RHS, rmNearestTiesToEven);
1374 return Result;
1375 }
1376
1377 /// Subtract two APFloats, rounding ties to the nearest even.
1378 /// No error checking.
1379 APFloat operator-(const APFloat &RHS) const {
1380 APFloat Result(*this);
1381 (void)Result.subtract(RHS, rmNearestTiesToEven);
1382 return Result;
1383 }
1384
1385 /// Multiply two APFloats, rounding ties to the nearest even.
1386 /// No error checking.
1387 APFloat operator*(const APFloat &RHS) const {
1388 APFloat Result(*this);
1389 (void)Result.multiply(RHS, rmNearestTiesToEven);
1390 return Result;
1391 }
1392
1393 /// Divide the first APFloat by the second, rounding ties to the nearest even.
1394 /// No error checking.
1395 APFloat operator/(const APFloat &RHS) const {
1396 APFloat Result(*this);
1397 (void)Result.divide(RHS, rmNearestTiesToEven);
1398 return Result;
1399 }
1400
1402 void clearSign() {
1403 if (isNegative())
1404 changeSign();
1405 }
1406 void copySign(const APFloat &RHS) {
1407 if (isNegative() != RHS.isNegative())
1408 changeSign();
1409 }
1410
1411 /// A static helper to produce a copy of an APFloat value with its sign
1412 /// copied from some other APFloat.
1413 static APFloat copySign(APFloat Value, const APFloat &Sign) {
1414 Value.copySign(Sign);
1415 return Value;
1416 }
1417
1418 /// Assuming this is an IEEE-754 NaN value, quiet its signaling bit.
1419 /// This preserves the sign and payload bits.
1420 [[nodiscard]] APFloat makeQuiet() const {
1421 APFloat Result(*this);
1422 Result.getIEEE().makeQuiet();
1423 return Result;
1424 }
1425
1426 LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM,
1427 bool *losesInfo);
1428 // Convert a floating point number to an integer according to the
1429 // rounding mode. We provide deterministic values in case of an invalid
1430 // operation exception, namely zero for NaNs and the minimal or maximal value
1431 // respectively for underflow or overflow.
1432 // The *IsExact output tells whether the result is exact, in the sense that
1433 // converting it back to the original floating point type produces the
1434 // original value. This is almost equivalent to result==opOK, except for
1435 // negative zeroes.
1437 unsigned int Width, bool IsSigned, roundingMode RM,
1438 bool *IsExact) const {
1440 convertToInteger(Input, Width, IsSigned, RM, IsExact));
1441 }
1442 // Same as convertToInteger(integerPart*, ...), except the result is returned
1443 // in an APSInt, whose initial bit-width and signed-ness are used to determine
1444 // the precision of the conversion.
1446 bool *IsExact) const;
1447
1448 // Convert a two's complement integer Input to a floating point number,
1449 // rounding according to RM. IsSigned is true if the integer is signed,
1450 // in which case it must be sign-extended.
1451 opStatus convertFromAPInt(const APInt &Input, bool IsSigned,
1452 roundingMode RM) {
1454 }
1455
1456 /// Fill this APFloat with the result of a string conversion.
1457 ///
1458 /// The following strings are accepted for conversion purposes:
1459 /// * Decimal floating-point literals (e.g., `0.1e-5`)
1460 /// * Hexadecimal floating-point literals (e.g., `0x1.0p-5`)
1461 /// * Positive infinity via "inf", "INFINITY", "Inf", "+Inf", or "+inf".
1462 /// * Negative infinity via "-inf", "-INFINITY", or "-Inf".
1463 /// * Quiet NaNs via "nan", "NaN", "nan(...)", or "NaN(...)", where the
1464 /// "..." is either a decimal or hexadecimal integer representing the
1465 /// payload. A negative sign may be optionally provided.
1466 /// * Signaling NaNs via "snan", "sNaN", "snan(...)", or "sNaN(...)", where
1467 /// the "..." is either a decimal or hexadecimal integer representing the
1468 /// payload. A negative sign may be optionally provided.
1469 ///
1470 /// If the input string is none of these forms, then an error is returned.
1471 ///
1472 /// If a floating-point exception occurs during conversion, then no error is
1473 /// returned, and the exception is indicated via opStatus.
1478
1479 /// Converts this APFloat to host double value.
1480 ///
1481 /// \pre The APFloat must be built using semantics, that can be represented by
1482 /// the host double type without loss of precision. It can be IEEEdouble and
1483 /// shorter semantics, like IEEEsingle and others.
1484 LLVM_ABI double convertToDouble() const;
1485
1486 /// Converts this APFloat to host float value.
1487 ///
1488 /// \pre The APFloat must be built using semantics, that can be represented by
1489 /// the host float type without loss of precision. It can be IEEEquad and
1490 /// shorter semantics, like IEEEdouble and others.
1491#ifdef HAS_IEE754_FLOAT128
1492 LLVM_ABI float128 convertToQuad() const;
1493#endif
1494
1495 /// Converts this APFloat to host float value.
1496 ///
1497 /// \pre The APFloat must be built using semantics, that can be represented by
1498 /// the host float type without loss of precision. It can be IEEEsingle and
1499 /// shorter semantics, like IEEEhalf.
1500 LLVM_ABI float convertToFloat() const;
1501
1502 bool operator==(const APFloat &RHS) const { return compare(RHS) == cmpEqual; }
1503
1504 bool operator!=(const APFloat &RHS) const { return compare(RHS) != cmpEqual; }
1505
1506 bool operator<(const APFloat &RHS) const {
1507 return compare(RHS) == cmpLessThan;
1508 }
1509
1510 bool operator>(const APFloat &RHS) const {
1511 return compare(RHS) == cmpGreaterThan;
1512 }
1513
1514 bool operator<=(const APFloat &RHS) const {
1515 cmpResult Res = compare(RHS);
1516 return Res == cmpLessThan || Res == cmpEqual;
1517 }
1518
1519 bool operator>=(const APFloat &RHS) const {
1520 cmpResult Res = compare(RHS);
1521 return Res == cmpGreaterThan || Res == cmpEqual;
1522 }
1523
1524 // IEEE comparison with another floating point number (NaNs compare unordered,
1525 // 0==-0).
1526 cmpResult compare(const APFloat &RHS) const {
1527 assert(&getSemantics() == &RHS.getSemantics() &&
1528 "Should only compare APFloats with the same semantics");
1529 if (usesLayout<IEEEFloat>(getSemantics()))
1530 return U.IEEE.compare(RHS.U.IEEE);
1531 if (usesLayout<DoubleAPFloat>(getSemantics()))
1532 return U.Double.compare(RHS.U.Double);
1533 llvm_unreachable("Unexpected semantics");
1534 }
1535
1536 // Compares the absolute value of this APFloat with another. Both operands
1537 // must be finite non-zero.
1538 cmpResult compareAbsoluteValue(const APFloat &RHS) const {
1539 assert(&getSemantics() == &RHS.getSemantics() &&
1540 "Should only compare APFloats with the same semantics");
1541 if (usesLayout<IEEEFloat>(getSemantics()))
1542 return U.IEEE.compareAbsoluteValue(RHS.U.IEEE);
1543 if (usesLayout<DoubleAPFloat>(getSemantics()))
1544 return U.Double.compareAbsoluteValue(RHS.U.Double);
1545 llvm_unreachable("Unexpected semantics");
1546 }
1547
1548 bool bitwiseIsEqual(const APFloat &RHS) const {
1549 if (&getSemantics() != &RHS.getSemantics())
1550 return false;
1551 if (usesLayout<IEEEFloat>(getSemantics()))
1552 return U.IEEE.bitwiseIsEqual(RHS.U.IEEE);
1553 if (usesLayout<DoubleAPFloat>(getSemantics()))
1554 return U.Double.bitwiseIsEqual(RHS.U.Double);
1555 llvm_unreachable("Unexpected semantics");
1556 }
1557
1558 /// We don't rely on operator== working on double values, as
1559 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1560 /// As such, this method can be used to do an exact bit-for-bit comparison of
1561 /// two floating point values.
1562 ///
1563 /// We leave the version with the double argument here because it's just so
1564 /// convenient to write "2.0" and the like. Without this function we'd
1565 /// have to duplicate its logic everywhere it's called.
1566 bool isExactlyValue(double V) const {
1567 bool ignored;
1568 APFloat Tmp(V);
1570 return bitwiseIsEqual(Tmp);
1571 }
1572
1573 unsigned int convertToHexString(char *DST, unsigned int HexDigits,
1574 bool UpperCase, roundingMode RM) const {
1576 convertToHexString(DST, HexDigits, UpperCase, RM));
1577 }
1578
1579 bool isZero() const { return getCategory() == fcZero; }
1580 bool isInfinity() const { return getCategory() == fcInfinity; }
1581 bool isNaN() const { return getCategory() == fcNaN; }
1582
1583 bool isNegative() const { return getIEEE().isNegative(); }
1585 bool isSignaling() const { return getIEEE().isSignaling(); }
1586
1587 bool isNormal() const { return !isDenormal() && isFiniteNonZero(); }
1588 bool isFinite() const { return !isNaN() && !isInfinity(); }
1589
1590 fltCategory getCategory() const { return getIEEE().getCategory(); }
1591 const fltSemantics &getSemantics() const { return *U.semantics; }
1592 bool isNonZero() const { return !isZero(); }
1593 bool isFiniteNonZero() const { return isFinite() && !isZero(); }
1594 bool isPosZero() const { return isZero() && !isNegative(); }
1595 bool isNegZero() const { return isZero() && isNegative(); }
1596 bool isPosInfinity() const { return isInfinity() && !isNegative(); }
1597 bool isNegInfinity() const { return isInfinity() && isNegative(); }
1601
1605
1606 /// If the value is a NaN value, return an integer containing the payload of
1607 /// this value. This payload will include the quiet bit as part of the
1608 /// returned integer.
1610 assert(isNaN() && "Can only call this on a NaN value");
1612 }
1613
1614 /// Return the FPClassTest which will return true for the value.
1616
1617 APFloat &operator=(const APFloat &RHS) = default;
1618 APFloat &operator=(APFloat &&RHS) = default;
1619
1620 void toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision = 0,
1621 unsigned FormatMaxPadding = 3, bool TruncateZero = true) const {
1623 toString(Str, FormatPrecision, FormatMaxPadding, TruncateZero));
1624 }
1625
1626 LLVM_ABI void print(raw_ostream &) const;
1627
1628#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1629 LLVM_DUMP_METHOD void dump() const;
1630#endif
1631
1632 /// If this value is normal and has an exact, normal, multiplicative inverse,
1633 /// store it in inv and return true.
1634 LLVM_ABI bool getExactInverse(APFloat *Inv) const;
1635
1636 // If this is an exact power of two, return the exponent while ignoring the
1637 // sign bit. If it's not an exact power of 2, return INT_MIN
1642
1643 // If this is an exact power of two, return the exponent. If it's not an exact
1644 // power of 2, return INT_MIN
1646 int getExactLog2() const {
1647 return isNegative() ? INT_MIN : getExactLog2Abs();
1648 }
1649
1650 // Returns true if this value is exactly 2^N.
1652 bool isPowerOf2(int N) const { return N != INT_MIN && getExactLog2() == N; }
1653
1654 // Returns true if this value is exactly -(2^N).
1656 bool isNegPowerOf2(int N) const {
1657 return N != INT_MIN && isNegative() && getExactLog2Abs() == N;
1658 }
1659
1660 // Returns true if this value is exactly +1.0.
1661 LLVM_READONLY bool isOne() const { return isPowerOf2(0); }
1662
1663 // Returns true if this value is exactly -1.0.
1664 LLVM_READONLY bool isMinusOne() const { return isNegPowerOf2(0); }
1665
1666 LLVM_ABI friend hash_code hash_value(const APFloat &Arg);
1667 friend int ilogb(const APFloat &Arg);
1668 friend APFloat scalbn(APFloat X, int Exp, roundingMode RM);
1669 friend APFloat frexp(const APFloat &X, int &Exp, roundingMode RM);
1670 friend IEEEFloat;
1671 friend DoubleAPFloat;
1672};
1673
1674static_assert(sizeof(APFloat) == sizeof(detail::IEEEFloat),
1675 "Empty base class optimization is not performed.");
1676
1677/// See friend declarations above.
1678///
1679/// These additional declarations are required in order to compile LLVM with IBM
1680/// xlC compiler.
1682
1683/// Returns the exponent of the internal representation of the APFloat.
1684///
1685/// Because the radix of APFloat is 2, this is equivalent to floor(log2(x)).
1686/// For special APFloat values, this returns special error codes:
1687///
1688/// NaN -> \c IEK_NaN
1689/// 0 -> \c IEK_Zero
1690/// Inf -> \c IEK_Inf
1691///
1692inline int ilogb(const APFloat &Arg) {
1693 if (APFloat::usesLayout<detail::IEEEFloat>(Arg.getSemantics()))
1694 return ilogb(Arg.U.IEEE);
1695 if (APFloat::usesLayout<detail::DoubleAPFloat>(Arg.getSemantics()))
1696 return ilogb(Arg.U.Double);
1697 llvm_unreachable("Unexpected semantics");
1698}
1699
1700/// Returns: X * 2^Exp for integral exponents.
1702 if (APFloat::usesLayout<detail::IEEEFloat>(X.getSemantics()))
1703 return APFloat(scalbn(X.U.IEEE, Exp, RM), X.getSemantics());
1704 if (APFloat::usesLayout<detail::DoubleAPFloat>(X.getSemantics()))
1705 return APFloat(scalbn(X.U.Double, Exp, RM), X.getSemantics());
1706 llvm_unreachable("Unexpected semantics");
1707}
1708
1709/// Equivalent of C standard library function.
1710///
1711/// While the C standard says Exp is an unspecified value for infinity and nan,
1712/// this returns INT_MAX for infinities, and INT_MIN for NaNs.
1713inline APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM) {
1714 if (APFloat::usesLayout<detail::IEEEFloat>(X.getSemantics()))
1715 return APFloat(frexp(X.U.IEEE, Exp, RM), X.getSemantics());
1716 if (APFloat::usesLayout<detail::DoubleAPFloat>(X.getSemantics()))
1717 return APFloat(frexp(X.U.Double, Exp, RM), X.getSemantics());
1718 llvm_unreachable("Unexpected semantics");
1719}
1720/// Returns the absolute value of the argument.
1722 X.clearSign();
1723 return X;
1724}
1725
1726/// Returns the negated value of the argument.
1728 X.changeSign();
1729 return X;
1730}
1731
1732/// Implements IEEE-754 2008 minNum semantics. Returns the smaller of the
1733/// 2 arguments if both are not NaN. If either argument is a qNaN, returns the
1734/// other argument. If either argument is sNaN, return a qNaN.
1735/// -0 is treated as ordered less than +0.
1737inline APFloat minnum(const APFloat &A, const APFloat &B) {
1738 if (A.isSignaling())
1739 return A.makeQuiet();
1740 if (B.isSignaling())
1741 return B.makeQuiet();
1742 if (A.isNaN())
1743 return B;
1744 if (B.isNaN())
1745 return A;
1746 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1747 return A.isNegative() ? A : B;
1748 return B < A ? B : A;
1749}
1750
1751/// Implements IEEE-754 2008 maxNum semantics. Returns the larger of the
1752/// 2 arguments if both are not NaN. If either argument is a qNaN, returns the
1753/// other argument. If either argument is sNaN, return a qNaN.
1754/// +0 is treated as ordered greater than -0.
1756inline APFloat maxnum(const APFloat &A, const APFloat &B) {
1757 if (A.isSignaling())
1758 return A.makeQuiet();
1759 if (B.isSignaling())
1760 return B.makeQuiet();
1761 if (A.isNaN())
1762 return B;
1763 if (B.isNaN())
1764 return A;
1765 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1766 return A.isNegative() ? B : A;
1767 return A < B ? B : A;
1768}
1769
1770/// Implements IEEE 754-2019 minimum semantics. Returns the smaller of 2
1771/// arguments, returning a quiet NaN if an argument is a NaN and treating -0
1772/// as less than +0.
1774inline APFloat minimum(const APFloat &A, const APFloat &B) {
1775 if (A.isNaN())
1776 return A.makeQuiet();
1777 if (B.isNaN())
1778 return B.makeQuiet();
1779 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1780 return A.isNegative() ? A : B;
1781 return B < A ? B : A;
1782}
1783
1784/// Implements IEEE 754-2019 minimumNumber semantics. Returns the smaller
1785/// of 2 arguments, not propagating NaNs and treating -0 as less than +0.
1787inline APFloat minimumnum(const APFloat &A, const APFloat &B) {
1788 if (A.isNaN())
1789 return B.isNaN() ? B.makeQuiet() : B;
1790 if (B.isNaN())
1791 return A;
1792 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1793 return A.isNegative() ? A : B;
1794 return B < A ? B : A;
1795}
1796
1797/// Implements IEEE 754-2019 maximum semantics. Returns the larger of 2
1798/// arguments, returning a quiet NaN if an argument is a NaN and treating -0
1799/// as less than +0.
1801inline APFloat maximum(const APFloat &A, const APFloat &B) {
1802 if (A.isNaN())
1803 return A.makeQuiet();
1804 if (B.isNaN())
1805 return B.makeQuiet();
1806 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1807 return A.isNegative() ? B : A;
1808 return A < B ? B : A;
1809}
1810
1811/// Implements IEEE 754-2019 maximumNumber semantics. Returns the larger
1812/// of 2 arguments, not propagating NaNs and treating -0 as less than +0.
1814inline APFloat maximumnum(const APFloat &A, const APFloat &B) {
1815 if (A.isNaN())
1816 return B.isNaN() ? B.makeQuiet() : B;
1817 if (B.isNaN())
1818 return A;
1819 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1820 return A.isNegative() ? B : A;
1821 return A < B ? B : A;
1822}
1823
1824/// Implement IEEE 754-2019 exp functions
1826LLVM_ABI std::optional<APFloat>
1827exp(const APFloat &X, RoundingMode RM = APFloat::rmNearestTiesToEven,
1828 APFloat::opStatus *Status = nullptr);
1829
1831 V.print(OS);
1832 return OS;
1833}
1834
1835// We want the following functions to be available in the header for inlining.
1836// We cannot define them inline in the class definition of `DoubleAPFloat`
1837// because doing so would instantiate `std::unique_ptr<APFloat[]>` before
1838// `APFloat` is defined, and that would be undefined behavior.
1839namespace detail {
1840
1842 if (this != &RHS) {
1843 this->~DoubleAPFloat();
1844 new (this) DoubleAPFloat(std::move(RHS));
1845 }
1846 return *this;
1847}
1848
1849APFloat &DoubleAPFloat::getFirst() { return Floats[0]; }
1850const APFloat &DoubleAPFloat::getFirst() const { return Floats[0]; }
1851APFloat &DoubleAPFloat::getSecond() { return Floats[1]; }
1852const APFloat &DoubleAPFloat::getSecond() const { return Floats[1]; }
1853
1854inline DoubleAPFloat::~DoubleAPFloat() { delete[] Floats; }
1855
1856} // namespace detail
1857
1858} // namespace llvm
1859
1860#undef APFLOAT_DISPATCH_ON_SEMANTICS
1861#endif // LLVM_ADT_APFLOAT_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned uint64_t
#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL)
Definition APFloat.h:27
This file implements a class to represent arbitrary precision integral constant values and operations...
#define X(NUM, ENUM, NAME)
Definition ELF.h:857
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:215
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:678
#define LLVM_READONLY
Definition Compiler.h:330
Utilities for dealing with flags related to floating point properties and mode controls.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Load MIR Sample Profile
#define T
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, const llvm::StringTable &StandardNames, VectorLibrary VecLib)
Initialize the set of available library functions based on the specified target triple.
Value * RHS
Value * LHS
The Input class is used to parse a yaml document into in-memory structs and vectors.
static const fltSemantics & IEEEsingle()
Definition APFloat.h:304
static const fltSemantics & Float8E4M3FN()
Definition APFloat.h:314
static LLVM_ABI const llvm::fltSemantics & EnumToSemantics(Semantics S)
Definition APFloat.cpp:134
static LLVM_ABI bool semanticsHasInf(const fltSemantics &)
Definition APFloat.cpp:351
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
Definition APFloat.h:351
static constexpr roundingMode rmTowardZero
Definition APFloat.h:365
static LLVM_ABI ExponentType semanticsMinExponent(const fltSemantics &)
Definition APFloat.cpp:326
llvm::RoundingMode roundingMode
IEEE-754R 4.3: Rounding-direction attributes.
Definition APFloat.h:359
static const fltSemantics & BFloat()
Definition APFloat.h:303
static const fltSemantics & IEEEquad()
Definition APFloat.h:306
static LLVM_ABI unsigned int semanticsSizeInBits(const fltSemantics &)
Definition APFloat.cpp:329
static const fltSemantics & Float8E8M0FNU()
Definition APFloat.h:321
static LLVM_ABI bool semanticsHasSignedRepr(const fltSemantics &)
Definition APFloat.cpp:347
static const fltSemantics & IEEEdouble()
Definition APFloat.h:305
static LLVM_ABI unsigned getSizeInBits(const fltSemantics &Sem)
Returns the size of the floating point number (in bits) in the given semantics.
Definition APFloat.cpp:382
static const fltSemantics & x87DoubleExtended()
Definition APFloat.h:326
static constexpr roundingMode rmTowardNegative
Definition APFloat.h:364
uninitializedTag
Convenience enum used to construct an uninitialized APFloat.
Definition APFloat.h:395
static constexpr roundingMode rmNearestTiesToEven
Definition APFloat.h:361
static LLVM_ABI bool isValidArbitraryFPFormat(StringRef Format)
Returns true if the given string is a valid arbitrary floating-point format interpretation for llvm....
Definition APFloat.cpp:6127
static LLVM_ABI bool hasSignBitInMSB(const fltSemantics &)
Definition APFloat.cpp:364
static LLVM_ABI ExponentType semanticsMaxExponent(const fltSemantics &)
Definition APFloat.cpp:322
friend class APFloat
Definition APFloat.h:299
static const fltSemantics & Bogus()
A Pseudo fltsemantic used to construct APFloats that cannot conflict with anything real.
Definition APFloat.h:332
static LLVM_ABI unsigned int semanticsPrecision(const fltSemantics &)
Definition APFloat.cpp:318
static LLVM_ABI bool semanticsHasNaN(const fltSemantics &)
Definition APFloat.cpp:355
static LLVM_ABI Semantics SemanticsToEnum(const llvm::fltSemantics &Sem)
Definition APFloat.cpp:183
int32_t ExponentType
A signed type to represent a floating point numbers unbiased exponent.
Definition APFloat.h:156
static constexpr unsigned integerPartWidth
Definition APFloat.h:153
static const fltSemantics & PPCDoubleDoubleLegacy()
Definition APFloat.h:308
static LLVM_ABI bool isLosslesslyConvertibleTo(const fltSemantics &From, const fltSemantics &To, bool IgnoreNaNs=false)
Returns whether converting a value from From to To is known to preserve all information.
Definition APFloat.cpp:236
APInt::WordType integerPart
Definition APFloat.h:152
static LLVM_ABI bool semanticsHasZero(const fltSemantics &)
Definition APFloat.cpp:343
static LLVM_ABI bool isRepresentableAsNormalIn(const fltSemantics &Src, const fltSemantics &Dst)
Definition APFloat.cpp:368
static const fltSemantics & Float8E5M2FNUZ()
Definition APFloat.h:312
static const fltSemantics & Float8E4M3FNUZ()
Definition APFloat.h:315
static constexpr roundingMode rmTowardPositive
Definition APFloat.h:363
static const fltSemantics & IEEEhalf()
Definition APFloat.h:302
static const fltSemantics & Float4E2M1FN()
Definition APFloat.h:325
static const fltSemantics & Float6E2M3FN()
Definition APFloat.h:324
IlogbErrorKinds
Enumeration of ilogb error results.
Definition APFloat.h:400
static const fltSemantics & Float8E4M3()
Definition APFloat.h:313
static const fltSemantics & Float8E4M3B11FNUZ()
Definition APFloat.h:316
static LLVM_ABI bool isRepresentableBy(const fltSemantics &A, const fltSemantics &B)
Definition APFloat.cpp:230
static const fltSemantics & Float8E3M4()
Definition APFloat.h:319
static LLVM_ABI bool isIEEELikeFP(const fltSemantics &)
Definition APFloat.cpp:359
static const fltSemantics & Float8E5M2()
Definition APFloat.h:311
fltCategory
Category of internally-represented number.
Definition APFloat.h:387
static constexpr roundingMode rmNearestTiesToAway
Definition APFloat.h:366
static const fltSemantics & PPCDoubleDouble()
Definition APFloat.h:307
static const fltSemantics & Float6E3M2FN()
Definition APFloat.h:323
opStatus
IEEE-754R 7: Default exception handling.
Definition APFloat.h:377
static const fltSemantics & Float8E5M3FNU()
Definition APFloat.h:322
static LLVM_ABI unsigned getArbitraryFPFormatSizeInBits(StringRef Format)
Returns the size in bits of a valid arbitrary floating-point format string, or 0 if the string is not...
Definition APFloat.cpp:6110
static LLVM_ABI const fltSemantics * getArbitraryFPSemantics(StringRef Format)
Returns the fltSemantics for a given arbitrary FP format string, or nullptr if invalid.
Definition APFloat.cpp:6131
static const fltSemantics & FloatTF32()
Definition APFloat.h:320
static LLVM_ABI unsigned int semanticsIntSizeInBits(const fltSemantics &, bool)
Definition APFloat.cpp:332
static APFloat getQNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for QNaN values.
Definition APFloat.h:1224
static APFloat getSNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for SNaN values.
Definition APFloat.h:1232
LLVM_READONLY bool isNegPowerOf2(int N) const
Definition APFloat.h:1656
opStatus divide(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1312
APFloat & operator=(APFloat &&RHS)=default
bool isFiniteNonZero() const
Definition APFloat.h:1593
APFloat(const APFloat &RHS)=default
void copySign(const APFloat &RHS)
Definition APFloat.h:1406
LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Definition APFloat.cpp:6010
LLVM_READONLY int getExactLog2Abs() const
Definition APFloat.h:1639
opStatus subtract(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1294
bool bitwiseIsEqual(const APFloat &RHS) const
Definition APFloat.h:1548
bool isNegative() const
Definition APFloat.h:1583
~APFloat()=default
LLVM_ABI bool getExactInverse(APFloat *Inv) const
If this value is normal and has an exact, normal, multiplicative inverse, store it in inv and return ...
Definition APFloat.cpp:5952
cmpResult compareAbsoluteValue(const APFloat &RHS) const
Definition APFloat.h:1538
APFloat operator+(const APFloat &RHS) const
Add two APFloats, rounding ties to the nearest even.
Definition APFloat.h:1371
friend DoubleAPFloat
Definition APFloat.h:1671
LLVM_ABI double convertToDouble() const
Converts this APFloat to host double value.
Definition APFloat.cpp:6069
bool isPosInfinity() const
Definition APFloat.h:1596
APFloat(APFloat &&RHS)=default
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
Definition APFloat.h:1620
bool isNormal() const
Definition APFloat.h:1587
bool isDenormal() const
Definition APFloat.h:1584
bool isExactlyValue(double V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
Definition APFloat.h:1566
opStatus add(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1285
LLVM_READONLY int getExactLog2() const
Definition APFloat.h:1646
APFloat(double d)
Definition APFloat.h:1171
APFloat & operator=(const APFloat &RHS)=default
LLVM_READONLY bool isPowerOf2(int N) const
Definition APFloat.h:1652
static LLVM_ABI APFloat getAllOnesValue(const fltSemantics &Semantics)
Returns a float which is bitcasted from an all one value int.
Definition APFloat.cpp:6036
LLVM_ABI friend hash_code hash_value(const APFloat &Arg)
See friend declarations above.
Definition APFloat.cpp:5924
APFloat(const fltSemantics &Semantics, integerPart I)
Definition APFloat.h:1163
bool operator!=(const APFloat &RHS) const
Definition APFloat.h:1504
APFloat(const fltSemantics &Semantics, T V)=delete
const fltSemantics & getSemantics() const
Definition APFloat.h:1591
APFloat operator-(const APFloat &RHS) const
Subtract two APFloats, rounding ties to the nearest even.
Definition APFloat.h:1379
APFloat operator*(const APFloat &RHS) const
Multiply two APFloats, rounding ties to the nearest even.
Definition APFloat.h:1387
APFloat(const fltSemantics &Semantics)
Definition APFloat.h:1161
bool isNonZero() const
Definition APFloat.h:1592
void clearSign()
Definition APFloat.h:1402
bool operator<(const APFloat &RHS) const
Definition APFloat.h:1506
bool isFinite() const
Definition APFloat.h:1588
APFloat makeQuiet() const
Assuming this is an IEEE-754 NaN value, quiet its signaling bit.
Definition APFloat.h:1420
bool isNaN() const
Definition APFloat.h:1581
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
Definition APFloat.h:1451
static APFloat getOne(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative One.
Definition APFloat.h:1192
unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
Definition APFloat.h:1573
opStatus multiply(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1303
LLVM_ABI float convertToFloat() const
Converts this APFloat to host float value.
Definition APFloat.cpp:6097
bool isSignaling() const
Definition APFloat.h:1585
bool operator>(const APFloat &RHS) const
Definition APFloat.h:1510
opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend, roundingMode RM)
Definition APFloat.h:1339
APFloat operator/(const APFloat &RHS) const
Divide the first APFloat by the second, rounding ties to the nearest even.
Definition APFloat.h:1395
opStatus remainder(const APFloat &RHS)
Definition APFloat.h:1321
APFloat operator-() const
Negate an APFloat.
Definition APFloat.h:1363
bool isZero() const
Definition APFloat.h:1579
LLVM_READONLY bool isOne() const
Definition APFloat.h:1661
static APFloat getSmallestNormalized(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
Definition APFloat.h:1262
APInt bitcastToAPInt() const
Definition APFloat.h:1475
bool isLargest() const
Definition APFloat.h:1599
friend APFloat frexp(const APFloat &X, int &Exp, roundingMode RM)
bool isSmallest() const
Definition APFloat.h:1598
static APFloat getLargest(const fltSemantics &Sem, bool Negative=false)
Returns the largest finite number in the given semantics.
Definition APFloat.h:1242
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
Definition APFloat.h:1436
opStatus next(bool nextDown)
Definition APFloat.h:1358
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
Definition APFloat.h:1202
friend APFloat scalbn(APFloat X, int Exp, roundingMode RM)
bool operator>=(const APFloat &RHS) const
Definition APFloat.h:1519
bool needsCleanup() const
Definition APFloat.h:1178
static APFloat getSmallest(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) finite number in the given semantics.
Definition APFloat.h:1252
LLVM_ABI FPClassTest classify() const
Return the FPClassTest which will return true for the value.
Definition APFloat.cpp:5939
bool operator==(const APFloat &RHS) const
Definition APFloat.h:1502
opStatus mod(const APFloat &RHS)
Definition APFloat.h:1330
bool isPosZero() const
Definition APFloat.h:1594
APInt getNaNPayload() const
If the value is a NaN value, return an integer containing the payload of this value.
Definition APFloat.h:1609
friend int ilogb(const APFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
Definition APFloat.h:1692
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
Fill this APFloat with the result of a string conversion.
Definition APFloat.cpp:5919
fltCategory getCategory() const
Definition APFloat.h:1590
APFloat(const fltSemantics &Semantics, uninitializedTag)
Definition APFloat.h:1168
bool isInteger() const
Definition APFloat.h:1600
bool isNegInfinity() const
Definition APFloat.h:1597
friend IEEEFloat
Definition APFloat.h:1670
LLVM_DUMP_METHOD void dump() const
Definition APFloat.cpp:6047
bool isNegZero() const
Definition APFloat.h:1595
LLVM_ABI void print(raw_ostream &) const
Definition APFloat.cpp:6040
static APFloat copySign(APFloat Value, const APFloat &Sign)
A static helper to produce a copy of an APFloat value with its sign copied from some other APFloat.
Definition APFloat.h:1413
LLVM_READONLY bool isMinusOne() const
Definition APFloat.h:1664
APFloat(float f)
Definition APFloat.h:1172
opStatus roundToIntegral(roundingMode RM)
Definition APFloat.h:1352
void changeSign()
Definition APFloat.h:1401
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
Definition APFloat.h:1213
static bool hasSignificand(const fltSemantics &Sem)
Returns true if the given semantics has actual significand.
Definition APFloat.h:1277
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Definition APFloat.h:1183
cmpResult compare(const APFloat &RHS) const
Definition APFloat.h:1526
bool isSmallestNormalized() const
Definition APFloat.h:1602
APFloat(const fltSemantics &Semantics, const APInt &I)
Definition APFloat.h:1170
bool isInfinity() const
Definition APFloat.h:1580
bool operator<=(const APFloat &RHS) const
Definition APFloat.h:1514
Class for arbitrary precision integers.
Definition APInt.h:78
uint64_t WordType
Definition APInt.h:80
static constexpr unsigned APINT_BITS_PER_WORD
Bits in a word.
Definition APInt.h:86
An arbitrary precision integer that knows its signedness.
Definition APSInt.h:24
Tagged union holding either a T or a Error.
Definition Error.h:485
This class is used to gather all the unique data bits of a node.
Definition FoldingSet.h:162
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:294
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
LLVM Value Representation.
Definition Value.h:75
LLVM_ABI void makeSmallestNormalized(bool Neg)
Definition APFloat.cpp:5266
LLVM_ABI DoubleAPFloat & operator=(const DoubleAPFloat &RHS)
Definition APFloat.cpp:4796
LLVM_ABI void changeSign()
Definition APFloat.cpp:5173
LLVM_ABI bool isLargest() const
Definition APFloat.cpp:5740
LLVM_ABI opStatus remainder(const DoubleAPFloat &RHS)
Definition APFloat.cpp:5060
LLVM_ABI opStatus multiply(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:4963
LLVM_ABI fltCategory getCategory() const
Definition APFloat.cpp:5232
LLVM_ABI bool bitwiseIsEqual(const DoubleAPFloat &RHS) const
Definition APFloat.cpp:5289
LLVM_ABI LLVM_READONLY int getExactLog2Abs() const
Definition APFloat.cpp:5764
LLVM_ABI opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
Definition APFloat.cpp:5691
LLVM_ABI APInt bitcastToAPInt() const
Definition APFloat.cpp:5300
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
Definition APFloat.cpp:5310
LLVM_ABI bool isSmallest() const
Definition APFloat.cpp:5723
LLVM_ABI opStatus subtract(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:4955
LLVM_ABI friend hash_code hash_value(const DoubleAPFloat &Arg)
Definition APFloat.cpp:5294
LLVM_ABI cmpResult compareAbsoluteValue(const DoubleAPFloat &RHS) const
Definition APFloat.cpp:5179
LLVM_ABI bool isDenormal() const
Definition APFloat.cpp:5716
LLVM_ABI opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
Definition APFloat.cpp:5527
LLVM_ABI void makeSmallest(bool Neg)
Definition APFloat.cpp:5259
LLVM_ABI friend int ilogb(const DoubleAPFloat &X)
Definition APFloat.cpp:5773
LLVM_ABI opStatus next(bool nextDown)
Definition APFloat.cpp:5326
LLVM_ABI void makeInf(bool Neg)
Definition APFloat.cpp:5238
LLVM_ABI bool isInteger() const
Definition APFloat.cpp:5748
LLVM_ABI void makeZero(bool Neg)
Definition APFloat.cpp:5243
LLVM_ABI opStatus divide(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:5049
LLVM_ABI bool isSmallestNormalized() const
Definition APFloat.cpp:5731
LLVM_ABI opStatus mod(const DoubleAPFloat &RHS)
Definition APFloat.cpp:5070
LLVM_ABI DoubleAPFloat(const fltSemantics &S)
Definition APFloat.cpp:4743
LLVM_ABI void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision, unsigned FormatMaxPadding, bool TruncateZero=true) const
Definition APFloat.cpp:5754
LLVM_ABI void makeLargest(bool Neg)
Definition APFloat.cpp:5248
LLVM_ABI cmpResult compare(const DoubleAPFloat &RHS) const
Definition APFloat.cpp:5281
LLVM_ABI friend DoubleAPFloat scalbn(const DoubleAPFloat &X, int Exp, roundingMode)
LLVM_ABI opStatus roundToIntegral(roundingMode RM)
Definition APFloat.cpp:5096
LLVM_ABI opStatus fusedMultiplyAdd(const DoubleAPFloat &Multiplicand, const DoubleAPFloat &Addend, roundingMode RM)
Definition APFloat.cpp:5081
LLVM_ABI APInt getNaNPayload() const
Definition APFloat.cpp:5902
LLVM_ABI unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
Definition APFloat.cpp:5706
bool needsCleanup() const
Definition APFloat.h:902
LLVM_ABI bool isNegative() const
Definition APFloat.cpp:5236
LLVM_ABI opStatus add(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:4950
LLVM_ABI friend DoubleAPFloat frexp(const DoubleAPFloat &X, int &Exp, roundingMode)
LLVM_ABI void makeNaN(bool SNaN, bool Neg, const APInt *fill)
Definition APFloat.cpp:5276
LLVM_ABI unsigned int convertToHexString(char *dst, unsigned int hexDigits, bool upperCase, roundingMode) const
Write out a hexadecimal representation of the floating point value to DST, which must be of sufficien...
Definition APFloat.cpp:3297
LLVM_ABI cmpResult compareAbsoluteValue(const IEEEFloat &) const
Definition APFloat.cpp:1529
LLVM_ABI opStatus mod(const IEEEFloat &)
C fmod, or llvm frem.
Definition APFloat.cpp:2285
fltCategory getCategory() const
Definition APFloat.h:605
LLVM_ABI opStatus convertFromAPInt(const APInt &, bool, roundingMode)
Definition APFloat.cpp:2857
LLVM_ABI APInt getNaNPayload() const
Definition APFloat.cpp:4631
bool isNonZero() const
Definition APFloat.h:607
bool isFiniteNonZero() const
Definition APFloat.h:608
bool needsCleanup() const
Returns whether this instance allocated memory.
Definition APFloat.h:495
LLVM_ABI void makeLargest(bool Neg=false)
Make this number the largest magnitude normal number in the given semantics.
Definition APFloat.cpp:4058
LLVM_ABI LLVM_READONLY int getExactLog2Abs() const
Definition APFloat.cpp:4453
LLVM_ABI APInt bitcastToAPInt() const
Definition APFloat.cpp:3678
LLVM_ABI friend IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
Definition APFloat.cpp:4703
LLVM_ABI cmpResult compare(const IEEEFloat &) const
IEEE comparison with another floating point number (NaNs compare unordered, 0==-0).
Definition APFloat.cpp:2453
bool isNegative() const
IEEE-754R isSignMinus: Returns true if and only if the current value is negative.
Definition APFloat.h:570
LLVM_ABI opStatus divide(const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2159
LLVM_ABI friend hash_code hash_value(const IEEEFloat &Arg)
Overload to compute a hash code for an APFloat value.
Definition APFloat.cpp:3437
bool isNaN() const
Returns true if and only if the float is a quiet or signaling NaN.
Definition APFloat.h:595
LLVM_ABI opStatus remainder(const IEEEFloat &)
IEEE remainder.
Definition APFloat.cpp:2177
LLVM_ABI double convertToDouble() const
Definition APFloat.cpp:3751
LLVM_ABI float convertToFloat() const
Definition APFloat.cpp:3744
LLVM_ABI opStatus subtract(const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2135
LLVM_ABI void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
Converts this value into a decimal string.
Definition APFloat.cpp:4409
LLVM_ABI void makeSmallest(bool Neg=false)
Make this number the smallest magnitude denormal number in the given semantics.
Definition APFloat.cpp:4090
LLVM_ABI void makeInf(bool Neg=false)
Definition APFloat.cpp:4650
bool isNormal() const
IEEE-754R isNormal: Returns true if and only if the current value is normal.
Definition APFloat.h:576
LLVM_ABI bool isSmallestNormalized() const
Returns true if this is the smallest (by magnitude) normalized finite number in the given semantics.
Definition APFloat.cpp:1050
friend class IEEEFloatUnitTestHelper
Definition APFloat.h:852
LLVM_ABI void makeQuiet()
Definition APFloat.cpp:4679
LLVM_ABI bool isLargest() const
Returns true if and only if the number has the largest possible finite magnitude in the current seman...
Definition APFloat.cpp:1152
LLVM_ABI opStatus add(const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2129
bool isFinite() const
Returns true if and only if the current value is zero, subnormal, or normal.
Definition APFloat.h:582
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
Definition APFloat.cpp:3240
LLVM_ABI void makeNaN(bool SNaN=false, bool Neg=false, const APInt *fill=nullptr)
Definition APFloat.cpp:938
LLVM_ABI opStatus multiply(const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2141
LLVM_ABI opStatus roundToIntegral(roundingMode)
Definition APFloat.cpp:2368
LLVM_ABI IEEEFloat & operator=(const IEEEFloat &)
Definition APFloat.cpp:1010
LLVM_ABI bool bitwiseIsEqual(const IEEEFloat &) const
Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
Definition APFloat.cpp:1177
LLVM_ABI void makeSmallestNormalized(bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
Definition APFloat.cpp:4104
LLVM_ABI bool isInteger() const
Returns true if and only if the number is an exact integer.
Definition APFloat.cpp:1169
bool isPosZero() const
Definition APFloat.h:609
LLVM_ABI IEEEFloat(const fltSemantics &)
Definition APFloat.cpp:1204
LLVM_ABI opStatus fusedMultiplyAdd(const IEEEFloat &, const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2322
LLVM_ABI friend int ilogb(const IEEEFloat &Arg)
Definition APFloat.cpp:4685
LLVM_ABI opStatus next(bool nextDown)
IEEE-754R 5.3.1: nextUp/nextDown.
Definition APFloat.cpp:4498
bool isInfinity() const
IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
Definition APFloat.h:592
const fltSemantics & getSemantics() const
Definition APFloat.h:606
bool isZero() const
Returns true if and only if the float is plus or minus zero.
Definition APFloat.h:585
LLVM_ABI bool isSignaling() const
Returns true if and only if the float is a signaling NaN.
Definition APFloat.cpp:4482
bool operator==(const IEEEFloat &) const =delete
The definition of equality is not straightforward for floating point, so we won't use operator==.
LLVM_ABI void makeZero(bool Neg=false)
Definition APFloat.cpp:4665
LLVM_ABI opStatus convert(const fltSemantics &, roundingMode, bool *)
IEEEFloat::convert - convert a value of one floating point type to another.
Definition APFloat.cpp:2529
LLVM_ABI void changeSign()
Definition APFloat.cpp:2087
LLVM_ABI bool isDenormal() const
IEEE-754R isSubnormal(): Returns true if and only if the float is a denormal.
Definition APFloat.cpp:1035
LLVM_ABI opStatus convertToInteger(MutableArrayRef< integerPart >, unsigned int, bool, roundingMode, bool *) const
Definition APFloat.cpp:2802
LLVM_ABI friend IEEEFloat frexp(const IEEEFloat &X, int &Exp, roundingMode)
Definition APFloat.cpp:4724
LLVM_ABI bool isSmallest() const
Returns true if and only if the number has the smallest possible non-zero magnitude in the current se...
Definition APFloat.cpp:1042
bool isNegZero() const
Definition APFloat.h:610
An opaque object representing a hash code.
Definition Hashing.h:77
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static constexpr opStatus opInexact
Definition APFloat.h:471
static constexpr fltCategory fcNaN
Definition APFloat.h:473
static constexpr opStatus opDivByZero
Definition APFloat.h:468
static constexpr opStatus opOverflow
Definition APFloat.h:469
static constexpr cmpResult cmpLessThan
Definition APFloat.h:463
static constexpr roundingMode rmTowardPositive
Definition APFloat.h:459
static constexpr uninitializedTag uninitialized
Definition APFloat.h:453
static constexpr fltCategory fcZero
Definition APFloat.h:475
static constexpr opStatus opOK
Definition APFloat.h:466
static constexpr cmpResult cmpGreaterThan
Definition APFloat.h:464
static constexpr unsigned integerPartWidth
Definition APFloat.h:461
LLVM_ABI hash_code hash_value(const IEEEFloat &Arg)
Definition APFloat.cpp:3437
APFloatBase::ExponentType ExponentType
Definition APFloat.h:452
APFloatBase::fltCategory fltCategory
Definition APFloat.h:451
static constexpr fltCategory fcNormal
Definition APFloat.h:474
static constexpr opStatus opInvalidOp
Definition APFloat.h:467
APFloatBase::opStatus opStatus
Definition APFloat.h:449
LLVM_ABI IEEEFloat frexp(const IEEEFloat &Val, int &Exp, roundingMode RM)
Definition APFloat.cpp:4724
APFloatBase::uninitializedTag uninitializedTag
Definition APFloat.h:447
static constexpr cmpResult cmpUnordered
Definition APFloat.h:465
static constexpr roundingMode rmTowardNegative
Definition APFloat.h:458
APFloatBase::roundingMode roundingMode
Definition APFloat.h:448
APFloatBase::cmpResult cmpResult
Definition APFloat.h:450
static constexpr fltCategory fcInfinity
Definition APFloat.h:472
static constexpr roundingMode rmNearestTiesToAway
Definition APFloat.h:456
static constexpr roundingMode rmTowardZero
Definition APFloat.h:460
static constexpr opStatus opUnderflow
Definition APFloat.h:470
static constexpr roundingMode rmNearestTiesToEven
Definition APFloat.h:454
LLVM_ABI int ilogb(const IEEEFloat &Arg)
Definition APFloat.cpp:4685
static constexpr cmpResult cmpEqual
Definition APFloat.h:462
LLVM_ABI IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
Definition APFloat.cpp:4703
APFloatBase::integerPart integerPart
Definition APFloat.h:446
This is an optimization pass for GlobalISel generic memory operations.
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1759
hash_code hash_value(const FixedPointSemantics &Val)
static constexpr APFloatBase::ExponentType exponentZero(const fltSemantics &semantics)
Definition APFloat.cpp:387
APFloat abs(APFloat X)
Returns the absolute value of the argument.
Definition APFloat.h:1721
LLVM_READONLY APFloat maximum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 maximum semantics.
Definition APFloat.h:1801
static void assign(DXContainerYAML::SourceInfo::SectionHeader &Dst, const dxbc::SourceInfo::SectionHeader &Src)
int ilogb(const APFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
Definition APFloat.h:1692
APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM)
Equivalent of C standard library function.
Definition APFloat.h:1713
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE-754 2008 maxNum semantics.
Definition APFloat.h:1756
lostFraction
Enum that represents what fraction of the LSB truncated bits of an fp number represent.
Definition APFloat.h:51
@ lfMoreThanHalf
Definition APFloat.h:55
@ lfLessThanHalf
Definition APFloat.h:53
@ lfExactlyHalf
Definition APFloat.h:54
@ lfExactlyZero
Definition APFloat.h:52
LLVM_READONLY LLVM_ABI std::optional< APFloat > exp(const APFloat &X, RoundingMode RM=APFloat::rmNearestTiesToEven, APFloat::opStatus *Status=nullptr)
Implement IEEE 754-2019 exp functions.
Definition APFloat.cpp:6229
LLVM_READONLY APFloat minimumnum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 minimumNumber semantics.
Definition APFloat.h:1787
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
APFloat scalbn(APFloat X, int Exp, APFloat::roundingMode RM)
Returns: X * 2^Exp for integral exponents.
Definition APFloat.h:1701
static constexpr APFloatBase::ExponentType exponentNaN(const fltSemantics &semantics)
Definition APFloat.cpp:397
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:74
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE-754 2008 minNum semantics.
Definition APFloat.h:1737
fltNonfiniteBehavior
Definition APFloat.h:977
RoundingMode
Rounding mode.
@ TowardZero
roundTowardZero.
@ NearestTiesToEven
roundTiesToEven.
@ TowardPositive
roundTowardPositive.
@ NearestTiesToAway
roundTiesToAway.
@ TowardNegative
roundTowardNegative.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
static constexpr APFloatBase::ExponentType exponentInf(const fltSemantics &semantics)
Definition APFloat.cpp:392
APFloat neg(APFloat X)
Returns the negated value of the argument.
Definition APFloat.h:1727
LLVM_READONLY APFloat minimum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 minimum semantics.
Definition APFloat.h:1774
LLVM_READONLY APFloat maximumnum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 maximumNumber semantics.
Definition APFloat.h:1814
fltNanEncoding
Definition APFloat.h:1001
#define N
APFloatBase::ExponentType maxExponent
Definition APFloat.h:1026
fltNonfiniteBehavior nonFiniteBehavior
Definition APFloat.h:1039
APFloatBase::ExponentType minExponent
Definition APFloat.h:1030
unsigned int sizeInBits
Definition APFloat.h:1037
unsigned int precision
Definition APFloat.h:1034
fltNanEncoding nanEncoding
Definition APFloat.h:1041
bool hasExplicitIntegerBit
Definition APFloat.h:1069