From 6b1e61f9dedd852a8a33cd97bb0f9bca98e8995a Mon Sep 17 00:00:00 2001 From: Sreelakshmi Haridas Maruthur Date: Sun, 6 Sep 2020 01:57:27 -0600 Subject: [PATCH] bruteforce: Fix out-of-domain input handling in bruteforce (#699) Cast input array to floats before setting NANs which are also floats to prevent large nonsensical numbers outside of the valid domains of several math functions from being tested. Khronos Bug: https://github.com/KhronosGroup/OpenCL-CTS/issues/491 Test Suite Affected: bruteforce Subtests: sin, cos, sincos, reciprocal Change-Id: Ie029837f4f9dfc73d6a9c356b73158e2ad41b871 --- test_conformance/math_brute_force/unary.cpp | 12 ++++++++---- .../math_brute_force/unary_two_results.cpp | 6 ++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/test_conformance/math_brute_force/unary.cpp b/test_conformance/math_brute_force/unary.cpp index 5a45d23d..91bc92d9 100644 --- a/test_conformance/math_brute_force/unary.cpp +++ b/test_conformance/math_brute_force/unary.cpp @@ -506,14 +506,18 @@ static cl_int TestFloat( cl_uint job_id, cl_uint thread_id, void *data ) float p_j = *(float *) &p[j]; if ( strcmp(fname,"sin")==0 || strcmp(fname,"cos")==0 ) //the domain of the function is [-pi,pi] { - if( fabs(p_j) > M_PI ) - p[j] = NAN; + if (fabs(p_j) > M_PI) ((float *)p)[j] = NAN; } if ( strcmp( fname, "reciprocal" ) == 0 ) { - if( fabs(p_j) > 0x7E800000 ) //the domain of the function is [2^-126,2^126] - p[j] = NAN; + const float l_limit = HEX_FLT(+, 1, 0, -, 126); + const float u_limit = HEX_FLT(+, 1, 0, +, 126); + + if (fabs(p_j) < l_limit + || fabs(p_j) + > u_limit) // the domain of the function is [2^-126,2^126] + ((float *)p)[j] = NAN; } } } diff --git a/test_conformance/math_brute_force/unary_two_results.cpp b/test_conformance/math_brute_force/unary_two_results.cpp index 4f39fde4..a86277f1 100644 --- a/test_conformance/math_brute_force/unary_two_results.cpp +++ b/test_conformance/math_brute_force/unary_two_results.cpp @@ -239,8 +239,7 @@ int TestFunc_Float2_Float(const Func *f, MTdata d, bool relaxedMode) if (relaxedMode && strcmp(f->name, "sincos") == 0) { float pj = *(float *)&p[j]; - if(fabs(pj) > M_PI) - p[j] = NAN; + if (fabs(pj) > M_PI) ((float *)p)[j] = NAN; } } } @@ -252,8 +251,7 @@ int TestFunc_Float2_Float(const Func *f, MTdata d, bool relaxedMode) if (relaxedMode && strcmp(f->name, "sincos") == 0) { float pj = *(float *)&p[j]; - if(fabs(pj) > M_PI) - p[j] = NAN; + if (fabs(pj) > M_PI) ((float *)p)[j] = NAN; } } }