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

24

25namespace llvm {

26

29

30

31

32

33

34

36public:

39

40

45 bool IsSaturated, bool HasUnsignedPadding)

47 IsSaturated, HasUnsignedPadding) {}

49 bool IsSaturated, bool HasUnsignedPadding)

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

51 IsSaturated(IsSaturated), HasUnsignedPadding(HasUnsignedPadding) {

53 assert(!(IsSigned && HasUnsignedPadding) &&

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

55 }

56

57

58

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

61 }

62 unsigned getWidth() const { return Width; }

66 return LsbWeight + Width - 1 ;

67 }

68 bool isSigned() const { return IsSigned; }

71

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

73

74

76

77

78

79

83

84

85

86

87

90

91

93

94

95

96

97

98

99

100

102

103

105 bool IsSigned) {

107 false,

108 false);

109 }

110

112 return Width == Other.Width && LsbWeight == Other.LsbWeight &&

113 IsSigned == Other.IsSigned && IsSaturated == Other.IsSaturated &&

114 HasUnsignedPadding == Other.HasUnsignedPadding;

115 }

117

118

119

120

121

123

124

126

127private:

130 unsigned IsSigned : 1;

131 unsigned IsSaturated : 1;

132 unsigned HasUnsignedPadding : 1;

133};

134

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

136

140

156

157

158

159

160

161

162

164public:

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

167 assert(Val.getBitWidth() == Sema.getWidth() &&

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

169 }

170

175

176

178

180 inline unsigned getWidth() const { return Sema.getWidth(); }

181 inline unsigned getScale() const { return Sema.getScale(); }

184 inline bool isSaturated() const { return Sema.isSaturated(); }

185 inline bool isSigned() const { return Sema.isSigned(); }

186 inline bool hasPadding() const { return Sema.hasUnsignedPadding(); }

188

190

191

192

193

195 bool *Overflow = nullptr) const;

196

197

198

199

200

202 bool *Overflow = nullptr) const;

204 bool *Overflow = nullptr) const;

206 bool *Overflow = nullptr) const;

208 bool *Overflow = nullptr) const;

209

210

211

212

215

216 if (Overflow)

217 *Overflow = false;

219 }

220

221

222

224

225

226

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

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

235 }

236

237

238

239

240

241

243 bool *Overflow = nullptr) const;

244

245

246

248

253 return std::string(S);

254 }

255

257

258#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

260#endif

261

262

278

282

283

284

287

288

289

290

291

294 bool *Overflow = nullptr);

295

296

297

298

299

300

301

302

305 bool *Overflow = nullptr);

306

307private:

310};

311

316

320

325

329

333

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

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

337 }

338};

339

340}

341

342#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

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

#define LLVM_DUMP_METHOD

Mark debug helper function definitions like dump() that should not be stripped from debug builds.

This file defines the SmallString class.

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

Definition APFixedPoint.h:163

LLVM_ABI APFixedPoint convert(const FixedPointSemantics &DstSema, bool *Overflow=nullptr) const

LLVM_ABI void toString(SmallVectorImpl< char > &Str) const

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

Definition APFixedPoint.h:165

static LLVM_ABI APFixedPoint getMin(const FixedPointSemantics &Sema)

bool operator==(const APFixedPoint &Other) const

Definition APFixedPoint.h:264

bool operator!=(const APFixedPoint &Other) const

Definition APFixedPoint.h:267

int getLsbWeight() const

Definition APFixedPoint.h:182

FixedPointSemantics getSemantics() const

Definition APFixedPoint.h:187

LLVM_ABI int compare(const APFixedPoint &Other) const

bool operator<(const APFixedPoint &Other) const

Definition APFixedPoint.h:271

LLVM_ABI 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

Definition APFixedPoint.h:214

static LLVM_ABI 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)

Definition APFixedPoint.h:177

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

LLVM_ABI 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)

Definition APFixedPoint.h:171

LLVM_DUMP_METHOD void dump() const

static LLVM_ABI 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

Definition APFixedPoint.h:181

std::string toString() const

Definition APFixedPoint.h:250

LLVM_ABI void print(raw_ostream &) const

