LLVM: include/llvm/ADT/APFixedPoint.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16#ifndef LLVM_ADT_APFIXEDPOINT_H

17#define LLVM_ADT_APFIXEDPOINT_H

18

23

24namespace llvm {

25

27struct fltSemantics;

28

29

30

31

32

33

35public:

38

39

42 };

44 bool IsSaturated, bool HasUnsignedPadding)

46 IsSaturated, HasUnsignedPadding) {}

48 bool IsSaturated, bool HasUnsignedPadding)

49 : Width(Width), LsbWeight(Weight.LsbWeight), IsSigned(IsSigned),

50 IsSaturated(IsSaturated), HasUnsignedPadding(HasUnsignedPadding) {

51 assert(isUInt(Width) && isInt(Weight.LsbWeight));

52 assert(!(IsSigned && HasUnsignedPadding) &&

53 "Cannot have unsigned padding on a signed type.");

54 }

55

56

57

59 return LsbWeight <= 0 && static_cast(Width) >= -LsbWeight;

60 }

61 unsigned getWidth() const { return Width; }

65 return LsbWeight + Width - 1 ;

66 }

67 bool isSigned() const { return IsSigned; }

70

71 void setSaturated(bool Saturated) { IsSaturated = Saturated; }

72

73

75

76

77

78

81 }

82

83

84

85

86

89

90

92

93

94

95

96

97

98

99

101

102

104 bool IsSigned) {

106 false,

107 false);

108 }

109

111 return Width == Other.Width && LsbWeight == Other.LsbWeight &&

112 IsSigned == Other.IsSigned && IsSaturated == Other.IsSaturated &&

113 HasUnsignedPadding == Other.HasUnsignedPadding;

114 }

116

117

118

119

120

122

123

125

126private:

129 unsigned IsSigned : 1;

130 unsigned IsSaturated : 1;

131 unsigned HasUnsignedPadding : 1;

132};

133

134static_assert(sizeof(FixedPointSemantics) == 4, "");

135

137 return hash_value(bit_cast<uint32_t>(Val));

138}

139

143 }

144

147 }

148

151 }

152

154};

155

156

157

158

159

160

161

163public:

165 : Val(Val, !Sema.isSigned()), Sema(Sema) {

167 "The value should have a bit width that matches the Sema width");

168 }

169

172 true),

173 Sema) {}

174

175

177

187

189

190

191

192

194 bool *Overflow = nullptr) const;

195

196

197

198

199

204

205

206

207

208 APFixedPoint shl(unsigned Amt, bool *Overflow = nullptr) const;

210

211 if (Overflow)

212 *Overflow = false;

214 }

215

216

217

219

220

221

227 if (Val < 0 && Val != -Val)

228 return -((-ExtVal).relativeShl(getLsbWeight()));

230 }

231

232

233

234

235

236

238 bool *Overflow = nullptr) const;

239

240

241

243

248 return std::string(S);

249 }

250

252 void dump() const;

253

254

258 }

261 }

266 }

269 }

270

274

275

276

278

279

280

281

282

285 bool *Overflow = nullptr);

286

287

288

289

290

291

292

293

296 bool *Overflow = nullptr);

297

298private:

301};

302

305 return OS;

306}

307

310}

311

315 }

316

319 }

320

323 }

324

326 return LHS.getSemantics() == RHS.getSemantics() &&

327 LHS.getValue() == RHS.getValue();

328 }

329};

330

331}

332

333#endif

This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

This file defines the SmallString class.

The APFixedPoint class works similarly to APInt/APSInt in that it is a functional replacement for a s...

void toString(SmallVectorImpl< char > &Str) const

APFixedPoint(const APInt &Val, const FixedPointSemantics &Sema)

static APFixedPoint getMin(const FixedPointSemantics &Sema)

bool operator==(const APFixedPoint &Other) const

bool operator!=(const APFixedPoint &Other) const

FixedPointSemantics getSemantics() const

int compare(const APFixedPoint &Other) const

bool operator<(const APFixedPoint &Other) const

APSInt convertToInt(unsigned DstWidth, bool DstSign, bool *Overflow=nullptr) const

Return the integral part of this fixed point number, rounded towards zero.

APFixedPoint shr(unsigned Amt, bool *Overflow=nullptr) const

static APFixedPoint getFromFloatValue(const APFloat &Value, const FixedPointSemantics &DstFXSema, bool *Overflow=nullptr)

Create an APFixedPoint with a value equal to that of the provided floating point value,...

APFixedPoint(const FixedPointSemantics &Sema)

APFixedPoint sub(const APFixedPoint &Other, bool *Overflow=nullptr) const

APFloat convertToFloat(const fltSemantics &FloatSema) const

