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_ARR
,
69 .Opcode
= RC_OPCODE_CEIL
,
76 .Opcode
= RC_OPCODE_CLAMP
,
83 .Opcode
= RC_OPCODE_CMP
,
90 .Opcode
= RC_OPCODE_CND
,
97 .Opcode
= RC_OPCODE_COS
,
101 .IsStandardScalar
= 1
104 .Opcode
= RC_OPCODE_DDX
,
111 .Opcode
= RC_OPCODE_DDY
,
118 .Opcode
= RC_OPCODE_DP2
,
124 .Opcode
= RC_OPCODE_DP3
,
130 .Opcode
= RC_OPCODE_DP4
,
136 .Opcode
= RC_OPCODE_DPH
,
142 .Opcode
= RC_OPCODE_DST
,
148 .Opcode
= RC_OPCODE_EX2
,
152 .IsStandardScalar
= 1
155 .Opcode
= RC_OPCODE_EXP
,
161 .Opcode
= RC_OPCODE_FLR
,
168 .Opcode
= RC_OPCODE_FRC
,
175 .Opcode
= RC_OPCODE_KIL
,
180 .Opcode
= RC_OPCODE_LG2
,
184 .IsStandardScalar
= 1
187 .Opcode
= RC_OPCODE_LIT
,
193 .Opcode
= RC_OPCODE_LOG
,
199 .Opcode
= RC_OPCODE_LRP
,
206 .Opcode
= RC_OPCODE_MAD
,
213 .Opcode
= RC_OPCODE_MAX
,
220 .Opcode
= RC_OPCODE_MIN
,
227 .Opcode
= RC_OPCODE_MOV
,
234 .Opcode
= RC_OPCODE_MUL
,
241 .Opcode
= RC_OPCODE_POW
,
245 .IsStandardScalar
= 1
248 .Opcode
= RC_OPCODE_RCP
,
252 .IsStandardScalar
= 1
255 .Opcode
= RC_OPCODE_ROUND
,
262 .Opcode
= RC_OPCODE_RSQ
,
266 .IsStandardScalar
= 1
269 .Opcode
= RC_OPCODE_SCS
,
275 .Opcode
= RC_OPCODE_SEQ
,
282 .Opcode
= RC_OPCODE_SFL
,
289 .Opcode
= RC_OPCODE_SGE
,
296 .Opcode
= RC_OPCODE_SGT
,
303 .Opcode
= RC_OPCODE_SIN
,
307 .IsStandardScalar
= 1
310 .Opcode
= RC_OPCODE_SLE
,
317 .Opcode
= RC_OPCODE_SLT
,
324 .Opcode
= RC_OPCODE_SNE
,
331 .Opcode
= RC_OPCODE_SSG
,
338 .Opcode
= RC_OPCODE_SUB
,
345 .Opcode
= RC_OPCODE_SWZ
,
352 .Opcode
= RC_OPCODE_TRUNC
,
359 .Opcode
= RC_OPCODE_XPD
,
365 .Opcode
= RC_OPCODE_TEX
,
372 .Opcode
= RC_OPCODE_TXB
,
379 .Opcode
= RC_OPCODE_TXD
,
386 .Opcode
= RC_OPCODE_TXL
,
393 .Opcode
= RC_OPCODE_TXP
,
400 .Opcode
= RC_OPCODE_IF
,
406 .Opcode
= RC_OPCODE_ELSE
,
412 .Opcode
= RC_OPCODE_ENDIF
,
418 .Opcode
= RC_OPCODE_BGNLOOP
,
424 .Opcode
= RC_OPCODE_BRK
,
430 .Opcode
= RC_OPCODE_ENDLOOP
,
436 .Opcode
= RC_OPCODE_CONT
,
442 .Opcode
= RC_OPCODE_REPL_ALPHA
,
443 .Name
= "REPL_ALPHA",
447 .Opcode
= RC_OPCODE_BEGIN_TEX
,
451 .Opcode
= RC_OPCODE_KILP
,
455 .Opcode
= RC_ME_PRED_SEQ
,
456 .Name
= "ME_PRED_SEQ",
461 .Opcode
= RC_ME_PRED_SGT
,
462 .Name
= "ME_PRED_SGT",
467 .Opcode
= RC_ME_PRED_SGE
,
468 .Name
= "ME_PRED_SGE",
473 .Opcode
= RC_ME_PRED_SNEQ
,
474 .Name
= "ME_PRED_SNEQ",
479 .Opcode
= RC_ME_PRED_SET_CLR
,
480 .Name
= "ME_PRED_SET_CLEAR",
485 .Opcode
= RC_ME_PRED_SET_INV
,
486 .Name
= "ME_PRED_SET_INV",
491 .Opcode
= RC_ME_PRED_SET_POP
,
492 .Name
= "ME_PRED_SET_POP",
497 .Opcode
= RC_ME_PRED_SET_RESTORE
,
498 .Name
= "ME_PRED_SET_RESTORE",
503 .Opcode
= RC_VE_PRED_SEQ_PUSH
,
504 .Name
= "VE_PRED_SEQ_PUSH",
509 .Opcode
= RC_VE_PRED_SGT_PUSH
,
510 .Name
= "VE_PRED_SGT_PUSH",
515 .Opcode
= RC_VE_PRED_SGE_PUSH
,
516 .Name
= "VE_PRED_SGE_PUSH",
521 .Opcode
= RC_VE_PRED_SNEQ_PUSH
,
522 .Name
= "VE_PRED_SNEQ_PUSH",
528 void rc_compute_sources_for_writemask(
529 const struct rc_instruction
*inst
,
530 unsigned int writemask
,
531 unsigned int *srcmasks
)
533 const struct rc_opcode_info
* opcode
= rc_get_opcode_info(inst
->U
.I
.Opcode
);
538 if (opcode
->Opcode
== RC_OPCODE_KIL
)
539 srcmasks
[0] |= RC_MASK_XYZW
;
540 else if (opcode
->Opcode
== RC_OPCODE_IF
)
541 srcmasks
[0] |= RC_MASK_X
;
546 if (opcode
->IsComponentwise
) {
547 for(unsigned int src
= 0; src
< opcode
->NumSrcRegs
; ++src
)
548 srcmasks
[src
] |= writemask
;
549 } else if (opcode
->IsStandardScalar
) {
550 for(unsigned int src
= 0; src
< opcode
->NumSrcRegs
; ++src
)
551 srcmasks
[src
] |= writemask
;
553 switch(opcode
->Opcode
) {
556 srcmasks
[0] |= RC_MASK_X
;
559 srcmasks
[0] |= RC_MASK_XY
;
560 srcmasks
[1] |= RC_MASK_XY
;
564 srcmasks
[0] |= RC_MASK_XYZ
;
565 srcmasks
[1] |= RC_MASK_XYZ
;
568 srcmasks
[0] |= RC_MASK_XYZW
;
569 srcmasks
[1] |= RC_MASK_XYZW
;
572 srcmasks
[0] |= RC_MASK_XYZ
;
573 srcmasks
[1] |= RC_MASK_XYZW
;
578 srcmasks
[0] |= RC_MASK_W
;
581 switch (inst
->U
.I
.TexSrcTarget
) {
583 srcmasks
[0] |= RC_MASK_X
;
586 case RC_TEXTURE_RECT
:
587 case RC_TEXTURE_1D_ARRAY
:
588 srcmasks
[0] |= RC_MASK_XY
;
591 case RC_TEXTURE_CUBE
:
592 case RC_TEXTURE_2D_ARRAY
:
593 srcmasks
[0] |= RC_MASK_XYZ
;
598 switch (inst
->U
.I
.TexSrcTarget
) {
599 case RC_TEXTURE_1D_ARRAY
:
600 srcmasks
[0] |= RC_MASK_Y
;
603 srcmasks
[0] |= RC_MASK_X
;
604 srcmasks
[1] |= RC_MASK_X
;
605 srcmasks
[2] |= RC_MASK_X
;
607 case RC_TEXTURE_2D_ARRAY
:
608 srcmasks
[0] |= RC_MASK_Z
;
611 case RC_TEXTURE_RECT
:
612 srcmasks
[0] |= RC_MASK_XY
;
613 srcmasks
[1] |= RC_MASK_XY
;
614 srcmasks
[2] |= RC_MASK_XY
;
617 case RC_TEXTURE_CUBE
:
618 srcmasks
[0] |= RC_MASK_XYZ
;
619 srcmasks
[1] |= RC_MASK_XYZ
;
620 srcmasks
[2] |= RC_MASK_XYZ
;
625 srcmasks
[0] |= RC_MASK_Y
| RC_MASK_Z
;
626 srcmasks
[1] |= RC_MASK_Y
| RC_MASK_W
;
630 srcmasks
[0] |= RC_MASK_XY
;
633 srcmasks
[0] |= RC_MASK_X
| RC_MASK_Y
| RC_MASK_W
;