tint: Implement const-eval of quantizeToF16

Bug: tint:1581
Change-Id: I5cf9806bde7875282d3b67731dbb88666523f598
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/108142
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/tint/intrinsics.def b/src/tint/intrinsics.def
index cc22831..3146aa8 100644
--- a/src/tint/intrinsics.def
+++ b/src/tint/intrinsics.def
@@ -514,8 +514,8 @@
 fn pack4x8unorm(vec4<f32>) -> u32
 fn pow<T: f32_f16>(T, T) -> T
 fn pow<N: num, T: f32_f16>(vec<N, T>, vec<N, T>) -> vec<N, T>
-fn quantizeToF16(f32) -> f32
-fn quantizeToF16<N: num>(vec<N, f32>) -> vec<N, f32>
+@const fn quantizeToF16(f32) -> f32
+@const fn quantizeToF16<N: num>(vec<N, f32>) -> vec<N, f32>
 fn radians<T: f32_f16>(T) -> T
 fn radians<N: num, T: f32_f16>(vec<N, T>) -> vec<N, T>
 fn reflect<N: num, T: f32_f16>(vec<N, T>, vec<N, T>) -> vec<N, T>
diff --git a/src/tint/resolver/const_eval.cc b/src/tint/resolver/const_eval.cc
index b61151d..0331f46 100644
--- a/src/tint/resolver/const_eval.cc
+++ b/src/tint/resolver/const_eval.cc
@@ -1869,6 +1869,27 @@
     return TransformElements(builder, ty, transform, args[0], args[1]);
 }
 
+ConstEval::Result ConstEval::quantizeToF16(const sem::Type* ty,
+                                           utils::VectorRef<const sem::Constant*> args,
+                                           const Source&) {
+    auto transform = [&](const sem::Constant* c) {
+        auto conv = CheckedConvert<f32>(f16(c->As<f32>()));
+        if (!conv) {
+            // https://www.w3.org/TR/WGSL/#quantizeToF16-builtin
+            // If e is outside the finite range of binary16, then the result is any value of type
+            // f32
+            switch (conv.Failure()) {
+                case ConversionFailure::kExceedsNegativeLimit:
+                    return CreateElement(builder, c->Type(), f16(f16::kLowestValue));
+                case ConversionFailure::kExceedsPositiveLimit:
+                    return CreateElement(builder, c->Type(), f16(f16::kHighestValue));
+            }
+        }
+        return CreateElement(builder, c->Type(), conv.Get());
+    };
+    return TransformElements(builder, ty, transform, args[0]);
+}
+
 ConstEval::Result ConstEval::Convert(const sem::Type* target_ty,
                                      const sem::Constant* value,
                                      const Source& source) {
diff --git a/src/tint/resolver/const_eval.h b/src/tint/resolver/const_eval.h
index 91189fa..07ce7e7 100644
--- a/src/tint/resolver/const_eval.h
+++ b/src/tint/resolver/const_eval.h
@@ -530,6 +530,15 @@
                 utils::VectorRef<const sem::Constant*> args,
                 const Source& source);
 
+    /// quantizeToF16 builtin
+    /// @param ty the expression type
+    /// @param args the input arguments
+    /// @param source the source location of the conversion
+    /// @return the result value, or null if the value cannot be calculated
+    Result quantizeToF16(const sem::Type* ty,
+                         utils::VectorRef<const sem::Constant*> args,
+                         const Source& source);
+
   private:
     /// Adds the given error message to the diagnostics
     void AddError(const std::string& msg, const Source& source) const;
diff --git a/src/tint/resolver/const_eval_builtin_test.cc b/src/tint/resolver/const_eval_builtin_test.cc
index 3c275cb..daa5a72 100644
--- a/src/tint/resolver/const_eval_builtin_test.cc
+++ b/src/tint/resolver/const_eval_builtin_test.cc
@@ -842,5 +842,62 @@
                                               StepCases<f32>(),
                                               StepCases<f16>()))));
 
