summaryrefslogtreecommitdiff
path: root/src/mesa/drivers/dri/r300/compiler/radeon_opcodes.h
blob: b58688206116b7785b9aefc581d23fbda8e9ae18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/*
 * Copyright (C) 2009 Nicolai Haehnle.
 *
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial
 * portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */

#ifndef RADEON_OPCODES_H
#define RADEON_OPCODES_H

#include <assert.h>

/**
 * Opcodes understood by the Radeon compiler.
 */
typedef enum {
	RC_OPCODE_NOP = 0,
	RC_OPCODE_ILLEGAL_OPCODE,

	/** vec4 instruction: dst.c = abs(src0.c); */
	RC_OPCODE_ABS,

	/** vec4 instruction: dst.c = src0.c + src1.c; */
	RC_OPCODE_ADD,

	/** special instruction: load address register
	 * dst.x = floor(src.x), where dst must be an address register */
	RC_OPCODE_ARL,

	/** vec4 instruction: dst.c = ceil(src0.c) */
	RC_OPCODE_CEIL,

	/** vec4 instruction: dst.c = clamp(src0.c, src1.c, src2.c) */
	RC_OPCODE_CLAMP,

	/** vec4 instruction: dst.c = src0.c < 0.0 ? src1.c : src2.c */
	RC_OPCODE_CMP,

	/** vec4 instruction: dst.c = src2.c > 0.5 ? src0.c : src1.c */
	RC_OPCODE_CND,

	/** scalar instruction: dst = cos(src0.x) */
	RC_OPCODE_COS,

	/** special instruction: take vec4 partial derivative in X direction
	 * dst.c = d src0.c / dx */
	RC_OPCODE_DDX,

	/** special instruction: take vec4 partial derivative in Y direction
	 * dst.c = d src0.c / dy */
	RC_OPCODE_DDY,

	/** scalar instruction: dst = src0.x*src1.x + src0.y*src1.y */
	RC_OPCODE_DP2,

	/** scalar instruction: dst = src0.x*src1.x + src0.y*src1.y + src0.z*src1.z */
	RC_OPCODE_DP3,

	/** scalar instruction: dst = src0.x*src1.x + src0.y*src1.y + src0.z*src1.z + src0.w*src1.w */
	RC_OPCODE_DP4,

	/** scalar instruction: dst = src0.x*src1.x + src0.y*src1.y + src0.z*src1.z + src1.w */
	RC_OPCODE_DPH,

	/** special instruction, see ARB_fragment_program */
	RC_OPCODE_DST,

	/** scalar instruction: dst = 2**src0.x */
	RC_OPCODE_EX2,

	/** special instruction, see ARB_vertex_program */
	RC_OPCODE_EXP,

	/** vec4 instruction: dst.c = floor(src0.c) */
	RC_OPCODE_FLR,

	/** vec4 instruction: dst.c = src0.c - floor(src0.c) */
	RC_OPCODE_FRC,

	/** special instruction: stop execution if any component of src0 is negative */
	RC_OPCODE_KIL,

	/** scalar instruction: dst = log_2(src0.x) */
	RC_OPCODE_LG2,

	/** special instruction, see ARB_vertex_program */
	RC_OPCODE_LIT,

	/** special instruction, see ARB_vertex_program */
	RC_OPCODE_LOG,

	/** vec4 instruction: dst.c = src0.c*src1.c + (1 - src0.c)*src2.c */
	RC_OPCODE_LRP,

	/** vec4 instruction: dst.c = src0.c*src1.c + src2.c */
	RC_OPCODE_MAD,

	/** vec4 instruction: dst.c = max(src0.c, src1.c) */
	RC_OPCODE_MAX,

	/** vec4 instruction: dst.c = min(src0.c, src1.c) */
	RC_OPCODE_MIN,

	/** vec4 instruction: dst.c = src0.c */
	RC_OPCODE_MOV,

	/** vec4 instruction: dst.c = src0.c*src1.c */
	RC_OPCODE_MUL,

	/** scalar instruction: dst = src0.x ** src1.x */
	RC_OPCODE_POW,

	/** scalar instruction: dst = 1 / src0.x */
	RC_OPCODE_RCP,

	/** scalar instruction: dst = 1 / sqrt(src0.x) */
	RC_OPCODE_RSQ,

	/** special instruction, see ARB_fragment_program */
	RC_OPCODE_SCS,

	/** vec4 instruction: dst.c = (src0.c == src1.c) ? 1.0 : 0.0 */
	RC_OPCODE_SEQ,

	/** vec4 instruction: dst.c = 0.0 */
	RC_OPCODE_SFL,

	/** vec4 instruction: dst.c = (src0.c >= src1.c) ? 1.0 : 0.0 */
	RC_OPCODE_SGE,

	/** vec4 instruction: dst.c = (src0.c > src1.c) ? 1.0 : 0.0 */
	RC_OPCODE_SGT,

	/** scalar instruction: dst = sin(src0.x) */
	RC_OPCODE_SIN,

	/** vec4 instruction: dst.c = (src0.c <= src1.c) ? 1.0 : 0.0 */
	RC_OPCODE_SLE,

	/** vec4 instruction: dst.c = (src0.c < src1.c) ? 1.0 : 0.0 */
	RC_OPCODE_SLT,

	/** vec4 instruction: dst.c = (src0.c != src1.c) ? 1.0 : 0.0 */
	RC_OPCODE_SNE,

	/** vec4 instruction: dst.c = (src0.c < 0 ?) -1 : ((src0.c > 0) : 1 : 0) */
	RC_OPCODE_SSG,

	/** vec4 instruction: dst.c = src0.c - src1.c */
	RC_OPCODE_SUB,

	/** vec4 instruction: dst.c = src0.c */
	RC_OPCODE_SWZ,

	/** special instruction, see ARB_fragment_program */
	RC_OPCODE_XPD,

	RC_OPCODE_TEX,
	RC_OPCODE_TXB,
	RC_OPCODE_TXD,
	RC_OPCODE_TXL,
	RC_OPCODE_TXP,

	/** branch instruction:
	 * If src0.x != 0.0, continue with the next instruction;
	 * otherwise, jump to matching RC_OPCODE_ELSE or RC_OPCODE_ENDIF.
	 */
	RC_OPCODE_IF,

	/** branch instruction: jump to matching RC_OPCODE_ENDIF */
	RC_OPCODE_ELSE,

	/** branch instruction: has no effect */
	RC_OPCODE_ENDIF,
	
	RC_OPCODE_BGNLOOP,

	RC_OPCODE_BRK,

	RC_OPCODE_ENDLOOP,

	RC_OPCODE_CONT,

	/** special instruction, used in R300-R500 fragment program pair instructions
	 * indicates that the result of the alpha operation shall be replicated
	 * across all other channels */
	RC_OPCODE_REPL_ALPHA,

	/** special instruction, used in R300-R500 fragment programs
	 * to indicate the start of a block of texture instructions that
	 * can run simultaneously. */
	RC_OPCODE_BEGIN_TEX,

	/** Stop execution of the shader (GLSL discard) */
	RC_OPCODE_KILP,

	MAX_RC_OPCODE
} rc_opcode;


