Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 1 | // Copyright (c) 2015 The Khronos Group Inc. |
| 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" |
Lei Zhang | 923f6c1 | 2015-11-11 12:45:23 -0500 | [diff] [blame] | 31 | #include "libspirv/libspirv.h" |
Lei Zhang | 7a222e4 | 2015-11-11 12:40:25 -0500 | [diff] [blame] | 32 | #include "table.h" |
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 | // Returns the name of a registered SPIR-V generator as a null-terminated |
| 35 | // string. If the generator is not known, then returns the string "Unknown". |
| 36 | // The generator parameter should be most significant 16-bits of the generator |
| 37 | // word in the SPIR-V module header. |
| 38 | // |
| 39 | // 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] | 40 | const char* spvGeneratorStr(uint32_t generator); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 41 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame^] | 42 | // Combines word_count and opcode enumerant in single word. |
| 43 | uint32_t spvOpcodeMake(uint16_t word_count, SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 44 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame^] | 45 | // Splits word into into two constituent parts: word_count and opcode. |
| 46 | void spvOpcodeSplit(const uint32_t word, uint16_t* word_count, SpvOp* opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 47 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame^] | 48 | // Finds the named opcode in the given opcode table. On success, returns |
| 49 | // 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] | 50 | spv_result_t spvOpcodeTableNameLookup(const spv_opcode_table table, |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame^] | 51 | const char* name, spv_opcode_desc* entry); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 52 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame^] | 53 | // Finds the opcode by enumerant in the given opcode table. On success, returns |
| 54 | // 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] | 55 | spv_result_t spvOpcodeTableValueLookup(const spv_opcode_table table, |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 56 | const SpvOp opcode, |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame^] | 57 | spv_opcode_desc* entry); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 58 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame^] | 59 | // Determines if the opcode has capability requirements. Returns zero if false, |
| 60 | // non-zero otherwise. This function does not check if the given entry is valid. |
| 61 | int32_t spvOpcodeRequiresCapabilities(spv_opcode_desc opcode); |
Lei Zhang | dfc5008 | 2015-08-21 11:50:55 -0400 | [diff] [blame] | 62 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame^] | 63 | // Copies an instruction's word and fixes the endianness to host native. The |
| 64 | // source instruction's stream/opcode/endianness is in the words/opcode/endian |
| 65 | // parameter. The word_count parameter specifies the number of words to copy. |
| 66 | // Writes copied instruction into *inst. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 67 | void spvInstructionCopy(const uint32_t* words, const SpvOp opcode, |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame^] | 68 | const uint16_t word_count, |
| 69 | const spv_endianness_t endian, spv_instruction_t* inst); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 70 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame^] | 71 | // Gets the name of an instruction, without the "Op" prefix. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 72 | const char* spvOpcodeString(const SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 73 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame^] | 74 | // Determine if the given opcode is a scalar type. Returns zero if false, |
| 75 | // non-zero otherwise. |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 76 | int32_t spvOpcodeIsScalarType(const SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 77 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame^] | 78 | // Determines if the given opcode is a constant. Returns zero if false, non-zero |
| 79 | // otherwise. |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 80 | int32_t spvOpcodeIsConstant(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 is a composite type. Returns zero if false, |
| 83 | // non-zero otherwise. |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 84 | int32_t spvOpcodeIsComposite(const SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 85 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame^] | 86 | // Deep equal comparison of type declaration instructions. Returns zero if |
| 87 | // false, non-zero otherwise. |
| 88 | int32_t spvOpcodeAreTypesEqual(const spv_instruction_t* type_inst0, |
| 89 | const spv_instruction_t* type_inst1); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 90 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame^] | 91 | // Determines if the given opcode results in a pointer. Returns zero if false, |
| 92 | // non-zero otherwise. |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 93 | int32_t spvOpcodeIsPointer(const SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 94 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame^] | 95 | // Determines if the given opcode results in an instantation of a non-void type. |
| 96 | // Returns zero if false, non-zero otherwise. |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 97 | int32_t spvOpcodeIsObject(const SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 98 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame^] | 99 | // Determines if the scalar type opcode is nullable. Returns zero if false, |
| 100 | // non-zero otherwise. |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 101 | int32_t spvOpcodeIsBasicTypeNullable(SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 102 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame^] | 103 | // Determines if an instruction is in a basic block. The first_inst parameter |
| 104 | // specifies the first instruction in the stream, while the inst parameter |
| 105 | // specifies the current instruction. Returns zero if false, non-zero otherwise. |
| 106 | int32_t spvInstructionIsInBasicBlock(const spv_instruction_t* first_inst, |
| 107 | const spv_instruction_t* inst); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 108 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame^] | 109 | // Determines if the given opcode contains a value. Returns zero if false, |
| 110 | // non-zero otherwise. |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 111 | int32_t spvOpcodeIsValue(SpvOp opcode); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 112 | |
Lei Zhang | af9906e | 2015-11-16 10:48:43 -0500 | [diff] [blame^] | 113 | // Determines if the given opcode generates a type. Returns zero if false, |
| 114 | // non-zero otherwise. |
| 115 | int32_t spvOpcodeGeneratesType(SpvOp opcode); |
Andrew Woloszyn | 537e776 | 2015-09-29 11:28:34 -0400 | [diff] [blame] | 116 | |
David Neto | 9f79d78 | 2015-10-27 16:27:05 -0400 | [diff] [blame] | 117 | #endif // LIBSPIRV_OPCODE_H_ |