Dejan Mircevski | b6fe02f | 2016-01-07 13:44:22 -0500 | [diff] [blame] | 1 | // Copyright (c) 2015-2016 The Khronos Group Inc. |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 2 | // |
David Neto | 9fc8658 | 2016-09-01 15:33:59 -0400 | [diff] [blame] | 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 |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 6 | // |
David Neto | 9fc8658 | 2016-09-01 15:33:59 -0400 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 8 | // |
David Neto | 9fc8658 | 2016-09-01 15:33:59 -0400 | [diff] [blame] | 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. |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 14 | |
David Neto | 9f79d78 | 2015-10-27 16:27:05 -0400 | [diff] [blame] | 15 | #ifndef LIBSPIRV_OPCODE_H_ |
| 16 | #define LIBSPIRV_OPCODE_H_ |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 17 | |
David Neto | b5dc8fc | 2015-10-06 16:22:00 -0400 | [diff] [blame] | 18 | #include "instruction.h" |
David Neto | 5a70335 | 2016-02-17 14:44:00 -0500 | [diff] [blame] | 19 | #include "spirv-tools/libspirv.h" |
Lei Zhang | 10dba91 | 2016-04-14 14:05:53 -0400 | [diff] [blame] | 20 | #include "spirv/1.1/spirv.h" |
Lei Zhang | 7a222e4 | 2015-11-11 12:40:25 -0500 | [diff] [blame] | 21 | #include "table.h" |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 22 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 23 | // Returns the name of a registered SPIR-V generator as a null-terminated |
| 24 | // string. If the generator is not known, then returns the string "Unknown". |
| 25 | // The generator parameter should be most significant 16-bits of the generator |
| 26 | // word in the SPIR-V module header. |
| 27 | // |
| 28 | // See the registry at https://www.khronos.org/registry/spir-v/api/spir-v.xml. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 29 | const char* spvGeneratorStr(uint32_t generator); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 30 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 31 | // Combines word_count and opcode enumerant in single word. |
| 32 | uint32_t spvOpcodeMake(uint16_t word_count, SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 33 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 34 | // Splits word into into two constituent parts: word_count and opcode. |
Lei Zhang | 6fa3f8a | 2016-03-31 17:26:31 -0400 | [diff] [blame] | 35 | void spvOpcodeSplit(const uint32_t word, uint16_t* word_count, |
| 36 | uint16_t* opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 37 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 38 | // Finds the named opcode in the given opcode table. On success, returns |
| 39 | // SPV_SUCCESS and writes a handle of the table entry into *entry. |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 40 | spv_result_t spvOpcodeTableNameLookup(const spv_opcode_table table, |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 41 | const char* name, spv_opcode_desc* entry); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 42 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 43 | // Finds the opcode by enumerant in the given opcode table. On success, returns |
| 44 | // SPV_SUCCESS and writes a handle of the table entry into *entry. |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 45 | spv_result_t spvOpcodeTableValueLookup(const spv_opcode_table table, |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 46 | const SpvOp opcode, |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 47 | spv_opcode_desc* entry); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 48 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 49 | // Copies an instruction's word and fixes the endianness to host native. The |
| 50 | // source instruction's stream/opcode/endianness is in the words/opcode/endian |
| 51 | // parameter. The word_count parameter specifies the number of words to copy. |
| 52 | // Writes copied instruction into *inst. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 53 | void spvInstructionCopy(const uint32_t* words, const SpvOp opcode, |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 54 | const uint16_t word_count, |
| 55 | const spv_endianness_t endian, spv_instruction_t* inst); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 56 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 57 | // Gets the name of an instruction, without the "Op" prefix. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 58 | const char* spvOpcodeString(const SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 59 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 60 | // Determine if the given opcode is a scalar type. Returns zero if false, |
| 61 | // non-zero otherwise. |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 62 | int32_t spvOpcodeIsScalarType(const SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 63 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 64 | // Determines if the given opcode is a constant. Returns zero if false, non-zero |
| 65 | // otherwise. |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 66 | int32_t spvOpcodeIsConstant(const SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 67 | |
David Neto | 1f3fb50 | 2016-09-14 11:57:20 -0400 | [diff] [blame] | 68 | // Returns true if the given opcode is a constant or undef. |
| 69 | bool spvOpcodeIsConstantOrUndef(const SpvOp opcode); |
| 70 | |
Aliya Pazylbekova | edb5264 | 2017-02-24 20:43:28 -0500 | [diff] [blame^] | 71 | // Returns true if the given opcode is a scalar specialization constant. |
| 72 | bool spvOpcodeIsScalarSpecConstant(const SpvOp opcode); |
| 73 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 74 | // Determines if the given opcode is a composite type. Returns zero if false, |
| 75 | // non-zero otherwise. |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 76 | int32_t spvOpcodeIsComposite(const SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 77 | |
Florian Ziesche | 66fcb45 | 2016-03-02 22:17:54 +0100 | [diff] [blame] | 78 | // Determines if the given opcode results in a pointer when using the logical |
| 79 | // addressing model. Returns zero if false, non-zero otherwise. |
| 80 | int32_t spvOpcodeReturnsLogicalPointer(const SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 81 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 82 | // Determines if the given opcode generates a type. Returns zero if false, |
| 83 | // non-zero otherwise. |
| 84 | int32_t spvOpcodeGeneratesType(SpvOp opcode); |
Andrew Woloszyn | 537e776 | 2015-09-29 11:28:34 -0400 | [diff] [blame] | 85 | |
David Neto | 9f79d78 | 2015-10-27 16:27:05 -0400 | [diff] [blame] | 86 | #endif // LIBSPIRV_OPCODE_H_ |