+std::vector<Case> QuantizeToF16Cases() {
+    return {
+        C({0_f}, 0_f),    //
+        C({-0_f}, -0_f),  //
+        C({1_f}, 1_f),    //
+        C({-1_f}, -1_f),  //
+
+        //   0.00006106496 quantized to 0.000061035156 = 0x1p-14
+        C({0.00006106496_f}, 0.000061035156_f),    //
+        C({-0.00006106496_f}, -0.000061035156_f),  //
+
+        //   1.0004883 quantized to 1.0 = 0x1p0
+        C({1.0004883_f}, 1.0_f),    //
+        C({-1.0004883_f}, -1.0_f),  //
+
+        //   8196.0 quantized to 8192.0 = 0x1p13
+        C({8196_f}, 8192_f),    //
+        C({-8196_f}, -8192_f),  //
+
+        // Value in subnormal f16 range
+        C({0x0.034p-14_f}, 0x0.034p-14_f),    //
+        C({-0x0.034p-14_f}, -0x0.034p-14_f),  //
+        C({0x0.068p-14_f}, 0x0.068p-14_f),    //
+        C({-0x0.068p-14_f}, -0x0.068p-14_f),  //
+
+        //   0x0.06b7p-14 quantized to 0x0.068p-14
+        C({0x0.06b7p-14_f}, 0x0.068p-14_f),    //
+        C({-0x0.06b7p-14_f}, -0x0.068p-14_f),  //
+
+        // Value out of f16 range
+        C({65504.003_f}, 65504_f),     //
+        C({-65504.003_f}, -65504_f),   //
+        C({0x1.234p56_f}, 65504_f),    //
+        C({-0x4.321p65_f}, -65504_f),  //
+
+        // Vector tests
+        C({Vec(0_f, -0_f)}, Vec(0_f, -0_f)),  //
+        C({Vec(1_f, -1_f)}, Vec(1_f, -1_f)),  //
+
+        C({Vec(0.00006106496_f, -0.00006106496_f, 1.0004883_f, -1.0004883_f)},
+          Vec(0.000061035156_f, -0.000061035156_f, 1.0_f, -1.0_f)),
+
+        C({Vec(8196_f, 8192_f, 0x0.034p-14_f)}, Vec(8192_f, 8192_f, 0x0.034p-14_f)),
+
+        C({Vec(0x0.034p-14_f, -0x0.034p-14_f, 0x0.068p-14_f, -0x0.068p-14_f)},
+          Vec(0x0.034p-14_f, -0x0.034p-14_f, 0x0.068p-14_f, -0x0.068p-14_f)),
+
+        C({Vec(65504.003_f, 0x1.234p56_f)}, Vec(65504_f, 65504_f)),
+        C({Vec(-0x1.234p56_f, -65504.003_f)}, Vec(-65504_f, -65504_f)),
+    };
+}
+INSTANTIATE_TEST_SUITE_P(  //
+    QuantizeToF16,
+    ResolverConstEvalBuiltinTest,
+    testing::Combine(testing::Values(sem::BuiltinType::kQuantizeToF16),
+                     testing::ValuesIn(QuantizeToF16Cases())));
+
 }  // namespace
 }  // namespace tint::resolver