struct rc_opcode_info {
	rc_opcode Opcode;
	const char * Name;

	/** true if the instruction reads from a texture.
	 *
	 * \note This is false for the KIL instruction, even though KIL is
	 * a texture instruction from a hardware point of view. */
	unsigned int HasTexture:1;

	unsigned int NumSrcRegs:2;
	unsigned int HasDstReg:1;

	/** true if this instruction affects control flow */
	unsigned int IsFlowControl:1;

	/** true if this is a vector instruction that operates on components in parallel
	 * without any cross-component interaction */
	unsigned int IsComponentwise:1;

	/** true if this instruction sources only its operands X components
	 * to compute one result which is smeared across all output channels */
	unsigned int IsStandardScalar:1;
};

extern struct rc_opcode_info rc_opcodes[MAX_RC_OPCODE];

static inline const struct rc_opcode_info * rc_get_opcode_info(rc_opcode opcode)
{
	assert((unsigned int)opcode < MAX_RC_OPCODE);
	assert(rc_opcodes[opcode].Opcode == opcode);

	return &rc_opcodes[opcode];
}

struct rc_instruction;

void rc_compute_sources_for_writemask(
		const struct rc_instruction *inst,
		unsigned int writemask,
		unsigned int *srcmasks);

#endif /* RADEON_OPCODES_H */