GLSL: fix isNormal.

(I know it's deprecated, I'm just being a completist.)

Bug: tint:1222
Change-Id: Ie7716d2f5dd2d2bd2245ba2b0fe7ed8705574de0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/80141
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
diff --git a/src/writer/glsl/generator_impl.cc b/src/writer/glsl/generator_impl.cc
index 5cd4bdc..f31a4a8 100644
--- a/src/writer/glsl/generator_impl.cc
+++ b/src/writer/glsl/generator_impl.cc
@@ -970,21 +970,27 @@
       [&](TextBuffer* b, const std::vector<std::string>& params) {
         auto* input_ty = builtin->Parameters()[0]->Type();
 
-        std::string width;
+        std::string vec_type;
         if (auto* vec = input_ty->As<sem::Vector>()) {
-          width = std::to_string(vec->Width());
+          vec_type = "uvec" + std::to_string(vec->Width());
+        } else {
+          vec_type = "uint";
         }
 
-        constexpr auto* kExponentMask = "0x7f80000";
-        constexpr auto* kMinNormalExponent = "0x0080000";
-        constexpr auto* kMaxNormalExponent = "0x7f00000";
+        constexpr auto* kExponentMask = "0x7f80000u";
+        constexpr auto* kMinNormalExponent = "0x0080000u";
+        constexpr auto* kMaxNormalExponent = "0x7f00000u";
 
-        line(b) << "uint" << width << " exponent = asuint(" << params[0]
+        line(b) << vec_type << " exponent = floatBitsToUint(" << params[0]
                 << ") & " << kExponentMask << ";";
-        line(b) << "uint" << width << " clamped = "
+        line(b) << vec_type << " clamped = "
                 << "clamp(exponent, " << kMinNormalExponent << ", "
                 << kMaxNormalExponent << ");";
-        line(b) << "return clamped == exponent;";
+        if (input_ty->Is<sem::Vector>()) {
+          line(b) << "return equal(clamped, exponent);";
+        } else {
+          line(b) << "return clamped == exponent;";
+        }
         return true;
       });
 }
diff --git a/src/writer/glsl/generator_impl_builtin_test.cc b/src/writer/glsl/generator_impl_builtin_test.cc
index bac0b61..8650eb0 100644
--- a/src/writer/glsl/generator_impl_builtin_test.cc
+++ b/src/writer/glsl/generator_impl_builtin_test.cc
@@ -415,7 +415,6 @@
 )"));
 }
 
