Skip to content

Commit 201a5b5

Browse files
Adding ModF tests to HLK Long Vector unittests (#7859)
This pr is adding ModF into HLK long vector unittest. Closes: [#7851](#7851) --------- Co-authored-by: Joao Saffran <[email protected]>
1 parent 53b058b commit 201a5b5

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

tools/clang/unittests/HLSLExec/LongVectorOps.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ OP_DEFAULT_DEFINES(UnaryMath, Frexp, 1, "TestFrexp", "", " -DFUNC_FREXP=1")
130130
OP_DEFAULT(FloatSpecial, IsFinite, 1, "isfinite", "")
131131
OP_DEFAULT(FloatSpecial, IsInf, 1, "isinf", "")
132132
OP_DEFAULT(FloatSpecial, IsNan, 1, "isnan", "")
133+
OP_DEFAULT_DEFINES(FloatSpecial, ModF, 1, "TestModF", "", " -DFUNC_TEST_MODF=1")
133134

134135
OP_DEFAULT(BinaryComparison, LessThan, 2, "", "<")
135136
OP_DEFAULT(BinaryComparison, LessEqual, 2, "", "<=")

tools/clang/unittests/HLSLExec/LongVectors.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,41 @@ FLOAT_SPECIAL_OP(OpType::IsInf, (std::isinf(A)));
12611261
FLOAT_SPECIAL_OP(OpType::IsNan, (std::isnan(A)));
12621262
#undef FLOAT_SPECIAL_OP
12631263

1264+
template <typename T> struct Op<OpType::ModF, T, 1> : DefaultValidation<T> {};
1265+
1266+
template <typename T> static T modF(T Input, T &OutParam);
1267+
1268+
template <> float modF(float Input, float &OutParam) {
1269+
return std::modf(Input, &OutParam);
1270+
}
1271+
1272+
template <> HLSLHalf_t modF(HLSLHalf_t Input, HLSLHalf_t &OutParam) {
1273+
float Exp = 0.0f;
1274+
float Man = std::modf(float(Input), &Exp);
1275+
OutParam = HLSLHalf_t(Exp);
1276+
return Man;
1277+
}
1278+
1279+
template <typename T> struct ExpectedBuilder<OpType::ModF, T> {
1280+
static std::vector<T> buildExpected(Op<OpType::ModF, T, 1> &,
1281+
const InputSets<T> &Inputs) {
1282+
DXASSERT_NOMSG(Inputs.size() == 1);
1283+
size_t VectorSize = Inputs[0].size();
1284+
1285+
std::vector<T> Expected;
1286+
Expected.resize(VectorSize * 2);
1287+
1288+
for (size_t I = 0; I < VectorSize; ++I) {
1289+
T Exp;
1290+
T Man = modF(Inputs[0][I], Exp);
1291+
Expected[I] = Man;
1292+
Expected[I + VectorSize] = Exp;
1293+
}
1294+
1295+
return Expected;
1296+
}
1297+
};
1298+
12641299
//
12651300
// Wave Ops
12661301
//
@@ -1957,10 +1992,12 @@ class DxilConf_SM69_Vectorized {
19571992
HLK_TEST(IsFinite, HLSLHalf_t);
19581993
HLK_TEST(IsInf, HLSLHalf_t);
19591994
HLK_TEST(IsNan, HLSLHalf_t);
1995+
HLK_TEST(ModF, HLSLHalf_t);
19601996

19611997
HLK_TEST(IsFinite, float);
19621998
HLK_TEST(IsInf, float);
19631999
HLK_TEST(IsNan, float);
2000+
HLK_TEST(ModF, float);
19642001

19652002
// Binary Comparison
19662003

tools/clang/unittests/HLSLExec/ShaderOpArith.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4121,6 +4121,20 @@ void MSMain(uint GID : SV_GroupIndex,
41214121
}
41224122
#endif
41234123
4124+
#ifdef FUNC_TEST_MODF
4125+
vector<OUT_TYPE, NUM> TestModF(vector<TYPE, NUM> Vector)
4126+
{
4127+
vector<OUT_TYPE, NUM> Mantissa;
4128+
vector<OUT_TYPE, NUM> Exponent;
4129+
4130+
Mantissa = modf(Vector, Exponent);
4131+
4132+
g_OutputVector.Store< vector<OUT_TYPE, NUM> >(sizeof(OUT_TYPE) * NUM, Exponent);
4133+
4134+
return Mantissa;
4135+
}
4136+
#endif
4137+
41244138
#ifdef FUNC_SHUFFLE_VECTOR
41254139
vector<OUT_TYPE, NUM> TestShuffleVector(TYPE Scalar)
41264140
{

0 commit comments

Comments
 (0)