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