validate_conversion.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. // Copyright (c) 2017 Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Validates correctness of conversion instructions.
  15. #include "source/val/validate.h"
  16. #include "source/diagnostic.h"
  17. #include "source/opcode.h"
  18. #include "source/val/instruction.h"
  19. #include "source/val/validation_state.h"
  20. namespace spvtools {
  21. namespace val {
  22. // Validates correctness of conversion instructions.
  23. spv_result_t ConversionPass(ValidationState_t& _, const Instruction* inst) {
  24. const SpvOp opcode = inst->opcode();
  25. const uint32_t result_type = inst->type_id();
  26. switch (opcode) {
  27. case SpvOpConvertFToU: {
  28. if (!_.IsUnsignedIntScalarType(result_type) &&
  29. !_.IsUnsignedIntVectorType(result_type) &&
  30. !_.IsUnsignedIntCooperativeMatrixType(result_type))
  31. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  32. << "Expected unsigned int scalar or vector type as Result Type: "
  33. << spvOpcodeString(opcode);
  34. const uint32_t input_type = _.GetOperandTypeId(inst, 2);
  35. if (!input_type || (!_.IsFloatScalarType(input_type) &&
  36. !_.IsFloatVectorType(input_type) &&
  37. !_.IsFloatCooperativeMatrixType(input_type)))
  38. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  39. << "Expected input to be float scalar or vector: "
  40. << spvOpcodeString(opcode);
  41. if (_.IsCooperativeMatrixType(result_type) ||
  42. _.IsCooperativeMatrixType(input_type)) {
  43. spv_result_t ret =
  44. _.CooperativeMatrixShapesMatch(inst, result_type, input_type);
  45. if (ret != SPV_SUCCESS) return ret;
  46. } else {
  47. if (_.GetDimension(result_type) != _.GetDimension(input_type))
  48. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  49. << "Expected input to have the same dimension as Result Type: "
  50. << spvOpcodeString(opcode);
  51. }
  52. if (!_.features().use_int8_type && (8 == _.GetBitWidth(result_type)))
  53. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  54. << "Invalid cast to 8-bit integer from a floating-point: "
  55. << spvOpcodeString(opcode);
  56. break;
  57. }
  58. case SpvOpConvertFToS: {
  59. if (!_.IsIntScalarType(result_type) && !_.IsIntVectorType(result_type) &&
  60. !_.IsIntCooperativeMatrixType(result_type))
  61. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  62. << "Expected int scalar or vector type as Result Type: "
  63. << spvOpcodeString(opcode);
  64. const uint32_t input_type = _.GetOperandTypeId(inst, 2);
  65. if (!input_type || (!_.IsFloatScalarType(input_type) &&
  66. !_.IsFloatVectorType(input_type) &&
  67. !_.IsFloatCooperativeMatrixType(input_type)))
  68. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  69. << "Expected input to be float scalar or vector: "
  70. << spvOpcodeString(opcode);
  71. if (_.IsCooperativeMatrixType(result_type) ||
  72. _.IsCooperativeMatrixType(input_type)) {
  73. spv_result_t ret =
  74. _.CooperativeMatrixShapesMatch(inst, result_type, input_type);
  75. if (ret != SPV_SUCCESS) return ret;
  76. } else {
  77. if (_.GetDimension(result_type) != _.GetDimension(input_type))
  78. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  79. << "Expected input to have the same dimension as Result Type: "
  80. << spvOpcodeString(opcode);
  81. }
  82. if (!_.features().use_int8_type && (8 == _.GetBitWidth(result_type)))
  83. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  84. << "Invalid cast to 8-bit integer from a floating-point: "
  85. << spvOpcodeString(opcode);
  86. break;
  87. }
  88. case SpvOpConvertSToF:
  89. case SpvOpConvertUToF: {
  90. if (!_.IsFloatScalarType(result_type) &&
  91. !_.IsFloatVectorType(result_type) &&
  92. !_.IsFloatCooperativeMatrixType(result_type))
  93. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  94. << "Expected float scalar or vector type as Result Type: "
  95. << spvOpcodeString(opcode);
  96. const uint32_t input_type = _.GetOperandTypeId(inst, 2);
  97. if (!input_type ||
  98. (!_.IsIntScalarType(input_type) && !_.IsIntVectorType(input_type) &&
  99. !_.IsIntCooperativeMatrixType(input_type)))
  100. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  101. << "Expected input to be int scalar or vector: "
  102. << spvOpcodeString(opcode);
  103. if (_.IsCooperativeMatrixType(result_type) ||
  104. _.IsCooperativeMatrixType(input_type)) {
  105. spv_result_t ret =
  106. _.CooperativeMatrixShapesMatch(inst, result_type, input_type);
  107. if (ret != SPV_SUCCESS) return ret;
  108. } else {
  109. if (_.GetDimension(result_type) != _.GetDimension(input_type))
  110. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  111. << "Expected input to have the same dimension as Result Type: "
  112. << spvOpcodeString(opcode);
  113. }
  114. if (!_.features().use_int8_type && (8 == _.GetBitWidth(input_type)))
  115. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  116. << "Invalid cast to floating-point from an 8-bit integer: "
  117. << spvOpcodeString(opcode);
  118. break;
  119. }
  120. case SpvOpUConvert: {
  121. if (!_.IsUnsignedIntScalarType(result_type) &&
  122. !_.IsUnsignedIntVectorType(result_type) &&
  123. !_.IsUnsignedIntCooperativeMatrixType(result_type))
  124. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  125. << "Expected unsigned int scalar or vector type as Result Type: "
  126. << spvOpcodeString(opcode);
  127. const uint32_t input_type = _.GetOperandTypeId(inst, 2);
  128. if (!input_type ||
  129. (!_.IsIntScalarType(input_type) && !_.IsIntVectorType(input_type) &&
  130. !_.IsIntCooperativeMatrixType(input_type)))
  131. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  132. << "Expected input to be int scalar or vector: "
  133. << spvOpcodeString(opcode);
  134. if (_.IsCooperativeMatrixType(result_type) ||
  135. _.IsCooperativeMatrixType(input_type)) {
  136. spv_result_t ret =
  137. _.CooperativeMatrixShapesMatch(inst, result_type, input_type);
  138. if (ret != SPV_SUCCESS) return ret;
  139. } else {
  140. if (_.GetDimension(result_type) != _.GetDimension(input_type))
  141. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  142. << "Expected input to have the same dimension as Result Type: "
  143. << spvOpcodeString(opcode);
  144. }
  145. if (_.GetBitWidth(result_type) == _.GetBitWidth(input_type))
  146. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  147. << "Expected input to have different bit width from Result "
  148. "Type: "
  149. << spvOpcodeString(opcode);
  150. break;
  151. }
  152. case SpvOpSConvert: {
  153. if (!_.IsIntScalarType(result_type) && !_.IsIntVectorType(result_type) &&
  154. !_.IsIntCooperativeMatrixType(result_type))
  155. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  156. << "Expected int scalar or vector type as Result Type: "
  157. << spvOpcodeString(opcode);
  158. const uint32_t input_type = _.GetOperandTypeId(inst, 2);
  159. if (!input_type ||
  160. (!_.IsIntScalarType(input_type) && !_.IsIntVectorType(input_type) &&
  161. !_.IsIntCooperativeMatrixType(input_type)))
  162. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  163. << "Expected input to be int scalar or vector: "
  164. << spvOpcodeString(opcode);
  165. if (_.IsCooperativeMatrixType(result_type) ||
  166. _.IsCooperativeMatrixType(input_type)) {
  167. spv_result_t ret =
  168. _.CooperativeMatrixShapesMatch(inst, result_type, input_type);
  169. if (ret != SPV_SUCCESS) return ret;
  170. } else {
  171. if (_.GetDimension(result_type) != _.GetDimension(input_type))
  172. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  173. << "Expected input to have the same dimension as Result Type: "
  174. << spvOpcodeString(opcode);
  175. }
  176. if (_.GetBitWidth(result_type) == _.GetBitWidth(input_type))
  177. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  178. << "Expected input to have different bit width from Result "
  179. "Type: "
  180. << spvOpcodeString(opcode);
  181. break;
  182. }
  183. case SpvOpFConvert: {
  184. if (!_.IsFloatScalarType(result_type) &&
  185. !_.IsFloatVectorType(result_type) &&
  186. !_.IsFloatCooperativeMatrixType(result_type))
  187. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  188. << "Expected float scalar or vector type as Result Type: "
  189. << spvOpcodeString(opcode);
  190. const uint32_t input_type = _.GetOperandTypeId(inst, 2);
  191. if (!input_type || (!_.IsFloatScalarType(input_type) &&
  192. !_.IsFloatVectorType(input_type) &&
  193. !_.IsFloatCooperativeMatrixType(input_type)))
  194. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  195. << "Expected input to be float scalar or vector: "
  196. << spvOpcodeString(opcode);
  197. if (_.IsCooperativeMatrixType(result_type) ||
  198. _.IsCooperativeMatrixType(input_type)) {
  199. spv_result_t ret =
  200. _.CooperativeMatrixShapesMatch(inst, result_type, input_type);
  201. if (ret != SPV_SUCCESS) return ret;
  202. } else {
  203. if (_.GetDimension(result_type) != _.GetDimension(input_type))
  204. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  205. << "Expected input to have the same dimension as Result Type: "
  206. << spvOpcodeString(opcode);
  207. }
  208. if (_.GetBitWidth(result_type) == _.GetBitWidth(input_type))
  209. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  210. << "Expected input to have different bit width from Result "
  211. "Type: "
  212. << spvOpcodeString(opcode);
  213. break;
  214. }
  215. case SpvOpQuantizeToF16: {
  216. if ((!_.IsFloatScalarType(result_type) &&
  217. !_.IsFloatVectorType(result_type)) ||
  218. _.GetBitWidth(result_type) != 32)
  219. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  220. << "Expected 32-bit float scalar or vector type as Result Type: "
  221. << spvOpcodeString(opcode);
  222. const uint32_t input_type = _.GetOperandTypeId(inst, 2);
  223. if (input_type != result_type)
  224. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  225. << "Expected input type to be equal to Result Type: "
  226. << spvOpcodeString(opcode);
  227. break;
  228. }
  229. case SpvOpConvertPtrToU: {
  230. if (!_.IsUnsignedIntScalarType(result_type))
  231. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  232. << "Expected unsigned int scalar type as Result Type: "
  233. << spvOpcodeString(opcode);
  234. const uint32_t input_type = _.GetOperandTypeId(inst, 2);
  235. if (!_.IsPointerType(input_type))
  236. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  237. << "Expected input to be a pointer: " << spvOpcodeString(opcode);
  238. if (_.addressing_model() == SpvAddressingModelLogical)
  239. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  240. << "Logical addressing not supported: "
  241. << spvOpcodeString(opcode);
  242. if (_.addressing_model() ==
  243. SpvAddressingModelPhysicalStorageBuffer64EXT) {
  244. uint32_t input_storage_class = 0;
  245. uint32_t input_data_type = 0;
  246. _.GetPointerTypeInfo(input_type, &input_data_type,
  247. &input_storage_class);
  248. if (input_storage_class != SpvStorageClassPhysicalStorageBufferEXT)
  249. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  250. << "Pointer storage class must be PhysicalStorageBufferEXT: "
  251. << spvOpcodeString(opcode);
  252. }
  253. break;
  254. }
  255. case SpvOpSatConvertSToU:
  256. case SpvOpSatConvertUToS: {
  257. if (!_.IsIntScalarType(result_type) && !_.IsIntVectorType(result_type))
  258. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  259. << "Expected int scalar or vector type as Result Type: "
  260. << spvOpcodeString(opcode);
  261. const uint32_t input_type = _.GetOperandTypeId(inst, 2);
  262. if (!input_type ||
  263. (!_.IsIntScalarType(input_type) && !_.IsIntVectorType(input_type)))
  264. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  265. << "Expected int scalar or vector as input: "
  266. << spvOpcodeString(opcode);
  267. if (_.GetDimension(result_type) != _.GetDimension(input_type))
  268. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  269. << "Expected input to have the same dimension as Result Type: "
  270. << spvOpcodeString(opcode);
  271. break;
  272. }
  273. case SpvOpConvertUToPtr: {
  274. if (!_.IsPointerType(result_type))
  275. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  276. << "Expected Result Type to be a pointer: "
  277. << spvOpcodeString(opcode);
  278. const uint32_t input_type = _.GetOperandTypeId(inst, 2);
  279. if (!input_type || !_.IsIntScalarType(input_type))
  280. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  281. << "Expected int scalar as input: " << spvOpcodeString(opcode);
  282. if (_.addressing_model() == SpvAddressingModelLogical)
  283. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  284. << "Logical addressing not supported: "
  285. << spvOpcodeString(opcode);
  286. if (_.addressing_model() ==
  287. SpvAddressingModelPhysicalStorageBuffer64EXT) {
  288. uint32_t result_storage_class = 0;
  289. uint32_t result_data_type = 0;
  290. _.GetPointerTypeInfo(result_type, &result_data_type,
  291. &result_storage_class);
  292. if (result_storage_class != SpvStorageClassPhysicalStorageBufferEXT)
  293. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  294. << "Pointer storage class must be PhysicalStorageBufferEXT: "
  295. << spvOpcodeString(opcode);
  296. }
  297. break;
  298. }
  299. case SpvOpPtrCastToGeneric: {
  300. uint32_t result_storage_class = 0;
  301. uint32_t result_data_type = 0;
  302. if (!_.GetPointerTypeInfo(result_type, &result_data_type,
  303. &result_storage_class))
  304. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  305. << "Expected Result Type to be a pointer: "
  306. << spvOpcodeString(opcode);
  307. if (result_storage_class != SpvStorageClassGeneric)
  308. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  309. << "Expected Result Type to have storage class Generic: "
  310. << spvOpcodeString(opcode);
  311. const uint32_t input_type = _.GetOperandTypeId(inst, 2);
  312. uint32_t input_storage_class = 0;
  313. uint32_t input_data_type = 0;
  314. if (!_.GetPointerTypeInfo(input_type, &input_data_type,
  315. &input_storage_class))
  316. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  317. << "Expected input to be a pointer: " << spvOpcodeString(opcode);
  318. if (input_storage_class != SpvStorageClassWorkgroup &&
  319. input_storage_class != SpvStorageClassCrossWorkgroup &&
  320. input_storage_class != SpvStorageClassFunction)
  321. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  322. << "Expected input to have storage class Workgroup, "
  323. << "CrossWorkgroup or Function: " << spvOpcodeString(opcode);
  324. if (result_data_type != input_data_type)
  325. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  326. << "Expected input and Result Type to point to the same type: "
  327. << spvOpcodeString(opcode);
  328. break;
  329. }
  330. case SpvOpGenericCastToPtr: {
  331. uint32_t result_storage_class = 0;
  332. uint32_t result_data_type = 0;
  333. if (!_.GetPointerTypeInfo(result_type, &result_data_type,
  334. &result_storage_class))
  335. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  336. << "Expected Result Type to be a pointer: "
  337. << spvOpcodeString(opcode);
  338. if (result_storage_class != SpvStorageClassWorkgroup &&
  339. result_storage_class != SpvStorageClassCrossWorkgroup &&
  340. result_storage_class != SpvStorageClassFunction)
  341. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  342. << "Expected Result Type to have storage class Workgroup, "
  343. << "CrossWorkgroup or Function: " << spvOpcodeString(opcode);
  344. const uint32_t input_type = _.GetOperandTypeId(inst, 2);
  345. uint32_t input_storage_class = 0;
  346. uint32_t input_data_type = 0;
  347. if (!_.GetPointerTypeInfo(input_type, &input_data_type,
  348. &input_storage_class))
  349. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  350. << "Expected input to be a pointer: " << spvOpcodeString(opcode);
  351. if (input_storage_class != SpvStorageClassGeneric)
  352. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  353. << "Expected input to have storage class Generic: "
  354. << spvOpcodeString(opcode);
  355. if (result_data_type != input_data_type)
  356. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  357. << "Expected input and Result Type to point to the same type: "
  358. << spvOpcodeString(opcode);
  359. break;
  360. }
  361. case SpvOpGenericCastToPtrExplicit: {
  362. uint32_t result_storage_class = 0;
  363. uint32_t result_data_type = 0;
  364. if (!_.GetPointerTypeInfo(result_type, &result_data_type,
  365. &result_storage_class))
  366. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  367. << "Expected Result Type to be a pointer: "
  368. << spvOpcodeString(opcode);
  369. const uint32_t target_storage_class = inst->word(4);
  370. if (result_storage_class != target_storage_class)
  371. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  372. << "Expected Result Type to be of target storage class: "
  373. << spvOpcodeString(opcode);
  374. const uint32_t input_type = _.GetOperandTypeId(inst, 2);
  375. uint32_t input_storage_class = 0;
  376. uint32_t input_data_type = 0;
  377. if (!_.GetPointerTypeInfo(input_type, &input_data_type,
  378. &input_storage_class))
  379. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  380. << "Expected input to be a pointer: " << spvOpcodeString(opcode);
  381. if (input_storage_class != SpvStorageClassGeneric)
  382. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  383. << "Expected input to have storage class Generic: "
  384. << spvOpcodeString(opcode);
  385. if (result_data_type != input_data_type)
  386. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  387. << "Expected input and Result Type to point to the same type: "
  388. << spvOpcodeString(opcode);
  389. if (target_storage_class != SpvStorageClassWorkgroup &&
  390. target_storage_class != SpvStorageClassCrossWorkgroup &&
  391. target_storage_class != SpvStorageClassFunction)
  392. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  393. << "Expected target storage class to be Workgroup, "
  394. << "CrossWorkgroup or Function: " << spvOpcodeString(opcode);
  395. break;
  396. }
  397. case SpvOpBitcast: {
  398. const uint32_t input_type = _.GetOperandTypeId(inst, 2);
  399. if (!input_type)
  400. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  401. << "Expected input to have a type: " << spvOpcodeString(opcode);
  402. const bool result_is_pointer = _.IsPointerType(result_type);
  403. const bool result_is_int_scalar = _.IsIntScalarType(result_type);
  404. const bool input_is_pointer = _.IsPointerType(input_type);
  405. const bool input_is_int_scalar = _.IsIntScalarType(input_type);
  406. if (!result_is_pointer && !result_is_int_scalar &&
  407. !_.IsIntVectorType(result_type) &&
  408. !_.IsFloatScalarType(result_type) &&
  409. !_.IsFloatVectorType(result_type))
  410. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  411. << "Expected Result Type to be a pointer or int or float vector "
  412. << "or scalar type: " << spvOpcodeString(opcode);
  413. if (!input_is_pointer && !input_is_int_scalar &&
  414. !_.IsIntVectorType(input_type) && !_.IsFloatScalarType(input_type) &&
  415. !_.IsFloatVectorType(input_type))
  416. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  417. << "Expected input to be a pointer or int or float vector "
  418. << "or scalar: " << spvOpcodeString(opcode);
  419. if (result_is_pointer && !input_is_pointer && !input_is_int_scalar)
  420. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  421. << "Expected input to be a pointer or int scalar if Result Type "
  422. << "is pointer: " << spvOpcodeString(opcode);
  423. if (input_is_pointer && !result_is_pointer && !result_is_int_scalar)
  424. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  425. << "Pointer can only be converted to another pointer or int "
  426. << "scalar: " << spvOpcodeString(opcode);
  427. if (!result_is_pointer && !input_is_pointer) {
  428. const uint32_t result_size =
  429. _.GetBitWidth(result_type) * _.GetDimension(result_type);
  430. const uint32_t input_size =
  431. _.GetBitWidth(input_type) * _.GetDimension(input_type);
  432. if (result_size != input_size)
  433. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  434. << "Expected input to have the same total bit width as "
  435. << "Result Type: " << spvOpcodeString(opcode);
  436. }
  437. break;
  438. }
  439. default:
  440. break;
  441. }
  442. return SPV_SUCCESS;
  443. }
  444. } // namespace val
  445. } // namespace spvtools