diff --git a/tools/clang/unittests/HLSLExec/LongVectorOps.def b/tools/clang/unittests/HLSLExec/LongVectorOps.def index 002b84a1f2..d0a53c7a7d 100644 --- a/tools/clang/unittests/HLSLExec/LongVectorOps.def +++ b/tools/clang/unittests/HLSLExec/LongVectorOps.def @@ -129,6 +129,7 @@ OP_DEFAULT_DEFINES(UnaryMath, Frexp, 1, "TestFrexp", "", " -DFUNC_FREXP=1") OP_DEFAULT(FloatSpecial, IsFinite, 1, "isfinite", "") OP_DEFAULT(FloatSpecial, IsInf, 1, "isinf", "") OP_DEFAULT(FloatSpecial, IsNan, 1, "isnan", "") +OP_DEFAULT_DEFINES(FloatSpecial, ModF, 1, "TestModF", "", " -DFUNC_TEST_MODF=1") OP_DEFAULT(BinaryComparison, LessThan, 2, "", "<") OP_DEFAULT(BinaryComparison, LessEqual, 2, "", "<=") diff --git a/tools/clang/unittests/HLSLExec/LongVectors.cpp b/tools/clang/unittests/HLSLExec/LongVectors.cpp index dce99fd647..956cde347f 100644 --- a/tools/clang/unittests/HLSLExec/LongVectors.cpp +++ b/tools/clang/unittests/HLSLExec/LongVectors.cpp @@ -1236,6 +1236,41 @@ FLOAT_SPECIAL_OP(OpType::IsInf, (std::isinf(A))); FLOAT_SPECIAL_OP(OpType::IsNan, (std::isnan(A))); #undef FLOAT_SPECIAL_OP +template struct Op : DefaultValidation {}; + +template static T modF(T Input, T &OutParam); + +template <> float modF(float Input, float &OutParam) { + return std::modf(Input, &OutParam); +} + +template <> HLSLHalf_t modF(HLSLHalf_t Input, HLSLHalf_t &OutParam) { + float Exp = 0.0f; + float Man = std::modf(float(Input), &Exp); + OutParam = HLSLHalf_t(Exp); + return Man; +} + +template struct ExpectedBuilder { + static std::vector buildExpected(Op &, + const InputSets &Inputs) { + DXASSERT_NOMSG(Inputs.size() == 1); + size_t VectorSize = Inputs[0].size(); + + std::vector Expected; + Expected.resize(VectorSize * 2); + + for (size_t I = 0; I < VectorSize; ++I) { + T Exp; + T Man = modF(Inputs[0][I], Exp); + Expected[I] = Man; + Expected[I + VectorSize] = Exp; + } + + return Expected; + } +}; + // // dispatchTest // @@ -1772,10 +1807,12 @@ class DxilConf_SM69_Vectorized { HLK_TEST(IsFinite, HLSLHalf_t); HLK_TEST(IsInf, HLSLHalf_t); HLK_TEST(IsNan, HLSLHalf_t); + HLK_TEST(ModF, HLSLHalf_t); HLK_TEST(IsFinite, float); HLK_TEST(IsInf, float); HLK_TEST(IsNan, float); + HLK_TEST(ModF, float); // Binary Comparison diff --git a/tools/clang/unittests/HLSLExec/ShaderOpArith.xml b/tools/clang/unittests/HLSLExec/ShaderOpArith.xml index f89a87ca68..43fe5d6412 100644 --- a/tools/clang/unittests/HLSLExec/ShaderOpArith.xml +++ b/tools/clang/unittests/HLSLExec/ShaderOpArith.xml @@ -4112,6 +4112,20 @@ void MSMain(uint GID : SV_GroupIndex, } #endif + #ifdef FUNC_TEST_MODF + vector TestModF(vector Vector) + { + vector Mantissa; + vector Exponent; + + Mantissa = modf(Vector, Exponent); + + g_OutputVector.Store< vector >(sizeof(OUT_TYPE) * NUM, Exponent); + + return Mantissa; + } + #endif + #ifdef FUNC_SHUFFLE_VECTOR vector TestShuffleVector(TYPE Scalar) {