writer/hlsl: Implement fma()

Change-Id: I30763381bcb0588379e0896f014fa9756b5f3395
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/54324
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc
index f159791..eded048 100644
--- a/src/writer/hlsl/generator_impl.cc
+++ b/src/writer/hlsl/generator_impl.cc
@@ -528,11 +528,9 @@
   if (auto* intrinsic = call->Target()->As<sem::Intrinsic>()) {
     if (intrinsic->IsTexture()) {
       return EmitTextureCall(pre, out, expr, intrinsic);
-    }
-    if (intrinsic->Type() == sem::IntrinsicType::kSelect) {
+    } else if (intrinsic->Type() == sem::IntrinsicType::kSelect) {
       return EmitSelectCall(pre, out, expr);
-    }
-    if (intrinsic->Type() == sem::IntrinsicType::kFrexp) {
+    } else if (intrinsic->Type() == sem::IntrinsicType::kFrexp) {
       return EmitFrexpCall(pre, out, expr, intrinsic);
     } else if (intrinsic->Type() == sem::IntrinsicType::kIsNormal) {
       return EmitIsNormalCall(pre, out, expr, intrinsic);
@@ -1177,7 +1175,6 @@
     case sem::IntrinsicType::kExp:
     case sem::IntrinsicType::kExp2:
     case sem::IntrinsicType::kFloor:
-    case sem::IntrinsicType::kFma:
     case sem::IntrinsicType::kFrexp:
     case sem::IntrinsicType::kLdexp:
     case sem::IntrinsicType::kLength:
@@ -1228,6 +1225,9 @@
     case sem::IntrinsicType::kFract:
       out = "frac";
       break;
+    case sem::IntrinsicType::kFma:
+      out = "mad";
+      break;
     case sem::IntrinsicType::kFwidth:
     case sem::IntrinsicType::kFwidthCoarse:
     case sem::IntrinsicType::kFwidthFine:
diff --git a/src/writer/hlsl/generator_impl_import_test.cc b/src/writer/hlsl/generator_impl_import_test.cc
index cec626f..201f345 100644
--- a/src/writer/hlsl/generator_impl_import_test.cc
+++ b/src/writer/hlsl/generator_impl_import_test.cc
@@ -201,7 +201,7 @@
     HlslGeneratorImplTest_Import,
     HlslImportData_TripleParamTest,
     testing::Values(HlslImportData{"faceForward", "faceforward"},
-                    HlslImportData{"fma", "fma"},
+                    HlslImportData{"fma", "mad"},
                     HlslImportData{"clamp", "clamp"},
                     HlslImportData{"smoothStep", "smoothstep"}));
 
diff --git a/src/writer/hlsl/generator_impl_intrinsic_test.cc b/src/writer/hlsl/generator_impl_intrinsic_test.cc
index ee4a206..0e5a619 100644
--- a/src/writer/hlsl/generator_impl_intrinsic_test.cc
+++ b/src/writer/hlsl/generator_impl_intrinsic_test.cc
@@ -217,7 +217,7 @@
         IntrinsicData{IntrinsicType::kFaceForward, ParamType::kF32,
                       "faceforward"},
         IntrinsicData{IntrinsicType::kFloor, ParamType::kF32, "floor"},
-        IntrinsicData{IntrinsicType::kFma, ParamType::kF32, "fma"},
+        IntrinsicData{IntrinsicType::kFma, ParamType::kF32, "mad"},
         IntrinsicData{IntrinsicType::kFract, ParamType::kF32, "frac"},
         IntrinsicData{IntrinsicType::kFwidth, ParamType::kF32, "fwidth"},
         IntrinsicData{IntrinsicType::kFwidthCoarse, ParamType::kF32, "fwidth"},
diff --git a/test/intrinsics/gen/fma/26a7a9.wgsl.expected.hlsl b/test/intrinsics/gen/fma/26a7a9.wgsl.expected.hlsl
index 6c1e754..c9733c7 100644
--- a/test/intrinsics/gen/fma/26a7a9.wgsl.expected.hlsl
+++ b/test/intrinsics/gen/fma/26a7a9.wgsl.expected.hlsl
@@ -1,10 +1,5 @@
-SKIP: FAILED
-
-
-
-Validation Failure:
 void fma_26a7a9() {
-  float2 res = fma(float2(0.0f, 0.0f), float2(0.0f, 0.0f), float2(0.0f, 0.0f));
+  float2 res = mad(float2(0.0f, 0.0f), float2(0.0f, 0.0f), float2(0.0f, 0.0f));
 }
 
 struct tint_symbol {
@@ -27,21 +22,3 @@
   fma_26a7a9();
   return;
 }
-
-tint_9GH744:2:16: error: no matching function for call to 'fma'
-  float2 res = fma(float2(0.0f, 0.0f), float2(0.0f, 0.0f), float2(0.0f, 0.0f));
-               ^~~
-note: candidate function not viable: no known conversion from 'vector<float, 2>' to 'vector<double, 2>' for 1st argument
-
-
-tint_9GH744:2:16: error: no matching function for call to 'fma'
-  float2 res = fma(float2(0.0f, 0.0f), float2(0.0f, 0.0f), float2(0.0f, 0.0f));
-               ^~~
-note: candidate function not viable: no known conversion from 'vector<float, 2>' to 'vector<double, 2>' for 1st argument
-
-
-tint_9GH744:2:16: error: no matching function for call to 'fma'
-  float2 res = fma(float2(0.0f, 0.0f), float2(0.0f, 0.0f), float2(0.0f, 0.0f));
-               ^~~
-note: candidate function not viable: no known conversion from 'vector<float, 2>' to 'vector<double, 2>' for 1st argument
-
diff --git a/test/intrinsics/gen/fma/6a3283.wgsl.expected.hlsl b/test/intrinsics/gen/fma/6a3283.wgsl.expected.hlsl
index 5e9e0c9..d6d98d3 100644
--- a/test/intrinsics/gen/fma/6a3283.wgsl.expected.hlsl
+++ b/test/intrinsics/gen/fma/6a3283.wgsl.expected.hlsl
@@ -1,10 +1,5 @@
-SKIP: FAILED
-
-
-
-Validation Failure:
 void fma_6a3283() {
-  float4 res = fma(float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f));
+  float4 res = mad(float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f));
 }
 
 struct tint_symbol {
@@ -27,21 +22,3 @@
   fma_6a3283();
   return;
 }
