Skip to content

Commit 08b8ecd

Browse files
committed
Add assert to prevent inf and nan in HLSLHalf_t::GetULP
1 parent 4b8c3d6 commit 08b8ecd

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

include/dxc/Test/HlslTestUtils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,10 @@ static const uint16_t Float16NegDenorm = 0x8008;
527527
static const uint16_t Float16PosZero = 0x0000;
528528
static const uint16_t Float16NegZero = 0x8000;
529529

530+
inline bool IsInfFloat16(uint16_t val) {
531+
return (val == Float16PosInf) || (val == Float16NegInf);
532+
}
533+
530534
inline bool GetSign(float x) { return std::signbit(x); }
531535

532536
inline int GetMantissa(float x) {

tools/clang/unittests/HLSLExec/LongVectorTestData.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ struct HLSLHalf_t {
119119
HLSLHalf_t(DirectX::PackedVector::HALF) = delete;
120120

121121
static double GetULP(HLSLHalf_t A) {
122+
DXASSERT(!IsInfFloat16(A.Val), "ULP of infinity is undefined");
123+
DXASSERT(!IsNanFloat16(A.Val), "ULP of NaN is undefined");
124+
122125
HLSLHalf_t Next = A;
123126
++Next.Val;
124127

0 commit comments

Comments
 (0)