-
Notifications
You must be signed in to change notification settings - Fork 0
Decimal float impl #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,8 +77,10 @@ | |
namespace llvm { | ||
|
||
class APFixedPoint; | ||
class APDecimalFloat; | ||
class FixedPointSemantics; | ||
struct fltSemantics; | ||
struct decFltSemantics; | ||
template <typename T, unsigned N> class SmallPtrSet; | ||
|
||
} // namespace llvm | ||
|
@@ -1117,6 +1119,8 @@ class ASTContext : public RefCountedBase<ASTContext> { | |
CanQualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy; | ||
CanQualType UnsignedLongLongTy, UnsignedInt128Ty; | ||
CanQualType FloatTy, DoubleTy, LongDoubleTy, Float128Ty, Ibm128Ty; | ||
CanQualType DecimalFloat32Ty, DecimalFloat64Ty, DecimalFloat128Ty; // ISO/IEC TS 18661-2:2015 C23 conditionally supported | ||
// ISO/IEC TR 24733:2011 C++ support | ||
Comment on lines
+1122
to
+1123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per https://llvm.org/docs/CodingStandards.html#source-code-width, limit line length to 80 characters. |
||
CanQualType ShortAccumTy, AccumTy, | ||
LongAccumTy; // ISO/IEC JTC1 SC22 WG14 N1169 Extension | ||
CanQualType UnsignedShortAccumTy, UnsignedAccumTy, UnsignedLongAccumTy; | ||
|
@@ -2187,6 +2191,10 @@ class ASTContext : public RefCountedBase<ASTContext> { | |
llvm::APFixedPoint getFixedPointMax(QualType Ty) const; | ||
llvm::APFixedPoint getFixedPointMin(QualType Ty) const; | ||
|
||
llvm::decFltSemantics getDecimalFloatSemantics(QualType Ty) const; | ||
llvm::APDecimalFloat getDecimalFloatMax(QualType Ty) const; | ||
llvm::APDecimalFloat getDecimalFloatMin(QualType Ty) const; | ||
|
||
DeclarationNameInfo getNameForTemplate(TemplateName Name, | ||
SourceLocation NameLoc) const; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1500,6 +1500,28 @@ class APFloatStorage : private APNumericStorage { | |
} | ||
}; | ||
|
||
class APDecimalFloatStorage : private APNumericStorage { | ||
public: | ||
// llvm::APDecimalFloat | ||
llvm::APInt getValue(const llvm::decFltSemantics &Semantics) const { | ||
// return llvm::APDecimalFloat(getIntValue(),Semantics); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for this anymore, right? Same below. |
||
return getIntValue(); | ||
} | ||
|
||
llvm::APInt getValue() const { | ||
// return llvm::APDecimalFloat(getIntValue(),Semantics); | ||
return getIntValue(); | ||
} | ||
|
||
void setValue(const ASTContext &C, const llvm::APDecimalFloat &Val) { | ||
setIntValue(C, Val.bitcastToAPInt()); | ||
} | ||
void setValue(const ASTContext &C, const llvm::APInt &Val) { | ||
setIntValue(C, Val); | ||
} | ||
}; | ||
|
||
|
||
class IntegerLiteral : public Expr, public APIntStorage { | ||
SourceLocation Loc; | ||
|
||
|
@@ -1590,6 +1612,61 @@ class FixedPointLiteral : public Expr, public APIntStorage { | |
} | ||
}; | ||
|
||
class DecimalFloatLiteral : public Expr, public APDecimalFloatStorage { | ||
SourceLocation Loc; | ||
unsigned width = 32; | ||
unsigned scale = 1; | ||
bool isSigned = false; | ||
|
||
/// \brief Construct an empty fixed-point literal. | ||
explicit DecimalFloatLiteral(EmptyShell Empty) | ||
: Expr(DecimalFloatLiteralClass, Empty) {} | ||
|
||
public: | ||
DecimalFloatLiteral(const ASTContext &C, const llvm::APDecimalFloat &V, QualType type, | ||
SourceLocation l, unsigned width = 32 ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to have width to be default? |
||
|
||
|
||
/// Returns an empty fixed-point literal. | ||
static DecimalFloatLiteral *Create(const ASTContext &C, EmptyShell Empty); | ||
static DecimalFloatLiteral * | ||
CreateFromAPDecimalFloat(const ASTContext &C, llvm::APDecimalFloat Val, | ||
QualType type, SourceLocation l, unsigned width); | ||
|
||
SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } | ||
SourceLocation getEndLoc() const LLVM_READONLY { return Loc; } | ||
|
||
/// \brief Retrieve the location of the literal. | ||
SourceLocation getLocation() const { return Loc; } | ||
|
||
void setLocation(SourceLocation Location) { Loc = Location; } | ||
|
||
llvm::decFltSemantics getSemantics() const { | ||
return {width, scale, isSigned, false, false}; | ||
} | ||
|
||
// llvm::APDecimalFloat getValue() const { | ||
// return APDecimalFloatStorage::getValue(getSemantics()); | ||
// } | ||
|
||
void setWidth(unsigned Width) { width = Width;} | ||
unsigned getWidth() { return width; } | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will need here get/set scale too. |
||
static bool classof(const Stmt *T) { | ||
return T->getStmtClass() == DecimalFloatLiteralClass; | ||
} | ||
|
||
std::string getValueAsString() const; | ||
|
||
// Iterators | ||
child_range children() { | ||
return child_range(child_iterator(), child_iterator()); | ||
} | ||
const_child_range children() const { | ||
return const_child_range(const_child_iterator(), const_child_iterator()); | ||
} | ||
}; | ||
|
||
class CharacterLiteral : public Expr { | ||
public: | ||
enum CharacterKind { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,10 +225,35 @@ CAST_OPERATION(FixedPointToIntegral) | |
/// (_Accum) 2 | ||
CAST_OPERATION(IntegralToFixedPoint) | ||
|
||
/// CK_FixedPointToBoolean - Fixed point to boolean. | ||
/// CK_FixedPointToBoolean - Decimal Float to boolean. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change to this comment doesn't seem right. |
||
/// (bool) 0.5r | ||
CAST_OPERATION(FixedPointToBoolean) | ||
|
||
/// CK_FloatingToDecimalFloat - Floating to Decimal Float. | ||
/// _Accum a = f; | ||
CAST_OPERATION(FloatingToDecimalFloat) | ||
|
||
/// CK_DecimalFloatToFloating - Decimal Float to floating. | ||
/// (float) 2.5k | ||
CAST_OPERATION(DecimalFloatToFloating) | ||
|
||
/// CK_DecimalFloatCast - Decimal Float to Decimal Float. | ||
/// (_Accum) 0.5r | ||
CAST_OPERATION(DecimalFloatCast) | ||
|
||
/// CK_DecimalFloatToIntegral - Decimal Float to integral. | ||
/// (int) 2.0k | ||
CAST_OPERATION(DecimalFloatToIntegral) | ||
|
||
/// CK_IntegralToDecimalFloat - Integral to a Decimal Float. | ||
/// (_Accum) 2 | ||
CAST_OPERATION(IntegralToDecimalFloat) | ||
|
||
/// CK_DecimalFloatToBoolean - Decimal Float to boolean. | ||
/// (bool) 0.5r | ||
CAST_OPERATION(DecimalFloatToBoolean) | ||
Comment on lines
+232
to
+254
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The example cast operations in the comments are still for fixed point types and should be switched to operations on DFP types and literals. |
||
|
||
|
||
/// CK_FloatingToIntegral - Floating point to integral. Rounds | ||
/// towards zero, discarding any fractional component. | ||
/// (int) f | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated change. The one below too.