1fd4e5da5Sopenharmony_ci// Copyright (c) 2017 Google Inc.
2fd4e5da5Sopenharmony_ci//
3fd4e5da5Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License");
4fd4e5da5Sopenharmony_ci// you may not use this file except in compliance with the License.
5fd4e5da5Sopenharmony_ci// You may obtain a copy of the License at
6fd4e5da5Sopenharmony_ci//
7fd4e5da5Sopenharmony_ci//     http://www.apache.org/licenses/LICENSE-2.0
8fd4e5da5Sopenharmony_ci//
9fd4e5da5Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software
10fd4e5da5Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS,
11fd4e5da5Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fd4e5da5Sopenharmony_ci// See the License for the specific language governing permissions and
13fd4e5da5Sopenharmony_ci// limitations under the License.
14fd4e5da5Sopenharmony_ci
15fd4e5da5Sopenharmony_ci// Tests for unique type declaration rules validator.
16fd4e5da5Sopenharmony_ci
17fd4e5da5Sopenharmony_ci#include <string>
18fd4e5da5Sopenharmony_ci
19fd4e5da5Sopenharmony_ci#include "gmock/gmock.h"
20fd4e5da5Sopenharmony_ci#include "test/unit_spirv.h"
21fd4e5da5Sopenharmony_ci#include "test/val/val_fixtures.h"
22fd4e5da5Sopenharmony_ci
23fd4e5da5Sopenharmony_cinamespace spvtools {
24fd4e5da5Sopenharmony_cinamespace val {
25fd4e5da5Sopenharmony_cinamespace {
26fd4e5da5Sopenharmony_ci
27fd4e5da5Sopenharmony_ciusing ::testing::HasSubstr;
28fd4e5da5Sopenharmony_ciusing ::testing::Not;
29fd4e5da5Sopenharmony_ci
30fd4e5da5Sopenharmony_ciusing ValidateArithmetics = spvtest::ValidateBase<bool>;
31fd4e5da5Sopenharmony_ci
32fd4e5da5Sopenharmony_cistd::string GenerateCode(const std::string& main_body) {
33fd4e5da5Sopenharmony_ci  const std::string prefix =
34fd4e5da5Sopenharmony_ci      R"(
35fd4e5da5Sopenharmony_ciOpCapability Shader
36fd4e5da5Sopenharmony_ciOpCapability Int64
37fd4e5da5Sopenharmony_ciOpCapability Float64
38fd4e5da5Sopenharmony_ciOpCapability Matrix
39fd4e5da5Sopenharmony_ci%ext_inst = OpExtInstImport "GLSL.std.450"
40fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
41fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main"
42fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
43fd4e5da5Sopenharmony_ci%void = OpTypeVoid
44fd4e5da5Sopenharmony_ci%func = OpTypeFunction %void
45fd4e5da5Sopenharmony_ci%bool = OpTypeBool
46fd4e5da5Sopenharmony_ci%f32 = OpTypeFloat 32
47fd4e5da5Sopenharmony_ci%u32 = OpTypeInt 32 0
48fd4e5da5Sopenharmony_ci%s32 = OpTypeInt 32 1
49fd4e5da5Sopenharmony_ci%f64 = OpTypeFloat 64
50fd4e5da5Sopenharmony_ci%u64 = OpTypeInt 64 0
51fd4e5da5Sopenharmony_ci%s64 = OpTypeInt 64 1
52fd4e5da5Sopenharmony_ci%boolvec2 = OpTypeVector %bool 2
53fd4e5da5Sopenharmony_ci%s32vec2 = OpTypeVector %s32 2
54fd4e5da5Sopenharmony_ci%u32vec2 = OpTypeVector %u32 2
55fd4e5da5Sopenharmony_ci%u64vec2 = OpTypeVector %u64 2
56fd4e5da5Sopenharmony_ci%f32vec2 = OpTypeVector %f32 2
57fd4e5da5Sopenharmony_ci%f64vec2 = OpTypeVector %f64 2
58fd4e5da5Sopenharmony_ci%boolvec3 = OpTypeVector %bool 3
59fd4e5da5Sopenharmony_ci%u32vec3 = OpTypeVector %u32 3
60fd4e5da5Sopenharmony_ci%u64vec3 = OpTypeVector %u64 3
61fd4e5da5Sopenharmony_ci%s32vec3 = OpTypeVector %s32 3
62fd4e5da5Sopenharmony_ci%f32vec3 = OpTypeVector %f32 3
63fd4e5da5Sopenharmony_ci%f64vec3 = OpTypeVector %f64 3
64fd4e5da5Sopenharmony_ci%boolvec4 = OpTypeVector %bool 4
65fd4e5da5Sopenharmony_ci%u32vec4 = OpTypeVector %u32 4
66fd4e5da5Sopenharmony_ci%u64vec4 = OpTypeVector %u64 4
67fd4e5da5Sopenharmony_ci%s32vec4 = OpTypeVector %s32 4
68fd4e5da5Sopenharmony_ci%f32vec4 = OpTypeVector %f32 4
69fd4e5da5Sopenharmony_ci%f64vec4 = OpTypeVector %f64 4
70fd4e5da5Sopenharmony_ci
71fd4e5da5Sopenharmony_ci%f32mat22 = OpTypeMatrix %f32vec2 2
72fd4e5da5Sopenharmony_ci%f32mat23 = OpTypeMatrix %f32vec2 3
73fd4e5da5Sopenharmony_ci%f32mat32 = OpTypeMatrix %f32vec3 2
74fd4e5da5Sopenharmony_ci%f32mat33 = OpTypeMatrix %f32vec3 3
75fd4e5da5Sopenharmony_ci%f64mat22 = OpTypeMatrix %f64vec2 2
76fd4e5da5Sopenharmony_ci
77fd4e5da5Sopenharmony_ci%struct_f32_f32 = OpTypeStruct %f32 %f32
78fd4e5da5Sopenharmony_ci%struct_u32_u32 = OpTypeStruct %u32 %u32
79fd4e5da5Sopenharmony_ci%struct_u32_u32_u32 = OpTypeStruct %u32 %u32 %u32
80fd4e5da5Sopenharmony_ci%struct_s32_s32 = OpTypeStruct %s32 %s32
81fd4e5da5Sopenharmony_ci%struct_s32_u32 = OpTypeStruct %s32 %u32
82fd4e5da5Sopenharmony_ci%struct_u32vec2_u32vec2 = OpTypeStruct %u32vec2 %u32vec2
83fd4e5da5Sopenharmony_ci%struct_s32vec2_s32vec2 = OpTypeStruct %s32vec2 %s32vec2
84fd4e5da5Sopenharmony_ci
85fd4e5da5Sopenharmony_ci%f32_0 = OpConstant %f32 0
86fd4e5da5Sopenharmony_ci%f32_1 = OpConstant %f32 1
87fd4e5da5Sopenharmony_ci%f32_2 = OpConstant %f32 2
88fd4e5da5Sopenharmony_ci%f32_3 = OpConstant %f32 3
89fd4e5da5Sopenharmony_ci%f32_4 = OpConstant %f32 4
90fd4e5da5Sopenharmony_ci%f32_pi = OpConstant %f32 3.14159
91fd4e5da5Sopenharmony_ci
92fd4e5da5Sopenharmony_ci%s32_0 = OpConstant %s32 0
93fd4e5da5Sopenharmony_ci%s32_1 = OpConstant %s32 1
94fd4e5da5Sopenharmony_ci%s32_2 = OpConstant %s32 2
95fd4e5da5Sopenharmony_ci%s32_3 = OpConstant %s32 3
96fd4e5da5Sopenharmony_ci%s32_4 = OpConstant %s32 4
97fd4e5da5Sopenharmony_ci%s32_m1 = OpConstant %s32 -1
98fd4e5da5Sopenharmony_ci
99fd4e5da5Sopenharmony_ci%u32_0 = OpConstant %u32 0
100fd4e5da5Sopenharmony_ci%u32_1 = OpConstant %u32 1
101fd4e5da5Sopenharmony_ci%u32_2 = OpConstant %u32 2
102fd4e5da5Sopenharmony_ci%u32_3 = OpConstant %u32 3
103fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
104fd4e5da5Sopenharmony_ci
105fd4e5da5Sopenharmony_ci%f64_0 = OpConstant %f64 0
106fd4e5da5Sopenharmony_ci%f64_1 = OpConstant %f64 1
107fd4e5da5Sopenharmony_ci%f64_2 = OpConstant %f64 2
108fd4e5da5Sopenharmony_ci%f64_3 = OpConstant %f64 3
109fd4e5da5Sopenharmony_ci%f64_4 = OpConstant %f64 4
110fd4e5da5Sopenharmony_ci
111fd4e5da5Sopenharmony_ci%s64_0 = OpConstant %s64 0
112fd4e5da5Sopenharmony_ci%s64_1 = OpConstant %s64 1
113fd4e5da5Sopenharmony_ci%s64_2 = OpConstant %s64 2
114fd4e5da5Sopenharmony_ci%s64_3 = OpConstant %s64 3
115fd4e5da5Sopenharmony_ci%s64_4 = OpConstant %s64 4
116fd4e5da5Sopenharmony_ci%s64_m1 = OpConstant %s64 -1
117fd4e5da5Sopenharmony_ci
118fd4e5da5Sopenharmony_ci%u64_0 = OpConstant %u64 0
119fd4e5da5Sopenharmony_ci%u64_1 = OpConstant %u64 1
120fd4e5da5Sopenharmony_ci%u64_2 = OpConstant %u64 2
121fd4e5da5Sopenharmony_ci%u64_3 = OpConstant %u64 3
122fd4e5da5Sopenharmony_ci%u64_4 = OpConstant %u64 4
123fd4e5da5Sopenharmony_ci
124fd4e5da5Sopenharmony_ci%u32vec2_01 = OpConstantComposite %u32vec2 %u32_0 %u32_1
125fd4e5da5Sopenharmony_ci%u32vec2_12 = OpConstantComposite %u32vec2 %u32_1 %u32_2
126fd4e5da5Sopenharmony_ci%u32vec3_012 = OpConstantComposite %u32vec3 %u32_0 %u32_1 %u32_2
127fd4e5da5Sopenharmony_ci%u32vec3_123 = OpConstantComposite %u32vec3 %u32_1 %u32_2 %u32_3
128fd4e5da5Sopenharmony_ci%u32vec4_0123 = OpConstantComposite %u32vec4 %u32_0 %u32_1 %u32_2 %u32_3
129fd4e5da5Sopenharmony_ci%u32vec4_1234 = OpConstantComposite %u32vec4 %u32_1 %u32_2 %u32_3 %u32_4
130fd4e5da5Sopenharmony_ci
131fd4e5da5Sopenharmony_ci%s32vec2_01 = OpConstantComposite %s32vec2 %s32_0 %s32_1
132fd4e5da5Sopenharmony_ci%s32vec2_12 = OpConstantComposite %s32vec2 %s32_1 %s32_2
133fd4e5da5Sopenharmony_ci%s32vec3_012 = OpConstantComposite %s32vec3 %s32_0 %s32_1 %s32_2
134fd4e5da5Sopenharmony_ci%s32vec3_123 = OpConstantComposite %s32vec3 %s32_1 %s32_2 %s32_3
135fd4e5da5Sopenharmony_ci%s32vec4_0123 = OpConstantComposite %s32vec4 %s32_0 %s32_1 %s32_2 %s32_3
136fd4e5da5Sopenharmony_ci%s32vec4_1234 = OpConstantComposite %s32vec4 %s32_1 %s32_2 %s32_3 %s32_4
137fd4e5da5Sopenharmony_ci
138fd4e5da5Sopenharmony_ci%f32vec2_01 = OpConstantComposite %f32vec2 %f32_0 %f32_1
139fd4e5da5Sopenharmony_ci%f32vec2_12 = OpConstantComposite %f32vec2 %f32_1 %f32_2
140fd4e5da5Sopenharmony_ci%f32vec3_012 = OpConstantComposite %f32vec3 %f32_0 %f32_1 %f32_2
141fd4e5da5Sopenharmony_ci%f32vec3_123 = OpConstantComposite %f32vec3 %f32_1 %f32_2 %f32_3
142fd4e5da5Sopenharmony_ci%f32vec4_0123 = OpConstantComposite %f32vec4 %f32_0 %f32_1 %f32_2 %f32_3
143fd4e5da5Sopenharmony_ci%f32vec4_1234 = OpConstantComposite %f32vec4 %f32_1 %f32_2 %f32_3 %f32_4
144fd4e5da5Sopenharmony_ci
145fd4e5da5Sopenharmony_ci%f64vec2_01 = OpConstantComposite %f64vec2 %f64_0 %f64_1
146fd4e5da5Sopenharmony_ci%f64vec2_12 = OpConstantComposite %f64vec2 %f64_1 %f64_2
147fd4e5da5Sopenharmony_ci%f64vec3_012 = OpConstantComposite %f64vec3 %f64_0 %f64_1 %f64_2
148fd4e5da5Sopenharmony_ci%f64vec3_123 = OpConstantComposite %f64vec3 %f64_1 %f64_2 %f64_3
149fd4e5da5Sopenharmony_ci%f64vec4_0123 = OpConstantComposite %f64vec4 %f64_0 %f64_1 %f64_2 %f64_3
150fd4e5da5Sopenharmony_ci%f64vec4_1234 = OpConstantComposite %f64vec4 %f64_1 %f64_2 %f64_3 %f64_4
151fd4e5da5Sopenharmony_ci
152fd4e5da5Sopenharmony_ci%f32mat22_1212 = OpConstantComposite %f32mat22 %f32vec2_12 %f32vec2_12
153fd4e5da5Sopenharmony_ci%f32mat23_121212 = OpConstantComposite %f32mat23 %f32vec2_12 %f32vec2_12 %f32vec2_12
154fd4e5da5Sopenharmony_ci%f32mat32_123123 = OpConstantComposite %f32mat32 %f32vec3_123 %f32vec3_123
155fd4e5da5Sopenharmony_ci%f32mat33_123123123 = OpConstantComposite %f32mat33 %f32vec3_123 %f32vec3_123 %f32vec3_123
156fd4e5da5Sopenharmony_ci
157fd4e5da5Sopenharmony_ci%f64mat22_1212 = OpConstantComposite %f64mat22 %f64vec2_12 %f64vec2_12
158fd4e5da5Sopenharmony_ci
159fd4e5da5Sopenharmony_ci%main = OpFunction %void None %func
160fd4e5da5Sopenharmony_ci%main_entry = OpLabel)";
161fd4e5da5Sopenharmony_ci
162fd4e5da5Sopenharmony_ci  const std::string suffix =
163fd4e5da5Sopenharmony_ci      R"(
164fd4e5da5Sopenharmony_ciOpReturn
165fd4e5da5Sopenharmony_ciOpFunctionEnd)";
166fd4e5da5Sopenharmony_ci
167fd4e5da5Sopenharmony_ci  return prefix + main_body + suffix;
168fd4e5da5Sopenharmony_ci}
169fd4e5da5Sopenharmony_ci
170fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, F32Success) {
171fd4e5da5Sopenharmony_ci  const std::string body = R"(
172fd4e5da5Sopenharmony_ci%val1 = OpFMul %f32 %f32_0 %f32_1
173fd4e5da5Sopenharmony_ci%val2 = OpFSub %f32 %f32_2 %f32_0
174fd4e5da5Sopenharmony_ci%val3 = OpFAdd %f32 %val1 %val2
175fd4e5da5Sopenharmony_ci%val4 = OpFNegate %f32 %val3
176fd4e5da5Sopenharmony_ci%val5 = OpFDiv %f32 %val4 %val1
177fd4e5da5Sopenharmony_ci%val6 = OpFRem %f32 %val4 %f32_2
178fd4e5da5Sopenharmony_ci%val7 = OpFMod %f32 %val4 %f32_2
179fd4e5da5Sopenharmony_ci)";
180fd4e5da5Sopenharmony_ci
181fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
182fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
183fd4e5da5Sopenharmony_ci}
184fd4e5da5Sopenharmony_ci
185fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, F64Success) {
186fd4e5da5Sopenharmony_ci  const std::string body = R"(
187fd4e5da5Sopenharmony_ci%val1 = OpFMul %f64 %f64_0 %f64_1
188fd4e5da5Sopenharmony_ci%val2 = OpFSub %f64 %f64_2 %f64_0
189fd4e5da5Sopenharmony_ci%val3 = OpFAdd %f64 %val1 %val2
190fd4e5da5Sopenharmony_ci%val4 = OpFNegate %f64 %val3
191fd4e5da5Sopenharmony_ci%val5 = OpFDiv %f64 %val4 %val1
192fd4e5da5Sopenharmony_ci%val6 = OpFRem %f64 %val4 %f64_2
193fd4e5da5Sopenharmony_ci%val7 = OpFMod %f64 %val4 %f64_2
194fd4e5da5Sopenharmony_ci)";
195fd4e5da5Sopenharmony_ci
196fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
197fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
198fd4e5da5Sopenharmony_ci}
199fd4e5da5Sopenharmony_ci
200fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, Int32Success) {
201fd4e5da5Sopenharmony_ci  const std::string body = R"(
202fd4e5da5Sopenharmony_ci%val1 = OpIMul %u32 %s32_0 %u32_1
203fd4e5da5Sopenharmony_ci%val2 = OpIMul %s32 %s32_2 %u32_1
204fd4e5da5Sopenharmony_ci%val3 = OpIAdd %u32 %val1 %val2
205fd4e5da5Sopenharmony_ci%val4 = OpIAdd %s32 %val1 %val2
206fd4e5da5Sopenharmony_ci%val5 = OpISub %u32 %val3 %val4
207fd4e5da5Sopenharmony_ci%val6 = OpISub %s32 %val4 %val3
208fd4e5da5Sopenharmony_ci%val7 = OpSDiv %s32 %val4 %val3
209fd4e5da5Sopenharmony_ci%val8 = OpSNegate %s32 %val7
210fd4e5da5Sopenharmony_ci%val9 = OpSRem %s32 %val4 %val3
211fd4e5da5Sopenharmony_ci%val10 = OpSMod %s32 %val4 %val3
212fd4e5da5Sopenharmony_ci)";
213fd4e5da5Sopenharmony_ci
214fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
215fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
216fd4e5da5Sopenharmony_ci}
217fd4e5da5Sopenharmony_ci
218fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, Int64Success) {
219fd4e5da5Sopenharmony_ci  const std::string body = R"(
220fd4e5da5Sopenharmony_ci%val1 = OpIMul %u64 %s64_0 %u64_1
221fd4e5da5Sopenharmony_ci%val2 = OpIMul %s64 %s64_2 %u64_1
222fd4e5da5Sopenharmony_ci%val3 = OpIAdd %u64 %val1 %val2
223fd4e5da5Sopenharmony_ci%val4 = OpIAdd %s64 %val1 %val2
224fd4e5da5Sopenharmony_ci%val5 = OpISub %u64 %val3 %val4
225fd4e5da5Sopenharmony_ci%val6 = OpISub %s64 %val4 %val3
226fd4e5da5Sopenharmony_ci%val7 = OpSDiv %s64 %val4 %val3
227fd4e5da5Sopenharmony_ci%val8 = OpSNegate %s64 %val7
228fd4e5da5Sopenharmony_ci%val9 = OpSRem %s64 %val4 %val3
229fd4e5da5Sopenharmony_ci%val10 = OpSMod %s64 %val4 %val3
230fd4e5da5Sopenharmony_ci)";
231fd4e5da5Sopenharmony_ci
232fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
233fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
234fd4e5da5Sopenharmony_ci}
235fd4e5da5Sopenharmony_ci
236fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, F32Vec2Success) {
237fd4e5da5Sopenharmony_ci  const std::string body = R"(
238fd4e5da5Sopenharmony_ci%val1 = OpFMul %f32vec2 %f32vec2_01 %f32vec2_12
239fd4e5da5Sopenharmony_ci%val2 = OpFSub %f32vec2 %f32vec2_12 %f32vec2_01
240fd4e5da5Sopenharmony_ci%val3 = OpFAdd %f32vec2 %val1 %val2
241fd4e5da5Sopenharmony_ci%val4 = OpFNegate %f32vec2 %val3
242fd4e5da5Sopenharmony_ci%val5 = OpFDiv %f32vec2 %val4 %val1
243fd4e5da5Sopenharmony_ci%val6 = OpFRem %f32vec2 %val4 %f32vec2_12
244fd4e5da5Sopenharmony_ci%val7 = OpFMod %f32vec2 %val4 %f32vec2_12
245fd4e5da5Sopenharmony_ci)";
246fd4e5da5Sopenharmony_ci
247fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
248fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
249fd4e5da5Sopenharmony_ci}
250fd4e5da5Sopenharmony_ci
251fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, F64Vec2Success) {
252fd4e5da5Sopenharmony_ci  const std::string body = R"(
253fd4e5da5Sopenharmony_ci%val1 = OpFMul %f64vec2 %f64vec2_01 %f64vec2_12
254fd4e5da5Sopenharmony_ci%val2 = OpFSub %f64vec2 %f64vec2_12 %f64vec2_01
255fd4e5da5Sopenharmony_ci%val3 = OpFAdd %f64vec2 %val1 %val2
256fd4e5da5Sopenharmony_ci%val4 = OpFNegate %f64vec2 %val3
257fd4e5da5Sopenharmony_ci%val5 = OpFDiv %f64vec2 %val4 %val1
258fd4e5da5Sopenharmony_ci%val6 = OpFRem %f64vec2 %val4 %f64vec2_12
259fd4e5da5Sopenharmony_ci%val7 = OpFMod %f64vec2 %val4 %f64vec2_12
260fd4e5da5Sopenharmony_ci)";
261fd4e5da5Sopenharmony_ci
262fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
263fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
264fd4e5da5Sopenharmony_ci}
265fd4e5da5Sopenharmony_ci
266fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, U32Vec2Success) {
267fd4e5da5Sopenharmony_ci  const std::string body = R"(
268fd4e5da5Sopenharmony_ci%val1 = OpIMul %u32vec2 %u32vec2_01 %u32vec2_12
269fd4e5da5Sopenharmony_ci%val2 = OpISub %u32vec2 %u32vec2_12 %u32vec2_01
270fd4e5da5Sopenharmony_ci%val3 = OpIAdd %u32vec2 %val1 %val2
271fd4e5da5Sopenharmony_ci%val4 = OpSNegate %u32vec2 %val3
272fd4e5da5Sopenharmony_ci%val5 = OpSDiv %u32vec2 %val4 %val1
273fd4e5da5Sopenharmony_ci%val6 = OpSRem %u32vec2 %val4 %u32vec2_12
274fd4e5da5Sopenharmony_ci%val7 = OpSMod %u32vec2 %val4 %u32vec2_12
275fd4e5da5Sopenharmony_ci)";
276fd4e5da5Sopenharmony_ci
277fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
278fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
279fd4e5da5Sopenharmony_ci}
280fd4e5da5Sopenharmony_ci
281fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, FNegateTypeIdU32) {
282fd4e5da5Sopenharmony_ci  const std::string body = R"(
283fd4e5da5Sopenharmony_ci%val = OpFNegate %u32 %u32_0
284fd4e5da5Sopenharmony_ci)";
285fd4e5da5Sopenharmony_ci
286fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
287fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
288fd4e5da5Sopenharmony_ci  EXPECT_THAT(
289fd4e5da5Sopenharmony_ci      getDiagnosticString(),
290fd4e5da5Sopenharmony_ci      HasSubstr(
291fd4e5da5Sopenharmony_ci          "Expected floating scalar or vector type as Result Type: FNegate"));
292fd4e5da5Sopenharmony_ci}
293fd4e5da5Sopenharmony_ci
294fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, FNegateTypeIdVec2U32) {
295fd4e5da5Sopenharmony_ci  const std::string body = R"(
296fd4e5da5Sopenharmony_ci%val = OpFNegate %u32vec2 %u32vec2_01
297fd4e5da5Sopenharmony_ci)";
298fd4e5da5Sopenharmony_ci
299fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
300fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
301fd4e5da5Sopenharmony_ci  EXPECT_THAT(
302fd4e5da5Sopenharmony_ci      getDiagnosticString(),
303fd4e5da5Sopenharmony_ci      HasSubstr(
304fd4e5da5Sopenharmony_ci          "Expected floating scalar or vector type as Result Type: FNegate"));
305fd4e5da5Sopenharmony_ci}
306fd4e5da5Sopenharmony_ci
307fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, FNegateWrongOperand) {
308fd4e5da5Sopenharmony_ci  const std::string body = R"(
309fd4e5da5Sopenharmony_ci%val = OpFNegate %f32 %u32_0
310fd4e5da5Sopenharmony_ci)";
311fd4e5da5Sopenharmony_ci
312fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
313fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
314fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
315fd4e5da5Sopenharmony_ci              HasSubstr("Expected arithmetic operands to be of Result Type: "
316fd4e5da5Sopenharmony_ci                        "FNegate operand index 2"));
317fd4e5da5Sopenharmony_ci}
318fd4e5da5Sopenharmony_ci
319fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, FMulTypeIdU32) {
320fd4e5da5Sopenharmony_ci  const std::string body = R"(
321fd4e5da5Sopenharmony_ci%val = OpFMul %u32 %u32_0 %u32_1
322fd4e5da5Sopenharmony_ci)";
323fd4e5da5Sopenharmony_ci
324fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
325fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
326fd4e5da5Sopenharmony_ci  EXPECT_THAT(
327fd4e5da5Sopenharmony_ci      getDiagnosticString(),
328fd4e5da5Sopenharmony_ci      HasSubstr(
329fd4e5da5Sopenharmony_ci          "Expected floating scalar or vector type as Result Type: FMul"));
330fd4e5da5Sopenharmony_ci}
331fd4e5da5Sopenharmony_ci
332fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, FMulTypeIdVec2U32) {
333fd4e5da5Sopenharmony_ci  const std::string body = R"(
334fd4e5da5Sopenharmony_ci%val = OpFMul %u32vec2 %u32vec2_01 %u32vec2_12
335fd4e5da5Sopenharmony_ci)";
336fd4e5da5Sopenharmony_ci
337fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
338fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
339fd4e5da5Sopenharmony_ci  EXPECT_THAT(
340fd4e5da5Sopenharmony_ci      getDiagnosticString(),
341fd4e5da5Sopenharmony_ci      HasSubstr(
342fd4e5da5Sopenharmony_ci          "Expected floating scalar or vector type as Result Type: FMul"));
343fd4e5da5Sopenharmony_ci}
344fd4e5da5Sopenharmony_ci
345fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, FMulWrongOperand1) {
346fd4e5da5Sopenharmony_ci  const std::string body = R"(
347fd4e5da5Sopenharmony_ci%val = OpFMul %f32 %u32_0 %f32_1
348fd4e5da5Sopenharmony_ci)";
349fd4e5da5Sopenharmony_ci
350fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
351fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
352fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
353fd4e5da5Sopenharmony_ci              HasSubstr("Expected arithmetic operands to be of Result Type: "
354fd4e5da5Sopenharmony_ci                        "FMul operand index 2"));
355fd4e5da5Sopenharmony_ci}
356fd4e5da5Sopenharmony_ci
357fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, FMulWrongOperand2) {
358fd4e5da5Sopenharmony_ci  const std::string body = R"(
359fd4e5da5Sopenharmony_ci%val = OpFMul %f32 %f32_0 %u32_1
360fd4e5da5Sopenharmony_ci)";
361fd4e5da5Sopenharmony_ci
362fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
363fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
364fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
365fd4e5da5Sopenharmony_ci              HasSubstr("Expected arithmetic operands to be of Result Type: "
366fd4e5da5Sopenharmony_ci                        "FMul operand index 3"));
367fd4e5da5Sopenharmony_ci}
368fd4e5da5Sopenharmony_ci
369fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, FMulWrongVectorOperand1) {
370fd4e5da5Sopenharmony_ci  const std::string body = R"(
371fd4e5da5Sopenharmony_ci%val = OpFMul %f64vec3 %f32vec3_123 %f64vec3_012
372fd4e5da5Sopenharmony_ci)";
373fd4e5da5Sopenharmony_ci
374fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
375fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
376fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
377fd4e5da5Sopenharmony_ci              HasSubstr("Expected arithmetic operands to be of Result Type: "
378fd4e5da5Sopenharmony_ci                        "FMul operand index 2"));
379fd4e5da5Sopenharmony_ci}
380fd4e5da5Sopenharmony_ci
381fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, FMulWrongVectorOperand2) {
382fd4e5da5Sopenharmony_ci  const std::string body = R"(
383fd4e5da5Sopenharmony_ci%val = OpFMul %f32vec3 %f32vec3_123 %f64vec3_012
384fd4e5da5Sopenharmony_ci)";
385fd4e5da5Sopenharmony_ci
386fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
387fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
388fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
389fd4e5da5Sopenharmony_ci              HasSubstr("Expected arithmetic operands to be of Result Type: "
390fd4e5da5Sopenharmony_ci                        "FMul operand index 3"));
391fd4e5da5Sopenharmony_ci}
392fd4e5da5Sopenharmony_ci
393fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, IMulFloatTypeId) {
394fd4e5da5Sopenharmony_ci  const std::string body = R"(
395fd4e5da5Sopenharmony_ci%val = OpIMul %f32 %u32_0 %s32_1
396fd4e5da5Sopenharmony_ci)";
397fd4e5da5Sopenharmony_ci
398fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
399fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
400fd4e5da5Sopenharmony_ci  EXPECT_THAT(
401fd4e5da5Sopenharmony_ci      getDiagnosticString(),
402fd4e5da5Sopenharmony_ci      HasSubstr("Expected int scalar or vector type as Result Type: IMul"));
403fd4e5da5Sopenharmony_ci}
404fd4e5da5Sopenharmony_ci
405fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, IMulFloatOperand1) {
406fd4e5da5Sopenharmony_ci  const std::string body = R"(
407fd4e5da5Sopenharmony_ci%val = OpIMul %u32 %f32_0 %s32_1
408fd4e5da5Sopenharmony_ci)";
409fd4e5da5Sopenharmony_ci
410fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
411fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
412fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
413fd4e5da5Sopenharmony_ci              HasSubstr("Expected int scalar or vector type as operand: "
414fd4e5da5Sopenharmony_ci                        "IMul operand index 2"));
415fd4e5da5Sopenharmony_ci}
416fd4e5da5Sopenharmony_ci
417fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, IMulFloatOperand2) {
418fd4e5da5Sopenharmony_ci  const std::string body = R"(
419fd4e5da5Sopenharmony_ci%val = OpIMul %u32 %s32_0 %f32_1
420fd4e5da5Sopenharmony_ci)";
421fd4e5da5Sopenharmony_ci
422fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
423fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
424fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
425fd4e5da5Sopenharmony_ci              HasSubstr("Expected int scalar or vector type as operand: "
426fd4e5da5Sopenharmony_ci                        "IMul operand index 3"));
427fd4e5da5Sopenharmony_ci}
428fd4e5da5Sopenharmony_ci
429fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, IMulWrongBitWidthOperand1) {
430fd4e5da5Sopenharmony_ci  const std::string body = R"(
431fd4e5da5Sopenharmony_ci%val = OpIMul %u64 %u32_0 %s64_1
432fd4e5da5Sopenharmony_ci)";
433fd4e5da5Sopenharmony_ci
434fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
435fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
436fd4e5da5Sopenharmony_ci  EXPECT_THAT(
437fd4e5da5Sopenharmony_ci      getDiagnosticString(),
438fd4e5da5Sopenharmony_ci      HasSubstr("Expected arithmetic operands to have the same bit width "
439fd4e5da5Sopenharmony_ci                "as Result Type: IMul operand index 2"));
440fd4e5da5Sopenharmony_ci}
441fd4e5da5Sopenharmony_ci
442fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, IMulWrongBitWidthOperand2) {
443fd4e5da5Sopenharmony_ci  const std::string body = R"(
444fd4e5da5Sopenharmony_ci%val = OpIMul %u32 %u32_0 %s64_1
445fd4e5da5Sopenharmony_ci)";
446fd4e5da5Sopenharmony_ci
447fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
448fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
449fd4e5da5Sopenharmony_ci  EXPECT_THAT(
450fd4e5da5Sopenharmony_ci      getDiagnosticString(),
451fd4e5da5Sopenharmony_ci      HasSubstr("Expected arithmetic operands to have the same bit width "
452fd4e5da5Sopenharmony_ci                "as Result Type: IMul operand index 3"));
453fd4e5da5Sopenharmony_ci}
454fd4e5da5Sopenharmony_ci
455fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, IMulWrongBitWidthVector) {
456fd4e5da5Sopenharmony_ci  const std::string body = R"(
457fd4e5da5Sopenharmony_ci%val = OpIMul %u64vec3 %u32vec3_012 %u32vec3_123
458fd4e5da5Sopenharmony_ci)";
459fd4e5da5Sopenharmony_ci
460fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
461fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
462fd4e5da5Sopenharmony_ci  EXPECT_THAT(
463fd4e5da5Sopenharmony_ci      getDiagnosticString(),
464fd4e5da5Sopenharmony_ci      HasSubstr("Expected arithmetic operands to have the same bit width "
465fd4e5da5Sopenharmony_ci                "as Result Type: IMul operand index 2"));
466fd4e5da5Sopenharmony_ci}
467fd4e5da5Sopenharmony_ci
468fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, IMulVectorScalarOperand1) {
469fd4e5da5Sopenharmony_ci  const std::string body = R"(
470fd4e5da5Sopenharmony_ci%val = OpIMul %u32vec2 %u32_0 %u32vec2_01
471fd4e5da5Sopenharmony_ci)";
472fd4e5da5Sopenharmony_ci
473fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
474fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
475fd4e5da5Sopenharmony_ci  EXPECT_THAT(
476fd4e5da5Sopenharmony_ci      getDiagnosticString(),
477fd4e5da5Sopenharmony_ci      HasSubstr("Expected arithmetic operands to have the same dimension "
478fd4e5da5Sopenharmony_ci                "as Result Type: IMul operand index 2"));
479fd4e5da5Sopenharmony_ci}
480fd4e5da5Sopenharmony_ci
481fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, IMulVectorScalarOperand2) {
482fd4e5da5Sopenharmony_ci  const std::string body = R"(
483fd4e5da5Sopenharmony_ci%val = OpIMul %u32vec2 %u32vec2_01 %u32_0
484fd4e5da5Sopenharmony_ci)";
485fd4e5da5Sopenharmony_ci
486fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
487fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
488fd4e5da5Sopenharmony_ci  EXPECT_THAT(
489fd4e5da5Sopenharmony_ci      getDiagnosticString(),
490fd4e5da5Sopenharmony_ci      HasSubstr("Expected arithmetic operands to have the same dimension "
491fd4e5da5Sopenharmony_ci                "as Result Type: IMul operand index 3"));
492fd4e5da5Sopenharmony_ci}
493fd4e5da5Sopenharmony_ci
494fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, IMulScalarVectorOperand1) {
495fd4e5da5Sopenharmony_ci  const std::string body = R"(
496fd4e5da5Sopenharmony_ci%val = OpIMul %s32 %u32vec2_01 %u32_0
497fd4e5da5Sopenharmony_ci)";
498fd4e5da5Sopenharmony_ci
499fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
500fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
501fd4e5da5Sopenharmony_ci  EXPECT_THAT(
502fd4e5da5Sopenharmony_ci      getDiagnosticString(),
503fd4e5da5Sopenharmony_ci      HasSubstr("Expected arithmetic operands to have the same dimension "
504fd4e5da5Sopenharmony_ci                "as Result Type: IMul operand index 2"));
505fd4e5da5Sopenharmony_ci}
506fd4e5da5Sopenharmony_ci
507fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, IMulScalarVectorOperand2) {
508fd4e5da5Sopenharmony_ci  const std::string body = R"(
509fd4e5da5Sopenharmony_ci%val = OpIMul %u32 %u32_0 %s32vec2_01
510fd4e5da5Sopenharmony_ci)";
511fd4e5da5Sopenharmony_ci
512fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
513fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
514fd4e5da5Sopenharmony_ci  EXPECT_THAT(
515fd4e5da5Sopenharmony_ci      getDiagnosticString(),
516fd4e5da5Sopenharmony_ci      HasSubstr("Expected arithmetic operands to have the same dimension "
517fd4e5da5Sopenharmony_ci                "as Result Type: IMul operand index 3"));
518fd4e5da5Sopenharmony_ci}
519fd4e5da5Sopenharmony_ci
520fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, SNegateFloat) {
521fd4e5da5Sopenharmony_ci  const std::string body = R"(
522fd4e5da5Sopenharmony_ci%val = OpSNegate %s32 %f32_1
523fd4e5da5Sopenharmony_ci)";
524fd4e5da5Sopenharmony_ci
525fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
526fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
527fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
528fd4e5da5Sopenharmony_ci              HasSubstr("Expected int scalar or vector type as operand: "
529fd4e5da5Sopenharmony_ci                        "SNegate operand index 2"));
530fd4e5da5Sopenharmony_ci}
531fd4e5da5Sopenharmony_ci
532fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, UDivFloatType) {
533fd4e5da5Sopenharmony_ci  const std::string body = R"(
534fd4e5da5Sopenharmony_ci%val = OpUDiv %f32 %u32_2 %u32_1
535fd4e5da5Sopenharmony_ci)";
536fd4e5da5Sopenharmony_ci
537fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
538fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
539fd4e5da5Sopenharmony_ci  EXPECT_THAT(
540fd4e5da5Sopenharmony_ci      getDiagnosticString(),
541fd4e5da5Sopenharmony_ci      HasSubstr(
542fd4e5da5Sopenharmony_ci          "Expected unsigned int scalar or vector type as Result Type: UDiv"));
543fd4e5da5Sopenharmony_ci}
544fd4e5da5Sopenharmony_ci
545fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, UDivSignedIntType) {
546fd4e5da5Sopenharmony_ci  const std::string body = R"(
547fd4e5da5Sopenharmony_ci%val = OpUDiv %s32 %u32_2 %u32_1
548fd4e5da5Sopenharmony_ci)";
549fd4e5da5Sopenharmony_ci
550fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
551fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
552fd4e5da5Sopenharmony_ci  EXPECT_THAT(
553fd4e5da5Sopenharmony_ci      getDiagnosticString(),
554fd4e5da5Sopenharmony_ci      HasSubstr(
555fd4e5da5Sopenharmony_ci          "Expected unsigned int scalar or vector type as Result Type: UDiv"));
556fd4e5da5Sopenharmony_ci}
557fd4e5da5Sopenharmony_ci
558fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, UDivWrongOperand1) {
559fd4e5da5Sopenharmony_ci  const std::string body = R"(
560fd4e5da5Sopenharmony_ci%val = OpUDiv %u64 %f64_2 %u64_1
561fd4e5da5Sopenharmony_ci)";
562fd4e5da5Sopenharmony_ci
563fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
564fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
565fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
566fd4e5da5Sopenharmony_ci              HasSubstr("Expected arithmetic operands to be of Result Type: "
567fd4e5da5Sopenharmony_ci                        "UDiv operand index 2"));
568fd4e5da5Sopenharmony_ci}
569fd4e5da5Sopenharmony_ci
570fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, UDivWrongOperand2) {
571fd4e5da5Sopenharmony_ci  const std::string body = R"(
572fd4e5da5Sopenharmony_ci%val = OpUDiv %u64 %u64_2 %u32_1
573fd4e5da5Sopenharmony_ci)";
574fd4e5da5Sopenharmony_ci
575fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
576fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
577fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
578fd4e5da5Sopenharmony_ci              HasSubstr("Expected arithmetic operands to be of Result Type: "
579fd4e5da5Sopenharmony_ci                        "UDiv operand index 3"));
580fd4e5da5Sopenharmony_ci}
581fd4e5da5Sopenharmony_ci
582fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, DotSuccess) {
583fd4e5da5Sopenharmony_ci  const std::string body = R"(
584fd4e5da5Sopenharmony_ci%val = OpDot %f32 %f32vec2_01 %f32vec2_12
585fd4e5da5Sopenharmony_ci)";
586fd4e5da5Sopenharmony_ci
587fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
588fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
589fd4e5da5Sopenharmony_ci}
590fd4e5da5Sopenharmony_ci
591fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, DotWrongTypeId) {
592fd4e5da5Sopenharmony_ci  const std::string body = R"(
593fd4e5da5Sopenharmony_ci%val = OpDot %u32 %u32vec2_01 %u32vec2_12
594fd4e5da5Sopenharmony_ci)";
595fd4e5da5Sopenharmony_ci
596fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
597fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
598fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
599fd4e5da5Sopenharmony_ci              HasSubstr("Expected float scalar type as Result Type: Dot"));
600fd4e5da5Sopenharmony_ci}
601fd4e5da5Sopenharmony_ci
602fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, DotNotVectorTypeOperand1) {
603fd4e5da5Sopenharmony_ci  const std::string body = R"(
604fd4e5da5Sopenharmony_ci%val = OpDot %f32 %f32 %f32vec2_12
605fd4e5da5Sopenharmony_ci)";
606fd4e5da5Sopenharmony_ci
607fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
608fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
609fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
610fd4e5da5Sopenharmony_ci              HasSubstr("Operand '6[%float]' cannot be a "
611fd4e5da5Sopenharmony_ci                        "type"));
612fd4e5da5Sopenharmony_ci}
613fd4e5da5Sopenharmony_ci
614fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, DotNotVectorTypeOperand2) {
615fd4e5da5Sopenharmony_ci  const std::string body = R"(
616fd4e5da5Sopenharmony_ci%val = OpDot %f32 %f32vec3_012 %f32_1
617fd4e5da5Sopenharmony_ci)";
618fd4e5da5Sopenharmony_ci
619fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
620fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
621fd4e5da5Sopenharmony_ci  EXPECT_THAT(
622fd4e5da5Sopenharmony_ci      getDiagnosticString(),
623fd4e5da5Sopenharmony_ci      HasSubstr("Expected float vector as operand: Dot operand index 3"));
624fd4e5da5Sopenharmony_ci}
625fd4e5da5Sopenharmony_ci
626fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, DotWrongComponentOperand1) {
627fd4e5da5Sopenharmony_ci  const std::string body = R"(
628fd4e5da5Sopenharmony_ci%val = OpDot %f64 %f32vec2_01 %f64vec2_12
629fd4e5da5Sopenharmony_ci)";
630fd4e5da5Sopenharmony_ci
631fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
632fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
633fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
634fd4e5da5Sopenharmony_ci              HasSubstr("Expected component type to be equal to Result Type: "
635fd4e5da5Sopenharmony_ci                        "Dot operand index 2"));
636fd4e5da5Sopenharmony_ci}
637fd4e5da5Sopenharmony_ci
638fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, DotWrongComponentOperand2) {
639fd4e5da5Sopenharmony_ci  const std::string body = R"(
640fd4e5da5Sopenharmony_ci%val = OpDot %f32 %f32vec2_01 %f64vec2_12
641fd4e5da5Sopenharmony_ci)";
642fd4e5da5Sopenharmony_ci
643fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
644fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
645fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
646fd4e5da5Sopenharmony_ci              HasSubstr("Expected component type to be equal to Result Type: "
647fd4e5da5Sopenharmony_ci                        "Dot operand index 3"));
648fd4e5da5Sopenharmony_ci}
649fd4e5da5Sopenharmony_ci
650fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, DotDifferentVectorSize) {
651fd4e5da5Sopenharmony_ci  const std::string body = R"(
652fd4e5da5Sopenharmony_ci%val = OpDot %f32 %f32vec2_01 %f32vec3_123
653fd4e5da5Sopenharmony_ci)";
654fd4e5da5Sopenharmony_ci
655fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
656fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
657fd4e5da5Sopenharmony_ci  EXPECT_THAT(
658fd4e5da5Sopenharmony_ci      getDiagnosticString(),
659fd4e5da5Sopenharmony_ci      HasSubstr(
660fd4e5da5Sopenharmony_ci          "Expected operands to have the same number of components: Dot"));
661fd4e5da5Sopenharmony_ci}
662fd4e5da5Sopenharmony_ci
663fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, VectorTimesScalarSuccess) {
664fd4e5da5Sopenharmony_ci  const std::string body = R"(
665fd4e5da5Sopenharmony_ci%val = OpVectorTimesScalar %f32vec2 %f32vec2_01 %f32_2
666fd4e5da5Sopenharmony_ci)";
667fd4e5da5Sopenharmony_ci
668fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
669fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
670fd4e5da5Sopenharmony_ci}
671fd4e5da5Sopenharmony_ci
672fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, VectorTimesScalarWrongTypeId) {
673fd4e5da5Sopenharmony_ci  const std::string body = R"(
674fd4e5da5Sopenharmony_ci%val = OpVectorTimesScalar %u32vec2 %f32vec2_01 %f32_2
675fd4e5da5Sopenharmony_ci)";
676fd4e5da5Sopenharmony_ci
677fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
678fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
679fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
680fd4e5da5Sopenharmony_ci              HasSubstr("Expected float vector type as Result Type: "
681fd4e5da5Sopenharmony_ci                        "VectorTimesScalar"));
682fd4e5da5Sopenharmony_ci}
683fd4e5da5Sopenharmony_ci
684fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, VectorTimesScalarWrongVector) {
685fd4e5da5Sopenharmony_ci  const std::string body = R"(
686fd4e5da5Sopenharmony_ci%val = OpVectorTimesScalar %f32vec2 %f32vec3_012 %f32_2
687fd4e5da5Sopenharmony_ci)";
688fd4e5da5Sopenharmony_ci
689fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
690fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
691fd4e5da5Sopenharmony_ci  EXPECT_THAT(
692fd4e5da5Sopenharmony_ci      getDiagnosticString(),
693fd4e5da5Sopenharmony_ci      HasSubstr("Expected vector operand type to be equal to Result Type: "
694fd4e5da5Sopenharmony_ci                "VectorTimesScalar"));
695fd4e5da5Sopenharmony_ci}
696fd4e5da5Sopenharmony_ci
697fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, VectorTimesScalarWrongScalar) {
698fd4e5da5Sopenharmony_ci  const std::string body = R"(
699fd4e5da5Sopenharmony_ci%val = OpVectorTimesScalar %f32vec2 %f32vec2_01 %f64_2
700fd4e5da5Sopenharmony_ci)";
701fd4e5da5Sopenharmony_ci
702fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
703fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
704fd4e5da5Sopenharmony_ci  EXPECT_THAT(
705fd4e5da5Sopenharmony_ci      getDiagnosticString(),
706fd4e5da5Sopenharmony_ci      HasSubstr("Expected scalar operand type to be equal to the component "
707fd4e5da5Sopenharmony_ci                "type of the vector operand: VectorTimesScalar"));
708fd4e5da5Sopenharmony_ci}
709fd4e5da5Sopenharmony_ci
710fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesScalarSuccess) {
711fd4e5da5Sopenharmony_ci  const std::string body = R"(
712fd4e5da5Sopenharmony_ci%val = OpMatrixTimesScalar %f32mat22 %f32mat22_1212 %f32_2
713fd4e5da5Sopenharmony_ci)";
714fd4e5da5Sopenharmony_ci
715fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
716fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
717fd4e5da5Sopenharmony_ci}
718fd4e5da5Sopenharmony_ci
719fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesScalarWrongTypeId) {
720fd4e5da5Sopenharmony_ci  const std::string body = R"(
721fd4e5da5Sopenharmony_ci%val = OpMatrixTimesScalar %f32vec2 %f32mat22_1212 %f32_2
722fd4e5da5Sopenharmony_ci)";
723fd4e5da5Sopenharmony_ci
724fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
725fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
726fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
727fd4e5da5Sopenharmony_ci              HasSubstr("Expected float matrix type as Result Type: "
728fd4e5da5Sopenharmony_ci                        "MatrixTimesScalar"));
729fd4e5da5Sopenharmony_ci}
730fd4e5da5Sopenharmony_ci
731fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesScalarWrongMatrix) {
732fd4e5da5Sopenharmony_ci  const std::string body = R"(
733fd4e5da5Sopenharmony_ci%val = OpMatrixTimesScalar %f32mat22 %f32vec2_01 %f32_2
734fd4e5da5Sopenharmony_ci)";
735fd4e5da5Sopenharmony_ci
736fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
737fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
738fd4e5da5Sopenharmony_ci  EXPECT_THAT(
739fd4e5da5Sopenharmony_ci      getDiagnosticString(),
740fd4e5da5Sopenharmony_ci      HasSubstr("Expected matrix operand type to be equal to Result Type: "
741fd4e5da5Sopenharmony_ci                "MatrixTimesScalar"));
742fd4e5da5Sopenharmony_ci}
743fd4e5da5Sopenharmony_ci
744fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesScalarWrongScalar) {
745fd4e5da5Sopenharmony_ci  const std::string body = R"(
746fd4e5da5Sopenharmony_ci%val = OpMatrixTimesScalar %f32mat22 %f32mat22_1212 %f64_2
747fd4e5da5Sopenharmony_ci)";
748fd4e5da5Sopenharmony_ci
749fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
750fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
751fd4e5da5Sopenharmony_ci  EXPECT_THAT(
752fd4e5da5Sopenharmony_ci      getDiagnosticString(),
753fd4e5da5Sopenharmony_ci      HasSubstr("Expected scalar operand type to be equal to the component "
754fd4e5da5Sopenharmony_ci                "type of the matrix operand: MatrixTimesScalar"));
755fd4e5da5Sopenharmony_ci}
756fd4e5da5Sopenharmony_ci
757fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, VectorTimesMatrix2x22Success) {
758fd4e5da5Sopenharmony_ci  const std::string body = R"(
759fd4e5da5Sopenharmony_ci%val = OpVectorTimesMatrix %f32vec2 %f32vec2_12 %f32mat22_1212
760fd4e5da5Sopenharmony_ci)";
761fd4e5da5Sopenharmony_ci
762fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
763fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
764fd4e5da5Sopenharmony_ci}
765fd4e5da5Sopenharmony_ci
766fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, VectorTimesMatrix3x32Success) {
767fd4e5da5Sopenharmony_ci  const std::string body = R"(
768fd4e5da5Sopenharmony_ci%val = OpVectorTimesMatrix %f32vec2 %f32vec3_123 %f32mat32_123123
769fd4e5da5Sopenharmony_ci)";
770fd4e5da5Sopenharmony_ci
771fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
772fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
773fd4e5da5Sopenharmony_ci}
774fd4e5da5Sopenharmony_ci
775fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, VectorTimesMatrixWrongTypeId) {
776fd4e5da5Sopenharmony_ci  const std::string body = R"(
777fd4e5da5Sopenharmony_ci%val = OpVectorTimesMatrix %f32mat22 %f32vec2_12 %f32mat22_1212
778fd4e5da5Sopenharmony_ci)";
779fd4e5da5Sopenharmony_ci
780fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
781fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
782fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
783fd4e5da5Sopenharmony_ci              HasSubstr("Expected float vector type as Result Type: "
784fd4e5da5Sopenharmony_ci                        "VectorTimesMatrix"));
785fd4e5da5Sopenharmony_ci}
786fd4e5da5Sopenharmony_ci
787fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, VectorTimesMatrixNotFloatVector) {
788fd4e5da5Sopenharmony_ci  const std::string body = R"(
789fd4e5da5Sopenharmony_ci%val = OpVectorTimesMatrix %f32vec2 %u32vec2_12 %f32mat22_1212
790fd4e5da5Sopenharmony_ci)";
791fd4e5da5Sopenharmony_ci
792fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
793fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
794fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
795fd4e5da5Sopenharmony_ci              HasSubstr("Expected float vector type as left operand: "
796fd4e5da5Sopenharmony_ci                        "VectorTimesMatrix"));
797fd4e5da5Sopenharmony_ci}
798fd4e5da5Sopenharmony_ci
799fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, VectorTimesMatrixWrongVectorComponent) {
800fd4e5da5Sopenharmony_ci  const std::string body = R"(
801fd4e5da5Sopenharmony_ci%val = OpVectorTimesMatrix %f32vec2 %f64vec2_12 %f32mat22_1212
802fd4e5da5Sopenharmony_ci)";
803fd4e5da5Sopenharmony_ci
804fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
805fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
806fd4e5da5Sopenharmony_ci  EXPECT_THAT(
807fd4e5da5Sopenharmony_ci      getDiagnosticString(),
808fd4e5da5Sopenharmony_ci      HasSubstr(
809fd4e5da5Sopenharmony_ci          "Expected component types of Result Type and vector to be equal: "
810fd4e5da5Sopenharmony_ci          "VectorTimesMatrix"));
811fd4e5da5Sopenharmony_ci}
812fd4e5da5Sopenharmony_ci
813fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, VectorTimesMatrixWrongMatrix) {
814fd4e5da5Sopenharmony_ci  const std::string body = R"(
815fd4e5da5Sopenharmony_ci%val = OpVectorTimesMatrix %f32vec2 %f32vec2_12 %f32vec2_12
816fd4e5da5Sopenharmony_ci)";
817fd4e5da5Sopenharmony_ci
818fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
819fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
820fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
821fd4e5da5Sopenharmony_ci              HasSubstr("Expected float matrix type as right operand: "
822fd4e5da5Sopenharmony_ci                        "VectorTimesMatrix"));
823fd4e5da5Sopenharmony_ci}
824fd4e5da5Sopenharmony_ci
825fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, VectorTimesMatrixWrongMatrixComponent) {
826fd4e5da5Sopenharmony_ci  const std::string body = R"(
827fd4e5da5Sopenharmony_ci%val = OpVectorTimesMatrix %f32vec2 %f32vec2_12 %f64mat22_1212
828fd4e5da5Sopenharmony_ci)";
829fd4e5da5Sopenharmony_ci
830fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
831fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
832fd4e5da5Sopenharmony_ci  EXPECT_THAT(
833fd4e5da5Sopenharmony_ci      getDiagnosticString(),
834fd4e5da5Sopenharmony_ci      HasSubstr(
835fd4e5da5Sopenharmony_ci          "Expected component types of Result Type and matrix to be equal: "
836fd4e5da5Sopenharmony_ci          "VectorTimesMatrix"));
837fd4e5da5Sopenharmony_ci}
838fd4e5da5Sopenharmony_ci
839fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, VectorTimesMatrix2eq2x23Fail) {
840fd4e5da5Sopenharmony_ci  const std::string body = R"(
841fd4e5da5Sopenharmony_ci%val = OpVectorTimesMatrix %f32vec2 %f32vec2_12 %f32mat23_121212
842fd4e5da5Sopenharmony_ci)";
843fd4e5da5Sopenharmony_ci
844fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
845fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
846fd4e5da5Sopenharmony_ci  EXPECT_THAT(
847fd4e5da5Sopenharmony_ci      getDiagnosticString(),
848fd4e5da5Sopenharmony_ci      HasSubstr(
849fd4e5da5Sopenharmony_ci          "Expected number of columns of the matrix to be equal to Result Type "
850fd4e5da5Sopenharmony_ci          "vector size: VectorTimesMatrix"));
851fd4e5da5Sopenharmony_ci}
852fd4e5da5Sopenharmony_ci
853fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, VectorTimesMatrix2x32Fail) {
854fd4e5da5Sopenharmony_ci  const std::string body = R"(
855fd4e5da5Sopenharmony_ci%val = OpVectorTimesMatrix %f32vec2 %f32vec2_12 %f32mat32_123123
856fd4e5da5Sopenharmony_ci)";
857fd4e5da5Sopenharmony_ci
858fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
859fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
860fd4e5da5Sopenharmony_ci  EXPECT_THAT(
861fd4e5da5Sopenharmony_ci      getDiagnosticString(),
862fd4e5da5Sopenharmony_ci      HasSubstr(
863fd4e5da5Sopenharmony_ci          "Expected number of rows of the matrix to be equal to the vector "
864fd4e5da5Sopenharmony_ci          "operand size: VectorTimesMatrix"));
865fd4e5da5Sopenharmony_ci}
866fd4e5da5Sopenharmony_ci
867fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesVector22x2Success) {
868fd4e5da5Sopenharmony_ci  const std::string body = R"(
869fd4e5da5Sopenharmony_ci%val = OpMatrixTimesVector %f32vec2 %f32mat22_1212 %f32vec2_12
870fd4e5da5Sopenharmony_ci)";
871fd4e5da5Sopenharmony_ci
872fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
873fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
874fd4e5da5Sopenharmony_ci}
875fd4e5da5Sopenharmony_ci
876fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesVector23x3Success) {
877fd4e5da5Sopenharmony_ci  const std::string body = R"(
878fd4e5da5Sopenharmony_ci%val = OpMatrixTimesVector %f32vec2 %f32mat23_121212 %f32vec3_123
879fd4e5da5Sopenharmony_ci)";
880fd4e5da5Sopenharmony_ci
881fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
882fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
883fd4e5da5Sopenharmony_ci}
884fd4e5da5Sopenharmony_ci
885fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesVectorWrongTypeId) {
886fd4e5da5Sopenharmony_ci  const std::string body = R"(
887fd4e5da5Sopenharmony_ci%val = OpMatrixTimesVector %f32mat22 %f32mat22_1212 %f32vec2_12
888fd4e5da5Sopenharmony_ci)";
889fd4e5da5Sopenharmony_ci
890fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
891fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
892fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
893fd4e5da5Sopenharmony_ci              HasSubstr("Expected float vector type as Result Type: "
894fd4e5da5Sopenharmony_ci                        "MatrixTimesVector"));
895fd4e5da5Sopenharmony_ci}
896fd4e5da5Sopenharmony_ci
897fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesVectorWrongMatrix) {
898fd4e5da5Sopenharmony_ci  const std::string body = R"(
899fd4e5da5Sopenharmony_ci%val = OpMatrixTimesVector %f32vec3 %f32vec3_123 %f32vec3_123
900fd4e5da5Sopenharmony_ci)";
901fd4e5da5Sopenharmony_ci
902fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
903fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
904fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
905fd4e5da5Sopenharmony_ci              HasSubstr("Expected float matrix type as left operand: "
906fd4e5da5Sopenharmony_ci                        "MatrixTimesVector"));
907fd4e5da5Sopenharmony_ci}
908fd4e5da5Sopenharmony_ci
909fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesVectorWrongMatrixCol) {
910fd4e5da5Sopenharmony_ci  const std::string body = R"(
911fd4e5da5Sopenharmony_ci%val = OpMatrixTimesVector %f32vec3 %f32mat23_121212 %f32vec3_123
912fd4e5da5Sopenharmony_ci)";
913fd4e5da5Sopenharmony_ci
914fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
915fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
916fd4e5da5Sopenharmony_ci  EXPECT_THAT(
917fd4e5da5Sopenharmony_ci      getDiagnosticString(),
918fd4e5da5Sopenharmony_ci      HasSubstr(
919fd4e5da5Sopenharmony_ci          "Expected column type of the matrix to be equal to Result Type: "
920fd4e5da5Sopenharmony_ci          "MatrixTimesVector"));
921fd4e5da5Sopenharmony_ci}
922fd4e5da5Sopenharmony_ci
923fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesVectorWrongVector) {
924fd4e5da5Sopenharmony_ci  const std::string body = R"(
925fd4e5da5Sopenharmony_ci%val = OpMatrixTimesVector %f32vec2 %f32mat22_1212 %u32vec2_12
926fd4e5da5Sopenharmony_ci)";
927fd4e5da5Sopenharmony_ci
928fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
929fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
930fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
931fd4e5da5Sopenharmony_ci              HasSubstr("Expected float vector type as right operand: "
932fd4e5da5Sopenharmony_ci                        "MatrixTimesVector"));
933fd4e5da5Sopenharmony_ci}
934fd4e5da5Sopenharmony_ci
935fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesVectorDifferentComponents) {
936fd4e5da5Sopenharmony_ci  const std::string body = R"(
937fd4e5da5Sopenharmony_ci%val = OpMatrixTimesVector %f32vec2 %f32mat22_1212 %f64vec2_12
938fd4e5da5Sopenharmony_ci)";
939fd4e5da5Sopenharmony_ci
940fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
941fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
942fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
943fd4e5da5Sopenharmony_ci              HasSubstr("Expected component types of the operands to be equal: "
944fd4e5da5Sopenharmony_ci                        "MatrixTimesVector"));
945fd4e5da5Sopenharmony_ci}
946fd4e5da5Sopenharmony_ci
947fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesVector22x3Fail) {
948fd4e5da5Sopenharmony_ci  const std::string body = R"(
949fd4e5da5Sopenharmony_ci%val = OpMatrixTimesVector %f32vec2 %f32mat22_1212 %f32vec3_123
950fd4e5da5Sopenharmony_ci)";
951fd4e5da5Sopenharmony_ci
952fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
953fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
954fd4e5da5Sopenharmony_ci  EXPECT_THAT(
955fd4e5da5Sopenharmony_ci      getDiagnosticString(),
956fd4e5da5Sopenharmony_ci      HasSubstr(
957fd4e5da5Sopenharmony_ci          "Expected number of columns of the matrix to be equal to the vector "
958fd4e5da5Sopenharmony_ci          "size: MatrixTimesVector"));
959fd4e5da5Sopenharmony_ci}
960fd4e5da5Sopenharmony_ci
961fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesMatrix22x22Success) {
962fd4e5da5Sopenharmony_ci  const std::string body = R"(
963fd4e5da5Sopenharmony_ci%val = OpMatrixTimesMatrix %f32mat22 %f32mat22_1212 %f32mat22_1212
964fd4e5da5Sopenharmony_ci)";
965fd4e5da5Sopenharmony_ci
966fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
967fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
968fd4e5da5Sopenharmony_ci}
969fd4e5da5Sopenharmony_ci
970fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesMatrix23x32Success) {
971fd4e5da5Sopenharmony_ci  const std::string body = R"(
972fd4e5da5Sopenharmony_ci%val = OpMatrixTimesMatrix %f32mat22 %f32mat23_121212 %f32mat32_123123
973fd4e5da5Sopenharmony_ci)";
974fd4e5da5Sopenharmony_ci
975fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
976fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
977fd4e5da5Sopenharmony_ci}
978fd4e5da5Sopenharmony_ci
979fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesMatrix33x33Success) {
980fd4e5da5Sopenharmony_ci  const std::string body = R"(
981fd4e5da5Sopenharmony_ci%val = OpMatrixTimesMatrix %f32mat33 %f32mat33_123123123 %f32mat33_123123123
982fd4e5da5Sopenharmony_ci)";
983fd4e5da5Sopenharmony_ci
984fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
985fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
986fd4e5da5Sopenharmony_ci}
987fd4e5da5Sopenharmony_ci
988fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesMatrixWrongTypeId) {
989fd4e5da5Sopenharmony_ci  const std::string body = R"(
990fd4e5da5Sopenharmony_ci%val = OpMatrixTimesMatrix %f32vec2 %f32mat22_1212 %f32mat22_1212
991fd4e5da5Sopenharmony_ci)";
992fd4e5da5Sopenharmony_ci
993fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
994fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
995fd4e5da5Sopenharmony_ci  EXPECT_THAT(
996fd4e5da5Sopenharmony_ci      getDiagnosticString(),
997fd4e5da5Sopenharmony_ci      HasSubstr(
998fd4e5da5Sopenharmony_ci          "Expected float matrix type as Result Type: MatrixTimesMatrix"));
999fd4e5da5Sopenharmony_ci}
1000fd4e5da5Sopenharmony_ci
1001fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesMatrixWrongLeftOperand) {
1002fd4e5da5Sopenharmony_ci  const std::string body = R"(
1003fd4e5da5Sopenharmony_ci%val = OpMatrixTimesMatrix %f32mat22 %f32vec2_12 %f32mat22_1212
1004fd4e5da5Sopenharmony_ci)";
1005fd4e5da5Sopenharmony_ci
1006fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1007fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1008fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1009fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1010fd4e5da5Sopenharmony_ci      HasSubstr(
1011fd4e5da5Sopenharmony_ci          "Expected float matrix type as left operand: MatrixTimesMatrix"));
1012fd4e5da5Sopenharmony_ci}
1013fd4e5da5Sopenharmony_ci
1014fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesMatrixWrongRightOperand) {
1015fd4e5da5Sopenharmony_ci  const std::string body = R"(
1016fd4e5da5Sopenharmony_ci%val = OpMatrixTimesMatrix %f32mat22 %f32mat22_1212 %f32vec2_12
1017fd4e5da5Sopenharmony_ci)";
1018fd4e5da5Sopenharmony_ci
1019fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1020fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1021fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1022fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1023fd4e5da5Sopenharmony_ci      HasSubstr(
1024fd4e5da5Sopenharmony_ci          "Expected float matrix type as right operand: MatrixTimesMatrix"));
1025fd4e5da5Sopenharmony_ci}
1026fd4e5da5Sopenharmony_ci
1027fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesMatrix32x23Fail) {
1028fd4e5da5Sopenharmony_ci  const std::string body = R"(
1029fd4e5da5Sopenharmony_ci%val = OpMatrixTimesMatrix %f32mat22 %f32mat32_123123 %f32mat23_121212
1030fd4e5da5Sopenharmony_ci)";
1031fd4e5da5Sopenharmony_ci
1032fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1033fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1034fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1035fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1036fd4e5da5Sopenharmony_ci      HasSubstr(
1037fd4e5da5Sopenharmony_ci          "Expected column types of Result Type and left matrix to be equal: "
1038fd4e5da5Sopenharmony_ci          "MatrixTimesMatrix"));
1039fd4e5da5Sopenharmony_ci}
1040fd4e5da5Sopenharmony_ci
1041fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesMatrixDifferentComponents) {
1042fd4e5da5Sopenharmony_ci  const std::string body = R"(
1043fd4e5da5Sopenharmony_ci%val = OpMatrixTimesMatrix %f32mat22 %f32mat22_1212 %f64mat22_1212
1044fd4e5da5Sopenharmony_ci)";
1045fd4e5da5Sopenharmony_ci
1046fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1047fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1048fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1049fd4e5da5Sopenharmony_ci              HasSubstr("Expected component types of Result Type and right "
1050fd4e5da5Sopenharmony_ci                        "matrix to be equal: "
1051fd4e5da5Sopenharmony_ci                        "MatrixTimesMatrix"));
1052fd4e5da5Sopenharmony_ci}
1053fd4e5da5Sopenharmony_ci
1054fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesMatrix23x23Fail) {
1055fd4e5da5Sopenharmony_ci  const std::string body = R"(
1056fd4e5da5Sopenharmony_ci%val = OpMatrixTimesMatrix %f32mat22 %f32mat23_121212 %f32mat23_121212
1057fd4e5da5Sopenharmony_ci)";
1058fd4e5da5Sopenharmony_ci
1059fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1060fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1061fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1062fd4e5da5Sopenharmony_ci              HasSubstr("Expected number of columns of Result Type and right "
1063fd4e5da5Sopenharmony_ci                        "matrix to be equal: "
1064fd4e5da5Sopenharmony_ci                        "MatrixTimesMatrix"));
1065fd4e5da5Sopenharmony_ci}
1066fd4e5da5Sopenharmony_ci
1067fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, MatrixTimesMatrix23x22Fail) {
1068fd4e5da5Sopenharmony_ci  const std::string body = R"(
1069fd4e5da5Sopenharmony_ci%val = OpMatrixTimesMatrix %f32mat22 %f32mat23_121212 %f32mat22_1212
1070fd4e5da5Sopenharmony_ci)";
1071fd4e5da5Sopenharmony_ci
1072fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1073fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1074fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1075fd4e5da5Sopenharmony_ci              HasSubstr("Expected number of columns of left matrix and number "
1076fd4e5da5Sopenharmony_ci                        "of rows of right "
1077fd4e5da5Sopenharmony_ci                        "matrix to be equal: MatrixTimesMatrix"));
1078fd4e5da5Sopenharmony_ci}
1079fd4e5da5Sopenharmony_ci
1080fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, OuterProduct2x2Success) {
1081fd4e5da5Sopenharmony_ci  const std::string body = R"(
1082fd4e5da5Sopenharmony_ci%val = OpOuterProduct %f32mat22 %f32vec2_12 %f32vec2_01
1083fd4e5da5Sopenharmony_ci)";
1084fd4e5da5Sopenharmony_ci
1085fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1086fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1087fd4e5da5Sopenharmony_ci}
1088fd4e5da5Sopenharmony_ci
1089fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, OuterProduct3x2Success) {
1090fd4e5da5Sopenharmony_ci  const std::string body = R"(
1091fd4e5da5Sopenharmony_ci%val = OpOuterProduct %f32mat32 %f32vec3_123 %f32vec2_01
1092fd4e5da5Sopenharmony_ci)";
1093fd4e5da5Sopenharmony_ci
1094fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1095fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1096fd4e5da5Sopenharmony_ci}
1097fd4e5da5Sopenharmony_ci
1098fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, OuterProduct2x3Success) {
1099fd4e5da5Sopenharmony_ci  const std::string body = R"(
1100fd4e5da5Sopenharmony_ci%val = OpOuterProduct %f32mat23 %f32vec2_01 %f32vec3_123
1101fd4e5da5Sopenharmony_ci)";
1102fd4e5da5Sopenharmony_ci
1103fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1104fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1105fd4e5da5Sopenharmony_ci}
1106fd4e5da5Sopenharmony_ci
1107fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, OuterProductWrongTypeId) {
1108fd4e5da5Sopenharmony_ci  const std::string body = R"(
1109fd4e5da5Sopenharmony_ci%val = OpOuterProduct %f32vec2 %f32vec2_01 %f32vec3_123
1110fd4e5da5Sopenharmony_ci)";
1111fd4e5da5Sopenharmony_ci
1112fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1113fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1114fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1115fd4e5da5Sopenharmony_ci              HasSubstr("Expected float matrix type as Result Type: "
1116fd4e5da5Sopenharmony_ci                        "OuterProduct"));
1117fd4e5da5Sopenharmony_ci}
1118fd4e5da5Sopenharmony_ci
1119fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, OuterProductWrongLeftOperand) {
1120fd4e5da5Sopenharmony_ci  const std::string body = R"(
1121fd4e5da5Sopenharmony_ci%val = OpOuterProduct %f32mat22 %f32vec3_123 %f32vec2_01
1122fd4e5da5Sopenharmony_ci)";
1123fd4e5da5Sopenharmony_ci
1124fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1125fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1126fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1127fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1128fd4e5da5Sopenharmony_ci      HasSubstr("Expected column type of Result Type to be equal to the type "
1129fd4e5da5Sopenharmony_ci                "of the left operand: OuterProduct"));
1130fd4e5da5Sopenharmony_ci}
1131fd4e5da5Sopenharmony_ci
1132fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, OuterProductRightOperandNotFloatVector) {
1133fd4e5da5Sopenharmony_ci  const std::string body = R"(
1134fd4e5da5Sopenharmony_ci%val = OpOuterProduct %f32mat22 %f32vec2_12 %u32vec2_01
1135fd4e5da5Sopenharmony_ci)";
1136fd4e5da5Sopenharmony_ci
1137fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1138fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1139fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1140fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1141fd4e5da5Sopenharmony_ci      HasSubstr("Expected float vector type as right operand: OuterProduct"));
1142fd4e5da5Sopenharmony_ci}
1143fd4e5da5Sopenharmony_ci
1144fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, OuterProductRightOperandWrongComponent) {
1145fd4e5da5Sopenharmony_ci  const std::string body = R"(
1146fd4e5da5Sopenharmony_ci%val = OpOuterProduct %f32mat22 %f32vec2_12 %f64vec2_01
1147fd4e5da5Sopenharmony_ci)";
1148fd4e5da5Sopenharmony_ci
1149fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1150fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1151fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1152fd4e5da5Sopenharmony_ci              HasSubstr("Expected component types of the operands to be equal: "
1153fd4e5da5Sopenharmony_ci                        "OuterProduct"));
1154fd4e5da5Sopenharmony_ci}
1155fd4e5da5Sopenharmony_ci
1156fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, OuterProductRightOperandWrongDimension) {
1157fd4e5da5Sopenharmony_ci  const std::string body = R"(
1158fd4e5da5Sopenharmony_ci%val = OpOuterProduct %f32mat22 %f32vec2_12 %f32vec3_123
1159fd4e5da5Sopenharmony_ci)";
1160fd4e5da5Sopenharmony_ci
1161fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1162fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1163fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1164fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1165fd4e5da5Sopenharmony_ci      HasSubstr("Expected number of columns of the matrix to be equal to the "
1166fd4e5da5Sopenharmony_ci                "vector size of the right operand: OuterProduct"));
1167fd4e5da5Sopenharmony_ci}
1168fd4e5da5Sopenharmony_ci
1169fd4e5da5Sopenharmony_cistd::string GenerateCoopMatCode(const std::string& extra_types,
1170fd4e5da5Sopenharmony_ci                                const std::string& main_body) {
1171fd4e5da5Sopenharmony_ci  const std::string prefix =
1172fd4e5da5Sopenharmony_ci      R"(
1173fd4e5da5Sopenharmony_ciOpCapability Shader
1174fd4e5da5Sopenharmony_ciOpCapability Float16
1175fd4e5da5Sopenharmony_ciOpCapability CooperativeMatrixNV
1176fd4e5da5Sopenharmony_ciOpExtension "SPV_NV_cooperative_matrix"
1177fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1178fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %main "main"
1179fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1180fd4e5da5Sopenharmony_ci%func = OpTypeFunction %void
1181fd4e5da5Sopenharmony_ci%bool = OpTypeBool
1182fd4e5da5Sopenharmony_ci%f16 = OpTypeFloat 16
1183fd4e5da5Sopenharmony_ci%f32 = OpTypeFloat 32
1184fd4e5da5Sopenharmony_ci%u32 = OpTypeInt 32 0
1185fd4e5da5Sopenharmony_ci%s32 = OpTypeInt 32 1
1186fd4e5da5Sopenharmony_ci
1187fd4e5da5Sopenharmony_ci%u32_8 = OpConstant %u32 8
1188fd4e5da5Sopenharmony_ci%u32_16 = OpConstant %u32 16
1189fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
1190fd4e5da5Sopenharmony_ci%subgroup = OpConstant %u32 3
1191fd4e5da5Sopenharmony_ci
1192fd4e5da5Sopenharmony_ci%f16mat = OpTypeCooperativeMatrixNV %f16 %subgroup %u32_8 %u32_8
1193fd4e5da5Sopenharmony_ci%u32mat = OpTypeCooperativeMatrixNV %u32 %subgroup %u32_8 %u32_8
1194fd4e5da5Sopenharmony_ci%s32mat = OpTypeCooperativeMatrixNV %s32 %subgroup %u32_8 %u32_8
1195fd4e5da5Sopenharmony_ci
1196fd4e5da5Sopenharmony_ci%f16_1 = OpConstant %f16 1
1197fd4e5da5Sopenharmony_ci%f32_1 = OpConstant %f32 1
1198fd4e5da5Sopenharmony_ci%u32_1 = OpConstant %u32 1
1199fd4e5da5Sopenharmony_ci%s32_1 = OpConstant %s32 1
1200fd4e5da5Sopenharmony_ci
1201fd4e5da5Sopenharmony_ci%f16mat_1 = OpConstantComposite %f16mat %f16_1
1202fd4e5da5Sopenharmony_ci%u32mat_1 = OpConstantComposite %u32mat %u32_1
1203fd4e5da5Sopenharmony_ci%s32mat_1 = OpConstantComposite %s32mat %s32_1
1204fd4e5da5Sopenharmony_ci
1205fd4e5da5Sopenharmony_ci%u32_c1 = OpSpecConstant %u32 1
1206fd4e5da5Sopenharmony_ci%u32_c2 = OpSpecConstant %u32 2
1207fd4e5da5Sopenharmony_ci
1208fd4e5da5Sopenharmony_ci%f16matc = OpTypeCooperativeMatrixNV %f16 %subgroup %u32_c1 %u32_c2
1209fd4e5da5Sopenharmony_ci%f16matc_1 = OpConstantComposite %f16matc %f16_1
1210fd4e5da5Sopenharmony_ci
1211fd4e5da5Sopenharmony_ci%mat16x4 = OpTypeCooperativeMatrixNV %f16 %subgroup %u32_16 %u32_4
1212fd4e5da5Sopenharmony_ci%mat4x16 = OpTypeCooperativeMatrixNV %f16 %subgroup %u32_4 %u32_16
1213fd4e5da5Sopenharmony_ci%mat16x16 = OpTypeCooperativeMatrixNV %f16 %subgroup %u32_16 %u32_16
1214fd4e5da5Sopenharmony_ci%f16mat_16x4_1 = OpConstantComposite %mat16x4 %f16_1
1215fd4e5da5Sopenharmony_ci%f16mat_4x16_1 = OpConstantComposite %mat4x16 %f16_1
1216fd4e5da5Sopenharmony_ci%f16mat_16x16_1 = OpConstantComposite %mat16x16 %f16_1)";
1217fd4e5da5Sopenharmony_ci
1218fd4e5da5Sopenharmony_ci  const std::string func_begin =
1219fd4e5da5Sopenharmony_ci      R"(
1220fd4e5da5Sopenharmony_ci%main = OpFunction %void None %func
1221fd4e5da5Sopenharmony_ci%main_entry = OpLabel)";
1222fd4e5da5Sopenharmony_ci
1223fd4e5da5Sopenharmony_ci  const std::string suffix =
1224fd4e5da5Sopenharmony_ci      R"(
1225fd4e5da5Sopenharmony_ciOpReturn
1226fd4e5da5Sopenharmony_ciOpFunctionEnd)";
1227fd4e5da5Sopenharmony_ci
1228fd4e5da5Sopenharmony_ci  return prefix + extra_types + func_begin + main_body + suffix;
1229fd4e5da5Sopenharmony_ci}
1230fd4e5da5Sopenharmony_ci
1231fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, CoopMatSuccess) {
1232fd4e5da5Sopenharmony_ci  const std::string body = R"(
1233fd4e5da5Sopenharmony_ci%val1 = OpFAdd %f16mat %f16mat_1 %f16mat_1
1234fd4e5da5Sopenharmony_ci%val2 = OpFSub %f16mat %f16mat_1 %f16mat_1
1235fd4e5da5Sopenharmony_ci%val3 = OpFDiv %f16mat %f16mat_1 %f16mat_1
1236fd4e5da5Sopenharmony_ci%val4 = OpFNegate %f16mat %f16mat_1
1237fd4e5da5Sopenharmony_ci%val5 = OpIAdd %u32mat %u32mat_1 %u32mat_1
1238fd4e5da5Sopenharmony_ci%val6 = OpISub %u32mat %u32mat_1 %u32mat_1
1239fd4e5da5Sopenharmony_ci%val7 = OpUDiv %u32mat %u32mat_1 %u32mat_1
1240fd4e5da5Sopenharmony_ci%val8 = OpIAdd %s32mat %s32mat_1 %s32mat_1
1241fd4e5da5Sopenharmony_ci%val9 = OpISub %s32mat %s32mat_1 %s32mat_1
1242fd4e5da5Sopenharmony_ci%val10 = OpSDiv %s32mat %s32mat_1 %s32mat_1
1243fd4e5da5Sopenharmony_ci%val11 = OpSNegate %s32mat %s32mat_1
1244fd4e5da5Sopenharmony_ci%val12 = OpMatrixTimesScalar %f16mat %f16mat_1 %f16_1
1245fd4e5da5Sopenharmony_ci%val13 = OpMatrixTimesScalar %u32mat %u32mat_1 %u32_1
1246fd4e5da5Sopenharmony_ci%val14 = OpMatrixTimesScalar %s32mat %s32mat_1 %s32_1
1247fd4e5da5Sopenharmony_ci%val15 = OpCooperativeMatrixMulAddNV %mat16x16 %f16mat_16x4_1 %f16mat_4x16_1 %f16mat_16x16_1
1248fd4e5da5Sopenharmony_ci%val16 = OpCooperativeMatrixMulAddNV %f16matc %f16matc_1 %f16matc_1 %f16matc_1
1249fd4e5da5Sopenharmony_ci)";
1250fd4e5da5Sopenharmony_ci
1251fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCoopMatCode("", body).c_str());
1252fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1253fd4e5da5Sopenharmony_ci}
1254fd4e5da5Sopenharmony_ci
1255fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, CoopMatFMulFail) {
1256fd4e5da5Sopenharmony_ci  const std::string body = R"(
1257fd4e5da5Sopenharmony_ci%val1 = OpFMul %f16mat %f16mat_1 %f16mat_1
1258fd4e5da5Sopenharmony_ci)";
1259fd4e5da5Sopenharmony_ci
1260fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCoopMatCode("", body).c_str());
1261fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1262fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1263fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1264fd4e5da5Sopenharmony_ci      HasSubstr(
1265fd4e5da5Sopenharmony_ci          "Expected floating scalar or vector type as Result Type: FMul"));
1266fd4e5da5Sopenharmony_ci}
1267fd4e5da5Sopenharmony_ci
1268fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, CoopMatMatrixTimesScalarMismatchFail) {
1269fd4e5da5Sopenharmony_ci  const std::string body = R"(
1270fd4e5da5Sopenharmony_ci%val1 = OpMatrixTimesScalar %f16mat %f16mat_1 %f32_1
1271fd4e5da5Sopenharmony_ci)";
1272fd4e5da5Sopenharmony_ci
1273fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCoopMatCode("", body).c_str());
1274fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1275fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1276fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1277fd4e5da5Sopenharmony_ci      HasSubstr("Expected scalar operand type to be equal to the component "
1278fd4e5da5Sopenharmony_ci                "type of the matrix operand: MatrixTimesScalar"));
1279fd4e5da5Sopenharmony_ci}
1280fd4e5da5Sopenharmony_ci
1281fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, CoopMatScopeFail) {
1282fd4e5da5Sopenharmony_ci  const std::string types = R"(
1283fd4e5da5Sopenharmony_ci%workgroup = OpConstant %u32 2
1284fd4e5da5Sopenharmony_ci
1285fd4e5da5Sopenharmony_ci%mat16x16_wg = OpTypeCooperativeMatrixNV %f16 %workgroup %u32_16 %u32_16
1286fd4e5da5Sopenharmony_ci%f16matwg_16x16_1 = OpConstantComposite %mat16x16_wg %f16_1
1287fd4e5da5Sopenharmony_ci)";
1288fd4e5da5Sopenharmony_ci
1289fd4e5da5Sopenharmony_ci  const std::string body = R"(
1290fd4e5da5Sopenharmony_ci%val1 = OpCooperativeMatrixMulAddNV %mat16x16 %f16mat_16x4_1 %f16mat_4x16_1 %f16matwg_16x16_1
1291fd4e5da5Sopenharmony_ci)";
1292fd4e5da5Sopenharmony_ci
1293fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCoopMatCode(types, body).c_str());
1294fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1295fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1296fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1297fd4e5da5Sopenharmony_ci      HasSubstr(
1298fd4e5da5Sopenharmony_ci          "Cooperative matrix scopes must match: CooperativeMatrixMulAddNV"));
1299fd4e5da5Sopenharmony_ci}
1300fd4e5da5Sopenharmony_ci
1301fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, CoopMatDimFail) {
1302fd4e5da5Sopenharmony_ci  const std::string body = R"(
1303fd4e5da5Sopenharmony_ci%val1 = OpCooperativeMatrixMulAddNV %mat16x16 %f16mat_4x16_1 %f16mat_16x4_1 %f16mat_16x16_1
1304fd4e5da5Sopenharmony_ci)";
1305fd4e5da5Sopenharmony_ci
1306fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCoopMatCode("", body).c_str());
1307fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1308fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1309fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1310fd4e5da5Sopenharmony_ci      HasSubstr("Cooperative matrix 'M' mismatch: CooperativeMatrixMulAddNV"));
1311fd4e5da5Sopenharmony_ci}
1312fd4e5da5Sopenharmony_ci
1313fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, CoopMatComponentTypeNotScalarNumeric) {
1314fd4e5da5Sopenharmony_ci  const std::string types = R"(
1315fd4e5da5Sopenharmony_ci%bad = OpTypeCooperativeMatrixNV %bool %subgroup %u32_8 %u32_8
1316fd4e5da5Sopenharmony_ci)";
1317fd4e5da5Sopenharmony_ci
1318fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCoopMatCode(types, "").c_str());
1319fd4e5da5Sopenharmony_ci  EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
1320fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1321fd4e5da5Sopenharmony_ci              HasSubstr("OpTypeCooperativeMatrix Component Type <id> "
1322fd4e5da5Sopenharmony_ci                        "'4[%bool]' is not a scalar numerical type."));
1323fd4e5da5Sopenharmony_ci}
1324fd4e5da5Sopenharmony_ci
1325fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, CoopMatScopeNotConstantInt) {
1326fd4e5da5Sopenharmony_ci  const std::string types = R"(
1327fd4e5da5Sopenharmony_ci%bad = OpTypeCooperativeMatrixNV %f16 %f32_1 %u32_8 %u32_8
1328fd4e5da5Sopenharmony_ci)";
1329fd4e5da5Sopenharmony_ci
1330fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCoopMatCode(types, "").c_str());
1331fd4e5da5Sopenharmony_ci  EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
1332fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1333fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1334fd4e5da5Sopenharmony_ci      HasSubstr("OpTypeCooperativeMatrix Scope <id> '17[%float_1]' is not a "
1335fd4e5da5Sopenharmony_ci                "constant instruction with scalar integer type."));
1336fd4e5da5Sopenharmony_ci}
1337fd4e5da5Sopenharmony_ci
1338fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, CoopMatRowsNotConstantInt) {
1339fd4e5da5Sopenharmony_ci  const std::string types = R"(
1340fd4e5da5Sopenharmony_ci%bad = OpTypeCooperativeMatrixNV %f16 %subgroup %f32_1 %u32_8
1341fd4e5da5Sopenharmony_ci)";
1342fd4e5da5Sopenharmony_ci
1343fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCoopMatCode(types, "").c_str());
1344fd4e5da5Sopenharmony_ci  EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
1345fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1346fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1347fd4e5da5Sopenharmony_ci      HasSubstr("OpTypeCooperativeMatrix Rows <id> '17[%float_1]' is not a "
1348fd4e5da5Sopenharmony_ci                "constant instruction with scalar integer type."));
1349fd4e5da5Sopenharmony_ci}
1350fd4e5da5Sopenharmony_ci
1351fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, CoopMatColumnsNotConstantInt) {
1352fd4e5da5Sopenharmony_ci  const std::string types = R"(
1353fd4e5da5Sopenharmony_ci%bad = OpTypeCooperativeMatrixNV %f16 %subgroup %u32_8 %f32_1
1354fd4e5da5Sopenharmony_ci)";
1355fd4e5da5Sopenharmony_ci
1356fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCoopMatCode(types, "").c_str());
1357fd4e5da5Sopenharmony_ci  EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
1358fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1359fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1360fd4e5da5Sopenharmony_ci      HasSubstr("OpTypeCooperativeMatrix Cols <id> '17[%float_1]' is not a "
1361fd4e5da5Sopenharmony_ci                "constant instruction with scalar integer type."));
1362fd4e5da5Sopenharmony_ci}
1363fd4e5da5Sopenharmony_ci
1364fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, IAddCarrySuccess) {
1365fd4e5da5Sopenharmony_ci  const std::string body = R"(
1366fd4e5da5Sopenharmony_ci%val1 = OpIAddCarry %struct_u32_u32 %u32_0 %u32_1
1367fd4e5da5Sopenharmony_ci%val2 = OpIAddCarry %struct_u32vec2_u32vec2 %u32vec2_01 %u32vec2_12
1368fd4e5da5Sopenharmony_ci)";
1369fd4e5da5Sopenharmony_ci
1370fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1371fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1372fd4e5da5Sopenharmony_ci}
1373fd4e5da5Sopenharmony_ci
1374fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, IAddCarryResultTypeNotStruct) {
1375fd4e5da5Sopenharmony_ci  const std::string body = R"(
1376fd4e5da5Sopenharmony_ci%val = OpIAddCarry %u32 %u32_0 %u32_1
1377fd4e5da5Sopenharmony_ci)";
1378fd4e5da5Sopenharmony_ci
1379fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1380fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1381fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1382fd4e5da5Sopenharmony_ci              HasSubstr("Expected a struct as Result Type: IAddCarry"));
1383fd4e5da5Sopenharmony_ci}
1384fd4e5da5Sopenharmony_ci
1385fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, IAddCarryResultTypeNotTwoMembers) {
1386fd4e5da5Sopenharmony_ci  const std::string body = R"(
1387fd4e5da5Sopenharmony_ci%val = OpIAddCarry %struct_u32_u32_u32 %u32_0 %u32_1
1388fd4e5da5Sopenharmony_ci)";
1389fd4e5da5Sopenharmony_ci
1390fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1391fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1392fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1393fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1394fd4e5da5Sopenharmony_ci      HasSubstr("Expected Result Type struct to have two members: IAddCarry"));
1395fd4e5da5Sopenharmony_ci}
1396fd4e5da5Sopenharmony_ci
1397fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, IAddCarryResultTypeMemberNotUnsignedInt) {
1398fd4e5da5Sopenharmony_ci  const std::string body = R"(
1399fd4e5da5Sopenharmony_ci%val = OpIAddCarry %struct_s32_s32 %s32_0 %s32_1
1400fd4e5da5Sopenharmony_ci)";
1401fd4e5da5Sopenharmony_ci
1402fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1403fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1404fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1405fd4e5da5Sopenharmony_ci              HasSubstr("Expected Result Type struct member types to be "
1406fd4e5da5Sopenharmony_ci                        "unsigned integer scalar "
1407fd4e5da5Sopenharmony_ci                        "or vector: IAddCarry"));
1408fd4e5da5Sopenharmony_ci}
1409fd4e5da5Sopenharmony_ci
1410fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, IAddCarryWrongLeftOperand) {
1411fd4e5da5Sopenharmony_ci  const std::string body = R"(
1412fd4e5da5Sopenharmony_ci%val = OpIAddCarry %struct_u32_u32 %s32_0 %u32_1
1413fd4e5da5Sopenharmony_ci)";
1414fd4e5da5Sopenharmony_ci
1415fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1416fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1417fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1418fd4e5da5Sopenharmony_ci              HasSubstr("Expected both operands to be of Result Type member "
1419fd4e5da5Sopenharmony_ci                        "type: IAddCarry"));
1420fd4e5da5Sopenharmony_ci}
1421fd4e5da5Sopenharmony_ci
1422fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, IAddCarryWrongRightOperand) {
1423fd4e5da5Sopenharmony_ci  const std::string body = R"(
1424fd4e5da5Sopenharmony_ci%val = OpIAddCarry %struct_u32_u32 %u32_0 %s32_1
1425fd4e5da5Sopenharmony_ci)";
1426fd4e5da5Sopenharmony_ci
1427fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1428fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1429fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1430fd4e5da5Sopenharmony_ci              HasSubstr("Expected both operands to be of Result Type member "
1431fd4e5da5Sopenharmony_ci                        "type: IAddCarry"));
1432fd4e5da5Sopenharmony_ci}
1433fd4e5da5Sopenharmony_ci
1434fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, OpSMulExtendedSuccess) {
1435fd4e5da5Sopenharmony_ci  const std::string body = R"(
1436fd4e5da5Sopenharmony_ci%val1 = OpSMulExtended %struct_u32_u32 %u32_0 %u32_1
1437fd4e5da5Sopenharmony_ci%val2 = OpSMulExtended %struct_s32_s32 %s32_0 %s32_1
1438fd4e5da5Sopenharmony_ci%val3 = OpSMulExtended %struct_u32vec2_u32vec2 %u32vec2_01 %u32vec2_12
1439fd4e5da5Sopenharmony_ci%val4 = OpSMulExtended %struct_s32vec2_s32vec2 %s32vec2_01 %s32vec2_12
1440fd4e5da5Sopenharmony_ci)";
1441fd4e5da5Sopenharmony_ci
1442fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1443fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1444fd4e5da5Sopenharmony_ci}
1445fd4e5da5Sopenharmony_ci
1446fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, SMulExtendedResultTypeMemberNotInt) {
1447fd4e5da5Sopenharmony_ci  const std::string body = R"(
1448fd4e5da5Sopenharmony_ci%val = OpSMulExtended %struct_f32_f32 %f32_0 %f32_1
1449fd4e5da5Sopenharmony_ci)";
1450fd4e5da5Sopenharmony_ci
1451fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1452fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1453fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1454fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1455fd4e5da5Sopenharmony_ci      HasSubstr("Expected Result Type struct member types to be integer scalar "
1456fd4e5da5Sopenharmony_ci                "or vector: SMulExtended"));
1457fd4e5da5Sopenharmony_ci}
1458fd4e5da5Sopenharmony_ci
1459fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, SMulExtendedResultTypeMembersNotIdentical) {
1460fd4e5da5Sopenharmony_ci  const std::string body = R"(
1461fd4e5da5Sopenharmony_ci%val = OpSMulExtended %struct_s32_u32 %s32_0 %s32_1
1462fd4e5da5Sopenharmony_ci)";
1463fd4e5da5Sopenharmony_ci
1464fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCode(body).c_str());
1465fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1466fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1467fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1468fd4e5da5Sopenharmony_ci      HasSubstr("Expected Result Type struct member types to be identical: "
1469fd4e5da5Sopenharmony_ci                "SMulExtended"));
1470fd4e5da5Sopenharmony_ci}
1471fd4e5da5Sopenharmony_ci
1472fd4e5da5Sopenharmony_cistd::string GenerateCoopMatKHRCode(const std::string& extra_types,
1473fd4e5da5Sopenharmony_ci                                   const std::string& main_body) {
1474fd4e5da5Sopenharmony_ci  const std::string prefix = R"(
1475fd4e5da5Sopenharmony_ciOpCapability Shader
1476fd4e5da5Sopenharmony_ciOpCapability Float16
1477fd4e5da5Sopenharmony_ciOpCapability CooperativeMatrixKHR
1478fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_cooperative_matrix"
1479fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_vulkan_memory_model"
1480fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1481fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %main "main"
1482fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1483fd4e5da5Sopenharmony_ci%func = OpTypeFunction %void
1484fd4e5da5Sopenharmony_ci%bool = OpTypeBool
1485fd4e5da5Sopenharmony_ci%f16 = OpTypeFloat 16
1486fd4e5da5Sopenharmony_ci%f32 = OpTypeFloat 32
1487fd4e5da5Sopenharmony_ci%u32 = OpTypeInt 32 0
1488fd4e5da5Sopenharmony_ci%s32 = OpTypeInt 32 1
1489fd4e5da5Sopenharmony_ci
1490fd4e5da5Sopenharmony_ci%u32_16 = OpConstant %u32 16
1491fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
1492fd4e5da5Sopenharmony_ci%subgroup = OpConstant %u32 3
1493fd4e5da5Sopenharmony_ci%useA = OpConstant %u32 0
1494fd4e5da5Sopenharmony_ci%useB = OpConstant %u32 1
1495fd4e5da5Sopenharmony_ci%useC = OpConstant %u32 2
1496fd4e5da5Sopenharmony_ci
1497fd4e5da5Sopenharmony_ci%f16matA = OpTypeCooperativeMatrixKHR %f16 %subgroup %u32_16 %u32_16 %useA
1498fd4e5da5Sopenharmony_ci%u32matA = OpTypeCooperativeMatrixKHR %u32 %subgroup %u32_16 %u32_16 %useA
1499fd4e5da5Sopenharmony_ci%s32matA = OpTypeCooperativeMatrixKHR %s32 %subgroup %u32_16 %u32_16 %useA
1500fd4e5da5Sopenharmony_ci
1501fd4e5da5Sopenharmony_ci%f16matB = OpTypeCooperativeMatrixKHR %f16 %subgroup %u32_16 %u32_16 %useB
1502fd4e5da5Sopenharmony_ci%u32matB = OpTypeCooperativeMatrixKHR %u32 %subgroup %u32_16 %u32_16 %useB
1503fd4e5da5Sopenharmony_ci%s32matB = OpTypeCooperativeMatrixKHR %s32 %subgroup %u32_16 %u32_16 %useB
1504fd4e5da5Sopenharmony_ci
1505fd4e5da5Sopenharmony_ci%f16matC = OpTypeCooperativeMatrixKHR %f16 %subgroup %u32_16 %u32_16 %useC
1506fd4e5da5Sopenharmony_ci%f32matC = OpTypeCooperativeMatrixKHR %f32 %subgroup %u32_16 %u32_16 %useC
1507fd4e5da5Sopenharmony_ci%u32matC = OpTypeCooperativeMatrixKHR %u32 %subgroup %u32_16 %u32_16 %useC
1508fd4e5da5Sopenharmony_ci%s32matC = OpTypeCooperativeMatrixKHR %s32 %subgroup %u32_16 %u32_16 %useC
1509fd4e5da5Sopenharmony_ci
1510fd4e5da5Sopenharmony_ci%f16_1 = OpConstant %f16 1
1511fd4e5da5Sopenharmony_ci%f32_1 = OpConstant %f32 1
1512fd4e5da5Sopenharmony_ci%u32_1 = OpConstant %u32 1
1513fd4e5da5Sopenharmony_ci%s32_1 = OpConstant %s32 1
1514fd4e5da5Sopenharmony_ci
1515fd4e5da5Sopenharmony_ci%f16mat_A_1 = OpConstantComposite %f16matA %f16_1
1516fd4e5da5Sopenharmony_ci%u32mat_A_1 = OpConstantComposite %u32matA %u32_1
1517fd4e5da5Sopenharmony_ci%s32mat_A_1 = OpConstantComposite %s32matA %s32_1
1518fd4e5da5Sopenharmony_ci
1519fd4e5da5Sopenharmony_ci%f16mat_B_1 = OpConstantComposite %f16matB %f16_1
1520fd4e5da5Sopenharmony_ci%u32mat_B_1 = OpConstantComposite %u32matB %u32_1
1521fd4e5da5Sopenharmony_ci%s32mat_B_1 = OpConstantComposite %s32matB %s32_1
1522fd4e5da5Sopenharmony_ci
1523fd4e5da5Sopenharmony_ci%f16mat_C_1 = OpConstantComposite %f16matC %f16_1
1524fd4e5da5Sopenharmony_ci%u32mat_C_1 = OpConstantComposite %u32matC %u32_1
1525fd4e5da5Sopenharmony_ci%s32mat_C_1 = OpConstantComposite %s32matC %s32_1
1526fd4e5da5Sopenharmony_ci
1527fd4e5da5Sopenharmony_ci)";
1528fd4e5da5Sopenharmony_ci
1529fd4e5da5Sopenharmony_ci  const std::string func_begin = R"(
1530fd4e5da5Sopenharmony_ci%main = OpFunction %void None %func
1531fd4e5da5Sopenharmony_ci%main_entry = OpLabel)";
1532fd4e5da5Sopenharmony_ci
1533fd4e5da5Sopenharmony_ci  const std::string suffix = R"(
1534fd4e5da5Sopenharmony_ciOpReturn
1535fd4e5da5Sopenharmony_ciOpFunctionEnd)";
1536fd4e5da5Sopenharmony_ci
1537fd4e5da5Sopenharmony_ci  return prefix + extra_types + func_begin + main_body + suffix;
1538fd4e5da5Sopenharmony_ci}
1539fd4e5da5Sopenharmony_ci
1540fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, CoopMatKHRSuccess) {
1541fd4e5da5Sopenharmony_ci  const std::string body = R"(
1542fd4e5da5Sopenharmony_ci%val1 = OpFAdd %f16matA %f16mat_A_1 %f16mat_A_1
1543fd4e5da5Sopenharmony_ci%val2 = OpFSub %f16matA %f16mat_A_1 %f16mat_A_1
1544fd4e5da5Sopenharmony_ci%val3 = OpFMul %f16matA %f16mat_A_1 %f16mat_A_1
1545fd4e5da5Sopenharmony_ci%val4 = OpFDiv %f16matA %f16mat_A_1 %f16mat_A_1
1546fd4e5da5Sopenharmony_ci%val5 = OpFNegate %f16matA %f16mat_A_1
1547fd4e5da5Sopenharmony_ci%val6 = OpIAdd %u32matA %u32mat_A_1 %u32mat_A_1
1548fd4e5da5Sopenharmony_ci%val7 = OpISub %u32matA %u32mat_A_1 %u32mat_A_1
1549fd4e5da5Sopenharmony_ci%val8 = OpUDiv %u32matA %u32mat_A_1 %u32mat_A_1
1550fd4e5da5Sopenharmony_ci%val9 = OpIAdd %s32matA %s32mat_A_1 %s32mat_A_1
1551fd4e5da5Sopenharmony_ci%val10 = OpISub %s32matA %s32mat_A_1 %s32mat_A_1
1552fd4e5da5Sopenharmony_ci%val11 = OpSDiv %s32matA %s32mat_A_1 %s32mat_A_1
1553fd4e5da5Sopenharmony_ci%val12 = OpSNegate %s32matA %s32mat_A_1
1554fd4e5da5Sopenharmony_ci%val13 = OpMatrixTimesScalar %f16matA %f16mat_A_1 %f16_1
1555fd4e5da5Sopenharmony_ci%val14 = OpMatrixTimesScalar %u32matA %u32mat_A_1 %u32_1
1556fd4e5da5Sopenharmony_ci%val15 = OpMatrixTimesScalar %s32matA %s32mat_A_1 %s32_1
1557fd4e5da5Sopenharmony_ci%val16 = OpCooperativeMatrixMulAddKHR %f32matC %f16mat_A_1 %f16mat_B_1 %f16mat_C_1
1558fd4e5da5Sopenharmony_ci%val17 = OpCooperativeMatrixMulAddKHR %s32matC %s32mat_A_1 %s32mat_B_1 %s32mat_C_1
1559fd4e5da5Sopenharmony_ci  MatrixASignedComponentsKHR|MatrixBSignedComponentsKHR|MatrixCSignedComponentsKHR|MatrixResultSignedComponentsKHR
1560fd4e5da5Sopenharmony_ci%val18 = OpCooperativeMatrixMulAddKHR %u32matC %u32mat_A_1 %u32mat_B_1 %u32mat_C_1
1561fd4e5da5Sopenharmony_ci)";
1562fd4e5da5Sopenharmony_ci
1563fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCoopMatKHRCode("", body).c_str());
1564fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1565fd4e5da5Sopenharmony_ci}
1566fd4e5da5Sopenharmony_ci
1567fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, CoopMatMatrixKHRTimesScalarMismatchFail) {
1568fd4e5da5Sopenharmony_ci  const std::string body = R"(
1569fd4e5da5Sopenharmony_ci%val1 = OpMatrixTimesScalar %f16matA %f16mat_A_1 %f32_1
1570fd4e5da5Sopenharmony_ci)";
1571fd4e5da5Sopenharmony_ci
1572fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCoopMatKHRCode("", body).c_str());
1573fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1574fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1575fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1576fd4e5da5Sopenharmony_ci      HasSubstr("Expected scalar operand type to be equal to the component "
1577fd4e5da5Sopenharmony_ci                "type of the matrix operand: MatrixTimesScalar"));
1578fd4e5da5Sopenharmony_ci}
1579fd4e5da5Sopenharmony_ci
1580fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, CoopMatKHRScopeFail) {
1581fd4e5da5Sopenharmony_ci  const std::string types = R"(
1582fd4e5da5Sopenharmony_ci%workgroup = OpConstant %u32 2
1583fd4e5da5Sopenharmony_ci%mat16x16_wg = OpTypeCooperativeMatrixKHR %f16 %workgroup %u32_16 %u32_16 %useC
1584fd4e5da5Sopenharmony_ci%f16matwg_16x16_1 = OpConstantComposite %mat16x16_wg %f16_1
1585fd4e5da5Sopenharmony_ci)";
1586fd4e5da5Sopenharmony_ci
1587fd4e5da5Sopenharmony_ci  const std::string body = R"(
1588fd4e5da5Sopenharmony_ci%val1 = OpFAdd %f16matA %f16matwg_16x16_1 %f16mat_A_1
1589fd4e5da5Sopenharmony_ci)";
1590fd4e5da5Sopenharmony_ci
1591fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCoopMatKHRCode(types, body).c_str());
1592fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1593fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1594fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1595fd4e5da5Sopenharmony_ci      HasSubstr("Expected scopes of Matrix and Result Type to be identical"));
1596fd4e5da5Sopenharmony_ci}
1597fd4e5da5Sopenharmony_ci
1598fd4e5da5Sopenharmony_ciTEST_F(ValidateArithmetics, CoopMatKHRDimFail) {
1599fd4e5da5Sopenharmony_ci  const std::string types = R"(
1600fd4e5da5Sopenharmony_ci%mat16x4 = OpTypeCooperativeMatrixKHR %f16 %subgroup %u32_16 %u32_4 %useC
1601fd4e5da5Sopenharmony_ci%mat16x4_C_1 = OpConstantComposite %mat16x4 %f16_1
1602fd4e5da5Sopenharmony_ci)";
1603fd4e5da5Sopenharmony_ci
1604fd4e5da5Sopenharmony_ci  const std::string body = R"(
1605fd4e5da5Sopenharmony_ci%val1 = OpCooperativeMatrixMulAddKHR %mat16x4 %f16mat_A_1 %f16mat_B_1 %mat16x4_C_1
1606fd4e5da5Sopenharmony_ci)";
1607fd4e5da5Sopenharmony_ci
1608fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateCoopMatKHRCode(types, body).c_str());
1609fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1610fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1611fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1612fd4e5da5Sopenharmony_ci      HasSubstr("Cooperative matrix 'N' mismatch: CooperativeMatrixMulAddKHR"));
1613fd4e5da5Sopenharmony_ci}
1614fd4e5da5Sopenharmony_ci
1615fd4e5da5Sopenharmony_ci}  // namespace
1616fd4e5da5Sopenharmony_ci}  // namespace val
1617fd4e5da5Sopenharmony_ci}  // namespace spvtools
1618