2017-08-30 14:13:10 +00:00
|
|
|
// Copyright (c) 2017 Google Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2017-10-13 19:53:58 +00:00
|
|
|
// Performs validation of arithmetic instructions.
|
2017-08-30 14:13:10 +00:00
|
|
|
|
2018-07-11 14:27:34 +00:00
|
|
|
#include "source/val/validate.h"
|
2017-08-30 14:13:10 +00:00
|
|
|
|
2018-08-03 19:06:09 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2018-07-11 14:27:34 +00:00
|
|
|
#include "source/diagnostic.h"
|
|
|
|
#include "source/opcode.h"
|
|
|
|
#include "source/val/instruction.h"
|
|
|
|
#include "source/val/validation_state.h"
|
2017-08-30 14:13:10 +00:00
|
|
|
|
2018-07-07 13:38:00 +00:00
|
|
|
namespace spvtools {
|
2018-07-10 03:18:44 +00:00
|
|
|
namespace val {
|
2017-08-30 14:13:10 +00:00
|
|
|
|
|
|
|
// Validates correctness of arithmetic instructions.
|
2018-07-10 14:57:52 +00:00
|
|
|
spv_result_t ArithmeticsPass(ValidationState_t& _, const Instruction* inst) {
|
|
|
|
const SpvOp opcode = inst->opcode();
|
|
|
|
const uint32_t result_type = inst->type_id();
|
2017-08-30 14:13:10 +00:00
|
|
|
|
|
|
|
switch (opcode) {
|
|
|
|
case SpvOpFAdd:
|
|
|
|
case SpvOpFSub:
|
|
|
|
case SpvOpFMul:
|
|
|
|
case SpvOpFDiv:
|
|
|
|
case SpvOpFRem:
|
|
|
|
case SpvOpFMod:
|
|
|
|
case SpvOpFNegate: {
|
2019-02-25 22:43:11 +00:00
|
|
|
bool supportsCoopMat =
|
|
|
|
(opcode != SpvOpFMul && opcode != SpvOpFRem && opcode != SpvOpFMod);
|
2017-09-18 21:07:00 +00:00
|
|
|
if (!_.IsFloatScalarType(result_type) &&
|
2019-02-25 22:43:11 +00:00
|
|
|
!_.IsFloatVectorType(result_type) &&
|
|
|
|
!(supportsCoopMat && _.IsFloatCooperativeMatrixType(result_type)))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected floating scalar or vector type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-08-30 14:13:10 +00:00
|
|
|
|
2018-07-10 14:57:52 +00:00
|
|
|
for (size_t operand_index = 2; operand_index < inst->operands().size();
|
2017-08-30 14:13:10 +00:00
|
|
|
++operand_index) {
|
2018-07-10 14:57:52 +00:00
|
|
|
if (_.GetOperandTypeId(inst, operand_index) != result_type)
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected arithmetic operands to be of Result Type: "
|
|
|
|
<< spvOpcodeString(opcode) << " operand index "
|
|
|
|
<< operand_index;
|
2017-08-30 14:13:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpUDiv:
|
|
|
|
case SpvOpUMod: {
|
2019-02-25 22:43:11 +00:00
|
|
|
bool supportsCoopMat = (opcode == SpvOpUDiv);
|
2017-09-18 21:07:00 +00:00
|
|
|
if (!_.IsUnsignedIntScalarType(result_type) &&
|
2019-02-25 22:43:11 +00:00
|
|
|
!_.IsUnsignedIntVectorType(result_type) &&
|
|
|
|
!(supportsCoopMat &&
|
|
|
|
_.IsUnsignedIntCooperativeMatrixType(result_type)))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected unsigned int scalar or vector type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-08-30 14:13:10 +00:00
|
|
|
|
2018-07-10 14:57:52 +00:00
|
|
|
for (size_t operand_index = 2; operand_index < inst->operands().size();
|
2017-08-30 14:13:10 +00:00
|
|
|
++operand_index) {
|
2018-07-10 14:57:52 +00:00
|
|
|
if (_.GetOperandTypeId(inst, operand_index) != result_type)
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected arithmetic operands to be of Result Type: "
|
|
|
|
<< spvOpcodeString(opcode) << " operand index "
|
|
|
|
<< operand_index;
|
2017-08-30 14:13:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpISub:
|
|
|
|
case SpvOpIAdd:
|
|
|
|
case SpvOpIMul:
|
|
|
|
case SpvOpSDiv:
|
|
|
|
case SpvOpSMod:
|
|
|
|
case SpvOpSRem:
|
|
|
|
case SpvOpSNegate: {
|
2019-02-25 22:43:11 +00:00
|
|
|
bool supportsCoopMat =
|
|
|
|
(opcode != SpvOpIMul && opcode != SpvOpSRem && opcode != SpvOpSMod);
|
|
|
|
if (!_.IsIntScalarType(result_type) && !_.IsIntVectorType(result_type) &&
|
|
|
|
!(supportsCoopMat && _.IsIntCooperativeMatrixType(result_type)))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected int scalar or vector type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-08-30 14:13:10 +00:00
|
|
|
|
2017-09-18 21:07:00 +00:00
|
|
|
const uint32_t dimension = _.GetDimension(result_type);
|
|
|
|
const uint32_t bit_width = _.GetBitWidth(result_type);
|
2017-08-30 14:13:10 +00:00
|
|
|
|
2018-07-10 14:57:52 +00:00
|
|
|
for (size_t operand_index = 2; operand_index < inst->operands().size();
|
2017-08-30 14:13:10 +00:00
|
|
|
++operand_index) {
|
2018-07-10 14:57:52 +00:00
|
|
|
const uint32_t type_id = _.GetOperandTypeId(inst, operand_index);
|
2017-08-30 14:13:10 +00:00
|
|
|
if (!type_id ||
|
2019-02-25 22:43:11 +00:00
|
|
|
(!_.IsIntScalarType(type_id) && !_.IsIntVectorType(type_id) &&
|
|
|
|
!(supportsCoopMat && _.IsIntCooperativeMatrixType(result_type))))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected int scalar or vector type as operand: "
|
|
|
|
<< spvOpcodeString(opcode) << " operand index "
|
|
|
|
<< operand_index;
|
2017-08-30 14:13:10 +00:00
|
|
|
|
|
|
|
if (_.GetDimension(type_id) != dimension)
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected arithmetic operands to have the same dimension "
|
|
|
|
<< "as Result Type: " << spvOpcodeString(opcode)
|
|
|
|
<< " operand index " << operand_index;
|
2017-08-30 14:13:10 +00:00
|
|
|
|
|
|
|
if (_.GetBitWidth(type_id) != bit_width)
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected arithmetic operands to have the same bit width "
|
|
|
|
<< "as Result Type: " << spvOpcodeString(opcode)
|
|
|
|
<< " operand index " << operand_index;
|
2017-08-30 14:13:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-09-06 18:30:27 +00:00
|
|
|
case SpvOpDot: {
|
2017-09-18 21:07:00 +00:00
|
|
|
if (!_.IsFloatScalarType(result_type))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected float scalar type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
uint32_t first_vector_num_components = 0;
|
|
|
|
|
2018-07-10 14:57:52 +00:00
|
|
|
for (size_t operand_index = 2; operand_index < inst->operands().size();
|
2017-09-06 18:30:27 +00:00
|
|
|
++operand_index) {
|
2018-07-10 14:57:52 +00:00
|
|
|
const uint32_t type_id = _.GetOperandTypeId(inst, operand_index);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
if (!type_id || !_.IsFloatVectorType(type_id))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected float vector as operand: "
|
|
|
|
<< spvOpcodeString(opcode) << " operand index "
|
|
|
|
<< operand_index;
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
const uint32_t component_type = _.GetComponentType(type_id);
|
2017-09-18 21:07:00 +00:00
|
|
|
if (component_type != result_type)
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected component type to be equal to Result Type: "
|
|
|
|
<< spvOpcodeString(opcode) << " operand index "
|
|
|
|
<< operand_index;
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
const uint32_t num_components = _.GetDimension(type_id);
|
|
|
|
if (operand_index == 2) {
|
|
|
|
first_vector_num_components = num_components;
|
|
|
|
} else if (num_components != first_vector_num_components) {
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2022-01-26 20:13:08 +00:00
|
|
|
<< "Expected operands to have the same number of components: "
|
2017-11-08 17:40:02 +00:00
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpVectorTimesScalar: {
|
2017-09-18 21:07:00 +00:00
|
|
|
if (!_.IsFloatVectorType(result_type))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected float vector type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
2018-07-10 14:57:52 +00:00
|
|
|
const uint32_t vector_type_id = _.GetOperandTypeId(inst, 2);
|
2017-09-18 21:07:00 +00:00
|
|
|
if (result_type != vector_type_id)
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected vector operand type to be equal to Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
const uint32_t component_type = _.GetComponentType(vector_type_id);
|
|
|
|
|
2018-07-10 14:57:52 +00:00
|
|
|
const uint32_t scalar_type_id = _.GetOperandTypeId(inst, 3);
|
2017-09-06 18:30:27 +00:00
|
|
|
if (component_type != scalar_type_id)
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected scalar operand type to be equal to the component "
|
|
|
|
<< "type of the vector operand: " << spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpMatrixTimesScalar: {
|
2019-02-25 22:43:11 +00:00
|
|
|
if (!_.IsFloatMatrixType(result_type) &&
|
|
|
|
!_.IsCooperativeMatrixType(result_type))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected float matrix type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
2018-07-10 14:57:52 +00:00
|
|
|
const uint32_t matrix_type_id = _.GetOperandTypeId(inst, 2);
|
2017-09-18 21:07:00 +00:00
|
|
|
if (result_type != matrix_type_id)
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected matrix operand type to be equal to Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
const uint32_t component_type = _.GetComponentType(matrix_type_id);
|
|
|
|
|
2018-07-10 14:57:52 +00:00
|
|
|
const uint32_t scalar_type_id = _.GetOperandTypeId(inst, 3);
|
2017-09-06 18:30:27 +00:00
|
|
|
if (component_type != scalar_type_id)
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected scalar operand type to be equal to the component "
|
|
|
|
<< "type of the matrix operand: " << spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpVectorTimesMatrix: {
|
2018-07-10 14:57:52 +00:00
|
|
|
const uint32_t vector_type_id = _.GetOperandTypeId(inst, 2);
|
|
|
|
const uint32_t matrix_type_id = _.GetOperandTypeId(inst, 3);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
2017-09-18 21:07:00 +00:00
|
|
|
if (!_.IsFloatVectorType(result_type))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected float vector type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
2017-09-18 21:07:00 +00:00
|
|
|
const uint32_t res_component_type = _.GetComponentType(result_type);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
if (!vector_type_id || !_.IsFloatVectorType(vector_type_id))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected float vector type as left operand: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
if (res_component_type != _.GetComponentType(vector_type_id))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected component types of Result Type and vector to be "
|
|
|
|
<< "equal: " << spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
uint32_t matrix_num_rows = 0;
|
|
|
|
uint32_t matrix_num_cols = 0;
|
|
|
|
uint32_t matrix_col_type = 0;
|
|
|
|
uint32_t matrix_component_type = 0;
|
|
|
|
if (!_.GetMatrixTypeInfo(matrix_type_id, &matrix_num_rows,
|
|
|
|
&matrix_num_cols, &matrix_col_type,
|
|
|
|
&matrix_component_type))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected float matrix type as right operand: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
if (res_component_type != matrix_component_type)
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected component types of Result Type and matrix to be "
|
|
|
|
<< "equal: " << spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
2017-09-18 21:07:00 +00:00
|
|
|
if (matrix_num_cols != _.GetDimension(result_type))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected number of columns of the matrix to be equal to "
|
|
|
|
<< "Result Type vector size: " << spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
if (matrix_num_rows != _.GetDimension(vector_type_id))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected number of rows of the matrix to be equal to the "
|
|
|
|
<< "vector operand size: " << spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpMatrixTimesVector: {
|
2018-07-10 14:57:52 +00:00
|
|
|
const uint32_t matrix_type_id = _.GetOperandTypeId(inst, 2);
|
|
|
|
const uint32_t vector_type_id = _.GetOperandTypeId(inst, 3);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
2017-09-18 21:07:00 +00:00
|
|
|
if (!_.IsFloatVectorType(result_type))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected float vector type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
uint32_t matrix_num_rows = 0;
|
|
|
|
uint32_t matrix_num_cols = 0;
|
|
|
|
uint32_t matrix_col_type = 0;
|
|
|
|
uint32_t matrix_component_type = 0;
|
|
|
|
if (!_.GetMatrixTypeInfo(matrix_type_id, &matrix_num_rows,
|
|
|
|
&matrix_num_cols, &matrix_col_type,
|
|
|
|
&matrix_component_type))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected float matrix type as left operand: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
2017-09-18 21:07:00 +00:00
|
|
|
if (result_type != matrix_col_type)
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected column type of the matrix to be equal to Result "
|
|
|
|
"Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
if (!vector_type_id || !_.IsFloatVectorType(vector_type_id))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected float vector type as right operand: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
if (matrix_component_type != _.GetComponentType(vector_type_id))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected component types of the operands to be equal: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
if (matrix_num_cols != _.GetDimension(vector_type_id))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected number of columns of the matrix to be equal to the "
|
|
|
|
<< "vector size: " << spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpMatrixTimesMatrix: {
|
2018-07-10 14:57:52 +00:00
|
|
|
const uint32_t left_type_id = _.GetOperandTypeId(inst, 2);
|
|
|
|
const uint32_t right_type_id = _.GetOperandTypeId(inst, 3);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
uint32_t res_num_rows = 0;
|
|
|
|
uint32_t res_num_cols = 0;
|
|
|
|
uint32_t res_col_type = 0;
|
|
|
|
uint32_t res_component_type = 0;
|
2017-09-18 21:07:00 +00:00
|
|
|
if (!_.GetMatrixTypeInfo(result_type, &res_num_rows, &res_num_cols,
|
2017-09-06 18:30:27 +00:00
|
|
|
&res_col_type, &res_component_type))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected float matrix type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
uint32_t left_num_rows = 0;
|
|
|
|
uint32_t left_num_cols = 0;
|
|
|
|
uint32_t left_col_type = 0;
|
|
|
|
uint32_t left_component_type = 0;
|
|
|
|
if (!_.GetMatrixTypeInfo(left_type_id, &left_num_rows, &left_num_cols,
|
|
|
|
&left_col_type, &left_component_type))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected float matrix type as left operand: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
uint32_t right_num_rows = 0;
|
|
|
|
uint32_t right_num_cols = 0;
|
|
|
|
uint32_t right_col_type = 0;
|
|
|
|
uint32_t right_component_type = 0;
|
|
|
|
if (!_.GetMatrixTypeInfo(right_type_id, &right_num_rows, &right_num_cols,
|
|
|
|
&right_col_type, &right_component_type))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected float matrix type as right operand: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
if (!_.IsFloatScalarType(res_component_type))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected float matrix type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
if (res_col_type != left_col_type)
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected column types of Result Type and left matrix to be "
|
|
|
|
<< "equal: " << spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
if (res_component_type != right_component_type)
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected component types of Result Type and right matrix to "
|
|
|
|
"be "
|
|
|
|
<< "equal: " << spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
if (res_num_cols != right_num_cols)
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected number of columns of Result Type and right matrix "
|
|
|
|
"to "
|
|
|
|
<< "be equal: " << spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
if (left_num_cols != right_num_rows)
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected number of columns of left matrix and number of "
|
|
|
|
"rows "
|
|
|
|
<< "of right matrix to be equal: " << spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
assert(left_num_rows == res_num_rows);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpOuterProduct: {
|
2018-07-10 14:57:52 +00:00
|
|
|
const uint32_t left_type_id = _.GetOperandTypeId(inst, 2);
|
|
|
|
const uint32_t right_type_id = _.GetOperandTypeId(inst, 3);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
uint32_t res_num_rows = 0;
|
|
|
|
uint32_t res_num_cols = 0;
|
|
|
|
uint32_t res_col_type = 0;
|
|
|
|
uint32_t res_component_type = 0;
|
2017-09-18 21:07:00 +00:00
|
|
|
if (!_.GetMatrixTypeInfo(result_type, &res_num_rows, &res_num_cols,
|
2017-09-06 18:30:27 +00:00
|
|
|
&res_col_type, &res_component_type))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected float matrix type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
if (left_type_id != res_col_type)
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected column type of Result Type to be equal to the type "
|
|
|
|
<< "of the left operand: " << spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
if (!right_type_id || !_.IsFloatVectorType(right_type_id))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected float vector type as right operand: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
if (res_component_type != _.GetComponentType(right_type_id))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected component types of the operands to be equal: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
if (res_num_cols != _.GetDimension(right_type_id))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected number of columns of the matrix to be equal to the "
|
|
|
|
<< "vector size of the right operand: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-06 18:30:27 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-09-18 17:06:40 +00:00
|
|
|
case SpvOpIAddCarry:
|
|
|
|
case SpvOpISubBorrow:
|
|
|
|
case SpvOpUMulExtended:
|
|
|
|
case SpvOpSMulExtended: {
|
|
|
|
std::vector<uint32_t> result_types;
|
|
|
|
if (!_.GetStructMemberTypes(result_type, &result_types))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected a struct as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-18 17:06:40 +00:00
|
|
|
|
|
|
|
if (result_types.size() != 2)
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected Result Type struct to have two members: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-18 17:06:40 +00:00
|
|
|
|
|
|
|
if (opcode == SpvOpSMulExtended) {
|
|
|
|
if (!_.IsIntScalarType(result_types[0]) &&
|
|
|
|
!_.IsIntVectorType(result_types[0]))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected Result Type struct member types to be integer "
|
|
|
|
"scalar "
|
|
|
|
<< "or vector: " << spvOpcodeString(opcode);
|
2017-09-18 17:06:40 +00:00
|
|
|
} else {
|
|
|
|
if (!_.IsUnsignedIntScalarType(result_types[0]) &&
|
|
|
|
!_.IsUnsignedIntVectorType(result_types[0]))
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected Result Type struct member types to be unsigned "
|
|
|
|
<< "integer scalar or vector: " << spvOpcodeString(opcode);
|
2017-09-18 17:06:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (result_types[0] != result_types[1])
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected Result Type struct member types to be identical: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-18 17:06:40 +00:00
|
|
|
|
2018-07-10 14:57:52 +00:00
|
|
|
const uint32_t left_type_id = _.GetOperandTypeId(inst, 2);
|
|
|
|
const uint32_t right_type_id = _.GetOperandTypeId(inst, 3);
|
2017-09-18 17:06:40 +00:00
|
|
|
|
|
|
|
if (left_type_id != result_types[0] || right_type_id != result_types[0])
|
2018-07-31 20:26:58 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected both operands to be of Result Type member type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-18 17:06:40 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2017-09-06 18:30:27 +00:00
|
|
|
|
2019-02-25 22:43:11 +00:00
|
|
|
case SpvOpCooperativeMatrixMulAddNV: {
|
|
|
|
const uint32_t D_type_id = _.GetOperandTypeId(inst, 1);
|
|
|
|
const uint32_t A_type_id = _.GetOperandTypeId(inst, 2);
|
|
|
|
const uint32_t B_type_id = _.GetOperandTypeId(inst, 3);
|
|
|
|
const uint32_t C_type_id = _.GetOperandTypeId(inst, 4);
|
|
|
|
|
|
|
|
if (!_.IsCooperativeMatrixType(A_type_id)) {
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Expected cooperative matrix type as A Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
}
|
|
|
|
if (!_.IsCooperativeMatrixType(B_type_id)) {
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Expected cooperative matrix type as B Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
}
|
|
|
|
if (!_.IsCooperativeMatrixType(C_type_id)) {
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Expected cooperative matrix type as C Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
}
|
|
|
|
if (!_.IsCooperativeMatrixType(D_type_id)) {
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Expected cooperative matrix type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto A = _.FindDef(A_type_id);
|
|
|
|
const auto B = _.FindDef(B_type_id);
|
|
|
|
const auto C = _.FindDef(C_type_id);
|
|
|
|
const auto D = _.FindDef(D_type_id);
|
|
|
|
|
|
|
|
std::tuple<bool, bool, uint32_t> A_scope, B_scope, C_scope, D_scope,
|
|
|
|
A_rows, B_rows, C_rows, D_rows, A_cols, B_cols, C_cols, D_cols;
|
|
|
|
|
|
|
|
A_scope = _.EvalInt32IfConst(A->GetOperandAs<uint32_t>(2));
|
|
|
|
B_scope = _.EvalInt32IfConst(B->GetOperandAs<uint32_t>(2));
|
|
|
|
C_scope = _.EvalInt32IfConst(C->GetOperandAs<uint32_t>(2));
|
|
|
|
D_scope = _.EvalInt32IfConst(D->GetOperandAs<uint32_t>(2));
|
|
|
|
|
|
|
|
A_rows = _.EvalInt32IfConst(A->GetOperandAs<uint32_t>(3));
|
|
|
|
B_rows = _.EvalInt32IfConst(B->GetOperandAs<uint32_t>(3));
|
|
|
|
C_rows = _.EvalInt32IfConst(C->GetOperandAs<uint32_t>(3));
|
|
|
|
D_rows = _.EvalInt32IfConst(D->GetOperandAs<uint32_t>(3));
|
|
|
|
|
|
|
|
A_cols = _.EvalInt32IfConst(A->GetOperandAs<uint32_t>(4));
|
|
|
|
B_cols = _.EvalInt32IfConst(B->GetOperandAs<uint32_t>(4));
|
|
|
|
C_cols = _.EvalInt32IfConst(C->GetOperandAs<uint32_t>(4));
|
|
|
|
D_cols = _.EvalInt32IfConst(D->GetOperandAs<uint32_t>(4));
|
|
|
|
|
|
|
|
const auto notEqual = [](std::tuple<bool, bool, uint32_t> X,
|
|
|
|
std::tuple<bool, bool, uint32_t> Y) {
|
|
|
|
return (std::get<1>(X) && std::get<1>(Y) &&
|
|
|
|
std::get<2>(X) != std::get<2>(Y));
|
|
|
|
};
|
|
|
|
|
|
|
|
if (notEqual(A_scope, B_scope) || notEqual(A_scope, C_scope) ||
|
|
|
|
notEqual(A_scope, D_scope) || notEqual(B_scope, C_scope) ||
|
|
|
|
notEqual(B_scope, D_scope) || notEqual(C_scope, D_scope)) {
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Cooperative matrix scopes must match: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (notEqual(A_rows, C_rows) || notEqual(A_rows, D_rows) ||
|
|
|
|
notEqual(C_rows, D_rows)) {
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Cooperative matrix 'M' mismatch: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (notEqual(B_cols, C_cols) || notEqual(B_cols, D_cols) ||
|
|
|
|
notEqual(C_cols, D_cols)) {
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Cooperative matrix 'N' mismatch: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (notEqual(A_cols, B_rows)) {
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Cooperative matrix 'K' mismatch: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-08-30 14:13:10 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SPV_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-07-10 03:18:44 +00:00
|
|
|
} // namespace val
|
2018-07-07 13:38:00 +00:00
|
|
|
} // namespace spvtools
|