-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[CLANG] Full support of complex multiplication and division. #81514
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
Changes from 1 commit
13fd739
eb9a35c
d3c4f78
4aa0925
fcd5665
2ddba9a
e62c462
f635f94
1d61aa6
148b6ce
5aa2711
ba9a8da
9098908
52181c7
a9449de
e20741e
0d97b9b
bc3fa4f
ec6296f
3117dbd
0a08598
a558d31
dec045b
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 |
---|---|---|
|
@@ -310,6 +310,13 @@ class ComplexExprEmitter | |
CGF.getContext().getFloatTypeSemantics(ElementType); | ||
const llvm::fltSemantics &HigherElementTypeSemantics = | ||
CGF.getContext().getFloatTypeSemantics(HigherElementType); | ||
// Check that LongDouble Size > Double Size. | ||
// This can be interpreted as: | ||
// SmallerType.LargestFiniteVal * SmallerType.LargestFiniteVal <= | ||
// LargerType.LargestFiniteVal. | ||
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. Not entirely accurate, it's |
||
// In terms of exponent it gives this formula: | ||
// (SmallerType.LargestFiniteVal * SmallerType.LargestFiniteVal | ||
// doubles the exponent of SmallerType.LargestFiniteVal); | ||
if (llvm::APFloat::semanticsMaxExponent(ElementTypeSemantics) * 2 + 1 <= | ||
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. I'd appreciate a comment here explaining why this is the correct check, so that future people reading this code can understand why this is being doing. |
||
llvm::APFloat::semanticsMaxExponent(HigherElementTypeSemantics)) { | ||
return CGF.getContext().getComplexType(HigherElementType); | ||
|
@@ -1036,10 +1043,9 @@ ComplexPairTy ComplexExprEmitter::EmitBinDiv(const BinOpInfo &Op) { | |
else if (Op.FPFeatures.getComplexRange() == LangOptions::CX_Basic || | ||
Op.FPFeatures.getComplexRange() == LangOptions::CX_Promoted) | ||
return EmitAlgebraicDiv(LHSr, LHSi, RHSr, RHSi); | ||
else if (!CGF.getLangOpts().FastMath || | ||
// '-ffast-math' is used in the command line but followed by an | ||
// '-fno-cx-limited-range' or '-fcomplex-arithmetic=full'. | ||
Op.FPFeatures.getComplexRange() == LangOptions::CX_Full) { | ||
// '-ffast-math' is used in the command line but followed by an | ||
// '-fno-cx-limited-range' or '-fcomplex-arithmetic=full'. | ||
else if (Op.FPFeatures.getComplexRange() == LangOptions::CX_Full) { | ||
LHSi = OrigLHSi; | ||
// If we have a complex operand on the RHS and FastMath is not allowed, we | ||
// delegate to a libcall to handle all of the complexities and minimize | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2794,8 +2794,10 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, | |
// ffast-math enables basic range rules for complex multiplication and | ||
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 may have a naming problem here. The term "limited range rules" has a direct definition in the C standard, whereas "basic range rules" is essentially our construct to get the same behavior. |
||
// division. | ||
// Warn if user expects to perform full implementation of complex | ||
// multiplication or division in the presence of nnan or ninf flags. | ||
if (Range == LangOptions::ComplexRangeKind::CX_Full) | ||
// multiplication or division in the presence of nan or ninf flags. | ||
if (Range == LangOptions::ComplexRangeKind::CX_Full || | ||
Range == LangOptions::ComplexRangeKind::CX_Improved || | ||
Range == LangOptions::ComplexRangeKind::CX_Promoted) | ||
EmitComplexRangeDiag( | ||
D, ComplexArithmeticStr(Range), | ||
!GccRangeComplexOption.empty() | ||
|
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.
I'd word this as "Check that the promoted type can handle the intermediate values without overflowing."