clang: lib/AST/ByteCode/FixedPoint.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_CLANG_AST_INTERP_FIXED_POINT_H

10#define LLVM_CLANG_AST_INTERP_FIXED_POINT_H

11

14#include "llvm/ADT/APFixedPoint.h"

15

18

21

22

24private:

25 llvm::APFixedPoint V;

26

27public:

31

35

37 return FixedPoint(APInt(Sem.getWidth(), 0ULL, Sem.isSigned()), Sem);

38 }

39

41 bool *Overflow) {

42 return FixedPoint(llvm::APFixedPoint::getFromIntValue(I, Sem, Overflow));

43 }

44 static FixedPoint from(const llvm::APFloat &I, llvm::FixedPointSemantics Sem,

45 bool *Overflow) {

46 return FixedPoint(llvm::APFixedPoint::getFromFloatValue(I, Sem, Overflow));

47 }

48

49 operator bool() const { return V.getBoolValue(); }

50 void print(llvm::raw_ostream &OS) const { OS << V; }

51

53 APSInt toAPSInt(unsigned BitWidth = 0) const { return V.getValue(); }

54

55 unsigned bitWidth() const { return V.getWidth(); }

56 bool isSigned() const { return V.isSigned(); }

57 bool isZero() const { return V.getValue().isZero(); }

58 bool isNegative() const { return V.getValue().isNegative(); }

59 bool isPositive() const { return V.getValue().isNonNegative(); }

61 return V == llvm::APFixedPoint::getMin(V.getSemantics());

62 }

63 bool isMinusOne() const { return V.isSigned() && V.getValue() == -1; }

64

66

68 bool *Overflow) const {

69 return FixedPoint(V.convert(Sem, Overflow));

70 }

71 llvm::FixedPointSemantics getSemantics() const { return V.getSemantics(); }

72

73 llvm::APFloat toFloat(const llvm::fltSemantics *Sem) const {

74 return V.convertToFloat(*Sem);

75 }

76

77 llvm::APSInt toInt(unsigned BitWidth, bool Signed, bool *Overflow) const {

78 return V.convertToInt(BitWidth, Signed, Overflow);

79 }

80

82 return V.toString();

83 }

84

86 int c = V.compare(Other.V);

87 if (c == 0)

89 else if (c < 0)

92 }

93

95 return sizeof(uint32_t) + (V.getValue().getBitWidth() / CHAR_BIT);

96 }

97

99

100 uint32_t SemI = V.getSemantics().toOpaqueInt();

101 std::memcpy(Buff, &SemI, sizeof(SemI));

102

103 llvm::APInt API = V.getValue();

104 llvm::StoreIntToMemory(API, (uint8_t *)(Buff + sizeof(SemI)),

106 }

107

109 auto Sem = llvm::FixedPointSemantics::getFromOpaqueInt(

110 *reinterpret_cast<const uint32_t *>(Buff));

111 unsigned BitWidth = Sem.getWidth();

112 APInt I(BitWidth, 0ull, !Sem.isSigned());

113 llvm::LoadIntFromMemory(

114 I, reinterpret_cast<const uint8_t *>(Buff + sizeof(uint32_t)),

116

118 }

119

121 bool Overflow = false;

122 *R = FixedPoint(A.V.negate(&Overflow));

123 return Overflow;

124 }

125

128 bool Overflow = false;

129 *R = FixedPoint(A.V.add(B.V, &Overflow));

130 return Overflow;

131 }

134 bool Overflow = false;

135 *R = FixedPoint(A.V.sub(B.V, &Overflow));

136 return Overflow;

137 }

140 bool Overflow = false;

141 *R = FixedPoint(A.V.mul(B.V, &Overflow));

142 return Overflow;

143 }

146 bool Overflow = false;

147 *R = FixedPoint(A.V.div(B.V, &Overflow));

148 return Overflow;

149 }

150

153 unsigned Amt = B.V.getValue().getLimitedValue(OpBits);

154 bool Overflow;

155 *R = FixedPoint(A.V.shl(Amt, &Overflow));

156 return Overflow;

157 }

160 unsigned Amt = B.V.getValue().getLimitedValue(OpBits);

161 bool Overflow;

162 *R = FixedPoint(A.V.shr(Amt, &Overflow));

163 return Overflow;

164 }

165

168 llvm_unreachable("Rem doesn't exist for fixed point values");

169 return true;

170 }

183

186};

187

189

194

195}

196}

197

198#endif

__device__ __2f16 float c

APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

Wrapper around fixed point types.

Definition FixedPoint.h:23

static bool sub(const FixedPoint A, const FixedPoint B, unsigned Bits, FixedPoint *R)