APSInt getValue() const

Definition APFixedPoint.h:179

unsigned getWidth() const

Definition APFixedPoint.h:180

bool isSigned() const

Definition APFixedPoint.h:185

bool operator>=(const APFixedPoint &Other) const

Definition APFixedPoint.h:272

bool hasPadding() const

Definition APFixedPoint.h:186

LLVM_ABI APFixedPoint negate(bool *Overflow=nullptr) const

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

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

bool operator<=(const APFixedPoint &Other) const

Definition APFixedPoint.h:275

bool operator>(const APFixedPoint &Other) const

Definition APFixedPoint.h:270

bool isSaturated() const

Definition APFixedPoint.h:184

static LLVM_ABI APFixedPoint getEpsilon(const FixedPointSemantics &Sema)

static LLVM_ABI const fltSemantics * promoteFloatSemantics(const fltSemantics *S)

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

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

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

APSInt getIntPart() const

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

Definition APFixedPoint.h:227

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

bool getBoolValue() const

Definition APFixedPoint.h:189

int getMsbWeight() const

Definition APFixedPoint.h:183

static LLVM_ABI APFixedPoint getMax(const FixedPointSemantics &Sema)

Class for arbitrary precision integers.

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.

Definition APFixedPoint.h:35

bool isSigned() const

Definition APFixedPoint.h:68

static LLVM_ABI FixedPointSemantics getFromOpaqueInt(uint32_t)

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

static constexpr unsigned WidthBitWidth

Definition APFixedPoint.h:37

int getMsbWeight() const

Definition APFixedPoint.h:65

unsigned getWidth() const

Definition APFixedPoint.h:62

void setSaturated(bool Saturated)

Definition APFixedPoint.h:72

bool hasUnsignedPadding() const

Definition APFixedPoint.h:70

bool isSaturated() const

Definition APFixedPoint.h:69

static constexpr unsigned LsbWeightBitWidth

Definition APFixedPoint.h:38

unsigned getScale() const

Definition APFixedPoint.h:63

unsigned getIntegralBits() const

Return the number of integral bits represented by these semantics.

Definition APFixedPoint.h:80

LLVM_ABI 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

Definition APFixedPoint.h:116

bool operator==(FixedPointSemantics Other) const

Definition APFixedPoint.h:111

LLVM_ABI void print(llvm::raw_ostream &OS) const

Print semantics for debug purposes.

int getLsbWeight() const

Definition APFixedPoint.h:64

LLVM_ABI 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

Definition APFixedPoint.h:75

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

Definition APFixedPoint.h:48

LLVM_ABI uint32_t toOpaqueInt() const

Convert the semantics to a 32-bit unsigned integer.

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

Definition APFixedPoint.h:44

bool isValidLegacySema() const

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

Definition APFixedPoint.h:59

static FixedPointSemantics GetIntegerSemantics(unsigned Width, bool IsSigned)

Return the FixedPointSemantics for an integer type.

Definition APFixedPoint.h:104

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)

Definition APFixedPoint.h:137

constexpr bool isInt(int64_t x)

Checks if an integer fits into the given bit width.

constexpr bool isUInt(uint64_t x)

Checks if an unsigned integer fits into the given bit width.

To bit_cast(const From &from) noexcept

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

Definition APFixedPoint.h:312

hash_code hash_combine(const Ts &...args)

Combine values into a single hash_code.

static unsigned getHashValue(const APFixedPoint &Val)

Definition APFixedPoint.h:330

static APFixedPoint getTombstoneKey()

Definition APFixedPoint.h:326

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

Definition APFixedPoint.h:334

static APFixedPoint getEmptyKey()

Definition APFixedPoint.h:322

static FixedPointSemantics getEmptyKey()

Definition APFixedPoint.h:142

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

Definition APFixedPoint.h:154

static unsigned getHashValue(const FixedPointSemantics &Val)

Definition APFixedPoint.h:150

static FixedPointSemantics getTombstoneKey()

Definition APFixedPoint.h:146

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.

Definition APFixedPoint.h:41

int LsbWeight

Definition APFixedPoint.h:42