Merge pull request #2809 from KhronosGroup/revert-2803-isinf_isnan
Revert "Use intermOut.cpp's IsNan and IsInfinity for parse-time constant folding"
This commit is contained in:
commit
ac1880cc7b
@ -39,7 +39,6 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <list>
|
#include <list>
|
||||||
@ -303,34 +302,6 @@ template <class T> int IntLog2(T n)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool IsInfinity(double x) {
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
switch (_fpclass(x)) {
|
|
||||||
case _FPCLASS_NINF:
|
|
||||||
case _FPCLASS_PINF:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
return std::isinf(x);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool IsNan(double x) {
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
switch (_fpclass(x)) {
|
|
||||||
case _FPCLASS_SNAN:
|
|
||||||
case _FPCLASS_QNAN:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
return std::isnan(x);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
} // end namespace glslang
|
} // end namespace glslang
|
||||||
|
|
||||||
#endif // _COMMON_INCLUDED_
|
#endif // _COMMON_INCLUDED_
|
||||||
|
@ -46,6 +46,35 @@ namespace {
|
|||||||
|
|
||||||
using namespace glslang;
|
using namespace glslang;
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
double d;
|
||||||
|
int i[2];
|
||||||
|
} DoubleIntUnion;
|
||||||
|
|
||||||
|
// Some helper functions
|
||||||
|
|
||||||
|
bool isNan(double x)
|
||||||
|
{
|
||||||
|
DoubleIntUnion u;
|
||||||
|
// tough to find a platform independent library function, do it directly
|
||||||
|
u.d = x;
|
||||||
|
int bitPatternL = u.i[0];
|
||||||
|
int bitPatternH = u.i[1];
|
||||||
|
return (bitPatternH & 0x7ff80000) == 0x7ff80000 &&
|
||||||
|
((bitPatternH & 0xFFFFF) != 0 || bitPatternL != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isInf(double x)
|
||||||
|
{
|
||||||
|
DoubleIntUnion u;
|
||||||
|
// tough to find a platform independent library function, do it directly
|
||||||
|
u.d = x;
|
||||||
|
int bitPatternL = u.i[0];
|
||||||
|
int bitPatternH = u.i[1];
|
||||||
|
return (bitPatternH & 0x7ff00000) == 0x7ff00000 &&
|
||||||
|
(bitPatternH & 0xFFFFF) == 0 && bitPatternL == 0;
|
||||||
|
}
|
||||||
|
|
||||||
const double pi = 3.1415926535897932384626433832795;
|
const double pi = 3.1415926535897932384626433832795;
|
||||||
|
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
@ -634,12 +663,12 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType)
|
|||||||
|
|
||||||
case EOpIsNan:
|
case EOpIsNan:
|
||||||
{
|
{
|
||||||
newConstArray[i].setBConst(IsNan(unionArray[i].getDConst()));
|
newConstArray[i].setBConst(isNan(unionArray[i].getDConst()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EOpIsInf:
|
case EOpIsInf:
|
||||||
{
|
{
|
||||||
newConstArray[i].setBConst(IsInfinity(unionArray[i].getDConst()));
|
newConstArray[i].setBConst(isInf(unionArray[i].getDConst()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,37 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
bool IsInfinity(double x) {
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
switch (_fpclass(x)) {
|
||||||
|
case _FPCLASS_NINF:
|
||||||
|
case _FPCLASS_PINF:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
return std::isinf(x);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsNan(double x) {
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
switch (_fpclass(x)) {
|
||||||
|
case _FPCLASS_SNAN:
|
||||||
|
case _FPCLASS_QNAN:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
return std::isnan(x);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
namespace glslang {
|
namespace glslang {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user