9#ifndef LLVM_CLANG_AST_INTERP_FIXED_POINT_H
10#define LLVM_CLANG_AST_INTERP_FIXED_POINT_H
14#include "llvm/ADT/APFixedPoint.h"
42 return FixedPoint(llvm::APFixedPoint::getFromIntValue(I, Sem, Overflow));
44 static FixedPoint from(
const llvm::APFloat &I, llvm::FixedPointSemantics Sem,
46 return FixedPoint(llvm::APFixedPoint::getFromFloatValue(I, Sem, Overflow));
49 operator bool()
const {
return V.getBoolValue(); }
50 void print(llvm::raw_ostream &OS)
const { OS <<
V; }
57 bool isZero()
const {
return V.getValue().isZero(); }
59 bool isPositive()
const {
return V.getValue().isNonNegative(); }
61 return V == llvm::APFixedPoint::getMin(
V.getSemantics());
63 bool isMinusOne()
const {
return V.isSigned() &&
V.getValue() == -1; }
68 bool *Overflow)
const {
71 llvm::FixedPointSemantics
getSemantics()
const {
return V.getSemantics(); }
73 llvm::APFloat
toFloat(
const llvm::fltSemantics *Sem)
const {
74 return V.convertToFloat(*Sem);
77 llvm::APSInt
toInt(
unsigned BitWidth,
bool Signed,
bool *Overflow)
const {
78 return V.convertToInt(BitWidth,
Signed, Overflow);
95 return sizeof(uint32_t) + (
V.getValue().getBitWidth() /
CHAR_BIT);
100 uint32_t SemI =
V.getSemantics().toOpaqueInt();
101 std::memcpy(Buff, &SemI,
sizeof(SemI));
103 llvm::APInt API =
V.getValue();
104 llvm::StoreIntToMemory(API, (uint8_t *)(Buff +
sizeof(SemI)),
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)),
121 bool Overflow =
false;
128 bool Overflow =
false;
134 bool Overflow =
false;
140 bool Overflow =
false;
146 bool Overflow =
false;
153 unsigned Amt = B.V.getValue().getLimitedValue(OpBits);
160 unsigned Amt = B.V.getValue().getLimitedValue(OpBits);
168 llvm_unreachable(
"Rem doesn't exist for fixed point values");
__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.
static bool sub(const FixedPoint A, const FixedPoint B, unsigned Bits, FixedPoint *R)
static bool add(const FixedPoint A, const FixedPoint B, unsigned Bits, FixedPoint *R)
void serialize(std::byte *Buff) const
FixedPoint(llvm::APFixedPoint &V)
llvm::FixedPointSemantics getSemantics() const
FixedPoint toSemantics(const llvm::FixedPointSemantics &Sem, bool *Overflow) const
static bool shiftRight(const FixedPoint A, const FixedPoint B, unsigned OpBits, FixedPoint *R)
static FixedPoint deserialize(const std::byte *Buff)
llvm::APSInt toInt(unsigned BitWidth, bool Signed, bool *Overflow) const
static bool shiftLeft(const FixedPoint A, const FixedPoint B, unsigned OpBits, FixedPoint *R)
llvm::APFloat toFloat(const llvm::fltSemantics *Sem) const
static bool rem(const FixedPoint A, const FixedPoint B, unsigned Bits, FixedPoint *R)
static FixedPoint from(const APSInt &I, llvm::FixedPointSemantics Sem, bool *Overflow)
static bool neg(const FixedPoint &A, FixedPoint *R)
FixedPoint truncate(unsigned BitWidth) const
ComparisonCategoryResult compare(const FixedPoint &Other) const
static bool increment(const FixedPoint &A, FixedPoint *R)
size_t bytesToSerialize() const
static FixedPoint from(const llvm::APFloat &I, llvm::FixedPointSemantics Sem, bool *Overflow)
static bool bitOr(const FixedPoint A, const FixedPoint B, unsigned Bits, FixedPoint *R)
static bool div(const FixedPoint A, const FixedPoint B, unsigned Bits, FixedPoint *R)
static bool mul(const FixedPoint A, const FixedPoint B, unsigned Bits, FixedPoint *R)
APSInt toAPSInt(unsigned BitWidth=0) const
FixedPoint(APInt V, llvm::FixedPointSemantics Sem)
std::string toDiagnosticString(const ASTContext &Ctx) const
static bool bitAnd(const FixedPoint A, const FixedPoint B, unsigned Bits, FixedPoint *R)
static bool decrement(const FixedPoint &A, FixedPoint *R)
FixedPoint(llvm::APFixedPoint &&V)
static bool bitXor(const FixedPoint A, const FixedPoint B, unsigned Bits, FixedPoint *R)
void print(llvm::raw_ostream &OS) const
static FixedPoint zero(llvm::FixedPointSemantics Sem)
APValue toAPValue(const ASTContext &) const
unsigned bitWidth() const
FixedPoint getSwappedBytes(FixedPoint F)
llvm::FixedPointSemantics FixedPointSemantics
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const Boolean &B)
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.