LLVM  17.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"
22 #include <memory>
23 
24 #define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL) \
25  do { \
26  if (usesLayout<IEEEFloat>(getSemantics())) \
27  return U.IEEE.METHOD_CALL; \
28  if (usesLayout<DoubleAPFloat>(getSemantics())) \
29  return U.Double.METHOD_CALL; \
30  llvm_unreachable("Unexpected semantics"); \
31  } while (false)
32 
33 namespace llvm {
34 
35 struct fltSemantics;
36 class APSInt;
37 class StringRef;
38 class APFloat;
39 class raw_ostream;
40 
41 template <typename T> class Expected;
42 template <typename T> class SmallVectorImpl;
43 
44 /// Enum that represents what fraction of the LSB truncated bits of an fp number
45 /// represent.
46 ///
47 /// This essentially combines the roles of guard and sticky bits.
48 enum lostFraction { // Example of truncated bits:
49  lfExactlyZero, // 000000
50  lfLessThanHalf, // 0xxxxx x's not all zero
51  lfExactlyHalf, // 100000
52  lfMoreThanHalf // 1xxxxx x's not all zero
53 };
54 
55 /// A self-contained host- and target-independent arbitrary-precision
56 /// floating-point software implementation.
57 ///
58 /// APFloat uses bignum integer arithmetic as provided by static functions in
59 /// the APInt class. The library will work with bignum integers whose parts are
60 /// any unsigned type at least 16 bits wide, but 64 bits is recommended.
61 ///
62 /// Written for clarity rather than speed, in particular with a view to use in
63 /// the front-end of a cross compiler so that target arithmetic can be correctly
64 /// performed on the host. Performance should nonetheless be reasonable,
65 /// particularly for its intended use. It may be useful as a base
66 /// implementation for a run-time library during development of a faster
67 /// target-specific one.
68 ///
69 /// All 5 rounding modes in the IEEE-754R draft are handled correctly for all
70 /// implemented operations. Currently implemented operations are add, subtract,
71 /// multiply, divide, fused-multiply-add, conversion-to-float,
72 /// conversion-to-integer and conversion-from-integer. New rounding modes
73 /// (e.g. away from zero) can be added with three or four lines of code.
74 ///
75 /// Four formats are built-in: IEEE single precision, double precision,
76 /// quadruple precision, and x87 80-bit extended double (when operating with
77 /// full extended precision). Adding a new format that obeys IEEE semantics
78 /// only requires adding two lines of code: a declaration and definition of the
79 /// format.
80 ///
81 /// All operations return the status of that operation as an exception bit-mask,
82 /// so multiple operations can be done consecutively with their results or-ed
83 /// together. The returned status can be useful for compiler diagnostics; e.g.,
84 /// inexact, underflow and overflow can be easily diagnosed on constant folding,
85 /// and compiler optimizers can determine what exceptions would be raised by
86 /// folding operations and optimize, or perhaps not optimize, accordingly.
87 ///
88 /// At present, underflow tininess is detected after rounding; it should be
89 /// straight forward to add support for the before-rounding case too.
90 ///
91 /// The library reads hexadecimal floating point numbers as per C99, and
92 /// correctly rounds if necessary according to the specified rounding mode.
93 /// Syntax is required to have been validated by the caller. It also converts
94 /// floating point numbers to hexadecimal text as per the C99 %a and %A
95 /// conversions. The output precision (or alternatively the natural minimal
96 /// precision) can be specified; if the requested precision is less than the
97 /// natural precision the output is correctly rounded for the specified rounding
98 /// mode.
99 ///
100 /// It also reads decimal floating point numbers and correctly rounds according
101 /// to the specified rounding mode.
102 ///
103 /// Conversion to decimal text is not currently implemented.
104 ///
105 /// Non-zero finite numbers are represented internally as a sign bit, a 16-bit
106 /// signed exponent, and the significand as an array of integer parts. After
107 /// normalization of a number of precision P the exponent is within the range of
108 /// the format, and if the number is not denormal the P-th bit of the
109 /// significand is set as an explicit integer bit. For denormals the most
110 /// significant bit is shifted right so that the exponent is maintained at the
111 /// format's minimum, so that the smallest denormal has just the least
112 /// significant bit of the significand set. The sign of zeroes and infinities
113 /// is significant; the exponent and significand of such numbers is not stored,
114 /// but has a known implicit (deterministic) value: 0 for the significands, 0
115 /// for zero exponent, all 1 bits for infinity exponent. For NaNs the sign and
116 /// significand are deterministic, although not really meaningful, and preserved
117 /// in non-conversion operations. The exponent is implicitly all 1 bits.
118 ///
119 /// APFloat does not provide any exception handling beyond default exception
120 /// handling. We represent Signaling NaNs via IEEE-754R 2008 6.2.1 should clause
121 /// by encoding Signaling NaNs with the first bit of its trailing significand as
122 /// 0.
123 ///
124 /// TODO
125 /// ====
126 ///
127 /// Some features that may or may not be worth adding:
128 ///
129 /// Binary to decimal conversion (hard).
130 ///
131 /// Optional ability to detect underflow tininess before rounding.
132 ///
133 /// New formats: x87 in single and double precision mode (IEEE apart from
134 /// extended exponent range) (hard).
135 ///
136 /// New operations: sqrt, IEEE remainder, C90 fmod, nexttoward.
137 ///
138 
139 // This is the common type definitions shared by APFloat and its internal
140 // implementation classes. This struct should not define any non-static data
141 // members.
142 struct APFloatBase {
144  static constexpr unsigned integerPartWidth = APInt::APINT_BITS_PER_WORD;
145 
146  /// A signed type to represent a floating point numbers unbiased exponent.
147  typedef int32_t ExponentType;
148 
149  /// \name Floating Point Semantics.
150  /// @{
151  enum Semantics {
158  // 8-bit floating point number following IEEE-754 conventions with bit
159  // layout S1E5M2 as described in https://arxiv.org/abs/2209.05433.
161  // 8-bit floating point number mostly following IEEE-754 conventions with
162  // bit layout S1E4M3 as described in https://arxiv.org/abs/2209.05433.
163  // Unlike IEEE-754 types, there are no infinity values, and NaN is
164  // represented with the exponent and mantissa bits set to all 1s.
168  };
169 
171  static Semantics SemanticsToEnum(const llvm::fltSemantics &Sem);
172 
173  static const fltSemantics &IEEEhalf() LLVM_READNONE;
182 
183  /// A Pseudo fltsemantic used to construct APFloats that cannot conflict with
184  /// anything real.
186 
187  /// @}
188 
189  /// IEEE-754R 5.11: Floating Point Comparison Relations.
190  enum cmpResult {
195  };
196 
197  /// IEEE-754R 4.3: Rounding-direction attributes.
199 
207 
208  /// IEEE-754R 7: Default exception handling.
209  ///
210  /// opUnderflow or opOverflow are always returned or-ed with opInexact.
211  ///
212  /// APFloat models this behavior specified by IEEE-754:
213  /// "For operations producing results in floating-point format, the default
214  /// result of an operation that signals the invalid operation exception
215  /// shall be a quiet NaN."
216  enum opStatus {
217  opOK = 0x00,
218  opInvalidOp = 0x01,
219  opDivByZero = 0x02,
220  opOverflow = 0x04,
221  opUnderflow = 0x08,
222  opInexact = 0x10
223  };
224 
225  /// Category of internally-represented number.
226  enum fltCategory {
231  };
232 
233  /// Convenience enum used to construct an uninitialized APFloat.
236  };
237 
238  /// Enumeration of \c ilogb error results.
240  IEK_Zero = INT_MIN + 1,
241  IEK_NaN = INT_MIN,
242  IEK_Inf = INT_MAX
243  };
244 
245  static unsigned int semanticsPrecision(const fltSemantics &);
248  static unsigned int semanticsSizeInBits(const fltSemantics &);
249 
250  /// Returns the size of the floating point number (in bits) in the given
251  /// semantics.
252  static unsigned getSizeInBits(const fltSemantics &Sem);
253 };
254 
255 namespace detail {
256 
257 class IEEEFloat final : public APFloatBase {
258 public:
259  /// \name Constructors
260  /// @{
261 
262  IEEEFloat(const fltSemantics &); // Default construct to +0.0
265  IEEEFloat(const fltSemantics &, const APInt &);
266  explicit IEEEFloat(double d);
267  explicit IEEEFloat(float f);
268  IEEEFloat(const IEEEFloat &);
269  IEEEFloat(IEEEFloat &&);
270  ~IEEEFloat();
271 
272  /// @}
273 
274  /// Returns whether this instance allocated memory.
275  bool needsCleanup() const { return partCount() > 1; }
276 
277  /// \name Convenience "constructors"
278  /// @{
279 
280  /// @}
281 
282  /// \name Arithmetic
283  /// @{
284 
289  /// IEEE remainder.
290  opStatus remainder(const IEEEFloat &);
291  /// C fmod, or llvm frem.
292  opStatus mod(const IEEEFloat &);
295  /// IEEE-754R 5.3.1: nextUp/nextDown.
296  opStatus next(bool nextDown);
297 
298  /// @}
299 
300  /// \name Sign operations.
301  /// @{
302 
303  void changeSign();
304 
305  /// @}
306 
307  /// \name Conversions
308  /// @{
309 
310  opStatus convert(const fltSemantics &, roundingMode, bool *);
312  roundingMode, bool *) const;
315  bool, roundingMode);
317  bool, roundingMode);
319  APInt bitcastToAPInt() const;
320  double convertToDouble() const;
321  float convertToFloat() const;
322 
323  /// @}
324 
325  /// The definition of equality is not straightforward for floating point, so
326  /// we won't use operator==. Use one of the following, or write whatever it
327  /// is you really mean.
328  bool operator==(const IEEEFloat &) const = delete;
329 
330  /// IEEE comparison with another floating point number (NaNs compare
331  /// unordered, 0==-0).
332  cmpResult compare(const IEEEFloat &) const;
333 
334  /// Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
335  bool bitwiseIsEqual(const IEEEFloat &) const;
336 
337  /// Write out a hexadecimal representation of the floating point value to DST,
338  /// which must be of sufficient size, in the C99 form [-]0xh.hhhhp[+-]d.
339  /// Return the number of characters written, excluding the terminating NUL.
340  unsigned int convertToHexString(char *dst, unsigned int hexDigits,
341  bool upperCase, roundingMode) const;
342 
343  /// \name IEEE-754R 5.7.2 General operations.
344  /// @{
345 
346  /// IEEE-754R isSignMinus: Returns true if and only if the current value is
347  /// negative.
348  ///
349  /// This applies to zeros and NaNs as well.
350  bool isNegative() const { return sign; }
351 
352  /// IEEE-754R isNormal: Returns true if and only if the current value is normal.
353  ///
354  /// This implies that the current value of the float is not zero, subnormal,
355  /// infinite, or NaN following the definition of normality from IEEE-754R.
356  bool isNormal() const { return !isDenormal() && isFiniteNonZero(); }
357 
358  /// Returns true if and only if the current value is zero, subnormal, or
359  /// normal.
360  ///
361  /// This means that the value is not infinite or NaN.
362  bool isFinite() const { return !isNaN() && !isInfinity(); }
363 
364  /// Returns true if and only if the float is plus or minus zero.
365  bool isZero() const { return category == fcZero; }
366 
367  /// IEEE-754R isSubnormal(): Returns true if and only if the float is a
368  /// denormal.
369  bool isDenormal() const;
370 
371  /// IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
372  bool isInfinity() const { return category == fcInfinity; }
373 
374  /// Returns true if and only if the float is a quiet or signaling NaN.
375  bool isNaN() const { return category == fcNaN; }
376 
377  /// Returns true if and only if the float is a signaling NaN.
378  bool isSignaling() const;
379 
380  /// @}
381 
382  /// \name Simple Queries
383  /// @{
384 
385  fltCategory getCategory() const { return category; }
386  const fltSemantics &getSemantics() const { return *semantics; }
387  bool isNonZero() const { return category != fcZero; }
388  bool isFiniteNonZero() const { return isFinite() && !isZero(); }
389  bool isPosZero() const { return isZero() && !isNegative(); }
390  bool isNegZero() const { return isZero() && isNegative(); }
391 
392  /// Returns true if and only if the number has the smallest possible non-zero
393  /// magnitude in the current semantics.
394  bool isSmallest() const;
395 
396  /// Returns true if this is the smallest (by magnitude) normalized finite
397  /// number in the given semantics.
398  bool isSmallestNormalized() const;
399 
400  /// Returns true if and only if the number has the largest possible finite
401  /// magnitude in the current semantics.
402  bool isLargest() const;
403 
404  /// Returns true if and only if the number is an exact integer.
405  bool isInteger() const;
406 
407  /// @}
408 
409  IEEEFloat &operator=(const IEEEFloat &);
411 
412  /// Overload to compute a hash code for an APFloat value.
413  ///
414  /// Note that the use of hash codes for floating point values is in general
415  /// frought with peril. Equality is hard to define for these values. For
416  /// example, should negative and positive zero hash to different codes? Are
417  /// they equal or not? This hash value implementation specifically
418  /// emphasizes producing different codes for different inputs in order to
419  /// be used in canonicalization and memoization. As such, equality is
420  /// bitwiseIsEqual, and 0 != -0.
421  friend hash_code hash_value(const IEEEFloat &Arg);
422 
423  /// Converts this value into a decimal string.
424  ///
425  /// \param FormatPrecision The maximum number of digits of
426  /// precision to output. If there are fewer digits available,
427  /// zero padding will not be used unless the value is
428  /// integral and small enough to be expressed in
429  /// FormatPrecision digits. 0 means to use the natural
430  /// precision of the number.
431  /// \param FormatMaxPadding The maximum number of zeros to
432  /// consider inserting before falling back to scientific
433  /// notation. 0 means to always use scientific notation.
434  ///
435  /// \param TruncateZero Indicate whether to remove the trailing zero in
436  /// fraction part or not. Also setting this parameter to false forcing
437  /// producing of output more similar to default printf behavior.
438  /// Specifically the lower e is used as exponent delimiter and exponent
439  /// always contains no less than two digits.
440  ///
441  /// Number Precision MaxPadding Result
442  /// ------ --------- ---------- ------
443  /// 1.01E+4 5 2 10100
444  /// 1.01E+4 4 2 1.01E+4
445  /// 1.01E+4 5 1 1.01E+4
446  /// 1.01E-2 5 2 0.0101
447  /// 1.01E-2 4 2 0.0101
448  /// 1.01E-2 4 1 1.01E-2
449  void toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision = 0,
450  unsigned FormatMaxPadding = 3, bool TruncateZero = true) const;
451 
452  /// If this value has an exact multiplicative inverse, store it in inv and
453  /// return true.
454  bool getExactInverse(APFloat *inv) const;
455 
456  /// Returns the exponent of the internal representation of the APFloat.
457  ///
458  /// Because the radix of APFloat is 2, this is equivalent to floor(log2(x)).
459  /// For special APFloat values, this returns special error codes:
460  ///
461  /// NaN -> \c IEK_NaN
462  /// 0 -> \c IEK_Zero
463  /// Inf -> \c IEK_Inf
464  ///
465  friend int ilogb(const IEEEFloat &Arg);
466 
467  /// Returns: X * 2^Exp for integral exponents.
468  friend IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode);
469 
470  friend IEEEFloat frexp(const IEEEFloat &X, int &Exp, roundingMode);
471 
472  /// \name Special value setters.
473  /// @{
474 
475  void makeLargest(bool Neg = false);
476  void makeSmallest(bool Neg = false);
477  void makeNaN(bool SNaN = false, bool Neg = false,
478  const APInt *fill = nullptr);
479  void makeInf(bool Neg = false);
480  void makeZero(bool Neg = false);
481  void makeQuiet();
482 
483  /// Returns the smallest (by magnitude) normalized finite number in the given
484  /// semantics.
485  ///
486  /// \param Negative - True iff the number should be negative
487  void makeSmallestNormalized(bool Negative = false);
488 
489  /// @}
490 
492 
493 private:
494  /// \name Simple Queries
495  /// @{
496 
497  integerPart *significandParts();
498  const integerPart *significandParts() const;
499  unsigned int partCount() const;
500 
501  /// @}
502 
503  /// \name Significand operations.
504  /// @{
505 
506  integerPart addSignificand(const IEEEFloat &);
507  integerPart subtractSignificand(const IEEEFloat &, integerPart);
508  lostFraction addOrSubtractSignificand(const IEEEFloat &, bool subtract);
509  lostFraction multiplySignificand(const IEEEFloat &, IEEEFloat);
510  lostFraction multiplySignificand(const IEEEFloat&);
511  lostFraction divideSignificand(const IEEEFloat &);
512  void incrementSignificand();
513  void initialize(const fltSemantics *);
514  void shiftSignificandLeft(unsigned int);
515  lostFraction shiftSignificandRight(unsigned int);
516  unsigned int significandLSB() const;
517  unsigned int significandMSB() const;
518  void zeroSignificand();
519  /// Return true if the significand excluding the integral bit is all ones.
520  bool isSignificandAllOnes() const;
521  bool isSignificandAllOnesExceptLSB() const;
522  /// Return true if the significand excluding the integral bit is all zeros.
523  bool isSignificandAllZeros() const;
524  bool isSignificandAllZerosExceptMSB() const;
525 
526  /// @}
527 
528  /// \name Arithmetic on special values.
529  /// @{
530 
531  opStatus addOrSubtractSpecials(const IEEEFloat &, bool subtract);
532  opStatus divideSpecials(const IEEEFloat &);
533  opStatus multiplySpecials(const IEEEFloat &);
534  opStatus modSpecials(const IEEEFloat &);
535  opStatus remainderSpecials(const IEEEFloat&);
536 
537  /// @}
538 
539  /// \name Miscellany
540  /// @{
541 
542  bool convertFromStringSpecials(StringRef str);
543  opStatus normalize(roundingMode, lostFraction);
544  opStatus addOrSubtract(const IEEEFloat &, roundingMode, bool subtract);
545  opStatus handleOverflow(roundingMode);
546  bool roundAwayFromZero(roundingMode, lostFraction, unsigned int) const;
547  opStatus convertToSignExtendedInteger(MutableArrayRef<integerPart>,
548  unsigned int, bool, roundingMode,
549  bool *) const;
550  opStatus convertFromUnsignedParts(const integerPart *, unsigned int,
551  roundingMode);
552  Expected<opStatus> convertFromHexadecimalString(StringRef, roundingMode);
553  Expected<opStatus> convertFromDecimalString(StringRef, roundingMode);
554  char *convertNormalToHexString(char *, unsigned int, bool,
555  roundingMode) const;
556  opStatus roundSignificandWithExponent(const integerPart *, unsigned int, int,
557  roundingMode);
558  ExponentType exponentNaN() const;
559  ExponentType exponentInf() const;
560  ExponentType exponentZero() const;
561 
562  /// @}
563 
564  APInt convertHalfAPFloatToAPInt() const;
565  APInt convertBFloatAPFloatToAPInt() const;
566  APInt convertFloatAPFloatToAPInt() const;
567  APInt convertDoubleAPFloatToAPInt() const;
568  APInt convertQuadrupleAPFloatToAPInt() const;
569  APInt convertF80LongDoubleAPFloatToAPInt() const;
570  APInt convertPPCDoubleDoubleAPFloatToAPInt() const;
571  APInt convertFloat8E5M2APFloatToAPInt() const;
572  APInt convertFloat8E4M3FNAPFloatToAPInt() const;
573  void initFromAPInt(const fltSemantics *Sem, const APInt &api);
574  void initFromHalfAPInt(const APInt &api);
575  void initFromBFloatAPInt(const APInt &api);
576  void initFromFloatAPInt(const APInt &api);
577  void initFromDoubleAPInt(const APInt &api);
578  void initFromQuadrupleAPInt(const APInt &api);
579  void initFromF80LongDoubleAPInt(const APInt &api);
580  void initFromPPCDoubleDoubleAPInt(const APInt &api);
581  void initFromFloat8E5M2APInt(const APInt &api);
582  void initFromFloat8E4M3FNAPInt(const APInt &api);
583 
584  void assign(const IEEEFloat &);
585  void copySignificand(const IEEEFloat &);
586  void freeSignificand();
587 
588  /// Note: this must be the first data member.
589  /// The semantics that this value obeys.
590  const fltSemantics *semantics;
591 
592  /// A binary fraction with an explicit integer bit.
593  ///
594  /// The significand must be at least one bit wider than the target precision.
595  union Significand {
596  integerPart part;
597  integerPart *parts;
598  } significand;
599 
600  /// The signed unbiased exponent of the value.
601  ExponentType exponent;
602 
603  /// What kind of floating point number this is.
604  ///
605  /// Only 2 bits are required, but VisualStudio incorrectly sign extends it.
606  /// Using the extra bit keeps it from failing under VisualStudio.
607  fltCategory category : 3;
608 
609  /// Sign bit of the number.
610  unsigned int sign : 1;
611 };
612 
613 hash_code hash_value(const IEEEFloat &Arg);
614 int ilogb(const IEEEFloat &Arg);
615 IEEEFloat scalbn(IEEEFloat X, int Exp, IEEEFloat::roundingMode);
616 IEEEFloat frexp(const IEEEFloat &Val, int &Exp, IEEEFloat::roundingMode RM);
617 
618 // This mode implements more precise float in terms of two APFloats.
619 // The interface and layout is designed for arbitrary underlying semantics,
620 // though currently only PPCDoubleDouble semantics are supported, whose
621 // corresponding underlying semantics are IEEEdouble.
622 class DoubleAPFloat final : public APFloatBase {
623  // Note: this must be the first data member.
624  const fltSemantics *Semantics;
625  std::unique_ptr<APFloat[]> Floats;
626 
627  opStatus addImpl(const APFloat &a, const APFloat &aa, const APFloat &c,
628  const APFloat &cc, roundingMode RM);
629 
630  opStatus addWithSpecial(const DoubleAPFloat &LHS, const DoubleAPFloat &RHS,
632 
633 public:
634  DoubleAPFloat(const fltSemantics &S);
637  DoubleAPFloat(const fltSemantics &S, const APInt &I);
638  DoubleAPFloat(const fltSemantics &S, APFloat &&First, APFloat &&Second);
641 
643 
645  if (this != &RHS) {
646  this->~DoubleAPFloat();
647  new (this) DoubleAPFloat(std::move(RHS));
648  }
649  return *this;
650  }
651 
652  bool needsCleanup() const { return Floats != nullptr; }
653 
654  APFloat &getFirst() { return Floats[0]; }
655  const APFloat &getFirst() const { return Floats[0]; }
656  APFloat &getSecond() { return Floats[1]; }
657  const APFloat &getSecond() const { return Floats[1]; }
658 
664  opStatus mod(const DoubleAPFloat &RHS);
665  opStatus fusedMultiplyAdd(const DoubleAPFloat &Multiplicand,
666  const DoubleAPFloat &Addend, roundingMode RM);
668  void changeSign();
670 
671  fltCategory getCategory() const;
672  bool isNegative() const;
673 
674  void makeInf(bool Neg);
675  void makeZero(bool Neg);
676  void makeLargest(bool Neg);
677  void makeSmallest(bool Neg);
678  void makeSmallestNormalized(bool Neg);
679  void makeNaN(bool SNaN, bool Neg, const APInt *fill);
680 
681  cmpResult compare(const DoubleAPFloat &RHS) const;
682  bool bitwiseIsEqual(const DoubleAPFloat &RHS) const;
683  APInt bitcastToAPInt() const;
685  opStatus next(bool nextDown);
686 
688  unsigned int Width, bool IsSigned, roundingMode RM,
689  bool *IsExact) const;
690  opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM);
692  unsigned int InputSize, bool IsSigned,
693  roundingMode RM);
695  unsigned int InputSize, bool IsSigned,
696  roundingMode RM);
697  unsigned int convertToHexString(char *DST, unsigned int HexDigits,
698  bool UpperCase, roundingMode RM) const;
699 
700  bool isDenormal() const;
701  bool isSmallest() const;
702  bool isSmallestNormalized() const;
703  bool isLargest() const;
704  bool isInteger() const;
705 
706  void toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision,
707  unsigned FormatMaxPadding, bool TruncateZero = true) const;
708 
709  bool getExactInverse(APFloat *inv) const;
710 
711  friend DoubleAPFloat scalbn(const DoubleAPFloat &X, int Exp, roundingMode);
712  friend DoubleAPFloat frexp(const DoubleAPFloat &X, int &Exp, roundingMode);
713  friend hash_code hash_value(const DoubleAPFloat &Arg);
714 };
715 
716 hash_code hash_value(const DoubleAPFloat &Arg);
717 
718 } // End detail namespace
719 
720 // This is a interface class that is currently forwarding functionalities from
721 // detail::IEEEFloat.
722 class APFloat : public APFloatBase {
725 
726  static_assert(std::is_standard_layout<IEEEFloat>::value);
727 
728  union Storage {
729  const fltSemantics *semantics;
730  IEEEFloat IEEE;
731  DoubleAPFloat Double;
732 
733  explicit Storage(IEEEFloat F, const fltSemantics &S);
734  explicit Storage(DoubleAPFloat F, const fltSemantics &S)
735  : Double(std::move(F)) {
736  assert(&S == &PPCDoubleDouble());
737  }
738 
739  template <typename... ArgTypes>
740  Storage(const fltSemantics &Semantics, ArgTypes &&... Args) {
741  if (usesLayout<IEEEFloat>(Semantics)) {
742  new (&IEEE) IEEEFloat(Semantics, std::forward<ArgTypes>(Args)...);
743  return;
744  }
745  if (usesLayout<DoubleAPFloat>(Semantics)) {
746  new (&Double) DoubleAPFloat(Semantics, std::forward<ArgTypes>(Args)...);
747  return;
748  }
749  llvm_unreachable("Unexpected semantics");
750  }
751 
752  ~Storage() {
753  if (usesLayout<IEEEFloat>(*semantics)) {
754  IEEE.~IEEEFloat();
755  return;
756  }
757  if (usesLayout<DoubleAPFloat>(*semantics)) {
758  Double.~DoubleAPFloat();
759  return;
760  }
761  llvm_unreachable("Unexpected semantics");
762  }
763 
764  Storage(const Storage &RHS) {
765  if (usesLayout<IEEEFloat>(*RHS.semantics)) {
766  new (this) IEEEFloat(RHS.IEEE);
767  return;
768  }
769  if (usesLayout<DoubleAPFloat>(*RHS.semantics)) {
770  new (this) DoubleAPFloat(RHS.Double);
771  return;
772  }
773  llvm_unreachable("Unexpected semantics");
774  }
775 
776  Storage(Storage &&RHS) {
777  if (usesLayout<IEEEFloat>(*RHS.semantics)) {
778  new (this) IEEEFloat(std::move(RHS.IEEE));
779  return;
780  }
781  if (usesLayout<DoubleAPFloat>(*RHS.semantics)) {
782  new (this) DoubleAPFloat(std::move(RHS.Double));
783  return;
784  }
785  llvm_unreachable("Unexpected semantics");
786  }
787 
788  Storage &operator=(const Storage &RHS) {
789  if (usesLayout<IEEEFloat>(*semantics) &&
790  usesLayout<IEEEFloat>(*RHS.semantics)) {
791  IEEE = RHS.IEEE;
792  } else if (usesLayout<DoubleAPFloat>(*semantics) &&
793  usesLayout<DoubleAPFloat>(*RHS.semantics)) {
794  Double = RHS.Double;
795  } else if (this != &RHS) {
796  this->~Storage();
797  new (this) Storage(RHS);
798  }
799  return *this;
800  }
801 
802  Storage &operator=(Storage &&RHS) {
803  if (usesLayout<IEEEFloat>(*semantics) &&
804  usesLayout<IEEEFloat>(*RHS.semantics)) {
805  IEEE = std::move(RHS.IEEE);
806  } else if (usesLayout<DoubleAPFloat>(*semantics) &&
807  usesLayout<DoubleAPFloat>(*RHS.semantics)) {
808  Double = std::move(RHS.Double);
809  } else if (this != &RHS) {
810  this->~Storage();
811  new (this) Storage(std::move(RHS));
812  }
813  return *this;
814  }
815  } U;
816 
817  template <typename T> static bool usesLayout(const fltSemantics &Semantics) {
818  static_assert(std::is_same<T, IEEEFloat>::value ||
819  std::is_same<T, DoubleAPFloat>::value);
820  if (std::is_same<T, DoubleAPFloat>::value) {
821  return &Semantics == &PPCDoubleDouble();
822  }
823  return &Semantics != &PPCDoubleDouble();
824  }
825 
826  IEEEFloat &getIEEE() {
827  if (usesLayout<IEEEFloat>(*U.semantics))
828  return U.IEEE;
829  if (usesLayout<DoubleAPFloat>(*U.semantics))
830  return U.Double.getFirst().U.IEEE;
831  llvm_unreachable("Unexpected semantics");
832  }
833 
834  const IEEEFloat &getIEEE() const {
835  if (usesLayout<IEEEFloat>(*U.semantics))
836  return U.IEEE;
837  if (usesLayout<DoubleAPFloat>(*U.semantics))
838  return U.Double.getFirst().U.IEEE;
839  llvm_unreachable("Unexpected semantics");
840  }
841 
842  void makeZero(bool Neg) { APFLOAT_DISPATCH_ON_SEMANTICS(makeZero(Neg)); }
843 
844  void makeInf(bool Neg) { APFLOAT_DISPATCH_ON_SEMANTICS(makeInf(Neg)); }
845 
846  void makeNaN(bool SNaN, bool Neg, const APInt *fill) {
847  APFLOAT_DISPATCH_ON_SEMANTICS(makeNaN(SNaN, Neg, fill));
848  }
849 
850  void makeLargest(bool Neg) {
851  APFLOAT_DISPATCH_ON_SEMANTICS(makeLargest(Neg));
852  }
853 
854  void makeSmallest(bool Neg) {
855  APFLOAT_DISPATCH_ON_SEMANTICS(makeSmallest(Neg));
856  }
857 
858  void makeSmallestNormalized(bool Neg) {
859  APFLOAT_DISPATCH_ON_SEMANTICS(makeSmallestNormalized(Neg));
860  }
861 
862  explicit APFloat(IEEEFloat F, const fltSemantics &S) : U(std::move(F), S) {}
863  explicit APFloat(DoubleAPFloat F, const fltSemantics &S)
864  : U(std::move(F), S) {}
865 
866  cmpResult compareAbsoluteValue(const APFloat &RHS) const {
867  assert(&getSemantics() == &RHS.getSemantics() &&
868  "Should only compare APFloats with the same semantics");
869  if (usesLayout<IEEEFloat>(getSemantics()))
870  return U.IEEE.compareAbsoluteValue(RHS.U.IEEE);
871  if (usesLayout<DoubleAPFloat>(getSemantics()))
872  return U.Double.compareAbsoluteValue(RHS.U.Double);
873  llvm_unreachable("Unexpected semantics");
874  }
875 
876 public:
880  template <typename T,
881  typename = std::enable_if_t<std::is_floating_point<T>::value>>
882  APFloat(const fltSemantics &Semantics, T V) = delete;
883  // TODO: Remove this constructor. This isn't faster than the first one.
885  : U(Semantics, uninitialized) {}
886  APFloat(const fltSemantics &Semantics, const APInt &I) : U(Semantics, I) {}
887  explicit APFloat(double d) : U(IEEEFloat(d), IEEEdouble()) {}
888  explicit APFloat(float f) : U(IEEEFloat(f), IEEEsingle()) {}
889  APFloat(const APFloat &RHS) = default;
890  APFloat(APFloat &&RHS) = default;
891 
892  ~APFloat() = default;
893 
895 
896  /// Factory for Positive and Negative Zero.
897  ///
898  /// \param Negative True iff the number should be negative.
899  static APFloat getZero(const fltSemantics &Sem, bool Negative = false) {
900  APFloat Val(Sem, uninitialized);
901  Val.makeZero(Negative);
902  return Val;
903  }
904 
905  /// Factory for Positive and Negative Infinity.
906  ///
907  /// \param Negative True iff the number should be negative.
908  static APFloat getInf(const fltSemantics &Sem, bool Negative = false) {
909  APFloat Val(Sem, uninitialized);
910  Val.makeInf(Negative);
911  return Val;
912  }
913 
914  /// Factory for NaN values.
915  ///
916  /// \param Negative - True iff the NaN generated should be negative.
917  /// \param payload - The unspecified fill bits for creating the NaN, 0 by
918  /// default. The value is truncated as necessary.
919  static APFloat getNaN(const fltSemantics &Sem, bool Negative = false,
920  uint64_t payload = 0) {
921  if (payload) {
922  APInt intPayload(64, payload);
923  return getQNaN(Sem, Negative, &intPayload);
924  } else {
925  return getQNaN(Sem, Negative, nullptr);
926  }
927  }
928 
929  /// Factory for QNaN values.
930  static APFloat getQNaN(const fltSemantics &Sem, bool Negative = false,
931  const APInt *payload = nullptr) {
932  APFloat Val(Sem, uninitialized);
933  Val.makeNaN(false, Negative, payload);
934  return Val;
935  }
936 
937  /// Factory for SNaN values.
938  static APFloat getSNaN(const fltSemantics &Sem, bool Negative = false,
939  const APInt *payload = nullptr) {
940  APFloat Val(Sem, uninitialized);
941  Val.makeNaN(true, Negative, payload);
942  return Val;
943  }
944 
945  /// Returns the largest finite number in the given semantics.
946  ///
947  /// \param Negative - True iff the number should be negative
948  static APFloat getLargest(const fltSemantics &Sem, bool Negative = false) {
949  APFloat Val(Sem, uninitialized);
950  Val.makeLargest(Negative);
951  return Val;
952  }
953 
954  /// Returns the smallest (by magnitude) finite number in the given semantics.
955  /// Might be denormalized, which implies a relative loss of precision.
956  ///
957  /// \param Negative - True iff the number should be negative
958  static APFloat getSmallest(const fltSemantics &Sem, bool Negative = false) {
959  APFloat Val(Sem, uninitialized);
960  Val.makeSmallest(Negative);
961  return Val;
962  }
963 
964  /// Returns the smallest (by magnitude) normalized finite number in the given
965  /// semantics.
966  ///
967  /// \param Negative - True iff the number should be negative
969  bool Negative = false) {
970  APFloat Val(Sem, uninitialized);
971  Val.makeSmallestNormalized(Negative);
972  return Val;
973  }
974 
975  /// Returns a float which is bitcasted from an all one value int.
976  ///
977  /// \param Semantics - type float semantics
979 
980  /// Used to insert APFloat objects, or objects that contain APFloat objects,
981  /// into FoldingSets.
982  void Profile(FoldingSetNodeID &NID) const;
983 
985  assert(&getSemantics() == &RHS.getSemantics() &&
986  "Should only call on two APFloats with the same semantics");
987  if (usesLayout<IEEEFloat>(getSemantics()))
988  return U.IEEE.add(RHS.U.IEEE, RM);
989  if (usesLayout<DoubleAPFloat>(getSemantics()))
990  return U.Double.add(RHS.U.Double, RM);
991  llvm_unreachable("Unexpected semantics");
992  }
994  assert(&getSemantics() == &RHS.getSemantics() &&
995  "Should only call on two APFloats with the same semantics");
996  if (usesLayout<IEEEFloat>(getSemantics()))
997  return U.IEEE.subtract(RHS.U.IEEE, RM);
998  if (usesLayout<DoubleAPFloat>(getSemantics()))
999  return U.Double.subtract(RHS.U.Double, RM);
1000  llvm_unreachable("Unexpected semantics");
1001  }
1003  assert(&getSemantics() == &RHS.getSemantics() &&
1004  "Should only call on two APFloats with the same semantics");
1005  if (usesLayout<IEEEFloat>(getSemantics()))
1006  return U.IEEE.multiply(RHS.U.IEEE, RM);
1007  if (usesLayout<DoubleAPFloat>(getSemantics()))
1008  return U.Double.multiply(RHS.U.Double, RM);
1009  llvm_unreachable("Unexpected semantics");
1010  }
1012  assert(&getSemantics() == &RHS.getSemantics() &&
1013  "Should only call on two APFloats with the same semantics");
1014  if (usesLayout<IEEEFloat>(getSemantics()))
1015  return U.IEEE.divide(RHS.U.IEEE, RM);
1016  if (usesLayout<DoubleAPFloat>(getSemantics()))
1017  return U.Double.divide(RHS.U.Double, RM);
1018  llvm_unreachable("Unexpected semantics");
1019  }
1021  assert(&getSemantics() == &RHS.getSemantics() &&
1022  "Should only call on two APFloats with the same semantics");
1023  if (usesLayout<IEEEFloat>(getSemantics()))
1024  return U.IEEE.remainder(RHS.U.IEEE);
1025  if (usesLayout<DoubleAPFloat>(getSemantics()))
1026  return U.Double.remainder(RHS.U.Double);
1027  llvm_unreachable("Unexpected semantics");
1028  }
1030  assert(&getSemantics() == &RHS.getSemantics() &&
1031  "Should only call on two APFloats with the same semantics");
1032  if (usesLayout<IEEEFloat>(getSemantics()))
1033  return U.IEEE.mod(RHS.U.IEEE);
1034  if (usesLayout<DoubleAPFloat>(getSemantics()))
1035  return U.Double.mod(RHS.U.Double);
1036  llvm_unreachable("Unexpected semantics");
1037  }
1038  opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend,
1039  roundingMode RM) {
1040  assert(&getSemantics() == &Multiplicand.getSemantics() &&
1041  "Should only call on APFloats with the same semantics");
1042  assert(&getSemantics() == &Addend.getSemantics() &&
1043  "Should only call on APFloats with the same semantics");
1044  if (usesLayout<IEEEFloat>(getSemantics()))
1045  return U.IEEE.fusedMultiplyAdd(Multiplicand.U.IEEE, Addend.U.IEEE, RM);
1046  if (usesLayout<DoubleAPFloat>(getSemantics()))
1047  return U.Double.fusedMultiplyAdd(Multiplicand.U.Double, Addend.U.Double,
1048  RM);
1049  llvm_unreachable("Unexpected semantics");
1050  }
1053  }
1054 
1055  // TODO: bool parameters are not readable and a source of bugs.
1056  // Do something.
1057  opStatus next(bool nextDown) {
1059  }
1060 
1061  /// Negate an APFloat.
1062  APFloat operator-() const {
1063  APFloat Result(*this);
1064  Result.changeSign();
1065  return Result;
1066  }
1067 
1068  /// Add two APFloats, rounding ties to the nearest even.
1069  /// No error checking.
1070  APFloat operator+(const APFloat &RHS) const {
1071  APFloat Result(*this);
1072  (void)Result.add(RHS, rmNearestTiesToEven);
1073  return Result;
1074  }
1075 
1076  /// Subtract two APFloats, rounding ties to the nearest even.
1077  /// No error checking.
1078  APFloat operator-(const APFloat &RHS) const {
1079  APFloat Result(*this);
1080  (void)Result.subtract(RHS, rmNearestTiesToEven);
1081  return Result;
1082  }
1083 
1084  /// Multiply two APFloats, rounding ties to the nearest even.
1085  /// No error checking.
1086  APFloat operator*(const APFloat &RHS) const {
1087  APFloat Result(*this);
1088  (void)Result.multiply(RHS, rmNearestTiesToEven);
1089  return Result;
1090  }
1091 
1092  /// Divide the first APFloat by the second, rounding ties to the nearest even.
1093  /// No error checking.
1094  APFloat operator/(const APFloat &RHS) const {
1095  APFloat Result(*this);
1096  (void)Result.divide(RHS, rmNearestTiesToEven);
1097  return Result;
1098  }
1099 
1101  void clearSign() {
1102  if (isNegative())
1103  changeSign();
1104  }
1105  void copySign(const APFloat &RHS) {
1106  if (isNegative() != RHS.isNegative())
1107  changeSign();
1108  }
1109 
1110  /// A static helper to produce a copy of an APFloat value with its sign
1111  /// copied from some other APFloat.
1112  static APFloat copySign(APFloat Value, const APFloat &Sign) {
1113  Value.copySign(Sign);
1114  return Value;
1115  }
1116 
1117  opStatus convert(const fltSemantics &ToSemantics, roundingMode RM,
1118  bool *losesInfo);
1120  unsigned int Width, bool IsSigned, roundingMode RM,
1121  bool *IsExact) const {
1123  convertToInteger(Input, Width, IsSigned, RM, IsExact));
1124  }
1126  bool *IsExact) const;
1127  opStatus convertFromAPInt(const APInt &Input, bool IsSigned,
1128  roundingMode RM) {
1130  }
1132  unsigned int InputSize, bool IsSigned,
1133  roundingMode RM) {
1135  convertFromSignExtendedInteger(Input, InputSize, IsSigned, RM));
1136  }
1138  unsigned int InputSize, bool IsSigned,
1139  roundingMode RM) {
1141  convertFromZeroExtendedInteger(Input, InputSize, IsSigned, RM));
1142  }
1146  }
1147 
1148  /// Converts this APFloat to host double value.
1149  ///
1150  /// \pre The APFloat must be built using semantics, that can be represented by
1151  /// the host double type without loss of precision. It can be IEEEdouble and
1152  /// shorter semantics, like IEEEsingle and others.
1153  double convertToDouble() const;
1154 
1155  /// Converts this APFloat to host float value.
1156  ///
1157  /// \pre The APFloat must be built using semantics, that can be represented by
1158  /// the host float type without loss of precision. It can be IEEEsingle and
1159  /// shorter semantics, like IEEEhalf.
1160  float convertToFloat() const;
1161 
1162  bool operator==(const APFloat &RHS) const { return compare(RHS) == cmpEqual; }
1163 
1164  bool operator!=(const APFloat &RHS) const { return compare(RHS) != cmpEqual; }
1165 
1166  bool operator<(const APFloat &RHS) const {
1167  return compare(RHS) == cmpLessThan;
1168  }
1169 
1170  bool operator>(const APFloat &RHS) const {
1171  return compare(RHS) == cmpGreaterThan;
1172  }
1173 
1174  bool operator<=(const APFloat &RHS) const {
1175  cmpResult Res = compare(RHS);
1176  return Res == cmpLessThan || Res == cmpEqual;
1177  }
1178 
1179  bool operator>=(const APFloat &RHS) const {
1180  cmpResult Res = compare(RHS);
1181  return Res == cmpGreaterThan || Res == cmpEqual;
1182  }
1183 
1184  cmpResult compare(const APFloat &RHS) const {
1185  assert(&getSemantics() == &RHS.getSemantics() &&
1186  "Should only compare APFloats with the same semantics");
1187  if (usesLayout<IEEEFloat>(getSemantics()))
1188  return U.IEEE.compare(RHS.U.IEEE);
1189  if (usesLayout<DoubleAPFloat>(getSemantics()))
1190  return U.Double.compare(RHS.U.Double);
1191  llvm_unreachable("Unexpected semantics");
1192  }
1193 
1194  bool bitwiseIsEqual(const APFloat &RHS) const {
1195  if (&getSemantics() != &RHS.getSemantics())
1196  return false;
1197  if (usesLayout<IEEEFloat>(getSemantics()))
1198  return U.IEEE.bitwiseIsEqual(RHS.U.IEEE);
1199  if (usesLayout<DoubleAPFloat>(getSemantics()))
1200  return U.Double.bitwiseIsEqual(RHS.U.Double);
1201  llvm_unreachable("Unexpected semantics");
1202  }
1203 
1204  /// We don't rely on operator== working on double values, as
1205  /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1206  /// As such, this method can be used to do an exact bit-for-bit comparison of
1207  /// two floating point values.
1208  ///
1209  /// We leave the version with the double argument here because it's just so
1210  /// convenient to write "2.0" and the like. Without this function we'd
1211  /// have to duplicate its logic everywhere it's called.
1212  bool isExactlyValue(double V) const {
1213  bool ignored;
1214  APFloat Tmp(V);
1216  return bitwiseIsEqual(Tmp);
1217  }
1218 
1219  unsigned int convertToHexString(char *DST, unsigned int HexDigits,
1220  bool UpperCase, roundingMode RM) const {
1222  convertToHexString(DST, HexDigits, UpperCase, RM));
1223  }
1224 
1225  bool isZero() const { return getCategory() == fcZero; }
1226  bool isInfinity() const { return getCategory() == fcInfinity; }
1227  bool isNaN() const { return getCategory() == fcNaN; }
1228 
1229  bool isNegative() const { return getIEEE().isNegative(); }
1231  bool isSignaling() const { return getIEEE().isSignaling(); }
1232 
1233  bool isNormal() const { return !isDenormal() && isFiniteNonZero(); }
1234  bool isFinite() const { return !isNaN() && !isInfinity(); }
1235 
1236  fltCategory getCategory() const { return getIEEE().getCategory(); }
1237  const fltSemantics &getSemantics() const { return *U.semantics; }
1238  bool isNonZero() const { return !isZero(); }
1239  bool isFiniteNonZero() const { return isFinite() && !isZero(); }
1240  bool isPosZero() const { return isZero() && !isNegative(); }
1241  bool isNegZero() const { return isZero() && isNegative(); }
1242  bool isPosInfinity() const { return isInfinity() && !isNegative(); }
1243  bool isNegInfinity() const { return isInfinity() && isNegative(); }
1247  bool isIEEE() const { return usesLayout<IEEEFloat>(getSemantics()); }
1248 
1249  bool isSmallestNormalized() const {
1251  }
1252 
1253  APFloat &operator=(const APFloat &RHS) = default;
1254  APFloat &operator=(APFloat &&RHS) = default;
1255 
1256  void toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision = 0,
1257  unsigned FormatMaxPadding = 3, bool TruncateZero = true) const {
1259  toString(Str, FormatPrecision, FormatMaxPadding, TruncateZero));
1260  }
1261 
1262  void print(raw_ostream &) const;
1263  void dump() const;
1264 
1265  bool getExactInverse(APFloat *inv) const {
1267  }
1268 
1269  friend hash_code hash_value(const APFloat &Arg);
1270  friend int ilogb(const APFloat &Arg) { return ilogb(Arg.getIEEE()); }
1271  friend APFloat scalbn(APFloat X, int Exp, roundingMode RM);
1272  friend APFloat frexp(const APFloat &X, int &Exp, roundingMode RM);
1273  friend IEEEFloat;
1275 };
1276 
1277 /// See friend declarations above.
1278 ///
1279 /// These additional declarations are required in order to compile LLVM with IBM
1280 /// xlC compiler.
1283  if (APFloat::usesLayout<detail::IEEEFloat>(X.getSemantics()))
1284  return APFloat(scalbn(X.U.IEEE, Exp, RM), X.getSemantics());
1285  if (APFloat::usesLayout<detail::DoubleAPFloat>(X.getSemantics()))
1286  return APFloat(scalbn(X.U.Double, Exp, RM), X.getSemantics());
1287  llvm_unreachable("Unexpected semantics");
1288 }
1289 
1290 /// Equivalent of C standard library function.
1291 ///
1292 /// While the C standard says Exp is an unspecified value for infinity and nan,
1293 /// this returns INT_MAX for infinities, and INT_MIN for NaNs.
1294 inline APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM) {
1295  if (APFloat::usesLayout<detail::IEEEFloat>(X.getSemantics()))
1296  return APFloat(frexp(X.U.IEEE, Exp, RM), X.getSemantics());
1297  if (APFloat::usesLayout<detail::DoubleAPFloat>(X.getSemantics()))
1298  return APFloat(frexp(X.U.Double, Exp, RM), X.getSemantics());
1299  llvm_unreachable("Unexpected semantics");
1300 }
1301 /// Returns the absolute value of the argument.
1303  X.clearSign();
1304  return X;
1305 }
1306 
1307 /// Returns the negated value of the argument.
1309  X.changeSign();
1310  return X;
1311 }
1312 
1313 /// Implements IEEE minNum semantics. Returns the smaller of the 2 arguments if
1314 /// both are not NaN. If either argument is a NaN, returns the other argument.
1316 inline APFloat minnum(const APFloat &A, const APFloat &B) {
1317  if (A.isNaN())
1318  return B;
1319  if (B.isNaN())
1320  return A;
1321  return B < A ? B : A;
1322 }
1323 
1324 /// Implements IEEE maxNum semantics. Returns the larger of the 2 arguments if
1325 /// both are not NaN. If either argument is a NaN, returns the other argument.
1327 inline APFloat maxnum(const APFloat &A, const APFloat &B) {
1328  if (A.isNaN())
1329  return B;
1330  if (B.isNaN())
1331  return A;
1332  return A < B ? B : A;
1333 }
1334 
1335 /// Implements IEEE 754-2018 minimum semantics. Returns the smaller of 2
1336 /// arguments, propagating NaNs and treating -0 as less than +0.
1338 inline APFloat minimum(const APFloat &A, const APFloat &B) {
1339  if (A.isNaN())
1340  return A;
1341  if (B.isNaN())
1342  return B;
1343  if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1344  return A.isNegative() ? A : B;
1345  return B < A ? B : A;
1346 }
1347 
1348 /// Implements IEEE 754-2018 maximum semantics. Returns the larger of 2
1349 /// arguments, propagating NaNs and treating -0 as less than +0.
1351 inline APFloat maximum(const APFloat &A, const APFloat &B) {
1352  if (A.isNaN())
1353  return A;
1354  if (B.isNaN())
1355  return B;
1356  if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1357  return A.isNegative() ? B : A;
1358  return A < B ? B : A;
1359 }
1360 
1361 } // namespace llvm
1362 
1363 #undef APFLOAT_DISPATCH_ON_SEMANTICS
1364 #endif // LLVM_ADT_APFLOAT_H
llvm::detail::DoubleAPFloat::convertFromString
Expected< opStatus > convertFromString(StringRef, roundingMode)
Definition: APFloat.cpp:4939
llvm::detail::IEEEFloat
Definition: APFloat.h:257
llvm::lltok::APFloat
@ APFloat
Definition: LLToken.h:461
FloatingPointMode.h
llvm::detail::IEEEFloat::add
opStatus add(const IEEEFloat &, roundingMode)
Definition: APFloat.cpp:1915
llvm::APFloat::isDenormal
bool isDenormal() const
Definition: APFloat.h:1230
llvm::APFloat::convertToFloat
float convertToFloat() const
Converts this APFloat to host float value.
Definition: APFloat.cpp:5189
llvm::detail::IEEEFloat::isInfinity
bool isInfinity() const
IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
Definition: APFloat.h:372
llvm::APFloatBase::opStatus
opStatus
IEEE-754R 7: Default exception handling.
Definition: APFloat.h:216
llvm::APFloat::isInfinity
bool isInfinity() const
Definition: APFloat.h:1226
llvm::detail::DoubleAPFloat::isNegative
bool isNegative() const
Definition: APFloat.cpp:4872
llvm::detail::IEEEFloat::isSmallestNormalized
bool isSmallestNormalized() const
Returns true if this is the smallest (by magnitude) normalized finite number in the given semantics.
Definition: APFloat.cpp:886
llvm::APFloat::getExactInverse
bool getExactInverse(APFloat *inv) const
Definition: APFloat.h:1265
llvm::detail::IEEEFloat::~IEEEFloat
~IEEEFloat()
Definition: APFloat.cpp:1047
llvm::detail::DoubleAPFloat::makeZero
void makeZero(bool Neg)
Definition: APFloat.cpp:4879
llvm::APFloatBase::semanticsSizeInBits
static unsigned int semanticsSizeInBits(const fltSemantics &)
Definition: APFloat.cpp:251
LLVM_READONLY
#define LLVM_READONLY
Definition: Compiler.h:196
llvm::APFloat::isSmallest
bool isSmallest() const
Definition: APFloat.h:1244
llvm::detail::DoubleAPFloat::add
opStatus add(const DoubleAPFloat &RHS, roundingMode RM)
Definition: APFloat.cpp:4695
llvm::APFloat::DoubleAPFloat
friend DoubleAPFloat
Definition: APFloat.h:1274
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::detail::IEEEFloat::divide
opStatus divide(const IEEEFloat &, roundingMode)
Definition: APFloat.cpp:1945
llvm::detail::IEEEFloat::isSmallest
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:878
llvm::APFloatBase::cmpGreaterThan
@ cmpGreaterThan
Definition: APFloat.h:193
llvm::APFloatBase::opUnderflow
@ opUnderflow
Definition: APFloat.h:221
llvm::detail::DoubleAPFloat::frexp
friend DoubleAPFloat frexp(const DoubleAPFloat &X, int &Exp, roundingMode)
llvm::detail::DoubleAPFloat::hash_value
friend hash_code hash_value(const DoubleAPFloat &Arg)
Definition: APFloat.cpp:4924
llvm::APFloat::operator==
bool operator==(const APFloat &RHS) const
Definition: APFloat.h:1162
llvm::APFloatBase::IEK_NaN
@ IEK_NaN
Definition: APFloat.h:241
llvm::detail::DoubleAPFloat
Definition: APFloat.h:622
llvm::APFloat::add
opStatus add(const APFloat &RHS, roundingMode RM)
Definition: APFloat.h:984
llvm::APFloatBase::IEEEsingle
static const fltSemantics & IEEEsingle() LLVM_READNONE
Definition: APFloat.cpp:201
llvm::APFloat::next
opStatus next(bool nextDown)
Definition: APFloat.h:1057
llvm::lfMoreThanHalf
@ lfMoreThanHalf
Definition: APFloat.h:52
llvm::APFloatBase::S_IEEEsingle
@ S_IEEEsingle
Definition: APFloat.h:154
aa
aa
Definition: AliasAnalysis.cpp:768
llvm::detail::IEEEFloat::roundToIntegral
opStatus roundToIntegral(roundingMode)
Definition: APFloat.cpp:2135
llvm::detail::DoubleAPFloat::convertFromAPInt
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
Definition: APFloat.cpp:4965
llvm::APFloat::isIEEE
bool isIEEE() const
Definition: APFloat.h:1247
llvm::detail::IEEEFloat::multiply
opStatus multiply(const IEEEFloat &, roundingMode)
Definition: APFloat.cpp:1927
llvm::APFloatBase::S_x87DoubleExtended
@ S_x87DoubleExtended
Definition: APFloat.h:166
llvm::detail::DoubleAPFloat::needsCleanup
bool needsCleanup() const
Definition: APFloat.h:652
llvm::detail::IEEEFloat::isLargest
bool isLargest() const
Returns true if and only if the number has the largest possible finite magnitude in the current seman...
Definition: APFloat.cpp:978
llvm::detail::DoubleAPFloat::makeLargest
void makeLargest(bool Neg)
Definition: APFloat.cpp:4884
llvm::APFloatBase::integerPart
APInt::WordType integerPart
Definition: APFloat.h:143
llvm::APFloat::isInteger
bool isInteger() const
Definition: APFloat.h:1246
ErrorHandling.h
llvm::detail::IEEEFloat::makeSmallest
void makeSmallest(bool Neg=false)
Make this number the smallest magnitude denormal number in the given semantics.
Definition: APFloat.cpp:3902
llvm::lfExactlyHalf
@ lfExactlyHalf
Definition: APFloat.h:51
llvm::detail::IEEEFloat::bitwiseIsEqual
bool bitwiseIsEqual(const IEEEFloat &) const
Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
Definition: APFloat.cpp:1001
llvm::detail::IEEEFloat::makeNaN
void makeNaN(bool SNaN=false, bool Neg=false, const APInt *fill=nullptr)
Definition: APFloat.cpp:791
llvm::detail::DoubleAPFloat::isInteger
bool isInteger() const
Definition: APFloat.cpp:5038
llvm::lltok::APSInt
@ APSInt
Definition: LLToken.h:462
llvm::minimum
LLVM_READONLY APFloat minimum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2018 minimum semantics.
Definition: APFloat.h:1338
llvm::APFloat::isZero
bool isZero() const
Definition: APFloat.h:1225
llvm::APFloatBase::x87DoubleExtended
static const fltSemantics & x87DoubleExtended() LLVM_READNONE
Definition: APFloat.cpp:213
llvm::detail::DoubleAPFloat::mod
opStatus mod(const DoubleAPFloat &RHS)
Definition: APFloat.cpp:4813
llvm::APFloat::frexp
friend APFloat frexp(const APFloat &X, int &Exp, roundingMode RM)
APInt.h
llvm::APFloat::divide
opStatus divide(const APFloat &RHS, roundingMode RM)
Definition: APFloat.h:1011
llvm::detail::IEEEFloat::compareAbsoluteValue
cmpResult compareAbsoluteValue(const IEEEFloat &) const
Definition: APFloat.cpp:1361
llvm::APFloat::isFiniteNonZero
bool isFiniteNonZero() const
Definition: APFloat.h:1239
llvm::APFloatBase::IEK_Inf
@ IEK_Inf
Definition: APFloat.h:242
llvm::APFloatBase::BFloat
static const fltSemantics & BFloat() LLVM_READNONE
Definition: APFloat.cpp:198
llvm::detail::IEEEFloat::isInteger
bool isInteger() const
Returns true if and only if the number is an exact integer.
Definition: APFloat.cpp:993
llvm::detail::DoubleAPFloat::getSecond
const APFloat & getSecond() const
Definition: APFloat.h:657
llvm::APFloat::fusedMultiplyAdd
opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend, roundingMode RM)
Definition: APFloat.h:1038
llvm::detail::DoubleAPFloat::toString
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision, unsigned FormatMaxPadding, bool TruncateZero=true) const
Definition: APFloat.cpp:5043
llvm::detail::DoubleAPFloat::scalbn
friend DoubleAPFloat scalbn(const DoubleAPFloat &X, int Exp, roundingMode)
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::lostFraction
lostFraction
Enum that represents what fraction of the LSB truncated bits of an fp number represent.
Definition: APFloat.h:48
llvm::APFloat::getSNaN
static APFloat getSNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for SNaN values.
Definition: APFloat.h:938
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::detail::ilogb
int ilogb(const IEEEFloat &Arg)
Definition: APFloat.cpp:4448
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::APFloat::operator+
APFloat operator+(const APFloat &RHS) const
Add two APFloats, rounding ties to the nearest even.
Definition: APFloat.h:1070
llvm::lfLessThanHalf
@ lfLessThanHalf
Definition: APFloat.h:50
llvm::detail::DoubleAPFloat::compareAbsoluteValue
cmpResult compareAbsoluteValue(const DoubleAPFloat &RHS) const
Definition: APFloat.cpp:4848
llvm::APFloat::mod
opStatus mod(const APFloat &RHS)
Definition: APFloat.h:1029
llvm::APFloat::getSemantics
const fltSemantics & getSemantics() const
Definition: APFloat.h:1237
llvm::APFloatBase::rmTowardNegative
static constexpr roundingMode rmTowardNegative
Definition: APFloat.h:203
llvm::APFloat::convertToHexString
unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
Definition: APFloat.h:1219
llvm::APFloatBase::S_BFloat
@ S_BFloat
Definition: APFloat.h:153
llvm::detail::IEEEFloat::makeLargest
void makeLargest(bool Neg=false)
Make this number the largest magnitude normal number in the given semantics.
Definition: APFloat.cpp:3874
llvm::detail::DoubleAPFloat::changeSign
void changeSign()
Definition: APFloat.cpp:4842
llvm::APFloatBase::opOverflow
@ opOverflow
Definition: APFloat.h:220
llvm::detail::IEEEFloat::makeZero
void makeZero(bool Neg=false)
Definition: APFloat.cpp:4435
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::detail::DoubleAPFloat::DoubleAPFloat
DoubleAPFloat(const fltSemantics &S)
Definition: APFloat.cpp:4506
llvm::detail::DoubleAPFloat::makeInf
void makeInf(bool Neg)
Definition: APFloat.cpp:4874
llvm::APFloatBase::IEEEquad
static const fltSemantics & IEEEquad() LLVM_READNONE
Definition: APFloat.cpp:207
a
=0.0 ? 0.0 :(a > 0.0 ? 1.0 :-1.0) a
Definition: README.txt:489
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:187
llvm::detail::IEEEFloat::convert
opStatus convert(const fltSemantics &, roundingMode, bool *)
IEEEFloat::convert - convert a value of one floating point type to another.
Definition: APFloat.cpp:2299
LHS
Value * LHS
Definition: X86PartialReduction.cpp:75
llvm::APFloat::getZero
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Definition: APFloat.h:899
llvm::detail::DoubleAPFloat::operator=
DoubleAPFloat & operator=(DoubleAPFloat &&RHS)
Definition: APFloat.h:644
llvm::APFloatBase::getSizeInBits
static unsigned getSizeInBits(const fltSemantics &Sem)
Returns the size of the floating point number (in bits) in the given semantics.
Definition: APFloat.cpp:255
llvm::APFloatBase::Float8E5M2
static const fltSemantics & Float8E5M2() LLVM_READNONE
Definition: APFloat.cpp:211
llvm::APFloat::convertToInteger
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
Definition: APFloat.h:1119
llvm::MutableArrayRef
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:27
llvm::maximum
LLVM_READONLY APFloat maximum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2018 maximum semantics.
Definition: APFloat.h:1351
f
Itanium Name Demangler i e convert the string _Z1fv into f()". You can also use the CRTP base ManglingParser to perform some simple analysis on the mangled name
llvm::APFloatBase::opDivByZero
@ opDivByZero
Definition: APFloat.h:219
llvm::APFloatBase::IEEEhalf
static const fltSemantics & IEEEhalf() LLVM_READNONE
Definition: APFloat.cpp:195
llvm::APFloat::IEEEFloat
friend IEEEFloat
Definition: APFloat.h:1273
llvm::APFloat::isNonZero
bool isNonZero() const
Definition: APFloat.h:1238
llvm::detail::DoubleAPFloat::makeNaN
void makeNaN(bool SNaN, bool Neg, const APInt *fill)
Definition: APFloat.cpp:4906
llvm::RoundingMode
RoundingMode
Rounding mode.
Definition: FloatingPointMode.h:36
llvm::detail::DoubleAPFloat::operator=
DoubleAPFloat & operator=(const DoubleAPFloat &RHS)
Definition: APFloat.cpp:4556
llvm::APFloatBase::opInexact
@ opInexact
Definition: APFloat.h:222
llvm::detail::IEEEFloat::remainder
opStatus remainder(const IEEEFloat &)
IEEE remainder.
Definition: APFloat.cpp:1963
llvm::detail::DoubleAPFloat::remainder
opStatus remainder(const DoubleAPFloat &RHS)
Definition: APFloat.cpp:4804
llvm::APFloat::isNaN
bool isNaN() const
Definition: APFloat.h:1227
llvm::detail::IEEEFloat::fusedMultiplyAdd
opStatus fusedMultiplyAdd(const IEEEFloat &, const IEEEFloat &, roundingMode)
Definition: APFloat.cpp:2092
llvm::APFloatBase::opOK
@ opOK
Definition: APFloat.h:217
llvm::APFloatBase::Bogus
static const fltSemantics & Bogus() LLVM_READNONE
A Pseudo fltsemantic used to construct APFloats that cannot conflict with anything real.
Definition: APFloat.cpp:216
llvm::detail::DoubleAPFloat::makeSmallest
void makeSmallest(bool Neg)
Definition: APFloat.cpp:4892
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
First
into llvm powi allowing the code generator to produce balanced multiplication trees First
Definition: README.txt:54
llvm::APFloat::isNegative
bool isNegative() const
Definition: APFloat.h:1229
llvm::APFloat::convertToDouble
double convertToDouble() const
Converts this APFloat to host double value.
Definition: APFloat.cpp:5176
llvm::APFloatBase::fltCategory
fltCategory
Category of internally-represented number.
Definition: APFloat.h:226
llvm::APFloatBase::S_IEEEquad
@ S_IEEEquad
Definition: APFloat.h:156
llvm::APFloat::bitwiseIsEqual
bool bitwiseIsEqual(const APFloat &RHS) const
Definition: APFloat.h:1194
llvm::detail::IEEEFloat::makeInf
void makeInf(bool Neg=false)
Definition: APFloat.cpp:4423
llvm::APSInt
An arbitrary precision integer that knows its signedness.
Definition: APSInt.h:23
llvm::detail::IEEEFloat::isDenormal
bool isDenormal() const
IEEE-754R isSubnormal(): Returns true if and only if the float is a denormal.
Definition: APFloat.cpp:872
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
llvm::detail::IEEEFloat::bitcastToAPInt
APInt bitcastToAPInt() const
Definition: APFloat.cpp:3541
llvm::APFloat::isNegInfinity
bool isNegInfinity() const
Definition: APFloat.h:1243
llvm::lfExactlyZero
@ lfExactlyZero
Definition: APFloat.h:49
llvm::APFloat::bitcastToAPInt
APInt bitcastToAPInt() const
Definition: APFloat.h:1144
llvm::detail::IEEEFloat::convertFromZeroExtendedInteger
opStatus convertFromZeroExtendedInteger(const integerPart *, unsigned int, bool, roundingMode)
Definition: APFloat.cpp:2649
llvm::APFloat::isLargest
bool isLargest() const
Definition: APFloat.h:1245
llvm::detail::DoubleAPFloat::makeSmallestNormalized
void makeSmallestNormalized(bool Neg)
Definition: APFloat.cpp:4898
c
the resulting code requires compare and branches when and if the revised code is with conditional branches instead of More there is a byte word extend before each where there should be only and the condition codes are not remembered when the same two values are compared twice More LSR enhancements i8 and i32 load store addressing modes are identical int int c
Definition: README.txt:418
llvm::APFloat::operator>
bool operator>(const APFloat &RHS) const
Definition: APFloat.h:1170
llvm::APFloat::scalbn
friend APFloat scalbn(APFloat X, int Exp, roundingMode RM)
llvm::APFloat::isPosInfinity
bool isPosInfinity() const
Definition: APFloat.h:1242
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
llvm::APFloat::subtract
opStatus subtract(const APFloat &RHS, roundingMode RM)
Definition: APFloat.h:993
llvm::detail::IEEEFloat::getCategory
fltCategory getCategory() const
Definition: APFloat.h:385
llvm::maxnum
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE maxNum semantics.
Definition: APFloat.h:1327
llvm::APFloat::APFloat
APFloat(const fltSemantics &Semantics, integerPart I)
Definition: APFloat.h:879
llvm::detail::IEEEFloat::scalbn
friend IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
Returns: X * 2^Exp for integral exponents.
llvm::APFloat::multiply
opStatus multiply(const APFloat &RHS, roundingMode RM)
Definition: APFloat.h:1002
llvm::APFloat::getQNaN
static APFloat getQNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for QNaN values.
Definition: APFloat.h:930
llvm::detail::DoubleAPFloat::divide
opStatus divide(const DoubleAPFloat &RHS, roundingMode RM)
Definition: APFloat.cpp:4794
llvm::APFloat::copySign
void copySign(const APFloat &RHS)
Definition: APFloat.h:1105
llvm::APFloatBase::IEK_Zero
@ IEK_Zero
Definition: APFloat.h:240
llvm::APFloat::convertFromString
Expected< opStatus > convertFromString(StringRef, roundingMode)
Definition: APFloat.cpp:5097
llvm::APFloat
Definition: APFloat.h:722
llvm::APFloat::changeSign
void changeSign()
Definition: APFloat.h:1100
llvm::detail::IEEEFloat::isNegZero
bool isNegZero() const
Definition: APFloat.h:390
llvm::APFloat::isNormal
bool isNormal() const
Definition: APFloat.h:1233
llvm::APFloat::ilogb
friend int ilogb(const APFloat &Arg)
Definition: APFloat.h:1270
llvm::APFloat::~APFloat
~APFloat()=default
llvm::APFloat::roundToIntegral
opStatus roundToIntegral(roundingMode RM)
Definition: APFloat.h:1051
uint64_t
llvm::APFloatBase::cmpResult
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
Definition: APFloat.h:190
const
aarch64 promote const
Definition: AArch64PromoteConstant.cpp:232
llvm::APFloatBase::cmpUnordered
@ cmpUnordered
Definition: APFloat.h:194
llvm::APFloat::operator-
APFloat operator-() const
Negate an APFloat.
Definition: APFloat.h:1062
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::neg
APFloat neg(APFloat X)
Returns the negated value of the argument.
Definition: APFloat.h:1308
llvm::APFloat::operator!=
bool operator!=(const APFloat &RHS) const
Definition: APFloat.h:1164
llvm::APFloat::isFinite
bool isFinite() const
Definition: APFloat.h:1234
semantics
Vector Shift Left don t map to llvm shl and because they have different semantics
Definition: README_P9.txt:119
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::detail::DoubleAPFloat::convertToHexString
unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
Definition: APFloat.cpp:4997
llvm::detail::IEEEFloat::convertFromAPInt
opStatus convertFromAPInt(const APInt &, bool, roundingMode)
Definition: APFloat.cpp:2605
llvm::detail::IEEEFloat::isNonZero
bool isNonZero() const
Definition: APFloat.h:387
llvm::APFloat::Profile
void Profile(FoldingSetNodeID &NID) const
Used to insert APFloat objects, or objects that contain APFloat objects, into FoldingSets.
Definition: APFloat.cpp:5156
llvm::APFloatBase::fcZero
@ fcZero
Definition: APFloat.h:230
ArrayRef.h
llvm::detail::IEEEFloat::convertFromString
Expected< opStatus > convertFromString(StringRef, roundingMode)
Definition: APFloat.cpp:3035
llvm::detail::DoubleAPFloat::fusedMultiplyAdd
opStatus fusedMultiplyAdd(const DoubleAPFloat &Multiplicand, const DoubleAPFloat &Addend, roundingMode RM)
Definition: APFloat.cpp:4822
llvm::APFloatBase::PPCDoubleDouble
static const fltSemantics & PPCDoubleDouble() LLVM_READNONE
Definition: APFloat.cpp:208
llvm::detail::DoubleAPFloat::getExactInverse
bool getExactInverse(APFloat *inv) const
Definition: APFloat.cpp:5052
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::APFloat::APFloat
APFloat(double d)
Definition: APFloat.h:887
llvm::APFloatBase::Float8E4M3FN
static const fltSemantics & Float8E4M3FN() LLVM_READNONE
Definition: APFloat.cpp:212
llvm::detail::DoubleAPFloat::convertFromSignExtendedInteger
opStatus convertFromSignExtendedInteger(const integerPart *Input, unsigned int InputSize, bool IsSigned, roundingMode RM)
Definition: APFloat.cpp:4976
llvm::detail::IEEEFloat::changeSign
void changeSign()
Definition: APFloat.cpp:1879
llvm::APFloat::getCategory
fltCategory getCategory() const
Definition: APFloat.h:1236
llvm::APFloat::operator-
APFloat operator-(const APFloat &RHS) const
Subtract two APFloats, rounding ties to the nearest even.
Definition: APFloat.h:1078
llvm::RoundingMode::TowardNegative
@ TowardNegative
roundTowardNegative.
llvm::detail::IEEEFloat::toString
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:4022
llvm::detail::DoubleAPFloat::roundToIntegral
opStatus roundToIntegral(roundingMode RM)
Definition: APFloat.cpp:4834
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
llvm::detail::IEEEFloat::isFinite
bool isFinite() const
Returns true if and only if the current value is zero, subnormal, or normal.
Definition: APFloat.h:362
llvm::detail::IEEEFloat::convertFromSignExtendedInteger
opStatus convertFromSignExtendedInteger(const integerPart *, unsigned int, bool, roundingMode)
Definition: APFloat.cpp:2623
llvm::detail::DoubleAPFloat::getFirst
APFloat & getFirst()
Definition: APFloat.h:654
llvm::AArch64::RM
@ RM
Definition: AArch64ISelLowering.h:499
llvm::APFloat::dump
void dump() const
Definition: APFloat.cpp:5153
llvm::scalbn
APFloat scalbn(APFloat X, int Exp, APFloat::roundingMode RM)
Definition: APFloat.h:1282
llvm::APFloat::isSignaling
bool isSignaling() const
Definition: APFloat.h:1231
llvm::APFloat::operator/
APFloat operator/(const APFloat &RHS) const
Divide the first APFloat by the second, rounding ties to the nearest even.
Definition: APFloat.h:1094
llvm::APFloatBase::rmNearestTiesToAway
static constexpr roundingMode rmNearestTiesToAway
Definition: APFloat.h:205
llvm::APFloat::isSmallestNormalized
bool isSmallestNormalized() const
Definition: APFloat.h:1249
llvm::APFloatBase::IEEEdouble
static const fltSemantics & IEEEdouble() LLVM_READNONE
Definition: APFloat.cpp:204
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::APFloat::isPosZero
bool isPosZero() const
Definition: APFloat.h:1240
llvm::APFloatBase::opInvalidOp
@ opInvalidOp
Definition: APFloat.h:218
llvm::detail::IEEEFloat::isZero
bool isZero() const
Returns true if and only if the float is plus or minus zero.
Definition: APFloat.h:365
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::APFloatBase::SemanticsToEnum
static Semantics SemanticsToEnum(const llvm::fltSemantics &Sem)
Definition: APFloat.cpp:172
llvm::detail::DoubleAPFloat::convertFromZeroExtendedInteger
opStatus convertFromZeroExtendedInteger(const integerPart *Input, unsigned int InputSize, bool IsSigned, roundingMode RM)
Definition: APFloat.cpp:4987
llvm::FoldingSetNodeID
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:318
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::detail::hash_value
hash_code hash_value(const IEEEFloat &Arg)
Definition: APFloat.cpp:3237
llvm::detail::DoubleAPFloat::bitwiseIsEqual
bool bitwiseIsEqual(const DoubleAPFloat &RHS) const
Definition: APFloat.cpp:4919
llvm::detail::IEEEFloat::operator==
bool operator==(const IEEEFloat &) const =delete
The definition of equality is not straightforward for floating point, so we won't use operator==.
llvm::APFloat::needsCleanup
bool needsCleanup() const
Definition: APFloat.h:894
llvm::APFloat::APFloat
APFloat(const fltSemantics &Semantics, const APInt &I)
Definition: APFloat.h:886
llvm::APFloatBase::EnumToSemantics
static const llvm::fltSemantics & EnumToSemantics(Semantics S)
Definition: APFloat.cpp:147
llvm::APFloatBase
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
Definition: APFloat.h:142
llvm::detail::IEEEFloat::mod
opStatus mod(const IEEEFloat &)
C fmod, or llvm frem.
Definition: APFloat.cpp:2068
llvm::detail::DoubleAPFloat::multiply
opStatus multiply(const DoubleAPFloat &RHS, roundingMode RM)
Definition: APFloat.cpp:4708
llvm::RoundingMode::NearestTiesToAway
@ NearestTiesToAway
roundTiesToAway.
llvm::APFloatBase::S_Float8E5M2
@ S_Float8E5M2
Definition: APFloat.h:160
APFLOAT_DISPATCH_ON_SEMANTICS
#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL)
Definition: APFloat.h:24
llvm::APFloat::convertFromSignExtendedInteger
opStatus convertFromSignExtendedInteger(const integerPart *Input, unsigned int InputSize, bool IsSigned, roundingMode RM)
Definition: APFloat.h:1131
llvm::RoundingMode::TowardZero
@ TowardZero
roundTowardZero.
llvm::APFloat::copySign
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:1112
llvm::detail::DoubleAPFloat::subtract
opStatus subtract(const DoubleAPFloat &RHS, roundingMode RM)
Definition: APFloat.cpp:4700
llvm::APFloat::getSmallest
static APFloat getSmallest(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) finite number in the given semantics.
Definition: APFloat.h:958
llvm::APFloatBase::rmTowardPositive
static constexpr roundingMode rmTowardPositive
Definition: APFloat.h:202
LLVM_READNONE
#define LLVM_READNONE
Definition: Compiler.h:189
llvm::detail::IEEEFloat::next
opStatus next(bool nextDown)
IEEE-754R 5.3.1: nextUp/nextDown.
Definition: APFloat.cpp:4287
llvm::APFloatBase::rmTowardZero
static constexpr roundingMode rmTowardZero
Definition: APFloat.h:204
llvm::minnum
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
Definition: APFloat.h:1316
llvm::APFloatBase::S_Float8E4M3FN
@ S_Float8E4M3FN
Definition: APFloat.h:165
llvm::APFloat::hash_value
friend hash_code hash_value(const APFloat &Arg)
See friend declarations above.
Definition: APFloat.cpp:5102
llvm::detail::DoubleAPFloat::isLargest
bool isLargest() const
Definition: APFloat.cpp:5030
llvm::APFloat::clearSign
void clearSign()
Definition: APFloat.h:1101
llvm::detail::IEEEFloat::getExactInverse
bool getExactInverse(APFloat *inv) const
If this value has an exact multiplicative inverse, store it in inv and return true.
Definition: APFloat.cpp:4243
llvm::APFloat::print
void print(raw_ostream &) const
Definition: APFloat.cpp:5146
llvm::APFloat::APFloat
APFloat(float f)
Definition: APFloat.h:888
llvm::detail::DoubleAPFloat::convertToInteger
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
Definition: APFloat.cpp:4957
llvm::APFloatBase::S_PPCDoubleDouble
@ S_PPCDoubleDouble
Definition: APFloat.h:157
llvm::fltSemantics
Definition: APFloat.cpp:71
llvm::detail::DoubleAPFloat::getFirst
const APFloat & getFirst() const
Definition: APFloat.h:655
llvm::detail::IEEEFloat::isNegative
bool isNegative() const
IEEE-754R isSignMinus: Returns true if and only if the current value is negative.
Definition: APFloat.h:350
llvm::APFloat::operator*
APFloat operator*(const APFloat &RHS) const
Multiply two APFloats, rounding ties to the nearest even.
Definition: APFloat.h:1086
llvm::APFloat::operator=
APFloat & operator=(const APFloat &RHS)=default
llvm::detail::IEEEFloat::isNormal
bool isNormal() const
IEEE-754R isNormal: Returns true if and only if the current value is normal.
Definition: APFloat.h:356
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::APFloatBase::fcNormal
@ fcNormal
Definition: APFloat.h:229
llvm::detail::IEEEFloat::makeSmallestNormalized
void makeSmallestNormalized(bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
Definition: APFloat.cpp:3913
llvm::detail::IEEEFloat::convertToDouble
double convertToDouble() const
Definition: APFloat.cpp:3578
llvm::APFloat::remainder
opStatus remainder(const APFloat &RHS)
Definition: APFloat.h:1020
llvm::detail::IEEEFloat::convertToFloat
float convertToFloat() const
Definition: APFloat.cpp:3571
llvm::detail::frexp
IEEEFloat frexp(const IEEEFloat &Val, int &Exp, IEEEFloat::roundingMode RM)
Definition: APFloat.cpp:4487
llvm::AMDGPU::VOPD::DST
@ DST
Definition: AMDGPUBaseInfo.h:537
llvm::detail::IEEEFloat::frexp
friend IEEEFloat frexp(const IEEEFloat &X, int &Exp, roundingMode)
llvm::APFloatBase::integerPartWidth
static constexpr unsigned integerPartWidth
Definition: APFloat.h:144
llvm::frexp
APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM)
Equivalent of C standard library function.
Definition: APFloat.h:1294
llvm::AMDGPU::Hwreg::Width
Width
Definition: SIDefines.h:439
llvm::detail::IEEEFloat::isSignaling
bool isSignaling() const
Returns true if and only if the float is a signaling NaN.
Definition: APFloat.cpp:4272
llvm::APFloat::isExactlyValue
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:1212
llvm::hash_value
hash_code hash_value(const FixedPointSemantics &Val)
Definition: APFixedPoint.h:128
llvm::detail::IEEEFloat::isPosZero
bool isPosZero() const
Definition: APFloat.h:389
llvm::APFloat::getAllOnesValue
static APFloat getAllOnesValue(const fltSemantics &Semantics)
Returns a float which is bitcasted from an all one value int.
Definition: APFloat.cpp:5142
llvm::APFloat::operator>=
bool operator>=(const APFloat &RHS) const
Definition: APFloat.h:1179
llvm::APFloatBase::rmNearestTiesToEven
static constexpr roundingMode rmNearestTiesToEven
Definition: APFloat.h:200
llvm::detail::DoubleAPFloat::getSecond
APFloat & getSecond()
Definition: APFloat.h:656
llvm::APFloat::convert
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Definition: APFloat.cpp:5117
llvm::APFloat::toString
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
Definition: APFloat.h:1256
llvm::APInt::APINT_BITS_PER_WORD
@ APINT_BITS_PER_WORD
Bits in a word.
Definition: APInt.h:84
llvm::APFloatBase::S_IEEEhalf
@ S_IEEEhalf
Definition: APFloat.h:152
llvm::APFloat::convertFromZeroExtendedInteger
opStatus convertFromZeroExtendedInteger(const integerPart *Input, unsigned int InputSize, bool IsSigned, roundingMode RM)
Definition: APFloat.h:1137
llvm::APFloatBase::S_IEEEdouble
@ S_IEEEdouble
Definition: APFloat.h:155
llvm::APFloatBase::fcInfinity
@ fcInfinity
Definition: APFloat.h:227
llvm::RoundingMode::TowardPositive
@ TowardPositive
roundTowardPositive.
llvm::detail::IEEEFloat::needsCleanup
bool needsCleanup() const
Returns whether this instance allocated memory.
Definition: APFloat.h:275
llvm::APFloatBase::semanticsPrecision
static unsigned int semanticsPrecision(const fltSemantics &)
Definition: APFloat.cpp:240
llvm::detail::DoubleAPFloat::compare
cmpResult compare(const DoubleAPFloat &RHS) const
Definition: APFloat.cpp:4911
llvm::APFloat::getNaN
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
Definition: APFloat.h:919
llvm::detail::IEEEFloat::hash_value
friend hash_code hash_value(const IEEEFloat &Arg)
Overload to compute a hash code for an APFloat value.
Definition: APFloat.cpp:3237
llvm::detail::IEEEFloat::getSemantics
const fltSemantics & getSemantics() const
Definition: APFloat.h:386
llvm::detail::DoubleAPFloat::bitcastToAPInt
APInt bitcastToAPInt() const
Definition: APFloat.cpp:4930
llvm::detail::IEEEFloat::makeQuiet
void makeQuiet()
Definition: APFloat.cpp:4442
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
llvm::detail::IEEEFloat::IEEEFloat
IEEEFloat(const fltSemantics &)
Definition: APFloat.cpp:1028
llvm::detail::IEEEFloat::isFiniteNonZero
bool isFiniteNonZero() const
Definition: APFloat.h:388
llvm::detail::DoubleAPFloat::getCategory
fltCategory getCategory() const
Definition: APFloat.cpp:4868
llvm::APFloat::APFloat
APFloat(const fltSemantics &Semantics, uninitializedTag)
Definition: APFloat.h:884
llvm::APFloatBase::ExponentType
int32_t ExponentType
A signed type to represent a floating point numbers unbiased exponent.
Definition: APFloat.h:147
llvm::APFloat::getInf
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
Definition: APFloat.h:908
llvm::detail::DoubleAPFloat::next
opStatus next(bool nextDown)
Definition: APFloat.cpp:4948
llvm::APFloat::compare
cmpResult compare(const APFloat &RHS) const
Definition: APFloat.h:1184
llvm::APFloat::convertFromAPInt
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
Definition: APFloat.h:1127
llvm::detail::DoubleAPFloat::isSmallest
bool isSmallest() const
Definition: APFloat.cpp:5013
llvm::detail::IEEEFloat::compare
cmpResult compare(const IEEEFloat &) const
IEEE comparison with another floating point number (NaNs compare unordered, 0==-0).
Definition: APFloat.cpp:2222
llvm::APFloatBase::IlogbErrorKinds
IlogbErrorKinds
Enumeration of ilogb error results.
Definition: APFloat.h:239
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:394
llvm::detail::DoubleAPFloat::isDenormal
bool isDenormal() const
Definition: APFloat.cpp:5006
llvm::detail::scalbn
IEEEFloat scalbn(IEEEFloat X, int Exp, IEEEFloat::roundingMode)
Definition: APFloat.cpp:4466
llvm::detail::IEEEFloat::subtract
opStatus subtract(const IEEEFloat &, roundingMode)
Definition: APFloat.cpp:1921
llvm::detail::IEEEFloat::ilogb
friend int ilogb(const IEEEFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
Definition: APFloat.cpp:4448
d
the resulting code requires compare and branches when and if the revised code is with conditional branches instead of More there is a byte word extend before each where there should be only and the condition codes are not remembered when the same two values are compared twice More LSR enhancements i8 and i32 load store addressing modes are identical int int int d
Definition: README.txt:418
llvm::APFloatBase::uninitializedTag
uninitializedTag
Convenience enum used to construct an uninitialized APFloat.
Definition: APFloat.h:234
llvm::APFloatBase::Semantics
Semantics
Definition: APFloat.h:151
llvm::APFloatBase::cmpEqual
@ cmpEqual
Definition: APFloat.h:192
llvm::APFloat::operator<
bool operator<(const APFloat &RHS) const
Definition: APFloat.h:1166
llvm::APFloat::isNegZero
bool isNegZero() const
Definition: APFloat.h:1241
llvm::APFloatBase::fcNaN
@ fcNaN
Definition: APFloat.h:228
llvm::abs
APFloat abs(APFloat X)
Returns the absolute value of the argument.
Definition: APFloat.h:1302
llvm::APFloatBase::roundingMode
llvm::RoundingMode roundingMode
IEEE-754R 4.3: Rounding-direction attributes.
Definition: APFloat.h:198
llvm::APFloatBase::cmpLessThan
@ cmpLessThan
Definition: APFloat.h:191
llvm::RoundingMode::NearestTiesToEven
@ NearestTiesToEven
roundTiesToEven.
llvm::detail::DoubleAPFloat::isSmallestNormalized
bool isSmallestNormalized() const
Definition: APFloat.cpp:5021
llvm::APFloat::getLargest
static APFloat getLargest(const fltSemantics &Sem, bool Negative=false)
Returns the largest finite number in the given semantics.
Definition: APFloat.h:948
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::APFloat::getSmallestNormalized
static APFloat getSmallestNormalized(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
Definition: APFloat.h:968
llvm::APFloatBase::S_MaxSemantics
@ S_MaxSemantics
Definition: APFloat.h:167
llvm::detail::IEEEFloat::operator=
IEEEFloat & operator=(const IEEEFloat &)
Definition: APFloat.cpp:847
llvm::APFloatBase::semanticsMaxExponent
static ExponentType semanticsMaxExponent(const fltSemantics &)
Definition: APFloat.cpp:244
llvm::APFloat::APFloat
APFloat(const fltSemantics &Semantics)
Definition: APFloat.h:877
llvm::detail::IEEEFloat::convertToHexString
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:3088
llvm::detail::IEEEFloat::isNaN
bool isNaN() const
Returns true if and only if the float is a quiet or signaling NaN.
Definition: APFloat.h:375
llvm::hash_code
An opaque object representing a hash code.
Definition: Hashing.h:74
llvm::detail::IEEEFloat::convertToInteger
opStatus convertToInteger(MutableArrayRef< integerPart >, unsigned int, bool, roundingMode, bool *) const
Definition: APFloat.cpp:2545
llvm::APFloatBase::semanticsMinExponent
static ExponentType semanticsMinExponent(const fltSemantics &)
Definition: APFloat.cpp:248
llvm::APFloat::operator<=
bool operator<=(const APFloat &RHS) const
Definition: APFloat.h:1174
llvm::APFloatBase::uninitialized
@ uninitialized
Definition: APFloat.h:235