2 * Copyright (C) 2009 Nicolai Haehnle.
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include "radeon_opcodes.h"
29 #include "radeon_program.h"
31 #include "radeon_program_constants.h"
33 struct rc_opcode_info rc_opcodes
[MAX_RC_OPCODE
] = {
35 .Opcode
= RC_OPCODE_NOP
,
39 .Opcode
= RC_OPCODE_ILLEGAL_OPCODE
,
40 .Name
= "ILLEGAL OPCODE"
43 .Opcode
= RC_OPCODE_ABS
,
50 .Opcode
= RC_OPCODE_ADD
,
57 .Opcode
= RC_OPCODE_ARL
,
63 .Opcode
= RC_OPCODE_CEIL
,
70 .Opcode
= RC_OPCODE_CMP
,
77 .Opcode
= RC_OPCODE_COS
,
84 .Opcode
= RC_OPCODE_DDX
,
91 .Opcode
= RC_OPCODE_DDY
,
98 .Opcode
= RC_OPCODE_DP2
,
104 .Opcode
= RC_OPCODE_DP3
,
110 .Opcode
= RC_OPCODE_DP4
,
116 .Opcode
= RC_OPCODE_DPH
,
122 .Opcode
= RC_OPCODE_DST
,
128 .Opcode
= RC_OPCODE_EX2
,
132 .IsStandardScalar
= 1
135 .Opcode
= RC_OPCODE_EXP
,
141 .Opcode
= RC_OPCODE_FLR
,
148 .Opcode
= RC_OPCODE_FRC
,
155 .Opcode
= RC_OPCODE_KIL
,
160 .Opcode
= RC_OPCODE_LG2
,
164 .IsStandardScalar
= 1
167 .Opcode
= RC_OPCODE_LIT
,
173 .Opcode
= RC_OPCODE_LOG
,
179 .Opcode
= RC_OPCODE_LRP
,
186 .Opcode
= RC_OPCODE_MAD
,
193 .Opcode
= RC_OPCODE_MAX
,
200 .Opcode
= RC_OPCODE_MIN
,
207 .Opcode
= RC_OPCODE_MOV
,
214 .Opcode
= RC_OPCODE_MUL
,
221 .Opcode
= RC_OPCODE_POW
,
225 .IsStandardScalar
= 1
228 .Opcode
= RC_OPCODE_RCP
,
232 .IsStandardScalar
= 1
235 .Opcode
= RC_OPCODE_RSQ
,
239 .IsStandardScalar
= 1
242 .Opcode
= RC_OPCODE_SCS
,
248 .Opcode
= RC_OPCODE_SEQ
,
255 .Opcode
= RC_OPCODE_SFL
,
262 .Opcode
= RC_OPCODE_SGE
,
269 .Opcode
= RC_OPCODE_SGT
,
276 .Opcode
= RC_OPCODE_SIN
,
280 .IsStandardScalar
= 1
283 .Opcode
= RC_OPCODE_SLE
,
290 .Opcode
= RC_OPCODE_SLT
,
297 .Opcode
= RC_OPCODE_SNE
,
304 .Opcode
= RC_OPCODE_SSG
,
311 .Opcode
= RC_OPCODE_SUB
,
318 .Opcode
= RC_OPCODE_SWZ
,
325 .Opcode
= RC_OPCODE_XPD
,
331 .Opcode
= RC_OPCODE_TEX
,
338 .Opcode
= RC_OPCODE_TXB
,
345 .Opcode
= RC_OPCODE_TXD
,
352 .Opcode
= RC_OPCODE_TXL
,
359 .Opcode
= RC_OPCODE_TXP
,
366 .Opcode
= RC_OPCODE_IF
,
372 .Opcode
= RC_OPCODE_ELSE
,
378 .Opcode
= RC_OPCODE_ENDIF
,
384 .Opcode
= RC_OPCODE_BGNLOOP
,
390 .Opcode
= RC_OPCODE_BRK
,
396 .Opcode
= RC_OPCODE_ENDLOOP
,
402 .Opcode
= RC_OPCODE_CONT
,
408 .Opcode
= RC_OPCODE_REPL_ALPHA
,
409 .Name
= "REPL_ALPHA",
413 .Opcode
= RC_OPCODE_BEGIN_TEX
,
417 .Opcode
= RC_OPCODE_KILP
,
422 void rc_compute_sources_for_writemask(
423 const struct rc_instruction
*inst
,
424 unsigned int writemask
,
425 unsigned int *srcmasks
)
427 const struct rc_opcode_info
* opcode
= rc_get_opcode_info(inst
->U
.I
.Opcode
);
432 if (opcode
->Opcode
== RC_OPCODE_KIL
)
433 srcmasks
[0] |= RC_MASK_XYZW
;
434 else if (opcode
->Opcode
== RC_OPCODE_IF
)
435 srcmasks
[0] |= RC_MASK_X
;
440 if (opcode
->IsComponentwise
) {
441 for(unsigned int src
= 0; src
< opcode
->NumSrcRegs
; ++src
)
442 srcmasks
[src
] |= writemask
;
443 } else if (opcode
->IsStandardScalar
) {
444 for(unsigned int src
= 0; src
< opcode
->NumSrcRegs
; ++src
)
445 srcmasks
[src
] |= RC_MASK_X
;
447 switch(opcode
->Opcode
) {
449 srcmasks
[0] |= RC_MASK_X
;
452 srcmasks
[0] |= RC_MASK_XY
;
453 srcmasks
[1] |= RC_MASK_XY
;
456 srcmasks
[0] |= RC_MASK_XYZ
;
457 srcmasks
[1] |= RC_MASK_XYZ
;
460 srcmasks
[0] |= RC_MASK_XYZW
;
461 srcmasks
[1] |= RC_MASK_XYZW
;
465 srcmasks
[0] |= RC_MASK_W
;
468 switch (inst
->U
.I
.TexSrcTarget
) {
470 srcmasks
[0] |= RC_MASK_X
;
473 case RC_TEXTURE_RECT
:
474 case RC_TEXTURE_1D_ARRAY
:
475 srcmasks
[0] |= RC_MASK_XY
;
478 case RC_TEXTURE_CUBE
:
479 case RC_TEXTURE_2D_ARRAY
:
480 srcmasks
[0] |= RC_MASK_XYZ
;
485 srcmasks
[0] |= RC_MASK_Y
| RC_MASK_Z
;
486 srcmasks
[1] |= RC_MASK_Y
| RC_MASK_W
;
490 srcmasks
[0] |= RC_MASK_XY
;
493 srcmasks
[0] |= RC_MASK_X
| RC_MASK_Y
| RC_MASK_W
;