diff --git a/src/tint/resolver/intrinsic_table.inl b/src/tint/resolver/intrinsic_table.inl
index 5335ed7..ea7ad98 100644
--- a/src/tint/resolver/intrinsic_table.inl
+++ b/src/tint/resolver/intrinsic_table.inl
@@ -12302,7 +12302,7 @@
     /* parameters */ &kParameters[880],
     /* return matcher indices */ &kMatcherIndices[62],
     /* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
-    /* const eval */ nullptr,
+    /* const eval */ &ConstEval::quantizeToF16,
   },
   {
     /* [331] */
@@ -12314,7 +12314,7 @@
     /* parameters */ &kParameters[879],
     /* return matcher indices */ &kMatcherIndices[60],
     /* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
-    /* const eval */ nullptr,
+    /* const eval */ &ConstEval::quantizeToF16,
   },
   {
     /* [332] */
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.dxc.hlsl
index 0068d1c..4ed0cbc 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.dxc.hlsl
@@ -1,5 +1,5 @@
 void quantizeToF16_12e50e() {
-  float res = float(min16float(1.0f));
+  float res = 1.0f;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.fxc.hlsl
index 0068d1c..4ed0cbc 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.fxc.hlsl
+++ b/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.fxc.hlsl
@@ -1,5 +1,5 @@
 void quantizeToF16_12e50e() {
-  float res = float(min16float(1.0f));
+  float res = 1.0f;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.glsl b/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.glsl
index b0c188f..531c0b2 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.glsl
@@ -1,12 +1,7 @@
 #version 310 es
 
-float tint_quantizeToF16(float param_0) {
-  return unpackHalf2x16(packHalf2x16(vec2(param_0))).x;
-}
-
-
 void quantizeToF16_12e50e() {
-  float res = tint_quantizeToF16(1.0f);
+  float res = 1.0f;
 }
 
 vec4 vertex_main() {
@@ -25,13 +20,8 @@
 #version 310 es
 precision mediump float;
 
-float tint_quantizeToF16(float param_0) {
-  return unpackHalf2x16(packHalf2x16(vec2(param_0))).x;
-}
-
-
 void quantizeToF16_12e50e() {
-  float res = tint_quantizeToF16(1.0f);
+  float res = 1.0f;
 }
 
 void fragment_main() {
@@ -44,13 +34,8 @@
 }
 #version 310 es
 
-float tint_quantizeToF16(float param_0) {
-  return unpackHalf2x16(packHalf2x16(vec2(param_0))).x;
-}
-
-
 void quantizeToF16_12e50e() {
-  float res = tint_quantizeToF16(1.0f);
+  float res = 1.0f;
 }
 
 void compute_main() {
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.msl b/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.msl
index ef41ccf..1299d62 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.msl
+++ b/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.msl
@@ -2,7 +2,7 @@
 
 using namespace metal;
 void quantizeToF16_12e50e() {
-  float res = float(half(1.0f));
+  float res = 1.0f;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.spvasm
index c9d9f27..623716f 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.spvasm
+++ b/test/tint/builtins/gen/literal/quantizeToF16/12e50e.wgsl.expected.spvasm
@@ -1,7 +1,7 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 0
-; Bound: 30
+; Bound: 29
 ; Schema: 0
                OpCapability Shader
                OpMemoryModel Logical GLSL450
@@ -32,33 +32,32 @@
           %9 = OpTypeFunction %void
     %float_1 = OpConstant %float 1
 %_ptr_Function_float = OpTypePointer Function %float
-         %17 = OpTypeFunction %v4float
+         %16 = OpTypeFunction %v4float
 %quantizeToF16_12e50e = OpFunction %void None %9
          %12 = OpLabel
         %res = OpVariable %_ptr_Function_float Function %8
-         %13 = OpQuantizeToF16 %float %float_1
-               OpStore %res %13
+               OpStore %res %float_1
                OpReturn
                OpFunctionEnd
-%vertex_main_inner = OpFunction %v4float None %17
-         %19 = OpLabel
-         %20 = OpFunctionCall %void %quantizeToF16_12e50e
+%vertex_main_inner = OpFunction %v4float None %16
+         %18 = OpLabel
+         %19 = OpFunctionCall %void %quantizeToF16_12e50e
                OpReturnValue %5
                OpFunctionEnd
 %vertex_main = OpFunction %void None %9
-         %22 = OpLabel
-         %23 = OpFunctionCall %v4float %vertex_main_inner
-               OpStore %value %23
+         %21 = OpLabel
+         %22 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %22
                OpStore %vertex_point_size %float_1
                OpReturn
                OpFunctionEnd
 %fragment_main = OpFunction %void None %9
-         %25 = OpLabel
-         %26 = OpFunctionCall %void %quantizeToF16_12e50e
+         %24 = OpLabel
+         %25 = OpFunctionCall %void %quantizeToF16_12e50e
                OpReturn
                OpFunctionEnd
 %compute_main = OpFunction %void None %9
-         %28 = OpLabel
-         %29 = OpFunctionCall %void %quantizeToF16_12e50e
+         %27 = OpLabel
+         %28 = OpFunctionCall %void %quantizeToF16_12e50e
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.dxc.hlsl
index d50ffc8..ef0fc56 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.dxc.hlsl
@@ -1,5 +1,5 @@
 void quantizeToF16_2cddf3() {
-  float2 res = float2(min16float2((1.0f).xx));
+  float2 res = (1.0f).xx;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.fxc.hlsl
index d50ffc8..ef0fc56 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.fxc.hlsl
+++ b/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.fxc.hlsl
@@ -1,5 +1,5 @@
 void quantizeToF16_2cddf3() {
-  float2 res = float2(min16float2((1.0f).xx));
+  float2 res = (1.0f).xx;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.glsl b/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.glsl
index 70672e9..1a895b1 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.glsl
@@ -1,12 +1,7 @@
 #version 310 es
 
-vec2 tint_quantizeToF16(vec2 param_0) {
-  return unpackHalf2x16(packHalf2x16(param_0));
-}
-
-
 void quantizeToF16_2cddf3() {
-  vec2 res = tint_quantizeToF16(vec2(1.0f));
+  vec2 res = vec2(1.0f);
 }
 
 vec4 vertex_main() {
@@ -25,13 +20,8 @@
 #version 310 es
 precision mediump float;
 
-vec2 tint_quantizeToF16(vec2 param_0) {
-  return unpackHalf2x16(packHalf2x16(param_0));
-}
-
-
 void quantizeToF16_2cddf3() {
-  vec2 res = tint_quantizeToF16(vec2(1.0f));
+  vec2 res = vec2(1.0f);
 }
 
 void fragment_main() {
@@ -44,13 +34,8 @@
 }
 #version 310 es
 
-vec2 tint_quantizeToF16(vec2 param_0) {
-  return unpackHalf2x16(packHalf2x16(param_0));
-}
-
-
 void quantizeToF16_2cddf3() {
-  vec2 res = tint_quantizeToF16(vec2(1.0f));
+  vec2 res = vec2(1.0f);
 }
 
 void compute_main() {
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.msl b/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.msl
index 0ac4a09..eccd5ae 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.msl
+++ b/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.msl
@@ -2,7 +2,7 @@
 
 using namespace metal;
 void quantizeToF16_2cddf3() {
-  float2 res = float2(half2(float2(1.0f)));
+  float2 res = float2(1.0f);
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.spvasm
index 189b7c0..b71e9da 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.spvasm
+++ b/test/tint/builtins/gen/literal/quantizeToF16/2cddf3.wgsl.expected.spvasm
@@ -1,7 +1,7 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 0
-; Bound: 45
+; Bound: 32
 ; Schema: 0
                OpCapability Shader
                OpMemoryModel Logical GLSL450
@@ -12,8 +12,6 @@
                OpExecutionMode %compute_main LocalSize 1 1 1
                OpName %value "value"
                OpName %vertex_point_size "vertex_point_size"
-               OpName %tint_quantizeToF16 "tint_quantizeToF16"
-               OpName %v "v"
                OpName %quantizeToF16_2cddf3 "quantizeToF16_2cddf3"
                OpName %res "res"
                OpName %vertex_main_inner "vertex_main_inner"
@@ -30,54 +28,39 @@
 %_ptr_Output_float = OpTypePointer Output %float
           %8 = OpConstantNull %float
 %vertex_point_size = OpVariable %_ptr_Output_float Output %8
-    %v2float = OpTypeVector %float 2
-          %9 = OpTypeFunction %v2float %v2float
-       %uint = OpTypeInt 32 0
-         %16 = OpConstantNull %uint
-     %uint_1 = OpConstant %uint 1
        %void = OpTypeVoid
-         %22 = OpTypeFunction %void
+          %9 = OpTypeFunction %void
+    %v2float = OpTypeVector %float 2
     %float_1 = OpConstant %float 1
-         %28 = OpConstantComposite %v2float %float_1 %float_1
+         %15 = OpConstantComposite %v2float %float_1 %float_1
 %_ptr_Function_v2float = OpTypePointer Function %v2float
-         %31 = OpConstantNull %v2float
-         %32 = OpTypeFunction %v4float
-%tint_quantizeToF16 = OpFunction %v2float None %9
-          %v = OpFunctionParameter %v2float
-         %13 = OpLabel
-         %17 = OpCompositeExtract %float %v 0
-         %14 = OpQuantizeToF16 %float %17
-         %20 = OpCompositeExtract %float %v 1
-         %18 = OpQuantizeToF16 %float %20
-         %21 = OpCompositeConstruct %v2float %14 %18
-               OpReturnValue %21
-               OpFunctionEnd
-%quantizeToF16_2cddf3 = OpFunction %void None %22
-         %25 = OpLabel
-        %res = OpVariable %_ptr_Function_v2float Function %31
-         %26 = OpFunctionCall %v2float %tint_quantizeToF16 %28
-               OpStore %res %26
+         %18 = OpConstantNull %v2float
+         %19 = OpTypeFunction %v4float
+%quantizeToF16_2cddf3 = OpFunction %void None %9
+         %12 = OpLabel
+        %res = OpVariable %_ptr_Function_v2float Function %18
+               OpStore %res %15
                OpReturn
                OpFunctionEnd
-%vertex_main_inner = OpFunction %v4float None %32
-         %34 = OpLabel
-         %35 = OpFunctionCall %void %quantizeToF16_2cddf3
+%vertex_main_inner = OpFunction %v4float None %19
+         %21 = OpLabel
+         %22 = OpFunctionCall %void %quantizeToF16_2cddf3
                OpReturnValue %5
                OpFunctionEnd
-%vertex_main = OpFunction %void None %22
-         %37 = OpLabel
-         %38 = OpFunctionCall %v4float %vertex_main_inner
-               OpStore %value %38
+%vertex_main = OpFunction %void None %9
+         %24 = OpLabel
+         %25 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %25
                OpStore %vertex_point_size %float_1
                OpReturn
                OpFunctionEnd
-%fragment_main = OpFunction %void None %22
-         %40 = OpLabel
-         %41 = OpFunctionCall %void %quantizeToF16_2cddf3
+%fragment_main = OpFunction %void None %9
+         %27 = OpLabel
+         %28 = OpFunctionCall %void %quantizeToF16_2cddf3
                OpReturn
                OpFunctionEnd
-%compute_main = OpFunction %void None %22
-         %43 = OpLabel
-         %44 = OpFunctionCall %void %quantizeToF16_2cddf3
+%compute_main = OpFunction %void None %9
+         %30 = OpLabel
+         %31 = OpFunctionCall %void %quantizeToF16_2cddf3
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.dxc.hlsl
index 85c7a6d..e597919 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.dxc.hlsl
@@ -1,5 +1,5 @@
 void quantizeToF16_cba294() {
-  float4 res = float4(min16float4((1.0f).xxxx));
+  float4 res = (1.0f).xxxx;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.fxc.hlsl
index 85c7a6d..e597919 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.fxc.hlsl
+++ b/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.fxc.hlsl
@@ -1,5 +1,5 @@
 void quantizeToF16_cba294() {
-  float4 res = float4(min16float4((1.0f).xxxx));
+  float4 res = (1.0f).xxxx;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.glsl b/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.glsl
index a16f0f9..dc1eb66 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.glsl
@@ -1,14 +1,7 @@
 #version 310 es
 
-vec4 tint_quantizeToF16(vec4 param_0) {
-  return vec4(
-    unpackHalf2x16(packHalf2x16(param_0.xy)),
-    unpackHalf2x16(packHalf2x16(param_0.zw)));
-}
-
-
 void quantizeToF16_cba294() {
-  vec4 res = tint_quantizeToF16(vec4(1.0f));
+  vec4 res = vec4(1.0f);
 }
 
 vec4 vertex_main() {
@@ -27,15 +20,8 @@
 #version 310 es
 precision mediump float;
 
-vec4 tint_quantizeToF16(vec4 param_0) {
-  return vec4(
-    unpackHalf2x16(packHalf2x16(param_0.xy)),
-    unpackHalf2x16(packHalf2x16(param_0.zw)));
-}
-
-
 void quantizeToF16_cba294() {
-  vec4 res = tint_quantizeToF16(vec4(1.0f));
+  vec4 res = vec4(1.0f);
 }
 
 void fragment_main() {
@@ -48,15 +34,8 @@
 }
 #version 310 es
 
-vec4 tint_quantizeToF16(vec4 param_0) {
-  return vec4(
-    unpackHalf2x16(packHalf2x16(param_0.xy)),
-    unpackHalf2x16(packHalf2x16(param_0.zw)));
-}
-
-
 void quantizeToF16_cba294() {
-  vec4 res = tint_quantizeToF16(vec4(1.0f));
+  vec4 res = vec4(1.0f);
 }
 
 void compute_main() {
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.msl b/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.msl
index d615dd5..6dbfc50 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.msl
+++ b/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.msl
@@ -2,7 +2,7 @@
 
 using namespace metal;
 void quantizeToF16_cba294() {
-  float4 res = float4(half4(float4(1.0f)));
+  float4 res = float4(1.0f);
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.spvasm
index 69dbb99..bea6961 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.spvasm
+++ b/test/tint/builtins/gen/literal/quantizeToF16/cba294.wgsl.expected.spvasm
@@ -1,7 +1,7 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 0
-; Bound: 49
+; Bound: 30
 ; Schema: 0
                OpCapability Shader
                OpMemoryModel Logical GLSL450
@@ -12,8 +12,6 @@
                OpExecutionMode %compute_main LocalSize 1 1 1
                OpName %value "value"
                OpName %vertex_point_size "vertex_point_size"
-               OpName %tint_quantizeToF16 "tint_quantizeToF16"
-               OpName %v "v"
                OpName %quantizeToF16_cba294 "quantizeToF16_cba294"
                OpName %res "res"
                OpName %vertex_main_inner "vertex_main_inner"
@@ -30,58 +28,37 @@
 %_ptr_Output_float = OpTypePointer Output %float
           %8 = OpConstantNull %float
 %vertex_point_size = OpVariable %_ptr_Output_float Output %8
-          %9 = OpTypeFunction %v4float %v4float
-       %uint = OpTypeInt 32 0
-         %15 = OpConstantNull %uint
-     %uint_1 = OpConstant %uint 1
-     %uint_2 = OpConstant %uint 2
-     %uint_3 = OpConstant %uint 3
        %void = OpTypeVoid
-         %27 = OpTypeFunction %void
+          %9 = OpTypeFunction %void
     %float_1 = OpConstant %float 1
-         %33 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
+         %14 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
 %_ptr_Function_v4float = OpTypePointer Function %v4float
-         %36 = OpTypeFunction %v4float
-%tint_quantizeToF16 = OpFunction %v4float None %9
-          %v = OpFunctionParameter %v4float
+         %17 = OpTypeFunction %v4float
+%quantizeToF16_cba294 = OpFunction %void None %9
          %12 = OpLabel
-         %16 = OpCompositeExtract %float %v 0
-         %13 = OpQuantizeToF16 %float %16
-         %19 = OpCompositeExtract %float %v 1
-         %17 = OpQuantizeToF16 %float %19
-         %22 = OpCompositeExtract %float %v 2
-         %20 = OpQuantizeToF16 %float %22
-         %25 = OpCompositeExtract %float %v 3
-         %23 = OpQuantizeToF16 %float %25
-         %26 = OpCompositeConstruct %v4float %13 %17 %20 %23
-               OpReturnValue %26
-               OpFunctionEnd
-%quantizeToF16_cba294 = OpFunction %void None %27
-         %30 = OpLabel
         %res = OpVariable %_ptr_Function_v4float Function %5
-         %31 = OpFunctionCall %v4float %tint_quantizeToF16 %33
-               OpStore %res %31
+               OpStore %res %14
                OpReturn
                OpFunctionEnd
-%vertex_main_inner = OpFunction %v4float None %36
-         %38 = OpLabel
-         %39 = OpFunctionCall %void %quantizeToF16_cba294
+%vertex_main_inner = OpFunction %v4float None %17
+         %19 = OpLabel
+         %20 = OpFunctionCall %void %quantizeToF16_cba294
                OpReturnValue %5
                OpFunctionEnd
-%vertex_main = OpFunction %void None %27
-         %41 = OpLabel
-         %42 = OpFunctionCall %v4float %vertex_main_inner
-               OpStore %value %42
+%vertex_main = OpFunction %void None %9
+         %22 = OpLabel
+         %23 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %23
                OpStore %vertex_point_size %float_1
                OpReturn
                OpFunctionEnd
-%fragment_main = OpFunction %void None %27
-         %44 = OpLabel
-         %45 = OpFunctionCall %void %quantizeToF16_cba294
+%fragment_main = OpFunction %void None %9
+         %25 = OpLabel
+         %26 = OpFunctionCall %void %quantizeToF16_cba294
                OpReturn
                OpFunctionEnd
-%compute_main = OpFunction %void None %27
-         %47 = OpLabel
-         %48 = OpFunctionCall %void %quantizeToF16_cba294
+%compute_main = OpFunction %void None %9
+         %28 = OpLabel
+         %29 = OpFunctionCall %void %quantizeToF16_cba294
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.dxc.hlsl
index e5a09b3..c403817 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.dxc.hlsl
@@ -1,5 +1,5 @@
 void quantizeToF16_e8fd14() {
-  float3 res = float3(min16float3((1.0f).xxx));
+  float3 res = (1.0f).xxx;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.fxc.hlsl
index e5a09b3..c403817 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.fxc.hlsl
+++ b/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.fxc.hlsl
@@ -1,5 +1,5 @@
 void quantizeToF16_e8fd14() {
-  float3 res = float3(min16float3((1.0f).xxx));
+  float3 res = (1.0f).xxx;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.glsl b/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.glsl
index d277459..b5cf6bf 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.glsl
@@ -1,14 +1,7 @@
 #version 310 es
 
-vec3 tint_quantizeToF16(vec3 param_0) {
-  return vec3(
-    unpackHalf2x16(packHalf2x16(param_0.xy)),
-    unpackHalf2x16(packHalf2x16(param_0.zz)).x);
-}
-
-
 void quantizeToF16_e8fd14() {
-  vec3 res = tint_quantizeToF16(vec3(1.0f));
+  vec3 res = vec3(1.0f);
 }
 
 vec4 vertex_main() {
@@ -27,15 +20,8 @@
 #version 310 es
 precision mediump float;
 
-vec3 tint_quantizeToF16(vec3 param_0) {
-  return vec3(
-    unpackHalf2x16(packHalf2x16(param_0.xy)),
-    unpackHalf2x16(packHalf2x16(param_0.zz)).x);
-}
-
-
 void quantizeToF16_e8fd14() {
-  vec3 res = tint_quantizeToF16(vec3(1.0f));
+  vec3 res = vec3(1.0f);
 }
 
 void fragment_main() {
@@ -48,15 +34,8 @@
 }
 #version 310 es
 
-vec3 tint_quantizeToF16(vec3 param_0) {
-  return vec3(
-    unpackHalf2x16(packHalf2x16(param_0.xy)),
-    unpackHalf2x16(packHalf2x16(param_0.zz)).x);
-}
-
-
 void quantizeToF16_e8fd14() {
-  vec3 res = tint_quantizeToF16(vec3(1.0f));
+  vec3 res = vec3(1.0f);
 }
 
 void compute_main() {
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.msl b/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.msl
index 3c4a55b..cef9dc2 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.msl
+++ b/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.msl
@@ -2,7 +2,7 @@
 
 using namespace metal;
 void quantizeToF16_e8fd14() {
-  float3 res = float3(half3(float3(1.0f)));
+  float3 res = float3(1.0f);
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.spvasm
index af5c62d..83f1845 100644
--- a/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.spvasm
+++ b/test/tint/builtins/gen/literal/quantizeToF16/e8fd14.wgsl.expected.spvasm
@@ -1,7 +1,7 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 0
-; Bound: 48
+; Bound: 32
 ; Schema: 0
                OpCapability Shader
                OpMemoryModel Logical GLSL450
@@ -12,8 +12,6 @@
                OpExecutionMode %compute_main LocalSize 1 1 1
                OpName %value "value"
                OpName %vertex_point_size "vertex_point_size"
-               OpName %tint_quantizeToF16 "tint_quantizeToF16"
-               OpName %v "v"
                OpName %quantizeToF16_e8fd14 "quantizeToF16_e8fd14"
                OpName %res "res"
                OpName %vertex_main_inner "vertex_main_inner"
@@ -30,57 +28,39 @@
 %_ptr_Output_float = OpTypePointer Output %float
           %8 = OpConstantNull %float
 %vertex_point_size = OpVariable %_ptr_Output_float Output %8
-    %v3float = OpTypeVector %float 3
-          %9 = OpTypeFunction %v3float %v3float
-       %uint = OpTypeInt 32 0
-         %16 = OpConstantNull %uint
-     %uint_1 = OpConstant %uint 1
-     %uint_2 = OpConstant %uint 2
        %void = OpTypeVoid
-         %25 = OpTypeFunction %void
+          %9 = OpTypeFunction %void
+    %v3float = OpTypeVector %float 3
     %float_1 = OpConstant %float 1
-         %31 = OpConstantComposite %v3float %float_1 %float_1 %float_1
+         %15 = OpConstantComposite %v3float %float_1 %float_1 %float_1
 %_ptr_Function_v3float = OpTypePointer Function %v3float
-         %34 = OpConstantNull %v3float
-         %35 = OpTypeFunction %v4float
-%tint_quantizeToF16 = OpFunction %v3float None %9
-          %v = OpFunctionParameter %v3float
-         %13 = OpLabel
-         %17 = OpCompositeExtract %float %v 0
-         %14 = OpQuantizeToF16 %float %17
-         %20 = OpCompositeExtract %float %v 1
-         %18 = OpQuantizeToF16 %float %20
-         %23 = OpCompositeExtract %float %v 2
-         %21 = OpQuantizeToF16 %float %23
-         %24 = OpCompositeConstruct %v3float %14 %18 %21
-               OpReturnValue %24
-               OpFunctionEnd
-%quantizeToF16_e8fd14 = OpFunction %void None %25
-         %28 = OpLabel
-        %res = OpVariable %_ptr_Function_v3float Function %34
-         %29 = OpFunctionCall %v3float %tint_quantizeToF16 %31
-               OpStore %res %29
+         %18 = OpConstantNull %v3float
+         %19 = OpTypeFunction %v4float
+%quantizeToF16_e8fd14 = OpFunction %void None %9
+         %12 = OpLabel
+        %res = OpVariable %_ptr_Function_v3float Function %18
+               OpStore %res %15
                OpReturn
                OpFunctionEnd
-%vertex_main_inner = OpFunction %v4float None %35
-         %37 = OpLabel
-         %38 = OpFunctionCall %void %quantizeToF16_e8fd14
+%vertex_main_inner = OpFunction %v4float None %19
+         %21 = OpLabel
+         %22 = OpFunctionCall %void %quantizeToF16_e8fd14
                OpReturnValue %5
                OpFunctionEnd
-%vertex_main = OpFunction %void None %25
-         %40 = OpLabel
-         %41 = OpFunctionCall %v4float %vertex_main_inner
-               OpStore %value %41
+%vertex_main = OpFunction %void None %9
+         %24 = OpLabel
+         %25 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %25
                OpStore %vertex_point_size %float_1
                OpReturn
                OpFunctionEnd
-%fragment_main = OpFunction %void None %25
-         %43 = OpLabel
-         %44 = OpFunctionCall %void %quantizeToF16_e8fd14
+%fragment_main = OpFunction %void None %9
+         %27 = OpLabel
+         %28 = OpFunctionCall %void %quantizeToF16_e8fd14
                OpReturn
                OpFunctionEnd
-%compute_main = OpFunction %void None %25
-         %46 = OpLabel
-         %47 = OpFunctionCall %void %quantizeToF16_e8fd14
+%compute_main = OpFunction %void None %9
+         %30 = OpLabel
+         %31 = OpFunctionCall %void %quantizeToF16_e8fd14
                OpReturn
                OpFunctionEnd
diff --git a/webgpu-cts/expectations.txt b/webgpu-cts/expectations.txt
index cdb6e7f..38de05e 100644
--- a/webgpu-cts/expectations.txt
+++ b/webgpu-cts/expectations.txt
@@ -351,7 +351,6 @@
 crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,insertBits:integer:inputSource="uniform";signed=true;width=2 [ Failure ]
 crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,insertBits:integer:inputSource="uniform";signed=true;width=3 [ Failure ]
 crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,insertBits:integer:inputSource="uniform";signed=true;width=4 [ Failure ]
-crbug.com/dawn/0000 webgpu:shader,execution,expression,call,builtin,quantizeToF16:* [ Failure ]
 crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,sign:f32:inputSource="storage_r";vectorize="_undef_" [ Failure ]
 crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,sign:f32:inputSource="storage_r";vectorize=2 [ Failure ]
 crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,sign:f32:inputSource="storage_r";vectorize=3 [ Failure ]