Convert this fixed point number to a floating point value with the provided semantics.

APFixedPoint(uint64_t Val, const FixedPointSemantics &Sema)

static APFixedPoint getFromIntValue(const APSInt &Value, const FixedPointSemantics &DstFXSema, bool *Overflow=nullptr)

Create an APFixedPoint with a value equal to that of the provided integer, and in the same semantics ...

unsigned getScale() const

std::string toString() const

void print(raw_ostream &) const

unsigned getWidth() const

bool operator>=(const APFixedPoint &Other) const

APFixedPoint negate(bool *Overflow=nullptr) const

Perform a unary negation (-X) on this fixed point type, taking into account saturation if applicable.

APFixedPoint shl(unsigned Amt, bool *Overflow=nullptr) const

bool operator<=(const APFixedPoint &Other) const

bool operator>(const APFixedPoint &Other) const

static APFixedPoint getEpsilon(const FixedPointSemantics &Sema)

static const fltSemantics * promoteFloatSemantics(const fltSemantics *S)

Given a floating point semantic, return the next floating point semantic with a larger exponent and l...

APFixedPoint div(const APFixedPoint &Other, bool *Overflow=nullptr) const

APFixedPoint mul(const APFixedPoint &Other, bool *Overflow=nullptr) const

APSInt getIntPart() const

Return the integral part of this fixed point number, rounded towards zero.

APFixedPoint add(const APFixedPoint &Other, bool *Overflow=nullptr) const

bool getBoolValue() const

static APFixedPoint getMax(const FixedPointSemantics &Sema)

Class for arbitrary precision integers.

unsigned getBitWidth() const

Return the number of bits in the APInt.

bool getBoolValue() const

Convert APInt to a boolean value.

static APInt getZero(unsigned numBits)

Get the '0' value for the specified bit-width.

An arbitrary precision integer that knows its signedness.

APSInt relativeShl(unsigned Amt) const

APSInt extend(uint32_t width) const

The fixed point semantics work similarly to fltSemantics.

static FixedPointSemantics getFromOpaqueInt(uint32_t)

Create a FixedPointSemantics object from an integer created via toOpaqueInt().

static constexpr unsigned WidthBitWidth

unsigned getWidth() const

void setSaturated(bool Saturated)

bool hasUnsignedPadding() const

static constexpr unsigned LsbWeightBitWidth

unsigned getScale() const

unsigned getIntegralBits() const

Return the number of integral bits represented by these semantics.

FixedPointSemantics getCommonSemantics(const FixedPointSemantics &Other) const

Return the FixedPointSemantics that allows for calculating the full precision semantic that can preci...

bool operator!=(FixedPointSemantics Other) const

bool operator==(FixedPointSemantics Other) const

void print(llvm::raw_ostream &OS) const

Print semantics for debug purposes.

bool fitsInFloatSemantics(const fltSemantics &FloatSema) const

Returns true if this fixed-point semantic with its value bits interpreted as an integer can fit in th...

bool hasSignOrPaddingBit() const

return true if the first bit doesn't have a strictly positive weight

FixedPointSemantics(unsigned Width, Lsb Weight, bool IsSigned, bool IsSaturated, bool HasUnsignedPadding)

uint32_t toOpaqueInt() const

Convert the semantics to a 32-bit unsigned integer.

FixedPointSemantics(unsigned Width, unsigned Scale, bool IsSigned, bool IsSaturated, bool HasUnsignedPadding)

bool isValidLegacySema() const

Check if the Semantic follow the requirements of an older more limited version of this class.

static FixedPointSemantics GetIntegerSemantics(unsigned Width, bool IsSigned)

Return the FixedPointSemantics for an integer type.

SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...

This class consists of common code factored out of the SmallVector class to reduce code duplication b...

LLVM Value Representation.

An opaque object representing a hash code.

This class implements an extremely fast bulk output stream that can only output to a stream.

This is an optimization pass for GlobalISel generic memory operations.

hash_code hash_value(const FixedPointSemantics &Val)

raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)

hash_code hash_combine(const Ts &...args)

Combine values into a single hash_code.

static unsigned getHashValue(const APFixedPoint &Val)

static APFixedPoint getTombstoneKey()

static bool isEqual(const APFixedPoint &LHS, const APFixedPoint &RHS)

static APFixedPoint getEmptyKey()

static FixedPointSemantics getEmptyKey()

static bool isEqual(const char &LHS, const char &RHS)

static unsigned getHashValue(const FixedPointSemantics &Val)

static FixedPointSemantics getTombstoneKey()

An information struct used to provide DenseMap with the various necessary components for a given valu...

Used to differentiate between constructors with Width and Lsb from the default Width and scale.