Definition FixedPoint.h:132

static bool add(const FixedPoint A, const FixedPoint B, unsigned Bits, FixedPoint *R)

Definition FixedPoint.h:126

void serialize(std::byte *Buff) const

Definition FixedPoint.h:98

FixedPoint(llvm::APFixedPoint &V)

Definition FixedPoint.h:29

llvm::FixedPointSemantics getSemantics() const

Definition FixedPoint.h:71

FixedPoint toSemantics(const llvm::FixedPointSemantics &Sem, bool *Overflow) const

Definition FixedPoint.h:67

FixedPoint()

Definition FixedPoint.h:32

static bool shiftRight(const FixedPoint A, const FixedPoint B, unsigned OpBits, FixedPoint *R)

Definition FixedPoint.h:158

bool isPositive() const

Definition FixedPoint.h:59

static FixedPoint deserialize(const std::byte *Buff)

Definition FixedPoint.h:108

llvm::APSInt toInt(unsigned BitWidth, bool Signed, bool *Overflow) const

Definition FixedPoint.h:77

static bool shiftLeft(const FixedPoint A, const FixedPoint B, unsigned OpBits, FixedPoint *R)

Definition FixedPoint.h:151

llvm::APFloat toFloat(const llvm::fltSemantics *Sem) const

Definition FixedPoint.h:73

static bool rem(const FixedPoint A, const FixedPoint B, unsigned Bits, FixedPoint *R)

Definition FixedPoint.h:166

static FixedPoint from(const APSInt &I, llvm::FixedPointSemantics Sem, bool *Overflow)

Definition FixedPoint.h:40

bool isZero() const

Definition FixedPoint.h:57

static bool neg(const FixedPoint &A, FixedPoint *R)

Definition FixedPoint.h:120

FixedPoint truncate(unsigned BitWidth) const

Definition FixedPoint.h:65

ComparisonCategoryResult compare(const FixedPoint &Other) const

Definition FixedPoint.h:85

static bool increment(const FixedPoint &A, FixedPoint *R)

Definition FixedPoint.h:184

size_t bytesToSerialize() const

Definition FixedPoint.h:94

static FixedPoint from(const llvm::APFloat &I, llvm::FixedPointSemantics Sem, bool *Overflow)

Definition FixedPoint.h:44

static bool bitOr(const FixedPoint A, const FixedPoint B, unsigned Bits, FixedPoint *R)

Definition FixedPoint.h:175

bool isMin() const

Definition FixedPoint.h:60

static bool div(const FixedPoint A, const FixedPoint B, unsigned Bits, FixedPoint *R)

Definition FixedPoint.h:144

static bool mul(const FixedPoint A, const FixedPoint B, unsigned Bits, FixedPoint *R)

Definition FixedPoint.h:138

bool isNegative() const

Definition FixedPoint.h:58

APSInt toAPSInt(unsigned BitWidth=0) const

Definition FixedPoint.h:53

FixedPoint(APInt V, llvm::FixedPointSemantics Sem)

Definition FixedPoint.h:30

std::string toDiagnosticString(const ASTContext &Ctx) const

Definition FixedPoint.h:81

bool isSigned() const

Definition FixedPoint.h:56

bool isMinusOne() const

Definition FixedPoint.h:63

static bool bitAnd(const FixedPoint A, const FixedPoint B, unsigned Bits, FixedPoint *R)

Definition FixedPoint.h:171

static bool decrement(const FixedPoint &A, FixedPoint *R)

Definition FixedPoint.h:185

FixedPoint(llvm::APFixedPoint &&V)

Definition FixedPoint.h:28

static bool bitXor(const FixedPoint A, const FixedPoint B, unsigned Bits, FixedPoint *R)

Definition FixedPoint.h:179

void print(llvm::raw_ostream &OS) const

Definition FixedPoint.h:50

static FixedPoint zero(llvm::FixedPointSemantics Sem)

Definition FixedPoint.h:36

APValue toAPValue(const ASTContext &) const

Definition FixedPoint.h:52

unsigned bitWidth() const

Definition FixedPoint.h:55

FixedPoint getSwappedBytes(FixedPoint F)

Definition FixedPoint.h:188

llvm::FixedPointSemantics FixedPointSemantics

llvm::APInt APInt

Definition FixedPoint.h:19

llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const Boolean &B)

llvm::APSInt APSInt

Definition FixedPoint.h:20

The JSON file list parser is used to communicate input to InstallAPI.

ComparisonCategoryResult

An enumeration representing the possible results of a three-way comparison.

@ Other

Other implicit parameter.

Diagnostic wrappers for TextAPI types for error reporting.