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 | // |
| 3 | // Permission is hereby granted, free of charge, to any person obtaining a |
| 4 | // copy of this software and/or associated documentation files (the |
| 5 | // "Materials"), to deal in the Materials without restriction, including |
| 6 | // without limitation the rights to use, copy, modify, merge, publish, |
| 7 | // distribute, sublicense, and/or sell copies of the Materials, and to |
| 8 | // permit persons to whom the Materials are furnished to do so, subject to |
| 9 | // the following conditions: |
| 10 | // |
| 11 | // The above copyright notice and this permission notice shall be included |
| 12 | // in all copies or substantial portions of the Materials. |
| 13 | // |
| 14 | // MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS |
| 15 | // KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS |
| 16 | // SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT |
| 17 | // https://www.khronos.org/registry/ |
| 18 | // |
| 19 | // THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 21 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 22 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 23 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 24 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 25 | // MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 26 | |
David Neto | 9f79d78 | 2015-10-27 16:27:05 -0400 | [diff] [blame] | 27 | #ifndef LIBSPIRV_OPCODE_H_ |
| 28 | #define LIBSPIRV_OPCODE_H_ |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 29 | |
David Neto | b5dc8fc | 2015-10-06 16:22:00 -0400 | [diff] [blame] | 30 | #include "instruction.h" |
David Neto | 5a70335 | 2016-02-17 14:44:00 -0500 | [diff] [blame] | 31 | #include "spirv-tools/libspirv.h" |
Lei Zhang | 10dba91 | 2016-04-14 14:05:53 -0400 | [diff] [blame^] | 32 | #include "spirv/1.1/spirv.h" |
Lei Zhang | 7a222e4 | 2015-11-11 12:40:25 -0500 | [diff] [blame] | 33 | #include "table.h" |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 34 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 35 | // Returns the name of a registered SPIR-V generator as a null-terminated |
| 36 | // string. If the generator is not known, then returns the string "Unknown". |
| 37 | // The generator parameter should be most significant 16-bits of the generator |
| 38 | // word in the SPIR-V module header. |
| 39 | // |
| 40 | // 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] | 41 | const char* spvGeneratorStr(uint32_t generator); |
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 | // Combines word_count and opcode enumerant in single word. |
| 44 | uint32_t spvOpcodeMake(uint16_t word_count, SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 45 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 46 | // Splits word into into two constituent parts: word_count and opcode. |
Lei Zhang | 6fa3f8a | 2016-03-31 17:26:31 -0400 | [diff] [blame] | 47 | void spvOpcodeSplit(const uint32_t word, uint16_t* word_count, |
| 48 | uint16_t* opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 49 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 50 | // Finds the named opcode in the given opcode table. On success, returns |
| 51 | // 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] | 52 | spv_result_t spvOpcodeTableNameLookup(const spv_opcode_table table, |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 53 | const char* name, spv_opcode_desc* entry); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 54 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 55 | // Finds the opcode by enumerant in the given opcode table. On success, returns |
| 56 | // 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] | 57 | spv_result_t spvOpcodeTableValueLookup(const spv_opcode_table table, |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 58 | const SpvOp opcode, |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 59 | spv_opcode_desc* entry); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 60 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 61 | // Determines if the opcode has capability requirements. Returns zero if false, |
| 62 | // non-zero otherwise. This function does not check if the given entry is valid. |
| 63 | int32_t spvOpcodeRequiresCapabilities(spv_opcode_desc opcode); |
Lei Zhang | dfc5008 | 2015-08-21 11:50:55 -0400 | [diff] [blame] | 64 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 65 | // Copies an instruction's word and fixes the endianness to host native. The |
| 66 | // source instruction's stream/opcode/endianness is in the words/opcode/endian |
| 67 | // parameter. The word_count parameter specifies the number of words to copy. |
| 68 | // Writes copied instruction into *inst. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 69 | void spvInstructionCopy(const uint32_t* words, const SpvOp opcode, |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 70 | const uint16_t word_count, |
| 71 | const spv_endianness_t endian, spv_instruction_t* inst); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 72 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 73 | // Gets the name of an instruction, without the "Op" prefix. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 74 | const char* spvOpcodeString(const SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 75 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 76 | // Determine if the given opcode is a scalar type. Returns zero if false, |
| 77 | // non-zero otherwise. |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 78 | int32_t spvOpcodeIsScalarType(const SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 79 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 80 | // Determines if the given opcode is a constant. Returns zero if false, non-zero |
| 81 | // otherwise. |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 82 | int32_t spvOpcodeIsConstant(const SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 83 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 84 | // Determines if the given opcode is a composite type. Returns zero if false, |
| 85 | // non-zero otherwise. |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 86 | int32_t spvOpcodeIsComposite(const SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 87 | |
Florian Ziesche | 66fcb45 | 2016-03-02 22:17:54 +0100 | [diff] [blame] | 88 | // Determines if the given opcode results in a pointer when using the logical |
| 89 | // addressing model. Returns zero if false, non-zero otherwise. |
| 90 | int32_t spvOpcodeReturnsLogicalPointer(const SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 91 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame] | 92 | // Determines if the given opcode generates a type. Returns zero if false, |
| 93 | // non-zero otherwise. |
| 94 | int32_t spvOpcodeGeneratesType(SpvOp opcode); |
Andrew Woloszyn | 537e776 | 2015-09-29 11:28:34 -0400 | [diff] [blame] | 95 | |
David Neto | 9f79d78 | 2015-10-27 16:27:05 -0400 | [diff] [blame] | 96 | #endif // LIBSPIRV_OPCODE_H_ |