1 /**************************************************************************
3 * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * 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, sub license, 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 portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 * TGSI interpreter/executor.
31 * Flow control information:
33 * Since we operate on 'quads' (4 pixels or 4 vertices in parallel)
34 * flow control statements (IF/ELSE/ENDIF, LOOP/ENDLOOP) require special
35 * care since a condition may be true for some quad components but false
36 * for other components.
38 * We basically execute all statements (even if they're in the part of
39 * an IF/ELSE clause that's "not taken") and use a special mask to
40 * control writing to destination registers. This is the ExecMask.
43 * The ExecMask is computed from three other masks (CondMask, LoopMask and
44 * ContMask) which are controlled by the flow control instructions (namely:
45 * (IF/ELSE/ENDIF, LOOP/ENDLOOP and CONT).
53 #include "pipe/p_compiler.h"
54 #include "pipe/p_state.h"
55 #include "pipe/p_shader_tokens.h"
56 #include "tgsi/tgsi_dump.h"
57 #include "tgsi/tgsi_parse.h"
58 #include "tgsi/tgsi_util.h"
59 #include "tgsi_exec.h"
60 #include "util/u_memory.h"
61 #include "util/u_math.h"
65 #define TILE_TOP_LEFT 0
66 #define TILE_TOP_RIGHT 1
67 #define TILE_BOTTOM_LEFT 2
68 #define TILE_BOTTOM_RIGHT 3
76 * Shorthand locations of various utility registers (_I = Index, _C = Channel)
78 #define TEMP_0_I TGSI_EXEC_TEMP_00000000_I
79 #define TEMP_0_C TGSI_EXEC_TEMP_00000000_C
80 #define TEMP_7F_I TGSI_EXEC_TEMP_7FFFFFFF_I
81 #define TEMP_7F_C TGSI_EXEC_TEMP_7FFFFFFF_C
82 #define TEMP_80_I TGSI_EXEC_TEMP_80000000_I
83 #define TEMP_80_C TGSI_EXEC_TEMP_80000000_C
84 #define TEMP_FF_I TGSI_EXEC_TEMP_FFFFFFFF_I
85 #define TEMP_FF_C TGSI_EXEC_TEMP_FFFFFFFF_C
86 #define TEMP_1_I TGSI_EXEC_TEMP_ONE_I
87 #define TEMP_1_C TGSI_EXEC_TEMP_ONE_C
88 #define TEMP_2_I TGSI_EXEC_TEMP_TWO_I
89 #define TEMP_2_C TGSI_EXEC_TEMP_TWO_C
90 #define TEMP_128_I TGSI_EXEC_TEMP_128_I
91 #define TEMP_128_C TGSI_EXEC_TEMP_128_C
92 #define TEMP_M128_I TGSI_EXEC_TEMP_MINUS_128_I
93 #define TEMP_M128_C TGSI_EXEC_TEMP_MINUS_128_C
94 #define TEMP_KILMASK_I TGSI_EXEC_TEMP_KILMASK_I
95 #define TEMP_KILMASK_C TGSI_EXEC_TEMP_KILMASK_C
96 #define TEMP_OUTPUT_I TGSI_EXEC_TEMP_OUTPUT_I
97 #define TEMP_OUTPUT_C TGSI_EXEC_TEMP_OUTPUT_C
98 #define TEMP_PRIMITIVE_I TGSI_EXEC_TEMP_PRIMITIVE_I
99 #define TEMP_PRIMITIVE_C TGSI_EXEC_TEMP_PRIMITIVE_C
100 #define TEMP_CC_I TGSI_EXEC_TEMP_CC_I
101 #define TEMP_CC_C TGSI_EXEC_TEMP_CC_C
102 #define TEMP_3_I TGSI_EXEC_TEMP_THREE_I
103 #define TEMP_3_C TGSI_EXEC_TEMP_THREE_C
104 #define TEMP_HALF_I TGSI_EXEC_TEMP_HALF_I
105 #define TEMP_HALF_C TGSI_EXEC_TEMP_HALF_C
106 #define TEMP_R0 TGSI_EXEC_TEMP_R0
107 #define TEMP_P0 TGSI_EXEC_TEMP_P0
109 #define IS_CHANNEL_ENABLED(INST, CHAN)\
110 ((INST).FullDstRegisters[0].DstRegister.WriteMask & (1 << (CHAN)))
112 #define IS_CHANNEL_ENABLED2(INST, CHAN)\
113 ((INST).FullDstRegisters[1].DstRegister.WriteMask & (1 << (CHAN)))
115 #define FOR_EACH_ENABLED_CHANNEL(INST, CHAN)\
116 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)\
117 if (IS_CHANNEL_ENABLED( INST, CHAN ))
119 #define FOR_EACH_ENABLED_CHANNEL2(INST, CHAN)\
120 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)\
121 if (IS_CHANNEL_ENABLED2( INST, CHAN ))
124 /** The execution mask depends on the conditional mask and the loop mask */
125 #define UPDATE_EXEC_MASK(MACH) \
126 MACH->ExecMask = MACH->CondMask & MACH->LoopMask & MACH->ContMask & MACH->FuncMask
129 static const union tgsi_exec_channel ZeroVec
=
130 { { 0.0, 0.0, 0.0, 0.0 } };
135 check_inf_or_nan(const union tgsi_exec_channel
*chan
)
137 assert(!util_is_inf_or_nan(chan
->f
[0]));
138 assert(!util_is_inf_or_nan(chan
->f
[1]));
139 assert(!util_is_inf_or_nan(chan
->f
[2]));
140 assert(!util_is_inf_or_nan(chan
->f
[3]));
147 print_chan(const char *msg
, const union tgsi_exec_channel
*chan
)
149 debug_printf("%s = {%f, %f, %f, %f}\n",
150 msg
, chan
->f
[0], chan
->f
[1], chan
->f
[2], chan
->f
[3]);
157 print_temp(const struct tgsi_exec_machine
*mach
, uint index
)
159 const struct tgsi_exec_vector
*tmp
= &mach
->Temps
[index
];
161 debug_printf("Temp[%u] =\n", index
);
162 for (i
= 0; i
< 4; i
++) {
163 debug_printf(" %c: { %f, %f, %f, %f }\n",
175 * Check if there's a potential src/dst register data dependency when
176 * using SOA execution.
179 * This would expand into:
184 * The second instruction will have the wrong value for t0 if executed as-is.
187 tgsi_check_soa_dependencies(const struct tgsi_full_instruction
*inst
)
191 uint writemask
= inst
->FullDstRegisters
[0].DstRegister
.WriteMask
;
192 if (writemask
== TGSI_WRITEMASK_X
||
193 writemask
== TGSI_WRITEMASK_Y
||
194 writemask
== TGSI_WRITEMASK_Z
||
195 writemask
== TGSI_WRITEMASK_W
||
196 writemask
== TGSI_WRITEMASK_NONE
) {
197 /* no chance of data dependency */
201 /* loop over src regs */
202 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
203 if ((inst
->FullSrcRegisters
[i
].SrcRegister
.File
==
204 inst
->FullDstRegisters
[0].DstRegister
.File
) &&
205 (inst
->FullSrcRegisters
[i
].SrcRegister
.Index
==
206 inst
->FullDstRegisters
[0].DstRegister
.Index
)) {
207 /* loop over dest channels */
208 uint channelsWritten
= 0x0;
209 FOR_EACH_ENABLED_CHANNEL(*inst
, chan
) {
210 /* check if we're reading a channel that's been written */
211 uint swizzle
= tgsi_util_get_full_src_register_swizzle(&inst
->FullSrcRegisters
[i
], chan
);
212 if (channelsWritten
& (1 << swizzle
)) {
216 channelsWritten
|= (1 << chan
);
225 * Initialize machine state by expanding tokens to full instructions,
226 * allocating temporary storage, setting up constants, etc.
227 * After this, we can call tgsi_exec_machine_run() many times.
230 tgsi_exec_machine_bind_shader(
231 struct tgsi_exec_machine
*mach
,
232 const struct tgsi_token
*tokens
,
234 struct tgsi_sampler
**samplers
)
237 struct tgsi_parse_context parse
;
238 struct tgsi_exec_labels
*labels
= &mach
->Labels
;
239 struct tgsi_full_instruction
*instructions
;
240 struct tgsi_full_declaration
*declarations
;
241 uint maxInstructions
= 10, numInstructions
= 0;
242 uint maxDeclarations
= 10, numDeclarations
= 0;
246 tgsi_dump(tokens
, 0);
251 mach
->Tokens
= tokens
;
252 mach
->Samplers
= samplers
;
254 k
= tgsi_parse_init (&parse
, mach
->Tokens
);
255 if (k
!= TGSI_PARSE_OK
) {
256 debug_printf( "Problem parsing!\n" );
260 mach
->Processor
= parse
.FullHeader
.Processor
.Processor
;
264 declarations
= (struct tgsi_full_declaration
*)
265 MALLOC( maxDeclarations
* sizeof(struct tgsi_full_declaration
) );
271 instructions
= (struct tgsi_full_instruction
*)
272 MALLOC( maxInstructions
* sizeof(struct tgsi_full_instruction
) );
275 FREE( declarations
);
279 while( !tgsi_parse_end_of_tokens( &parse
) ) {
280 uint pointer
= parse
.Position
;
283 tgsi_parse_token( &parse
);
284 switch( parse
.FullToken
.Token
.Type
) {
285 case TGSI_TOKEN_TYPE_DECLARATION
:
286 /* save expanded declaration */
287 if (numDeclarations
== maxDeclarations
) {
288 declarations
= REALLOC(declarations
,
290 * sizeof(struct tgsi_full_declaration
),
291 (maxDeclarations
+ 10)
292 * sizeof(struct tgsi_full_declaration
));
293 maxDeclarations
+= 10;
295 memcpy(declarations
+ numDeclarations
,
296 &parse
.FullToken
.FullDeclaration
,
297 sizeof(declarations
[0]));
301 case TGSI_TOKEN_TYPE_IMMEDIATE
:
303 uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
305 assert( mach
->ImmLimit
+ 1 <= TGSI_EXEC_NUM_IMMEDIATES
);
307 for( i
= 0; i
< size
; i
++ ) {
308 mach
->Imms
[mach
->ImmLimit
][i
] =
309 parse
.FullToken
.FullImmediate
.u
[i
].Float
;
315 case TGSI_TOKEN_TYPE_INSTRUCTION
:
316 assert( labels
->count
< MAX_LABELS
);
318 labels
->labels
[labels
->count
][0] = instno
;
319 labels
->labels
[labels
->count
][1] = pointer
;
322 /* save expanded instruction */
323 if (numInstructions
== maxInstructions
) {
324 instructions
= REALLOC(instructions
,
326 * sizeof(struct tgsi_full_instruction
),
327 (maxInstructions
+ 10)
328 * sizeof(struct tgsi_full_instruction
));
329 maxInstructions
+= 10;
332 memcpy(instructions
+ numInstructions
,
333 &parse
.FullToken
.FullInstruction
,
334 sizeof(instructions
[0]));
343 tgsi_parse_free (&parse
);
345 if (mach
->Declarations
) {
346 FREE( mach
->Declarations
);
348 mach
->Declarations
= declarations
;
349 mach
->NumDeclarations
= numDeclarations
;
351 if (mach
->Instructions
) {
352 FREE( mach
->Instructions
);
354 mach
->Instructions
= instructions
;
355 mach
->NumInstructions
= numInstructions
;
359 struct tgsi_exec_machine
*
360 tgsi_exec_machine_create( void )
362 struct tgsi_exec_machine
*mach
;
365 mach
= align_malloc( sizeof *mach
, 16 );
369 memset(mach
, 0, sizeof(*mach
));
371 mach
->Addrs
= &mach
->Temps
[TGSI_EXEC_TEMP_ADDR
];
372 mach
->Predicates
= &mach
->Temps
[TGSI_EXEC_TEMP_P0
];
374 /* Setup constants. */
375 for( i
= 0; i
< 4; i
++ ) {
376 mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
].u
[i
] = 0x00000000;
377 mach
->Temps
[TEMP_7F_I
].xyzw
[TEMP_7F_C
].u
[i
] = 0x7FFFFFFF;
378 mach
->Temps
[TEMP_80_I
].xyzw
[TEMP_80_C
].u
[i
] = 0x80000000;
379 mach
->Temps
[TEMP_FF_I
].xyzw
[TEMP_FF_C
].u
[i
] = 0xFFFFFFFF;
380 mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
].f
[i
] = 1.0f
;
381 mach
->Temps
[TEMP_2_I
].xyzw
[TEMP_2_C
].f
[i
] = 2.0f
;
382 mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
].f
[i
] = 128.0f
;
383 mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
].f
[i
] = -128.0f
;
384 mach
->Temps
[TEMP_3_I
].xyzw
[TEMP_3_C
].f
[i
] = 3.0f
;
385 mach
->Temps
[TEMP_HALF_I
].xyzw
[TEMP_HALF_C
].f
[i
] = 0.5f
;
389 /* silence warnings */
403 tgsi_exec_machine_destroy(struct tgsi_exec_machine
*mach
)
406 FREE(mach
->Instructions
);
407 FREE(mach
->Declarations
);
416 union tgsi_exec_channel
*dst
,
417 const union tgsi_exec_channel
*src
)
419 dst
->f
[0] = fabsf( src
->f
[0] );
420 dst
->f
[1] = fabsf( src
->f
[1] );
421 dst
->f
[2] = fabsf( src
->f
[2] );
422 dst
->f
[3] = fabsf( src
->f
[3] );
427 union tgsi_exec_channel
*dst
,
428 const union tgsi_exec_channel
*src0
,
429 const union tgsi_exec_channel
*src1
)
431 dst
->f
[0] = src0
->f
[0] + src1
->f
[0];
432 dst
->f
[1] = src0
->f
[1] + src1
->f
[1];
433 dst
->f
[2] = src0
->f
[2] + src1
->f
[2];
434 dst
->f
[3] = src0
->f
[3] + src1
->f
[3];
440 union tgsi_exec_channel
*dst
,
441 const union tgsi_exec_channel
*src0
,
442 const union tgsi_exec_channel
*src1
)
444 dst
->i
[0] = src0
->i
[0] + src1
->i
[0];
445 dst
->i
[1] = src0
->i
[1] + src1
->i
[1];
446 dst
->i
[2] = src0
->i
[2] + src1
->i
[2];
447 dst
->i
[3] = src0
->i
[3] + src1
->i
[3];
453 union tgsi_exec_channel
*dst
,
454 const union tgsi_exec_channel
*src0
,
455 const union tgsi_exec_channel
*src1
)
457 dst
->u
[0] = src0
->u
[0] & src1
->u
[0];
458 dst
->u
[1] = src0
->u
[1] & src1
->u
[1];
459 dst
->u
[2] = src0
->u
[2] & src1
->u
[2];
460 dst
->u
[3] = src0
->u
[3] & src1
->u
[3];
465 union tgsi_exec_channel
*dst
,
466 const union tgsi_exec_channel
*src
)
468 dst
->f
[0] = ceilf( src
->f
[0] );
469 dst
->f
[1] = ceilf( src
->f
[1] );
470 dst
->f
[2] = ceilf( src
->f
[2] );
471 dst
->f
[3] = ceilf( src
->f
[3] );
476 union tgsi_exec_channel
*dst
,
477 const union tgsi_exec_channel
*src
)
479 dst
->f
[0] = cosf( src
->f
[0] );
480 dst
->f
[1] = cosf( src
->f
[1] );
481 dst
->f
[2] = cosf( src
->f
[2] );
482 dst
->f
[3] = cosf( src
->f
[3] );
487 union tgsi_exec_channel
*dst
,
488 const union tgsi_exec_channel
*src
)
493 dst
->f
[3] = src
->f
[TILE_BOTTOM_RIGHT
] - src
->f
[TILE_BOTTOM_LEFT
];
498 union tgsi_exec_channel
*dst
,
499 const union tgsi_exec_channel
*src
)
504 dst
->f
[3] = src
->f
[TILE_TOP_LEFT
] - src
->f
[TILE_BOTTOM_LEFT
];
509 union tgsi_exec_channel
*dst
,
510 const union tgsi_exec_channel
*src0
,
511 const union tgsi_exec_channel
*src1
)
513 if (src1
->f
[0] != 0) {
514 dst
->f
[0] = src0
->f
[0] / src1
->f
[0];
516 if (src1
->f
[1] != 0) {
517 dst
->f
[1] = src0
->f
[1] / src1
->f
[1];
519 if (src1
->f
[2] != 0) {
520 dst
->f
[2] = src0
->f
[2] / src1
->f
[2];
522 if (src1
->f
[3] != 0) {
523 dst
->f
[3] = src0
->f
[3] / src1
->f
[3];
530 union tgsi_exec_channel
*dst
,
531 const union tgsi_exec_channel
*src0
,
532 const union tgsi_exec_channel
*src1
)
534 dst
->u
[0] = src0
->u
[0] / src1
->u
[0];
535 dst
->u
[1] = src0
->u
[1] / src1
->u
[1];
536 dst
->u
[2] = src0
->u
[2] / src1
->u
[2];
537 dst
->u
[3] = src0
->u
[3] / src1
->u
[3];
543 union tgsi_exec_channel
*dst
,
544 const union tgsi_exec_channel
*src0
,
545 const union tgsi_exec_channel
*src1
,
546 const union tgsi_exec_channel
*src2
,
547 const union tgsi_exec_channel
*src3
)
549 dst
->f
[0] = src0
->f
[0] == src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
550 dst
->f
[1] = src0
->f
[1] == src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
551 dst
->f
[2] = src0
->f
[2] == src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
552 dst
->f
[3] = src0
->f
[3] == src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
558 union tgsi_exec_channel
*dst
,
559 const union tgsi_exec_channel
*src0
,
560 const union tgsi_exec_channel
*src1
,
561 const union tgsi_exec_channel
*src2
,
562 const union tgsi_exec_channel
*src3
)
564 dst
->i
[0] = src0
->i
[0] == src1
->i
[0] ? src2
->i
[0] : src3
->i
[0];
565 dst
->i
[1] = src0
->i
[1] == src1
->i
[1] ? src2
->i
[1] : src3
->i
[1];
566 dst
->i
[2] = src0
->i
[2] == src1
->i
[2] ? src2
->i
[2] : src3
->i
[2];
567 dst
->i
[3] = src0
->i
[3] == src1
->i
[3] ? src2
->i
[3] : src3
->i
[3];
573 union tgsi_exec_channel
*dst
,
574 const union tgsi_exec_channel
*src
)
577 dst
->f
[0] = util_fast_exp2( src
->f
[0] );
578 dst
->f
[1] = util_fast_exp2( src
->f
[1] );
579 dst
->f
[2] = util_fast_exp2( src
->f
[2] );
580 dst
->f
[3] = util_fast_exp2( src
->f
[3] );
584 /* Inf is okay for this instruction, so clamp it to silence assertions. */
586 union tgsi_exec_channel clamped
;
588 for (i
= 0; i
< 4; i
++) {
589 if (src
->f
[i
] > 127.99999f
) {
590 clamped
.f
[i
] = 127.99999f
;
591 } else if (src
->f
[i
] < -126.99999f
) {
592 clamped
.f
[i
] = -126.99999f
;
594 clamped
.f
[i
] = src
->f
[i
];
600 dst
->f
[0] = powf( 2.0f
, src
->f
[0] );
601 dst
->f
[1] = powf( 2.0f
, src
->f
[1] );
602 dst
->f
[2] = powf( 2.0f
, src
->f
[2] );
603 dst
->f
[3] = powf( 2.0f
, src
->f
[3] );
610 union tgsi_exec_channel
*dst
,
611 const union tgsi_exec_channel
*src
)
613 dst
->u
[0] = (uint
) src
->f
[0];
614 dst
->u
[1] = (uint
) src
->f
[1];
615 dst
->u
[2] = (uint
) src
->f
[2];
616 dst
->u
[3] = (uint
) src
->f
[3];
621 micro_float_clamp(union tgsi_exec_channel
*dst
,
622 const union tgsi_exec_channel
*src
)
626 for (i
= 0; i
< 4; i
++) {
627 if (src
->f
[i
] > 0.0f
) {
628 if (src
->f
[i
] > 1.884467e+019f
)
629 dst
->f
[i
] = 1.884467e+019f
;
630 else if (src
->f
[i
] < 5.42101e-020f
)
631 dst
->f
[i
] = 5.42101e-020f
;
633 dst
->f
[i
] = src
->f
[i
];
636 if (src
->f
[i
] < -1.884467e+019f
)
637 dst
->f
[i
] = -1.884467e+019f
;
638 else if (src
->f
[i
] > -5.42101e-020f
)
639 dst
->f
[i
] = -5.42101e-020f
;
641 dst
->f
[i
] = src
->f
[i
];
648 union tgsi_exec_channel
*dst
,
649 const union tgsi_exec_channel
*src
)
651 dst
->f
[0] = floorf( src
->f
[0] );
652 dst
->f
[1] = floorf( src
->f
[1] );
653 dst
->f
[2] = floorf( src
->f
[2] );
654 dst
->f
[3] = floorf( src
->f
[3] );
659 union tgsi_exec_channel
*dst
,
660 const union tgsi_exec_channel
*src
)
662 dst
->f
[0] = src
->f
[0] - floorf( src
->f
[0] );
663 dst
->f
[1] = src
->f
[1] - floorf( src
->f
[1] );
664 dst
->f
[2] = src
->f
[2] - floorf( src
->f
[2] );
665 dst
->f
[3] = src
->f
[3] - floorf( src
->f
[3] );
670 union tgsi_exec_channel
*dst
,
671 const union tgsi_exec_channel
*src
)
673 dst
->f
[0] = (float) src
->i
[0];
674 dst
->f
[1] = (float) src
->i
[1];
675 dst
->f
[2] = (float) src
->i
[2];
676 dst
->f
[3] = (float) src
->i
[3];
681 union tgsi_exec_channel
*dst
,
682 const union tgsi_exec_channel
*src
)
685 dst
->f
[0] = util_fast_log2( src
->f
[0] );
686 dst
->f
[1] = util_fast_log2( src
->f
[1] );
687 dst
->f
[2] = util_fast_log2( src
->f
[2] );
688 dst
->f
[3] = util_fast_log2( src
->f
[3] );
690 dst
->f
[0] = logf( src
->f
[0] ) * 1.442695f
;
691 dst
->f
[1] = logf( src
->f
[1] ) * 1.442695f
;
692 dst
->f
[2] = logf( src
->f
[2] ) * 1.442695f
;
693 dst
->f
[3] = logf( src
->f
[3] ) * 1.442695f
;
699 union tgsi_exec_channel
*dst
,
700 const union tgsi_exec_channel
*src0
,
701 const union tgsi_exec_channel
*src1
,
702 const union tgsi_exec_channel
*src2
,
703 const union tgsi_exec_channel
*src3
)
705 dst
->f
[0] = src0
->f
[0] <= src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
706 dst
->f
[1] = src0
->f
[1] <= src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
707 dst
->f
[2] = src0
->f
[2] <= src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
708 dst
->f
[3] = src0
->f
[3] <= src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
713 union tgsi_exec_channel
*dst
,
714 const union tgsi_exec_channel
*src0
,
715 const union tgsi_exec_channel
*src1
,
716 const union tgsi_exec_channel
*src2
,
717 const union tgsi_exec_channel
*src3
)
719 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
720 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
721 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
722 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
728 union tgsi_exec_channel
*dst
,
729 const union tgsi_exec_channel
*src0
,
730 const union tgsi_exec_channel
*src1
,
731 const union tgsi_exec_channel
*src2
,
732 const union tgsi_exec_channel
*src3
)
734 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? src2
->i
[0] : src3
->i
[0];
735 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? src2
->i
[1] : src3
->i
[1];
736 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? src2
->i
[2] : src3
->i
[2];
737 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? src2
->i
[3] : src3
->i
[3];
744 union tgsi_exec_channel
*dst
,
745 const union tgsi_exec_channel
*src0
,
746 const union tgsi_exec_channel
*src1
,
747 const union tgsi_exec_channel
*src2
,
748 const union tgsi_exec_channel
*src3
)
750 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? src2
->u
[0] : src3
->u
[0];
751 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? src2
->u
[1] : src3
->u
[1];
752 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? src2
->u
[2] : src3
->u
[2];
753 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? src2
->u
[3] : src3
->u
[3];
759 union tgsi_exec_channel
*dst
,
760 const union tgsi_exec_channel
*src0
,
761 const union tgsi_exec_channel
*src1
)
763 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
764 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
765 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
766 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
772 union tgsi_exec_channel
*dst
,
773 const union tgsi_exec_channel
*src0
,
774 const union tgsi_exec_channel
*src1
)
776 dst
->i
[0] = src0
->i
[0] > src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
777 dst
->i
[1] = src0
->i
[1] > src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
778 dst
->i
[2] = src0
->i
[2] > src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
779 dst
->i
[3] = src0
->i
[3] > src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
786 union tgsi_exec_channel
*dst
,
787 const union tgsi_exec_channel
*src0
,
788 const union tgsi_exec_channel
*src1
)
790 dst
->u
[0] = src0
->u
[0] > src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
791 dst
->u
[1] = src0
->u
[1] > src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
792 dst
->u
[2] = src0
->u
[2] > src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
793 dst
->u
[3] = src0
->u
[3] > src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
799 union tgsi_exec_channel
*dst
,
800 const union tgsi_exec_channel
*src0
,
801 const union tgsi_exec_channel
*src1
)
803 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
804 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
805 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
806 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
812 union tgsi_exec_channel
*dst
,
813 const union tgsi_exec_channel
*src0
,
814 const union tgsi_exec_channel
*src1
)
816 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
817 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
818 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
819 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
826 union tgsi_exec_channel
*dst
,
827 const union tgsi_exec_channel
*src0
,
828 const union tgsi_exec_channel
*src1
)
830 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
831 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
832 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
833 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
840 union tgsi_exec_channel
*dst
,
841 const union tgsi_exec_channel
*src0
,
842 const union tgsi_exec_channel
*src1
)
844 dst
->u
[0] = src0
->u
[0] % src1
->u
[0];
845 dst
->u
[1] = src0
->u
[1] % src1
->u
[1];
846 dst
->u
[2] = src0
->u
[2] % src1
->u
[2];
847 dst
->u
[3] = src0
->u
[3] % src1
->u
[3];
853 union tgsi_exec_channel
*dst
,
854 const union tgsi_exec_channel
*src0
,
855 const union tgsi_exec_channel
*src1
)
857 dst
->f
[0] = src0
->f
[0] * src1
->f
[0];
858 dst
->f
[1] = src0
->f
[1] * src1
->f
[1];
859 dst
->f
[2] = src0
->f
[2] * src1
->f
[2];
860 dst
->f
[3] = src0
->f
[3] * src1
->f
[3];
866 union tgsi_exec_channel
*dst
,
867 const union tgsi_exec_channel
*src0
,
868 const union tgsi_exec_channel
*src1
)
870 dst
->i
[0] = src0
->i
[0] * src1
->i
[0];
871 dst
->i
[1] = src0
->i
[1] * src1
->i
[1];
872 dst
->i
[2] = src0
->i
[2] * src1
->i
[2];
873 dst
->i
[3] = src0
->i
[3] * src1
->i
[3];
880 union tgsi_exec_channel
*dst0
,
881 union tgsi_exec_channel
*dst1
,
882 const union tgsi_exec_channel
*src0
,
883 const union tgsi_exec_channel
*src1
)
885 dst1
->i
[0] = src0
->i
[0] * src1
->i
[0];
886 dst1
->i
[1] = src0
->i
[1] * src1
->i
[1];
887 dst1
->i
[2] = src0
->i
[2] * src1
->i
[2];
888 dst1
->i
[3] = src0
->i
[3] * src1
->i
[3];
899 union tgsi_exec_channel
*dst0
,
900 union tgsi_exec_channel
*dst1
,
901 const union tgsi_exec_channel
*src0
,
902 const union tgsi_exec_channel
*src1
)
904 dst1
->u
[0] = src0
->u
[0] * src1
->u
[0];
905 dst1
->u
[1] = src0
->u
[1] * src1
->u
[1];
906 dst1
->u
[2] = src0
->u
[2] * src1
->u
[2];
907 dst1
->u
[3] = src0
->u
[3] * src1
->u
[3];
919 union tgsi_exec_channel
*dst
,
920 const union tgsi_exec_channel
*src0
,
921 const union tgsi_exec_channel
*src1
,
922 const union tgsi_exec_channel
*src2
)
924 dst
->u
[0] = src0
->u
[0] ? src1
->u
[0] : src2
->u
[0];
925 dst
->u
[1] = src0
->u
[1] ? src1
->u
[1] : src2
->u
[1];
926 dst
->u
[2] = src0
->u
[2] ? src1
->u
[2] : src2
->u
[2];
927 dst
->u
[3] = src0
->u
[3] ? src1
->u
[3] : src2
->u
[3];
933 union tgsi_exec_channel
*dst
,
934 const union tgsi_exec_channel
*src
)
936 dst
->f
[0] = -src
->f
[0];
937 dst
->f
[1] = -src
->f
[1];
938 dst
->f
[2] = -src
->f
[2];
939 dst
->f
[3] = -src
->f
[3];
945 union tgsi_exec_channel
*dst
,
946 const union tgsi_exec_channel
*src
)
948 dst
->i
[0] = -src
->i
[0];
949 dst
->i
[1] = -src
->i
[1];
950 dst
->i
[2] = -src
->i
[2];
951 dst
->i
[3] = -src
->i
[3];
957 union tgsi_exec_channel
*dst
,
958 const union tgsi_exec_channel
*src
)
960 dst
->u
[0] = ~src
->u
[0];
961 dst
->u
[1] = ~src
->u
[1];
962 dst
->u
[2] = ~src
->u
[2];
963 dst
->u
[3] = ~src
->u
[3];
968 union tgsi_exec_channel
*dst
,
969 const union tgsi_exec_channel
*src0
,
970 const union tgsi_exec_channel
*src1
)
972 dst
->u
[0] = src0
->u
[0] | src1
->u
[0];
973 dst
->u
[1] = src0
->u
[1] | src1
->u
[1];
974 dst
->u
[2] = src0
->u
[2] | src1
->u
[2];
975 dst
->u
[3] = src0
->u
[3] | src1
->u
[3];
980 union tgsi_exec_channel
*dst
,
981 const union tgsi_exec_channel
*src0
,
982 const union tgsi_exec_channel
*src1
)
985 dst
->f
[0] = util_fast_pow( src0
->f
[0], src1
->f
[0] );
986 dst
->f
[1] = util_fast_pow( src0
->f
[1], src1
->f
[1] );
987 dst
->f
[2] = util_fast_pow( src0
->f
[2], src1
->f
[2] );
988 dst
->f
[3] = util_fast_pow( src0
->f
[3], src1
->f
[3] );
990 dst
->f
[0] = powf( src0
->f
[0], src1
->f
[0] );
991 dst
->f
[1] = powf( src0
->f
[1], src1
->f
[1] );
992 dst
->f
[2] = powf( src0
->f
[2], src1
->f
[2] );
993 dst
->f
[3] = powf( src0
->f
[3], src1
->f
[3] );
999 union tgsi_exec_channel
*dst
,
1000 const union tgsi_exec_channel
*src
)
1002 dst
->f
[0] = floorf( src
->f
[0] + 0.5f
);
1003 dst
->f
[1] = floorf( src
->f
[1] + 0.5f
);
1004 dst
->f
[2] = floorf( src
->f
[2] + 0.5f
);
1005 dst
->f
[3] = floorf( src
->f
[3] + 0.5f
);
1010 union tgsi_exec_channel
*dst
,
1011 const union tgsi_exec_channel
*src
)
1013 dst
->f
[0] = src
->f
[0] < 0.0f
? -1.0f
: src
->f
[0] > 0.0f
? 1.0f
: 0.0f
;
1014 dst
->f
[1] = src
->f
[1] < 0.0f
? -1.0f
: src
->f
[1] > 0.0f
? 1.0f
: 0.0f
;
1015 dst
->f
[2] = src
->f
[2] < 0.0f
? -1.0f
: src
->f
[2] > 0.0f
? 1.0f
: 0.0f
;
1016 dst
->f
[3] = src
->f
[3] < 0.0f
? -1.0f
: src
->f
[3] > 0.0f
? 1.0f
: 0.0f
;
1021 union tgsi_exec_channel
*dst
,
1022 const union tgsi_exec_channel
*src0
,
1023 const union tgsi_exec_channel
*src1
)
1025 dst
->i
[0] = src0
->i
[0] << src1
->i
[0];
1026 dst
->i
[1] = src0
->i
[1] << src1
->i
[1];
1027 dst
->i
[2] = src0
->i
[2] << src1
->i
[2];
1028 dst
->i
[3] = src0
->i
[3] << src1
->i
[3];
1033 union tgsi_exec_channel
*dst
,
1034 const union tgsi_exec_channel
*src0
,
1035 const union tgsi_exec_channel
*src1
)
1037 dst
->i
[0] = src0
->i
[0] >> src1
->i
[0];
1038 dst
->i
[1] = src0
->i
[1] >> src1
->i
[1];
1039 dst
->i
[2] = src0
->i
[2] >> src1
->i
[2];
1040 dst
->i
[3] = src0
->i
[3] >> src1
->i
[3];
1045 union tgsi_exec_channel
*dst
,
1046 const union tgsi_exec_channel
*src0
)
1048 dst
->f
[0] = (float) (int) src0
->f
[0];
1049 dst
->f
[1] = (float) (int) src0
->f
[1];
1050 dst
->f
[2] = (float) (int) src0
->f
[2];
1051 dst
->f
[3] = (float) (int) src0
->f
[3];
1057 union tgsi_exec_channel
*dst
,
1058 const union tgsi_exec_channel
*src0
,
1059 const union tgsi_exec_channel
*src1
)
1061 dst
->u
[0] = src0
->u
[0] >> src1
->u
[0];
1062 dst
->u
[1] = src0
->u
[1] >> src1
->u
[1];
1063 dst
->u
[2] = src0
->u
[2] >> src1
->u
[2];
1064 dst
->u
[3] = src0
->u
[3] >> src1
->u
[3];
1070 union tgsi_exec_channel
*dst
,
1071 const union tgsi_exec_channel
*src
)
1073 dst
->f
[0] = sinf( src
->f
[0] );
1074 dst
->f
[1] = sinf( src
->f
[1] );
1075 dst
->f
[2] = sinf( src
->f
[2] );
1076 dst
->f
[3] = sinf( src
->f
[3] );
1080 micro_sqrt( union tgsi_exec_channel
*dst
,
1081 const union tgsi_exec_channel
*src
)
1083 dst
->f
[0] = sqrtf( src
->f
[0] );
1084 dst
->f
[1] = sqrtf( src
->f
[1] );
1085 dst
->f
[2] = sqrtf( src
->f
[2] );
1086 dst
->f
[3] = sqrtf( src
->f
[3] );
1091 union tgsi_exec_channel
*dst
,
1092 const union tgsi_exec_channel
*src0
,
1093 const union tgsi_exec_channel
*src1
)
1095 dst
->f
[0] = src0
->f
[0] - src1
->f
[0];
1096 dst
->f
[1] = src0
->f
[1] - src1
->f
[1];
1097 dst
->f
[2] = src0
->f
[2] - src1
->f
[2];
1098 dst
->f
[3] = src0
->f
[3] - src1
->f
[3];
1104 union tgsi_exec_channel
*dst
,
1105 const union tgsi_exec_channel
*src
)
1107 dst
->f
[0] = (float) src
->u
[0];
1108 dst
->f
[1] = (float) src
->u
[1];
1109 dst
->f
[2] = (float) src
->u
[2];
1110 dst
->f
[3] = (float) src
->u
[3];
1116 union tgsi_exec_channel
*dst
,
1117 const union tgsi_exec_channel
*src0
,
1118 const union tgsi_exec_channel
*src1
)
1120 dst
->u
[0] = src0
->u
[0] ^ src1
->u
[0];
1121 dst
->u
[1] = src0
->u
[1] ^ src1
->u
[1];
1122 dst
->u
[2] = src0
->u
[2] ^ src1
->u
[2];
1123 dst
->u
[3] = src0
->u
[3] ^ src1
->u
[3];
1127 fetch_src_file_channel(
1128 const struct tgsi_exec_machine
*mach
,
1131 const union tgsi_exec_channel
*index
,
1132 union tgsi_exec_channel
*chan
)
1135 case TGSI_SWIZZLE_X
:
1136 case TGSI_SWIZZLE_Y
:
1137 case TGSI_SWIZZLE_Z
:
1138 case TGSI_SWIZZLE_W
:
1140 case TGSI_FILE_CONSTANT
:
1141 assert(mach
->Consts
);
1142 if (index
->i
[0] < 0)
1145 chan
->f
[0] = mach
->Consts
[index
->i
[0]][swizzle
];
1146 if (index
->i
[1] < 0)
1149 chan
->f
[1] = mach
->Consts
[index
->i
[1]][swizzle
];
1150 if (index
->i
[2] < 0)
1153 chan
->f
[2] = mach
->Consts
[index
->i
[2]][swizzle
];
1154 if (index
->i
[3] < 0)
1157 chan
->f
[3] = mach
->Consts
[index
->i
[3]][swizzle
];
1160 case TGSI_FILE_INPUT
:
1161 chan
->u
[0] = mach
->Inputs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1162 chan
->u
[1] = mach
->Inputs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1163 chan
->u
[2] = mach
->Inputs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1164 chan
->u
[3] = mach
->Inputs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1167 case TGSI_FILE_TEMPORARY
:
1168 assert(index
->i
[0] < TGSI_EXEC_NUM_TEMPS
);
1169 chan
->u
[0] = mach
->Temps
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1170 chan
->u
[1] = mach
->Temps
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1171 chan
->u
[2] = mach
->Temps
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1172 chan
->u
[3] = mach
->Temps
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1175 case TGSI_FILE_IMMEDIATE
:
1176 assert( index
->i
[0] < (int) mach
->ImmLimit
);
1177 chan
->f
[0] = mach
->Imms
[index
->i
[0]][swizzle
];
1178 assert( index
->i
[1] < (int) mach
->ImmLimit
);
1179 chan
->f
[1] = mach
->Imms
[index
->i
[1]][swizzle
];
1180 assert( index
->i
[2] < (int) mach
->ImmLimit
);
1181 chan
->f
[2] = mach
->Imms
[index
->i
[2]][swizzle
];
1182 assert( index
->i
[3] < (int) mach
->ImmLimit
);
1183 chan
->f
[3] = mach
->Imms
[index
->i
[3]][swizzle
];
1186 case TGSI_FILE_ADDRESS
:
1187 chan
->u
[0] = mach
->Addrs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1188 chan
->u
[1] = mach
->Addrs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1189 chan
->u
[2] = mach
->Addrs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1190 chan
->u
[3] = mach
->Addrs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1193 case TGSI_FILE_PREDICATE
:
1194 assert(index
->i
[0] < TGSI_EXEC_NUM_PREDS
);
1195 assert(index
->i
[1] < TGSI_EXEC_NUM_PREDS
);
1196 assert(index
->i
[2] < TGSI_EXEC_NUM_PREDS
);
1197 assert(index
->i
[3] < TGSI_EXEC_NUM_PREDS
);
1198 chan
->u
[0] = mach
->Predicates
[0].xyzw
[swizzle
].u
[0];
1199 chan
->u
[1] = mach
->Predicates
[0].xyzw
[swizzle
].u
[1];
1200 chan
->u
[2] = mach
->Predicates
[0].xyzw
[swizzle
].u
[2];
1201 chan
->u
[3] = mach
->Predicates
[0].xyzw
[swizzle
].u
[3];
1204 case TGSI_FILE_OUTPUT
:
1205 /* vertex/fragment output vars can be read too */
1206 chan
->u
[0] = mach
->Outputs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1207 chan
->u
[1] = mach
->Outputs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1208 chan
->u
[2] = mach
->Outputs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1209 chan
->u
[3] = mach
->Outputs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1224 const struct tgsi_exec_machine
*mach
,
1225 union tgsi_exec_channel
*chan
,
1226 const struct tgsi_full_src_register
*reg
,
1227 const uint chan_index
)
1229 union tgsi_exec_channel index
;
1232 /* We start with a direct index into a register file.
1236 * file = SrcRegister.File
1237 * [1] = SrcRegister.Index
1242 index
.i
[3] = reg
->SrcRegister
.Index
;
1244 /* There is an extra source register that indirectly subscripts
1245 * a register file. The direct index now becomes an offset
1246 * that is being added to the indirect register.
1250 * ind = SrcRegisterInd.File
1251 * [2] = SrcRegisterInd.Index
1252 * .x = SrcRegisterInd.SwizzleX
1254 if (reg
->SrcRegister
.Indirect
) {
1255 union tgsi_exec_channel index2
;
1256 union tgsi_exec_channel indir_index
;
1257 const uint execmask
= mach
->ExecMask
;
1260 /* which address register (always zero now) */
1264 index2
.i
[3] = reg
->SrcRegisterInd
.Index
;
1266 /* get current value of address register[swizzle] */
1267 swizzle
= tgsi_util_get_src_register_swizzle( ®
->SrcRegisterInd
, CHAN_X
);
1268 fetch_src_file_channel(
1270 reg
->SrcRegisterInd
.File
,
1275 /* add value of address register to the offset */
1276 index
.i
[0] += (int) indir_index
.f
[0];
1277 index
.i
[1] += (int) indir_index
.f
[1];
1278 index
.i
[2] += (int) indir_index
.f
[2];
1279 index
.i
[3] += (int) indir_index
.f
[3];
1281 /* for disabled execution channels, zero-out the index to
1282 * avoid using a potential garbage value.
1284 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1285 if ((execmask
& (1 << i
)) == 0)
1290 /* There is an extra source register that is a second
1291 * subscript to a register file. Effectively it means that
1292 * the register file is actually a 2D array of registers.
1294 * file[1][3] == file[1*sizeof(file[1])+3],
1296 * [3] = SrcRegisterDim.Index
1298 if (reg
->SrcRegister
.Dimension
) {
1299 /* The size of the first-order array depends on the register file type.
1300 * We need to multiply the index to the first array to get an effective,
1301 * "flat" index that points to the beginning of the second-order array.
1303 switch (reg
->SrcRegister
.File
) {
1304 case TGSI_FILE_INPUT
:
1305 index
.i
[0] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1306 index
.i
[1] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1307 index
.i
[2] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1308 index
.i
[3] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1310 case TGSI_FILE_CONSTANT
:
1311 index
.i
[0] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1312 index
.i
[1] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1313 index
.i
[2] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1314 index
.i
[3] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1320 index
.i
[0] += reg
->SrcRegisterDim
.Index
;
1321 index
.i
[1] += reg
->SrcRegisterDim
.Index
;
1322 index
.i
[2] += reg
->SrcRegisterDim
.Index
;
1323 index
.i
[3] += reg
->SrcRegisterDim
.Index
;
1325 /* Again, the second subscript index can be addressed indirectly
1326 * identically to the first one.
1327 * Nothing stops us from indirectly addressing the indirect register,
1328 * but there is no need for that, so we won't exercise it.
1330 * file[1][ind[4].y+3],
1332 * ind = SrcRegisterDimInd.File
1333 * [4] = SrcRegisterDimInd.Index
1334 * .y = SrcRegisterDimInd.SwizzleX
1336 if (reg
->SrcRegisterDim
.Indirect
) {
1337 union tgsi_exec_channel index2
;
1338 union tgsi_exec_channel indir_index
;
1339 const uint execmask
= mach
->ExecMask
;
1345 index2
.i
[3] = reg
->SrcRegisterDimInd
.Index
;
1347 swizzle
= tgsi_util_get_src_register_swizzle( ®
->SrcRegisterDimInd
, CHAN_X
);
1348 fetch_src_file_channel(
1350 reg
->SrcRegisterDimInd
.File
,
1355 index
.i
[0] += (int) indir_index
.f
[0];
1356 index
.i
[1] += (int) indir_index
.f
[1];
1357 index
.i
[2] += (int) indir_index
.f
[2];
1358 index
.i
[3] += (int) indir_index
.f
[3];
1360 /* for disabled execution channels, zero-out the index to
1361 * avoid using a potential garbage value.
1363 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1364 if ((execmask
& (1 << i
)) == 0)
1369 /* If by any chance there was a need for a 3D array of register
1370 * files, we would have to check whether SrcRegisterDim is followed
1371 * by a dimension register and continue the saga.
1375 swizzle
= tgsi_util_get_full_src_register_swizzle( reg
, chan_index
);
1376 fetch_src_file_channel(
1378 reg
->SrcRegister
.File
,
1383 switch (tgsi_util_get_full_src_register_sign_mode( reg
, chan_index
)) {
1384 case TGSI_UTIL_SIGN_CLEAR
:
1385 micro_abs( chan
, chan
);
1388 case TGSI_UTIL_SIGN_SET
:
1389 micro_abs( chan
, chan
);
1390 micro_neg( chan
, chan
);
1393 case TGSI_UTIL_SIGN_TOGGLE
:
1394 micro_neg( chan
, chan
);
1397 case TGSI_UTIL_SIGN_KEEP
:
1401 if (reg
->SrcRegisterExtMod
.Complement
) {
1402 micro_sub( chan
, &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], chan
);
1408 struct tgsi_exec_machine
*mach
,
1409 const union tgsi_exec_channel
*chan
,
1410 const struct tgsi_full_dst_register
*reg
,
1411 const struct tgsi_full_instruction
*inst
,
1415 union tgsi_exec_channel null
;
1416 union tgsi_exec_channel
*dst
;
1417 uint execmask
= mach
->ExecMask
;
1418 int offset
= 0; /* indirection offset */
1422 check_inf_or_nan(chan
);
1425 /* There is an extra source register that indirectly subscripts
1426 * a register file. The direct index now becomes an offset
1427 * that is being added to the indirect register.
1431 * ind = DstRegisterInd.File
1432 * [2] = DstRegisterInd.Index
1433 * .x = DstRegisterInd.SwizzleX
1435 if (reg
->DstRegister
.Indirect
) {
1436 union tgsi_exec_channel index
;
1437 union tgsi_exec_channel indir_index
;
1440 /* which address register (always zero for now) */
1444 index
.i
[3] = reg
->DstRegisterInd
.Index
;
1446 /* get current value of address register[swizzle] */
1447 swizzle
= tgsi_util_get_src_register_swizzle( ®
->DstRegisterInd
, CHAN_X
);
1449 /* fetch values from the address/indirection register */
1450 fetch_src_file_channel(
1452 reg
->DstRegisterInd
.File
,
1457 /* save indirection offset */
1458 offset
= (int) indir_index
.f
[0];
1461 switch (reg
->DstRegister
.File
) {
1462 case TGSI_FILE_NULL
:
1466 case TGSI_FILE_OUTPUT
:
1467 index
= mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0]
1468 + reg
->DstRegister
.Index
;
1469 dst
= &mach
->Outputs
[offset
+ index
].xyzw
[chan_index
];
1472 case TGSI_FILE_TEMPORARY
:
1473 index
= reg
->DstRegister
.Index
;
1474 assert( index
< TGSI_EXEC_NUM_TEMPS
);
1475 dst
= &mach
->Temps
[offset
+ index
].xyzw
[chan_index
];
1478 case TGSI_FILE_ADDRESS
:
1479 index
= reg
->DstRegister
.Index
;
1480 dst
= &mach
->Addrs
[index
].xyzw
[chan_index
];
1483 case TGSI_FILE_LOOP
:
1484 assert(reg
->DstRegister
.Index
== 0);
1485 assert(mach
->LoopCounterStackTop
> 0);
1486 assert(chan_index
== CHAN_X
);
1487 dst
= &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[chan_index
];
1490 case TGSI_FILE_PREDICATE
:
1491 index
= reg
->DstRegister
.Index
;
1492 assert(index
< TGSI_EXEC_NUM_PREDS
);
1493 dst
= &mach
->Predicates
[index
].xyzw
[chan_index
];
1501 if (inst
->Instruction
.Predicate
) {
1503 union tgsi_exec_channel
*pred
;
1505 switch (chan_index
) {
1507 swizzle
= inst
->InstructionPredicate
.SwizzleX
;
1510 swizzle
= inst
->InstructionPredicate
.SwizzleY
;
1513 swizzle
= inst
->InstructionPredicate
.SwizzleZ
;
1516 swizzle
= inst
->InstructionPredicate
.SwizzleW
;
1523 assert(inst
->InstructionPredicate
.Index
== 0);
1525 pred
= &mach
->Predicates
[inst
->InstructionPredicate
.Index
].xyzw
[swizzle
];
1527 if (inst
->InstructionPredicate
.Negate
) {
1528 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1530 execmask
&= ~(1 << i
);
1534 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1536 execmask
&= ~(1 << i
);
1542 switch (inst
->Instruction
.Saturate
) {
1544 for (i
= 0; i
< QUAD_SIZE
; i
++)
1545 if (execmask
& (1 << i
))
1546 dst
->i
[i
] = chan
->i
[i
];
1549 case TGSI_SAT_ZERO_ONE
:
1550 for (i
= 0; i
< QUAD_SIZE
; i
++)
1551 if (execmask
& (1 << i
)) {
1552 if (chan
->f
[i
] < 0.0f
)
1554 else if (chan
->f
[i
] > 1.0f
)
1557 dst
->i
[i
] = chan
->i
[i
];
1561 case TGSI_SAT_MINUS_PLUS_ONE
:
1562 for (i
= 0; i
< QUAD_SIZE
; i
++)
1563 if (execmask
& (1 << i
)) {
1564 if (chan
->f
[i
] < -1.0f
)
1566 else if (chan
->f
[i
] > 1.0f
)
1569 dst
->i
[i
] = chan
->i
[i
];
1578 #define FETCH(VAL,INDEX,CHAN)\
1579 fetch_source (mach, VAL, &inst->FullSrcRegisters[INDEX], CHAN)
1581 #define STORE(VAL,INDEX,CHAN)\
1582 store_dest (mach, VAL, &inst->FullDstRegisters[INDEX], inst, CHAN )
1586 * Execute ARB-style KIL which is predicated by a src register.
1587 * Kill fragment if any of the four values is less than zero.
1590 exec_kil(struct tgsi_exec_machine
*mach
,
1591 const struct tgsi_full_instruction
*inst
)
1595 uint kilmask
= 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1596 union tgsi_exec_channel r
[1];
1598 /* This mask stores component bits that were already tested. */
1601 for (chan_index
= 0; chan_index
< 4; chan_index
++)
1606 /* unswizzle channel */
1607 swizzle
= tgsi_util_get_full_src_register_swizzle (
1608 &inst
->FullSrcRegisters
[0],
1611 /* check if the component has not been already tested */
1612 if (uniquemask
& (1 << swizzle
))
1614 uniquemask
|= 1 << swizzle
;
1616 FETCH(&r
[0], 0, chan_index
);
1617 for (i
= 0; i
< 4; i
++)
1618 if (r
[0].f
[i
] < 0.0f
)
1622 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1626 * Execute NVIDIA-style KIL which is predicated by a condition code.
1627 * Kill fragment if the condition code is TRUE.
1630 exec_kilp(struct tgsi_exec_machine
*mach
,
1631 const struct tgsi_full_instruction
*inst
)
1633 uint kilmask
; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1635 /* "unconditional" kil */
1636 kilmask
= mach
->ExecMask
;
1637 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1642 * Fetch a four texture samples using STR texture coordinates.
1645 fetch_texel( struct tgsi_sampler
*sampler
,
1646 const union tgsi_exec_channel
*s
,
1647 const union tgsi_exec_channel
*t
,
1648 const union tgsi_exec_channel
*p
,
1649 float lodbias
, /* XXX should be float[4] */
1650 union tgsi_exec_channel
*r
,
1651 union tgsi_exec_channel
*g
,
1652 union tgsi_exec_channel
*b
,
1653 union tgsi_exec_channel
*a
)
1656 float rgba
[NUM_CHANNELS
][QUAD_SIZE
];
1658 sampler
->get_samples(sampler
, s
->f
, t
->f
, p
->f
, lodbias
, rgba
);
1660 for (j
= 0; j
< 4; j
++) {
1661 r
->f
[j
] = rgba
[0][j
];
1662 g
->f
[j
] = rgba
[1][j
];
1663 b
->f
[j
] = rgba
[2][j
];
1664 a
->f
[j
] = rgba
[3][j
];
1670 exec_tex(struct tgsi_exec_machine
*mach
,
1671 const struct tgsi_full_instruction
*inst
,
1675 const uint unit
= inst
->FullSrcRegisters
[1].SrcRegister
.Index
;
1676 union tgsi_exec_channel r
[4];
1680 /* debug_printf("Sampler %u unit %u\n", sampler, unit); */
1682 switch (inst
->InstructionExtTexture
.Texture
) {
1683 case TGSI_TEXTURE_1D
:
1684 case TGSI_TEXTURE_SHADOW1D
:
1686 FETCH(&r
[0], 0, CHAN_X
);
1689 FETCH(&r
[1], 0, CHAN_W
);
1690 micro_div( &r
[0], &r
[0], &r
[1] );
1694 FETCH(&r
[1], 0, CHAN_W
);
1695 lodBias
= r
[2].f
[0];
1700 fetch_texel(mach
->Samplers
[unit
],
1701 &r
[0], &ZeroVec
, &ZeroVec
, lodBias
, /* S, T, P, BIAS */
1702 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1705 case TGSI_TEXTURE_2D
:
1706 case TGSI_TEXTURE_RECT
:
1707 case TGSI_TEXTURE_SHADOW2D
:
1708 case TGSI_TEXTURE_SHADOWRECT
:
1710 FETCH(&r
[0], 0, CHAN_X
);
1711 FETCH(&r
[1], 0, CHAN_Y
);
1712 FETCH(&r
[2], 0, CHAN_Z
);
1715 FETCH(&r
[3], 0, CHAN_W
);
1716 micro_div( &r
[0], &r
[0], &r
[3] );
1717 micro_div( &r
[1], &r
[1], &r
[3] );
1718 micro_div( &r
[2], &r
[2], &r
[3] );
1722 FETCH(&r
[3], 0, CHAN_W
);
1723 lodBias
= r
[3].f
[0];
1728 fetch_texel(mach
->Samplers
[unit
],
1729 &r
[0], &r
[1], &r
[2], lodBias
, /* inputs */
1730 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1733 case TGSI_TEXTURE_3D
:
1734 case TGSI_TEXTURE_CUBE
:
1736 FETCH(&r
[0], 0, CHAN_X
);
1737 FETCH(&r
[1], 0, CHAN_Y
);
1738 FETCH(&r
[2], 0, CHAN_Z
);
1741 FETCH(&r
[3], 0, CHAN_W
);
1742 micro_div( &r
[0], &r
[0], &r
[3] );
1743 micro_div( &r
[1], &r
[1], &r
[3] );
1744 micro_div( &r
[2], &r
[2], &r
[3] );
1748 FETCH(&r
[3], 0, CHAN_W
);
1749 lodBias
= r
[3].f
[0];
1754 fetch_texel(mach
->Samplers
[unit
],
1755 &r
[0], &r
[1], &r
[2], lodBias
,
1756 &r
[0], &r
[1], &r
[2], &r
[3]);
1763 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1764 STORE( &r
[chan_index
], 0, chan_index
);
1769 exec_txd(struct tgsi_exec_machine
*mach
,
1770 const struct tgsi_full_instruction
*inst
)
1772 const uint unit
= inst
->FullSrcRegisters
[3].SrcRegister
.Index
;
1773 union tgsi_exec_channel r
[4];
1777 * XXX: This is fake TXD -- the derivatives are not taken into account, yet.
1780 switch (inst
->InstructionExtTexture
.Texture
) {
1781 case TGSI_TEXTURE_1D
:
1782 case TGSI_TEXTURE_SHADOW1D
:
1784 FETCH(&r
[0], 0, CHAN_X
);
1786 fetch_texel(mach
->Samplers
[unit
],
1787 &r
[0], &ZeroVec
, &ZeroVec
, 0.0f
, /* S, T, P, BIAS */
1788 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1791 case TGSI_TEXTURE_2D
:
1792 case TGSI_TEXTURE_RECT
:
1793 case TGSI_TEXTURE_SHADOW2D
:
1794 case TGSI_TEXTURE_SHADOWRECT
:
1796 FETCH(&r
[0], 0, CHAN_X
);
1797 FETCH(&r
[1], 0, CHAN_Y
);
1798 FETCH(&r
[2], 0, CHAN_Z
);
1800 fetch_texel(mach
->Samplers
[unit
],
1801 &r
[0], &r
[1], &r
[2], 0.0f
, /* inputs */
1802 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1805 case TGSI_TEXTURE_3D
:
1806 case TGSI_TEXTURE_CUBE
:
1808 FETCH(&r
[0], 0, CHAN_X
);
1809 FETCH(&r
[1], 0, CHAN_Y
);
1810 FETCH(&r
[2], 0, CHAN_Z
);
1812 fetch_texel(mach
->Samplers
[unit
],
1813 &r
[0], &r
[1], &r
[2], 0.0f
,
1814 &r
[0], &r
[1], &r
[2], &r
[3]);
1821 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
1822 STORE(&r
[chan_index
], 0, chan_index
);
1828 * Evaluate a constant-valued coefficient at the position of the
1833 struct tgsi_exec_machine
*mach
,
1839 for( i
= 0; i
< QUAD_SIZE
; i
++ ) {
1840 mach
->Inputs
[attrib
].xyzw
[chan
].f
[i
] = mach
->InterpCoefs
[attrib
].a0
[chan
];
1845 * Evaluate a linear-valued coefficient at the position of the
1850 struct tgsi_exec_machine
*mach
,
1854 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1855 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1856 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1857 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1858 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1859 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
;
1860 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = a0
+ dadx
;
1861 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = a0
+ dady
;
1862 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = a0
+ dadx
+ dady
;
1866 * Evaluate a perspective-valued coefficient at the position of the
1870 eval_perspective_coef(
1871 struct tgsi_exec_machine
*mach
,
1875 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1876 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1877 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1878 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1879 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1880 const float *w
= mach
->QuadPos
.xyzw
[3].f
;
1881 /* divide by W here */
1882 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
/ w
[0];
1883 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = (a0
+ dadx
) / w
[1];
1884 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = (a0
+ dady
) / w
[2];
1885 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = (a0
+ dadx
+ dady
) / w
[3];
1889 typedef void (* eval_coef_func
)(
1890 struct tgsi_exec_machine
*mach
,
1895 exec_declaration(struct tgsi_exec_machine
*mach
,
1896 const struct tgsi_full_declaration
*decl
)
1898 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
1899 if (decl
->Declaration
.File
== TGSI_FILE_INPUT
) {
1900 uint first
, last
, mask
;
1902 first
= decl
->DeclarationRange
.First
;
1903 last
= decl
->DeclarationRange
.Last
;
1904 mask
= decl
->Declaration
.UsageMask
;
1906 if (decl
->Semantic
.SemanticName
== TGSI_SEMANTIC_POSITION
) {
1907 assert(decl
->Semantic
.SemanticIndex
== 0);
1908 assert(first
== last
);
1909 assert(mask
= TGSI_WRITEMASK_XYZW
);
1911 mach
->Inputs
[first
] = mach
->QuadPos
;
1912 } else if (decl
->Semantic
.SemanticName
== TGSI_SEMANTIC_FACE
) {
1915 assert(decl
->Semantic
.SemanticIndex
== 0);
1916 assert(first
== last
);
1918 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1919 mach
->Inputs
[first
].xyzw
[0].f
[i
] = mach
->Face
;
1922 eval_coef_func eval
;
1925 switch (decl
->Declaration
.Interpolate
) {
1926 case TGSI_INTERPOLATE_CONSTANT
:
1927 eval
= eval_constant_coef
;
1930 case TGSI_INTERPOLATE_LINEAR
:
1931 eval
= eval_linear_coef
;
1934 case TGSI_INTERPOLATE_PERSPECTIVE
:
1935 eval
= eval_perspective_coef
;
1943 for (j
= 0; j
< NUM_CHANNELS
; j
++) {
1944 if (mask
& (1 << j
)) {
1945 for (i
= first
; i
<= last
; i
++) {
1957 struct tgsi_exec_machine
*mach
,
1958 const struct tgsi_full_instruction
*inst
,
1962 union tgsi_exec_channel r
[10];
1963 union tgsi_exec_channel d
[8];
1967 switch (inst
->Instruction
.Opcode
) {
1968 case TGSI_OPCODE_ARL
:
1969 case TGSI_OPCODE_FLR
:
1970 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1971 FETCH( &r
[0], 0, chan_index
);
1972 micro_flr(&d
[chan_index
], &r
[0]);
1974 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
1975 STORE(&d
[chan_index
], 0, chan_index
);
1979 case TGSI_OPCODE_MOV
:
1980 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1981 FETCH(&d
[chan_index
], 0, chan_index
);
1983 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1984 STORE(&d
[chan_index
], 0, chan_index
);
1988 case TGSI_OPCODE_LIT
:
1989 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
1990 FETCH( &r
[0], 0, CHAN_X
);
1991 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
1992 micro_max(&d
[CHAN_Y
], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
1995 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
1996 FETCH( &r
[1], 0, CHAN_Y
);
1997 micro_max( &r
[1], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
1999 FETCH( &r
[2], 0, CHAN_W
);
2000 micro_min( &r
[2], &r
[2], &mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
] );
2001 micro_max( &r
[2], &r
[2], &mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
] );
2002 micro_pow( &r
[1], &r
[1], &r
[2] );
2003 micro_lt(&d
[CHAN_Z
], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &r
[0], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
2006 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2007 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2009 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2010 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2013 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2014 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2016 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2017 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2021 case TGSI_OPCODE_RCP
:
2022 /* TGSI_OPCODE_RECIP */
2023 FETCH( &r
[0], 0, CHAN_X
);
2024 micro_div( &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0] );
2025 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2026 STORE( &r
[0], 0, chan_index
);
2030 case TGSI_OPCODE_RSQ
:
2031 /* TGSI_OPCODE_RECIPSQRT */
2032 FETCH( &r
[0], 0, CHAN_X
);
2033 micro_abs( &r
[0], &r
[0] );
2034 micro_sqrt( &r
[0], &r
[0] );
2035 micro_div( &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0] );
2036 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2037 STORE( &r
[0], 0, chan_index
);
2041 case TGSI_OPCODE_EXP
:
2042 FETCH( &r
[0], 0, CHAN_X
);
2043 micro_flr( &r
[1], &r
[0] ); /* r1 = floor(r0) */
2044 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2045 micro_exp2( &r
[2], &r
[1] ); /* r2 = 2 ^ r1 */
2046 STORE( &r
[2], 0, CHAN_X
); /* store r2 */
2048 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2049 micro_sub( &r
[2], &r
[0], &r
[1] ); /* r2 = r0 - r1 */
2050 STORE( &r
[2], 0, CHAN_Y
); /* store r2 */
2052 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2053 micro_exp2( &r
[2], &r
[0] ); /* r2 = 2 ^ r0 */
2054 STORE( &r
[2], 0, CHAN_Z
); /* store r2 */
2056 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2057 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2061 case TGSI_OPCODE_LOG
:
2062 FETCH( &r
[0], 0, CHAN_X
);
2063 micro_abs( &r
[2], &r
[0] ); /* r2 = abs(r0) */
2064 micro_lg2( &r
[1], &r
[2] ); /* r1 = lg2(r2) */
2065 micro_flr( &r
[0], &r
[1] ); /* r0 = floor(r1) */
2066 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2067 STORE( &r
[0], 0, CHAN_X
);
2069 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2070 micro_exp2( &r
[0], &r
[0] ); /* r0 = 2 ^ r0 */
2071 micro_div( &r
[0], &r
[2], &r
[0] ); /* r0 = r2 / r0 */
2072 STORE( &r
[0], 0, CHAN_Y
);
2074 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2075 STORE( &r
[1], 0, CHAN_Z
);
2077 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2078 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2082 case TGSI_OPCODE_MUL
:
2083 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2084 FETCH(&r
[0], 0, chan_index
);
2085 FETCH(&r
[1], 1, chan_index
);
2086 micro_mul(&d
[chan_index
], &r
[0], &r
[1]);
2088 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2089 STORE(&d
[chan_index
], 0, chan_index
);
2093 case TGSI_OPCODE_ADD
:
2094 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2095 FETCH( &r
[0], 0, chan_index
);
2096 FETCH( &r
[1], 1, chan_index
);
2097 micro_add(&d
[chan_index
], &r
[0], &r
[1]);
2099 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2100 STORE(&d
[chan_index
], 0, chan_index
);
2104 case TGSI_OPCODE_DP3
:
2105 /* TGSI_OPCODE_DOT3 */
2106 FETCH( &r
[0], 0, CHAN_X
);
2107 FETCH( &r
[1], 1, CHAN_X
);
2108 micro_mul( &r
[0], &r
[0], &r
[1] );
2110 FETCH( &r
[1], 0, CHAN_Y
);
2111 FETCH( &r
[2], 1, CHAN_Y
);
2112 micro_mul( &r
[1], &r
[1], &r
[2] );
2113 micro_add( &r
[0], &r
[0], &r
[1] );
2115 FETCH( &r
[1], 0, CHAN_Z
);
2116 FETCH( &r
[2], 1, CHAN_Z
);
2117 micro_mul( &r
[1], &r
[1], &r
[2] );
2118 micro_add( &r
[0], &r
[0], &r
[1] );
2120 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2121 STORE( &r
[0], 0, chan_index
);
2125 case TGSI_OPCODE_DP4
:
2126 /* TGSI_OPCODE_DOT4 */
2127 FETCH(&r
[0], 0, CHAN_X
);
2128 FETCH(&r
[1], 1, CHAN_X
);
2130 micro_mul( &r
[0], &r
[0], &r
[1] );
2132 FETCH(&r
[1], 0, CHAN_Y
);
2133 FETCH(&r
[2], 1, CHAN_Y
);
2135 micro_mul( &r
[1], &r
[1], &r
[2] );
2136 micro_add( &r
[0], &r
[0], &r
[1] );
2138 FETCH(&r
[1], 0, CHAN_Z
);
2139 FETCH(&r
[2], 1, CHAN_Z
);
2141 micro_mul( &r
[1], &r
[1], &r
[2] );
2142 micro_add( &r
[0], &r
[0], &r
[1] );
2144 FETCH(&r
[1], 0, CHAN_W
);
2145 FETCH(&r
[2], 1, CHAN_W
);
2147 micro_mul( &r
[1], &r
[1], &r
[2] );
2148 micro_add( &r
[0], &r
[0], &r
[1] );
2150 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2151 STORE( &r
[0], 0, chan_index
);
2155 case TGSI_OPCODE_DST
:
2156 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2157 FETCH( &r
[0], 0, CHAN_Y
);
2158 FETCH( &r
[1], 1, CHAN_Y
);
2159 micro_mul(&d
[CHAN_Y
], &r
[0], &r
[1]);
2161 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2162 FETCH(&d
[CHAN_Z
], 0, CHAN_Z
);
2164 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2165 FETCH(&d
[CHAN_W
], 1, CHAN_W
);
2168 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2169 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2171 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2172 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2174 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2175 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2177 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2178 STORE(&d
[CHAN_W
], 0, CHAN_W
);
2182 case TGSI_OPCODE_MIN
:
2183 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2184 FETCH(&r
[0], 0, chan_index
);
2185 FETCH(&r
[1], 1, chan_index
);
2187 /* XXX use micro_min()?? */
2188 micro_lt(&d
[chan_index
], &r
[0], &r
[1], &r
[0], &r
[1]);
2190 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2191 STORE(&d
[chan_index
], 0, chan_index
);
2195 case TGSI_OPCODE_MAX
:
2196 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2197 FETCH(&r
[0], 0, chan_index
);
2198 FETCH(&r
[1], 1, chan_index
);
2200 /* XXX use micro_max()?? */
2201 micro_lt(&d
[chan_index
], &r
[0], &r
[1], &r
[1], &r
[0] );
2203 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2204 STORE(&d
[chan_index
], 0, chan_index
);
2208 case TGSI_OPCODE_SLT
:
2209 /* TGSI_OPCODE_SETLT */
2210 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2211 FETCH( &r
[0], 0, chan_index
);
2212 FETCH( &r
[1], 1, chan_index
);
2213 micro_lt(&d
[chan_index
], &r
[0], &r
[1], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
2215 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2216 STORE(&d
[chan_index
], 0, chan_index
);
2220 case TGSI_OPCODE_SGE
:
2221 /* TGSI_OPCODE_SETGE */
2222 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2223 FETCH( &r
[0], 0, chan_index
);
2224 FETCH( &r
[1], 1, chan_index
);
2225 micro_le(&d
[chan_index
], &r
[1], &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
2227 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2228 STORE(&d
[chan_index
], 0, chan_index
);
2232 case TGSI_OPCODE_MAD
:
2233 /* TGSI_OPCODE_MADD */
2234 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2235 FETCH( &r
[0], 0, chan_index
);
2236 FETCH( &r
[1], 1, chan_index
);
2237 micro_mul( &r
[0], &r
[0], &r
[1] );
2238 FETCH( &r
[1], 2, chan_index
);
2239 micro_add(&d
[chan_index
], &r
[0], &r
[1]);
2241 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2242 STORE(&d
[chan_index
], 0, chan_index
);
2246 case TGSI_OPCODE_SUB
:
2247 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2248 FETCH(&r
[0], 0, chan_index
);
2249 FETCH(&r
[1], 1, chan_index
);
2250 micro_sub(&d
[chan_index
], &r
[0], &r
[1]);
2252 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2253 STORE(&d
[chan_index
], 0, chan_index
);
2257 case TGSI_OPCODE_LRP
:
2258 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2259 FETCH(&r
[0], 0, chan_index
);
2260 FETCH(&r
[1], 1, chan_index
);
2261 FETCH(&r
[2], 2, chan_index
);
2262 micro_sub( &r
[1], &r
[1], &r
[2] );
2263 micro_mul( &r
[0], &r
[0], &r
[1] );
2264 micro_add(&d
[chan_index
], &r
[0], &r
[2]);
2266 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2267 STORE(&d
[chan_index
], 0, chan_index
);
2271 case TGSI_OPCODE_CND
:
2272 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2273 FETCH(&r
[0], 0, chan_index
);
2274 FETCH(&r
[1], 1, chan_index
);
2275 FETCH(&r
[2], 2, chan_index
);
2276 micro_lt(&d
[chan_index
], &mach
->Temps
[TEMP_HALF_I
].xyzw
[TEMP_HALF_C
], &r
[2], &r
[0], &r
[1]);
2278 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2279 STORE(&d
[chan_index
], 0, chan_index
);
2283 case TGSI_OPCODE_DP2A
:
2284 FETCH( &r
[0], 0, CHAN_X
);
2285 FETCH( &r
[1], 1, CHAN_X
);
2286 micro_mul( &r
[0], &r
[0], &r
[1] );
2288 FETCH( &r
[1], 0, CHAN_Y
);
2289 FETCH( &r
[2], 1, CHAN_Y
);
2290 micro_mul( &r
[1], &r
[1], &r
[2] );
2291 micro_add( &r
[0], &r
[0], &r
[1] );
2293 FETCH( &r
[2], 2, CHAN_X
);
2294 micro_add( &r
[0], &r
[0], &r
[2] );
2296 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2297 STORE( &r
[0], 0, chan_index
);
2301 case TGSI_OPCODE_FRC
:
2302 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2303 FETCH( &r
[0], 0, chan_index
);
2304 micro_frc(&d
[chan_index
], &r
[0]);
2306 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2307 STORE(&d
[chan_index
], 0, chan_index
);
2311 case TGSI_OPCODE_CLAMP
:
2312 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2313 FETCH(&r
[0], 0, chan_index
);
2314 FETCH(&r
[1], 1, chan_index
);
2315 micro_max(&r
[0], &r
[0], &r
[1]);
2316 FETCH(&r
[1], 2, chan_index
);
2317 micro_min(&d
[chan_index
], &r
[0], &r
[1]);
2319 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2320 STORE(&d
[chan_index
], 0, chan_index
);
2324 case TGSI_OPCODE_ROUND
:
2325 case TGSI_OPCODE_ARR
:
2326 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2327 FETCH( &r
[0], 0, chan_index
);
2328 micro_rnd(&d
[chan_index
], &r
[0]);
2330 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2331 STORE(&d
[chan_index
], 0, chan_index
);
2335 case TGSI_OPCODE_EX2
:
2336 FETCH(&r
[0], 0, CHAN_X
);
2338 micro_exp2( &r
[0], &r
[0] );
2340 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2341 STORE( &r
[0], 0, chan_index
);
2345 case TGSI_OPCODE_LG2
:
2346 FETCH( &r
[0], 0, CHAN_X
);
2347 micro_lg2( &r
[0], &r
[0] );
2348 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2349 STORE( &r
[0], 0, chan_index
);
2353 case TGSI_OPCODE_POW
:
2354 FETCH(&r
[0], 0, CHAN_X
);
2355 FETCH(&r
[1], 1, CHAN_X
);
2357 micro_pow( &r
[0], &r
[0], &r
[1] );
2359 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2360 STORE( &r
[0], 0, chan_index
);
2364 case TGSI_OPCODE_XPD
:
2365 FETCH(&r
[0], 0, CHAN_Y
);
2366 FETCH(&r
[1], 1, CHAN_Z
);
2368 micro_mul( &r
[2], &r
[0], &r
[1] );
2370 FETCH(&r
[3], 0, CHAN_Z
);
2371 FETCH(&r
[4], 1, CHAN_Y
);
2373 micro_mul( &r
[5], &r
[3], &r
[4] );
2374 micro_sub(&d
[CHAN_X
], &r
[2], &r
[5]);
2376 FETCH(&r
[2], 1, CHAN_X
);
2378 micro_mul( &r
[3], &r
[3], &r
[2] );
2380 FETCH(&r
[5], 0, CHAN_X
);
2382 micro_mul( &r
[1], &r
[1], &r
[5] );
2383 micro_sub(&d
[CHAN_Y
], &r
[3], &r
[1]);
2385 micro_mul( &r
[5], &r
[5], &r
[4] );
2386 micro_mul( &r
[0], &r
[0], &r
[2] );
2387 micro_sub(&d
[CHAN_Z
], &r
[5], &r
[0]);
2389 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2390 STORE(&d
[CHAN_X
], 0, CHAN_X
);
2392 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2393 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2395 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2396 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2398 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2399 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2403 case TGSI_OPCODE_ABS
:
2404 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2405 FETCH(&r
[0], 0, chan_index
);
2406 micro_abs(&d
[chan_index
], &r
[0]);
2408 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2409 STORE(&d
[chan_index
], 0, chan_index
);
2413 case TGSI_OPCODE_RCC
:
2414 FETCH(&r
[0], 0, CHAN_X
);
2415 micro_div(&r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0]);
2416 micro_float_clamp(&r
[0], &r
[0]);
2417 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2418 STORE(&r
[0], 0, chan_index
);
2422 case TGSI_OPCODE_DPH
:
2423 FETCH(&r
[0], 0, CHAN_X
);
2424 FETCH(&r
[1], 1, CHAN_X
);
2426 micro_mul( &r
[0], &r
[0], &r
[1] );
2428 FETCH(&r
[1], 0, CHAN_Y
);
2429 FETCH(&r
[2], 1, CHAN_Y
);
2431 micro_mul( &r
[1], &r
[1], &r
[2] );
2432 micro_add( &r
[0], &r
[0], &r
[1] );
2434 FETCH(&r
[1], 0, CHAN_Z
);
2435 FETCH(&r
[2], 1, CHAN_Z
);
2437 micro_mul( &r
[1], &r
[1], &r
[2] );
2438 micro_add( &r
[0], &r
[0], &r
[1] );
2440 FETCH(&r
[1], 1, CHAN_W
);
2442 micro_add( &r
[0], &r
[0], &r
[1] );
2444 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2445 STORE( &r
[0], 0, chan_index
);
2449 case TGSI_OPCODE_COS
:
2450 FETCH(&r
[0], 0, CHAN_X
);
2452 micro_cos( &r
[0], &r
[0] );
2454 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2455 STORE( &r
[0], 0, chan_index
);
2459 case TGSI_OPCODE_DDX
:
2460 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2461 FETCH( &r
[0], 0, chan_index
);
2462 micro_ddx(&d
[chan_index
], &r
[0]);
2464 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2465 STORE(&d
[chan_index
], 0, chan_index
);
2469 case TGSI_OPCODE_DDY
:
2470 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2471 FETCH( &r
[0], 0, chan_index
);
2472 micro_ddy(&d
[chan_index
], &r
[0]);
2474 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2475 STORE(&d
[chan_index
], 0, chan_index
);
2479 case TGSI_OPCODE_KILP
:
2480 exec_kilp (mach
, inst
);
2483 case TGSI_OPCODE_KIL
:
2484 exec_kil (mach
, inst
);
2487 case TGSI_OPCODE_PK2H
:
2491 case TGSI_OPCODE_PK2US
:
2495 case TGSI_OPCODE_PK4B
:
2499 case TGSI_OPCODE_PK4UB
:
2503 case TGSI_OPCODE_RFL
:
2504 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2505 IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2506 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2507 /* r0 = dp3(src0, src0) */
2508 FETCH(&r
[2], 0, CHAN_X
);
2509 micro_mul(&r
[0], &r
[2], &r
[2]);
2510 FETCH(&r
[4], 0, CHAN_Y
);
2511 micro_mul(&r
[8], &r
[4], &r
[4]);
2512 micro_add(&r
[0], &r
[0], &r
[8]);
2513 FETCH(&r
[6], 0, CHAN_Z
);
2514 micro_mul(&r
[8], &r
[6], &r
[6]);
2515 micro_add(&r
[0], &r
[0], &r
[8]);
2517 /* r1 = dp3(src0, src1) */
2518 FETCH(&r
[3], 1, CHAN_X
);
2519 micro_mul(&r
[1], &r
[2], &r
[3]);
2520 FETCH(&r
[5], 1, CHAN_Y
);
2521 micro_mul(&r
[8], &r
[4], &r
[5]);
2522 micro_add(&r
[1], &r
[1], &r
[8]);
2523 FETCH(&r
[7], 1, CHAN_Z
);
2524 micro_mul(&r
[8], &r
[6], &r
[7]);
2525 micro_add(&r
[1], &r
[1], &r
[8]);
2527 /* r1 = 2 * r1 / r0 */
2528 micro_add(&r
[1], &r
[1], &r
[1]);
2529 micro_div(&r
[1], &r
[1], &r
[0]);
2531 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2532 micro_mul(&r
[2], &r
[2], &r
[1]);
2533 micro_sub(&r
[2], &r
[2], &r
[3]);
2534 STORE(&r
[2], 0, CHAN_X
);
2536 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2537 micro_mul(&r
[4], &r
[4], &r
[1]);
2538 micro_sub(&r
[4], &r
[4], &r
[5]);
2539 STORE(&r
[4], 0, CHAN_Y
);
2541 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2542 micro_mul(&r
[6], &r
[6], &r
[1]);
2543 micro_sub(&r
[6], &r
[6], &r
[7]);
2544 STORE(&r
[6], 0, CHAN_Z
);
2547 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2548 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2552 case TGSI_OPCODE_SEQ
:
2553 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2554 FETCH( &r
[0], 0, chan_index
);
2555 FETCH( &r
[1], 1, chan_index
);
2556 micro_eq(&d
[chan_index
], &r
[0], &r
[1], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
2558 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2559 STORE(&d
[chan_index
], 0, chan_index
);
2563 case TGSI_OPCODE_SFL
:
2564 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2565 STORE(&mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, chan_index
);
2569 case TGSI_OPCODE_SGT
:
2570 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2571 FETCH( &r
[0], 0, chan_index
);
2572 FETCH( &r
[1], 1, chan_index
);
2573 micro_le(&d
[chan_index
], &r
[0], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
]);
2575 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2576 STORE(&d
[chan_index
], 0, chan_index
);
2580 case TGSI_OPCODE_SIN
:
2581 FETCH( &r
[0], 0, CHAN_X
);
2582 micro_sin( &r
[0], &r
[0] );
2583 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2584 STORE( &r
[0], 0, chan_index
);
2588 case TGSI_OPCODE_SLE
:
2589 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2590 FETCH( &r
[0], 0, chan_index
);
2591 FETCH( &r
[1], 1, chan_index
);
2592 micro_le(&d
[chan_index
], &r
[0], &r
[1], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
2594 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2595 STORE(&d
[chan_index
], 0, chan_index
);
2599 case TGSI_OPCODE_SNE
:
2600 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2601 FETCH( &r
[0], 0, chan_index
);
2602 FETCH( &r
[1], 1, chan_index
);
2603 micro_eq(&d
[chan_index
], &r
[0], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
]);
2605 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2606 STORE(&d
[chan_index
], 0, chan_index
);
2610 case TGSI_OPCODE_STR
:
2611 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2612 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, chan_index
);
2616 case TGSI_OPCODE_TEX
:
2617 /* simple texture lookup */
2618 /* src[0] = texcoord */
2619 /* src[1] = sampler unit */
2620 exec_tex(mach
, inst
, FALSE
, FALSE
);
2623 case TGSI_OPCODE_TXB
:
2624 /* Texture lookup with lod bias */
2625 /* src[0] = texcoord (src[0].w = LOD bias) */
2626 /* src[1] = sampler unit */
2627 exec_tex(mach
, inst
, TRUE
, FALSE
);
2630 case TGSI_OPCODE_TXD
:
2631 /* Texture lookup with explict partial derivatives */
2632 /* src[0] = texcoord */
2633 /* src[1] = d[strq]/dx */
2634 /* src[2] = d[strq]/dy */
2635 /* src[3] = sampler unit */
2636 exec_txd(mach
, inst
);
2639 case TGSI_OPCODE_TXL
:
2640 /* Texture lookup with explit LOD */
2641 /* src[0] = texcoord (src[0].w = LOD) */
2642 /* src[1] = sampler unit */
2643 exec_tex(mach
, inst
, TRUE
, FALSE
);
2646 case TGSI_OPCODE_TXP
:
2647 /* Texture lookup with projection */
2648 /* src[0] = texcoord (src[0].w = projection) */
2649 /* src[1] = sampler unit */
2650 exec_tex(mach
, inst
, FALSE
, TRUE
);
2653 case TGSI_OPCODE_UP2H
:
2657 case TGSI_OPCODE_UP2US
:
2661 case TGSI_OPCODE_UP4B
:
2665 case TGSI_OPCODE_UP4UB
:
2669 case TGSI_OPCODE_X2D
:
2670 FETCH(&r
[0], 1, CHAN_X
);
2671 FETCH(&r
[1], 1, CHAN_Y
);
2672 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2673 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2674 FETCH(&r
[2], 2, CHAN_X
);
2675 micro_mul(&r
[2], &r
[2], &r
[0]);
2676 FETCH(&r
[3], 2, CHAN_Y
);
2677 micro_mul(&r
[3], &r
[3], &r
[1]);
2678 micro_add(&r
[2], &r
[2], &r
[3]);
2679 FETCH(&r
[3], 0, CHAN_X
);
2680 micro_add(&d
[CHAN_X
], &r
[2], &r
[3]);
2683 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2684 IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2685 FETCH(&r
[2], 2, CHAN_Z
);
2686 micro_mul(&r
[2], &r
[2], &r
[0]);
2687 FETCH(&r
[3], 2, CHAN_W
);
2688 micro_mul(&r
[3], &r
[3], &r
[1]);
2689 micro_add(&r
[2], &r
[2], &r
[3]);
2690 FETCH(&r
[3], 0, CHAN_Y
);
2691 micro_add(&d
[CHAN_Y
], &r
[2], &r
[3]);
2694 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2695 STORE(&d
[CHAN_X
], 0, CHAN_X
);
2697 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2698 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2700 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2701 STORE(&d
[CHAN_X
], 0, CHAN_Z
);
2703 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2704 STORE(&d
[CHAN_Y
], 0, CHAN_W
);
2708 case TGSI_OPCODE_ARA
:
2712 case TGSI_OPCODE_BRA
:
2716 case TGSI_OPCODE_CAL
:
2717 /* skip the call if no execution channels are enabled */
2718 if (mach
->ExecMask
) {
2721 /* First, record the depths of the execution stacks.
2722 * This is important for deeply nested/looped return statements.
2723 * We have to unwind the stacks by the correct amount. For a
2724 * real code generator, we could determine the number of entries
2725 * to pop off each stack with simple static analysis and avoid
2726 * implementing this data structure at run time.
2728 mach
->CallStack
[mach
->CallStackTop
].CondStackTop
= mach
->CondStackTop
;
2729 mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
= mach
->LoopStackTop
;
2730 mach
->CallStack
[mach
->CallStackTop
].ContStackTop
= mach
->ContStackTop
;
2731 /* note that PC was already incremented above */
2732 mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
= *pc
;
2734 mach
->CallStackTop
++;
2736 /* Second, push the Cond, Loop, Cont, Func stacks */
2737 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
2738 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
2739 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2740 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
2741 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2742 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
2743 assert(mach
->FuncStackTop
< TGSI_EXEC_MAX_CALL_NESTING
);
2744 mach
->FuncStack
[mach
->FuncStackTop
++] = mach
->FuncMask
;
2746 /* Finally, jump to the subroutine */
2747 *pc
= inst
->InstructionExtLabel
.Label
;
2751 case TGSI_OPCODE_RET
:
2752 mach
->FuncMask
&= ~mach
->ExecMask
;
2753 UPDATE_EXEC_MASK(mach
);
2755 if (mach
->FuncMask
== 0x0) {
2756 /* really return now (otherwise, keep executing */
2758 if (mach
->CallStackTop
== 0) {
2759 /* returning from main() */
2764 assert(mach
->CallStackTop
> 0);
2765 mach
->CallStackTop
--;
2767 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
2768 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
2770 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
2771 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
2773 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
2774 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
2776 assert(mach
->FuncStackTop
> 0);
2777 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
2779 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
2781 UPDATE_EXEC_MASK(mach
);
2785 case TGSI_OPCODE_SSG
:
2786 /* TGSI_OPCODE_SGN */
2787 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2788 FETCH( &r
[0], 0, chan_index
);
2789 micro_sgn(&d
[chan_index
], &r
[0]);
2791 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2792 STORE(&d
[chan_index
], 0, chan_index
);
2796 case TGSI_OPCODE_CMP
:
2797 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2798 FETCH(&r
[0], 0, chan_index
);
2799 FETCH(&r
[1], 1, chan_index
);
2800 FETCH(&r
[2], 2, chan_index
);
2801 micro_lt(&d
[chan_index
], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &r
[1], &r
[2]);
2803 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2804 STORE(&d
[chan_index
], 0, chan_index
);
2808 case TGSI_OPCODE_SCS
:
2809 if( IS_CHANNEL_ENABLED( *inst
, CHAN_X
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) ) {
2810 FETCH( &r
[0], 0, CHAN_X
);
2811 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2812 micro_cos(&r
[1], &r
[0]);
2813 STORE(&r
[1], 0, CHAN_X
);
2815 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2816 micro_sin(&r
[1], &r
[0]);
2817 STORE(&r
[1], 0, CHAN_Y
);
2820 if( IS_CHANNEL_ENABLED( *inst
, CHAN_Z
) ) {
2821 STORE( &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, CHAN_Z
);
2823 if( IS_CHANNEL_ENABLED( *inst
, CHAN_W
) ) {
2824 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2828 case TGSI_OPCODE_NRM
:
2829 /* 3-component vector normalize */
2830 if(IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2831 IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2832 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2833 /* r3 = sqrt(dp3(src0, src0)) */
2834 FETCH(&r
[0], 0, CHAN_X
);
2835 micro_mul(&r
[3], &r
[0], &r
[0]);
2836 FETCH(&r
[1], 0, CHAN_Y
);
2837 micro_mul(&r
[4], &r
[1], &r
[1]);
2838 micro_add(&r
[3], &r
[3], &r
[4]);
2839 FETCH(&r
[2], 0, CHAN_Z
);
2840 micro_mul(&r
[4], &r
[2], &r
[2]);
2841 micro_add(&r
[3], &r
[3], &r
[4]);
2842 micro_sqrt(&r
[3], &r
[3]);
2844 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2845 micro_div(&r
[0], &r
[0], &r
[3]);
2846 STORE(&r
[0], 0, CHAN_X
);
2848 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2849 micro_div(&r
[1], &r
[1], &r
[3]);
2850 STORE(&r
[1], 0, CHAN_Y
);
2852 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2853 micro_div(&r
[2], &r
[2], &r
[3]);
2854 STORE(&r
[2], 0, CHAN_Z
);
2857 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2858 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2862 case TGSI_OPCODE_NRM4
:
2863 /* 4-component vector normalize */
2865 union tgsi_exec_channel tmp
, dot
;
2867 /* tmp = dp4(src0, src0): */
2868 FETCH( &r
[0], 0, CHAN_X
);
2869 micro_mul( &tmp
, &r
[0], &r
[0] );
2871 FETCH( &r
[1], 0, CHAN_Y
);
2872 micro_mul( &dot
, &r
[1], &r
[1] );
2873 micro_add( &tmp
, &tmp
, &dot
);
2875 FETCH( &r
[2], 0, CHAN_Z
);
2876 micro_mul( &dot
, &r
[2], &r
[2] );
2877 micro_add( &tmp
, &tmp
, &dot
);
2879 FETCH( &r
[3], 0, CHAN_W
);
2880 micro_mul( &dot
, &r
[3], &r
[3] );
2881 micro_add( &tmp
, &tmp
, &dot
);
2883 /* tmp = 1 / sqrt(tmp) */
2884 micro_sqrt( &tmp
, &tmp
);
2885 micro_div( &tmp
, &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &tmp
);
2887 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2888 /* chan = chan * tmp */
2889 micro_mul( &r
[chan_index
], &tmp
, &r
[chan_index
] );
2890 STORE( &r
[chan_index
], 0, chan_index
);
2895 case TGSI_OPCODE_DIV
:
2899 case TGSI_OPCODE_DP2
:
2900 FETCH( &r
[0], 0, CHAN_X
);
2901 FETCH( &r
[1], 1, CHAN_X
);
2902 micro_mul( &r
[0], &r
[0], &r
[1] );
2904 FETCH( &r
[1], 0, CHAN_Y
);
2905 FETCH( &r
[2], 1, CHAN_Y
);
2906 micro_mul( &r
[1], &r
[1], &r
[2] );
2907 micro_add( &r
[0], &r
[0], &r
[1] );
2909 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2910 STORE( &r
[0], 0, chan_index
);
2914 case TGSI_OPCODE_IF
:
2916 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
2917 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
2918 FETCH( &r
[0], 0, CHAN_X
);
2919 /* update CondMask */
2921 mach
->CondMask
&= ~0x1;
2924 mach
->CondMask
&= ~0x2;
2927 mach
->CondMask
&= ~0x4;
2930 mach
->CondMask
&= ~0x8;
2932 UPDATE_EXEC_MASK(mach
);
2933 /* Todo: If CondMask==0, jump to ELSE */
2936 case TGSI_OPCODE_ELSE
:
2937 /* invert CondMask wrt previous mask */
2940 assert(mach
->CondStackTop
> 0);
2941 prevMask
= mach
->CondStack
[mach
->CondStackTop
- 1];
2942 mach
->CondMask
= ~mach
->CondMask
& prevMask
;
2943 UPDATE_EXEC_MASK(mach
);
2944 /* Todo: If CondMask==0, jump to ENDIF */
2948 case TGSI_OPCODE_ENDIF
:
2950 assert(mach
->CondStackTop
> 0);
2951 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
2952 UPDATE_EXEC_MASK(mach
);
2955 case TGSI_OPCODE_END
:
2956 /* halt execution */
2960 case TGSI_OPCODE_REP
:
2964 case TGSI_OPCODE_ENDREP
:
2968 case TGSI_OPCODE_PUSHA
:
2972 case TGSI_OPCODE_POPA
:
2976 case TGSI_OPCODE_CEIL
:
2977 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2978 FETCH( &r
[0], 0, chan_index
);
2979 micro_ceil(&d
[chan_index
], &r
[0]);
2981 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2982 STORE(&d
[chan_index
], 0, chan_index
);
2986 case TGSI_OPCODE_I2F
:
2987 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2988 FETCH( &r
[0], 0, chan_index
);
2989 micro_i2f(&d
[chan_index
], &r
[0]);
2991 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2992 STORE(&d
[chan_index
], 0, chan_index
);
2996 case TGSI_OPCODE_NOT
:
2997 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2998 FETCH( &r
[0], 0, chan_index
);
2999 micro_not(&d
[chan_index
], &r
[0]);
3001 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3002 STORE(&d
[chan_index
], 0, chan_index
);
3006 case TGSI_OPCODE_TRUNC
:
3007 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3008 FETCH( &r
[0], 0, chan_index
);
3009 micro_trunc(&d
[chan_index
], &r
[0]);
3011 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3012 STORE(&d
[chan_index
], 0, chan_index
);
3016 case TGSI_OPCODE_SHL
:
3017 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3018 FETCH( &r
[0], 0, chan_index
);
3019 FETCH( &r
[1], 1, chan_index
);
3020 micro_shl(&d
[chan_index
], &r
[0], &r
[1]);
3022 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3023 STORE(&d
[chan_index
], 0, chan_index
);
3027 case TGSI_OPCODE_SHR
:
3028 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3029 FETCH( &r
[0], 0, chan_index
);
3030 FETCH( &r
[1], 1, chan_index
);
3031 micro_ishr(&d
[chan_index
], &r
[0], &r
[1]);
3033 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3034 STORE(&d
[chan_index
], 0, chan_index
);
3038 case TGSI_OPCODE_AND
:
3039 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3040 FETCH( &r
[0], 0, chan_index
);
3041 FETCH( &r
[1], 1, chan_index
);
3042 micro_and(&d
[chan_index
], &r
[0], &r
[1]);
3044 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3045 STORE(&d
[chan_index
], 0, chan_index
);
3049 case TGSI_OPCODE_OR
:
3050 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3051 FETCH( &r
[0], 0, chan_index
);
3052 FETCH( &r
[1], 1, chan_index
);
3053 micro_or(&d
[chan_index
], &r
[0], &r
[1]);
3055 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3056 STORE(&d
[chan_index
], 0, chan_index
);
3060 case TGSI_OPCODE_MOD
:
3064 case TGSI_OPCODE_XOR
:
3065 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3066 FETCH( &r
[0], 0, chan_index
);
3067 FETCH( &r
[1], 1, chan_index
);
3068 micro_xor(&d
[chan_index
], &r
[0], &r
[1]);
3070 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3071 STORE(&d
[chan_index
], 0, chan_index
);
3075 case TGSI_OPCODE_SAD
:
3079 case TGSI_OPCODE_TXF
:
3083 case TGSI_OPCODE_TXQ
:
3087 case TGSI_OPCODE_EMIT
:
3088 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] += 16;
3089 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]]++;
3092 case TGSI_OPCODE_ENDPRIM
:
3093 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]++;
3094 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]] = 0;
3097 case TGSI_OPCODE_BGNFOR
:
3098 assert(mach
->LoopCounterStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3099 for (chan_index
= 0; chan_index
< 3; chan_index
++) {
3100 FETCH( &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[chan_index
], 0, chan_index
);
3102 ++mach
->LoopCounterStackTop
;
3103 STORE(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
], 0, CHAN_X
);
3104 /* update LoopMask */
3105 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[0] <= 0.0f
) {
3106 mach
->LoopMask
&= ~0x1;
3108 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[1] <= 0.0f
) {
3109 mach
->LoopMask
&= ~0x2;
3111 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[2] <= 0.0f
) {
3112 mach
->LoopMask
&= ~0x4;
3114 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[3] <= 0.0f
) {
3115 mach
->LoopMask
&= ~0x8;
3117 /* TODO: if mach->LoopMask == 0, jump to end of loop */
3118 UPDATE_EXEC_MASK(mach
);
3119 /* fall-through (for now) */
3120 case TGSI_OPCODE_BGNLOOP
:
3121 /* push LoopMask and ContMasks */
3122 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3123 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
3124 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3125 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
3126 assert(mach
->LoopLabelStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3127 mach
->LoopLabelStack
[mach
->LoopLabelStackTop
++] = *pc
- 1;
3130 case TGSI_OPCODE_ENDFOR
:
3131 assert(mach
->LoopCounterStackTop
> 0);
3132 micro_sub(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
],
3133 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
],
3134 &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
]);
3135 /* update LoopMask */
3136 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[0] <= 0.0f
) {
3137 mach
->LoopMask
&= ~0x1;
3139 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[1] <= 0.0f
) {
3140 mach
->LoopMask
&= ~0x2;
3142 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[2] <= 0.0f
) {
3143 mach
->LoopMask
&= ~0x4;
3145 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[3] <= 0.0f
) {
3146 mach
->LoopMask
&= ~0x8;
3148 micro_add(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
],
3149 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
],
3150 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Z
]);
3151 assert(mach
->LoopLabelStackTop
> 0);
3152 inst
= mach
->Instructions
+ mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1];
3153 STORE(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[CHAN_X
], 0, CHAN_X
);
3154 /* Restore ContMask, but don't pop */
3155 assert(mach
->ContStackTop
> 0);
3156 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3157 UPDATE_EXEC_MASK(mach
);
3158 if (mach
->ExecMask
) {
3159 /* repeat loop: jump to instruction just past BGNLOOP */
3160 assert(mach
->LoopLabelStackTop
> 0);
3161 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3164 /* exit loop: pop LoopMask */
3165 assert(mach
->LoopStackTop
> 0);
3166 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3168 assert(mach
->ContStackTop
> 0);
3169 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3170 assert(mach
->LoopLabelStackTop
> 0);
3171 --mach
->LoopLabelStackTop
;
3172 assert(mach
->LoopCounterStackTop
> 0);
3173 --mach
->LoopCounterStackTop
;
3175 UPDATE_EXEC_MASK(mach
);
3178 case TGSI_OPCODE_ENDLOOP
:
3179 /* Restore ContMask, but don't pop */
3180 assert(mach
->ContStackTop
> 0);
3181 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3182 UPDATE_EXEC_MASK(mach
);
3183 if (mach
->ExecMask
) {
3184 /* repeat loop: jump to instruction just past BGNLOOP */
3185 assert(mach
->LoopLabelStackTop
> 0);
3186 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3189 /* exit loop: pop LoopMask */
3190 assert(mach
->LoopStackTop
> 0);
3191 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3193 assert(mach
->ContStackTop
> 0);
3194 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3195 assert(mach
->LoopLabelStackTop
> 0);
3196 --mach
->LoopLabelStackTop
;
3198 UPDATE_EXEC_MASK(mach
);
3201 case TGSI_OPCODE_BRK
:
3202 /* turn off loop channels for each enabled exec channel */
3203 mach
->LoopMask
&= ~mach
->ExecMask
;
3204 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3205 UPDATE_EXEC_MASK(mach
);
3208 case TGSI_OPCODE_CONT
:
3209 /* turn off cont channels for each enabled exec channel */
3210 mach
->ContMask
&= ~mach
->ExecMask
;
3211 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3212 UPDATE_EXEC_MASK(mach
);
3215 case TGSI_OPCODE_BGNSUB
:
3219 case TGSI_OPCODE_ENDSUB
:
3223 case TGSI_OPCODE_NOP
:
3231 #define DEBUG_EXECUTION 0
3235 * Run TGSI interpreter.
3236 * \return bitmask of "alive" quad components
3239 tgsi_exec_machine_run( struct tgsi_exec_machine
*mach
)
3244 mach
->CondMask
= 0xf;
3245 mach
->LoopMask
= 0xf;
3246 mach
->ContMask
= 0xf;
3247 mach
->FuncMask
= 0xf;
3248 mach
->ExecMask
= 0xf;
3250 assert(mach
->CondStackTop
== 0);
3251 assert(mach
->LoopStackTop
== 0);
3252 assert(mach
->ContStackTop
== 0);
3253 assert(mach
->CallStackTop
== 0);
3255 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] = 0;
3256 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] = 0;
3258 if( mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
3259 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0] = 0;
3260 mach
->Primitives
[0] = 0;
3263 for (i
= 0; i
< QUAD_SIZE
; i
++) {
3264 mach
->Temps
[TEMP_CC_I
].xyzw
[TEMP_CC_C
].u
[i
] =
3265 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_X_SHIFT
) |
3266 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Y_SHIFT
) |
3267 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Z_SHIFT
) |
3268 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_W_SHIFT
);
3271 /* execute declarations (interpolants) */
3272 for (i
= 0; i
< mach
->NumDeclarations
; i
++) {
3273 exec_declaration( mach
, mach
->Declarations
+i
);
3278 struct tgsi_exec_vector temps
[TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
];
3279 struct tgsi_exec_vector outputs
[PIPE_MAX_ATTRIBS
];
3282 memcpy(temps
, mach
->Temps
, sizeof(temps
));
3283 memcpy(outputs
, mach
->Outputs
, sizeof(outputs
));
3286 /* execute instructions, until pc is set to -1 */
3292 tgsi_dump_instruction(&mach
->Instructions
[pc
], inst
++);
3295 assert(pc
< (int) mach
->NumInstructions
);
3296 exec_instruction(mach
, mach
->Instructions
+ pc
, &pc
);
3299 for (i
= 0; i
< TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
; i
++) {
3300 if (memcmp(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]))) {
3303 memcpy(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]));
3304 debug_printf("TEMP[%2u] = ", i
);
3305 for (j
= 0; j
< 4; j
++) {
3309 debug_printf("(%6f, %6f, %6f, %6f)\n",
3310 temps
[i
].xyzw
[0].f
[j
],
3311 temps
[i
].xyzw
[1].f
[j
],
3312 temps
[i
].xyzw
[2].f
[j
],
3313 temps
[i
].xyzw
[3].f
[j
]);
3317 for (i
= 0; i
< PIPE_MAX_ATTRIBS
; i
++) {
3318 if (memcmp(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]))) {
3321 memcpy(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]));
3322 debug_printf("OUT[%2u] = ", i
);
3323 for (j
= 0; j
< 4; j
++) {
3327 debug_printf("{%6f, %6f, %6f, %6f}\n",
3328 outputs
[i
].xyzw
[0].f
[j
],
3329 outputs
[i
].xyzw
[1].f
[j
],
3330 outputs
[i
].xyzw
[2].f
[j
],
3331 outputs
[i
].xyzw
[3].f
[j
]);
3340 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
3341 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
3343 * Scale back depth component.
3345 for (i
= 0; i
< 4; i
++)
3346 mach
->Outputs
[0].xyzw
[2].f
[i
] *= ctx
->DrawBuffer
->_DepthMaxF
;
3350 return ~mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];