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