//
// The LLVM Compiler Infrastructure
//
-// This file was developed by Neil Booth and is distributed under the
-// University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// APInt contains static functions implementing bignum arithmetic.
#include "llvm/ADT/APInt.h"
-#include "llvm/CodeGen/ValueTypes.h"
namespace llvm {
/* When bits of a floating point number are truncated, this enum is
used to indicate what fraction of the LSB those bits represented.
It essentially combines the roles of guard and sticky bits. */
- enum lostFraction { // Example of truncated bits:
- lfExactlyZero, // 000000
- lfLessThanHalf, // 0xxxxx x's not all zero
- lfExactlyHalf, // 100000
- lfMoreThanHalf // 1xxxxx x's not all zero
+ enum lostFraction { // Example of truncated bits:
+ lfExactlyZero, // 000000
+ lfLessThanHalf, // 0xxxxx x's not all zero
+ lfExactlyHalf, // 100000
+ lfMoreThanHalf // 1xxxxx x's not all zero
};
class APFloat {
static const fltSemantics IEEEquad;
static const fltSemantics PPCDoubleDouble;
static const fltSemantics x87DoubleExtended;
- /* And this psuedo, used to construct APFloats that cannot
+ /* And this pseudo, used to construct APFloats that cannot
conflict with anything real. */
static const fltSemantics Bogus;
rmNearestTiesToAway
};
- /* Operation status. opUnderflow or opOverflow are always returned
- or-ed with opInexact. */
+ // Operation status. opUnderflow or opOverflow are always returned
+ // or-ed with opInexact.
enum opStatus {
opOK = 0x00,
opInvalidOp = 0x01,
opInexact = 0x10
};
- /* Category of internally-represented number. */
+ // Category of internally-represented number.
enum fltCategory {
fcInfinity,
fcNaN,
fcZero
};
- /* Constructors. */
+ // Constructors.
APFloat(const fltSemantics &, const char *);
APFloat(const fltSemantics &, integerPart);
APFloat(const fltSemantics &, fltCategory, bool negative);
APFloat(const APFloat &);
~APFloat();
+ // Convenience "constructors"
+ static APFloat getZero(const fltSemantics &Sem, bool Negative = false) {
+ return APFloat(Sem, fcZero, Negative);
+ }
+ static APFloat getInf(const fltSemantics &Sem, bool Negative = false) {
+ return APFloat(Sem, fcInfinity, Negative);
+ }
+ static APFloat getNaN(const fltSemantics &Sem, bool Negative = false) {
+ return APFloat(Sem, fcNaN, Negative);
+ }
+
+ /// Profile - Used to insert APFloat objects, or objects that contain
+ /// APFloat objects, into FoldingSets.
+ void Profile(FoldingSetNodeID& NID) const;
+
+ /// @brief Used by the Bitcode serializer to emit APInts to Bitcode.
+ void Emit(Serializer& S) const;
+
+ /// @brief Used by the Bitcode deserializer to deserialize APInts.
+ static APFloat ReadVal(Deserializer& D);
+
/* Arithmetic. */
opStatus add(const APFloat &, roundingMode);
opStatus subtract(const APFloat &, roundingMode);
opStatus multiply(const APFloat &, roundingMode);
opStatus divide(const APFloat &, roundingMode);
+ /* IEEE remainder. */
+ opStatus remainder(const APFloat &);
+ /* C fmod, or llvm frem. */
opStatus mod(const APFloat &, roundingMode);
opStatus fusedMultiplyAdd(const APFloat &, const APFloat &, roundingMode);
void copySign(const APFloat &);
/* Conversions. */
- opStatus convert(const fltSemantics &, roundingMode);
+ opStatus convert(const fltSemantics &, roundingMode, bool *);
opStatus convertToInteger(integerPart *, unsigned int, bool,
- roundingMode) const;
+ roundingMode, bool *) const;
+ opStatus convertFromAPInt(const APInt &,
+ bool, roundingMode);
opStatus convertFromSignExtendedInteger(const integerPart *, unsigned int,
bool, roundingMode);
opStatus convertFromZeroExtendedInteger(const integerPart *, unsigned int,
bool, roundingMode);
opStatus convertFromString(const char *, roundingMode);
- APInt convertToAPInt() const;
+ APInt bitcastToAPInt() const;
double convertToDouble() const;
float convertToFloat() const;
compare unordered, 0==-0). */
cmpResult compare(const APFloat &) const;
+ /* Bitwise comparison for equality (QNaNs compare equal, 0!=-0). */
+ bool bitwiseIsEqual(const APFloat &) const;
+
/* Write out a hexadecimal representation of the floating point
value to DST, which must be of sufficient size, in the C99 form
[-]0xh.hhhhp[+-]d. Return the number of characters written,
unsigned int convertToHexString(char *dst, unsigned int hexDigits,
bool upperCase, roundingMode) const;
- /* Bitwise comparison for equality (QNaNs compare equal, 0!=-0). */
- bool bitwiseIsEqual(const APFloat &) const;
-
/* Simple queries. */
fltCategory getCategory() const { return category; }
const fltSemantics &getSemantics() const { return *semantics; }
bool isZero() const { return category == fcZero; }
bool isNonZero() const { return category != fcZero; }
+ bool isNaN() const { return category == fcNaN; }
+ bool isInfinity() const { return category == fcInfinity; }
bool isNegative() const { return sign; }
bool isPosZero() const { return isZero() && !isNegative(); }
bool isNegZero() const { return isZero() && isNegative(); }
opStatus addOrSubtractSpecials(const APFloat &, bool subtract);
opStatus divideSpecials(const APFloat &);
opStatus multiplySpecials(const APFloat &);
+ opStatus modSpecials(const APFloat &);
/* Miscellany. */
void makeNaN(void);
cmpResult compareAbsoluteValue(const APFloat &) const;
opStatus handleOverflow(roundingMode);
bool roundAwayFromZero(roundingMode, lostFraction, unsigned int) const;
+ opStatus convertToSignExtendedInteger(integerPart *, unsigned int, bool,
+ roundingMode, bool *) const;
opStatus convertFromUnsignedParts(const integerPart *, unsigned int,
roundingMode);
opStatus convertFromHexadecimalString(const char *, roundingMode);