MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / ValidateFloat

Function ValidateFloat

source/val/validate_arithmetics.cpp:27–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25namespace val {
26
27spv_result_t ValidateFloat(ValidationState_t& _, const Instruction* inst,
28 uint32_t starting_index = 2) {
29 const spv::Op opcode = inst->opcode();
30 const uint32_t result_type = inst->type_id();
31 bool supportsCoopMat =
32 (opcode != spv::Op::OpFMul && opcode != spv::Op::OpFRem &&
33 opcode != spv::Op::OpFMod);
34 bool supportsCoopVec =
35 (opcode != spv::Op::OpFRem && opcode != spv::Op::OpFMod);
36 if (!_.IsFloatScalarType(result_type) && !_.IsFloatVectorType(result_type) &&
37 !(supportsCoopMat && _.IsFloatCooperativeMatrixType(result_type)) &&
38 !(opcode == spv::Op::OpFMul &&
39 _.IsCooperativeMatrixKHRType(result_type) &&
40 _.IsFloatCooperativeMatrixType(result_type)) &&
41 !(supportsCoopVec && _.IsFloatCooperativeVectorNVType(result_type)))
42 return _.diag(SPV_ERROR_INVALID_DATA, inst)
43 << "Expected floating scalar or vector type as Result Type: "
44 << spvOpcodeString(opcode);
45
46 for (size_t operand_index = starting_index;
47 operand_index < inst->operands().size(); ++operand_index) {
48 if (supportsCoopVec && _.IsCooperativeVectorNVType(result_type)) {
49 const uint32_t type_id = _.GetOperandTypeId(inst, operand_index);
50 if (!_.IsCooperativeVectorNVType(type_id)) {
51 return _.diag(SPV_ERROR_INVALID_DATA, inst)
52 << "Expected arithmetic operands to be of Result Type: "
53 << spvOpcodeString(opcode) << " operand index " << operand_index;
54 }
55 spv_result_t ret =
56 _.CooperativeVectorDimensionsMatch(inst, type_id, result_type);
57 if (ret != SPV_SUCCESS) return ret;
58 } else if (supportsCoopMat && _.IsCooperativeMatrixKHRType(result_type)) {
59 const uint32_t type_id = _.GetOperandTypeId(inst, operand_index);
60 if (!_.IsCooperativeMatrixKHRType(type_id) ||
61 !_.IsFloatCooperativeMatrixType(type_id)) {
62 return _.diag(SPV_ERROR_INVALID_DATA, inst)
63 << "Expected arithmetic operands to be of Result Type: "
64 << spvOpcodeString(opcode) << " operand index " << operand_index;
65 }
66 spv_result_t ret =
67 _.CooperativeMatrixShapesMatch(inst, result_type, type_id, false);
68 if (ret != SPV_SUCCESS) return ret;
69 } else if (_.GetOperandTypeId(inst, operand_index) != result_type)
70 return _.diag(SPV_ERROR_INVALID_DATA, inst)
71 << "Expected arithmetic operands to be of Result Type: "
72 << spvOpcodeString(opcode) << " operand index " << operand_index;
73 }
74 return SPV_SUCCESS;
75}
76
77spv_result_t ValidateUnsignedInt(ValidationState_t& _, const Instruction* inst,
78 uint32_t starting_index = 2) {

Callers 1

ArithmeticsPassFunction · 0.85

Calls 15

spvOpcodeStringFunction · 0.85
IsFloatScalarTypeMethod · 0.80
IsFloatVectorTypeMethod · 0.80
diagMethod · 0.80
operandsMethod · 0.80
GetOperandTypeIdMethod · 0.80

Tested by

no test coverage detected