diff --git a/test_conformance/spirv_new/spirv_asm/decorate_saturated_conversion_char.spvasm32 b/test_conformance/spirv_new/spirv_asm/decorate_saturated_conversion_char.spvasm32 index 5437067f93..417b2efd1e 100644 --- a/test_conformance/spirv_new/spirv_asm/decorate_saturated_conversion_char.spvasm32 +++ b/test_conformance/spirv_new/spirv_asm/decorate_saturated_conversion_char.spvasm32 @@ -7,6 +7,7 @@ OpCapability Linkage OpCapability Kernel OpCapability Int8 + OpCapability Float16 OpMemoryModel Physical32 OpenCL OpEntryPoint Kernel %1 "decorate_saturated_conversion_char" %gl_GlobalInvocationID OpName %res "res" @@ -23,22 +24,22 @@ %void = OpTypeVoid %uchar = OpTypeInt 8 0 %_ptr_CrossWorkgroup_uchar = OpTypePointer CrossWorkgroup %uchar - %float = OpTypeFloat 32 -%_ptr_CrossWorkgroup_float = OpTypePointer CrossWorkgroup %float - %16 = OpTypeFunction %void %_ptr_CrossWorkgroup_uchar %_ptr_CrossWorkgroup_float %_ptr_CrossWorkgroup_float + %half = OpTypeFloat 16 +%_ptr_CrossWorkgroup_half = OpTypePointer CrossWorkgroup %half + %16 = OpTypeFunction %void %_ptr_CrossWorkgroup_uchar %_ptr_CrossWorkgroup_half %_ptr_CrossWorkgroup_half %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input %1 = OpFunction %void None %16 %res = OpFunctionParameter %_ptr_CrossWorkgroup_uchar - %lhs = OpFunctionParameter %_ptr_CrossWorkgroup_float - %rhs = OpFunctionParameter %_ptr_CrossWorkgroup_float + %lhs = OpFunctionParameter %_ptr_CrossWorkgroup_half + %rhs = OpFunctionParameter %_ptr_CrossWorkgroup_half %entry = OpLabel %17 = OpLoad %v3uint %gl_GlobalInvocationID Aligned 0 %18 = OpCompositeExtract %uint %17 0 - %19 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_float %lhs %18 - %20 = OpLoad %float %19 Aligned 4 - %21 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_float %rhs %18 - %22 = OpLoad %float %21 Aligned 4 - %23 = OpFMul %float %20 %22 + %19 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_half %lhs %18 + %20 = OpLoad %half %19 Aligned 2 + %21 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_half %rhs %18 + %22 = OpLoad %half %21 Aligned 2 + %23 = OpFMul %half %20 %22 %7 = OpConvertFToS %uchar %23 %24 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_uchar %res %18 OpStore %24 %7 diff --git a/test_conformance/spirv_new/spirv_asm/decorate_saturated_conversion_char.spvasm64 b/test_conformance/spirv_new/spirv_asm/decorate_saturated_conversion_char.spvasm64 index ba4d6492ac..7f75b7e20d 100644 --- a/test_conformance/spirv_new/spirv_asm/decorate_saturated_conversion_char.spvasm64 +++ b/test_conformance/spirv_new/spirv_asm/decorate_saturated_conversion_char.spvasm64 @@ -8,6 +8,7 @@ OpCapability Kernel OpCapability Int64 OpCapability Int8 + OpCapability Float16 OpMemoryModel Physical64 OpenCL OpEntryPoint Kernel %1 "decorate_saturated_conversion_char" %gl_GlobalInvocationID OpName %res "res" @@ -24,25 +25,25 @@ %void = OpTypeVoid %uchar = OpTypeInt 8 0 %_ptr_CrossWorkgroup_uchar = OpTypePointer CrossWorkgroup %uchar - %float = OpTypeFloat 32 -%_ptr_CrossWorkgroup_float = OpTypePointer CrossWorkgroup %float - %16 = OpTypeFunction %void %_ptr_CrossWorkgroup_uchar %_ptr_CrossWorkgroup_float %_ptr_CrossWorkgroup_float + %half = OpTypeFloat 16 +%_ptr_CrossWorkgroup_half = OpTypePointer CrossWorkgroup %half + %16 = OpTypeFunction %void %_ptr_CrossWorkgroup_uchar %_ptr_CrossWorkgroup_half %_ptr_CrossWorkgroup_half %ulong_32 = OpConstant %ulong 32 %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3ulong Input %1 = OpFunction %void None %16 %res = OpFunctionParameter %_ptr_CrossWorkgroup_uchar - %lhs = OpFunctionParameter %_ptr_CrossWorkgroup_float - %rhs = OpFunctionParameter %_ptr_CrossWorkgroup_float + %lhs = OpFunctionParameter %_ptr_CrossWorkgroup_half + %rhs = OpFunctionParameter %_ptr_CrossWorkgroup_half %entry = OpLabel %18 = OpLoad %v3ulong %gl_GlobalInvocationID Aligned 0 %19 = OpCompositeExtract %ulong %18 0 %20 = OpShiftLeftLogical %ulong %19 %ulong_32 %21 = OpShiftRightArithmetic %ulong %20 %ulong_32 - %22 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_float %lhs %21 - %23 = OpLoad %float %22 Aligned 4 - %24 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_float %rhs %21 - %25 = OpLoad %float %24 Aligned 4 - %26 = OpFMul %float %23 %25 + %22 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_half %lhs %21 + %23 = OpLoad %half %22 Aligned 2 + %24 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_half %rhs %21 + %25 = OpLoad %half %24 Aligned 2 + %26 = OpFMul %half %23 %25 %7 = OpConvertFToS %uchar %26 %27 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_uchar %res %21 OpStore %27 %7 diff --git a/test_conformance/spirv_new/spirv_asm/decorate_saturated_conversion_uchar.spvasm32 b/test_conformance/spirv_new/spirv_asm/decorate_saturated_conversion_uchar.spvasm32 index 9bffb686c8..b2225664f2 100644 --- a/test_conformance/spirv_new/spirv_asm/decorate_saturated_conversion_uchar.spvasm32 +++ b/test_conformance/spirv_new/spirv_asm/decorate_saturated_conversion_uchar.spvasm32 @@ -7,6 +7,7 @@ OpCapability Linkage OpCapability Kernel OpCapability Int8 + OpCapability Float16 OpMemoryModel Physical32 OpenCL OpEntryPoint Kernel %1 "decorate_saturated_conversion_uchar" %gl_GlobalInvocationID OpName %res "res" @@ -23,22 +24,22 @@ %void = OpTypeVoid %uchar = OpTypeInt 8 0 %_ptr_CrossWorkgroup_uchar = OpTypePointer CrossWorkgroup %uchar - %float = OpTypeFloat 32 -%_ptr_CrossWorkgroup_float = OpTypePointer CrossWorkgroup %float - %16 = OpTypeFunction %void %_ptr_CrossWorkgroup_uchar %_ptr_CrossWorkgroup_float %_ptr_CrossWorkgroup_float + %half = OpTypeFloat 16 +%_ptr_CrossWorkgroup_half = OpTypePointer CrossWorkgroup %half + %16 = OpTypeFunction %void %_ptr_CrossWorkgroup_uchar %_ptr_CrossWorkgroup_half %_ptr_CrossWorkgroup_half %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input %1 = OpFunction %void None %16 %res = OpFunctionParameter %_ptr_CrossWorkgroup_uchar - %lhs = OpFunctionParameter %_ptr_CrossWorkgroup_float - %rhs = OpFunctionParameter %_ptr_CrossWorkgroup_float + %lhs = OpFunctionParameter %_ptr_CrossWorkgroup_half + %rhs = OpFunctionParameter %_ptr_CrossWorkgroup_half %entry = OpLabel %17 = OpLoad %v3uint %gl_GlobalInvocationID Aligned 0 %18 = OpCompositeExtract %uint %17 0 - %19 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_float %lhs %18 - %20 = OpLoad %float %19 Aligned 4 - %21 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_float %rhs %18 - %22 = OpLoad %float %21 Aligned 4 - %23 = OpFMul %float %20 %22 + %19 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_half %lhs %18 + %20 = OpLoad %half %19 Aligned 2 + %21 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_half %rhs %18 + %22 = OpLoad %half %21 Aligned 2 + %23 = OpFMul %half %20 %22 %7 = OpConvertFToU %uchar %23 %24 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_uchar %res %18 OpStore %24 %7 diff --git a/test_conformance/spirv_new/spirv_asm/decorate_saturated_conversion_uchar.spvasm64 b/test_conformance/spirv_new/spirv_asm/decorate_saturated_conversion_uchar.spvasm64 index 354639fe65..0134d3af02 100644 --- a/test_conformance/spirv_new/spirv_asm/decorate_saturated_conversion_uchar.spvasm64 +++ b/test_conformance/spirv_new/spirv_asm/decorate_saturated_conversion_uchar.spvasm64 @@ -8,6 +8,7 @@ OpCapability Kernel OpCapability Int64 OpCapability Int8 + OpCapability Float16 OpMemoryModel Physical64 OpenCL OpEntryPoint Kernel %1 "decorate_saturated_conversion_uchar" %gl_GlobalInvocationID OpName %res "res" @@ -24,25 +25,25 @@ %void = OpTypeVoid %uchar = OpTypeInt 8 0 %_ptr_CrossWorkgroup_uchar = OpTypePointer CrossWorkgroup %uchar - %float = OpTypeFloat 32 -%_ptr_CrossWorkgroup_float = OpTypePointer CrossWorkgroup %float - %16 = OpTypeFunction %void %_ptr_CrossWorkgroup_uchar %_ptr_CrossWorkgroup_float %_ptr_CrossWorkgroup_float + %half = OpTypeFloat 16 +%_ptr_CrossWorkgroup_half = OpTypePointer CrossWorkgroup %half + %16 = OpTypeFunction %void %_ptr_CrossWorkgroup_uchar %_ptr_CrossWorkgroup_half %_ptr_CrossWorkgroup_half %ulong_32 = OpConstant %ulong 32 %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3ulong Input %1 = OpFunction %void None %16 %res = OpFunctionParameter %_ptr_CrossWorkgroup_uchar - %lhs = OpFunctionParameter %_ptr_CrossWorkgroup_float - %rhs = OpFunctionParameter %_ptr_CrossWorkgroup_float + %lhs = OpFunctionParameter %_ptr_CrossWorkgroup_half + %rhs = OpFunctionParameter %_ptr_CrossWorkgroup_half %entry = OpLabel %18 = OpLoad %v3ulong %gl_GlobalInvocationID Aligned 0 %19 = OpCompositeExtract %ulong %18 0 %20 = OpShiftLeftLogical %ulong %19 %ulong_32 %21 = OpShiftRightArithmetic %ulong %20 %ulong_32 - %22 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_float %lhs %21 - %23 = OpLoad %float %22 Aligned 4 - %24 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_float %rhs %21 - %25 = OpLoad %float %24 Aligned 4 - %26 = OpFMul %float %23 %25 + %22 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_half %lhs %21 + %23 = OpLoad %half %22 Aligned 2 + %24 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_half %rhs %21 + %25 = OpLoad %half %24 Aligned 2 + %26 = OpFMul %half %23 %25 %7 = OpConvertFToU %uchar %26 %27 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_uchar %res %21 OpStore %27 %7 diff --git a/test_conformance/spirv_new/test_decorate.cpp b/test_conformance/spirv_new/test_decorate.cpp index cbe6270261..ffcb1ec563 100644 --- a/test_conformance/spirv_new/test_decorate.cpp +++ b/test_conformance/spirv_new/test_decorate.cpp @@ -26,12 +26,15 @@ or Khronos Conformance Test Source License Agreement as executed between Khronos #define isnan std::isnan #endif +#define HALF_NAN 0x7e00 + long double reference_remainderl(long double x, long double y); int gIsInRTZMode = 0; int gDeviceILogb0 = 1; int gDeviceILogbNaN = 1; int gCheckTininessBeforeRounding = 1; +static int inline is_half_nan(cl_half half) { return (half & 0x7fff) > 0x7c00; } static int verify_results(cl_device_id deviceID, cl_context context, @@ -212,14 +215,39 @@ int verify_saturated_results(cl_device_id deviceID, Tl range = (Tl)(hiVal) - (Tl)(loVal); RandomSeed seed(gRandomSeed); - for (int i = 0; i < num; i++) { - h_lhs[i] = genrand(seed) * range; - Tl val = (genrand(seed) % hiVal); - // randomly set some values on rhs to NaN - if (val * 20 < hiVal) { - h_rhs[i] = NAN; - } else { - h_rhs[i] = (Ti)(val); + if (std::is_same::value) + { + for (int i = 0; i < num; i++) + { + h_lhs[i] = + cl_half_from_float(genrand(seed) * range, CL_HALF_RTE); + Tl val = (genrand(seed) % hiVal); + // randomly set some values on rhs to NaN + if (val * 20 < hiVal) + { + h_rhs[i] = HALF_NAN; + } + else + { + h_rhs[i] = (Ti)(val); + } + } + } + else + { + for (int i = 0; i < num; i++) + { + h_lhs[i] = genrand(seed) * range; + Tl val = (genrand(seed) % hiVal); + // randomly set some values on rhs to NaN + if (val * 20 < hiVal) + { + h_rhs[i] = NAN; + } + else + { + h_rhs[i] = (Ti)(val); + } } } @@ -256,11 +284,28 @@ int verify_saturated_results(cl_device_id deviceID, SPIRV_CHECK_ERROR(err, "Failed to read to output"); for (int i = 0; i < num; i++) { - Tl ival = (Tl)(h_lhs[i] * h_rhs[i]); - To val = (To)std::min(std::max(ival, loVal), hiVal); - if (isnan(h_rhs[i])) { - val = 0; + To val; + if (std::is_same::value) + { + Tl ival = + (Tl)(cl_half_to_float(h_lhs[i]) * cl_half_to_float(h_rhs[i])); + val = (To)std::min(std::max(ival, loVal), hiVal); + + if (is_half_nan(h_rhs[i])) + { + val = 0; + } + } + else + { + Tl ival = (Tl)(h_lhs[i] * h_rhs[i]); + val = (To)std::min(std::max(ival, loVal), hiVal); + + if (isnan(h_rhs[i])) + { + val = 0; + } } if (val != h_res[i]) { @@ -303,10 +348,10 @@ int test_saturate_full(cl_device_id deviceID, (deviceID, context, queue, \ "decorate_saturated_conversion_" #To, \ #Ti #Tl #To); \ - } \ + } -TEST_SATURATED_CONVERSION(float, int, char) -TEST_SATURATED_CONVERSION(float, uint, uchar) +TEST_SATURATED_CONVERSION(half, short, char) +TEST_SATURATED_CONVERSION(half, ushort, uchar) TEST_SATURATED_CONVERSION(float, int, short) TEST_SATURATED_CONVERSION(float, uint, ushort) TEST_SATURATED_CONVERSION(double, long, int)