xref: /aosp_15_r20/external/mesa3d/src/compiler/isaspec/isaspec_decode_decl.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2020 Google, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 /* This file should not be included directly. Instead, it is included as part
25  * of the header file generated by isaspec/decode.py
26  */
27 
28 #include <stdbool.h>
29 #include <stdint.h>
30 
31 /*
32  * Defines the tables which are generated from xml for disassembly
33  */
34 
35 struct decode_scope;
36 struct isa_bitset;
37 
38 /**
39  * Table of enum values
40  */
41 struct isa_enum {
42 	unsigned num_values;
43 	struct {
44 		unsigned val;
45 		const char *display;
46 	} values[];
47 };
48 
49 /**
50  * An expression used to for conditional overrides, derived fields, etc
51  */
52 typedef uint64_t (*isa_expr_t)(struct decode_scope *scope);
53 
54 /**
55  * For bitset fields, there are some cases where we want to "remap" field
56  * names, essentially allowing one to parameterize a nested bitset when
57  * it resolves fields in an enclosing bitset.
58  */
59 struct isa_field_params {
60 	unsigned num_params;
61 	struct {
62 		const char *name;
63 		const char *as;
64 	} params[];
65 };
66 
67 struct decode_scope;
68 
69 /**
70  * Description of a single field within a bitset case.
71  */
72 struct isa_field {
73 	const char *name;
74 	isa_expr_t expr;       /* for virtual "derived" fields */
75 	unsigned low;
76 	unsigned high;
77 	enum {
78 		/* Basic types: */
79 		TYPE_BRANCH,   /* relative branch target, like INT but optional labeling*/
80 		TYPE_ABSBRANCH,   /* absolute branch target */
81 		TYPE_INT,
82 		TYPE_UINT,
83 		TYPE_HEX,
84 		TYPE_OFFSET,   /* Like INT but formated with +/- or omitted if ==0 */
85 		TYPE_UOFFSET,  /* Like UINT but formated with + or omitted if ==0 */
86 		TYPE_FLOAT,
87 		TYPE_BOOL,
88 		TYPE_BOOL_INV, /* Like BOOL but inverted */
89 		TYPE_ENUM,
90 
91 		/* For fields that must be printed via a user-provided callback */
92 		TYPE_CUSTOM,
93 
94 		/* To assert a certain value in a given range of bits.. not
95 		 * used for pattern matching, but allows an override to specify
96 		 * that a certain bitpattern in some "unused" bits is expected
97 		 */
98 		TYPE_ASSERT,
99 
100 		/* For fields that are decoded with another bitset hierarchy: */
101 		TYPE_BITSET,
102 	} type;
103 	union {
104 		const struct isa_bitset **bitsets;  /* if type==BITSET */
105 		bitmask_t val;                      /* if type==ASSERT */
106 		const struct isa_enum *enums;       /* if type==ENUM */
107 		const char *display;                /* if type==BOOL */
108 		bool call;                          /* if type==(BRANCH|ABSBRANCH) */
109 	};
110 
111 	/**
112 	 * type==BITSET fields can also optionally provide remapping for
113 	 * field names
114 	 */
115 	const struct isa_field_params *params;
116 };
117 
118 /**
119  * A bitset consists of N "cases", with the last one (with case->expr==NULL)
120  * being the default.
121  *
122  * When resolving a field, display template string, etc, all the cases with
123  * an expression that evaluates to non-zero are consider, falling back to
124  * the last (default) case.
125  */
126 struct isa_case {
127 	isa_expr_t expr;
128 	const char *display;
129 	unsigned num_fields;
130 	struct isa_field fields[];
131 };
132 
133 struct isa_field_decode {
134 	const char *name;
135 	void (*decode)(void *out, struct decode_scope *scope, uint64_t val);
136 };
137 
138 /**
139  * An individual bitset, the leaves of a bitset inheritance hiearchy will
140  * have the match and mask to match a single instruction (or arbitrary
141  * bit-pattern) against.
142  */
143 struct isa_bitset {
144 	const struct isa_bitset *parent;
145 	const char *name;
146 	struct {
147 		unsigned min;
148 		unsigned max;
149 	} gen;
150 	bitmask_t match;
151 	bitmask_t dontcare;
152 	bitmask_t mask;
153 	void (*decode)(void *out, struct decode_scope *scope);
154 	unsigned num_decode_fields;
155 	const struct isa_field_decode *decode_fields;
156 	unsigned num_cases;
157 	const struct isa_case *cases[];
158 };
159