-#if 0
 TEST_F(GlslGeneratorImplTest_Builtin, IsNormal_Scalar) {
   auto* val = Var("val", ty.f32());
   auto* call = Call("isNormal", val);
@@ -424,10 +423,23 @@
   GeneratorImpl& gen = SanitizeAndBuild();
 
   ASSERT_TRUE(gen.Generate()) << gen.error();
-  EXPECT_THAT(gen.result(), HasSubstr(R"(
-  uint tint_isnormal_exponent = asuint(val) & 0x7f80000;
-  uint tint_isnormal_clamped = clamp(tint_isnormal_exponent, 0x0080000, 0x7f00000);
-  (tint_isnormal_clamped == tint_isnormal_exponent);
+  EXPECT_THAT(gen.result(), HasSubstr(R"(ion 310 es
+
+bool tint_isNormal(float param_0) {
+  uint exponent = floatBitsToUint(param_0) & 0x7f80000u;
+  uint clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
+  return clamped == exponent;
+}
+
+
+void test_function() {
+  float val = 0.0f;
+  bool tint_symbol = tint_isNormal(val);
+}
+
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+  test_function();
 )"));
 }
 
@@ -439,13 +451,25 @@
   GeneratorImpl& gen = SanitizeAndBuild();
 
   ASSERT_TRUE(gen.Generate()) << gen.error();
-  EXPECT_THAT(gen.result(), HasSubstr(R"(
-  uvec3 tint_isnormal_exponent = asuint(val) & 0x7f80000;
-  uvec3 tint_isnormal_clamped = clamp(tint_isnormal_exponent, 0x0080000, 0x7f00000);
-  (tint_isnormal_clamped == tint_isnormal_exponent);
+  EXPECT_THAT(gen.result(), HasSubstr(R"( 310 es
+
+bvec3 tint_isNormal(vec3 param_0) {
+  uvec3 exponent = floatBitsToUint(param_0) & 0x7f80000u;
+  uvec3 clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
+  return equal(clamped, exponent);
+}
+
+
+void test_function() {
+  vec3 val = vec3(0.0f, 0.0f, 0.0f);
+  bvec3 tint_symbol = tint_isNormal(val);
+}
+
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+  test_function();
 )"));
 }
-#endif
 
 TEST_F(GlslGeneratorImplTest_Builtin, Degrees_Scalar) {
   auto* val = Var("val", ty.f32());
diff --git a/test/builtins/gen/isNormal/863dcd.wgsl.expected.glsl b/test/builtins/gen/isNormal/863dcd.wgsl.expected.glsl
index 43d272c..29875d0 100644
--- a/test/builtins/gen/isNormal/863dcd.wgsl.expected.glsl
+++ b/test/builtins/gen/isNormal/863dcd.wgsl.expected.glsl
@@ -1,5 +1,3 @@
-SKIP: FAILED
-
 builtins/gen/isNormal/863dcd.wgsl:28:25 warning: use of deprecated builtin
   var res: vec4<bool> = isNormal(vec4<f32>());
                         ^^^^^^^^
@@ -7,9 +5,9 @@
 #version 310 es
 
 bvec4 tint_isNormal(vec4 param_0) {
-  uint4 exponent = asuint(param_0) & 0x7f80000;
-  uint4 clamped = clamp(exponent, 0x0080000, 0x7f00000);
-  return clamped == exponent;
+  uvec4 exponent = floatBitsToUint(param_0) & 0x7f80000u;
+  uvec4 clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
+  return equal(clamped, exponent);
 }
 
 
@@ -29,20 +27,13 @@
   gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:4: 'uint4' : undeclared identifier 
-ERROR: 0:4: '' : compilation terminated 
-ERROR: 2 compilation errors.  No code generated.
-
-
-
 #version 310 es
 precision mediump float;
 
 bvec4 tint_isNormal(vec4 param_0) {
-  uint4 exponent = asuint(param_0) & 0x7f80000;
-  uint4 clamped = clamp(exponent, 0x0080000, 0x7f00000);
-  return clamped == exponent;
+  uvec4 exponent = floatBitsToUint(param_0) & 0x7f80000u;
+  uvec4 clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
+  return equal(clamped, exponent);
 }
 
 
@@ -58,19 +49,12 @@
   fragment_main();
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:5: 'uint4' : undeclared identifier 
-ERROR: 0:5: '' : compilation terminated 
-ERROR: 2 compilation errors.  No code generated.
-
-
-
 #version 310 es
 
 bvec4 tint_isNormal(vec4 param_0) {
-  uint4 exponent = asuint(param_0) & 0x7f80000;
-  uint4 clamped = clamp(exponent, 0x0080000, 0x7f00000);
-  return clamped == exponent;
+  uvec4 exponent = floatBitsToUint(param_0) & 0x7f80000u;
+  uvec4 clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
+  return equal(clamped, exponent);
 }
 
 
@@ -87,10 +71,3 @@
   compute_main();
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:4: 'uint4' : undeclared identifier 
-ERROR: 0:4: '' : compilation terminated 
-ERROR: 2 compilation errors.  No code generated.
-
-
-
diff --git a/test/builtins/gen/isNormal/b00ab1.wgsl.expected.glsl b/test/builtins/gen/isNormal/b00ab1.wgsl.expected.glsl
index 1642490..2cdfc12 100644
--- a/test/builtins/gen/isNormal/b00ab1.wgsl.expected.glsl
+++ b/test/builtins/gen/isNormal/b00ab1.wgsl.expected.glsl
@@ -1,5 +1,3 @@
-SKIP: FAILED
-
 builtins/gen/isNormal/b00ab1.wgsl:28:25 warning: use of deprecated builtin
   var res: vec2<bool> = isNormal(vec2<f32>());
                         ^^^^^^^^
@@ -7,9 +5,9 @@
 #version 310 es
 
 bvec2 tint_isNormal(vec2 param_0) {
-  uint2 exponent = asuint(param_0) & 0x7f80000;
-  uint2 clamped = clamp(exponent, 0x0080000, 0x7f00000);
-  return clamped == exponent;
+  uvec2 exponent = floatBitsToUint(param_0) & 0x7f80000u;
+  uvec2 clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
+  return equal(clamped, exponent);
 }
 
 
@@ -29,20 +27,13 @@
   gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:4: 'uint2' : undeclared identifier 
-ERROR: 0:4: '' : compilation terminated 
-ERROR: 2 compilation errors.  No code generated.
-
-
-
 #version 310 es
 precision mediump float;
 
 bvec2 tint_isNormal(vec2 param_0) {
-  uint2 exponent = asuint(param_0) & 0x7f80000;
-  uint2 clamped = clamp(exponent, 0x0080000, 0x7f00000);
-  return clamped == exponent;
+  uvec2 exponent = floatBitsToUint(param_0) & 0x7f80000u;
+  uvec2 clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
+  return equal(clamped, exponent);
 }
 
 
@@ -58,19 +49,12 @@
   fragment_main();
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:5: 'uint2' : undeclared identifier 
-ERROR: 0:5: '' : compilation terminated 
-ERROR: 2 compilation errors.  No code generated.
-
-
-
 #version 310 es
 
 bvec2 tint_isNormal(vec2 param_0) {
-  uint2 exponent = asuint(param_0) & 0x7f80000;
-  uint2 clamped = clamp(exponent, 0x0080000, 0x7f00000);
-  return clamped == exponent;
+  uvec2 exponent = floatBitsToUint(param_0) & 0x7f80000u;
+  uvec2 clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
+  return equal(clamped, exponent);
 }
 
 
@@ -87,10 +71,3 @@
   compute_main();
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:4: 'uint2' : undeclared identifier 
-ERROR: 0:4: '' : compilation terminated 
-ERROR: 2 compilation errors.  No code generated.
-
-
-
diff --git a/test/builtins/gen/isNormal/c286b7.wgsl.expected.glsl b/test/builtins/gen/isNormal/c286b7.wgsl.expected.glsl
index 29e3684..061db27 100644
--- a/test/builtins/gen/isNormal/c286b7.wgsl.expected.glsl
+++ b/test/builtins/gen/isNormal/c286b7.wgsl.expected.glsl
@@ -1,5 +1,3 @@
-SKIP: FAILED
-
 builtins/gen/isNormal/c286b7.wgsl:28:25 warning: use of deprecated builtin
   var res: vec3<bool> = isNormal(vec3<f32>());
                         ^^^^^^^^
@@ -7,9 +5,9 @@
 #version 310 es
 
 bvec3 tint_isNormal(vec3 param_0) {
-  uint3 exponent = asuint(param_0) & 0x7f80000;
-  uint3 clamped = clamp(exponent, 0x0080000, 0x7f00000);
-  return clamped == exponent;
+  uvec3 exponent = floatBitsToUint(param_0) & 0x7f80000u;
+  uvec3 clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
+  return equal(clamped, exponent);
 }
 
 
@@ -29,20 +27,13 @@
   gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:4: 'uint3' : undeclared identifier 
-ERROR: 0:4: '' : compilation terminated 
-ERROR: 2 compilation errors.  No code generated.
-
-
-
 #version 310 es
 precision mediump float;
 
 bvec3 tint_isNormal(vec3 param_0) {
-  uint3 exponent = asuint(param_0) & 0x7f80000;
-  uint3 clamped = clamp(exponent, 0x0080000, 0x7f00000);
-  return clamped == exponent;
+  uvec3 exponent = floatBitsToUint(param_0) & 0x7f80000u;
+  uvec3 clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
+  return equal(clamped, exponent);
 }
 
 
@@ -58,19 +49,12 @@
   fragment_main();
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:5: 'uint3' : undeclared identifier 
-ERROR: 0:5: '' : compilation terminated 
-ERROR: 2 compilation errors.  No code generated.
-
-
-
 #version 310 es
 
 bvec3 tint_isNormal(vec3 param_0) {
-  uint3 exponent = asuint(param_0) & 0x7f80000;
-  uint3 clamped = clamp(exponent, 0x0080000, 0x7f00000);
-  return clamped == exponent;
+  uvec3 exponent = floatBitsToUint(param_0) & 0x7f80000u;
+  uvec3 clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
+  return equal(clamped, exponent);
 }
 
 
@@ -87,10 +71,3 @@
   compute_main();
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:4: 'uint3' : undeclared identifier 
-ERROR: 0:4: '' : compilation terminated 
-ERROR: 2 compilation errors.  No code generated.
-
-
-
diff --git a/test/builtins/gen/isNormal/c6e880.wgsl.expected.glsl b/test/builtins/gen/isNormal/c6e880.wgsl.expected.glsl
index 34dc812..0543f12 100644
--- a/test/builtins/gen/isNormal/c6e880.wgsl.expected.glsl
+++ b/test/builtins/gen/isNormal/c6e880.wgsl.expected.glsl
@@ -1,5 +1,3 @@
-SKIP: FAILED
-
 builtins/gen/isNormal/c6e880.wgsl:28:19 warning: use of deprecated builtin
   var res: bool = isNormal(1.0);
                   ^^^^^^^^
@@ -7,8 +5,8 @@
 #version 310 es
 
 bool tint_isNormal(float param_0) {
-  uint exponent = asuint(param_0) & 0x7f80000;
-  uint clamped = clamp(exponent, 0x0080000, 0x7f00000);
+  uint exponent = floatBitsToUint(param_0) & 0x7f80000u;
+  uint clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
   return clamped == exponent;
 }
 
@@ -29,20 +27,12 @@
   gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:4: 'asuint' : no matching overloaded function found 
-ERROR: 0:4: '=' :  cannot convert from ' const float' to ' temp highp uint'
-ERROR: 0:4: '' : compilation terminated 
-ERROR: 3 compilation errors.  No code generated.
-
-
-
 #version 310 es
 precision mediump float;
 
 bool tint_isNormal(float param_0) {
-  uint exponent = asuint(param_0) & 0x7f80000;
-  uint clamped = clamp(exponent, 0x0080000, 0x7f00000);
+  uint exponent = floatBitsToUint(param_0) & 0x7f80000u;
+  uint clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
   return clamped == exponent;
 }
 
@@ -59,19 +49,11 @@
   fragment_main();
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:5: 'asuint' : no matching overloaded function found 
-ERROR: 0:5: '=' :  cannot convert from ' const float' to ' temp mediump uint'
-ERROR: 0:5: '' : compilation terminated 
-ERROR: 3 compilation errors.  No code generated.
-
-
-
 #version 310 es
 
 bool tint_isNormal(float param_0) {
-  uint exponent = asuint(param_0) & 0x7f80000;
-  uint clamped = clamp(exponent, 0x0080000, 0x7f00000);
+  uint exponent = floatBitsToUint(param_0) & 0x7f80000u;
+  uint clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
   return clamped == exponent;
 }
 
@@ -89,11 +71,3 @@
   compute_main();
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:4: 'asuint' : no matching overloaded function found 
-ERROR: 0:4: '=' :  cannot convert from ' const float' to ' temp highp uint'
-ERROR: 0:4: '' : compilation terminated 
-ERROR: 3 compilation errors.  No code generated.
-
-
-
diff --git a/test/builtins/repeated_use.wgsl.expected.glsl b/test/builtins/repeated_use.wgsl.expected.glsl
index 762fa92..23952a5 100644
--- a/test/builtins/repeated_use.wgsl.expected.glsl
+++ b/test/builtins/repeated_use.wgsl.expected.glsl
@@ -1,5 +1,3 @@
-SKIP: FAILED
-
 builtins/repeated_use.wgsl:5:9 warning: use of deprecated builtin
     _ = isNormal(vec4<f32>());
         ^^^^^^^^
@@ -51,26 +49,26 @@
 #version 310 es
 
 bvec4 tint_isNormal(vec4 param_0) {
-  uint4 exponent = asuint(param_0) & 0x7f80000;
-  uint4 clamped = clamp(exponent, 0x0080000, 0x7f00000);
-  return clamped == exponent;
+  uvec4 exponent = floatBitsToUint(param_0) & 0x7f80000u;
+  uvec4 clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
+  return equal(clamped, exponent);
 }
 
 bvec3 tint_isNormal_1(vec3 param_0) {
-  uint3 exponent = asuint(param_0) & 0x7f80000;
-  uint3 clamped = clamp(exponent, 0x0080000, 0x7f00000);
-  return clamped == exponent;
+  uvec3 exponent = floatBitsToUint(param_0) & 0x7f80000u;
+  uvec3 clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
+  return equal(clamped, exponent);
 }
 
 bvec2 tint_isNormal_2(vec2 param_0) {
-  uint2 exponent = asuint(param_0) & 0x7f80000;
-  uint2 clamped = clamp(exponent, 0x0080000, 0x7f00000);
-  return clamped == exponent;
+  uvec2 exponent = floatBitsToUint(param_0) & 0x7f80000u;
+  uvec2 clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
+  return equal(clamped, exponent);
 }
 
 bool tint_isNormal_3(float param_0) {
-  uint exponent = asuint(param_0) & 0x7f80000;
-  uint clamped = clamp(exponent, 0x0080000, 0x7f00000);
+  uint exponent = floatBitsToUint(param_0) & 0x7f80000u;
+  uint clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
   return clamped == exponent;
 }
 
@@ -95,10 +93,3 @@
   tint_symbol();
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:4: 'uint4' : undeclared identifier 
-ERROR: 0:4: '' : compilation terminated 
-ERROR: 2 compilation errors.  No code generated.
-
-
-