Skip to content

Commit b3619bf

Browse files
Adding IsFinite, IsInf and IsNan long vector tests (#7836)
This PR adds `isfinite`, `isinf`, `isnan` intrinsic test to long vectors. Closes: [#7850](#7850) --------- Co-authored-by: Joao Saffran <[email protected]>
1 parent a29145e commit b3619bf

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

tools/clang/unittests/HLSLExec/LongVectorOps.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ INPUT_SET(NoZero)
1818
INPUT_SET(Positive)
1919
INPUT_SET(Bitwise)
2020
INPUT_SET(SelectCond)
21+
INPUT_SET(FloatSpecial)
2122

2223
#undef INPUT_SET
2324

@@ -125,6 +126,10 @@ OP_DEFAULT(UnaryMath, Log10, 1, "log10", "")
125126
OP_DEFAULT(UnaryMath, Log2, 1, "log2", "")
126127
OP_DEFAULT_DEFINES(UnaryMath, Frexp, 1, "TestFrexp", "", " -DFUNC_FREXP=1")
127128

129+
OP_DEFAULT(FloatSpecial, IsFinite, 1, "isfinite", "")
130+
OP_DEFAULT(FloatSpecial, IsInf, 1, "isinf", "")
131+
OP_DEFAULT(FloatSpecial, IsNan, 1, "isnan", "")
132+
128133
OP_DEFAULT(BinaryComparison, LessThan, 2, "", "<")
129134
OP_DEFAULT(BinaryComparison, LessEqual, 2, "", "<=")
130135
OP_DEFAULT(BinaryComparison, GreaterThan, 2, "", ">")

tools/clang/unittests/HLSLExec/LongVectorTestData.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,20 @@ INPUT_SET(InputSet::RangeOne, 0.331, 0.727, -0.957, 0.677, -0.025, 0.495, 0.855,
358358
INPUT_SET(InputSet::Positive, 1.0, 1.0, 342.0, 0.01, 5531.0, 0.01, 1.0, 0.01,
359359
331.2330, 3250.01);
360360
INPUT_SET(InputSet::SelectCond, 0.0, 1.0);
361+
// HLSLHalf_t has a constructor which accepts a float and converts it to half
362+
// precision by clamping to the representable range via
363+
// DirectX::PackedVector::XMConvertFloatToHalf.
364+
INPUT_SET(InputSet::FloatSpecial, std::numeric_limits<float>::infinity(),
365+
-std::numeric_limits<float>::infinity(),
366+
std::numeric_limits<float>::signaling_NaN(),
367+
-std::numeric_limits<float>::signaling_NaN(),
368+
std::numeric_limits<float>::quiet_NaN(),
369+
-std::numeric_limits<float>::quiet_NaN(), 0.0, -0.0,
370+
std::numeric_limits<float>::min(), std::numeric_limits<float>::max(),
371+
-std::numeric_limits<float>::min(),
372+
-std::numeric_limits<float>::max(),
373+
std::numeric_limits<float>::denorm_min(),
374+
std::numeric_limits<float>::denorm_min() * 10.0, 1.0 / 3.0);
361375
END_INPUT_SETS()
362376

363377
BEGIN_INPUT_SETS(float)
@@ -374,6 +388,17 @@ INPUT_SET(InputSet::RangeOne, 0.727f, 0.331f, -0.957f, 0.677f, -0.025f, 0.495f,
374388
INPUT_SET(InputSet::Positive, 1.0f, 1.0f, 65535.0f, 0.01f, 5531.0f, 0.01f, 1.0f,
375389
0.01f, 331.2330f, 3250.01f);
376390
INPUT_SET(InputSet::SelectCond, 0.0f, 1.0f);
391+
INPUT_SET(InputSet::FloatSpecial, std::numeric_limits<float>::infinity(),
392+
-std::numeric_limits<float>::infinity(),
393+
std::numeric_limits<float>::signaling_NaN(),
394+
-std::numeric_limits<float>::signaling_NaN(),
395+
std::numeric_limits<float>::quiet_NaN(),
396+
-std::numeric_limits<float>::quiet_NaN(), 0.0f, -0.0f,
397+
std::numeric_limits<float>::min(), std::numeric_limits<float>::max(),
398+
-std::numeric_limits<float>::min(),
399+
-std::numeric_limits<float>::max(),
400+
std::numeric_limits<float>::denorm_min(),
401+
std::numeric_limits<float>::denorm_min() * 10.0f, 1.0f / 3.0f);
377402
END_INPUT_SETS()
378403

379404
BEGIN_INPUT_SETS(double)

tools/clang/unittests/HLSLExec/LongVectors.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,20 @@ STRICT_OP_1(OpType::LoadAndStore_DT_SB_SRV, (A));
12221222
STRICT_OP_1(OpType::LoadAndStore_RD_SB_UAV, (A));
12231223
STRICT_OP_1(OpType::LoadAndStore_RD_SB_SRV, (A));
12241224

1225+
//
1226+
// Float Ops
1227+
//
1228+
1229+
#define FLOAT_SPECIAL_OP(OP, IMPL) \
1230+
template <typename T> struct Op<OP, T, 1> : StrictValidation { \
1231+
HLSLBool_t operator()(T A) { return IMPL; } \
1232+
};
1233+
1234+
FLOAT_SPECIAL_OP(OpType::IsFinite, (std::isfinite(A)));
1235+
FLOAT_SPECIAL_OP(OpType::IsInf, (std::isinf(A)));
1236+
FLOAT_SPECIAL_OP(OpType::IsNan, (std::isnan(A)));
1237+
#undef FLOAT_SPECIAL_OP
1238+
12251239
//
12261240
// dispatchTest
12271241
//
@@ -1753,6 +1767,16 @@ class DxilConf_SM69_Vectorized {
17531767
HLK_TEST(Abs, double);
17541768
HLK_TEST(Sign, double);
17551769

1770+
// Float Special
1771+
1772+
HLK_TEST(IsFinite, HLSLHalf_t);
1773+
HLK_TEST(IsInf, HLSLHalf_t);
1774+
HLK_TEST(IsNan, HLSLHalf_t);
1775+
1776+
HLK_TEST(IsFinite, float);
1777+
HLK_TEST(IsInf, float);
1778+
HLK_TEST(IsNan, float);
1779+
17561780
// Binary Comparison
17571781

17581782
HLK_TEST(LessThan, int16_t);

0 commit comments

Comments
 (0)