blob: 9f00b4a1a78c8365f5189bfe6cc99799e754cca2 [file] [log] [blame]
Dejan Mircevskib6fe02f2016-01-07 13:44:22 -05001// Copyright (c) 2015-2016 The Khronos Group Inc.
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01002//
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 Neto9f79d782015-10-27 16:27:05 -040027#ifndef LIBSPIRV_OPCODE_H_
28#define LIBSPIRV_OPCODE_H_
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010029
David Netob5dc8fc2015-10-06 16:22:00 -040030#include "instruction.h"
David Neto5a703352016-02-17 14:44:00 -050031#include "spirv-tools/libspirv.h"
Lei Zhang10dba912016-04-14 14:05:53 -040032#include "spirv/1.1/spirv.h"
Lei Zhang7a222e42015-11-11 12:40:25 -050033#include "table.h"
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010034
Lei Zhangaf9906e2015-11-16 10:48:43 -050035// 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 Zhang1a0334e2015-11-02 09:41:20 -050041const char* spvGeneratorStr(uint32_t generator);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010042
Lei Zhangaf9906e2015-11-16 10:48:43 -050043// Combines word_count and opcode enumerant in single word.
44uint32_t spvOpcodeMake(uint16_t word_count, SpvOp opcode);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010045
Lei Zhangaf9906e2015-11-16 10:48:43 -050046// Splits word into into two constituent parts: word_count and opcode.
Lei Zhang6fa3f8a2016-03-31 17:26:31 -040047void spvOpcodeSplit(const uint32_t word, uint16_t* word_count,
48 uint16_t* opcode);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010049
Lei Zhangaf9906e2015-11-16 10:48:43 -050050// 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)83e5a292015-05-22 18:26:19 +010052spv_result_t spvOpcodeTableNameLookup(const spv_opcode_table table,
Lei Zhangaf9906e2015-11-16 10:48:43 -050053 const char* name, spv_opcode_desc* entry);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010054
Lei Zhangaf9906e2015-11-16 10:48:43 -050055// 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)83e5a292015-05-22 18:26:19 +010057spv_result_t spvOpcodeTableValueLookup(const spv_opcode_table table,
Lei Zhangb36e7042015-10-28 13:40:52 -040058 const SpvOp opcode,
Lei Zhangaf9906e2015-11-16 10:48:43 -050059 spv_opcode_desc* entry);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010060
Lei Zhangaf9906e2015-11-16 10:48:43 -050061// 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.
63int32_t spvOpcodeRequiresCapabilities(spv_opcode_desc opcode);
Lei Zhangdfc50082015-08-21 11:50:55 -040064
Lei Zhangaf9906e2015-11-16 10:48:43 -050065// 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 Zhang1a0334e2015-11-02 09:41:20 -050069void spvInstructionCopy(const uint32_t* words, const SpvOp opcode,
Lei Zhangaf9906e2015-11-16 10:48:43 -050070 const uint16_t word_count,
71 const spv_endianness_t endian, spv_instruction_t* inst);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010072
Lei Zhangaf9906e2015-11-16 10:48:43 -050073// Gets the name of an instruction, without the "Op" prefix.
Lei Zhang1a0334e2015-11-02 09:41:20 -050074const char* spvOpcodeString(const SpvOp opcode);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010075
Lei Zhangaf9906e2015-11-16 10:48:43 -050076// Determine if the given opcode is a scalar type. Returns zero if false,
77// non-zero otherwise.
Lei Zhangb36e7042015-10-28 13:40:52 -040078int32_t spvOpcodeIsScalarType(const SpvOp opcode);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010079
Lei Zhangaf9906e2015-11-16 10:48:43 -050080// Determines if the given opcode is a constant. Returns zero if false, non-zero
81// otherwise.
Lei Zhangb36e7042015-10-28 13:40:52 -040082int32_t spvOpcodeIsConstant(const SpvOp opcode);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010083
Lei Zhangaf9906e2015-11-16 10:48:43 -050084// Determines if the given opcode is a composite type. Returns zero if false,
85// non-zero otherwise.
Lei Zhangb36e7042015-10-28 13:40:52 -040086int32_t spvOpcodeIsComposite(const SpvOp opcode);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010087
Florian Ziesche66fcb452016-03-02 22:17:54 +010088// Determines if the given opcode results in a pointer when using the logical
89// addressing model. Returns zero if false, non-zero otherwise.
90int32_t spvOpcodeReturnsLogicalPointer(const SpvOp opcode);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010091
Lei Zhangaf9906e2015-11-16 10:48:43 -050092// Determines if the given opcode generates a type. Returns zero if false,
93// non-zero otherwise.
94int32_t spvOpcodeGeneratesType(SpvOp opcode);
Andrew Woloszyn537e7762015-09-29 11:28:34 -040095
David Neto9f79d782015-10-27 16:27:05 -040096#endif // LIBSPIRV_OPCODE_H_