-
-tint_GZ5kFN:2:16: error: no matching function for call to 'fma'
-  float4 res = fma(float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f));
-               ^~~
-note: candidate function not viable: no known conversion from 'vector<float, 4>' to 'vector<double, 4>' for 1st argument
-
-
-tint_GZ5kFN:2:16: error: no matching function for call to 'fma'
-  float4 res = fma(float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f));
-               ^~~
-note: candidate function not viable: no known conversion from 'vector<float, 4>' to 'vector<double, 4>' for 1st argument
-
-
-tint_GZ5kFN:2:16: error: no matching function for call to 'fma'
-  float4 res = fma(float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f));
-               ^~~
-note: candidate function not viable: no known conversion from 'vector<float, 4>' to 'vector<double, 4>' for 1st argument
-
diff --git a/test/intrinsics/gen/fma/c10ba3.wgsl.expected.hlsl b/test/intrinsics/gen/fma/c10ba3.wgsl.expected.hlsl
index 3181c25..eead041 100644
--- a/test/intrinsics/gen/fma/c10ba3.wgsl.expected.hlsl
+++ b/test/intrinsics/gen/fma/c10ba3.wgsl.expected.hlsl
@@ -1,10 +1,5 @@
-SKIP: FAILED
-
-
-
-Validation Failure:
 void fma_c10ba3() {
-  float res = fma(1.0f, 1.0f, 1.0f);
+  float res = mad(1.0f, 1.0f, 1.0f);
 }
 
 struct tint_symbol {
@@ -27,21 +22,3 @@
   fma_c10ba3();
   return;
 }
-
-tint_tqaLcU:2:15: error: no matching function for call to 'fma'
-  float res = fma(1.0f, 1.0f, 1.0f);
-              ^~~
-note: candidate function not viable: no known conversion from 'float' to 'double' for 1st argument
-
-
-tint_tqaLcU:2:15: error: no matching function for call to 'fma'
-  float res = fma(1.0f, 1.0f, 1.0f);
-              ^~~
-note: candidate function not viable: no known conversion from 'float' to 'double' for 1st argument
-
-
-tint_tqaLcU:2:15: error: no matching function for call to 'fma'
-  float res = fma(1.0f, 1.0f, 1.0f);
-              ^~~
-note: candidate function not viable: no known conversion from 'float' to 'double' for 1st argument
-
diff --git a/test/intrinsics/gen/fma/e17c5c.wgsl.expected.hlsl b/test/intrinsics/gen/fma/e17c5c.wgsl.expected.hlsl
index aa67a89..958567b 100644
--- a/test/intrinsics/gen/fma/e17c5c.wgsl.expected.hlsl
+++ b/test/intrinsics/gen/fma/e17c5c.wgsl.expected.hlsl
@@ -1,10 +1,5 @@
-SKIP: FAILED
-
-
-
-Validation Failure:
 void fma_e17c5c() {
-  float3 res = fma(float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f));
+  float3 res = mad(float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f));
 }
 
 struct tint_symbol {
@@ -27,21 +22,3 @@
   fma_e17c5c();
   return;
 }
-
-tint_NJUQps:2:16: error: no matching function for call to 'fma'
-  float3 res = fma(float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f));
-               ^~~
-note: candidate function not viable: no known conversion from 'vector<float, 3>' to 'vector<double, 3>' for 1st argument
-
-
-tint_NJUQps:2:16: error: no matching function for call to 'fma'
-  float3 res = fma(float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f));
-               ^~~
-note: candidate function not viable: no known conversion from 'vector<float, 3>' to 'vector<double, 3>' for 1st argument
-
-
-tint_NJUQps:2:16: error: no matching function for call to 'fma'
-  float3 res = fma(float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f));
-               ^~~
-note: candidate function not viable: no known conversion from 'vector<float, 3>' to 'vector<double, 3>' for 1st argument
-