[APFloat] Rename macro convolve => PackCategoriesIntoKey so that it is clear what APFloat is actually using said macro for.

In the context of APFloat, seeing a macro called convolve suggests that APFloat
is using said value in some sort of convolution somewhere in the source code.
This is misleading.

I also added a documentation comment to the macro.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184710 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael Gottesman
2013-06-24 09:57:57 +00:00
parent 37d002f0a8
commit c29f5dc29e

View File

@@ -25,7 +25,13 @@
using namespace llvm; using namespace llvm;
#define convolve(lhs, rhs) ((lhs) * 4 + (rhs)) /// A macro used to combine two fcCategory enums into one key which can be used
/// in a switch statement to classify how the interaction of two APFloat's
/// categories affects an operation.
///
/// TODO: If clang source code is ever allowed to use constexpr in its own
/// codebase, change this into a static inline function.
#define PackCategoriesIntoKey(_lhs, _rhs) ((_lhs) * 4 + (_rhs))
/* Assumed in hexadecimal significand parsing, and conversion to /* Assumed in hexadecimal significand parsing, and conversion to
hexadecimal strings. */ hexadecimal strings. */
@@ -1345,42 +1351,42 @@ APFloat::normalize(roundingMode rounding_mode,
APFloat::opStatus APFloat::opStatus
APFloat::addOrSubtractSpecials(const APFloat &rhs, bool subtract) APFloat::addOrSubtractSpecials(const APFloat &rhs, bool subtract)
{ {
switch (convolve(category, rhs.category)) { switch (PackCategoriesIntoKey(category, rhs.category)) {
default: default:
llvm_unreachable(0); llvm_unreachable(0);
case convolve(fcNaN, fcZero): case PackCategoriesIntoKey(fcNaN, fcZero):
case convolve(fcNaN, fcNormal): case PackCategoriesIntoKey(fcNaN, fcNormal):
case convolve(fcNaN, fcInfinity): case PackCategoriesIntoKey(fcNaN, fcInfinity):
case convolve(fcNaN, fcNaN): case PackCategoriesIntoKey(fcNaN, fcNaN):
case convolve(fcNormal, fcZero): case PackCategoriesIntoKey(fcNormal, fcZero):
case convolve(fcInfinity, fcNormal): case PackCategoriesIntoKey(fcInfinity, fcNormal):
case convolve(fcInfinity, fcZero): case PackCategoriesIntoKey(fcInfinity, fcZero):
return opOK; return opOK;
case convolve(fcZero, fcNaN): case PackCategoriesIntoKey(fcZero, fcNaN):
case convolve(fcNormal, fcNaN): case PackCategoriesIntoKey(fcNormal, fcNaN):
case convolve(fcInfinity, fcNaN): case PackCategoriesIntoKey(fcInfinity, fcNaN):
category = fcNaN; category = fcNaN;
copySignificand(rhs); copySignificand(rhs);
return opOK; return opOK;
case convolve(fcNormal, fcInfinity): case PackCategoriesIntoKey(fcNormal, fcInfinity):
case convolve(fcZero, fcInfinity): case PackCategoriesIntoKey(fcZero, fcInfinity):
category = fcInfinity; category = fcInfinity;
sign = rhs.sign ^ subtract; sign = rhs.sign ^ subtract;
return opOK; return opOK;
case convolve(fcZero, fcNormal): case PackCategoriesIntoKey(fcZero, fcNormal):
assign(rhs); assign(rhs);
sign = rhs.sign ^ subtract; sign = rhs.sign ^ subtract;
return opOK; return opOK;
case convolve(fcZero, fcZero): case PackCategoriesIntoKey(fcZero, fcZero):
/* Sign depends on rounding mode; handled by caller. */ /* Sign depends on rounding mode; handled by caller. */
return opOK; return opOK;
case convolve(fcInfinity, fcInfinity): case PackCategoriesIntoKey(fcInfinity, fcInfinity):
/* Differently signed infinities can only be validly /* Differently signed infinities can only be validly
subtracted. */ subtracted. */
if (((sign ^ rhs.sign)!=0) != subtract) { if (((sign ^ rhs.sign)!=0) != subtract) {
@@ -1390,7 +1396,7 @@ APFloat::addOrSubtractSpecials(const APFloat &rhs, bool subtract)
return opOK; return opOK;
case convolve(fcNormal, fcNormal): case PackCategoriesIntoKey(fcNormal, fcNormal):
return opDivByZero; return opDivByZero;
} }
} }
@@ -1471,41 +1477,41 @@ APFloat::addOrSubtractSignificand(const APFloat &rhs, bool subtract)
APFloat::opStatus APFloat::opStatus
APFloat::multiplySpecials(const APFloat &rhs) APFloat::multiplySpecials(const APFloat &rhs)
{ {
switch (convolve(category, rhs.category)) { switch (PackCategoriesIntoKey(category, rhs.category)) {
default: default:
llvm_unreachable(0); llvm_unreachable(0);
case convolve(fcNaN, fcZero): case PackCategoriesIntoKey(fcNaN, fcZero):
case convolve(fcNaN, fcNormal): case PackCategoriesIntoKey(fcNaN, fcNormal):
case convolve(fcNaN, fcInfinity): case PackCategoriesIntoKey(fcNaN, fcInfinity):
case convolve(fcNaN, fcNaN): case PackCategoriesIntoKey(fcNaN, fcNaN):
return opOK; return opOK;
case convolve(fcZero, fcNaN): case PackCategoriesIntoKey(fcZero, fcNaN):
case convolve(fcNormal, fcNaN): case PackCategoriesIntoKey(fcNormal, fcNaN):
case convolve(fcInfinity, fcNaN): case PackCategoriesIntoKey(fcInfinity, fcNaN):
category = fcNaN; category = fcNaN;
copySignificand(rhs); copySignificand(rhs);
return opOK; return opOK;
case convolve(fcNormal, fcInfinity): case PackCategoriesIntoKey(fcNormal, fcInfinity):
case convolve(fcInfinity, fcNormal): case PackCategoriesIntoKey(fcInfinity, fcNormal):
case convolve(fcInfinity, fcInfinity): case PackCategoriesIntoKey(fcInfinity, fcInfinity):
category = fcInfinity; category = fcInfinity;
return opOK; return opOK;
case convolve(fcZero, fcNormal): case PackCategoriesIntoKey(fcZero, fcNormal):
case convolve(fcNormal, fcZero): case PackCategoriesIntoKey(fcNormal, fcZero):
case convolve(fcZero, fcZero): case PackCategoriesIntoKey(fcZero, fcZero):
category = fcZero; category = fcZero;
return opOK; return opOK;
case convolve(fcZero, fcInfinity): case PackCategoriesIntoKey(fcZero, fcInfinity):
case convolve(fcInfinity, fcZero): case PackCategoriesIntoKey(fcInfinity, fcZero):
makeNaN(); makeNaN();
return opInvalidOp; return opInvalidOp;
case convolve(fcNormal, fcNormal): case PackCategoriesIntoKey(fcNormal, fcNormal):
return opOK; return opOK;
} }
} }
@@ -1513,41 +1519,41 @@ APFloat::multiplySpecials(const APFloat &rhs)
APFloat::opStatus APFloat::opStatus
APFloat::divideSpecials(const APFloat &rhs) APFloat::divideSpecials(const APFloat &rhs)
{ {
switch (convolve(category, rhs.category)) { switch (PackCategoriesIntoKey(category, rhs.category)) {
default: default:
llvm_unreachable(0); llvm_unreachable(0);
case convolve(fcNaN, fcZero): case PackCategoriesIntoKey(fcNaN, fcZero):
case convolve(fcNaN, fcNormal): case PackCategoriesIntoKey(fcNaN, fcNormal):
case convolve(fcNaN, fcInfinity): case PackCategoriesIntoKey(fcNaN, fcInfinity):
case convolve(fcNaN, fcNaN): case PackCategoriesIntoKey(fcNaN, fcNaN):
case convolve(fcInfinity, fcZero): case PackCategoriesIntoKey(fcInfinity, fcZero):
case convolve(fcInfinity, fcNormal): case PackCategoriesIntoKey(fcInfinity, fcNormal):
case convolve(fcZero, fcInfinity): case PackCategoriesIntoKey(fcZero, fcInfinity):
case convolve(fcZero, fcNormal): case PackCategoriesIntoKey(fcZero, fcNormal):
return opOK; return opOK;
case convolve(fcZero, fcNaN): case PackCategoriesIntoKey(fcZero, fcNaN):
case convolve(fcNormal, fcNaN): case PackCategoriesIntoKey(fcNormal, fcNaN):
case convolve(fcInfinity, fcNaN): case PackCategoriesIntoKey(fcInfinity, fcNaN):
category = fcNaN; category = fcNaN;
copySignificand(rhs); copySignificand(rhs);
return opOK; return opOK;
case convolve(fcNormal, fcInfinity): case PackCategoriesIntoKey(fcNormal, fcInfinity):
category = fcZero; category = fcZero;
return opOK; return opOK;
case convolve(fcNormal, fcZero): case PackCategoriesIntoKey(fcNormal, fcZero):
category = fcInfinity; category = fcInfinity;
return opDivByZero; return opDivByZero;
case convolve(fcInfinity, fcInfinity): case PackCategoriesIntoKey(fcInfinity, fcInfinity):
case convolve(fcZero, fcZero): case PackCategoriesIntoKey(fcZero, fcZero):
makeNaN(); makeNaN();
return opInvalidOp; return opInvalidOp;
case convolve(fcNormal, fcNormal): case PackCategoriesIntoKey(fcNormal, fcNormal):
return opOK; return opOK;
} }
} }
@@ -1555,35 +1561,35 @@ APFloat::divideSpecials(const APFloat &rhs)
APFloat::opStatus APFloat::opStatus
APFloat::modSpecials(const APFloat &rhs) APFloat::modSpecials(const APFloat &rhs)
{ {
switch (convolve(category, rhs.category)) { switch (PackCategoriesIntoKey(category, rhs.category)) {
default: default:
llvm_unreachable(0); llvm_unreachable(0);
case convolve(fcNaN, fcZero): case PackCategoriesIntoKey(fcNaN, fcZero):
case convolve(fcNaN, fcNormal): case PackCategoriesIntoKey(fcNaN, fcNormal):
case convolve(fcNaN, fcInfinity): case PackCategoriesIntoKey(fcNaN, fcInfinity):
case convolve(fcNaN, fcNaN): case PackCategoriesIntoKey(fcNaN, fcNaN):
case convolve(fcZero, fcInfinity): case PackCategoriesIntoKey(fcZero, fcInfinity):
case convolve(fcZero, fcNormal): case PackCategoriesIntoKey(fcZero, fcNormal):
case convolve(fcNormal, fcInfinity): case PackCategoriesIntoKey(fcNormal, fcInfinity):
return opOK; return opOK;
case convolve(fcZero, fcNaN): case PackCategoriesIntoKey(fcZero, fcNaN):
case convolve(fcNormal, fcNaN): case PackCategoriesIntoKey(fcNormal, fcNaN):
case convolve(fcInfinity, fcNaN): case PackCategoriesIntoKey(fcInfinity, fcNaN):
category = fcNaN; category = fcNaN;
copySignificand(rhs); copySignificand(rhs);
return opOK; return opOK;
case convolve(fcNormal, fcZero): case PackCategoriesIntoKey(fcNormal, fcZero):
case convolve(fcInfinity, fcZero): case PackCategoriesIntoKey(fcInfinity, fcZero):
case convolve(fcInfinity, fcNormal): case PackCategoriesIntoKey(fcInfinity, fcNormal):
case convolve(fcInfinity, fcInfinity): case PackCategoriesIntoKey(fcInfinity, fcInfinity):
case convolve(fcZero, fcZero): case PackCategoriesIntoKey(fcZero, fcZero):
makeNaN(); makeNaN();
return opInvalidOp; return opInvalidOp;
case convolve(fcNormal, fcNormal): case PackCategoriesIntoKey(fcNormal, fcNormal):
return opOK; return opOK;
} }
} }
@@ -1866,36 +1872,36 @@ APFloat::compare(const APFloat &rhs) const
assert(semantics == rhs.semantics); assert(semantics == rhs.semantics);
switch (convolve(category, rhs.category)) { switch (PackCategoriesIntoKey(category, rhs.category)) {
default: default:
llvm_unreachable(0); llvm_unreachable(0);
case convolve(fcNaN, fcZero): case PackCategoriesIntoKey(fcNaN, fcZero):
case convolve(fcNaN, fcNormal): case PackCategoriesIntoKey(fcNaN, fcNormal):
case convolve(fcNaN, fcInfinity): case PackCategoriesIntoKey(fcNaN, fcInfinity):
case convolve(fcNaN, fcNaN): case PackCategoriesIntoKey(fcNaN, fcNaN):
case convolve(fcZero, fcNaN): case PackCategoriesIntoKey(fcZero, fcNaN):
case convolve(fcNormal, fcNaN): case PackCategoriesIntoKey(fcNormal, fcNaN):
case convolve(fcInfinity, fcNaN): case PackCategoriesIntoKey(fcInfinity, fcNaN):
return cmpUnordered; return cmpUnordered;
case convolve(fcInfinity, fcNormal): case PackCategoriesIntoKey(fcInfinity, fcNormal):
case convolve(fcInfinity, fcZero): case PackCategoriesIntoKey(fcInfinity, fcZero):
case convolve(fcNormal, fcZero): case PackCategoriesIntoKey(fcNormal, fcZero):
if (sign) if (sign)
return cmpLessThan; return cmpLessThan;
else else
return cmpGreaterThan; return cmpGreaterThan;
case convolve(fcNormal, fcInfinity): case PackCategoriesIntoKey(fcNormal, fcInfinity):
case convolve(fcZero, fcInfinity): case PackCategoriesIntoKey(fcZero, fcInfinity):
case convolve(fcZero, fcNormal): case PackCategoriesIntoKey(fcZero, fcNormal):
if (rhs.sign) if (rhs.sign)
return cmpGreaterThan; return cmpGreaterThan;
else else
return cmpLessThan; return cmpLessThan;
case convolve(fcInfinity, fcInfinity): case PackCategoriesIntoKey(fcInfinity, fcInfinity):
if (sign == rhs.sign) if (sign == rhs.sign)
return cmpEqual; return cmpEqual;
else if (sign) else if (sign)
@@ -1903,10 +1909,10 @@ APFloat::compare(const APFloat &rhs) const
else else
return cmpGreaterThan; return cmpGreaterThan;
case convolve(fcZero, fcZero): case PackCategoriesIntoKey(fcZero, fcZero):
return cmpEqual; return cmpEqual;
case convolve(fcNormal, fcNormal): case PackCategoriesIntoKey(fcNormal, fcNormal):
break; break;
} }