diff --git a/test_common/harness/conversions.h b/test_common/harness/conversions.h index 50f2838a..8e5346d4 100644 --- a/test_common/harness/conversions.h +++ b/test_common/harness/conversions.h @@ -114,7 +114,8 @@ static inline int IsDoubleSubnormal( double x ) } static inline int IsHalfSubnormal( cl_half x ) -{ +{ + // this relies on interger overflow to exclude 0 as a subnormal return ( ( x & 0x7fffU ) - 1U ) < 0x03ffU; } diff --git a/test_conformance/half/cl_utils.h b/test_conformance/half/cl_utils.h index 82a63115..50d8af3d 100644 --- a/test_conformance/half/cl_utils.h +++ b/test_conformance/half/cl_utils.h @@ -18,6 +18,7 @@ #include "harness/testHarness.h" #include "harness/compat.h" +#include "harness/conversions.h" #include @@ -109,43 +110,6 @@ static inline cl_ulong DoubleFromUInt( cl_uint bits ) return u; } -static inline int IsHalfSubnormal( uint16_t x ) -{ - // this relies on interger overflow to exclude 0 as a subnormal - return ( ( x & 0x7fffU ) - 1U ) < 0x03ffU; -} - -// prevent silent failures due to missing FLT_RADIX -#ifndef FLT_RADIX - #error FLT_RADIX is not defined by float.h -#endif - -static inline int IsFloatSubnormal( double x ) -{ -#if 2 == FLT_RADIX - // Do this in integer to avoid problems with FTZ behavior - union{ float d; uint32_t u;}u; - u.d = fabsf((float) x); - return (u.u-1) < 0x007fffffU; -#else - // rely on floating point hardware for non-radix2 non-IEEE-754 hardware -- will fail if you flush subnormals to zero - return fabs(x) < (double) FLT_MIN && x != 0.0; -#endif -} - -static inline int IsDoubleSubnormal( long double x ) -{ -#if 2 == FLT_RADIX - // Do this in integer to avoid problems with FTZ behavior - union{ double d; uint64_t u;}u; - u.d = fabs((double)x); - return (u.u-1) < 0x000fffffffffffffULL; -#else - // rely on floating point hardware for non-radix2 non-IEEE-754 hardware -- will fail if you flush subnormals to zero - return fabs(x) < (double) DBL_MIN && x != 0.0; -#endif -} - #endif /* CL_UTILS_H */ diff --git a/test_conformance/math_brute_force/Utility.h b/test_conformance/math_brute_force/Utility.h index 02bb4b9f..7011c95f 100644 --- a/test_conformance/math_brute_force/Utility.h +++ b/test_conformance/math_brute_force/Utility.h @@ -28,6 +28,7 @@ #include "harness/fpcontrol.h" #include "harness/testHarness.h" #include "harness/ThreadPool.h" +#include "harness/conversions.h" #define BUFFER_SIZE (1024*1024*2) #if defined( __GNUC__ ) @@ -124,34 +125,6 @@ void _LogBuildError( cl_program p, int line, const char *file ); #define PERF_LOOP_COUNT 100 -// Note: though this takes a double, this is for use with single precision tests -static inline int IsFloatSubnormal( double x ) -{ -#if 2 == FLT_RADIX - // Do this in integer to avoid problems with FTZ behavior - union{ float d; uint32_t u;}u; - u.d = fabsf((float)x); - return (u.u-1) < 0x007fffffU; -#else - // rely on floating point hardware for non-radix2 non-IEEE-754 hardware -- will fail if you flush subnormals to zero - return fabs(x) < (double) FLT_MIN && x != 0.0; -#endif -} - - -static inline int IsDoubleSubnormal( long double x ) -{ -#if 2 == FLT_RADIX - // Do this in integer to avoid problems with FTZ behavior - union{ double d; uint64_t u;}u; - u.d = fabs((double) x); - return (u.u-1) < 0x000fffffffffffffULL; -#else - // rely on floating point hardware for non-radix2 non-IEEE-754 hardware -- will fail if you flush subnormals to zero - return fabs(x) < (double) DBL_MIN && x != 0.0; -#endif -} - //The spec is fairly clear that we may enforce a hard cutoff to prevent premature flushing to zero. // However, to avoid conflict for 1.0, we are letting results at TYPE_MIN + ulp_limit to be flushed to zero. static inline int IsFloatResultSubnormal( double x, float ulps )