LLVM 23.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 // TODO: Documentation is missing.
262 };
263
266
267private:
268 LLVM_ABI static const fltSemantics semIEEEhalf;
269 LLVM_ABI static const fltSemantics semBFloat;
270 LLVM_ABI static const fltSemantics semIEEEsingle;
271 LLVM_ABI static const fltSemantics semIEEEdouble;
272 LLVM_ABI static const fltSemantics semIEEEquad;
273 LLVM_ABI static const fltSemantics semFloat8E5M2;
274 LLVM_ABI static const fltSemantics semFloat8E5M2FNUZ;
275 LLVM_ABI static const fltSemantics semFloat8E4M3;
276 LLVM_ABI static const fltSemantics semFloat8E4M3FN;
277 LLVM_ABI static const fltSemantics semFloat8E4M3FNUZ;
278 LLVM_ABI static const fltSemantics semFloat8E4M3B11FNUZ;
279 LLVM_ABI static const fltSemantics semFloat8E3M4;
280 LLVM_ABI static const fltSemantics semFloatTF32;
281 LLVM_ABI static const fltSemantics semFloat8E8M0FNU;
282 LLVM_ABI static const fltSemantics semFloat6E3M2FN;
283 LLVM_ABI static const fltSemantics semFloat6E2M3FN;
284 LLVM_ABI static const fltSemantics semFloat4E2M1FN;
285 LLVM_ABI static const fltSemantics semX87DoubleExtended;
286 LLVM_ABI static const fltSemantics semBogus;
287 LLVM_ABI static const fltSemantics semPPCDoubleDouble;
288 LLVM_ABI static const fltSemantics semPPCDoubleDoubleLegacy;
289
290 friend class detail::IEEEFloat;
292 friend class APFloat;
293
294public:
295 static const fltSemantics &IEEEhalf() { return semIEEEhalf; }
296 static const fltSemantics &BFloat() { return semBFloat; }
297 static const fltSemantics &IEEEsingle() { return semIEEEsingle; }
298 static const fltSemantics &IEEEdouble() { return semIEEEdouble; }
299 static const fltSemantics &IEEEquad() { return semIEEEquad; }
300 static const fltSemantics &PPCDoubleDouble() { return semPPCDoubleDouble; }
302 return semPPCDoubleDoubleLegacy;
303 }
304 static const fltSemantics &Float8E5M2() { return semFloat8E5M2; }
305 static const fltSemantics &Float8E5M2FNUZ() { return semFloat8E5M2FNUZ; }
306 static const fltSemantics &Float8E4M3() { return semFloat8E4M3; }
307 static const fltSemantics &Float8E4M3FN() { return semFloat8E4M3FN; }
308 static const fltSemantics &Float8E4M3FNUZ() { return semFloat8E4M3FNUZ; }
310 return semFloat8E4M3B11FNUZ;
311 }
312 static const fltSemantics &Float8E3M4() { return semFloat8E3M4; }
313 static const fltSemantics &FloatTF32() { return semFloatTF32; }
314 static const fltSemantics &Float8E8M0FNU() { return semFloat8E8M0FNU; }
315 static const fltSemantics &Float6E3M2FN() { return semFloat6E3M2FN; }
316 static const fltSemantics &Float6E2M3FN() { return semFloat6E2M3FN; }
317 static const fltSemantics &Float4E2M1FN() { return semFloat4E2M1FN; }
319 return semX87DoubleExtended;
320 }
321
322 /// A Pseudo fltsemantic used to construct APFloats that cannot conflict with
323 /// anything real.
324 static const fltSemantics &Bogus() { return semBogus; }
325
326 // Returns true if any number described by this semantics can be precisely
327 // represented by the specified semantics. Does not take into account
328 // the value of fltNonfiniteBehavior, hasZero, hasSignedRepr.
329 LLVM_ABI static bool isRepresentableBy(const fltSemantics &A,
330 const fltSemantics &B);
331
332 /// @}
333
334 /// IEEE-754R 5.11: Floating Point Comparison Relations.
341
342 /// IEEE-754R 4.3: Rounding-direction attributes.
344
352
353 /// IEEE-754R 7: Default exception handling.
354 ///
355 /// opUnderflow or opOverflow are always returned or-ed with opInexact.
356 ///
357 /// APFloat models this behavior specified by IEEE-754:
358 /// "For operations producing results in floating-point format, the default
359 /// result of an operation that signals the invalid operation exception
360 /// shall be a quiet NaN."
361 enum opStatus {
362 opOK = 0x00,
368 };
369
370 /// Category of internally-represented number.
377
378 /// Convenience enum used to construct an uninitialized APFloat.
382
383 /// Enumeration of \c ilogb error results.
385 IEK_Zero = INT_MIN + 1,
386 IEK_NaN = INT_MIN,
387 IEK_Inf = INT_MAX
388 };
389
390 LLVM_ABI static unsigned int semanticsPrecision(const fltSemantics &);
393 LLVM_ABI static unsigned int semanticsSizeInBits(const fltSemantics &);
394 LLVM_ABI static unsigned int semanticsIntSizeInBits(const fltSemantics &,
395 bool);
396 LLVM_ABI static bool semanticsHasZero(const fltSemantics &);
397 LLVM_ABI static bool semanticsHasSignedRepr(const fltSemantics &);
398 LLVM_ABI static bool semanticsHasInf(const fltSemantics &);
399 LLVM_ABI static bool semanticsHasNaN(const fltSemantics &);
400 LLVM_ABI static bool isIEEELikeFP(const fltSemantics &);
401 LLVM_ABI static bool hasSignBitInMSB(const fltSemantics &);
402
403 // Returns true if any number described by \p Src can be precisely represented
404 // by a normal (not subnormal) value in \p Dst.
405 LLVM_ABI static bool isRepresentableAsNormalIn(const fltSemantics &Src,
406 const fltSemantics &Dst);
407
408 /// Returns the size of the floating point number (in bits) in the given
409 /// semantics.
410 LLVM_ABI static unsigned getSizeInBits(const fltSemantics &Sem);
411
412 /// Returns true if the given string is a valid arbitrary floating-point
413 /// format interpretation for llvm.convert.to.arbitrary.fp and
414 /// llvm.convert.from.arbitrary.fp intrinsics.
416
417 /// Returns the fltSemantics for a given arbitrary FP format string,
418 /// or nullptr if invalid.
420};
421
422namespace detail {
423
444static constexpr opStatus opOK = APFloatBase::opOK;
454
455class IEEEFloat final {
456public:
457 /// \name Constructors
458 /// @{
459
460 LLVM_ABI IEEEFloat(const fltSemantics &); // Default construct to +0.0
463 LLVM_ABI IEEEFloat(const fltSemantics &, const APInt &);
464 LLVM_ABI explicit IEEEFloat(double d);
465 LLVM_ABI explicit IEEEFloat(float f);
469
470 /// @}
471
472 /// Returns whether this instance allocated memory.
473 bool needsCleanup() const { return partCount() > 1; }
474
475 /// \name Convenience "constructors"
476 /// @{
477
478 /// @}
479
480 /// \name Arithmetic
481 /// @{
482
487 /// IEEE remainder.
489 /// C fmod, or llvm frem.
494 /// IEEE-754R 5.3.1: nextUp/nextDown.
495 LLVM_ABI opStatus next(bool nextDown);
496
497 /// @}
498
499 /// \name Sign operations.
500 /// @{
501
502 LLVM_ABI void changeSign();
503
504 /// @}
505
506 /// \name Conversions
507 /// @{
508
511 bool, roundingMode, bool *) const;
515 LLVM_ABI double convertToDouble() const;
516#ifdef HAS_IEE754_FLOAT128
517 LLVM_ABI float128 convertToQuad() const;
518#endif
519 LLVM_ABI float convertToFloat() const;
520
521 /// @}
522
523 /// The definition of equality is not straightforward for floating point, so
524 /// we won't use operator==. Use one of the following, or write whatever it
525 /// is you really mean.
526 bool operator==(const IEEEFloat &) const = delete;
527
528 /// IEEE comparison with another floating point number (NaNs compare
529 /// unordered, 0==-0).
530 LLVM_ABI cmpResult compare(const IEEEFloat &) const;
531
532 /// Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
533 LLVM_ABI bool bitwiseIsEqual(const IEEEFloat &) const;
534
535 /// Write out a hexadecimal representation of the floating point value to DST,
536 /// which must be of sufficient size, in the C99 form [-]0xh.hhhhp[+-]d.
537 /// Return the number of characters written, excluding the terminating NUL.
538 LLVM_ABI unsigned int convertToHexString(char *dst, unsigned int hexDigits,
539 bool upperCase, roundingMode) const;
540
541 /// \name IEEE-754R 5.7.2 General operations.
542 /// @{
543
544 /// IEEE-754R isSignMinus: Returns true if and only if the current value is
545 /// negative.
546 ///
547 /// This applies to zeros and NaNs as well.
548 bool isNegative() const { return sign; }
549
550 /// IEEE-754R isNormal: Returns true if and only if the current value is normal.
551 ///
552 /// This implies that the current value of the float is not zero, subnormal,
553 /// infinite, or NaN following the definition of normality from IEEE-754R.
554 bool isNormal() const { return !isDenormal() && isFiniteNonZero(); }
555
556 /// Returns true if and only if the current value is zero, subnormal, or
557 /// normal.
558 ///
559 /// This means that the value is not infinite or NaN.
560 bool isFinite() const { return !isNaN() && !isInfinity(); }
561
562 /// Returns true if and only if the float is plus or minus zero.
563 bool isZero() const { return category == fltCategory::fcZero; }
564
565 /// IEEE-754R isSubnormal(): Returns true if and only if the float is a
566 /// denormal.
567 LLVM_ABI bool isDenormal() const;
568
569 /// IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
570 bool isInfinity() const { return category == fcInfinity; }
571
572 /// Returns true if and only if the float is a quiet or signaling NaN.
573 bool isNaN() const { return category == fcNaN; }
574
575 /// Returns true if and only if the float is a signaling NaN.
576 LLVM_ABI bool isSignaling() const;
577
578 /// @}
579
580 /// \name Simple Queries
581 /// @{
582
583 fltCategory getCategory() const { return category; }
584 const fltSemantics &getSemantics() const { return *semantics; }
585 bool isNonZero() const { return category != fltCategory::fcZero; }
586 bool isFiniteNonZero() const { return isFinite() && !isZero(); }
587 bool isPosZero() const { return isZero() && !isNegative(); }
588 bool isNegZero() const { return isZero() && isNegative(); }
589
590 /// Returns true if and only if the number has the smallest possible non-zero
591 /// magnitude in the current semantics.
592 LLVM_ABI bool isSmallest() const;
593
594 /// Returns true if this is the smallest (by magnitude) normalized finite
595 /// number in the given semantics.
596 LLVM_ABI bool isSmallestNormalized() const;
597
598 /// Returns true if and only if the number has the largest possible finite
599 /// magnitude in the current semantics.
600 LLVM_ABI bool isLargest() const;
601
602 /// Returns true if and only if the number is an exact integer.
603 LLVM_ABI bool isInteger() const;
604
605 /// @}
606
609
610 /// Overload to compute a hash code for an APFloat value.
611 ///
612 /// Note that the use of hash codes for floating point values is in general
613 /// frought with peril. Equality is hard to define for these values. For
614 /// example, should negative and positive zero hash to different codes? Are
615 /// they equal or not? This hash value implementation specifically
616 /// emphasizes producing different codes for different inputs in order to
617 /// be used in canonicalization and memoization. As such, equality is
618 /// bitwiseIsEqual, and 0 != -0.
619 LLVM_ABI friend hash_code hash_value(const IEEEFloat &Arg);
620
621 /// Converts this value into a decimal string.
622 ///
623 /// \param FormatPrecision The maximum number of digits of
624 /// precision to output. If there are fewer digits available,
625 /// zero padding will not be used unless the value is
626 /// integral and small enough to be expressed in
627 /// FormatPrecision digits. 0 means to use the natural
628 /// precision of the number.
629 /// \param FormatMaxPadding The maximum number of zeros to
630 /// consider inserting before falling back to scientific
631 /// notation. 0 means to always use scientific notation.
632 ///
633 /// \param TruncateZero Indicate whether to remove the trailing zero in
634 /// fraction part or not. Also setting this parameter to false forcing
635 /// producing of output more similar to default printf behavior.
636 /// Specifically the lower e is used as exponent delimiter and exponent
637 /// always contains no less than two digits.
638 ///
639 /// Number Precision MaxPadding Result
640 /// ------ --------- ---------- ------
641 /// 1.01E+4 5 2 10100
642 /// 1.01E+4 4 2 1.01E+4
643 /// 1.01E+4 5 1 1.01E+4
644 /// 1.01E-2 5 2 0.0101
645 /// 1.01E-2 4 2 0.0101
646 /// 1.01E-2 4 1 1.01E-2
648 unsigned FormatPrecision = 0,
649 unsigned FormatMaxPadding = 3,
650 bool TruncateZero = true) const;
651
653
654 LLVM_ABI friend int ilogb(const IEEEFloat &Arg);
655
657
658 LLVM_ABI friend IEEEFloat frexp(const IEEEFloat &X, int &Exp, roundingMode);
659
660 /// \name Special value setters.
661 /// @{
662
663 LLVM_ABI void makeLargest(bool Neg = false);
664 LLVM_ABI void makeSmallest(bool Neg = false);
665 LLVM_ABI void makeNaN(bool SNaN = false, bool Neg = false,
666 const APInt *fill = nullptr);
667 LLVM_ABI void makeInf(bool Neg = false);
668 LLVM_ABI void makeZero(bool Neg = false);
669 LLVM_ABI void makeQuiet();
670
671 /// Returns the smallest (by magnitude) normalized finite number in the given
672 /// semantics.
673 ///
674 /// \param Negative - True iff the number should be negative
675 LLVM_ABI void makeSmallestNormalized(bool Negative = false);
676
677 /// @}
678
680
682
683private:
684 /// \name Simple Queries
685 /// @{
686
687 integerPart *significandParts();
688 const integerPart *significandParts() const;
689 LLVM_ABI unsigned int partCount() const;
690
691 /// @}
692
693 /// \name Significand operations.
694 /// @{
695
696 integerPart addSignificand(const IEEEFloat &);
697 integerPart subtractSignificand(const IEEEFloat &, integerPart);
698 // Exported for IEEEFloatUnitTestHelper.
699 LLVM_ABI lostFraction addOrSubtractSignificand(const IEEEFloat &,
700 bool subtract);
701 lostFraction multiplySignificand(const IEEEFloat &, IEEEFloat,
702 bool ignoreAddend = false);
703 lostFraction multiplySignificand(const IEEEFloat&);
704 lostFraction divideSignificand(const IEEEFloat &);
705 void incrementSignificand();
706 void initialize(const fltSemantics *);
707 void shiftSignificandLeft(unsigned int);
708 lostFraction shiftSignificandRight(unsigned int);
709 unsigned int significandLSB() const;
710 unsigned int significandMSB() const;
711 void zeroSignificand();
712 unsigned int getNumHighBits() const;
713 /// Return true if the significand excluding the integral bit is all ones.
714 bool isSignificandAllOnes() const;
715 bool isSignificandAllOnesExceptLSB() const;
716 /// Return true if the significand excluding the integral bit is all zeros.
717 bool isSignificandAllZeros() const;
718 bool isSignificandAllZerosExceptMSB() const;
719
720 /// @}
721
722 /// \name Arithmetic on special values.
723 /// @{
724
725 opStatus addOrSubtractSpecials(const IEEEFloat &, bool subtract);
726 opStatus divideSpecials(const IEEEFloat &);
727 opStatus multiplySpecials(const IEEEFloat &);
728 opStatus modSpecials(const IEEEFloat &);
729 opStatus remainderSpecials(const IEEEFloat&);
730
731 /// @}
732
733 /// \name Miscellany
734 /// @{
735
736 bool convertFromStringSpecials(StringRef str);
738 opStatus addOrSubtract(const IEEEFloat &, roundingMode, bool subtract);
739 opStatus handleOverflow(roundingMode);
740 bool roundAwayFromZero(roundingMode, lostFraction, unsigned int) const;
741 opStatus convertToSignExtendedInteger(MutableArrayRef<integerPart>,
742 unsigned int, bool, roundingMode,
743 bool *) const;
744 opStatus convertFromUnsignedParts(const integerPart *, unsigned int,
746 Expected<opStatus> convertFromHexadecimalString(StringRef, roundingMode);
747 Expected<opStatus> convertFromDecimalString(StringRef, roundingMode);
748 char *convertNormalToHexString(char *, unsigned int, bool,
749 roundingMode) const;
750 opStatus roundSignificandWithExponent(const integerPart *, unsigned int, int,
755
756 /// @}
757
758 template <const fltSemantics &S> APInt convertIEEEFloatToAPInt() const;
759 APInt convertHalfAPFloatToAPInt() const;
760 APInt convertBFloatAPFloatToAPInt() const;
761 APInt convertFloatAPFloatToAPInt() const;
762 APInt convertDoubleAPFloatToAPInt() const;
763 APInt convertQuadrupleAPFloatToAPInt() const;
764 APInt convertF80LongDoubleAPFloatToAPInt() const;
765 APInt convertPPCDoubleDoubleLegacyAPFloatToAPInt() const;
766 APInt convertFloat8E5M2APFloatToAPInt() const;
767 APInt convertFloat8E5M2FNUZAPFloatToAPInt() const;
768 APInt convertFloat8E4M3APFloatToAPInt() const;
769 APInt convertFloat8E4M3FNAPFloatToAPInt() const;
770 APInt convertFloat8E4M3FNUZAPFloatToAPInt() const;
771 APInt convertFloat8E4M3B11FNUZAPFloatToAPInt() const;
772 APInt convertFloat8E3M4APFloatToAPInt() const;
773 APInt convertFloatTF32APFloatToAPInt() const;
774 APInt convertFloat8E8M0FNUAPFloatToAPInt() const;
775 APInt convertFloat6E3M2FNAPFloatToAPInt() const;
776 APInt convertFloat6E2M3FNAPFloatToAPInt() const;
777 APInt convertFloat4E2M1FNAPFloatToAPInt() const;
778 void initFromAPInt(const fltSemantics *Sem, const APInt &api);
779 template <const fltSemantics &S> void initFromIEEEAPInt(const APInt &api);
780 void initFromHalfAPInt(const APInt &api);
781 void initFromBFloatAPInt(const APInt &api);
782 void initFromFloatAPInt(const APInt &api);
783 void initFromDoubleAPInt(const APInt &api);
784 void initFromQuadrupleAPInt(const APInt &api);
785 void initFromF80LongDoubleAPInt(const APInt &api);
786 void initFromPPCDoubleDoubleLegacyAPInt(const APInt &api);
787 void initFromFloat8E5M2APInt(const APInt &api);
788 void initFromFloat8E5M2FNUZAPInt(const APInt &api);
789 void initFromFloat8E4M3APInt(const APInt &api);
790 void initFromFloat8E4M3FNAPInt(const APInt &api);
791 void initFromFloat8E4M3FNUZAPInt(const APInt &api);
792 void initFromFloat8E4M3B11FNUZAPInt(const APInt &api);
793 void initFromFloat8E3M4APInt(const APInt &api);
794 void initFromFloatTF32APInt(const APInt &api);
795 void initFromFloat8E8M0FNUAPInt(const APInt &api);
796 void initFromFloat6E3M2FNAPInt(const APInt &api);
797 void initFromFloat6E2M3FNAPInt(const APInt &api);
798 void initFromFloat4E2M1FNAPInt(const APInt &api);
799
800 void assign(const IEEEFloat &);
801 void copySignificand(const IEEEFloat &);
802 void freeSignificand();
803
804 /// Note: this must be the first data member.
805 /// The semantics that this value obeys.
806 const fltSemantics *semantics;
807
808 /// A binary fraction with an explicit integer bit.
809 ///
810 /// The significand must be at least one bit wider than the target precision.
811 union Significand {
812 integerPart part;
813 integerPart *parts;
814 } significand;
815
816 /// The signed unbiased exponent of the value.
817 ExponentType exponent;
818
819 /// What kind of floating point number this is.
820 ///
821 /// Only 2 bits are required, but VisualStudio incorrectly sign extends it.
822 /// Using the extra bit keeps it from failing under VisualStudio.
823 fltCategory category : 3;
824
825 /// Sign bit of the number.
826 unsigned int sign : 1;
827
829};
830
832LLVM_ABI int ilogb(const IEEEFloat &Arg);
834LLVM_ABI IEEEFloat frexp(const IEEEFloat &Val, int &Exp, roundingMode RM);
835
836// This mode implements more precise float in terms of two APFloats.
837// The interface and layout is designed for arbitrary underlying semantics,
838// though currently only PPCDoubleDouble semantics are supported, whose
839// corresponding underlying semantics are IEEEdouble.
840class DoubleAPFloat final {
841 // Note: this must be the first data member.
842 const fltSemantics *Semantics;
843 APFloat *Floats;
844
845 opStatus addImpl(const APFloat &a, const APFloat &aa, const APFloat &c,
846 const APFloat &cc, roundingMode RM);
847
848 opStatus addWithSpecial(const DoubleAPFloat &LHS, const DoubleAPFloat &RHS,
849 DoubleAPFloat &Out, roundingMode RM);
850 opStatus convertToSignExtendedInteger(MutableArrayRef<integerPart> Input,
851 unsigned int Width, bool IsSigned,
852 roundingMode RM, bool *IsExact) const;
853
854 // Convert an unsigned integer Src to a floating point number,
855 // rounding according to RM. The sign of the floating point number is not
856 // modified.
857 opStatus convertFromUnsignedParts(const integerPart *Src,
858 unsigned int SrcCount, roundingMode RM);
859
860 // Handle overflow. Sign is preserved. We either become infinity or
861 // the largest finite number.
862 opStatus handleOverflow(roundingMode RM);
863
864public:
868 LLVM_ABI DoubleAPFloat(const fltSemantics &S, const APInt &I);
870 APFloat &&Second);
874
877
878 bool needsCleanup() const { return Floats != nullptr; }
879
880 inline APFloat &getFirst();
881 inline const APFloat &getFirst() const;
882 inline APFloat &getSecond();
883 inline const APFloat &getSecond() const;
884
892 const DoubleAPFloat &Addend,
893 roundingMode RM);
895 LLVM_ABI void changeSign();
897
899 LLVM_ABI bool isNegative() const;
900
901 LLVM_ABI void makeInf(bool Neg);
902 LLVM_ABI void makeZero(bool Neg);
903 LLVM_ABI void makeLargest(bool Neg);
904 LLVM_ABI void makeSmallest(bool Neg);
905 LLVM_ABI void makeSmallestNormalized(bool Neg);
906 LLVM_ABI void makeNaN(bool SNaN, bool Neg, const APInt *fill);
907
909 LLVM_ABI bool bitwiseIsEqual(const DoubleAPFloat &RHS) const;
912 LLVM_ABI opStatus next(bool nextDown);
913
915 unsigned int Width, bool IsSigned,
916 roundingMode RM, bool *IsExact) const;
917 LLVM_ABI opStatus convertFromAPInt(const APInt &Input, bool IsSigned,
918 roundingMode RM);
919 LLVM_ABI unsigned int convertToHexString(char *DST, unsigned int HexDigits,
920 bool UpperCase,
921 roundingMode RM) const;
922
923 LLVM_ABI bool isDenormal() const;
924 LLVM_ABI bool isSmallest() const;
925 LLVM_ABI bool isSmallestNormalized() const;
926 LLVM_ABI bool isLargest() const;
927 LLVM_ABI bool isInteger() const;
928
930
931 LLVM_ABI void toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision,
932 unsigned FormatMaxPadding,
933 bool TruncateZero = true) const;
934
936
937 LLVM_ABI friend int ilogb(const DoubleAPFloat &X);
940 LLVM_ABI friend DoubleAPFloat frexp(const DoubleAPFloat &X, int &Exp,
942 LLVM_ABI friend hash_code hash_value(const DoubleAPFloat &Arg);
943};
944
946LLVM_ABI DoubleAPFloat scalbn(const DoubleAPFloat &Arg, int Exp,
947 roundingMode RM);
949
950} // End detail namespace
951
952// How the nonfinite values Inf and NaN are represented.
954 // Represents standard IEEE 754 behavior. A value is nonfinite if the
955 // exponent field is all 1s. In such cases, a value is Inf if the
956 // significand bits are all zero, and NaN otherwise
958
959 // This behavior is present in the Float8ExMyFN* types (Float8E4M3FN,
960 // Float8E5M2FNUZ, Float8E4M3FNUZ, and Float8E4M3B11FNUZ). There is no
961 // representation for Inf, and operations that would ordinarily produce Inf
962 // produce NaN instead.
963 // The details of the NaN representation(s) in this form are determined by the
964 // `fltNanEncoding` enum. We treat all NaNs as quiet, as the available
965 // encodings do not distinguish between signalling and quiet NaN.
967
968 // This behavior is present in Float6E3M2FN, Float6E2M3FN, and
969 // Float4E2M1FN types, which do not support Inf or NaN values.
971};
972
973// How NaN values are represented. This is curently only used in combination
974// with fltNonfiniteBehavior::NanOnly, and using a variant other than IEEE
975// while having IEEE non-finite behavior is liable to lead to unexpected
976// results.
977enum class fltNanEncoding {
978 // Represents the standard IEEE behavior where a value is NaN if its
979 // exponent is all 1s and the significand is non-zero.
981
982 // Represents the behavior in the Float8E4M3FN floating point type where NaN
983 // is represented by having the exponent and mantissa set to all 1s.
984 // This behavior matches the FP8 E4M3 type described in
985 // https://arxiv.org/abs/2209.05433. We treat both signed and unsigned NaNs
986 // as non-signalling, although the paper does not state whether the NaN
987 // values are signalling or not.
989
990 // Represents the behavior in Float8E{5,4}E{2,3}FNUZ floating point types
991 // where NaN is represented by a sign bit of 1 and all 0s in the exponent
992 // and mantissa (i.e. the negative zero encoding in a IEEE float). Since
993 // there is only one NaN value, it is treated as quiet NaN. This matches the
994 // behavior described in https://arxiv.org/abs/2206.02915 .
996};
997/* Represents floating point arithmetic semantics. */
999 /* The largest E such that 2^E is representable; this matches the
1000 definition of IEEE 754. */
1002
1003 /* The smallest E such that 2^E is a normalized number; this
1004 matches the definition of IEEE 754. */
1006
1007 /* Number of bits in the significand. This includes the integer
1008 bit. */
1009 unsigned int precision;
1010
1011 /* Number of bits actually used in the semantics. */
1012 unsigned int sizeInBits;
1013
1015
1017
1018 /* Whether this semantics has an encoding for Zero */
1019 bool hasZero = true;
1020
1021 /* Whether this semantics can represent signed values */
1022 bool hasSignedRepr = true;
1023
1024 /* Whether the sign bit of this semantics is the most significant bit */
1025 bool hasSignBitInMSB = true;
1026
1027 /* Whether the format supports IEEE754 denormal representation.
1028 If both hasDenormals and hasZero are false exponent 0 is assumed to be a
1029 regular exponent instead of being reserved. This changes the bias by +1. */
1030 bool hasDenormals = true;
1031};
1032
1033// This is a interface class that is currently forwarding functionalities from
1034// detail::IEEEFloat.
1035class APFloat : public APFloatBase {
1036 using IEEEFloat = detail::IEEEFloat;
1037 using DoubleAPFloat = detail::DoubleAPFloat;
1038
1039 static_assert(std::is_standard_layout<IEEEFloat>::value);
1040
1041 union Storage {
1042 const fltSemantics *semantics;
1043 IEEEFloat IEEE;
1044 DoubleAPFloat Double;
1045
1046 LLVM_ABI explicit Storage(IEEEFloat F, const fltSemantics &S);
1047 explicit Storage(DoubleAPFloat F, const fltSemantics &S)
1048 : Double(std::move(F)) {
1049 assert(&S == &PPCDoubleDouble());
1050 }
1051
1052 template <typename... ArgTypes>
1053 Storage(const fltSemantics &Semantics, ArgTypes &&... Args) {
1054 if (usesLayout<IEEEFloat>(Semantics)) {
1055 new (&IEEE) IEEEFloat(Semantics, std::forward<ArgTypes>(Args)...);
1056 return;
1057 }
1058 if (usesLayout<DoubleAPFloat>(Semantics)) {
1059 new (&Double) DoubleAPFloat(Semantics, std::forward<ArgTypes>(Args)...);
1060 return;
1061 }
1062 llvm_unreachable("Unexpected semantics");
1063 }
1064
1065 LLVM_ABI ~Storage();
1066 LLVM_ABI Storage(const Storage &RHS);
1067 LLVM_ABI Storage(Storage &&RHS);
1068 LLVM_ABI Storage &operator=(const Storage &RHS);
1069 LLVM_ABI Storage &operator=(Storage &&RHS);
1070 } U;
1071
1072 template <typename T> static bool usesLayout(const fltSemantics &Semantics) {
1073 static_assert(std::is_same<T, IEEEFloat>::value ||
1074 std::is_same<T, DoubleAPFloat>::value);
1075 if (std::is_same<T, DoubleAPFloat>::value) {
1076 return &Semantics == &PPCDoubleDouble();
1077 }
1078 return &Semantics != &PPCDoubleDouble();
1079 }
1080
1081 IEEEFloat &getIEEE() {
1082 if (usesLayout<IEEEFloat>(*U.semantics))
1083 return U.IEEE;
1084 if (usesLayout<DoubleAPFloat>(*U.semantics))
1085 return U.Double.getFirst().U.IEEE;
1086 llvm_unreachable("Unexpected semantics");
1087 }
1088
1089 const IEEEFloat &getIEEE() const {
1090 if (usesLayout<IEEEFloat>(*U.semantics))
1091 return U.IEEE;
1092 if (usesLayout<DoubleAPFloat>(*U.semantics))
1093 return U.Double.getFirst().U.IEEE;
1094 llvm_unreachable("Unexpected semantics");
1095 }
1096
1097 void makeZero(bool Neg) { APFLOAT_DISPATCH_ON_SEMANTICS(makeZero(Neg)); }
1098
1099 void makeInf(bool Neg) { APFLOAT_DISPATCH_ON_SEMANTICS(makeInf(Neg)); }
1100
1101 void makeNaN(bool SNaN, bool Neg, const APInt *fill) {
1102 APFLOAT_DISPATCH_ON_SEMANTICS(makeNaN(SNaN, Neg, fill));
1103 }
1104
1105 void makeLargest(bool Neg) {
1106 APFLOAT_DISPATCH_ON_SEMANTICS(makeLargest(Neg));
1107 }
1108
1109 void makeSmallest(bool Neg) {
1110 APFLOAT_DISPATCH_ON_SEMANTICS(makeSmallest(Neg));
1111 }
1112
1113 void makeSmallestNormalized(bool Neg) {
1114 APFLOAT_DISPATCH_ON_SEMANTICS(makeSmallestNormalized(Neg));
1115 }
1116
1117 explicit APFloat(IEEEFloat F, const fltSemantics &S) : U(std::move(F), S) {}
1118 explicit APFloat(DoubleAPFloat F, const fltSemantics &S)
1119 : U(std::move(F), S) {}
1120
1121public:
1125 template <typename T,
1126 typename = std::enable_if_t<std::is_floating_point<T>::value>>
1127 APFloat(const fltSemantics &Semantics, T V) = delete;
1128 // TODO: Remove this constructor. This isn't faster than the first one.
1132 explicit APFloat(double d) : U(IEEEFloat(d), IEEEdouble()) {}
1133 explicit APFloat(float f) : U(IEEEFloat(f), IEEEsingle()) {}
1134 APFloat(const APFloat &RHS) = default;
1135 APFloat(APFloat &&RHS) = default;
1136
1137 ~APFloat() = default;
1138
1140
1141 /// Factory for Positive and Negative Zero.
1142 ///
1143 /// \param Negative True iff the number should be negative.
1144 static APFloat getZero(const fltSemantics &Sem, bool Negative = false) {
1145 APFloat Val(Sem, uninitialized);
1146 Val.makeZero(Negative);
1147 return Val;
1148 }
1149
1150 /// Factory for Positive and Negative One.
1151 ///
1152 /// \param Negative True iff the number should be negative.
1153 static APFloat getOne(const fltSemantics &Sem, bool Negative = false) {
1154 APFloat Val(Sem, 1U);
1155 if (Negative)
1156 Val.changeSign();
1157 return Val;
1158 }
1159
1160 /// Factory for Positive and Negative Infinity.
1161 ///
1162 /// \param Negative True iff the number should be negative.
1163 static APFloat getInf(const fltSemantics &Sem, bool Negative = false) {
1164 APFloat Val(Sem, uninitialized);
1165 Val.makeInf(Negative);
1166 return Val;
1167 }
1168
1169 /// Factory for NaN values.
1170 ///
1171 /// \param Negative - True iff the NaN generated should be negative.
1172 /// \param payload - The unspecified fill bits for creating the NaN, 0 by
1173 /// default. The value is truncated as necessary.
1174 static APFloat getNaN(const fltSemantics &Sem, bool Negative = false,
1175 uint64_t payload = 0) {
1176 if (payload) {
1177 APInt intPayload(64, payload);
1178 return getQNaN(Sem, Negative, &intPayload);
1179 } else {
1180 return getQNaN(Sem, Negative, nullptr);
1181 }
1182 }
1183
1184 /// Factory for QNaN values.
1185 static APFloat getQNaN(const fltSemantics &Sem, bool Negative = false,
1186 const APInt *payload = nullptr) {
1187 APFloat Val(Sem, uninitialized);
1188 Val.makeNaN(false, Negative, payload);
1189 return Val;
1190 }
1191
1192 /// Factory for SNaN values.
1193 static APFloat getSNaN(const fltSemantics &Sem, bool Negative = false,
1194 const APInt *payload = nullptr) {
1195 APFloat Val(Sem, uninitialized);
1196 Val.makeNaN(true, Negative, payload);
1197 return Val;
1198 }
1199
1200 /// Returns the largest finite number in the given semantics.
1201 ///
1202 /// \param Negative - True iff the number should be negative
1203 static APFloat getLargest(const fltSemantics &Sem, bool Negative = false) {
1204 APFloat Val(Sem, uninitialized);
1205 Val.makeLargest(Negative);
1206 return Val;
1207 }
1208
1209 /// Returns the smallest (by magnitude) finite number in the given semantics.
1210 /// Might be denormalized, which implies a relative loss of precision.
1211 ///
1212 /// \param Negative - True iff the number should be negative
1213 static APFloat getSmallest(const fltSemantics &Sem, bool Negative = false) {
1214 APFloat Val(Sem, uninitialized);
1215 Val.makeSmallest(Negative);
1216 return Val;
1217 }
1218
1219 /// Returns the smallest (by magnitude) normalized finite number in the given
1220 /// semantics.
1221 ///
1222 /// \param Negative - True iff the number should be negative
1223 static APFloat getSmallestNormalized(const fltSemantics &Sem,
1224 bool Negative = false) {
1225 APFloat Val(Sem, uninitialized);
1226 Val.makeSmallestNormalized(Negative);
1227 return Val;
1228 }
1229
1230 /// Returns a float which is bitcasted from an all one value int.
1231 ///
1232 /// \param Semantics - type float semantics
1234
1235 /// Returns true if the given semantics has actual significand.
1236 ///
1237 /// \param Sem - type float semantics
1238 static bool hasSignificand(const fltSemantics &Sem) {
1239 return &Sem != &Float8E8M0FNU();
1240 }
1241
1242 /// Used to insert APFloat objects, or objects that contain APFloat objects,
1243 /// into FoldingSets.
1244 LLVM_ABI void Profile(FoldingSetNodeID &NID) const;
1245
1246 opStatus add(const APFloat &RHS, roundingMode RM) {
1247 assert(&getSemantics() == &RHS.getSemantics() &&
1248 "Should only call on two APFloats with the same semantics");
1249 if (usesLayout<IEEEFloat>(getSemantics()))
1250 return U.IEEE.add(RHS.U.IEEE, RM);
1251 if (usesLayout<DoubleAPFloat>(getSemantics()))
1252 return U.Double.add(RHS.U.Double, RM);
1253 llvm_unreachable("Unexpected semantics");
1254 }
1255 opStatus subtract(const APFloat &RHS, roundingMode RM) {
1256 assert(&getSemantics() == &RHS.getSemantics() &&
1257 "Should only call on two APFloats with the same semantics");
1258 if (usesLayout<IEEEFloat>(getSemantics()))
1259 return U.IEEE.subtract(RHS.U.IEEE, RM);
1260 if (usesLayout<DoubleAPFloat>(getSemantics()))
1261 return U.Double.subtract(RHS.U.Double, RM);
1262 llvm_unreachable("Unexpected semantics");
1263 }
1264 opStatus multiply(const APFloat &RHS, roundingMode RM) {
1265 assert(&getSemantics() == &RHS.getSemantics() &&
1266 "Should only call on two APFloats with the same semantics");
1267 if (usesLayout<IEEEFloat>(getSemantics()))
1268 return U.IEEE.multiply(RHS.U.IEEE, RM);
1269 if (usesLayout<DoubleAPFloat>(getSemantics()))
1270 return U.Double.multiply(RHS.U.Double, RM);
1271 llvm_unreachable("Unexpected semantics");
1272 }
1273 opStatus divide(const APFloat &RHS, roundingMode RM) {
1274 assert(&getSemantics() == &RHS.getSemantics() &&
1275 "Should only call on two APFloats with the same semantics");
1276 if (usesLayout<IEEEFloat>(getSemantics()))
1277 return U.IEEE.divide(RHS.U.IEEE, RM);
1278 if (usesLayout<DoubleAPFloat>(getSemantics()))
1279 return U.Double.divide(RHS.U.Double, RM);
1280 llvm_unreachable("Unexpected semantics");
1281 }
1282 opStatus remainder(const APFloat &RHS) {
1283 assert(&getSemantics() == &RHS.getSemantics() &&
1284 "Should only call on two APFloats with the same semantics");
1285 if (usesLayout<IEEEFloat>(getSemantics()))
1286 return U.IEEE.remainder(RHS.U.IEEE);
1287 if (usesLayout<DoubleAPFloat>(getSemantics()))
1288 return U.Double.remainder(RHS.U.Double);
1289 llvm_unreachable("Unexpected semantics");
1290 }
1291 opStatus mod(const APFloat &RHS) {
1292 assert(&getSemantics() == &RHS.getSemantics() &&
1293 "Should only call on two APFloats with the same semantics");
1294 if (usesLayout<IEEEFloat>(getSemantics()))
1295 return U.IEEE.mod(RHS.U.IEEE);
1296 if (usesLayout<DoubleAPFloat>(getSemantics()))
1297 return U.Double.mod(RHS.U.Double);
1298 llvm_unreachable("Unexpected semantics");
1299 }
1300 opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend,
1301 roundingMode RM) {
1302 assert(&getSemantics() == &Multiplicand.getSemantics() &&
1303 "Should only call on APFloats with the same semantics");
1304 assert(&getSemantics() == &Addend.getSemantics() &&
1305 "Should only call on APFloats with the same semantics");
1306 if (usesLayout<IEEEFloat>(getSemantics()))
1307 return U.IEEE.fusedMultiplyAdd(Multiplicand.U.IEEE, Addend.U.IEEE, RM);
1308 if (usesLayout<DoubleAPFloat>(getSemantics()))
1309 return U.Double.fusedMultiplyAdd(Multiplicand.U.Double, Addend.U.Double,
1310 RM);
1311 llvm_unreachable("Unexpected semantics");
1312 }
1316
1317 // TODO: bool parameters are not readable and a source of bugs.
1318 // Do something.
1319 opStatus next(bool nextDown) {
1321 }
1322
1323 /// Negate an APFloat.
1324 APFloat operator-() const {
1325 APFloat Result(*this);
1326 Result.changeSign();
1327 return Result;
1328 }
1329
1330 /// Add two APFloats, rounding ties to the nearest even.
1331 /// No error checking.
1332 APFloat operator+(const APFloat &RHS) const {
1333 APFloat Result(*this);
1334 (void)Result.add(RHS, rmNearestTiesToEven);
1335 return Result;
1336 }
1337
1338 /// Subtract two APFloats, rounding ties to the nearest even.
1339 /// No error checking.
1340 APFloat operator-(const APFloat &RHS) const {
1341 APFloat Result(*this);
1342 (void)Result.subtract(RHS, rmNearestTiesToEven);
1343 return Result;
1344 }
1345
1346 /// Multiply two APFloats, rounding ties to the nearest even.
1347 /// No error checking.
1348 APFloat operator*(const APFloat &RHS) const {
1349 APFloat Result(*this);
1350 (void)Result.multiply(RHS, rmNearestTiesToEven);
1351 return Result;
1352 }
1353
1354 /// Divide the first APFloat by the second, rounding ties to the nearest even.
1355 /// No error checking.
1356 APFloat operator/(const APFloat &RHS) const {
1357 APFloat Result(*this);
1358 (void)Result.divide(RHS, rmNearestTiesToEven);
1359 return Result;
1360 }
1361
1363 void clearSign() {
1364 if (isNegative())
1365 changeSign();
1366 }
1367 void copySign(const APFloat &RHS) {
1368 if (isNegative() != RHS.isNegative())
1369 changeSign();
1370 }
1371
1372 /// A static helper to produce a copy of an APFloat value with its sign
1373 /// copied from some other APFloat.
1374 static APFloat copySign(APFloat Value, const APFloat &Sign) {
1375 Value.copySign(Sign);
1376 return Value;
1377 }
1378
1379 /// Assuming this is an IEEE-754 NaN value, quiet its signaling bit.
1380 /// This preserves the sign and payload bits.
1381 [[nodiscard]] APFloat makeQuiet() const {
1382 APFloat Result(*this);
1383 Result.getIEEE().makeQuiet();
1384 return Result;
1385 }
1386
1387 LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM,
1388 bool *losesInfo);
1389 // Convert a floating point number to an integer according to the
1390 // rounding mode. We provide deterministic values in case of an invalid
1391 // operation exception, namely zero for NaNs and the minimal or maximal value
1392 // respectively for underflow or overflow.
1393 // The *IsExact output tells whether the result is exact, in the sense that
1394 // converting it back to the original floating point type produces the
1395 // original value. This is almost equivalent to result==opOK, except for
1396 // negative zeroes.
1398 unsigned int Width, bool IsSigned, roundingMode RM,
1399 bool *IsExact) const {
1401 convertToInteger(Input, Width, IsSigned, RM, IsExact));
1402 }
1403 // Same as convertToInteger(integerPart*, ...), except the result is returned
1404 // in an APSInt, whose initial bit-width and signed-ness are used to determine
1405 // the precision of the conversion.
1407 bool *IsExact) const;
1408
1409 // Convert a two's complement integer Input to a floating point number,
1410 // rounding according to RM. IsSigned is true if the integer is signed,
1411 // in which case it must be sign-extended.
1412 opStatus convertFromAPInt(const APInt &Input, bool IsSigned,
1413 roundingMode RM) {
1415 }
1416
1417 /// Fill this APFloat with the result of a string conversion.
1418 ///
1419 /// The following strings are accepted for conversion purposes:
1420 /// * Decimal floating-point literals (e.g., `0.1e-5`)
1421 /// * Hexadecimal floating-point literals (e.g., `0x1.0p-5`)
1422 /// * Positive infinity via "inf", "INFINITY", "Inf", "+Inf", or "+inf".
1423 /// * Negative infinity via "-inf", "-INFINITY", or "-Inf".
1424 /// * Quiet NaNs via "nan", "NaN", "nan(...)", or "NaN(...)", where the
1425 /// "..." is either a decimal or hexadecimal integer representing the
1426 /// payload. A negative sign may be optionally provided.
1427 /// * Signaling NaNs via "snan", "sNaN", "snan(...)", or "sNaN(...)", where
1428 /// the "..." is either a decimal or hexadecimal integer representing the
1429 /// payload. A negative sign may be optionally provided.
1430 ///
1431 /// If the input string is none of these forms, then an error is returned.
1432 ///
1433 /// If a floating-point exception occurs during conversion, then no error is
1434 /// returned, and the exception is indicated via opStatus.
1439
1440 /// Converts this APFloat to host double value.
1441 ///
1442 /// \pre The APFloat must be built using semantics, that can be represented by
1443 /// the host double type without loss of precision. It can be IEEEdouble and
1444 /// shorter semantics, like IEEEsingle and others.
1445 LLVM_ABI double convertToDouble() const;
1446
1447 /// Converts this APFloat to host float value.
1448 ///
1449 /// \pre The APFloat must be built using semantics, that can be represented by
1450 /// the host float type without loss of precision. It can be IEEEquad and
1451 /// shorter semantics, like IEEEdouble and others.
1452#ifdef HAS_IEE754_FLOAT128
1453 LLVM_ABI float128 convertToQuad() const;
1454#endif
1455
1456 /// Converts this APFloat to host float value.
1457 ///
1458 /// \pre The APFloat must be built using semantics, that can be represented by
1459 /// the host float type without loss of precision. It can be IEEEsingle and
1460 /// shorter semantics, like IEEEhalf.
1461 LLVM_ABI float convertToFloat() const;
1462
1463 bool operator==(const APFloat &RHS) const { return compare(RHS) == cmpEqual; }
1464
1465 bool operator!=(const APFloat &RHS) const { return compare(RHS) != cmpEqual; }
1466
1467 bool operator<(const APFloat &RHS) const {
1468 return compare(RHS) == cmpLessThan;
1469 }
1470
1471 bool operator>(const APFloat &RHS) const {
1472 return compare(RHS) == cmpGreaterThan;
1473 }
1474
1475 bool operator<=(const APFloat &RHS) const {
1476 cmpResult Res = compare(RHS);
1477 return Res == cmpLessThan || Res == cmpEqual;
1478 }
1479
1480 bool operator>=(const APFloat &RHS) const {
1481 cmpResult Res = compare(RHS);
1482 return Res == cmpGreaterThan || Res == cmpEqual;
1483 }
1484
1485 // IEEE comparison with another floating point number (NaNs compare unordered,
1486 // 0==-0).
1487 cmpResult compare(const APFloat &RHS) const {
1488 assert(&getSemantics() == &RHS.getSemantics() &&
1489 "Should only compare APFloats with the same semantics");
1490 if (usesLayout<IEEEFloat>(getSemantics()))
1491 return U.IEEE.compare(RHS.U.IEEE);
1492 if (usesLayout<DoubleAPFloat>(getSemantics()))
1493 return U.Double.compare(RHS.U.Double);
1494 llvm_unreachable("Unexpected semantics");
1495 }
1496
1497 // Compares the absolute value of this APFloat with another. Both operands
1498 // must be finite non-zero.
1499 cmpResult compareAbsoluteValue(const APFloat &RHS) const {
1500 assert(&getSemantics() == &RHS.getSemantics() &&
1501 "Should only compare APFloats with the same semantics");
1502 if (usesLayout<IEEEFloat>(getSemantics()))
1503 return U.IEEE.compareAbsoluteValue(RHS.U.IEEE);
1504 if (usesLayout<DoubleAPFloat>(getSemantics()))
1505 return U.Double.compareAbsoluteValue(RHS.U.Double);
1506 llvm_unreachable("Unexpected semantics");
1507 }
1508
1509 bool bitwiseIsEqual(const APFloat &RHS) const {
1510 if (&getSemantics() != &RHS.getSemantics())
1511 return false;
1512 if (usesLayout<IEEEFloat>(getSemantics()))
1513 return U.IEEE.bitwiseIsEqual(RHS.U.IEEE);
1514 if (usesLayout<DoubleAPFloat>(getSemantics()))
1515 return U.Double.bitwiseIsEqual(RHS.U.Double);
1516 llvm_unreachable("Unexpected semantics");
1517 }
1518
1519 /// We don't rely on operator== working on double values, as
1520 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1521 /// As such, this method can be used to do an exact bit-for-bit comparison of
1522 /// two floating point values.
1523 ///
1524 /// We leave the version with the double argument here because it's just so
1525 /// convenient to write "2.0" and the like. Without this function we'd
1526 /// have to duplicate its logic everywhere it's called.
1527 bool isExactlyValue(double V) const {
1528 bool ignored;
1529 APFloat Tmp(V);
1531 return bitwiseIsEqual(Tmp);
1532 }
1533
1534 unsigned int convertToHexString(char *DST, unsigned int HexDigits,
1535 bool UpperCase, roundingMode RM) const {
1537 convertToHexString(DST, HexDigits, UpperCase, RM));
1538 }
1539
1540 bool isZero() const { return getCategory() == fcZero; }
1541 bool isInfinity() const { return getCategory() == fcInfinity; }
1542 bool isNaN() const { return getCategory() == fcNaN; }
1543
1544 bool isNegative() const { return getIEEE().isNegative(); }
1546 bool isSignaling() const { return getIEEE().isSignaling(); }
1547
1548 bool isNormal() const { return !isDenormal() && isFiniteNonZero(); }
1549 bool isFinite() const { return !isNaN() && !isInfinity(); }
1550
1551 fltCategory getCategory() const { return getIEEE().getCategory(); }
1552 const fltSemantics &getSemantics() const { return *U.semantics; }
1553 bool isNonZero() const { return !isZero(); }
1554 bool isFiniteNonZero() const { return isFinite() && !isZero(); }
1555 bool isPosZero() const { return isZero() && !isNegative(); }
1556 bool isNegZero() const { return isZero() && isNegative(); }
1557 bool isPosInfinity() const { return isInfinity() && !isNegative(); }
1558 bool isNegInfinity() const { return isInfinity() && isNegative(); }
1562
1566
1567 /// If the value is a NaN value, return an integer containing the payload of
1568 /// this value. This payload will include the quiet bit as part of the
1569 /// returned integer.
1571 assert(isNaN() && "Can only call this on a NaN value");
1573 }
1574
1575 /// Return the FPClassTest which will return true for the value.
1577
1578 APFloat &operator=(const APFloat &RHS) = default;
1579 APFloat &operator=(APFloat &&RHS) = default;
1580
1581 void toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision = 0,
1582 unsigned FormatMaxPadding = 3, bool TruncateZero = true) const {
1584 toString(Str, FormatPrecision, FormatMaxPadding, TruncateZero));
1585 }
1586
1587 LLVM_ABI void print(raw_ostream &) const;
1588
1589#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1590 LLVM_DUMP_METHOD void dump() const;
1591#endif
1592
1593 /// If this value is normal and has an exact, normal, multiplicative inverse,
1594 /// store it in inv and return true.
1595 LLVM_ABI bool getExactInverse(APFloat *Inv) const;
1596
1597 // If this is an exact power of two, return the exponent while ignoring the
1598 // sign bit. If it's not an exact power of 2, return INT_MIN
1603
1604 // If this is an exact power of two, return the exponent. If it's not an exact
1605 // power of 2, return INT_MIN
1607 int getExactLog2() const {
1608 return isNegative() ? INT_MIN : getExactLog2Abs();
1609 }
1610
1611 LLVM_ABI friend hash_code hash_value(const APFloat &Arg);
1612 friend int ilogb(const APFloat &Arg);
1613 friend APFloat scalbn(APFloat X, int Exp, roundingMode RM);
1614 friend APFloat frexp(const APFloat &X, int &Exp, roundingMode RM);
1615 friend IEEEFloat;
1616 friend DoubleAPFloat;
1617};
1618
1619static_assert(sizeof(APFloat) == sizeof(detail::IEEEFloat),
1620 "Empty base class optimization is not performed.");
1621
1622/// See friend declarations above.
1623///
1624/// These additional declarations are required in order to compile LLVM with IBM
1625/// xlC compiler.
1627
1628/// Returns the exponent of the internal representation of the APFloat.
1629///
1630/// Because the radix of APFloat is 2, this is equivalent to floor(log2(x)).
1631/// For special APFloat values, this returns special error codes:
1632///
1633/// NaN -> \c IEK_NaN
1634/// 0 -> \c IEK_Zero
1635/// Inf -> \c IEK_Inf
1636///
1637inline int ilogb(const APFloat &Arg) {
1638 if (APFloat::usesLayout<detail::IEEEFloat>(Arg.getSemantics()))
1639 return ilogb(Arg.U.IEEE);
1640 if (APFloat::usesLayout<detail::DoubleAPFloat>(Arg.getSemantics()))
1641 return ilogb(Arg.U.Double);
1642 llvm_unreachable("Unexpected semantics");
1643}
1644
1645/// Returns: X * 2^Exp for integral exponents.
1647 if (APFloat::usesLayout<detail::IEEEFloat>(X.getSemantics()))
1648 return APFloat(scalbn(X.U.IEEE, Exp, RM), X.getSemantics());
1649 if (APFloat::usesLayout<detail::DoubleAPFloat>(X.getSemantics()))
1650 return APFloat(scalbn(X.U.Double, Exp, RM), X.getSemantics());
1651 llvm_unreachable("Unexpected semantics");
1652}
1653
1654/// Equivalent of C standard library function.
1655///
1656/// While the C standard says Exp is an unspecified value for infinity and nan,
1657/// this returns INT_MAX for infinities, and INT_MIN for NaNs.
1658inline APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM) {
1659 if (APFloat::usesLayout<detail::IEEEFloat>(X.getSemantics()))
1660 return APFloat(frexp(X.U.IEEE, Exp, RM), X.getSemantics());
1661 if (APFloat::usesLayout<detail::DoubleAPFloat>(X.getSemantics()))
1662 return APFloat(frexp(X.U.Double, Exp, RM), X.getSemantics());
1663 llvm_unreachable("Unexpected semantics");
1664}
1665/// Returns the absolute value of the argument.
1667 X.clearSign();
1668 return X;
1669}
1670
1671/// Returns the negated value of the argument.
1673 X.changeSign();
1674 return X;
1675}
1676
1677/// Implements IEEE-754 2008 minNum semantics. Returns the smaller of the
1678/// 2 arguments if both are not NaN. If either argument is a qNaN, returns the
1679/// other argument. If either argument is sNaN, return a qNaN.
1680/// -0 is treated as ordered less than +0.
1682inline APFloat minnum(const APFloat &A, const APFloat &B) {
1683 if (A.isSignaling())
1684 return A.makeQuiet();
1685 if (B.isSignaling())
1686 return B.makeQuiet();
1687 if (A.isNaN())
1688 return B;
1689 if (B.isNaN())
1690 return A;
1691 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1692 return A.isNegative() ? A : B;
1693 return B < A ? B : A;
1694}
1695
1696/// Implements IEEE-754 2008 maxNum semantics. Returns the larger of the
1697/// 2 arguments if both are not NaN. If either argument is a qNaN, returns the
1698/// other argument. If either argument is sNaN, return a qNaN.
1699/// +0 is treated as ordered greater than -0.
1701inline APFloat maxnum(const APFloat &A, const APFloat &B) {
1702 if (A.isSignaling())
1703 return A.makeQuiet();
1704 if (B.isSignaling())
1705 return B.makeQuiet();
1706 if (A.isNaN())
1707 return B;
1708 if (B.isNaN())
1709 return A;
1710 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1711 return A.isNegative() ? B : A;
1712 return A < B ? B : A;
1713}
1714
1715/// Implements IEEE 754-2019 minimum semantics. Returns the smaller of 2
1716/// arguments, returning a quiet NaN if an argument is a NaN and treating -0
1717/// as less than +0.
1719inline APFloat minimum(const APFloat &A, const APFloat &B) {
1720 if (A.isNaN())
1721 return A.makeQuiet();
1722 if (B.isNaN())
1723 return B.makeQuiet();
1724 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1725 return A.isNegative() ? A : B;
1726 return B < A ? B : A;
1727}
1728
1729/// Implements IEEE 754-2019 minimumNumber semantics. Returns the smaller
1730/// of 2 arguments, not propagating NaNs and treating -0 as less than +0.
1732inline APFloat minimumnum(const APFloat &A, const APFloat &B) {
1733 if (A.isNaN())
1734 return B.isNaN() ? B.makeQuiet() : B;
1735 if (B.isNaN())
1736 return A;
1737 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1738 return A.isNegative() ? A : B;
1739 return B < A ? B : A;
1740}
1741
1742/// Implements IEEE 754-2019 maximum semantics. Returns the larger of 2
1743/// arguments, returning a quiet NaN if an argument is a NaN and treating -0
1744/// as less than +0.
1746inline APFloat maximum(const APFloat &A, const APFloat &B) {
1747 if (A.isNaN())
1748 return A.makeQuiet();
1749 if (B.isNaN())
1750 return B.makeQuiet();
1751 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1752 return A.isNegative() ? B : A;
1753 return A < B ? B : A;
1754}
1755
1756/// Implements IEEE 754-2019 maximumNumber semantics. Returns the larger
1757/// of 2 arguments, not propagating NaNs and treating -0 as less than +0.
1759inline APFloat maximumnum(const APFloat &A, const APFloat &B) {
1760 if (A.isNaN())
1761 return B.isNaN() ? B.makeQuiet() : B;
1762 if (B.isNaN())
1763 return A;
1764 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1765 return A.isNegative() ? B : A;
1766 return A < B ? B : A;
1767}
1768
1769/// Implement IEEE 754-2019 exp functions
1771LLVM_ABI std::optional<APFloat>
1772exp(const APFloat &X, RoundingMode RM = APFloat::rmNearestTiesToEven,
1773 APFloat::opStatus *Status = nullptr);
1774
1776 V.print(OS);
1777 return OS;
1778}
1779
1780// We want the following functions to be available in the header for inlining.
1781// We cannot define them inline in the class definition of `DoubleAPFloat`
1782// because doing so would instantiate `std::unique_ptr<APFloat[]>` before
1783// `APFloat` is defined, and that would be undefined behavior.
1784namespace detail {
1785
1787 if (this != &RHS) {
1788 this->~DoubleAPFloat();
1789 new (this) DoubleAPFloat(std::move(RHS));
1790 }
1791 return *this;
1792}
1793
1794APFloat &DoubleAPFloat::getFirst() { return Floats[0]; }
1795const APFloat &DoubleAPFloat::getFirst() const { return Floats[0]; }
1796APFloat &DoubleAPFloat::getSecond() { return Floats[1]; }
1797const APFloat &DoubleAPFloat::getSecond() const { return Floats[1]; }
1798
1799inline DoubleAPFloat::~DoubleAPFloat() { delete[] Floats; }
1800
1801} // namespace detail
1802
1803} // namespace llvm
1804
1805#undef APFLOAT_DISPATCH_ON_SEMANTICS
1806#endif // LLVM_ADT_APFLOAT_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#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:853
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:213
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:661
#define LLVM_READONLY
Definition Compiler.h:322
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:297
static const fltSemantics & Float8E4M3FN()
Definition APFloat.h:307
static LLVM_ABI const llvm::fltSemantics & EnumToSemantics(Semantics S)
Definition APFloat.cpp:113
static LLVM_ABI bool semanticsHasInf(const fltSemantics &)
Definition APFloat.cpp:262
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
Definition APFloat.h:335
static constexpr roundingMode rmTowardZero
Definition APFloat.h:349
static LLVM_ABI ExponentType semanticsMinExponent(const fltSemantics &)
Definition APFloat.cpp:237
llvm::RoundingMode roundingMode
IEEE-754R 4.3: Rounding-direction attributes.
Definition APFloat.h:343
static const fltSemantics & BFloat()
Definition APFloat.h:296
static const fltSemantics & IEEEquad()
Definition APFloat.h:299
static LLVM_ABI unsigned int semanticsSizeInBits(const fltSemantics &)
Definition APFloat.cpp:240
static const fltSemantics & Float8E8M0FNU()
Definition APFloat.h:314
static LLVM_ABI bool semanticsHasSignedRepr(const fltSemantics &)
Definition APFloat.cpp:258
static const fltSemantics & IEEEdouble()
Definition APFloat.h:298
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:293
static const fltSemantics & x87DoubleExtended()
Definition APFloat.h:318
static constexpr roundingMode rmTowardNegative
Definition APFloat.h:348
uninitializedTag
Convenience enum used to construct an uninitialized APFloat.
Definition APFloat.h:379
static constexpr roundingMode rmNearestTiesToEven
Definition APFloat.h:345
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:6001
static LLVM_ABI bool hasSignBitInMSB(const fltSemantics &)
Definition APFloat.cpp:275
static LLVM_ABI ExponentType semanticsMaxExponent(const fltSemantics &)
Definition APFloat.cpp:233
friend class APFloat
Definition APFloat.h:292
static const fltSemantics & Bogus()
A Pseudo fltsemantic used to construct APFloats that cannot conflict with anything real.
Definition APFloat.h:324
static LLVM_ABI unsigned int semanticsPrecision(const fltSemantics &)
Definition APFloat.cpp:229
static LLVM_ABI bool semanticsHasNaN(const fltSemantics &)
Definition APFloat.cpp:266
static LLVM_ABI Semantics SemanticsToEnum(const llvm::fltSemantics &Sem)
Definition APFloat.cpp:160
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:301
APInt::WordType integerPart
Definition APFloat.h:152
static LLVM_ABI bool semanticsHasZero(const fltSemantics &)
Definition APFloat.cpp:254
static LLVM_ABI bool isRepresentableAsNormalIn(const fltSemantics &Src, const fltSemantics &Dst)
Definition APFloat.cpp:279
static const fltSemantics & Float8E5M2FNUZ()
Definition APFloat.h:305
static const fltSemantics & Float8E4M3FNUZ()
Definition APFloat.h:308
static constexpr roundingMode rmTowardPositive
Definition APFloat.h:347
static const fltSemantics & IEEEhalf()
Definition APFloat.h:295
static const fltSemantics & Float4E2M1FN()
Definition APFloat.h:317
static const fltSemantics & Float6E2M3FN()
Definition APFloat.h:316
IlogbErrorKinds
Enumeration of ilogb error results.
Definition APFloat.h:384
static const fltSemantics & Float8E4M3()
Definition APFloat.h:306
static const fltSemantics & Float8E4M3B11FNUZ()
Definition APFloat.h:309
static LLVM_ABI bool isRepresentableBy(const fltSemantics &A, const fltSemantics &B)
Definition APFloat.cpp:205
static const fltSemantics & Float8E3M4()
Definition APFloat.h:312
static LLVM_ABI bool isIEEELikeFP(const fltSemantics &)
Definition APFloat.cpp:270
static const fltSemantics & Float8E5M2()
Definition APFloat.h:304
fltCategory
Category of internally-represented number.
Definition APFloat.h:371
static constexpr roundingMode rmNearestTiesToAway
Definition APFloat.h:350
static const fltSemantics & PPCDoubleDouble()
Definition APFloat.h:300
static const fltSemantics & Float6E3M2FN()
Definition APFloat.h:315
opStatus
IEEE-754R 7: Default exception handling.
Definition APFloat.h:361
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:6009
static const fltSemantics & FloatTF32()
Definition APFloat.h:313
static LLVM_ABI unsigned int semanticsIntSizeInBits(const fltSemantics &, bool)
Definition APFloat.cpp:243
static APFloat getQNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for QNaN values.
Definition APFloat.h:1185
static APFloat getSNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for SNaN values.
Definition APFloat.h:1193
opStatus divide(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1273
APFloat & operator=(APFloat &&RHS)=default
bool isFiniteNonZero() const
Definition APFloat.h:1554
APFloat(const APFloat &RHS)=default
void copySign(const APFloat &RHS)
Definition APFloat.h:1367
LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Definition APFloat.cpp:5901
LLVM_READONLY int getExactLog2Abs() const
Definition APFloat.h:1600
opStatus subtract(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1255
bool bitwiseIsEqual(const APFloat &RHS) const
Definition APFloat.h:1509
bool isNegative() const
Definition APFloat.h:1544
~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:5843
cmpResult compareAbsoluteValue(const APFloat &RHS) const
Definition APFloat.h:1499
APFloat operator+(const APFloat &RHS) const
Add two APFloats, rounding ties to the nearest even.
Definition APFloat.h:1332
friend DoubleAPFloat
Definition APFloat.h:1616
LLVM_ABI double convertToDouble() const
Converts this APFloat to host double value.
Definition APFloat.cpp:5960
bool isPosInfinity() const
Definition APFloat.h:1557
APFloat(APFloat &&RHS)=default
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
Definition APFloat.h:1581
bool isNormal() const
Definition APFloat.h:1548
bool isDenormal() const
Definition APFloat.h:1545
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:1527
opStatus add(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1246
LLVM_READONLY int getExactLog2() const
Definition APFloat.h:1607
APFloat(double d)
Definition APFloat.h:1132
APFloat & operator=(const APFloat &RHS)=default
static LLVM_ABI APFloat getAllOnesValue(const fltSemantics &Semantics)
Returns a float which is bitcasted from an all one value int.
Definition APFloat.cpp:5927
LLVM_ABI friend hash_code hash_value(const APFloat &Arg)
See friend declarations above.
Definition APFloat.cpp:5815
APFloat(const fltSemantics &Semantics, integerPart I)
Definition APFloat.h:1124
bool operator!=(const APFloat &RHS) const
Definition APFloat.h:1465
APFloat(const fltSemantics &Semantics, T V)=delete
const fltSemantics & getSemantics() const
Definition APFloat.h:1552
APFloat operator-(const APFloat &RHS) const
Subtract two APFloats, rounding ties to the nearest even.
Definition APFloat.h:1340
APFloat operator*(const APFloat &RHS) const
Multiply two APFloats, rounding ties to the nearest even.
Definition APFloat.h:1348
APFloat(const fltSemantics &Semantics)
Definition APFloat.h:1122
bool isNonZero() const
Definition APFloat.h:1553
void clearSign()
Definition APFloat.h:1363
bool operator<(const APFloat &RHS) const
Definition APFloat.h:1467
bool isFinite() const
Definition APFloat.h:1549
APFloat makeQuiet() const
Assuming this is an IEEE-754 NaN value, quiet its signaling bit.
Definition APFloat.h:1381
bool isNaN() const
Definition APFloat.h:1542
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
Definition APFloat.h:1412
static APFloat getOne(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative One.
Definition APFloat.h:1153
unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
Definition APFloat.h:1534
opStatus multiply(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1264
LLVM_ABI float convertToFloat() const
Converts this APFloat to host float value.
Definition APFloat.cpp:5988
bool isSignaling() const
Definition APFloat.h:1546
bool operator>(const APFloat &RHS) const
Definition APFloat.h:1471
opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend, roundingMode RM)
Definition APFloat.h:1300
APFloat operator/(const APFloat &RHS) const
Divide the first APFloat by the second, rounding ties to the nearest even.
Definition APFloat.h:1356
opStatus remainder(const APFloat &RHS)
Definition APFloat.h:1282
APFloat operator-() const
Negate an APFloat.
Definition APFloat.h:1324
bool isZero() const
Definition APFloat.h:1540
static APFloat getSmallestNormalized(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
Definition APFloat.h:1223
APInt bitcastToAPInt() const
Definition APFloat.h:1436
bool isLargest() const
Definition APFloat.h:1560
friend APFloat frexp(const APFloat &X, int &Exp, roundingMode RM)
bool isSmallest() const
Definition APFloat.h:1559
static APFloat getLargest(const fltSemantics &Sem, bool Negative=false)
Returns the largest finite number in the given semantics.
Definition APFloat.h:1203
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
Definition APFloat.h:1397
opStatus next(bool nextDown)
Definition APFloat.h:1319
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
Definition APFloat.h:1163
friend APFloat scalbn(APFloat X, int Exp, roundingMode RM)
bool operator>=(const APFloat &RHS) const
Definition APFloat.h:1480
bool needsCleanup() const
Definition APFloat.h:1139
static APFloat getSmallest(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) finite number in the given semantics.
Definition APFloat.h:1213
LLVM_ABI FPClassTest classify() const
Return the FPClassTest which will return true for the value.
Definition APFloat.cpp:5830
bool operator==(const APFloat &RHS) const
Definition APFloat.h:1463
opStatus mod(const APFloat &RHS)
Definition APFloat.h:1291
bool isPosZero() const
Definition APFloat.h:1555
APInt getNaNPayload() const
If the value is a NaN value, return an integer containing the payload of this value.
Definition APFloat.h:1570
friend int ilogb(const APFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
Definition APFloat.h:1637
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
Fill this APFloat with the result of a string conversion.
Definition APFloat.cpp:5810
fltCategory getCategory() const
Definition APFloat.h:1551
APFloat(const fltSemantics &Semantics, uninitializedTag)
Definition APFloat.h:1129
bool isInteger() const
Definition APFloat.h:1561
bool isNegInfinity() const
Definition APFloat.h:1558
friend IEEEFloat
Definition APFloat.h:1615
LLVM_DUMP_METHOD void dump() const
Definition APFloat.cpp:5938
bool isNegZero() const
Definition APFloat.h:1556
LLVM_ABI void print(raw_ostream &) const
Definition APFloat.cpp:5931
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:1374
APFloat(float f)
Definition APFloat.h:1133
opStatus roundToIntegral(roundingMode RM)
Definition APFloat.h:1313
void changeSign()
Definition APFloat.h:1362
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
Definition APFloat.h:1174
static bool hasSignificand(const fltSemantics &Sem)
Returns true if the given semantics has actual significand.
Definition APFloat.h:1238
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Definition APFloat.h:1144
cmpResult compare(const APFloat &RHS) const
Definition APFloat.h:1487
bool isSmallestNormalized() const
Definition APFloat.h:1563
APFloat(const fltSemantics &Semantics, const APInt &I)
Definition APFloat.h:1131
bool isInfinity() const
Definition APFloat.h:1541
bool operator<=(const APFloat &RHS) const
Definition APFloat.h:1475
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:208
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:5157
LLVM_ABI DoubleAPFloat & operator=(const DoubleAPFloat &RHS)
Definition APFloat.cpp:4687
LLVM_ABI void changeSign()
Definition APFloat.cpp:5064
LLVM_ABI bool isLargest() const
Definition APFloat.cpp:5631
LLVM_ABI opStatus remainder(const DoubleAPFloat &RHS)
Definition APFloat.cpp:4951
LLVM_ABI opStatus multiply(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:4854
LLVM_ABI fltCategory getCategory() const
Definition APFloat.cpp:5123
LLVM_ABI bool bitwiseIsEqual(const DoubleAPFloat &RHS) const
Definition APFloat.cpp:5180
LLVM_ABI LLVM_READONLY int getExactLog2Abs() const
Definition APFloat.cpp:5655
LLVM_ABI opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
Definition APFloat.cpp:5582
LLVM_ABI APInt bitcastToAPInt() const
Definition APFloat.cpp:5191
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
Definition APFloat.cpp:5201
LLVM_ABI bool isSmallest() const
Definition APFloat.cpp:5614
LLVM_ABI opStatus subtract(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:4846
LLVM_ABI friend hash_code hash_value(const DoubleAPFloat &Arg)
Definition APFloat.cpp:5185
LLVM_ABI cmpResult compareAbsoluteValue(const DoubleAPFloat &RHS) const
Definition APFloat.cpp:5070
LLVM_ABI bool isDenormal() const
Definition APFloat.cpp:5607
LLVM_ABI opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
Definition APFloat.cpp:5418
LLVM_ABI void makeSmallest(bool Neg)
Definition APFloat.cpp:5150
LLVM_ABI friend int ilogb(const DoubleAPFloat &X)
Definition APFloat.cpp:5664
LLVM_ABI opStatus next(bool nextDown)
Definition APFloat.cpp:5217
LLVM_ABI void makeInf(bool Neg)
Definition APFloat.cpp:5129
LLVM_ABI bool isInteger() const
Definition APFloat.cpp:5639
LLVM_ABI void makeZero(bool Neg)
Definition APFloat.cpp:5134
LLVM_ABI opStatus divide(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:4940
LLVM_ABI bool isSmallestNormalized() const
Definition APFloat.cpp:5622
LLVM_ABI opStatus mod(const DoubleAPFloat &RHS)
Definition APFloat.cpp:4961
LLVM_ABI DoubleAPFloat(const fltSemantics &S)
Definition APFloat.cpp:4634
LLVM_ABI void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision, unsigned FormatMaxPadding, bool TruncateZero=true) const
Definition APFloat.cpp:5645
LLVM_ABI void makeLargest(bool Neg)
Definition APFloat.cpp:5139
LLVM_ABI cmpResult compare(const DoubleAPFloat &RHS) const
Definition APFloat.cpp:5172
LLVM_ABI friend DoubleAPFloat scalbn(const DoubleAPFloat &X, int Exp, roundingMode)
LLVM_ABI opStatus roundToIntegral(roundingMode RM)
Definition APFloat.cpp:4987
LLVM_ABI opStatus fusedMultiplyAdd(const DoubleAPFloat &Multiplicand, const DoubleAPFloat &Addend, roundingMode RM)
Definition APFloat.cpp:4972
LLVM_ABI APInt getNaNPayload() const
Definition APFloat.cpp:5793
LLVM_ABI unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
Definition APFloat.cpp:5597
bool needsCleanup() const
Definition APFloat.h:878
LLVM_ABI bool isNegative() const
Definition APFloat.cpp:5127
LLVM_ABI opStatus add(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:4841
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:5167
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:3191
LLVM_ABI cmpResult compareAbsoluteValue(const IEEEFloat &) const
Definition APFloat.cpp:1440
LLVM_ABI opStatus mod(const IEEEFloat &)
C fmod, or llvm frem.
Definition APFloat.cpp:2196
fltCategory getCategory() const
Definition APFloat.h:583
LLVM_ABI opStatus convertFromAPInt(const APInt &, bool, roundingMode)
Definition APFloat.cpp:2751
LLVM_ABI APInt getNaNPayload() const
Definition APFloat.cpp:4522
bool isNonZero() const
Definition APFloat.h:585
bool isFiniteNonZero() const
Definition APFloat.h:586
bool needsCleanup() const
Returns whether this instance allocated memory.
Definition APFloat.h:473
LLVM_ABI void makeLargest(bool Neg=false)
Make this number the largest magnitude normal number in the given semantics.
Definition APFloat.cpp:3949
LLVM_ABI LLVM_READONLY int getExactLog2Abs() const
Definition APFloat.cpp:4344
LLVM_ABI APInt bitcastToAPInt() const
Definition APFloat.cpp:3587
LLVM_ABI friend IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
Definition APFloat.cpp:4594
LLVM_ABI cmpResult compare(const IEEEFloat &) const
IEEE comparison with another floating point number (NaNs compare unordered, 0==-0).
Definition APFloat.cpp:2364
bool isNegative() const
IEEE-754R isSignMinus: Returns true if and only if the current value is negative.
Definition APFloat.h:548
LLVM_ABI opStatus divide(const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2070
LLVM_ABI friend hash_code hash_value(const IEEEFloat &Arg)
Overload to compute a hash code for an APFloat value.
Definition APFloat.cpp:3331
bool isNaN() const
Returns true if and only if the float is a quiet or signaling NaN.
Definition APFloat.h:573
LLVM_ABI opStatus remainder(const IEEEFloat &)
IEEE remainder.
Definition APFloat.cpp:2088
LLVM_ABI double convertToDouble() const
Definition APFloat.cpp:3657
LLVM_ABI float convertToFloat() const
Definition APFloat.cpp:3650
LLVM_ABI opStatus subtract(const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2046
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:4300
LLVM_ABI void makeSmallest(bool Neg=false)
Make this number the smallest magnitude denormal number in the given semantics.
Definition APFloat.cpp:3981
LLVM_ABI void makeInf(bool Neg=false)
Definition APFloat.cpp:4541
bool isNormal() const
IEEE-754R isNormal: Returns true if and only if the current value is normal.
Definition APFloat.h:554
LLVM_ABI bool isSmallestNormalized() const
Returns true if this is the smallest (by magnitude) normalized finite number in the given semantics.
Definition APFloat.cpp:961
friend class IEEEFloatUnitTestHelper
Definition APFloat.h:828
LLVM_ABI void makeQuiet()
Definition APFloat.cpp:4570
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:1063
LLVM_ABI opStatus add(const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2040
bool isFinite() const
Returns true if and only if the current value is zero, subnormal, or normal.
Definition APFloat.h:560
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
Definition APFloat.cpp:3134
LLVM_ABI void makeNaN(bool SNaN=false, bool Neg=false, const APInt *fill=nullptr)
Definition APFloat.cpp:849
LLVM_ABI opStatus multiply(const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2052
LLVM_ABI opStatus roundToIntegral(roundingMode)
Definition APFloat.cpp:2279
LLVM_ABI IEEEFloat & operator=(const IEEEFloat &)
Definition APFloat.cpp:921
LLVM_ABI bool bitwiseIsEqual(const IEEEFloat &) const
Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
Definition APFloat.cpp:1088
LLVM_ABI void makeSmallestNormalized(bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
Definition APFloat.cpp:3995
LLVM_ABI bool isInteger() const
Returns true if and only if the number is an exact integer.
Definition APFloat.cpp:1080
bool isPosZero() const
Definition APFloat.h:587
LLVM_ABI IEEEFloat(const fltSemantics &)
Definition APFloat.cpp:1115
LLVM_ABI opStatus fusedMultiplyAdd(const IEEEFloat &, const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2233
LLVM_ABI friend int ilogb(const IEEEFloat &Arg)
Definition APFloat.cpp:4576
LLVM_ABI opStatus next(bool nextDown)
IEEE-754R 5.3.1: nextUp/nextDown.
Definition APFloat.cpp:4389
bool isInfinity() const
IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
Definition APFloat.h:570
const fltSemantics & getSemantics() const
Definition APFloat.h:584
bool isZero() const
Returns true if and only if the float is plus or minus zero.
Definition APFloat.h:563
LLVM_ABI bool isSignaling() const
Returns true if and only if the float is a signaling NaN.
Definition APFloat.cpp:4373
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:4556
LLVM_ABI opStatus convert(const fltSemantics &, roundingMode, bool *)
IEEEFloat::convert - convert a value of one floating point type to another.
Definition APFloat.cpp:2440
LLVM_ABI void changeSign()
Definition APFloat.cpp:1998
LLVM_ABI bool isDenormal() const
IEEE-754R isSubnormal(): Returns true if and only if the float is a denormal.
Definition APFloat.cpp:946
LLVM_ABI opStatus convertToInteger(MutableArrayRef< integerPart >, unsigned int, bool, roundingMode, bool *) const
Definition APFloat.cpp:2696
LLVM_ABI friend IEEEFloat frexp(const IEEEFloat &X, int &Exp, roundingMode)
Definition APFloat.cpp:4615
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:953
bool isNegZero() const
Definition APFloat.h:588
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:449
static constexpr fltCategory fcNaN
Definition APFloat.h:451
static constexpr opStatus opDivByZero
Definition APFloat.h:446
static constexpr opStatus opOverflow
Definition APFloat.h:447
static constexpr cmpResult cmpLessThan
Definition APFloat.h:441
static constexpr roundingMode rmTowardPositive
Definition APFloat.h:437
static constexpr uninitializedTag uninitialized
Definition APFloat.h:431
static constexpr fltCategory fcZero
Definition APFloat.h:453
static constexpr opStatus opOK
Definition APFloat.h:444
static constexpr cmpResult cmpGreaterThan
Definition APFloat.h:442
static constexpr unsigned integerPartWidth
Definition APFloat.h:439
LLVM_ABI hash_code hash_value(const IEEEFloat &Arg)
Definition APFloat.cpp:3331
APFloatBase::ExponentType ExponentType
Definition APFloat.h:430
APFloatBase::fltCategory fltCategory
Definition APFloat.h:429
static constexpr fltCategory fcNormal
Definition APFloat.h:452
static constexpr opStatus opInvalidOp
Definition APFloat.h:445
APFloatBase::opStatus opStatus
Definition APFloat.h:427
LLVM_ABI IEEEFloat frexp(const IEEEFloat &Val, int &Exp, roundingMode RM)
Definition APFloat.cpp:4615
APFloatBase::uninitializedTag uninitializedTag
Definition APFloat.h:425
static constexpr cmpResult cmpUnordered
Definition APFloat.h:443
static constexpr roundingMode rmTowardNegative
Definition APFloat.h:436
APFloatBase::roundingMode roundingMode
Definition APFloat.h:426
APFloatBase::cmpResult cmpResult
Definition APFloat.h:428
static constexpr fltCategory fcInfinity
Definition APFloat.h:450
static constexpr roundingMode rmNearestTiesToAway
Definition APFloat.h:434
static constexpr roundingMode rmTowardZero
Definition APFloat.h:438
static constexpr opStatus opUnderflow
Definition APFloat.h:448
static constexpr roundingMode rmNearestTiesToEven
Definition APFloat.h:432
LLVM_ABI int ilogb(const IEEEFloat &Arg)
Definition APFloat.cpp:4576
static constexpr cmpResult cmpEqual
Definition APFloat.h:440
LLVM_ABI IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
Definition APFloat.cpp:4594
APFloatBase::integerPart integerPart
Definition APFloat.h:424
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:1758
hash_code hash_value(const FixedPointSemantics &Val)
static constexpr APFloatBase::ExponentType exponentZero(const fltSemantics &semantics)
Definition APFloat.cpp:298
APFloat abs(APFloat X)
Returns the absolute value of the argument.
Definition APFloat.h:1666
LLVM_READONLY APFloat maximum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 maximum semantics.
Definition APFloat.h:1746
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:1637
APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM)
Equivalent of C standard library function.
Definition APFloat.h:1658
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE-754 2008 maxNum semantics.
Definition APFloat.h:1701
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:6106
LLVM_READONLY APFloat minimumnum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 minimumNumber semantics.
Definition APFloat.h:1732
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:1646
static constexpr APFloatBase::ExponentType exponentNaN(const fltSemantics &semantics)
Definition APFloat.cpp:308
@ 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:1682
fltNonfiniteBehavior
Definition APFloat.h:953
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:303
APFloat neg(APFloat X)
Returns the negated value of the argument.
Definition APFloat.h:1672
LLVM_READONLY APFloat minimum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 minimum semantics.
Definition APFloat.h:1719
LLVM_READONLY APFloat maximumnum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 maximumNumber semantics.
Definition APFloat.h:1759
fltNanEncoding
Definition APFloat.h:977
APFloatBase::ExponentType maxExponent
Definition APFloat.h:1001
fltNonfiniteBehavior nonFiniteBehavior
Definition APFloat.h:1014
APFloatBase::ExponentType minExponent
Definition APFloat.h:1005
unsigned int sizeInBits
Definition APFloat.h:1012
unsigned int precision
Definition APFloat.h:1009
fltNanEncoding nanEncoding
Definition APFloat.h:1016