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
26#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL) \
27 do { \
28 if (usesLayout<IEEEFloat>(getSemantics())) \
29 return U.IEEE.METHOD_CALL; \
30 if (usesLayout<DoubleAPFloat>(getSemantics())) \
31 return U.Double.METHOD_CALL; \
32 llvm_unreachable("Unexpected semantics"); \
33 } while (false)
34
35namespace llvm {
36
37struct fltSemantics;
38class APSInt;
39class StringRef;
40class APFloat;
41class raw_ostream;
42
43template <typename T> class Expected;
44template <typename T> class SmallVectorImpl;
45
46/// Enum that represents what fraction of the LSB truncated bits of an fp number
47/// represent.
48///
49/// This essentially combines the roles of guard and sticky bits.
50enum lostFraction { // Example of truncated bits:
51 lfExactlyZero, // 000000
52 lfLessThanHalf, // 0xxxxx x's not all zero
53 lfExactlyHalf, // 100000
54 lfMoreThanHalf // 1xxxxx x's not all zero
55};
56
57/// A self-contained host- and target-independent arbitrary-precision
58/// floating-point software implementation.
59///
60/// APFloat uses bignum integer arithmetic as provided by static functions in
61/// the APInt class. The library will work with bignum integers whose parts are
62/// any unsigned type at least 16 bits wide, but 64 bits is recommended.
63///
64/// Written for clarity rather than speed, in particular with a view to use in
65/// the front-end of a cross compiler so that target arithmetic can be correctly
66/// performed on the host. Performance should nonetheless be reasonable,
67/// particularly for its intended use. It may be useful as a base
68/// implementation for a run-time library during development of a faster
69/// target-specific one.
70///
71/// All 5 rounding modes in the IEEE-754R draft are handled correctly for all
72/// implemented operations. Currently implemented operations are add, subtract,
73/// multiply, divide, fused-multiply-add, conversion-to-float,
74/// conversion-to-integer and conversion-from-integer. New rounding modes
75/// (e.g. away from zero) can be added with three or four lines of code.
76///
77/// Four formats are built-in: IEEE single precision, double precision,
78/// quadruple precision, and x87 80-bit extended double (when operating with
79/// full extended precision). Adding a new format that obeys IEEE semantics
80/// only requires adding two lines of code: a declaration and definition of the
81/// format.
82///
83/// All operations return the status of that operation as an exception bit-mask,
84/// so multiple operations can be done consecutively with their results or-ed
85/// together. The returned status can be useful for compiler diagnostics; e.g.,
86/// inexact, underflow and overflow can be easily diagnosed on constant folding,
87/// and compiler optimizers can determine what exceptions would be raised by
88/// folding operations and optimize, or perhaps not optimize, accordingly.
89///
90/// At present, underflow tininess is detected after rounding; it should be
91/// straight forward to add support for the before-rounding case too.
92///
93/// The library reads hexadecimal floating point numbers as per C99, and
94/// correctly rounds if necessary according to the specified rounding mode.
95/// Syntax is required to have been validated by the caller. It also converts
96/// floating point numbers to hexadecimal text as per the C99 %a and %A
97/// conversions. The output precision (or alternatively the natural minimal
98/// precision) can be specified; if the requested precision is less than the
99/// natural precision the output is correctly rounded for the specified rounding
100/// mode.
101///
102/// It also reads decimal floating point numbers and correctly rounds according
103/// to the specified rounding mode.
104///
105/// Conversion to decimal text is not currently implemented.
106///
107/// Non-zero finite numbers are represented internally as a sign bit, a 16-bit
108/// signed exponent, and the significand as an array of integer parts. After
109/// normalization of a number of precision P the exponent is within the range of
110/// the format, and if the number is not denormal the P-th bit of the
111/// significand is set as an explicit integer bit. For denormals the most
112/// significant bit is shifted right so that the exponent is maintained at the
113/// format's minimum, so that the smallest denormal has just the least
114/// significant bit of the significand set. The sign of zeroes and infinities
115/// is significant; the exponent and significand of such numbers is not stored,
116/// but has a known implicit (deterministic) value: 0 for the significands, 0
117/// for zero exponent, all 1 bits for infinity exponent. For NaNs the sign and
118/// significand are deterministic, although not really meaningful, and preserved
119/// in non-conversion operations. The exponent is implicitly all 1 bits.
120///
121/// APFloat does not provide any exception handling beyond default exception
122/// handling. We represent Signaling NaNs via IEEE-754R 2008 6.2.1 should clause
123/// by encoding Signaling NaNs with the first bit of its trailing significand as
124/// 0.
125///
126/// TODO
127/// ====
128///
129/// Some features that may or may not be worth adding:
130///
131/// Binary to decimal conversion (hard).
132///
133/// Optional ability to detect underflow tininess before rounding.
134///
135/// New formats: x87 in single and double precision mode (IEEE apart from
136/// extended exponent range) (hard).
137///
138/// New operations: sqrt, IEEE remainder, C90 fmod, nexttoward.
139///
140
141namespace detail {
142class IEEEFloat;
143class DoubleAPFloat;
144} // namespace detail
145
146// This is the common type definitions shared by APFloat and its internal
147// implementation classes. This struct should not define any non-static data
148// members.
150public:
152 static constexpr unsigned integerPartWidth = APInt::APINT_BITS_PER_WORD;
153
154 /// A signed type to represent a floating point numbers unbiased exponent.
155 using ExponentType = int32_t;
156
157 /// \name Floating Point Semantics.
158 /// @{
165 // The IBM double-double semantics. Such a number consists of a pair of
166 // IEEE 64-bit doubles (Hi, Lo), where |Hi| > |Lo|, and if normal,
167 // (double)(Hi + Lo) == Hi. The numeric value it's modeling is Hi + Lo.
168 // Therefore it has two 53-bit mantissa parts that aren't necessarily
169 // adjacent to each other, and two 11-bit exponents.
170 //
171 // Note: we need to make the value different from semBogus as otherwise
172 // an unsafe optimization may collapse both values to a single address,
173 // and we heavily rely on them having distinct addresses.
175 // These are legacy semantics for the fallback, inaccurate implementation
176 // of IBM double-double, if the accurate semPPCDoubleDouble doesn't handle
177 // the operation. It's equivalent to having an IEEE number with consecutive
178 // 106 bits of mantissa and 11 bits of exponent.
179 //
180 // It's not equivalent to IBM double-double. For example, a legit IBM
181 // double-double, 1 + epsilon:
182 //
183 // 1 + epsilon = 1 + (1 >> 1076)
184 //
185 // is not representable by a consecutive 106 bits of mantissa.
186 //
187 // Currently, these semantics are used in the following way:
188 //
189 // semPPCDoubleDouble -> (IEEEdouble, IEEEdouble) ->
190 // (64-bit APInt, 64-bit APInt) -> (128-bit APInt) ->
191 // semPPCDoubleDoubleLegacy -> IEEE operations
192 //
193 // We use bitcastToAPInt() to get the bit representation (in APInt) of the
194 // underlying IEEEdouble, then use the APInt constructor to construct the
195 // legacy IEEE float.
196 //
197 // TODO: Implement all operations in semPPCDoubleDouble, and delete these
198 // semantics.
200 // 8-bit floating point number following IEEE-754 conventions with bit
201 // layout S1E5M2 as described in https://arxiv.org/abs/2209.05433.
203 // 8-bit floating point number mostly following IEEE-754 conventions
204 // and bit layout S1E5M2 described in https://arxiv.org/abs/2206.02915,
205 // with expanded range and with no infinity or signed zero.
206 // NaN is represented as negative zero. (FN -> Finite, UZ -> unsigned zero).
207 // This format's exponent bias is 16, instead of the 15 (2 ** (5 - 1) - 1)
208 // that IEEE precedent would imply.
210 // 8-bit floating point number following IEEE-754 conventions with bit
211 // layout S1E4M3.
213 // 8-bit floating point number mostly following IEEE-754 conventions with
214 // bit layout S1E4M3 as described in https://arxiv.org/abs/2209.05433.
215 // Unlike IEEE-754 types, there are no infinity values, and NaN is
216 // represented with the exponent and mantissa bits set to all 1s.
218 // 8-bit floating point number mostly following IEEE-754 conventions
219 // and bit layout S1E4M3 described in https://arxiv.org/abs/2206.02915,
220 // with expanded range and with no infinity or signed zero.
221 // NaN is represented as negative zero. (FN -> Finite, UZ -> unsigned zero).
222 // This format's exponent bias is 8, instead of the 7 (2 ** (4 - 1) - 1)
223 // that IEEE precedent would imply.
225 // 8-bit floating point number mostly following IEEE-754 conventions
226 // and bit layout S1E4M3 with expanded range and with no infinity or signed
227 // zero.
228 // NaN is represented as negative zero. (FN -> Finite, UZ -> unsigned zero).
229 // This format's exponent bias is 11, instead of the 7 (2 ** (4 - 1) - 1)
230 // that IEEE precedent would imply.
232 // 8-bit floating point number following IEEE-754 conventions with bit
233 // layout S1E3M4.
235 // Floating point number that occupies 32 bits or less of storage, providing
236 // improved range compared to half (16-bit) formats, at (potentially)
237 // greater throughput than single precision (32-bit) formats.
239 // 8-bit floating point number with (all the) 8 bits for the exponent
240 // like in FP32. There are no zeroes, no infinities, and no denormal values.
241 // This format has unsigned representation only. (U -> Unsigned only).
242 // NaN is represented with all bits set to 1. Bias is 127.
243 // This format represents the scale data type in the MX specification from:
244 // https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf
246 // 6-bit floating point number with bit layout S1E3M2. Unlike IEEE-754
247 // types, there are no infinity or NaN values. The format is detailed in
248 // https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf
250 // 6-bit floating point number with bit layout S1E2M3. Unlike IEEE-754
251 // types, there are no infinity or NaN values. The format is detailed in
252 // https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf
254 // 4-bit floating point number with bit layout S1E2M1. Unlike IEEE-754
255 // types, there are no infinity or NaN values. The format is detailed in
256 // https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf
258 // TODO: Documentation is missing.
261 };
262
265
266private:
267 LLVM_ABI static const fltSemantics semIEEEhalf;
268 LLVM_ABI static const fltSemantics semBFloat;
269 LLVM_ABI static const fltSemantics semIEEEsingle;
270 LLVM_ABI static const fltSemantics semIEEEdouble;
271 LLVM_ABI static const fltSemantics semIEEEquad;
272 LLVM_ABI static const fltSemantics semFloat8E5M2;
273 LLVM_ABI static const fltSemantics semFloat8E5M2FNUZ;
274 LLVM_ABI static const fltSemantics semFloat8E4M3;
275 LLVM_ABI static const fltSemantics semFloat8E4M3FN;
276 LLVM_ABI static const fltSemantics semFloat8E4M3FNUZ;
277 LLVM_ABI static const fltSemantics semFloat8E4M3B11FNUZ;
278 LLVM_ABI static const fltSemantics semFloat8E3M4;
279 LLVM_ABI static const fltSemantics semFloatTF32;
280 LLVM_ABI static const fltSemantics semFloat8E8M0FNU;
281 LLVM_ABI static const fltSemantics semFloat6E3M2FN;
282 LLVM_ABI static const fltSemantics semFloat6E2M3FN;
283 LLVM_ABI static const fltSemantics semFloat4E2M1FN;
284 LLVM_ABI static const fltSemantics semX87DoubleExtended;
285 LLVM_ABI static const fltSemantics semBogus;
286 LLVM_ABI static const fltSemantics semPPCDoubleDouble;
287 LLVM_ABI static const fltSemantics semPPCDoubleDoubleLegacy;
288
289 friend class detail::IEEEFloat;
291 friend class APFloat;
292
293public:
294 static const fltSemantics &IEEEhalf() { return semIEEEhalf; }
295 static const fltSemantics &BFloat() { return semBFloat; }
296 static const fltSemantics &IEEEsingle() { return semIEEEsingle; }
297 static const fltSemantics &IEEEdouble() { return semIEEEdouble; }
298 static const fltSemantics &IEEEquad() { return semIEEEquad; }
299 static const fltSemantics &PPCDoubleDouble() { return semPPCDoubleDouble; }
301 return semPPCDoubleDoubleLegacy;
302 }
303 static const fltSemantics &Float8E5M2() { return semFloat8E5M2; }
304 static const fltSemantics &Float8E5M2FNUZ() { return semFloat8E5M2FNUZ; }
305 static const fltSemantics &Float8E4M3() { return semFloat8E4M3; }
306 static const fltSemantics &Float8E4M3FN() { return semFloat8E4M3FN; }
307 static const fltSemantics &Float8E4M3FNUZ() { return semFloat8E4M3FNUZ; }
309 return semFloat8E4M3B11FNUZ;
310 }
311 static const fltSemantics &Float8E3M4() { return semFloat8E3M4; }
312 static const fltSemantics &FloatTF32() { return semFloatTF32; }
313 static const fltSemantics &Float8E8M0FNU() { return semFloat8E8M0FNU; }
314 static const fltSemantics &Float6E3M2FN() { return semFloat6E3M2FN; }
315 static const fltSemantics &Float6E2M3FN() { return semFloat6E2M3FN; }
316 static const fltSemantics &Float4E2M1FN() { return semFloat4E2M1FN; }
318 return semX87DoubleExtended;
319 }
320
321 /// A Pseudo fltsemantic used to construct APFloats that cannot conflict with
322 /// anything real.
323 static const fltSemantics &Bogus() { return semBogus; }
324
325 // Returns true if any number described by this semantics can be precisely
326 // represented by the specified semantics. Does not take into account
327 // the value of fltNonfiniteBehavior, hasZero, hasSignedRepr.
328 LLVM_ABI static bool isRepresentableBy(const fltSemantics &A,
329 const fltSemantics &B);
330
331 /// @}
332
333 /// IEEE-754R 5.11: Floating Point Comparison Relations.
340
341 /// IEEE-754R 4.3: Rounding-direction attributes.
343
351
352 /// IEEE-754R 7: Default exception handling.
353 ///
354 /// opUnderflow or opOverflow are always returned or-ed with opInexact.
355 ///
356 /// APFloat models this behavior specified by IEEE-754:
357 /// "For operations producing results in floating-point format, the default
358 /// result of an operation that signals the invalid operation exception
359 /// shall be a quiet NaN."
360 enum opStatus {
361 opOK = 0x00,
367 };
368
369 /// Category of internally-represented number.
376
377 /// Convenience enum used to construct an uninitialized APFloat.
381
382 /// Enumeration of \c ilogb error results.
384 IEK_Zero = INT_MIN + 1,
385 IEK_NaN = INT_MIN,
386 IEK_Inf = INT_MAX
387 };
388
389 LLVM_ABI static unsigned int semanticsPrecision(const fltSemantics &);
392 LLVM_ABI static unsigned int semanticsSizeInBits(const fltSemantics &);
393 LLVM_ABI static unsigned int semanticsIntSizeInBits(const fltSemantics &,
394 bool);
395 LLVM_ABI static bool semanticsHasZero(const fltSemantics &);
396 LLVM_ABI static bool semanticsHasSignedRepr(const fltSemantics &);
397 LLVM_ABI static bool semanticsHasInf(const fltSemantics &);
398 LLVM_ABI static bool semanticsHasNaN(const fltSemantics &);
399 LLVM_ABI static bool isIEEELikeFP(const fltSemantics &);
400 LLVM_ABI static bool hasSignBitInMSB(const fltSemantics &);
401
402 // Returns true if any number described by \p Src can be precisely represented
403 // by a normal (not subnormal) value in \p Dst.
404 LLVM_ABI static bool isRepresentableAsNormalIn(const fltSemantics &Src,
405 const fltSemantics &Dst);
406
407 /// Returns the size of the floating point number (in bits) in the given
408 /// semantics.
409 LLVM_ABI static unsigned getSizeInBits(const fltSemantics &Sem);
410
411 /// Returns true if the given string is a valid arbitrary floating-point
412 /// format interpretation for llvm.convert.to.arbitrary.fp and
413 /// llvm.convert.from.arbitrary.fp intrinsics.
415};
416
417namespace detail {
418
439static constexpr opStatus opOK = APFloatBase::opOK;
449
450class IEEEFloat final {
451public:
452 /// \name Constructors
453 /// @{
454
455 LLVM_ABI IEEEFloat(const fltSemantics &); // Default construct to +0.0
458 LLVM_ABI IEEEFloat(const fltSemantics &, const APInt &);
459 LLVM_ABI explicit IEEEFloat(double d);
460 LLVM_ABI explicit IEEEFloat(float f);
464
465 /// @}
466
467 /// Returns whether this instance allocated memory.
468 bool needsCleanup() const { return partCount() > 1; }
469
470 /// \name Convenience "constructors"
471 /// @{
472
473 /// @}
474
475 /// \name Arithmetic
476 /// @{
477
482 /// IEEE remainder.
484 /// C fmod, or llvm frem.
489 /// IEEE-754R 5.3.1: nextUp/nextDown.
490 LLVM_ABI opStatus next(bool nextDown);
491
492 /// @}
493
494 /// \name Sign operations.
495 /// @{
496
497 LLVM_ABI void changeSign();
498
499 /// @}
500
501 /// \name Conversions
502 /// @{
503
506 bool, roundingMode, bool *) const;
510 LLVM_ABI double convertToDouble() const;
511#ifdef HAS_IEE754_FLOAT128
512 LLVM_ABI float128 convertToQuad() const;
513#endif
514 LLVM_ABI float convertToFloat() const;
515
516 /// @}
517
518 /// The definition of equality is not straightforward for floating point, so
519 /// we won't use operator==. Use one of the following, or write whatever it
520 /// is you really mean.
521 bool operator==(const IEEEFloat &) const = delete;
522
523 /// IEEE comparison with another floating point number (NaNs compare
524 /// unordered, 0==-0).
525 LLVM_ABI cmpResult compare(const IEEEFloat &) const;
526
527 /// Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
528 LLVM_ABI bool bitwiseIsEqual(const IEEEFloat &) const;
529
530 /// Write out a hexadecimal representation of the floating point value to DST,
531 /// which must be of sufficient size, in the C99 form [-]0xh.hhhhp[+-]d.
532 /// Return the number of characters written, excluding the terminating NUL.
533 LLVM_ABI unsigned int convertToHexString(char *dst, unsigned int hexDigits,
534 bool upperCase, roundingMode) const;
535
536 /// \name IEEE-754R 5.7.2 General operations.
537 /// @{
538
539 /// IEEE-754R isSignMinus: Returns true if and only if the current value is
540 /// negative.
541 ///
542 /// This applies to zeros and NaNs as well.
543 bool isNegative() const { return sign; }
544
545 /// IEEE-754R isNormal: Returns true if and only if the current value is normal.
546 ///
547 /// This implies that the current value of the float is not zero, subnormal,
548 /// infinite, or NaN following the definition of normality from IEEE-754R.
549 bool isNormal() const { return !isDenormal() && isFiniteNonZero(); }
550
551 /// Returns true if and only if the current value is zero, subnormal, or
552 /// normal.
553 ///
554 /// This means that the value is not infinite or NaN.
555 bool isFinite() const { return !isNaN() && !isInfinity(); }
556
557 /// Returns true if and only if the float is plus or minus zero.
558 bool isZero() const { return category == fltCategory::fcZero; }
559
560 /// IEEE-754R isSubnormal(): Returns true if and only if the float is a
561 /// denormal.
562 LLVM_ABI bool isDenormal() const;
563
564 /// IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
565 bool isInfinity() const { return category == fcInfinity; }
566
567 /// Returns true if and only if the float is a quiet or signaling NaN.
568 bool isNaN() const { return category == fcNaN; }
569
570 /// Returns true if and only if the float is a signaling NaN.
571 LLVM_ABI bool isSignaling() const;
572
573 /// @}
574
575 /// \name Simple Queries
576 /// @{
577
578 fltCategory getCategory() const { return category; }
579 const fltSemantics &getSemantics() const { return *semantics; }
580 bool isNonZero() const { return category != fltCategory::fcZero; }
581 bool isFiniteNonZero() const { return isFinite() && !isZero(); }
582 bool isPosZero() const { return isZero() && !isNegative(); }
583 bool isNegZero() const { return isZero() && isNegative(); }
584
585 /// Returns true if and only if the number has the smallest possible non-zero
586 /// magnitude in the current semantics.
587 LLVM_ABI bool isSmallest() const;
588
589 /// Returns true if this is the smallest (by magnitude) normalized finite
590 /// number in the given semantics.
591 LLVM_ABI bool isSmallestNormalized() const;
592
593 /// Returns true if and only if the number has the largest possible finite
594 /// magnitude in the current semantics.
595 LLVM_ABI bool isLargest() const;
596
597 /// Returns true if and only if the number is an exact integer.
598 LLVM_ABI bool isInteger() const;
599
600 /// @}
601
604
605 /// Overload to compute a hash code for an APFloat value.
606 ///
607 /// Note that the use of hash codes for floating point values is in general
608 /// frought with peril. Equality is hard to define for these values. For
609 /// example, should negative and positive zero hash to different codes? Are
610 /// they equal or not? This hash value implementation specifically
611 /// emphasizes producing different codes for different inputs in order to
612 /// be used in canonicalization and memoization. As such, equality is
613 /// bitwiseIsEqual, and 0 != -0.
614 LLVM_ABI friend hash_code hash_value(const IEEEFloat &Arg);
615
616 /// Converts this value into a decimal string.
617 ///
618 /// \param FormatPrecision The maximum number of digits of
619 /// precision to output. If there are fewer digits available,
620 /// zero padding will not be used unless the value is
621 /// integral and small enough to be expressed in
622 /// FormatPrecision digits. 0 means to use the natural
623 /// precision of the number.
624 /// \param FormatMaxPadding The maximum number of zeros to
625 /// consider inserting before falling back to scientific
626 /// notation. 0 means to always use scientific notation.
627 ///
628 /// \param TruncateZero Indicate whether to remove the trailing zero in
629 /// fraction part or not. Also setting this parameter to false forcing
630 /// producing of output more similar to default printf behavior.
631 /// Specifically the lower e is used as exponent delimiter and exponent
632 /// always contains no less than two digits.
633 ///
634 /// Number Precision MaxPadding Result
635 /// ------ --------- ---------- ------
636 /// 1.01E+4 5 2 10100
637 /// 1.01E+4 4 2 1.01E+4
638 /// 1.01E+4 5 1 1.01E+4
639 /// 1.01E-2 5 2 0.0101
640 /// 1.01E-2 4 2 0.0101
641 /// 1.01E-2 4 1 1.01E-2
643 unsigned FormatPrecision = 0,
644 unsigned FormatMaxPadding = 3,
645 bool TruncateZero = true) const;
646
648
649 LLVM_ABI friend int ilogb(const IEEEFloat &Arg);
650
652
653 LLVM_ABI friend IEEEFloat frexp(const IEEEFloat &X, int &Exp, roundingMode);
654
655 /// \name Special value setters.
656 /// @{
657
658 LLVM_ABI void makeLargest(bool Neg = false);
659 LLVM_ABI void makeSmallest(bool Neg = false);
660 LLVM_ABI void makeNaN(bool SNaN = false, bool Neg = false,
661 const APInt *fill = nullptr);
662 LLVM_ABI void makeInf(bool Neg = false);
663 LLVM_ABI void makeZero(bool Neg = false);
664 LLVM_ABI void makeQuiet();
665
666 /// Returns the smallest (by magnitude) normalized finite number in the given
667 /// semantics.
668 ///
669 /// \param Negative - True iff the number should be negative
670 LLVM_ABI void makeSmallestNormalized(bool Negative = false);
671
672 /// @}
673
675
676private:
677 /// \name Simple Queries
678 /// @{
679
680 integerPart *significandParts();
681 const integerPart *significandParts() const;
682 LLVM_ABI unsigned int partCount() const;
683
684 /// @}
685
686 /// \name Significand operations.
687 /// @{
688
689 integerPart addSignificand(const IEEEFloat &);
690 integerPart subtractSignificand(const IEEEFloat &, integerPart);
691 // Exported for IEEEFloatUnitTestHelper.
692 LLVM_ABI lostFraction addOrSubtractSignificand(const IEEEFloat &,
693 bool subtract);
694 lostFraction multiplySignificand(const IEEEFloat &, IEEEFloat,
695 bool ignoreAddend = false);
696 lostFraction multiplySignificand(const IEEEFloat&);
697 lostFraction divideSignificand(const IEEEFloat &);
698 void incrementSignificand();
699 void initialize(const fltSemantics *);
700 void shiftSignificandLeft(unsigned int);
701 lostFraction shiftSignificandRight(unsigned int);
702 unsigned int significandLSB() const;
703 unsigned int significandMSB() const;
704 void zeroSignificand();
705 unsigned int getNumHighBits() const;
706 /// Return true if the significand excluding the integral bit is all ones.
707 bool isSignificandAllOnes() const;
708 bool isSignificandAllOnesExceptLSB() const;
709 /// Return true if the significand excluding the integral bit is all zeros.
710 bool isSignificandAllZeros() const;
711 bool isSignificandAllZerosExceptMSB() const;
712
713 /// @}
714
715 /// \name Arithmetic on special values.
716 /// @{
717
718 opStatus addOrSubtractSpecials(const IEEEFloat &, bool subtract);
719 opStatus divideSpecials(const IEEEFloat &);
720 opStatus multiplySpecials(const IEEEFloat &);
721 opStatus modSpecials(const IEEEFloat &);
722 opStatus remainderSpecials(const IEEEFloat&);
723
724 /// @}
725
726 /// \name Miscellany
727 /// @{
728
729 bool convertFromStringSpecials(StringRef str);
731 opStatus addOrSubtract(const IEEEFloat &, roundingMode, bool subtract);
732 opStatus handleOverflow(roundingMode);
733 bool roundAwayFromZero(roundingMode, lostFraction, unsigned int) const;
734 opStatus convertToSignExtendedInteger(MutableArrayRef<integerPart>,
735 unsigned int, bool, roundingMode,
736 bool *) const;
737 opStatus convertFromUnsignedParts(const integerPart *, unsigned int,
739 Expected<opStatus> convertFromHexadecimalString(StringRef, roundingMode);
740 Expected<opStatus> convertFromDecimalString(StringRef, roundingMode);
741 char *convertNormalToHexString(char *, unsigned int, bool,
742 roundingMode) const;
743 opStatus roundSignificandWithExponent(const integerPart *, unsigned int, int,
748
749 /// @}
750
751 template <const fltSemantics &S> APInt convertIEEEFloatToAPInt() const;
752 APInt convertHalfAPFloatToAPInt() const;
753 APInt convertBFloatAPFloatToAPInt() const;
754 APInt convertFloatAPFloatToAPInt() const;
755 APInt convertDoubleAPFloatToAPInt() const;
756 APInt convertQuadrupleAPFloatToAPInt() const;
757 APInt convertF80LongDoubleAPFloatToAPInt() const;
758 APInt convertPPCDoubleDoubleLegacyAPFloatToAPInt() const;
759 APInt convertFloat8E5M2APFloatToAPInt() const;
760 APInt convertFloat8E5M2FNUZAPFloatToAPInt() const;
761 APInt convertFloat8E4M3APFloatToAPInt() const;
762 APInt convertFloat8E4M3FNAPFloatToAPInt() const;
763 APInt convertFloat8E4M3FNUZAPFloatToAPInt() const;
764 APInt convertFloat8E4M3B11FNUZAPFloatToAPInt() const;
765 APInt convertFloat8E3M4APFloatToAPInt() const;
766 APInt convertFloatTF32APFloatToAPInt() const;
767 APInt convertFloat8E8M0FNUAPFloatToAPInt() const;
768 APInt convertFloat6E3M2FNAPFloatToAPInt() const;
769 APInt convertFloat6E2M3FNAPFloatToAPInt() const;
770 APInt convertFloat4E2M1FNAPFloatToAPInt() const;
771 void initFromAPInt(const fltSemantics *Sem, const APInt &api);
772 template <const fltSemantics &S> void initFromIEEEAPInt(const APInt &api);
773 void initFromHalfAPInt(const APInt &api);
774 void initFromBFloatAPInt(const APInt &api);
775 void initFromFloatAPInt(const APInt &api);
776 void initFromDoubleAPInt(const APInt &api);
777 void initFromQuadrupleAPInt(const APInt &api);
778 void initFromF80LongDoubleAPInt(const APInt &api);
779 void initFromPPCDoubleDoubleLegacyAPInt(const APInt &api);
780 void initFromFloat8E5M2APInt(const APInt &api);
781 void initFromFloat8E5M2FNUZAPInt(const APInt &api);
782 void initFromFloat8E4M3APInt(const APInt &api);
783 void initFromFloat8E4M3FNAPInt(const APInt &api);
784 void initFromFloat8E4M3FNUZAPInt(const APInt &api);
785 void initFromFloat8E4M3B11FNUZAPInt(const APInt &api);
786 void initFromFloat8E3M4APInt(const APInt &api);
787 void initFromFloatTF32APInt(const APInt &api);
788 void initFromFloat8E8M0FNUAPInt(const APInt &api);
789 void initFromFloat6E3M2FNAPInt(const APInt &api);
790 void initFromFloat6E2M3FNAPInt(const APInt &api);
791 void initFromFloat4E2M1FNAPInt(const APInt &api);
792
793 void assign(const IEEEFloat &);
794 void copySignificand(const IEEEFloat &);
795 void freeSignificand();
796
797 /// Note: this must be the first data member.
798 /// The semantics that this value obeys.
799 const fltSemantics *semantics;
800
801 /// A binary fraction with an explicit integer bit.
802 ///
803 /// The significand must be at least one bit wider than the target precision.
804 union Significand {
805 integerPart part;
806 integerPart *parts;
807 } significand;
808
809 /// The signed unbiased exponent of the value.
810 ExponentType exponent;
811
812 /// What kind of floating point number this is.
813 ///
814 /// Only 2 bits are required, but VisualStudio incorrectly sign extends it.
815 /// Using the extra bit keeps it from failing under VisualStudio.
816 fltCategory category : 3;
817
818 /// Sign bit of the number.
819 unsigned int sign : 1;
820
822};
823
825LLVM_ABI int ilogb(const IEEEFloat &Arg);
827LLVM_ABI IEEEFloat frexp(const IEEEFloat &Val, int &Exp, roundingMode RM);
828
829// This mode implements more precise float in terms of two APFloats.
830// The interface and layout is designed for arbitrary underlying semantics,
831// though currently only PPCDoubleDouble semantics are supported, whose
832// corresponding underlying semantics are IEEEdouble.
833class DoubleAPFloat final {
834 // Note: this must be the first data member.
835 const fltSemantics *Semantics;
836 APFloat *Floats;
837
838 opStatus addImpl(const APFloat &a, const APFloat &aa, const APFloat &c,
839 const APFloat &cc, roundingMode RM);
840
841 opStatus addWithSpecial(const DoubleAPFloat &LHS, const DoubleAPFloat &RHS,
842 DoubleAPFloat &Out, roundingMode RM);
843 opStatus convertToSignExtendedInteger(MutableArrayRef<integerPart> Input,
844 unsigned int Width, bool IsSigned,
845 roundingMode RM, bool *IsExact) const;
846
847 // Convert an unsigned integer Src to a floating point number,
848 // rounding according to RM. The sign of the floating point number is not
849 // modified.
850 opStatus convertFromUnsignedParts(const integerPart *Src,
851 unsigned int SrcCount, roundingMode RM);
852
853 // Handle overflow. Sign is preserved. We either become infinity or
854 // the largest finite number.
855 opStatus handleOverflow(roundingMode RM);
856
857public:
861 LLVM_ABI DoubleAPFloat(const fltSemantics &S, const APInt &I);
863 APFloat &&Second);
867
870
871 bool needsCleanup() const { return Floats != nullptr; }
872
873 inline APFloat &getFirst();
874 inline const APFloat &getFirst() const;
875 inline APFloat &getSecond();
876 inline const APFloat &getSecond() const;
877
885 const DoubleAPFloat &Addend,
886 roundingMode RM);
888 LLVM_ABI void changeSign();
890
892 LLVM_ABI bool isNegative() const;
893
894 LLVM_ABI void makeInf(bool Neg);
895 LLVM_ABI void makeZero(bool Neg);
896 LLVM_ABI void makeLargest(bool Neg);
897 LLVM_ABI void makeSmallest(bool Neg);
898 LLVM_ABI void makeSmallestNormalized(bool Neg);
899 LLVM_ABI void makeNaN(bool SNaN, bool Neg, const APInt *fill);
900
902 LLVM_ABI bool bitwiseIsEqual(const DoubleAPFloat &RHS) const;
905 LLVM_ABI opStatus next(bool nextDown);
906
908 unsigned int Width, bool IsSigned,
909 roundingMode RM, bool *IsExact) const;
910 LLVM_ABI opStatus convertFromAPInt(const APInt &Input, bool IsSigned,
911 roundingMode RM);
912 LLVM_ABI unsigned int convertToHexString(char *DST, unsigned int HexDigits,
913 bool UpperCase,
914 roundingMode RM) const;
915
916 LLVM_ABI bool isDenormal() const;
917 LLVM_ABI bool isSmallest() const;
918 LLVM_ABI bool isSmallestNormalized() const;
919 LLVM_ABI bool isLargest() const;
920 LLVM_ABI bool isInteger() const;
921
922 LLVM_ABI void toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision,
923 unsigned FormatMaxPadding,
924 bool TruncateZero = true) const;
925
927
928 LLVM_ABI friend int ilogb(const DoubleAPFloat &X);
931 LLVM_ABI friend DoubleAPFloat frexp(const DoubleAPFloat &X, int &Exp,
933 LLVM_ABI friend hash_code hash_value(const DoubleAPFloat &Arg);
934};
935
937LLVM_ABI DoubleAPFloat scalbn(const DoubleAPFloat &Arg, int Exp,
938 roundingMode RM);
940
941} // End detail namespace
942
943// How the nonfinite values Inf and NaN are represented.
945 // Represents standard IEEE 754 behavior. A value is nonfinite if the
946 // exponent field is all 1s. In such cases, a value is Inf if the
947 // significand bits are all zero, and NaN otherwise
949
950 // This behavior is present in the Float8ExMyFN* types (Float8E4M3FN,
951 // Float8E5M2FNUZ, Float8E4M3FNUZ, and Float8E4M3B11FNUZ). There is no
952 // representation for Inf, and operations that would ordinarily produce Inf
953 // produce NaN instead.
954 // The details of the NaN representation(s) in this form are determined by the
955 // `fltNanEncoding` enum. We treat all NaNs as quiet, as the available
956 // encodings do not distinguish between signalling and quiet NaN.
958
959 // This behavior is present in Float6E3M2FN, Float6E2M3FN, and
960 // Float4E2M1FN types, which do not support Inf or NaN values.
962};
963
964// How NaN values are represented. This is curently only used in combination
965// with fltNonfiniteBehavior::NanOnly, and using a variant other than IEEE
966// while having IEEE non-finite behavior is liable to lead to unexpected
967// results.
968enum class fltNanEncoding {
969 // Represents the standard IEEE behavior where a value is NaN if its
970 // exponent is all 1s and the significand is non-zero.
972
973 // Represents the behavior in the Float8E4M3FN floating point type where NaN
974 // is represented by having the exponent and mantissa set to all 1s.
975 // This behavior matches the FP8 E4M3 type described in
976 // https://arxiv.org/abs/2209.05433. We treat both signed and unsigned NaNs
977 // as non-signalling, although the paper does not state whether the NaN
978 // values are signalling or not.
980
981 // Represents the behavior in Float8E{5,4}E{2,3}FNUZ floating point types
982 // where NaN is represented by a sign bit of 1 and all 0s in the exponent
983 // and mantissa (i.e. the negative zero encoding in a IEEE float). Since
984 // there is only one NaN value, it is treated as quiet NaN. This matches the
985 // behavior described in https://arxiv.org/abs/2206.02915 .
987};
988/* Represents floating point arithmetic semantics. */
990 /* The largest E such that 2^E is representable; this matches the
991 definition of IEEE 754. */
993
994 /* The smallest E such that 2^E is a normalized number; this
995 matches the definition of IEEE 754. */
997
998 /* Number of bits in the significand. This includes the integer
999 bit. */
1000 unsigned int precision;
1001
1002 /* Number of bits actually used in the semantics. */
1003 unsigned int sizeInBits;
1004
1006
1008
1009 /* Whether this semantics has an encoding for Zero */
1010 bool hasZero = true;
1011
1012 /* Whether this semantics can represent signed values */
1013 bool hasSignedRepr = true;
1014
1015 /* Whether the sign bit of this semantics is the most significant bit */
1016 bool hasSignBitInMSB = true;
1017};
1018
1019// This is a interface class that is currently forwarding functionalities from
1020// detail::IEEEFloat.
1021class APFloat : public APFloatBase {
1022 using IEEEFloat = detail::IEEEFloat;
1023 using DoubleAPFloat = detail::DoubleAPFloat;
1024
1025 static_assert(std::is_standard_layout<IEEEFloat>::value);
1026
1027 union Storage {
1028 const fltSemantics *semantics;
1029 IEEEFloat IEEE;
1030 DoubleAPFloat Double;
1031
1032 LLVM_ABI explicit Storage(IEEEFloat F, const fltSemantics &S);
1033 explicit Storage(DoubleAPFloat F, const fltSemantics &S)
1034 : Double(std::move(F)) {
1035 assert(&S == &PPCDoubleDouble());
1036 }
1037
1038 template <typename... ArgTypes>
1039 Storage(const fltSemantics &Semantics, ArgTypes &&... Args) {
1040 if (usesLayout<IEEEFloat>(Semantics)) {
1041 new (&IEEE) IEEEFloat(Semantics, std::forward<ArgTypes>(Args)...);
1042 return;
1043 }
1044 if (usesLayout<DoubleAPFloat>(Semantics)) {
1045 new (&Double) DoubleAPFloat(Semantics, std::forward<ArgTypes>(Args)...);
1046 return;
1047 }
1048 llvm_unreachable("Unexpected semantics");
1049 }
1050
1051 LLVM_ABI ~Storage();
1052 LLVM_ABI Storage(const Storage &RHS);
1053 LLVM_ABI Storage(Storage &&RHS);
1054 LLVM_ABI Storage &operator=(const Storage &RHS);
1055 LLVM_ABI Storage &operator=(Storage &&RHS);
1056 } U;
1057
1058 template <typename T> static bool usesLayout(const fltSemantics &Semantics) {
1059 static_assert(std::is_same<T, IEEEFloat>::value ||
1060 std::is_same<T, DoubleAPFloat>::value);
1061 if (std::is_same<T, DoubleAPFloat>::value) {
1062 return &Semantics == &PPCDoubleDouble();
1063 }
1064 return &Semantics != &PPCDoubleDouble();
1065 }
1066
1067 IEEEFloat &getIEEE() {
1068 if (usesLayout<IEEEFloat>(*U.semantics))
1069 return U.IEEE;
1070 if (usesLayout<DoubleAPFloat>(*U.semantics))
1071 return U.Double.getFirst().U.IEEE;
1072 llvm_unreachable("Unexpected semantics");
1073 }
1074
1075 const IEEEFloat &getIEEE() const {
1076 if (usesLayout<IEEEFloat>(*U.semantics))
1077 return U.IEEE;
1078 if (usesLayout<DoubleAPFloat>(*U.semantics))
1079 return U.Double.getFirst().U.IEEE;
1080 llvm_unreachable("Unexpected semantics");
1081 }
1082
1083 void makeZero(bool Neg) { APFLOAT_DISPATCH_ON_SEMANTICS(makeZero(Neg)); }
1084
1085 void makeInf(bool Neg) { APFLOAT_DISPATCH_ON_SEMANTICS(makeInf(Neg)); }
1086
1087 void makeNaN(bool SNaN, bool Neg, const APInt *fill) {
1088 APFLOAT_DISPATCH_ON_SEMANTICS(makeNaN(SNaN, Neg, fill));
1089 }
1090
1091 void makeLargest(bool Neg) {
1092 APFLOAT_DISPATCH_ON_SEMANTICS(makeLargest(Neg));
1093 }
1094
1095 void makeSmallest(bool Neg) {
1096 APFLOAT_DISPATCH_ON_SEMANTICS(makeSmallest(Neg));
1097 }
1098
1099 void makeSmallestNormalized(bool Neg) {
1100 APFLOAT_DISPATCH_ON_SEMANTICS(makeSmallestNormalized(Neg));
1101 }
1102
1103 explicit APFloat(IEEEFloat F, const fltSemantics &S) : U(std::move(F), S) {}
1104 explicit APFloat(DoubleAPFloat F, const fltSemantics &S)
1105 : U(std::move(F), S) {}
1106
1107 // Compares the absolute value of this APFloat with another. Both operands
1108 // must be finite non-zero.
1109 cmpResult compareAbsoluteValue(const APFloat &RHS) const {
1110 assert(&getSemantics() == &RHS.getSemantics() &&
1111 "Should only compare APFloats with the same semantics");
1112 if (usesLayout<IEEEFloat>(getSemantics()))
1113 return U.IEEE.compareAbsoluteValue(RHS.U.IEEE);
1114 if (usesLayout<DoubleAPFloat>(getSemantics()))
1115 return U.Double.compareAbsoluteValue(RHS.U.Double);
1116 llvm_unreachable("Unexpected semantics");
1117 }
1118
1119public:
1123 template <typename T,
1124 typename = std::enable_if_t<std::is_floating_point<T>::value>>
1125 APFloat(const fltSemantics &Semantics, T V) = delete;
1126 // TODO: Remove this constructor. This isn't faster than the first one.
1130 explicit APFloat(double d) : U(IEEEFloat(d), IEEEdouble()) {}
1131 explicit APFloat(float f) : U(IEEEFloat(f), IEEEsingle()) {}
1132 APFloat(const APFloat &RHS) = default;
1133 APFloat(APFloat &&RHS) = default;
1134
1135 ~APFloat() = default;
1136
1138
1139 /// Factory for Positive and Negative Zero.
1140 ///
1141 /// \param Negative True iff the number should be negative.
1142 static APFloat getZero(const fltSemantics &Sem, bool Negative = false) {
1143 APFloat Val(Sem, uninitialized);
1144 Val.makeZero(Negative);
1145 return Val;
1146 }
1147
1148 /// Factory for Positive and Negative One.
1149 ///
1150 /// \param Negative True iff the number should be negative.
1151 static APFloat getOne(const fltSemantics &Sem, bool Negative = false) {
1152 APFloat Val(Sem, 1U);
1153 if (Negative)
1154 Val.changeSign();
1155 return Val;
1156 }
1157
1158 /// Factory for Positive and Negative Infinity.
1159 ///
1160 /// \param Negative True iff the number should be negative.
1161 static APFloat getInf(const fltSemantics &Sem, bool Negative = false) {
1162 APFloat Val(Sem, uninitialized);
1163 Val.makeInf(Negative);
1164 return Val;
1165 }
1166
1167 /// Factory for NaN values.
1168 ///
1169 /// \param Negative - True iff the NaN generated should be negative.
1170 /// \param payload - The unspecified fill bits for creating the NaN, 0 by
1171 /// default. The value is truncated as necessary.
1172 static APFloat getNaN(const fltSemantics &Sem, bool Negative = false,
1173 uint64_t payload = 0) {
1174 if (payload) {
1175 APInt intPayload(64, payload);
1176 return getQNaN(Sem, Negative, &intPayload);
1177 } else {
1178 return getQNaN(Sem, Negative, nullptr);
1179 }
1180 }
1181
1182 /// Factory for QNaN values.
1183 static APFloat getQNaN(const fltSemantics &Sem, bool Negative = false,
1184 const APInt *payload = nullptr) {
1185 APFloat Val(Sem, uninitialized);
1186 Val.makeNaN(false, Negative, payload);
1187 return Val;
1188 }
1189
1190 /// Factory for SNaN values.
1191 static APFloat getSNaN(const fltSemantics &Sem, bool Negative = false,
1192 const APInt *payload = nullptr) {
1193 APFloat Val(Sem, uninitialized);
1194 Val.makeNaN(true, Negative, payload);
1195 return Val;
1196 }
1197
1198 /// Returns the largest finite number in the given semantics.
1199 ///
1200 /// \param Negative - True iff the number should be negative
1201 static APFloat getLargest(const fltSemantics &Sem, bool Negative = false) {
1202 APFloat Val(Sem, uninitialized);
1203 Val.makeLargest(Negative);
1204 return Val;
1205 }
1206
1207 /// Returns the smallest (by magnitude) finite number in the given semantics.
1208 /// Might be denormalized, which implies a relative loss of precision.
1209 ///
1210 /// \param Negative - True iff the number should be negative
1211 static APFloat getSmallest(const fltSemantics &Sem, bool Negative = false) {
1212 APFloat Val(Sem, uninitialized);
1213 Val.makeSmallest(Negative);
1214 return Val;
1215 }
1216
1217 /// Returns the smallest (by magnitude) normalized finite number in the given
1218 /// semantics.
1219 ///
1220 /// \param Negative - True iff the number should be negative
1221 static APFloat getSmallestNormalized(const fltSemantics &Sem,
1222 bool Negative = false) {
1223 APFloat Val(Sem, uninitialized);
1224 Val.makeSmallestNormalized(Negative);
1225 return Val;
1226 }
1227
1228 /// Returns a float which is bitcasted from an all one value int.
1229 ///
1230 /// \param Semantics - type float semantics
1232
1233 /// Returns true if the given semantics has actual significand.
1234 ///
1235 /// \param Sem - type float semantics
1236 static bool hasSignificand(const fltSemantics &Sem) {
1237 return &Sem != &Float8E8M0FNU();
1238 }
1239
1240 /// Used to insert APFloat objects, or objects that contain APFloat objects,
1241 /// into FoldingSets.
1242 LLVM_ABI void Profile(FoldingSetNodeID &NID) const;
1243
1244 opStatus add(const APFloat &RHS, roundingMode RM) {
1245 assert(&getSemantics() == &RHS.getSemantics() &&
1246 "Should only call on two APFloats with the same semantics");
1247 if (usesLayout<IEEEFloat>(getSemantics()))
1248 return U.IEEE.add(RHS.U.IEEE, RM);
1249 if (usesLayout<DoubleAPFloat>(getSemantics()))
1250 return U.Double.add(RHS.U.Double, RM);
1251 llvm_unreachable("Unexpected semantics");
1252 }
1253 opStatus subtract(const APFloat &RHS, roundingMode RM) {
1254 assert(&getSemantics() == &RHS.getSemantics() &&
1255 "Should only call on two APFloats with the same semantics");
1256 if (usesLayout<IEEEFloat>(getSemantics()))
1257 return U.IEEE.subtract(RHS.U.IEEE, RM);
1258 if (usesLayout<DoubleAPFloat>(getSemantics()))
1259 return U.Double.subtract(RHS.U.Double, RM);
1260 llvm_unreachable("Unexpected semantics");
1261 }
1262 opStatus multiply(const APFloat &RHS, roundingMode RM) {
1263 assert(&getSemantics() == &RHS.getSemantics() &&
1264 "Should only call on two APFloats with the same semantics");
1265 if (usesLayout<IEEEFloat>(getSemantics()))
1266 return U.IEEE.multiply(RHS.U.IEEE, RM);
1267 if (usesLayout<DoubleAPFloat>(getSemantics()))
1268 return U.Double.multiply(RHS.U.Double, RM);
1269 llvm_unreachable("Unexpected semantics");
1270 }
1271 opStatus divide(const APFloat &RHS, roundingMode RM) {
1272 assert(&getSemantics() == &RHS.getSemantics() &&
1273 "Should only call on two APFloats with the same semantics");
1274 if (usesLayout<IEEEFloat>(getSemantics()))
1275 return U.IEEE.divide(RHS.U.IEEE, RM);
1276 if (usesLayout<DoubleAPFloat>(getSemantics()))
1277 return U.Double.divide(RHS.U.Double, RM);
1278 llvm_unreachable("Unexpected semantics");
1279 }
1280 opStatus remainder(const APFloat &RHS) {
1281 assert(&getSemantics() == &RHS.getSemantics() &&
1282 "Should only call on two APFloats with the same semantics");
1283 if (usesLayout<IEEEFloat>(getSemantics()))
1284 return U.IEEE.remainder(RHS.U.IEEE);
1285 if (usesLayout<DoubleAPFloat>(getSemantics()))
1286 return U.Double.remainder(RHS.U.Double);
1287 llvm_unreachable("Unexpected semantics");
1288 }
1289 opStatus mod(const APFloat &RHS) {
1290 assert(&getSemantics() == &RHS.getSemantics() &&
1291 "Should only call on two APFloats with the same semantics");
1292 if (usesLayout<IEEEFloat>(getSemantics()))
1293 return U.IEEE.mod(RHS.U.IEEE);
1294 if (usesLayout<DoubleAPFloat>(getSemantics()))
1295 return U.Double.mod(RHS.U.Double);
1296 llvm_unreachable("Unexpected semantics");
1297 }
1298 opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend,
1299 roundingMode RM) {
1300 assert(&getSemantics() == &Multiplicand.getSemantics() &&
1301 "Should only call on APFloats with the same semantics");
1302 assert(&getSemantics() == &Addend.getSemantics() &&
1303 "Should only call on APFloats with the same semantics");
1304 if (usesLayout<IEEEFloat>(getSemantics()))
1305 return U.IEEE.fusedMultiplyAdd(Multiplicand.U.IEEE, Addend.U.IEEE, RM);
1306 if (usesLayout<DoubleAPFloat>(getSemantics()))
1307 return U.Double.fusedMultiplyAdd(Multiplicand.U.Double, Addend.U.Double,
1308 RM);
1309 llvm_unreachable("Unexpected semantics");
1310 }
1314
1315 // TODO: bool parameters are not readable and a source of bugs.
1316 // Do something.
1317 opStatus next(bool nextDown) {
1319 }
1320
1321 /// Negate an APFloat.
1322 APFloat operator-() const {
1323 APFloat Result(*this);
1324 Result.changeSign();
1325 return Result;
1326 }
1327
1328 /// Add two APFloats, rounding ties to the nearest even.
1329 /// No error checking.
1330 APFloat operator+(const APFloat &RHS) const {
1331 APFloat Result(*this);
1332 (void)Result.add(RHS, rmNearestTiesToEven);
1333 return Result;
1334 }
1335
1336 /// Subtract two APFloats, rounding ties to the nearest even.
1337 /// No error checking.
1338 APFloat operator-(const APFloat &RHS) const {
1339 APFloat Result(*this);
1340 (void)Result.subtract(RHS, rmNearestTiesToEven);
1341 return Result;
1342 }
1343
1344 /// Multiply two APFloats, rounding ties to the nearest even.
1345 /// No error checking.
1346 APFloat operator*(const APFloat &RHS) const {
1347 APFloat Result(*this);
1348 (void)Result.multiply(RHS, rmNearestTiesToEven);
1349 return Result;
1350 }
1351
1352 /// Divide the first APFloat by the second, rounding ties to the nearest even.
1353 /// No error checking.
1354 APFloat operator/(const APFloat &RHS) const {
1355 APFloat Result(*this);
1356 (void)Result.divide(RHS, rmNearestTiesToEven);
1357 return Result;
1358 }
1359
1361 void clearSign() {
1362 if (isNegative())
1363 changeSign();
1364 }
1365 void copySign(const APFloat &RHS) {
1366 if (isNegative() != RHS.isNegative())
1367 changeSign();
1368 }
1369
1370 /// A static helper to produce a copy of an APFloat value with its sign
1371 /// copied from some other APFloat.
1372 static APFloat copySign(APFloat Value, const APFloat &Sign) {
1373 Value.copySign(Sign);
1374 return Value;
1375 }
1376
1377 /// Assuming this is an IEEE-754 NaN value, quiet its signaling bit.
1378 /// This preserves the sign and payload bits.
1379 [[nodiscard]] APFloat makeQuiet() const {
1380 APFloat Result(*this);
1381 Result.getIEEE().makeQuiet();
1382 return Result;
1383 }
1384
1385 LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM,
1386 bool *losesInfo);
1387 // Convert a floating point number to an integer according to the
1388 // rounding mode. We provide deterministic values in case of an invalid
1389 // operation exception, namely zero for NaNs and the minimal or maximal value
1390 // respectively for underflow or overflow.
1391 // The *IsExact output tells whether the result is exact, in the sense that
1392 // converting it back to the original floating point type produces the
1393 // original value. This is almost equivalent to result==opOK, except for
1394 // negative zeroes.
1396 unsigned int Width, bool IsSigned, roundingMode RM,
1397 bool *IsExact) const {
1399 convertToInteger(Input, Width, IsSigned, RM, IsExact));
1400 }
1401 // Same as convertToInteger(integerPart*, ...), except the result is returned
1402 // in an APSInt, whose initial bit-width and signed-ness are used to determine
1403 // the precision of the conversion.
1405 bool *IsExact) const;
1406
1407 // Convert a two's complement integer Input to a floating point number,
1408 // rounding according to RM. IsSigned is true if the integer is signed,
1409 // in which case it must be sign-extended.
1410 opStatus convertFromAPInt(const APInt &Input, bool IsSigned,
1411 roundingMode RM) {
1413 }
1414
1419
1420 /// Converts this APFloat to host double value.
1421 ///
1422 /// \pre The APFloat must be built using semantics, that can be represented by
1423 /// the host double type without loss of precision. It can be IEEEdouble and
1424 /// shorter semantics, like IEEEsingle and others.
1425 LLVM_ABI double convertToDouble() const;
1426
1427 /// Converts this APFloat to host float value.
1428 ///
1429 /// \pre The APFloat must be built using semantics, that can be represented by
1430 /// the host float type without loss of precision. It can be IEEEquad and
1431 /// shorter semantics, like IEEEdouble and others.
1432#ifdef HAS_IEE754_FLOAT128
1433 LLVM_ABI float128 convertToQuad() const;
1434#endif
1435
1436 /// Converts this APFloat to host float value.
1437 ///
1438 /// \pre The APFloat must be built using semantics, that can be represented by
1439 /// the host float type without loss of precision. It can be IEEEsingle and
1440 /// shorter semantics, like IEEEhalf.
1441 LLVM_ABI float convertToFloat() const;
1442
1443 bool operator==(const APFloat &RHS) const { return compare(RHS) == cmpEqual; }
1444
1445 bool operator!=(const APFloat &RHS) const { return compare(RHS) != cmpEqual; }
1446
1447 bool operator<(const APFloat &RHS) const {
1448 return compare(RHS) == cmpLessThan;
1449 }
1450
1451 bool operator>(const APFloat &RHS) const {
1452 return compare(RHS) == cmpGreaterThan;
1453 }
1454
1455 bool operator<=(const APFloat &RHS) const {
1456 cmpResult Res = compare(RHS);
1457 return Res == cmpLessThan || Res == cmpEqual;
1458 }
1459
1460 bool operator>=(const APFloat &RHS) const {
1461 cmpResult Res = compare(RHS);
1462 return Res == cmpGreaterThan || Res == cmpEqual;
1463 }
1464
1465 // IEEE comparison with another floating point number (NaNs compare unordered,
1466 // 0==-0).
1467 cmpResult compare(const APFloat &RHS) const {
1468 assert(&getSemantics() == &RHS.getSemantics() &&
1469 "Should only compare APFloats with the same semantics");
1470 if (usesLayout<IEEEFloat>(getSemantics()))
1471 return U.IEEE.compare(RHS.U.IEEE);
1472 if (usesLayout<DoubleAPFloat>(getSemantics()))
1473 return U.Double.compare(RHS.U.Double);
1474 llvm_unreachable("Unexpected semantics");
1475 }
1476
1477 bool bitwiseIsEqual(const APFloat &RHS) const {
1478 if (&getSemantics() != &RHS.getSemantics())
1479 return false;
1480 if (usesLayout<IEEEFloat>(getSemantics()))
1481 return U.IEEE.bitwiseIsEqual(RHS.U.IEEE);
1482 if (usesLayout<DoubleAPFloat>(getSemantics()))
1483 return U.Double.bitwiseIsEqual(RHS.U.Double);
1484 llvm_unreachable("Unexpected semantics");
1485 }
1486
1487 /// We don't rely on operator== working on double values, as
1488 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1489 /// As such, this method can be used to do an exact bit-for-bit comparison of
1490 /// two floating point values.
1491 ///
1492 /// We leave the version with the double argument here because it's just so
1493 /// convenient to write "2.0" and the like. Without this function we'd
1494 /// have to duplicate its logic everywhere it's called.
1495 bool isExactlyValue(double V) const {
1496 bool ignored;
1497 APFloat Tmp(V);
1499 return bitwiseIsEqual(Tmp);
1500 }
1501
1502 unsigned int convertToHexString(char *DST, unsigned int HexDigits,
1503 bool UpperCase, roundingMode RM) const {
1505 convertToHexString(DST, HexDigits, UpperCase, RM));
1506 }
1507
1508 bool isZero() const { return getCategory() == fcZero; }
1509 bool isInfinity() const { return getCategory() == fcInfinity; }
1510 bool isNaN() const { return getCategory() == fcNaN; }
1511
1512 bool isNegative() const { return getIEEE().isNegative(); }
1514 bool isSignaling() const { return getIEEE().isSignaling(); }
1515
1516 bool isNormal() const { return !isDenormal() && isFiniteNonZero(); }
1517 bool isFinite() const { return !isNaN() && !isInfinity(); }
1518
1519 fltCategory getCategory() const { return getIEEE().getCategory(); }
1520 const fltSemantics &getSemantics() const { return *U.semantics; }
1521 bool isNonZero() const { return !isZero(); }
1522 bool isFiniteNonZero() const { return isFinite() && !isZero(); }
1523 bool isPosZero() const { return isZero() && !isNegative(); }
1524 bool isNegZero() const { return isZero() && isNegative(); }
1525 bool isPosInfinity() const { return isInfinity() && !isNegative(); }
1526 bool isNegInfinity() const { return isInfinity() && isNegative(); }
1530
1534
1535 /// Return the FPClassTest which will return true for the value.
1537
1538 APFloat &operator=(const APFloat &RHS) = default;
1539 APFloat &operator=(APFloat &&RHS) = default;
1540
1541 void toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision = 0,
1542 unsigned FormatMaxPadding = 3, bool TruncateZero = true) const {
1544 toString(Str, FormatPrecision, FormatMaxPadding, TruncateZero));
1545 }
1546
1547 LLVM_ABI void print(raw_ostream &) const;
1548
1549#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1550 LLVM_DUMP_METHOD void dump() const;
1551#endif
1552
1553 /// If this value is normal and has an exact, normal, multiplicative inverse,
1554 /// store it in inv and return true.
1555 LLVM_ABI bool getExactInverse(APFloat *Inv) const;
1556
1557 // If this is an exact power of two, return the exponent while ignoring the
1558 // sign bit. If it's not an exact power of 2, return INT_MIN
1563
1564 // If this is an exact power of two, return the exponent. If it's not an exact
1565 // power of 2, return INT_MIN
1567 int getExactLog2() const {
1568 return isNegative() ? INT_MIN : getExactLog2Abs();
1569 }
1570
1571 LLVM_ABI friend hash_code hash_value(const APFloat &Arg);
1572 friend int ilogb(const APFloat &Arg);
1573 friend APFloat scalbn(APFloat X, int Exp, roundingMode RM);
1574 friend APFloat frexp(const APFloat &X, int &Exp, roundingMode RM);
1575 friend IEEEFloat;
1576 friend DoubleAPFloat;
1577};
1578
1579static_assert(sizeof(APFloat) == sizeof(detail::IEEEFloat),
1580 "Empty base class optimization is not performed.");
1581
1582/// See friend declarations above.
1583///
1584/// These additional declarations are required in order to compile LLVM with IBM
1585/// xlC compiler.
1587
1588/// Returns the exponent of the internal representation of the APFloat.
1589///
1590/// Because the radix of APFloat is 2, this is equivalent to floor(log2(x)).
1591/// For special APFloat values, this returns special error codes:
1592///
1593/// NaN -> \c IEK_NaN
1594/// 0 -> \c IEK_Zero
1595/// Inf -> \c IEK_Inf
1596///
1597inline int ilogb(const APFloat &Arg) {
1598 if (APFloat::usesLayout<detail::IEEEFloat>(Arg.getSemantics()))
1599 return ilogb(Arg.U.IEEE);
1600 if (APFloat::usesLayout<detail::DoubleAPFloat>(Arg.getSemantics()))
1601 return ilogb(Arg.U.Double);
1602 llvm_unreachable("Unexpected semantics");
1603}
1604
1605/// Returns: X * 2^Exp for integral exponents.
1607 if (APFloat::usesLayout<detail::IEEEFloat>(X.getSemantics()))
1608 return APFloat(scalbn(X.U.IEEE, Exp, RM), X.getSemantics());
1609 if (APFloat::usesLayout<detail::DoubleAPFloat>(X.getSemantics()))
1610 return APFloat(scalbn(X.U.Double, Exp, RM), X.getSemantics());
1611 llvm_unreachable("Unexpected semantics");
1612}
1613
1614/// Equivalent of C standard library function.
1615///
1616/// While the C standard says Exp is an unspecified value for infinity and nan,
1617/// this returns INT_MAX for infinities, and INT_MIN for NaNs.
1618inline APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM) {
1619 if (APFloat::usesLayout<detail::IEEEFloat>(X.getSemantics()))
1620 return APFloat(frexp(X.U.IEEE, Exp, RM), X.getSemantics());
1621 if (APFloat::usesLayout<detail::DoubleAPFloat>(X.getSemantics()))
1622 return APFloat(frexp(X.U.Double, Exp, RM), X.getSemantics());
1623 llvm_unreachable("Unexpected semantics");
1624}
1625/// Returns the absolute value of the argument.
1627 X.clearSign();
1628 return X;
1629}
1630
1631/// Returns the negated value of the argument.
1633 X.changeSign();
1634 return X;
1635}
1636
1637/// Implements IEEE-754 2008 minNum semantics. Returns the smaller of the
1638/// 2 arguments if both are not NaN. If either argument is a qNaN, returns the
1639/// other argument. If either argument is sNaN, return a qNaN.
1640/// -0 is treated as ordered less than +0.
1642inline APFloat minnum(const APFloat &A, const APFloat &B) {
1643 if (A.isSignaling())
1644 return A.makeQuiet();
1645 if (B.isSignaling())
1646 return B.makeQuiet();
1647 if (A.isNaN())
1648 return B;
1649 if (B.isNaN())
1650 return A;
1651 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1652 return A.isNegative() ? A : B;
1653 return B < A ? B : A;
1654}
1655
1656/// Implements IEEE-754 2008 maxNum semantics. Returns the larger of the
1657/// 2 arguments if both are not NaN. If either argument is a qNaN, returns the
1658/// other argument. If either argument is sNaN, return a qNaN.
1659/// +0 is treated as ordered greater than -0.
1661inline APFloat maxnum(const APFloat &A, const APFloat &B) {
1662 if (A.isSignaling())
1663 return A.makeQuiet();
1664 if (B.isSignaling())
1665 return B.makeQuiet();
1666 if (A.isNaN())
1667 return B;
1668 if (B.isNaN())
1669 return A;
1670 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1671 return A.isNegative() ? B : A;
1672 return A < B ? B : A;
1673}
1674
1675/// Implements IEEE 754-2019 minimum semantics. Returns the smaller of 2
1676/// arguments, returning a quiet NaN if an argument is a NaN and treating -0
1677/// as less than +0.
1679inline APFloat minimum(const APFloat &A, const APFloat &B) {
1680 if (A.isNaN())
1681 return A.makeQuiet();
1682 if (B.isNaN())
1683 return B.makeQuiet();
1684 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1685 return A.isNegative() ? A : B;
1686 return B < A ? B : A;
1687}
1688
1689/// Implements IEEE 754-2019 minimumNumber semantics. Returns the smaller
1690/// of 2 arguments, not propagating NaNs and treating -0 as less than +0.
1692inline APFloat minimumnum(const APFloat &A, const APFloat &B) {
1693 if (A.isNaN())
1694 return B.isNaN() ? B.makeQuiet() : B;
1695 if (B.isNaN())
1696 return A;
1697 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1698 return A.isNegative() ? A : B;
1699 return B < A ? B : A;
1700}
1701
1702/// Implements IEEE 754-2019 maximum semantics. Returns the larger of 2
1703/// arguments, returning a quiet NaN if an argument is a NaN and treating -0
1704/// as less than +0.
1706inline APFloat maximum(const APFloat &A, const APFloat &B) {
1707 if (A.isNaN())
1708 return A.makeQuiet();
1709 if (B.isNaN())
1710 return B.makeQuiet();
1711 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1712 return A.isNegative() ? B : A;
1713 return A < B ? B : A;
1714}
1715
1716/// Implements IEEE 754-2019 maximumNumber semantics. Returns the larger
1717/// of 2 arguments, not propagating NaNs and treating -0 as less than +0.
1719inline APFloat maximumnum(const APFloat &A, const APFloat &B) {
1720 if (A.isNaN())
1721 return B.isNaN() ? B.makeQuiet() : B;
1722 if (B.isNaN())
1723 return A;
1724 if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1725 return A.isNegative() ? B : A;
1726 return A < B ? B : A;
1727}
1728
1730 V.print(OS);
1731 return OS;
1732}
1733
1734// We want the following functions to be available in the header for inlining.
1735// We cannot define them inline in the class definition of `DoubleAPFloat`
1736// because doing so would instantiate `std::unique_ptr<APFloat[]>` before
1737// `APFloat` is defined, and that would be undefined behavior.
1738namespace detail {
1739
1741 if (this != &RHS) {
1742 this->~DoubleAPFloat();
1743 new (this) DoubleAPFloat(std::move(RHS));
1744 }
1745 return *this;
1746}
1747
1748APFloat &DoubleAPFloat::getFirst() { return Floats[0]; }
1749const APFloat &DoubleAPFloat::getFirst() const { return Floats[0]; }
1750APFloat &DoubleAPFloat::getSecond() { return Floats[1]; }
1751const APFloat &DoubleAPFloat::getSecond() const { return Floats[1]; }
1752
1753inline DoubleAPFloat::~DoubleAPFloat() { delete[] Floats; }
1754
1755} // namespace detail
1756
1757} // namespace llvm
1758
1759#undef APFLOAT_DISPATCH_ON_SEMANTICS
1760#endif // LLVM_ADT_APFLOAT_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL)
Definition APFloat.h:26
This file implements a class to represent arbitrary precision integral constant values and operations...
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 TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
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:296
static const fltSemantics & Float8E4M3FN()
Definition APFloat.h:306
static LLVM_ABI const llvm::fltSemantics & EnumToSemantics(Semantics S)
Definition APFloat.cpp:97
static LLVM_ABI bool semanticsHasInf(const fltSemantics &)
Definition APFloat.cpp:246
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
Definition APFloat.h:334
static constexpr roundingMode rmTowardZero
Definition APFloat.h:348
static LLVM_ABI ExponentType semanticsMinExponent(const fltSemantics &)
Definition APFloat.cpp:221
llvm::RoundingMode roundingMode
IEEE-754R 4.3: Rounding-direction attributes.
Definition APFloat.h:342
static const fltSemantics & BFloat()
Definition APFloat.h:295
static const fltSemantics & IEEEquad()
Definition APFloat.h:298
static LLVM_ABI unsigned int semanticsSizeInBits(const fltSemantics &)
Definition APFloat.cpp:224
static const fltSemantics & Float8E8M0FNU()
Definition APFloat.h:313
static LLVM_ABI bool semanticsHasSignedRepr(const fltSemantics &)
Definition APFloat.cpp:242
static const fltSemantics & IEEEdouble()
Definition APFloat.h:297
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:277
static const fltSemantics & x87DoubleExtended()
Definition APFloat.h:317
static constexpr roundingMode rmTowardNegative
Definition APFloat.h:347
uninitializedTag
Convenience enum used to construct an uninitialized APFloat.
Definition APFloat.h:378
static constexpr roundingMode rmNearestTiesToEven
Definition APFloat.h:344
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:6080
static LLVM_ABI bool hasSignBitInMSB(const fltSemantics &)
Definition APFloat.cpp:259
static LLVM_ABI ExponentType semanticsMaxExponent(const fltSemantics &)
Definition APFloat.cpp:217
friend class APFloat
Definition APFloat.h:291
static const fltSemantics & Bogus()
A Pseudo fltsemantic used to construct APFloats that cannot conflict with anything real.
Definition APFloat.h:323
static LLVM_ABI unsigned int semanticsPrecision(const fltSemantics &)
Definition APFloat.cpp:213
static LLVM_ABI bool semanticsHasNaN(const fltSemantics &)
Definition APFloat.cpp:250
static LLVM_ABI Semantics SemanticsToEnum(const llvm::fltSemantics &Sem)
Definition APFloat.cpp:144
int32_t ExponentType
A signed type to represent a floating point numbers unbiased exponent.
Definition APFloat.h:155
static constexpr unsigned integerPartWidth
Definition APFloat.h:152
static const fltSemantics & PPCDoubleDoubleLegacy()
Definition APFloat.h:300
APInt::WordType integerPart
Definition APFloat.h:151
static LLVM_ABI bool semanticsHasZero(const fltSemantics &)
Definition APFloat.cpp:238
static LLVM_ABI bool isRepresentableAsNormalIn(const fltSemantics &Src, const fltSemantics &Dst)
Definition APFloat.cpp:263
static const fltSemantics & Float8E5M2FNUZ()
Definition APFloat.h:304
static const fltSemantics & Float8E4M3FNUZ()
Definition APFloat.h:307
static constexpr roundingMode rmTowardPositive
Definition APFloat.h:346
static const fltSemantics & IEEEhalf()
Definition APFloat.h:294
static const fltSemantics & Float4E2M1FN()
Definition APFloat.h:316
static const fltSemantics & Float6E2M3FN()
Definition APFloat.h:315
IlogbErrorKinds
Enumeration of ilogb error results.
Definition APFloat.h:383
static const fltSemantics & Float8E4M3()
Definition APFloat.h:305
static const fltSemantics & Float8E4M3B11FNUZ()
Definition APFloat.h:308
static LLVM_ABI bool isRepresentableBy(const fltSemantics &A, const fltSemantics &B)
Definition APFloat.cpp:189
static const fltSemantics & Float8E3M4()
Definition APFloat.h:311
static LLVM_ABI bool isIEEELikeFP(const fltSemantics &)
Definition APFloat.cpp:254
static const fltSemantics & Float8E5M2()
Definition APFloat.h:303
fltCategory
Category of internally-represented number.
Definition APFloat.h:370
static constexpr roundingMode rmNearestTiesToAway
Definition APFloat.h:349
static const fltSemantics & PPCDoubleDouble()
Definition APFloat.h:299
static const fltSemantics & Float6E3M2FN()
Definition APFloat.h:314
opStatus
IEEE-754R 7: Default exception handling.
Definition APFloat.h:360
static const fltSemantics & FloatTF32()
Definition APFloat.h:312
static LLVM_ABI unsigned int semanticsIntSizeInBits(const fltSemantics &, bool)
Definition APFloat.cpp:227
static APFloat getQNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for QNaN values.
Definition APFloat.h:1183
static APFloat getSNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for SNaN values.
Definition APFloat.h:1191
opStatus divide(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1271
APFloat & operator=(APFloat &&RHS)=default
bool isFiniteNonZero() const
Definition APFloat.h:1522
APFloat(const APFloat &RHS)=default
void copySign(const APFloat &RHS)
Definition APFloat.h:1365
LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Definition APFloat.cpp:5975
LLVM_READONLY int getExactLog2Abs() const
Definition APFloat.h:1560
opStatus subtract(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1253
bool bitwiseIsEqual(const APFloat &RHS) const
Definition APFloat.h:1477
bool isNegative() const
Definition APFloat.h:1512
~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:5917
APFloat operator+(const APFloat &RHS) const
Add two APFloats, rounding ties to the nearest even.
Definition APFloat.h:1330
friend DoubleAPFloat
Definition APFloat.h:1576
LLVM_ABI double convertToDouble() const
Converts this APFloat to host double value.
Definition APFloat.cpp:6034
bool isPosInfinity() const
Definition APFloat.h:1525
APFloat(APFloat &&RHS)=default
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
Definition APFloat.h:1541
bool isNormal() const
Definition APFloat.h:1516
bool isDenormal() const
Definition APFloat.h:1513
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:1495
opStatus add(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1244
LLVM_READONLY int getExactLog2() const
Definition APFloat.h:1567
APFloat(double d)
Definition APFloat.h:1130
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:6001
LLVM_ABI friend hash_code hash_value(const APFloat &Arg)
See friend declarations above.
Definition APFloat.cpp:5889
APFloat(const fltSemantics &Semantics, integerPart I)
Definition APFloat.h:1122
bool operator!=(const APFloat &RHS) const
Definition APFloat.h:1445
APFloat(const fltSemantics &Semantics, T V)=delete
const fltSemantics & getSemantics() const
Definition APFloat.h:1520
APFloat operator-(const APFloat &RHS) const
Subtract two APFloats, rounding ties to the nearest even.
Definition APFloat.h:1338
APFloat operator*(const APFloat &RHS) const
Multiply two APFloats, rounding ties to the nearest even.
Definition APFloat.h:1346
APFloat(const fltSemantics &Semantics)
Definition APFloat.h:1120
bool isNonZero() const
Definition APFloat.h:1521
void clearSign()
Definition APFloat.h:1361
bool operator<(const APFloat &RHS) const
Definition APFloat.h:1447
bool isFinite() const
Definition APFloat.h:1517
APFloat makeQuiet() const
Assuming this is an IEEE-754 NaN value, quiet its signaling bit.
Definition APFloat.h:1379
bool isNaN() const
Definition APFloat.h:1510
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
Definition APFloat.h:1410
static APFloat getOne(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative One.
Definition APFloat.h:1151
unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
Definition APFloat.h:1502
opStatus multiply(const APFloat &RHS, roundingMode RM)
Definition APFloat.h:1262
LLVM_ABI float convertToFloat() const
Converts this APFloat to host float value.
Definition APFloat.cpp:6065
bool isSignaling() const
Definition APFloat.h:1514
bool operator>(const APFloat &RHS) const
Definition APFloat.h:1451
opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend, roundingMode RM)
Definition APFloat.h:1298
APFloat operator/(const APFloat &RHS) const
Divide the first APFloat by the second, rounding ties to the nearest even.
Definition APFloat.h:1354
opStatus remainder(const APFloat &RHS)
Definition APFloat.h:1280
APFloat operator-() const
Negate an APFloat.
Definition APFloat.h:1322
bool isZero() const
Definition APFloat.h:1508
static APFloat getSmallestNormalized(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
Definition APFloat.h:1221
APInt bitcastToAPInt() const
Definition APFloat.h:1416
bool isLargest() const
Definition APFloat.h:1528
friend APFloat frexp(const APFloat &X, int &Exp, roundingMode RM)
bool isSmallest() const
Definition APFloat.h:1527
static APFloat getLargest(const fltSemantics &Sem, bool Negative=false)
Returns the largest finite number in the given semantics.
Definition APFloat.h:1201
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
Definition APFloat.h:1395
opStatus next(bool nextDown)
Definition APFloat.h:1317
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
Definition APFloat.h:1161
friend APFloat scalbn(APFloat X, int Exp, roundingMode RM)
bool operator>=(const APFloat &RHS) const
Definition APFloat.h:1460
bool needsCleanup() const
Definition APFloat.h:1137
static APFloat getSmallest(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) finite number in the given semantics.
Definition APFloat.h:1211
LLVM_ABI FPClassTest classify() const
Return the FPClassTest which will return true for the value.
Definition APFloat.cpp:5904
bool operator==(const APFloat &RHS) const
Definition APFloat.h:1443
opStatus mod(const APFloat &RHS)
Definition APFloat.h:1289
bool isPosZero() const
Definition APFloat.h:1523
friend int ilogb(const APFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
Definition APFloat.h:1597
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
Definition APFloat.cpp:5884
fltCategory getCategory() const
Definition APFloat.h:1519
APFloat(const fltSemantics &Semantics, uninitializedTag)
Definition APFloat.h:1127
bool isInteger() const
Definition APFloat.h:1529
bool isNegInfinity() const
Definition APFloat.h:1526
friend IEEEFloat
Definition APFloat.h:1575
LLVM_DUMP_METHOD void dump() const
Definition APFloat.cpp:6012
bool isNegZero() const
Definition APFloat.h:1524
LLVM_ABI void print(raw_ostream &) const
Definition APFloat.cpp:6005
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:1372
APFloat(float f)
Definition APFloat.h:1131
opStatus roundToIntegral(roundingMode RM)
Definition APFloat.h:1311
void changeSign()
Definition APFloat.h:1360
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
Definition APFloat.h:1172
static bool hasSignificand(const fltSemantics &Sem)
Returns true if the given semantics has actual significand.
Definition APFloat.h:1236
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Definition APFloat.h:1142
cmpResult compare(const APFloat &RHS) const
Definition APFloat.h:1467
bool isSmallestNormalized() const
Definition APFloat.h:1531
APFloat(const fltSemantics &Semantics, const APInt &I)
Definition APFloat.h:1129
bool isInfinity() const
Definition APFloat.h:1509
bool operator<=(const APFloat &RHS) const
Definition APFloat.h:1455
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
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition FoldingSet.h:209
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition ArrayRef.h:298
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
LLVM Value Representation.
Definition Value.h:75
LLVM_ABI void makeSmallestNormalized(bool Neg)
Definition APFloat.cpp:5232
LLVM_ABI DoubleAPFloat & operator=(const DoubleAPFloat &RHS)
Definition APFloat.cpp:4762
LLVM_ABI void changeSign()
Definition APFloat.cpp:5139
LLVM_ABI bool isLargest() const
Definition APFloat.cpp:5706
LLVM_ABI opStatus remainder(const DoubleAPFloat &RHS)
Definition APFloat.cpp:5026
LLVM_ABI opStatus multiply(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:4929
LLVM_ABI fltCategory getCategory() const
Definition APFloat.cpp:5198
LLVM_ABI bool bitwiseIsEqual(const DoubleAPFloat &RHS) const
Definition APFloat.cpp:5255
LLVM_ABI LLVM_READONLY int getExactLog2Abs() const
Definition APFloat.cpp:5730
LLVM_ABI opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
Definition APFloat.cpp:5657
LLVM_ABI APInt bitcastToAPInt() const
Definition APFloat.cpp:5266
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
Definition APFloat.cpp:5276
LLVM_ABI bool isSmallest() const
Definition APFloat.cpp:5689
LLVM_ABI opStatus subtract(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:4921
LLVM_ABI friend hash_code hash_value(const DoubleAPFloat &Arg)
Definition APFloat.cpp:5260
LLVM_ABI cmpResult compareAbsoluteValue(const DoubleAPFloat &RHS) const
Definition APFloat.cpp:5145
LLVM_ABI bool isDenormal() const
Definition APFloat.cpp:5682
LLVM_ABI opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
Definition APFloat.cpp:5493
LLVM_ABI void makeSmallest(bool Neg)
Definition APFloat.cpp:5225
LLVM_ABI friend int ilogb(const DoubleAPFloat &X)
Definition APFloat.cpp:5739
LLVM_ABI opStatus next(bool nextDown)
Definition APFloat.cpp:5292
LLVM_ABI void makeInf(bool Neg)
Definition APFloat.cpp:5204
LLVM_ABI bool isInteger() const
Definition APFloat.cpp:5714
LLVM_ABI void makeZero(bool Neg)
Definition APFloat.cpp:5209
LLVM_ABI opStatus divide(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:5015
LLVM_ABI bool isSmallestNormalized() const
Definition APFloat.cpp:5697
LLVM_ABI opStatus mod(const DoubleAPFloat &RHS)
Definition APFloat.cpp:5036
LLVM_ABI DoubleAPFloat(const fltSemantics &S)
Definition APFloat.cpp:4709
LLVM_ABI void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision, unsigned FormatMaxPadding, bool TruncateZero=true) const
Definition APFloat.cpp:5720
LLVM_ABI void makeLargest(bool Neg)
Definition APFloat.cpp:5214
LLVM_ABI cmpResult compare(const DoubleAPFloat &RHS) const
Definition APFloat.cpp:5247
LLVM_ABI friend DoubleAPFloat scalbn(const DoubleAPFloat &X, int Exp, roundingMode)
LLVM_ABI opStatus roundToIntegral(roundingMode RM)
Definition APFloat.cpp:5062
LLVM_ABI opStatus fusedMultiplyAdd(const DoubleAPFloat &Multiplicand, const DoubleAPFloat &Addend, roundingMode RM)
Definition APFloat.cpp:5047
LLVM_ABI unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
Definition APFloat.cpp:5672
bool needsCleanup() const
Definition APFloat.h:871
LLVM_ABI bool isNegative() const
Definition APFloat.cpp:5202
LLVM_ABI opStatus add(const DoubleAPFloat &RHS, roundingMode RM)
Definition APFloat.cpp:4916
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:5242
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:3246
LLVM_ABI cmpResult compareAbsoluteValue(const IEEEFloat &) const
Definition APFloat.cpp:1464
LLVM_ABI opStatus mod(const IEEEFloat &)
C fmod, or llvm frem.
Definition APFloat.cpp:2235
fltCategory getCategory() const
Definition APFloat.h:578
LLVM_ABI opStatus convertFromAPInt(const APInt &, bool, roundingMode)
Definition APFloat.cpp:2804
bool isNonZero() const
Definition APFloat.h:580
bool isFiniteNonZero() const
Definition APFloat.h:581
bool needsCleanup() const
Returns whether this instance allocated memory.
Definition APFloat.h:468
LLVM_ABI void makeLargest(bool Neg=false)
Make this number the largest magnitude normal number in the given semantics.
Definition APFloat.cpp:4031
LLVM_ABI LLVM_READONLY int getExactLog2Abs() const
Definition APFloat.cpp:4426
LLVM_ABI APInt bitcastToAPInt() const
Definition APFloat.cpp:3656
LLVM_ABI friend IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
Definition APFloat.cpp:4669
LLVM_ABI cmpResult compare(const IEEEFloat &) const
IEEE comparison with another floating point number (NaNs compare unordered, 0==-0).
Definition APFloat.cpp:2406
bool isNegative() const
IEEE-754R isSignMinus: Returns true if and only if the current value is negative.
Definition APFloat.h:543
LLVM_ABI opStatus divide(const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2105
LLVM_ABI friend hash_code hash_value(const IEEEFloat &Arg)
Overload to compute a hash code for an APFloat value.
Definition APFloat.cpp:3394
bool isNaN() const
Returns true if and only if the float is a quiet or signaling NaN.
Definition APFloat.h:568
LLVM_ABI opStatus remainder(const IEEEFloat &)
IEEE remainder.
Definition APFloat.cpp:2125
LLVM_ABI double convertToDouble() const
Definition APFloat.cpp:3726
LLVM_ABI float convertToFloat() const
Definition APFloat.cpp:3719
LLVM_ABI opStatus subtract(const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2079
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:4382
LLVM_ABI void makeSmallest(bool Neg=false)
Make this number the smallest magnitude denormal number in the given semantics.
Definition APFloat.cpp:4063
LLVM_ABI void makeInf(bool Neg=false)
Definition APFloat.cpp:4616
bool isNormal() const
IEEE-754R isNormal: Returns true if and only if the current value is normal.
Definition APFloat.h:549
LLVM_ABI bool isSmallestNormalized() const
Returns true if this is the smallest (by magnitude) normalized finite number in the given semantics.
Definition APFloat.cpp:964
friend class IEEEFloatUnitTestHelper
Definition APFloat.h:821
LLVM_ABI void makeQuiet()
Definition APFloat.cpp:4645
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:1066
LLVM_ABI opStatus add(const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2073
bool isFinite() const
Returns true if and only if the current value is zero, subnormal, or normal.
Definition APFloat.h:555
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
Definition APFloat.cpp:3189
LLVM_ABI void makeNaN(bool SNaN=false, bool Neg=false, const APInt *fill=nullptr)
Definition APFloat.cpp:853
LLVM_ABI opStatus multiply(const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2085
LLVM_ABI opStatus roundToIntegral(roundingMode)
Definition APFloat.cpp:2319
LLVM_ABI IEEEFloat & operator=(const IEEEFloat &)
Definition APFloat.cpp:925
LLVM_ABI bool bitwiseIsEqual(const IEEEFloat &) const
Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
Definition APFloat.cpp:1091
LLVM_ABI void makeSmallestNormalized(bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
Definition APFloat.cpp:4077
LLVM_ABI bool isInteger() const
Returns true if and only if the number is an exact integer.
Definition APFloat.cpp:1083
bool isPosZero() const
Definition APFloat.h:582
LLVM_ABI IEEEFloat(const fltSemantics &)
Definition APFloat.cpp:1118
LLVM_ABI opStatus fusedMultiplyAdd(const IEEEFloat &, const IEEEFloat &, roundingMode)
Definition APFloat.cpp:2273
LLVM_ABI friend int ilogb(const IEEEFloat &Arg)
Definition APFloat.cpp:4651
LLVM_ABI opStatus next(bool nextDown)
IEEE-754R 5.3.1: nextUp/nextDown.
Definition APFloat.cpp:4471
bool isInfinity() const
IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
Definition APFloat.h:565
const fltSemantics & getSemantics() const
Definition APFloat.h:579
bool isZero() const
Returns true if and only if the float is plus or minus zero.
Definition APFloat.h:558
LLVM_ABI bool isSignaling() const
Returns true if and only if the float is a signaling NaN.
Definition APFloat.cpp:4455
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:4631
LLVM_ABI opStatus convert(const fltSemantics &, roundingMode, bool *)
IEEEFloat::convert - convert a value of one floating point type to another.
Definition APFloat.cpp:2483
LLVM_ABI void changeSign()
Definition APFloat.cpp:2029
LLVM_ABI bool isDenormal() const
IEEE-754R isSubnormal(): Returns true if and only if the float is a denormal.
Definition APFloat.cpp:950
LLVM_ABI opStatus convertToInteger(MutableArrayRef< integerPart >, unsigned int, bool, roundingMode, bool *) const
Definition APFloat.cpp:2744
LLVM_ABI friend IEEEFloat frexp(const IEEEFloat &X, int &Exp, roundingMode)
Definition APFloat.cpp:4690
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:956
bool isNegZero() const
Definition APFloat.h:583
An opaque object representing a hash code.
Definition Hashing.h:76
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:444
static constexpr fltCategory fcNaN
Definition APFloat.h:446
static constexpr opStatus opDivByZero
Definition APFloat.h:441
static constexpr opStatus opOverflow
Definition APFloat.h:442
static constexpr cmpResult cmpLessThan
Definition APFloat.h:436
static constexpr roundingMode rmTowardPositive
Definition APFloat.h:432
static constexpr uninitializedTag uninitialized
Definition APFloat.h:426
static constexpr fltCategory fcZero
Definition APFloat.h:448
static constexpr opStatus opOK
Definition APFloat.h:439
static constexpr cmpResult cmpGreaterThan
Definition APFloat.h:437
static constexpr unsigned integerPartWidth
Definition APFloat.h:434
LLVM_ABI hash_code hash_value(const IEEEFloat &Arg)
Definition APFloat.cpp:3394
APFloatBase::ExponentType ExponentType
Definition APFloat.h:425
APFloatBase::fltCategory fltCategory
Definition APFloat.h:424
static constexpr fltCategory fcNormal
Definition APFloat.h:447
static constexpr opStatus opInvalidOp
Definition APFloat.h:440
APFloatBase::opStatus opStatus
Definition APFloat.h:422
LLVM_ABI IEEEFloat frexp(const IEEEFloat &Val, int &Exp, roundingMode RM)
Definition APFloat.cpp:4690
APFloatBase::uninitializedTag uninitializedTag
Definition APFloat.h:420
static constexpr cmpResult cmpUnordered
Definition APFloat.h:438
static constexpr roundingMode rmTowardNegative
Definition APFloat.h:431
APFloatBase::roundingMode roundingMode
Definition APFloat.h:421
APFloatBase::cmpResult cmpResult
Definition APFloat.h:423
static constexpr fltCategory fcInfinity
Definition APFloat.h:445
static constexpr roundingMode rmNearestTiesToAway
Definition APFloat.h:429
static constexpr roundingMode rmTowardZero
Definition APFloat.h:433
static constexpr opStatus opUnderflow
Definition APFloat.h:443
static constexpr roundingMode rmNearestTiesToEven
Definition APFloat.h:427
LLVM_ABI int ilogb(const IEEEFloat &Arg)
Definition APFloat.cpp:4651
static constexpr cmpResult cmpEqual
Definition APFloat.h:435
LLVM_ABI IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
Definition APFloat.cpp:4669
APFloatBase::integerPart integerPart
Definition APFloat.h:419
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
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:1757
hash_code hash_value(const FixedPointSemantics &Val)
static constexpr APFloatBase::ExponentType exponentZero(const fltSemantics &semantics)
Definition APFloat.cpp:282
APFloat abs(APFloat X)
Returns the absolute value of the argument.
Definition APFloat.h:1626
LLVM_READONLY APFloat maximum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 maximum semantics.
Definition APFloat.h:1706
int ilogb(const APFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
Definition APFloat.h:1597
APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM)
Equivalent of C standard library function.
Definition APFloat.h:1618
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE-754 2008 maxNum semantics.
Definition APFloat.h:1661
lostFraction
Enum that represents what fraction of the LSB truncated bits of an fp number represent.
Definition APFloat.h:50
@ lfMoreThanHalf
Definition APFloat.h:54
@ lfLessThanHalf
Definition APFloat.h:52
@ lfExactlyHalf
Definition APFloat.h:53
@ lfExactlyZero
Definition APFloat.h:51
LLVM_READONLY APFloat minimumnum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 minimumNumber semantics.
Definition APFloat.h:1692
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:1606
static constexpr APFloatBase::ExponentType exponentNaN(const fltSemantics &semantics)
Definition APFloat.cpp:292
@ 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:1642
fltNonfiniteBehavior
Definition APFloat.h:944
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:287
APFloat neg(APFloat X)
Returns the negated value of the argument.
Definition APFloat.h:1632
LLVM_READONLY APFloat minimum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 minimum semantics.
Definition APFloat.h:1679
LLVM_READONLY APFloat maximumnum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 maximumNumber semantics.
Definition APFloat.h:1719
fltNanEncoding
Definition APFloat.h:968
APFloatBase::ExponentType maxExponent
Definition APFloat.h:992
fltNonfiniteBehavior nonFiniteBehavior
Definition APFloat.h:1005
APFloatBase::ExponentType minExponent
Definition APFloat.h:996
unsigned int sizeInBits
Definition APFloat.h:1003
unsigned int precision
Definition APFloat.h:1000
fltNanEncoding nanEncoding
Definition APFloat.h:1007