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
];
373 /* Setup constants. */
374 for( i
= 0; i
< 4; i
++ ) {
375 mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
].u
[i
] = 0x00000000;
376 mach
->Temps
[TEMP_7F_I
].xyzw
[TEMP_7F_C
].u
[i
] = 0x7FFFFFFF;
377 mach
->Temps
[TEMP_80_I
].xyzw
[TEMP_80_C
].u
[i
] = 0x80000000;
378 mach
->Temps
[TEMP_FF_I
].xyzw
[TEMP_FF_C
].u
[i
] = 0xFFFFFFFF;
379 mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
].f
[i
] = 1.0f
;
380 mach
->Temps
[TEMP_2_I
].xyzw
[TEMP_2_C
].f
[i
] = 2.0f
;
381 mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
].f
[i
] = 128.0f
;
382 mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
].f
[i
] = -128.0f
;
383 mach
->Temps
[TEMP_3_I
].xyzw
[TEMP_3_C
].f
[i
] = 3.0f
;
384 mach
->Temps
[TEMP_HALF_I
].xyzw
[TEMP_HALF_C
].f
[i
] = 0.5f
;
388 /* silence warnings */
402 tgsi_exec_machine_destroy(struct tgsi_exec_machine
*mach
)
405 FREE(mach
->Instructions
);
406 FREE(mach
->Declarations
);
415 union tgsi_exec_channel
*dst
,
416 const union tgsi_exec_channel
*src
)
418 dst
->f
[0] = fabsf( src
->f
[0] );
419 dst
->f
[1] = fabsf( src
->f
[1] );
420 dst
->f
[2] = fabsf( src
->f
[2] );
421 dst
->f
[3] = fabsf( src
->f
[3] );
426 union tgsi_exec_channel
*dst
,
427 const union tgsi_exec_channel
*src0
,
428 const union tgsi_exec_channel
*src1
)
430 dst
->f
[0] = src0
->f
[0] + src1
->f
[0];
431 dst
->f
[1] = src0
->f
[1] + src1
->f
[1];
432 dst
->f
[2] = src0
->f
[2] + src1
->f
[2];
433 dst
->f
[3] = src0
->f
[3] + src1
->f
[3];
439 union tgsi_exec_channel
*dst
,
440 const union tgsi_exec_channel
*src0
,
441 const union tgsi_exec_channel
*src1
)
443 dst
->i
[0] = src0
->i
[0] + src1
->i
[0];
444 dst
->i
[1] = src0
->i
[1] + src1
->i
[1];
445 dst
->i
[2] = src0
->i
[2] + src1
->i
[2];
446 dst
->i
[3] = src0
->i
[3] + src1
->i
[3];
452 union tgsi_exec_channel
*dst
,
453 const union tgsi_exec_channel
*src0
,
454 const union tgsi_exec_channel
*src1
)
456 dst
->u
[0] = src0
->u
[0] & src1
->u
[0];
457 dst
->u
[1] = src0
->u
[1] & src1
->u
[1];
458 dst
->u
[2] = src0
->u
[2] & src1
->u
[2];
459 dst
->u
[3] = src0
->u
[3] & src1
->u
[3];
464 union tgsi_exec_channel
*dst
,
465 const union tgsi_exec_channel
*src
)
467 dst
->f
[0] = ceilf( src
->f
[0] );
468 dst
->f
[1] = ceilf( src
->f
[1] );
469 dst
->f
[2] = ceilf( src
->f
[2] );
470 dst
->f
[3] = ceilf( src
->f
[3] );
475 union tgsi_exec_channel
*dst
,
476 const union tgsi_exec_channel
*src
)
478 dst
->f
[0] = cosf( src
->f
[0] );
479 dst
->f
[1] = cosf( src
->f
[1] );
480 dst
->f
[2] = cosf( src
->f
[2] );
481 dst
->f
[3] = cosf( src
->f
[3] );
486 union tgsi_exec_channel
*dst
,
487 const union tgsi_exec_channel
*src
)
492 dst
->f
[3] = src
->f
[TILE_BOTTOM_RIGHT
] - src
->f
[TILE_BOTTOM_LEFT
];
497 union tgsi_exec_channel
*dst
,
498 const union tgsi_exec_channel
*src
)
503 dst
->f
[3] = src
->f
[TILE_TOP_LEFT
] - src
->f
[TILE_BOTTOM_LEFT
];
508 union tgsi_exec_channel
*dst
,
509 const union tgsi_exec_channel
*src0
,
510 const union tgsi_exec_channel
*src1
)
512 if (src1
->f
[0] != 0) {
513 dst
->f
[0] = src0
->f
[0] / src1
->f
[0];
515 if (src1
->f
[1] != 0) {
516 dst
->f
[1] = src0
->f
[1] / src1
->f
[1];
518 if (src1
->f
[2] != 0) {
519 dst
->f
[2] = src0
->f
[2] / src1
->f
[2];
521 if (src1
->f
[3] != 0) {
522 dst
->f
[3] = src0
->f
[3] / src1
->f
[3];
529 union tgsi_exec_channel
*dst
,
530 const union tgsi_exec_channel
*src0
,
531 const union tgsi_exec_channel
*src1
)
533 dst
->u
[0] = src0
->u
[0] / src1
->u
[0];
534 dst
->u
[1] = src0
->u
[1] / src1
->u
[1];
535 dst
->u
[2] = src0
->u
[2] / src1
->u
[2];
536 dst
->u
[3] = src0
->u
[3] / src1
->u
[3];
542 union tgsi_exec_channel
*dst
,
543 const union tgsi_exec_channel
*src0
,
544 const union tgsi_exec_channel
*src1
,
545 const union tgsi_exec_channel
*src2
,
546 const union tgsi_exec_channel
*src3
)
548 dst
->f
[0] = src0
->f
[0] == src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
549 dst
->f
[1] = src0
->f
[1] == src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
550 dst
->f
[2] = src0
->f
[2] == src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
551 dst
->f
[3] = src0
->f
[3] == src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
557 union tgsi_exec_channel
*dst
,
558 const union tgsi_exec_channel
*src0
,
559 const union tgsi_exec_channel
*src1
,
560 const union tgsi_exec_channel
*src2
,
561 const union tgsi_exec_channel
*src3
)
563 dst
->i
[0] = src0
->i
[0] == src1
->i
[0] ? src2
->i
[0] : src3
->i
[0];
564 dst
->i
[1] = src0
->i
[1] == src1
->i
[1] ? src2
->i
[1] : src3
->i
[1];
565 dst
->i
[2] = src0
->i
[2] == src1
->i
[2] ? src2
->i
[2] : src3
->i
[2];
566 dst
->i
[3] = src0
->i
[3] == src1
->i
[3] ? src2
->i
[3] : src3
->i
[3];
572 union tgsi_exec_channel
*dst
,
573 const union tgsi_exec_channel
*src
)
576 dst
->f
[0] = util_fast_exp2( src
->f
[0] );
577 dst
->f
[1] = util_fast_exp2( src
->f
[1] );
578 dst
->f
[2] = util_fast_exp2( src
->f
[2] );
579 dst
->f
[3] = util_fast_exp2( src
->f
[3] );
581 dst
->f
[0] = powf( 2.0f
, src
->f
[0] );
582 dst
->f
[1] = powf( 2.0f
, src
->f
[1] );
583 dst
->f
[2] = powf( 2.0f
, src
->f
[2] );
584 dst
->f
[3] = powf( 2.0f
, src
->f
[3] );
591 union tgsi_exec_channel
*dst
,
592 const union tgsi_exec_channel
*src
)
594 dst
->u
[0] = (uint
) src
->f
[0];
595 dst
->u
[1] = (uint
) src
->f
[1];
596 dst
->u
[2] = (uint
) src
->f
[2];
597 dst
->u
[3] = (uint
) src
->f
[3];
602 micro_float_clamp(union tgsi_exec_channel
*dst
,
603 const union tgsi_exec_channel
*src
)
607 for (i
= 0; i
< 4; i
++) {
608 if (src
->f
[i
] > 0.0f
) {
609 if (src
->f
[i
] > 1.884467e+019f
)
610 dst
->f
[i
] = 1.884467e+019f
;
611 else if (src
->f
[i
] < 5.42101e-020f
)
612 dst
->f
[i
] = 5.42101e-020f
;
614 dst
->f
[i
] = src
->f
[i
];
617 if (src
->f
[i
] < -1.884467e+019f
)
618 dst
->f
[i
] = -1.884467e+019f
;
619 else if (src
->f
[i
] > -5.42101e-020f
)
620 dst
->f
[i
] = -5.42101e-020f
;
622 dst
->f
[i
] = src
->f
[i
];
629 union tgsi_exec_channel
*dst
,
630 const union tgsi_exec_channel
*src
)
632 dst
->f
[0] = floorf( src
->f
[0] );
633 dst
->f
[1] = floorf( src
->f
[1] );
634 dst
->f
[2] = floorf( src
->f
[2] );
635 dst
->f
[3] = floorf( src
->f
[3] );
640 union tgsi_exec_channel
*dst
,
641 const union tgsi_exec_channel
*src
)
643 dst
->f
[0] = src
->f
[0] - floorf( src
->f
[0] );
644 dst
->f
[1] = src
->f
[1] - floorf( src
->f
[1] );
645 dst
->f
[2] = src
->f
[2] - floorf( src
->f
[2] );
646 dst
->f
[3] = src
->f
[3] - floorf( src
->f
[3] );
651 union tgsi_exec_channel
*dst
,
652 const union tgsi_exec_channel
*src
)
654 dst
->f
[0] = (float) src
->i
[0];
655 dst
->f
[1] = (float) src
->i
[1];
656 dst
->f
[2] = (float) src
->i
[2];
657 dst
->f
[3] = (float) src
->i
[3];
662 union tgsi_exec_channel
*dst
,
663 const union tgsi_exec_channel
*src
)
666 dst
->f
[0] = util_fast_log2( src
->f
[0] );
667 dst
->f
[1] = util_fast_log2( src
->f
[1] );
668 dst
->f
[2] = util_fast_log2( src
->f
[2] );
669 dst
->f
[3] = util_fast_log2( src
->f
[3] );
671 dst
->f
[0] = logf( src
->f
[0] ) * 1.442695f
;
672 dst
->f
[1] = logf( src
->f
[1] ) * 1.442695f
;
673 dst
->f
[2] = logf( src
->f
[2] ) * 1.442695f
;
674 dst
->f
[3] = logf( src
->f
[3] ) * 1.442695f
;
680 union tgsi_exec_channel
*dst
,
681 const union tgsi_exec_channel
*src0
,
682 const union tgsi_exec_channel
*src1
,
683 const union tgsi_exec_channel
*src2
,
684 const union tgsi_exec_channel
*src3
)
686 dst
->f
[0] = src0
->f
[0] <= src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
687 dst
->f
[1] = src0
->f
[1] <= src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
688 dst
->f
[2] = src0
->f
[2] <= src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
689 dst
->f
[3] = src0
->f
[3] <= src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
694 union tgsi_exec_channel
*dst
,
695 const union tgsi_exec_channel
*src0
,
696 const union tgsi_exec_channel
*src1
,
697 const union tgsi_exec_channel
*src2
,
698 const union tgsi_exec_channel
*src3
)
700 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
701 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
702 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
703 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
709 union tgsi_exec_channel
*dst
,
710 const union tgsi_exec_channel
*src0
,
711 const union tgsi_exec_channel
*src1
,
712 const union tgsi_exec_channel
*src2
,
713 const union tgsi_exec_channel
*src3
)
715 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? src2
->i
[0] : src3
->i
[0];
716 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? src2
->i
[1] : src3
->i
[1];
717 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? src2
->i
[2] : src3
->i
[2];
718 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? src2
->i
[3] : src3
->i
[3];
725 union tgsi_exec_channel
*dst
,
726 const union tgsi_exec_channel
*src0
,
727 const union tgsi_exec_channel
*src1
,
728 const union tgsi_exec_channel
*src2
,
729 const union tgsi_exec_channel
*src3
)
731 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? src2
->u
[0] : src3
->u
[0];
732 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? src2
->u
[1] : src3
->u
[1];
733 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? src2
->u
[2] : src3
->u
[2];
734 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? src2
->u
[3] : src3
->u
[3];
740 union tgsi_exec_channel
*dst
,
741 const union tgsi_exec_channel
*src0
,
742 const union tgsi_exec_channel
*src1
)
744 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
745 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
746 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
747 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
753 union tgsi_exec_channel
*dst
,
754 const union tgsi_exec_channel
*src0
,
755 const union tgsi_exec_channel
*src1
)
757 dst
->i
[0] = src0
->i
[0] > src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
758 dst
->i
[1] = src0
->i
[1] > src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
759 dst
->i
[2] = src0
->i
[2] > src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
760 dst
->i
[3] = src0
->i
[3] > src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
767 union tgsi_exec_channel
*dst
,
768 const union tgsi_exec_channel
*src0
,
769 const union tgsi_exec_channel
*src1
)
771 dst
->u
[0] = src0
->u
[0] > src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
772 dst
->u
[1] = src0
->u
[1] > src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
773 dst
->u
[2] = src0
->u
[2] > src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
774 dst
->u
[3] = src0
->u
[3] > src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
780 union tgsi_exec_channel
*dst
,
781 const union tgsi_exec_channel
*src0
,
782 const union tgsi_exec_channel
*src1
)
784 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
785 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
786 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
787 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
793 union tgsi_exec_channel
*dst
,
794 const union tgsi_exec_channel
*src0
,
795 const union tgsi_exec_channel
*src1
)
797 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
798 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
799 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
800 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
807 union tgsi_exec_channel
*dst
,
808 const union tgsi_exec_channel
*src0
,
809 const union tgsi_exec_channel
*src1
)
811 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
812 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
813 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
814 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
821 union tgsi_exec_channel
*dst
,
822 const union tgsi_exec_channel
*src0
,
823 const union tgsi_exec_channel
*src1
)
825 dst
->u
[0] = src0
->u
[0] % src1
->u
[0];
826 dst
->u
[1] = src0
->u
[1] % src1
->u
[1];
827 dst
->u
[2] = src0
->u
[2] % src1
->u
[2];
828 dst
->u
[3] = src0
->u
[3] % src1
->u
[3];
834 union tgsi_exec_channel
*dst
,
835 const union tgsi_exec_channel
*src0
,
836 const union tgsi_exec_channel
*src1
)
838 dst
->f
[0] = src0
->f
[0] * src1
->f
[0];
839 dst
->f
[1] = src0
->f
[1] * src1
->f
[1];
840 dst
->f
[2] = src0
->f
[2] * src1
->f
[2];
841 dst
->f
[3] = src0
->f
[3] * src1
->f
[3];
847 union tgsi_exec_channel
*dst
,
848 const union tgsi_exec_channel
*src0
,
849 const union tgsi_exec_channel
*src1
)
851 dst
->i
[0] = src0
->i
[0] * src1
->i
[0];
852 dst
->i
[1] = src0
->i
[1] * src1
->i
[1];
853 dst
->i
[2] = src0
->i
[2] * src1
->i
[2];
854 dst
->i
[3] = src0
->i
[3] * src1
->i
[3];
861 union tgsi_exec_channel
*dst0
,
862 union tgsi_exec_channel
*dst1
,
863 const union tgsi_exec_channel
*src0
,
864 const union tgsi_exec_channel
*src1
)
866 dst1
->i
[0] = src0
->i
[0] * src1
->i
[0];
867 dst1
->i
[1] = src0
->i
[1] * src1
->i
[1];
868 dst1
->i
[2] = src0
->i
[2] * src1
->i
[2];
869 dst1
->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
->u
[0] = src0
->u
[0] * src1
->u
[0];
886 dst1
->u
[1] = src0
->u
[1] * src1
->u
[1];
887 dst1
->u
[2] = src0
->u
[2] * src1
->u
[2];
888 dst1
->u
[3] = src0
->u
[3] * src1
->u
[3];
900 union tgsi_exec_channel
*dst
,
901 const union tgsi_exec_channel
*src0
,
902 const union tgsi_exec_channel
*src1
,
903 const union tgsi_exec_channel
*src2
)
905 dst
->u
[0] = src0
->u
[0] ? src1
->u
[0] : src2
->u
[0];
906 dst
->u
[1] = src0
->u
[1] ? src1
->u
[1] : src2
->u
[1];
907 dst
->u
[2] = src0
->u
[2] ? src1
->u
[2] : src2
->u
[2];
908 dst
->u
[3] = src0
->u
[3] ? src1
->u
[3] : src2
->u
[3];
914 union tgsi_exec_channel
*dst
,
915 const union tgsi_exec_channel
*src
)
917 dst
->f
[0] = -src
->f
[0];
918 dst
->f
[1] = -src
->f
[1];
919 dst
->f
[2] = -src
->f
[2];
920 dst
->f
[3] = -src
->f
[3];
926 union tgsi_exec_channel
*dst
,
927 const union tgsi_exec_channel
*src
)
929 dst
->i
[0] = -src
->i
[0];
930 dst
->i
[1] = -src
->i
[1];
931 dst
->i
[2] = -src
->i
[2];
932 dst
->i
[3] = -src
->i
[3];
938 union tgsi_exec_channel
*dst
,
939 const union tgsi_exec_channel
*src
)
941 dst
->u
[0] = ~src
->u
[0];
942 dst
->u
[1] = ~src
->u
[1];
943 dst
->u
[2] = ~src
->u
[2];
944 dst
->u
[3] = ~src
->u
[3];
949 union tgsi_exec_channel
*dst
,
950 const union tgsi_exec_channel
*src0
,
951 const union tgsi_exec_channel
*src1
)
953 dst
->u
[0] = src0
->u
[0] | src1
->u
[0];
954 dst
->u
[1] = src0
->u
[1] | src1
->u
[1];
955 dst
->u
[2] = src0
->u
[2] | src1
->u
[2];
956 dst
->u
[3] = src0
->u
[3] | src1
->u
[3];
961 union tgsi_exec_channel
*dst
,
962 const union tgsi_exec_channel
*src0
,
963 const union tgsi_exec_channel
*src1
)
966 dst
->f
[0] = util_fast_pow( src0
->f
[0], src1
->f
[0] );
967 dst
->f
[1] = util_fast_pow( src0
->f
[1], src1
->f
[1] );
968 dst
->f
[2] = util_fast_pow( src0
->f
[2], src1
->f
[2] );
969 dst
->f
[3] = util_fast_pow( src0
->f
[3], src1
->f
[3] );
971 dst
->f
[0] = powf( src0
->f
[0], src1
->f
[0] );
972 dst
->f
[1] = powf( src0
->f
[1], src1
->f
[1] );
973 dst
->f
[2] = powf( src0
->f
[2], src1
->f
[2] );
974 dst
->f
[3] = powf( src0
->f
[3], src1
->f
[3] );
980 union tgsi_exec_channel
*dst
,
981 const union tgsi_exec_channel
*src
)
983 dst
->f
[0] = floorf( src
->f
[0] + 0.5f
);
984 dst
->f
[1] = floorf( src
->f
[1] + 0.5f
);
985 dst
->f
[2] = floorf( src
->f
[2] + 0.5f
);
986 dst
->f
[3] = floorf( src
->f
[3] + 0.5f
);
991 union tgsi_exec_channel
*dst
,
992 const union tgsi_exec_channel
*src
)
994 dst
->f
[0] = src
->f
[0] < 0.0f
? -1.0f
: src
->f
[0] > 0.0f
? 1.0f
: 0.0f
;
995 dst
->f
[1] = src
->f
[1] < 0.0f
? -1.0f
: src
->f
[1] > 0.0f
? 1.0f
: 0.0f
;
996 dst
->f
[2] = src
->f
[2] < 0.0f
? -1.0f
: src
->f
[2] > 0.0f
? 1.0f
: 0.0f
;
997 dst
->f
[3] = src
->f
[3] < 0.0f
? -1.0f
: src
->f
[3] > 0.0f
? 1.0f
: 0.0f
;
1002 union tgsi_exec_channel
*dst
,
1003 const union tgsi_exec_channel
*src0
,
1004 const union tgsi_exec_channel
*src1
)
1006 dst
->i
[0] = src0
->i
[0] << src1
->i
[0];
1007 dst
->i
[1] = src0
->i
[1] << src1
->i
[1];
1008 dst
->i
[2] = src0
->i
[2] << src1
->i
[2];
1009 dst
->i
[3] = src0
->i
[3] << src1
->i
[3];
1014 union tgsi_exec_channel
*dst
,
1015 const union tgsi_exec_channel
*src0
,
1016 const union tgsi_exec_channel
*src1
)
1018 dst
->i
[0] = src0
->i
[0] >> src1
->i
[0];
1019 dst
->i
[1] = src0
->i
[1] >> src1
->i
[1];
1020 dst
->i
[2] = src0
->i
[2] >> src1
->i
[2];
1021 dst
->i
[3] = src0
->i
[3] >> src1
->i
[3];
1026 union tgsi_exec_channel
*dst
,
1027 const union tgsi_exec_channel
*src0
)
1029 dst
->f
[0] = (float) (int) src0
->f
[0];
1030 dst
->f
[1] = (float) (int) src0
->f
[1];
1031 dst
->f
[2] = (float) (int) src0
->f
[2];
1032 dst
->f
[3] = (float) (int) src0
->f
[3];
1038 union tgsi_exec_channel
*dst
,
1039 const union tgsi_exec_channel
*src0
,
1040 const union tgsi_exec_channel
*src1
)
1042 dst
->u
[0] = src0
->u
[0] >> src1
->u
[0];
1043 dst
->u
[1] = src0
->u
[1] >> src1
->u
[1];
1044 dst
->u
[2] = src0
->u
[2] >> src1
->u
[2];
1045 dst
->u
[3] = src0
->u
[3] >> src1
->u
[3];
1051 union tgsi_exec_channel
*dst
,
1052 const union tgsi_exec_channel
*src
)
1054 dst
->f
[0] = sinf( src
->f
[0] );
1055 dst
->f
[1] = sinf( src
->f
[1] );
1056 dst
->f
[2] = sinf( src
->f
[2] );
1057 dst
->f
[3] = sinf( src
->f
[3] );
1061 micro_sqrt( union tgsi_exec_channel
*dst
,
1062 const union tgsi_exec_channel
*src
)
1064 dst
->f
[0] = sqrtf( src
->f
[0] );
1065 dst
->f
[1] = sqrtf( src
->f
[1] );
1066 dst
->f
[2] = sqrtf( src
->f
[2] );
1067 dst
->f
[3] = sqrtf( src
->f
[3] );
1072 union tgsi_exec_channel
*dst
,
1073 const union tgsi_exec_channel
*src0
,
1074 const union tgsi_exec_channel
*src1
)
1076 dst
->f
[0] = src0
->f
[0] - src1
->f
[0];
1077 dst
->f
[1] = src0
->f
[1] - src1
->f
[1];
1078 dst
->f
[2] = src0
->f
[2] - src1
->f
[2];
1079 dst
->f
[3] = src0
->f
[3] - src1
->f
[3];
1085 union tgsi_exec_channel
*dst
,
1086 const union tgsi_exec_channel
*src
)
1088 dst
->f
[0] = (float) src
->u
[0];
1089 dst
->f
[1] = (float) src
->u
[1];
1090 dst
->f
[2] = (float) src
->u
[2];
1091 dst
->f
[3] = (float) src
->u
[3];
1097 union tgsi_exec_channel
*dst
,
1098 const union tgsi_exec_channel
*src0
,
1099 const union tgsi_exec_channel
*src1
)
1101 dst
->u
[0] = src0
->u
[0] ^ src1
->u
[0];
1102 dst
->u
[1] = src0
->u
[1] ^ src1
->u
[1];
1103 dst
->u
[2] = src0
->u
[2] ^ src1
->u
[2];
1104 dst
->u
[3] = src0
->u
[3] ^ src1
->u
[3];
1108 fetch_src_file_channel(
1109 const struct tgsi_exec_machine
*mach
,
1112 const union tgsi_exec_channel
*index
,
1113 union tgsi_exec_channel
*chan
)
1116 case TGSI_SWIZZLE_X
:
1117 case TGSI_SWIZZLE_Y
:
1118 case TGSI_SWIZZLE_Z
:
1119 case TGSI_SWIZZLE_W
:
1121 case TGSI_FILE_CONSTANT
:
1122 assert(mach
->Consts
);
1123 if (index
->i
[0] < 0)
1126 chan
->f
[0] = mach
->Consts
[index
->i
[0]][swizzle
];
1127 if (index
->i
[1] < 0)
1130 chan
->f
[1] = mach
->Consts
[index
->i
[1]][swizzle
];
1131 if (index
->i
[2] < 0)
1134 chan
->f
[2] = mach
->Consts
[index
->i
[2]][swizzle
];
1135 if (index
->i
[3] < 0)
1138 chan
->f
[3] = mach
->Consts
[index
->i
[3]][swizzle
];
1141 case TGSI_FILE_INPUT
:
1142 chan
->u
[0] = mach
->Inputs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1143 chan
->u
[1] = mach
->Inputs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1144 chan
->u
[2] = mach
->Inputs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1145 chan
->u
[3] = mach
->Inputs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1148 case TGSI_FILE_TEMPORARY
:
1149 assert(index
->i
[0] < TGSI_EXEC_NUM_TEMPS
);
1150 chan
->u
[0] = mach
->Temps
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1151 chan
->u
[1] = mach
->Temps
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1152 chan
->u
[2] = mach
->Temps
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1153 chan
->u
[3] = mach
->Temps
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1156 case TGSI_FILE_IMMEDIATE
:
1157 assert( index
->i
[0] < (int) mach
->ImmLimit
);
1158 chan
->f
[0] = mach
->Imms
[index
->i
[0]][swizzle
];
1159 assert( index
->i
[1] < (int) mach
->ImmLimit
);
1160 chan
->f
[1] = mach
->Imms
[index
->i
[1]][swizzle
];
1161 assert( index
->i
[2] < (int) mach
->ImmLimit
);
1162 chan
->f
[2] = mach
->Imms
[index
->i
[2]][swizzle
];
1163 assert( index
->i
[3] < (int) mach
->ImmLimit
);
1164 chan
->f
[3] = mach
->Imms
[index
->i
[3]][swizzle
];
1167 case TGSI_FILE_ADDRESS
:
1168 chan
->u
[0] = mach
->Addrs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1169 chan
->u
[1] = mach
->Addrs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1170 chan
->u
[2] = mach
->Addrs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1171 chan
->u
[3] = mach
->Addrs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1174 case TGSI_FILE_PREDICATE
:
1175 assert(index
->i
[0] < TGSI_EXEC_NUM_PREDS
);
1176 assert(index
->i
[1] < TGSI_EXEC_NUM_PREDS
);
1177 assert(index
->i
[2] < TGSI_EXEC_NUM_PREDS
);
1178 assert(index
->i
[3] < TGSI_EXEC_NUM_PREDS
);
1179 chan
->u
[0] = mach
->Addrs
[0].xyzw
[swizzle
].u
[0];
1180 chan
->u
[1] = mach
->Addrs
[0].xyzw
[swizzle
].u
[1];
1181 chan
->u
[2] = mach
->Addrs
[0].xyzw
[swizzle
].u
[2];
1182 chan
->u
[3] = mach
->Addrs
[0].xyzw
[swizzle
].u
[3];
1185 case TGSI_FILE_OUTPUT
:
1186 /* vertex/fragment output vars can be read too */
1187 chan
->u
[0] = mach
->Outputs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1188 chan
->u
[1] = mach
->Outputs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1189 chan
->u
[2] = mach
->Outputs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1190 chan
->u
[3] = mach
->Outputs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1205 const struct tgsi_exec_machine
*mach
,
1206 union tgsi_exec_channel
*chan
,
1207 const struct tgsi_full_src_register
*reg
,
1208 const uint chan_index
)
1210 union tgsi_exec_channel index
;
1213 /* We start with a direct index into a register file.
1217 * file = SrcRegister.File
1218 * [1] = SrcRegister.Index
1223 index
.i
[3] = reg
->SrcRegister
.Index
;
1225 /* There is an extra source register that indirectly subscripts
1226 * a register file. The direct index now becomes an offset
1227 * that is being added to the indirect register.
1231 * ind = SrcRegisterInd.File
1232 * [2] = SrcRegisterInd.Index
1233 * .x = SrcRegisterInd.SwizzleX
1235 if (reg
->SrcRegister
.Indirect
) {
1236 union tgsi_exec_channel index2
;
1237 union tgsi_exec_channel indir_index
;
1238 const uint execmask
= mach
->ExecMask
;
1241 /* which address register (always zero now) */
1245 index2
.i
[3] = reg
->SrcRegisterInd
.Index
;
1247 /* get current value of address register[swizzle] */
1248 swizzle
= tgsi_util_get_src_register_swizzle( ®
->SrcRegisterInd
, CHAN_X
);
1249 fetch_src_file_channel(
1251 reg
->SrcRegisterInd
.File
,
1256 /* add value of address register to the offset */
1257 index
.i
[0] += (int) indir_index
.f
[0];
1258 index
.i
[1] += (int) indir_index
.f
[1];
1259 index
.i
[2] += (int) indir_index
.f
[2];
1260 index
.i
[3] += (int) indir_index
.f
[3];
1262 /* for disabled execution channels, zero-out the index to
1263 * avoid using a potential garbage value.
1265 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1266 if ((execmask
& (1 << i
)) == 0)
1271 /* There is an extra source register that is a second
1272 * subscript to a register file. Effectively it means that
1273 * the register file is actually a 2D array of registers.
1275 * file[1][3] == file[1*sizeof(file[1])+3],
1277 * [3] = SrcRegisterDim.Index
1279 if (reg
->SrcRegister
.Dimension
) {
1280 /* The size of the first-order array depends on the register file type.
1281 * We need to multiply the index to the first array to get an effective,
1282 * "flat" index that points to the beginning of the second-order array.
1284 switch (reg
->SrcRegister
.File
) {
1285 case TGSI_FILE_INPUT
:
1286 index
.i
[0] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1287 index
.i
[1] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1288 index
.i
[2] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1289 index
.i
[3] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1291 case TGSI_FILE_CONSTANT
:
1292 index
.i
[0] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1293 index
.i
[1] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1294 index
.i
[2] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1295 index
.i
[3] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1301 index
.i
[0] += reg
->SrcRegisterDim
.Index
;
1302 index
.i
[1] += reg
->SrcRegisterDim
.Index
;
1303 index
.i
[2] += reg
->SrcRegisterDim
.Index
;
1304 index
.i
[3] += reg
->SrcRegisterDim
.Index
;
1306 /* Again, the second subscript index can be addressed indirectly
1307 * identically to the first one.
1308 * Nothing stops us from indirectly addressing the indirect register,
1309 * but there is no need for that, so we won't exercise it.
1311 * file[1][ind[4].y+3],
1313 * ind = SrcRegisterDimInd.File
1314 * [4] = SrcRegisterDimInd.Index
1315 * .y = SrcRegisterDimInd.SwizzleX
1317 if (reg
->SrcRegisterDim
.Indirect
) {
1318 union tgsi_exec_channel index2
;
1319 union tgsi_exec_channel indir_index
;
1320 const uint execmask
= mach
->ExecMask
;
1326 index2
.i
[3] = reg
->SrcRegisterDimInd
.Index
;
1328 swizzle
= tgsi_util_get_src_register_swizzle( ®
->SrcRegisterDimInd
, CHAN_X
);
1329 fetch_src_file_channel(
1331 reg
->SrcRegisterDimInd
.File
,
1336 index
.i
[0] += (int) indir_index
.f
[0];
1337 index
.i
[1] += (int) indir_index
.f
[1];
1338 index
.i
[2] += (int) indir_index
.f
[2];
1339 index
.i
[3] += (int) indir_index
.f
[3];
1341 /* for disabled execution channels, zero-out the index to
1342 * avoid using a potential garbage value.
1344 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1345 if ((execmask
& (1 << i
)) == 0)
1350 /* If by any chance there was a need for a 3D array of register
1351 * files, we would have to check whether SrcRegisterDim is followed
1352 * by a dimension register and continue the saga.
1356 swizzle
= tgsi_util_get_full_src_register_swizzle( reg
, chan_index
);
1357 fetch_src_file_channel(
1359 reg
->SrcRegister
.File
,
1364 switch (tgsi_util_get_full_src_register_sign_mode( reg
, chan_index
)) {
1365 case TGSI_UTIL_SIGN_CLEAR
:
1366 micro_abs( chan
, chan
);
1369 case TGSI_UTIL_SIGN_SET
:
1370 micro_abs( chan
, chan
);
1371 micro_neg( chan
, chan
);
1374 case TGSI_UTIL_SIGN_TOGGLE
:
1375 micro_neg( chan
, chan
);
1378 case TGSI_UTIL_SIGN_KEEP
:
1382 if (reg
->SrcRegisterExtMod
.Complement
) {
1383 micro_sub( chan
, &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], chan
);
1389 struct tgsi_exec_machine
*mach
,
1390 const union tgsi_exec_channel
*chan
,
1391 const struct tgsi_full_dst_register
*reg
,
1392 const struct tgsi_full_instruction
*inst
,
1396 union tgsi_exec_channel null
;
1397 union tgsi_exec_channel
*dst
;
1398 uint execmask
= mach
->ExecMask
;
1399 int offset
= 0; /* indirection offset */
1403 check_inf_or_nan(chan
);
1406 /* There is an extra source register that indirectly subscripts
1407 * a register file. The direct index now becomes an offset
1408 * that is being added to the indirect register.
1412 * ind = DstRegisterInd.File
1413 * [2] = DstRegisterInd.Index
1414 * .x = DstRegisterInd.SwizzleX
1416 if (reg
->DstRegister
.Indirect
) {
1417 union tgsi_exec_channel index
;
1418 union tgsi_exec_channel indir_index
;
1421 /* which address register (always zero for now) */
1425 index
.i
[3] = reg
->DstRegisterInd
.Index
;
1427 /* get current value of address register[swizzle] */
1428 swizzle
= tgsi_util_get_src_register_swizzle( ®
->DstRegisterInd
, CHAN_X
);
1430 /* fetch values from the address/indirection register */
1431 fetch_src_file_channel(
1433 reg
->DstRegisterInd
.File
,
1438 /* save indirection offset */
1439 offset
= (int) indir_index
.f
[0];
1442 switch (reg
->DstRegister
.File
) {
1443 case TGSI_FILE_NULL
:
1447 case TGSI_FILE_OUTPUT
:
1448 index
= mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0]
1449 + reg
->DstRegister
.Index
;
1450 dst
= &mach
->Outputs
[offset
+ index
].xyzw
[chan_index
];
1453 case TGSI_FILE_TEMPORARY
:
1454 index
= reg
->DstRegister
.Index
;
1455 assert( index
< TGSI_EXEC_NUM_TEMPS
);
1456 dst
= &mach
->Temps
[offset
+ index
].xyzw
[chan_index
];
1459 case TGSI_FILE_ADDRESS
:
1460 index
= reg
->DstRegister
.Index
;
1461 dst
= &mach
->Addrs
[index
].xyzw
[chan_index
];
1464 case TGSI_FILE_PREDICATE
:
1465 index
= reg
->DstRegister
.Index
;
1466 assert(index
< TGSI_EXEC_NUM_PREDS
);
1467 dst
= &mach
->Addrs
[index
].xyzw
[chan_index
];
1475 switch (inst
->Instruction
.Saturate
) {
1477 for (i
= 0; i
< QUAD_SIZE
; i
++)
1478 if (execmask
& (1 << i
))
1479 dst
->i
[i
] = chan
->i
[i
];
1482 case TGSI_SAT_ZERO_ONE
:
1483 for (i
= 0; i
< QUAD_SIZE
; i
++)
1484 if (execmask
& (1 << i
)) {
1485 if (chan
->f
[i
] < 0.0f
)
1487 else if (chan
->f
[i
] > 1.0f
)
1490 dst
->i
[i
] = chan
->i
[i
];
1494 case TGSI_SAT_MINUS_PLUS_ONE
:
1495 for (i
= 0; i
< QUAD_SIZE
; i
++)
1496 if (execmask
& (1 << i
)) {
1497 if (chan
->f
[i
] < -1.0f
)
1499 else if (chan
->f
[i
] > 1.0f
)
1502 dst
->i
[i
] = chan
->i
[i
];
1511 #define FETCH(VAL,INDEX,CHAN)\
1512 fetch_source (mach, VAL, &inst->FullSrcRegisters[INDEX], CHAN)
1514 #define STORE(VAL,INDEX,CHAN)\
1515 store_dest (mach, VAL, &inst->FullDstRegisters[INDEX], inst, CHAN )
1519 * Execute ARB-style KIL which is predicated by a src register.
1520 * Kill fragment if any of the four values is less than zero.
1523 exec_kil(struct tgsi_exec_machine
*mach
,
1524 const struct tgsi_full_instruction
*inst
)
1528 uint kilmask
= 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1529 union tgsi_exec_channel r
[1];
1531 /* This mask stores component bits that were already tested. */
1534 for (chan_index
= 0; chan_index
< 4; chan_index
++)
1539 /* unswizzle channel */
1540 swizzle
= tgsi_util_get_full_src_register_swizzle (
1541 &inst
->FullSrcRegisters
[0],
1544 /* check if the component has not been already tested */
1545 if (uniquemask
& (1 << swizzle
))
1547 uniquemask
|= 1 << swizzle
;
1549 FETCH(&r
[0], 0, chan_index
);
1550 for (i
= 0; i
< 4; i
++)
1551 if (r
[0].f
[i
] < 0.0f
)
1555 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1559 * Execute NVIDIA-style KIL which is predicated by a condition code.
1560 * Kill fragment if the condition code is TRUE.
1563 exec_kilp(struct tgsi_exec_machine
*mach
,
1564 const struct tgsi_full_instruction
*inst
)
1566 uint kilmask
; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1568 /* "unconditional" kil */
1569 kilmask
= mach
->ExecMask
;
1570 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1575 * Fetch a four texture samples using STR texture coordinates.
1578 fetch_texel( struct tgsi_sampler
*sampler
,
1579 const union tgsi_exec_channel
*s
,
1580 const union tgsi_exec_channel
*t
,
1581 const union tgsi_exec_channel
*p
,
1582 float lodbias
, /* XXX should be float[4] */
1583 union tgsi_exec_channel
*r
,
1584 union tgsi_exec_channel
*g
,
1585 union tgsi_exec_channel
*b
,
1586 union tgsi_exec_channel
*a
)
1589 float rgba
[NUM_CHANNELS
][QUAD_SIZE
];
1591 sampler
->get_samples(sampler
, s
->f
, t
->f
, p
->f
, lodbias
, rgba
);
1593 for (j
= 0; j
< 4; j
++) {
1594 r
->f
[j
] = rgba
[0][j
];
1595 g
->f
[j
] = rgba
[1][j
];
1596 b
->f
[j
] = rgba
[2][j
];
1597 a
->f
[j
] = rgba
[3][j
];
1603 exec_tex(struct tgsi_exec_machine
*mach
,
1604 const struct tgsi_full_instruction
*inst
,
1608 const uint unit
= inst
->FullSrcRegisters
[1].SrcRegister
.Index
;
1609 union tgsi_exec_channel r
[4];
1613 /* debug_printf("Sampler %u unit %u\n", sampler, unit); */
1615 switch (inst
->InstructionExtTexture
.Texture
) {
1616 case TGSI_TEXTURE_1D
:
1617 case TGSI_TEXTURE_SHADOW1D
:
1619 FETCH(&r
[0], 0, CHAN_X
);
1622 FETCH(&r
[1], 0, CHAN_W
);
1623 micro_div( &r
[0], &r
[0], &r
[1] );
1627 FETCH(&r
[1], 0, CHAN_W
);
1628 lodBias
= r
[2].f
[0];
1633 fetch_texel(mach
->Samplers
[unit
],
1634 &r
[0], &ZeroVec
, &ZeroVec
, lodBias
, /* S, T, P, BIAS */
1635 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1638 case TGSI_TEXTURE_2D
:
1639 case TGSI_TEXTURE_RECT
:
1640 case TGSI_TEXTURE_SHADOW2D
:
1641 case TGSI_TEXTURE_SHADOWRECT
:
1643 FETCH(&r
[0], 0, CHAN_X
);
1644 FETCH(&r
[1], 0, CHAN_Y
);
1645 FETCH(&r
[2], 0, CHAN_Z
);
1648 FETCH(&r
[3], 0, CHAN_W
);
1649 micro_div( &r
[0], &r
[0], &r
[3] );
1650 micro_div( &r
[1], &r
[1], &r
[3] );
1651 micro_div( &r
[2], &r
[2], &r
[3] );
1655 FETCH(&r
[3], 0, CHAN_W
);
1656 lodBias
= r
[3].f
[0];
1661 fetch_texel(mach
->Samplers
[unit
],
1662 &r
[0], &r
[1], &r
[2], lodBias
, /* inputs */
1663 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1666 case TGSI_TEXTURE_3D
:
1667 case TGSI_TEXTURE_CUBE
:
1669 FETCH(&r
[0], 0, CHAN_X
);
1670 FETCH(&r
[1], 0, CHAN_Y
);
1671 FETCH(&r
[2], 0, CHAN_Z
);
1674 FETCH(&r
[3], 0, CHAN_W
);
1675 micro_div( &r
[0], &r
[0], &r
[3] );
1676 micro_div( &r
[1], &r
[1], &r
[3] );
1677 micro_div( &r
[2], &r
[2], &r
[3] );
1681 FETCH(&r
[3], 0, CHAN_W
);
1682 lodBias
= r
[3].f
[0];
1687 fetch_texel(mach
->Samplers
[unit
],
1688 &r
[0], &r
[1], &r
[2], lodBias
,
1689 &r
[0], &r
[1], &r
[2], &r
[3]);
1696 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1697 STORE( &r
[chan_index
], 0, chan_index
);
1703 * Evaluate a constant-valued coefficient at the position of the
1708 struct tgsi_exec_machine
*mach
,
1714 for( i
= 0; i
< QUAD_SIZE
; i
++ ) {
1715 mach
->Inputs
[attrib
].xyzw
[chan
].f
[i
] = mach
->InterpCoefs
[attrib
].a0
[chan
];
1720 * Evaluate a linear-valued coefficient at the position of the
1725 struct tgsi_exec_machine
*mach
,
1729 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1730 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1731 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1732 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1733 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1734 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
;
1735 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = a0
+ dadx
;
1736 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = a0
+ dady
;
1737 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = a0
+ dadx
+ dady
;
1741 * Evaluate a perspective-valued coefficient at the position of the
1745 eval_perspective_coef(
1746 struct tgsi_exec_machine
*mach
,
1750 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1751 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1752 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1753 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1754 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1755 const float *w
= mach
->QuadPos
.xyzw
[3].f
;
1756 /* divide by W here */
1757 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
/ w
[0];
1758 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = (a0
+ dadx
) / w
[1];
1759 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = (a0
+ dady
) / w
[2];
1760 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = (a0
+ dadx
+ dady
) / w
[3];
1764 typedef void (* eval_coef_func
)(
1765 struct tgsi_exec_machine
*mach
,
1771 struct tgsi_exec_machine
*mach
,
1772 const struct tgsi_full_declaration
*decl
)
1774 if( mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
1775 if( decl
->Declaration
.File
== TGSI_FILE_INPUT
) {
1776 unsigned first
, last
, mask
;
1777 eval_coef_func eval
;
1779 first
= decl
->DeclarationRange
.First
;
1780 last
= decl
->DeclarationRange
.Last
;
1781 mask
= decl
->Declaration
.UsageMask
;
1783 switch( decl
->Declaration
.Interpolate
) {
1784 case TGSI_INTERPOLATE_CONSTANT
:
1785 eval
= eval_constant_coef
;
1788 case TGSI_INTERPOLATE_LINEAR
:
1789 eval
= eval_linear_coef
;
1792 case TGSI_INTERPOLATE_PERSPECTIVE
:
1793 eval
= eval_perspective_coef
;
1801 if( mask
== TGSI_WRITEMASK_XYZW
) {
1804 for( i
= first
; i
<= last
; i
++ ) {
1805 for( j
= 0; j
< NUM_CHANNELS
; j
++ ) {
1813 for( j
= 0; j
< NUM_CHANNELS
; j
++ ) {
1814 if( mask
& (1 << j
) ) {
1815 for( i
= first
; i
<= last
; i
++ ) {
1827 struct tgsi_exec_machine
*mach
,
1828 const struct tgsi_full_instruction
*inst
,
1832 union tgsi_exec_channel r
[10];
1833 union tgsi_exec_channel d
[8];
1837 switch (inst
->Instruction
.Opcode
) {
1838 case TGSI_OPCODE_ARL
:
1839 case TGSI_OPCODE_FLR
:
1840 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1841 FETCH( &r
[0], 0, chan_index
);
1842 micro_flr(&d
[chan_index
], &r
[0]);
1844 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
1845 STORE(&d
[chan_index
], 0, chan_index
);
1849 case TGSI_OPCODE_MOV
:
1850 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1851 FETCH(&d
[chan_index
], 0, chan_index
);
1853 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1854 STORE(&d
[chan_index
], 0, chan_index
);
1858 case TGSI_OPCODE_LIT
:
1859 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
1860 FETCH( &r
[0], 0, CHAN_X
);
1861 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
1862 micro_max(&d
[CHAN_Y
], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
1865 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
1866 FETCH( &r
[1], 0, CHAN_Y
);
1867 micro_max( &r
[1], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
1869 FETCH( &r
[2], 0, CHAN_W
);
1870 micro_min( &r
[2], &r
[2], &mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
] );
1871 micro_max( &r
[2], &r
[2], &mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
] );
1872 micro_pow( &r
[1], &r
[1], &r
[2] );
1873 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
]);
1876 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
1877 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
1879 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
1880 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
1883 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
1884 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
1886 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
1887 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
1891 case TGSI_OPCODE_RCP
:
1892 /* TGSI_OPCODE_RECIP */
1893 FETCH( &r
[0], 0, CHAN_X
);
1894 micro_div( &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0] );
1895 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1896 STORE( &r
[0], 0, chan_index
);
1900 case TGSI_OPCODE_RSQ
:
1901 /* TGSI_OPCODE_RECIPSQRT */
1902 FETCH( &r
[0], 0, CHAN_X
);
1903 micro_abs( &r
[0], &r
[0] );
1904 micro_sqrt( &r
[0], &r
[0] );
1905 micro_div( &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0] );
1906 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1907 STORE( &r
[0], 0, chan_index
);
1911 case TGSI_OPCODE_EXP
:
1912 FETCH( &r
[0], 0, CHAN_X
);
1913 micro_flr( &r
[1], &r
[0] ); /* r1 = floor(r0) */
1914 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
1915 micro_exp2( &r
[2], &r
[1] ); /* r2 = 2 ^ r1 */
1916 STORE( &r
[2], 0, CHAN_X
); /* store r2 */
1918 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
1919 micro_sub( &r
[2], &r
[0], &r
[1] ); /* r2 = r0 - r1 */
1920 STORE( &r
[2], 0, CHAN_Y
); /* store r2 */
1922 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
1923 micro_exp2( &r
[2], &r
[0] ); /* r2 = 2 ^ r0 */
1924 STORE( &r
[2], 0, CHAN_Z
); /* store r2 */
1926 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
1927 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
1931 case TGSI_OPCODE_LOG
:
1932 FETCH( &r
[0], 0, CHAN_X
);
1933 micro_abs( &r
[2], &r
[0] ); /* r2 = abs(r0) */
1934 micro_lg2( &r
[1], &r
[2] ); /* r1 = lg2(r2) */
1935 micro_flr( &r
[0], &r
[1] ); /* r0 = floor(r1) */
1936 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
1937 STORE( &r
[0], 0, CHAN_X
);
1939 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
1940 micro_exp2( &r
[0], &r
[0] ); /* r0 = 2 ^ r0 */
1941 micro_div( &r
[0], &r
[2], &r
[0] ); /* r0 = r2 / r0 */
1942 STORE( &r
[0], 0, CHAN_Y
);
1944 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
1945 STORE( &r
[1], 0, CHAN_Z
);
1947 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
1948 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
1952 case TGSI_OPCODE_MUL
:
1953 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
1954 FETCH(&r
[0], 0, chan_index
);
1955 FETCH(&r
[1], 1, chan_index
);
1956 micro_mul(&d
[chan_index
], &r
[0], &r
[1]);
1958 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
1959 STORE(&d
[chan_index
], 0, chan_index
);
1963 case TGSI_OPCODE_ADD
:
1964 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1965 FETCH( &r
[0], 0, chan_index
);
1966 FETCH( &r
[1], 1, chan_index
);
1967 micro_add(&d
[chan_index
], &r
[0], &r
[1]);
1969 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
1970 STORE(&d
[chan_index
], 0, chan_index
);
1974 case TGSI_OPCODE_DP3
:
1975 /* TGSI_OPCODE_DOT3 */
1976 FETCH( &r
[0], 0, CHAN_X
);
1977 FETCH( &r
[1], 1, CHAN_X
);
1978 micro_mul( &r
[0], &r
[0], &r
[1] );
1980 FETCH( &r
[1], 0, CHAN_Y
);
1981 FETCH( &r
[2], 1, CHAN_Y
);
1982 micro_mul( &r
[1], &r
[1], &r
[2] );
1983 micro_add( &r
[0], &r
[0], &r
[1] );
1985 FETCH( &r
[1], 0, CHAN_Z
);
1986 FETCH( &r
[2], 1, CHAN_Z
);
1987 micro_mul( &r
[1], &r
[1], &r
[2] );
1988 micro_add( &r
[0], &r
[0], &r
[1] );
1990 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1991 STORE( &r
[0], 0, chan_index
);
1995 case TGSI_OPCODE_DP4
:
1996 /* TGSI_OPCODE_DOT4 */
1997 FETCH(&r
[0], 0, CHAN_X
);
1998 FETCH(&r
[1], 1, CHAN_X
);
2000 micro_mul( &r
[0], &r
[0], &r
[1] );
2002 FETCH(&r
[1], 0, CHAN_Y
);
2003 FETCH(&r
[2], 1, CHAN_Y
);
2005 micro_mul( &r
[1], &r
[1], &r
[2] );
2006 micro_add( &r
[0], &r
[0], &r
[1] );
2008 FETCH(&r
[1], 0, CHAN_Z
);
2009 FETCH(&r
[2], 1, CHAN_Z
);
2011 micro_mul( &r
[1], &r
[1], &r
[2] );
2012 micro_add( &r
[0], &r
[0], &r
[1] );
2014 FETCH(&r
[1], 0, CHAN_W
);
2015 FETCH(&r
[2], 1, CHAN_W
);
2017 micro_mul( &r
[1], &r
[1], &r
[2] );
2018 micro_add( &r
[0], &r
[0], &r
[1] );
2020 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2021 STORE( &r
[0], 0, chan_index
);
2025 case TGSI_OPCODE_DST
:
2026 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2027 FETCH( &r
[0], 0, CHAN_Y
);
2028 FETCH( &r
[1], 1, CHAN_Y
);
2029 micro_mul(&d
[CHAN_Y
], &r
[0], &r
[1]);
2031 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2032 FETCH(&d
[CHAN_Z
], 0, CHAN_Z
);
2034 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2035 FETCH(&d
[CHAN_W
], 1, CHAN_W
);
2038 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2039 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2041 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2042 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2044 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2045 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2047 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2048 STORE(&d
[CHAN_W
], 0, CHAN_W
);
2052 case TGSI_OPCODE_MIN
:
2053 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2054 FETCH(&r
[0], 0, chan_index
);
2055 FETCH(&r
[1], 1, chan_index
);
2057 /* XXX use micro_min()?? */
2058 micro_lt(&d
[chan_index
], &r
[0], &r
[1], &r
[0], &r
[1]);
2060 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2061 STORE(&d
[chan_index
], 0, chan_index
);
2065 case TGSI_OPCODE_MAX
:
2066 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2067 FETCH(&r
[0], 0, chan_index
);
2068 FETCH(&r
[1], 1, chan_index
);
2070 /* XXX use micro_max()?? */
2071 micro_lt(&d
[chan_index
], &r
[0], &r
[1], &r
[1], &r
[0] );
2073 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2074 STORE(&d
[chan_index
], 0, chan_index
);
2078 case TGSI_OPCODE_SLT
:
2079 /* TGSI_OPCODE_SETLT */
2080 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2081 FETCH( &r
[0], 0, chan_index
);
2082 FETCH( &r
[1], 1, chan_index
);
2083 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
]);
2085 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2086 STORE(&d
[chan_index
], 0, chan_index
);
2090 case TGSI_OPCODE_SGE
:
2091 /* TGSI_OPCODE_SETGE */
2092 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2093 FETCH( &r
[0], 0, chan_index
);
2094 FETCH( &r
[1], 1, chan_index
);
2095 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
]);
2097 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2098 STORE(&d
[chan_index
], 0, chan_index
);
2102 case TGSI_OPCODE_MAD
:
2103 /* TGSI_OPCODE_MADD */
2104 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2105 FETCH( &r
[0], 0, chan_index
);
2106 FETCH( &r
[1], 1, chan_index
);
2107 micro_mul( &r
[0], &r
[0], &r
[1] );
2108 FETCH( &r
[1], 2, chan_index
);
2109 micro_add(&d
[chan_index
], &r
[0], &r
[1]);
2111 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2112 STORE(&d
[chan_index
], 0, chan_index
);
2116 case TGSI_OPCODE_SUB
:
2117 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2118 FETCH(&r
[0], 0, chan_index
);
2119 FETCH(&r
[1], 1, chan_index
);
2120 micro_sub(&d
[chan_index
], &r
[0], &r
[1]);
2122 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2123 STORE(&d
[chan_index
], 0, chan_index
);
2127 case TGSI_OPCODE_LRP
:
2128 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2129 FETCH(&r
[0], 0, chan_index
);
2130 FETCH(&r
[1], 1, chan_index
);
2131 FETCH(&r
[2], 2, chan_index
);
2132 micro_sub( &r
[1], &r
[1], &r
[2] );
2133 micro_mul( &r
[0], &r
[0], &r
[1] );
2134 micro_add(&d
[chan_index
], &r
[0], &r
[2]);
2136 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2137 STORE(&d
[chan_index
], 0, chan_index
);
2141 case TGSI_OPCODE_CND
:
2142 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2143 FETCH(&r
[0], 0, chan_index
);
2144 FETCH(&r
[1], 1, chan_index
);
2145 FETCH(&r
[2], 2, chan_index
);
2146 micro_lt(&d
[chan_index
], &mach
->Temps
[TEMP_HALF_I
].xyzw
[TEMP_HALF_C
], &r
[2], &r
[0], &r
[1]);
2148 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2149 STORE(&d
[chan_index
], 0, chan_index
);
2153 case TGSI_OPCODE_DP2A
:
2154 FETCH( &r
[0], 0, CHAN_X
);
2155 FETCH( &r
[1], 1, CHAN_X
);
2156 micro_mul( &r
[0], &r
[0], &r
[1] );
2158 FETCH( &r
[1], 0, CHAN_Y
);
2159 FETCH( &r
[2], 1, CHAN_Y
);
2160 micro_mul( &r
[1], &r
[1], &r
[2] );
2161 micro_add( &r
[0], &r
[0], &r
[1] );
2163 FETCH( &r
[2], 2, CHAN_X
);
2164 micro_add( &r
[0], &r
[0], &r
[2] );
2166 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2167 STORE( &r
[0], 0, chan_index
);
2171 case TGSI_OPCODE_FRC
:
2172 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2173 FETCH( &r
[0], 0, chan_index
);
2174 micro_frc(&d
[chan_index
], &r
[0]);
2176 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2177 STORE(&d
[chan_index
], 0, chan_index
);
2181 case TGSI_OPCODE_CLAMP
:
2182 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2183 FETCH(&r
[0], 0, chan_index
);
2184 FETCH(&r
[1], 1, chan_index
);
2185 micro_max(&r
[0], &r
[0], &r
[1]);
2186 FETCH(&r
[1], 2, chan_index
);
2187 micro_min(&d
[chan_index
], &r
[0], &r
[1]);
2189 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2190 STORE(&d
[chan_index
], 0, chan_index
);
2194 case TGSI_OPCODE_ROUND
:
2195 case TGSI_OPCODE_ARR
:
2196 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2197 FETCH( &r
[0], 0, chan_index
);
2198 micro_rnd(&d
[chan_index
], &r
[0]);
2200 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2201 STORE(&d
[chan_index
], 0, chan_index
);
2205 case TGSI_OPCODE_EX2
:
2206 FETCH(&r
[0], 0, CHAN_X
);
2209 micro_exp2( &r
[0], &r
[0] );
2211 micro_pow( &r
[0], &mach
->Temps
[TEMP_2_I
].xyzw
[TEMP_2_C
], &r
[0] );
2214 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2215 STORE( &r
[0], 0, chan_index
);
2219 case TGSI_OPCODE_LG2
:
2220 FETCH( &r
[0], 0, CHAN_X
);
2221 micro_lg2( &r
[0], &r
[0] );
2222 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2223 STORE( &r
[0], 0, chan_index
);
2227 case TGSI_OPCODE_POW
:
2228 FETCH(&r
[0], 0, CHAN_X
);
2229 FETCH(&r
[1], 1, CHAN_X
);
2231 micro_pow( &r
[0], &r
[0], &r
[1] );
2233 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2234 STORE( &r
[0], 0, chan_index
);
2238 case TGSI_OPCODE_XPD
:
2239 FETCH(&r
[0], 0, CHAN_Y
);
2240 FETCH(&r
[1], 1, CHAN_Z
);
2242 micro_mul( &r
[2], &r
[0], &r
[1] );
2244 FETCH(&r
[3], 0, CHAN_Z
);
2245 FETCH(&r
[4], 1, CHAN_Y
);
2247 micro_mul( &r
[5], &r
[3], &r
[4] );
2248 micro_sub(&d
[CHAN_X
], &r
[2], &r
[5]);
2250 FETCH(&r
[2], 1, CHAN_X
);
2252 micro_mul( &r
[3], &r
[3], &r
[2] );
2254 FETCH(&r
[5], 0, CHAN_X
);
2256 micro_mul( &r
[1], &r
[1], &r
[5] );
2257 micro_sub(&d
[CHAN_Y
], &r
[3], &r
[1]);
2259 micro_mul( &r
[5], &r
[5], &r
[4] );
2260 micro_mul( &r
[0], &r
[0], &r
[2] );
2261 micro_sub(&d
[CHAN_Z
], &r
[5], &r
[0]);
2263 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2264 STORE(&d
[CHAN_X
], 0, CHAN_X
);
2266 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2267 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2269 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2270 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2272 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2273 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2277 case TGSI_OPCODE_ABS
:
2278 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2279 FETCH(&r
[0], 0, chan_index
);
2280 micro_abs(&d
[chan_index
], &r
[0]);
2282 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2283 STORE(&d
[chan_index
], 0, chan_index
);
2287 case TGSI_OPCODE_RCC
:
2288 FETCH(&r
[0], 0, CHAN_X
);
2289 micro_div(&r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0]);
2290 micro_float_clamp(&r
[0], &r
[0]);
2291 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2292 STORE(&r
[0], 0, chan_index
);
2296 case TGSI_OPCODE_DPH
:
2297 FETCH(&r
[0], 0, CHAN_X
);
2298 FETCH(&r
[1], 1, CHAN_X
);
2300 micro_mul( &r
[0], &r
[0], &r
[1] );
2302 FETCH(&r
[1], 0, CHAN_Y
);
2303 FETCH(&r
[2], 1, CHAN_Y
);
2305 micro_mul( &r
[1], &r
[1], &r
[2] );
2306 micro_add( &r
[0], &r
[0], &r
[1] );
2308 FETCH(&r
[1], 0, CHAN_Z
);
2309 FETCH(&r
[2], 1, CHAN_Z
);
2311 micro_mul( &r
[1], &r
[1], &r
[2] );
2312 micro_add( &r
[0], &r
[0], &r
[1] );
2314 FETCH(&r
[1], 1, CHAN_W
);
2316 micro_add( &r
[0], &r
[0], &r
[1] );
2318 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2319 STORE( &r
[0], 0, chan_index
);
2323 case TGSI_OPCODE_COS
:
2324 FETCH(&r
[0], 0, CHAN_X
);
2326 micro_cos( &r
[0], &r
[0] );
2328 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2329 STORE( &r
[0], 0, chan_index
);
2333 case TGSI_OPCODE_DDX
:
2334 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2335 FETCH( &r
[0], 0, chan_index
);
2336 micro_ddx(&d
[chan_index
], &r
[0]);
2338 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2339 STORE(&d
[chan_index
], 0, chan_index
);
2343 case TGSI_OPCODE_DDY
:
2344 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2345 FETCH( &r
[0], 0, chan_index
);
2346 micro_ddy(&d
[chan_index
], &r
[0]);
2348 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2349 STORE(&d
[chan_index
], 0, chan_index
);
2353 case TGSI_OPCODE_KILP
:
2354 exec_kilp (mach
, inst
);
2357 case TGSI_OPCODE_KIL
:
2358 exec_kil (mach
, inst
);
2361 case TGSI_OPCODE_PK2H
:
2365 case TGSI_OPCODE_PK2US
:
2369 case TGSI_OPCODE_PK4B
:
2373 case TGSI_OPCODE_PK4UB
:
2377 case TGSI_OPCODE_RFL
:
2378 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2379 IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2380 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2381 /* r0 = dp3(src0, src0) */
2382 FETCH(&r
[2], 0, CHAN_X
);
2383 micro_mul(&r
[0], &r
[2], &r
[2]);
2384 FETCH(&r
[4], 0, CHAN_Y
);
2385 micro_mul(&r
[8], &r
[4], &r
[4]);
2386 micro_add(&r
[0], &r
[0], &r
[8]);
2387 FETCH(&r
[6], 0, CHAN_Z
);
2388 micro_mul(&r
[8], &r
[6], &r
[6]);
2389 micro_add(&r
[0], &r
[0], &r
[8]);
2391 /* r1 = dp3(src0, src1) */
2392 FETCH(&r
[3], 1, CHAN_X
);
2393 micro_mul(&r
[1], &r
[2], &r
[3]);
2394 FETCH(&r
[5], 1, CHAN_Y
);
2395 micro_mul(&r
[8], &r
[4], &r
[5]);
2396 micro_add(&r
[1], &r
[1], &r
[8]);
2397 FETCH(&r
[7], 1, CHAN_Z
);
2398 micro_mul(&r
[8], &r
[6], &r
[7]);
2399 micro_add(&r
[1], &r
[1], &r
[8]);
2401 /* r1 = 2 * r1 / r0 */
2402 micro_add(&r
[1], &r
[1], &r
[1]);
2403 micro_div(&r
[1], &r
[1], &r
[0]);
2405 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2406 micro_mul(&r
[2], &r
[2], &r
[1]);
2407 micro_sub(&r
[2], &r
[2], &r
[3]);
2408 STORE(&r
[2], 0, CHAN_X
);
2410 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2411 micro_mul(&r
[4], &r
[4], &r
[1]);
2412 micro_sub(&r
[4], &r
[4], &r
[5]);
2413 STORE(&r
[4], 0, CHAN_Y
);
2415 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2416 micro_mul(&r
[6], &r
[6], &r
[1]);
2417 micro_sub(&r
[6], &r
[6], &r
[7]);
2418 STORE(&r
[6], 0, CHAN_Z
);
2421 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2422 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2426 case TGSI_OPCODE_SEQ
:
2427 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2428 FETCH( &r
[0], 0, chan_index
);
2429 FETCH( &r
[1], 1, chan_index
);
2430 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
]);
2432 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2433 STORE(&d
[chan_index
], 0, chan_index
);
2437 case TGSI_OPCODE_SFL
:
2438 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2439 STORE(&mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, chan_index
);
2443 case TGSI_OPCODE_SGT
:
2444 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2445 FETCH( &r
[0], 0, chan_index
);
2446 FETCH( &r
[1], 1, chan_index
);
2447 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
]);
2449 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2450 STORE(&d
[chan_index
], 0, chan_index
);
2454 case TGSI_OPCODE_SIN
:
2455 FETCH( &r
[0], 0, CHAN_X
);
2456 micro_sin( &r
[0], &r
[0] );
2457 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2458 STORE( &r
[0], 0, chan_index
);
2462 case TGSI_OPCODE_SLE
:
2463 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2464 FETCH( &r
[0], 0, chan_index
);
2465 FETCH( &r
[1], 1, chan_index
);
2466 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
]);
2468 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2469 STORE(&d
[chan_index
], 0, chan_index
);
2473 case TGSI_OPCODE_SNE
:
2474 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2475 FETCH( &r
[0], 0, chan_index
);
2476 FETCH( &r
[1], 1, chan_index
);
2477 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
]);
2479 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2480 STORE(&d
[chan_index
], 0, chan_index
);
2484 case TGSI_OPCODE_STR
:
2485 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2486 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, chan_index
);
2490 case TGSI_OPCODE_TEX
:
2491 /* simple texture lookup */
2492 /* src[0] = texcoord */
2493 /* src[1] = sampler unit */
2494 exec_tex(mach
, inst
, FALSE
, FALSE
);
2497 case TGSI_OPCODE_TXB
:
2498 /* Texture lookup with lod bias */
2499 /* src[0] = texcoord (src[0].w = LOD bias) */
2500 /* src[1] = sampler unit */
2501 exec_tex(mach
, inst
, TRUE
, FALSE
);
2504 case TGSI_OPCODE_TXD
:
2505 /* Texture lookup with explict partial derivatives */
2506 /* src[0] = texcoord */
2507 /* src[1] = d[strq]/dx */
2508 /* src[2] = d[strq]/dy */
2509 /* src[3] = sampler unit */
2513 case TGSI_OPCODE_TXL
:
2514 /* Texture lookup with explit LOD */
2515 /* src[0] = texcoord (src[0].w = LOD) */
2516 /* src[1] = sampler unit */
2517 exec_tex(mach
, inst
, TRUE
, FALSE
);
2520 case TGSI_OPCODE_TXP
:
2521 /* Texture lookup with projection */
2522 /* src[0] = texcoord (src[0].w = projection) */
2523 /* src[1] = sampler unit */
2524 exec_tex(mach
, inst
, FALSE
, TRUE
);
2527 case TGSI_OPCODE_UP2H
:
2531 case TGSI_OPCODE_UP2US
:
2535 case TGSI_OPCODE_UP4B
:
2539 case TGSI_OPCODE_UP4UB
:
2543 case TGSI_OPCODE_X2D
:
2544 FETCH(&r
[0], 1, CHAN_X
);
2545 FETCH(&r
[1], 1, CHAN_Y
);
2546 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2547 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2548 FETCH(&r
[2], 2, CHAN_X
);
2549 micro_mul(&r
[2], &r
[2], &r
[0]);
2550 FETCH(&r
[3], 2, CHAN_Y
);
2551 micro_mul(&r
[3], &r
[3], &r
[1]);
2552 micro_add(&r
[2], &r
[2], &r
[3]);
2553 FETCH(&r
[3], 0, CHAN_X
);
2554 micro_add(&d
[CHAN_X
], &r
[2], &r
[3]);
2557 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2558 IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2559 FETCH(&r
[2], 2, CHAN_Z
);
2560 micro_mul(&r
[2], &r
[2], &r
[0]);
2561 FETCH(&r
[3], 2, CHAN_W
);
2562 micro_mul(&r
[3], &r
[3], &r
[1]);
2563 micro_add(&r
[2], &r
[2], &r
[3]);
2564 FETCH(&r
[3], 0, CHAN_Y
);
2565 micro_add(&d
[CHAN_Y
], &r
[2], &r
[3]);
2568 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2569 STORE(&d
[CHAN_X
], 0, CHAN_X
);
2571 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2572 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2574 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2575 STORE(&d
[CHAN_X
], 0, CHAN_Z
);
2577 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2578 STORE(&d
[CHAN_Y
], 0, CHAN_W
);
2582 case TGSI_OPCODE_ARA
:
2586 case TGSI_OPCODE_BRA
:
2590 case TGSI_OPCODE_CAL
:
2591 /* skip the call if no execution channels are enabled */
2592 if (mach
->ExecMask
) {
2595 /* First, record the depths of the execution stacks.
2596 * This is important for deeply nested/looped return statements.
2597 * We have to unwind the stacks by the correct amount. For a
2598 * real code generator, we could determine the number of entries
2599 * to pop off each stack with simple static analysis and avoid
2600 * implementing this data structure at run time.
2602 mach
->CallStack
[mach
->CallStackTop
].CondStackTop
= mach
->CondStackTop
;
2603 mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
= mach
->LoopStackTop
;
2604 mach
->CallStack
[mach
->CallStackTop
].ContStackTop
= mach
->ContStackTop
;
2605 /* note that PC was already incremented above */
2606 mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
= *pc
;
2608 mach
->CallStackTop
++;
2610 /* Second, push the Cond, Loop, Cont, Func stacks */
2611 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
2612 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
2613 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2614 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
2615 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2616 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
2617 assert(mach
->FuncStackTop
< TGSI_EXEC_MAX_CALL_NESTING
);
2618 mach
->FuncStack
[mach
->FuncStackTop
++] = mach
->FuncMask
;
2620 /* Finally, jump to the subroutine */
2621 *pc
= inst
->InstructionExtLabel
.Label
;
2625 case TGSI_OPCODE_RET
:
2626 mach
->FuncMask
&= ~mach
->ExecMask
;
2627 UPDATE_EXEC_MASK(mach
);
2629 if (mach
->FuncMask
== 0x0) {
2630 /* really return now (otherwise, keep executing */
2632 if (mach
->CallStackTop
== 0) {
2633 /* returning from main() */
2638 assert(mach
->CallStackTop
> 0);
2639 mach
->CallStackTop
--;
2641 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
2642 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
2644 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
2645 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
2647 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
2648 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
2650 assert(mach
->FuncStackTop
> 0);
2651 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
2653 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
2655 UPDATE_EXEC_MASK(mach
);
2659 case TGSI_OPCODE_SSG
:
2660 /* TGSI_OPCODE_SGN */
2661 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2662 FETCH( &r
[0], 0, chan_index
);
2663 micro_sgn(&d
[chan_index
], &r
[0]);
2665 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2666 STORE(&d
[chan_index
], 0, chan_index
);
2670 case TGSI_OPCODE_CMP
:
2671 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2672 FETCH(&r
[0], 0, chan_index
);
2673 FETCH(&r
[1], 1, chan_index
);
2674 FETCH(&r
[2], 2, chan_index
);
2675 micro_lt(&d
[chan_index
], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &r
[1], &r
[2]);
2677 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2678 STORE(&d
[chan_index
], 0, chan_index
);
2682 case TGSI_OPCODE_SCS
:
2683 if( IS_CHANNEL_ENABLED( *inst
, CHAN_X
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) ) {
2684 FETCH( &r
[0], 0, CHAN_X
);
2685 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2686 micro_cos(&r
[1], &r
[0]);
2687 STORE(&r
[1], 0, CHAN_X
);
2689 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2690 micro_sin(&r
[1], &r
[0]);
2691 STORE(&r
[1], 0, CHAN_Y
);
2694 if( IS_CHANNEL_ENABLED( *inst
, CHAN_Z
) ) {
2695 STORE( &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, CHAN_Z
);
2697 if( IS_CHANNEL_ENABLED( *inst
, CHAN_W
) ) {
2698 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2702 case TGSI_OPCODE_NRM
:
2703 /* 3-component vector normalize */
2704 if(IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2705 IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2706 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2707 /* r3 = sqrt(dp3(src0, src0)) */
2708 FETCH(&r
[0], 0, CHAN_X
);
2709 micro_mul(&r
[3], &r
[0], &r
[0]);
2710 FETCH(&r
[1], 0, CHAN_Y
);
2711 micro_mul(&r
[4], &r
[1], &r
[1]);
2712 micro_add(&r
[3], &r
[3], &r
[4]);
2713 FETCH(&r
[2], 0, CHAN_Z
);
2714 micro_mul(&r
[4], &r
[2], &r
[2]);
2715 micro_add(&r
[3], &r
[3], &r
[4]);
2716 micro_sqrt(&r
[3], &r
[3]);
2718 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2719 micro_div(&r
[0], &r
[0], &r
[3]);
2720 STORE(&r
[0], 0, CHAN_X
);
2722 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2723 micro_div(&r
[1], &r
[1], &r
[3]);
2724 STORE(&r
[1], 0, CHAN_Y
);
2726 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2727 micro_div(&r
[2], &r
[2], &r
[3]);
2728 STORE(&r
[2], 0, CHAN_Z
);
2731 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2732 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2736 case TGSI_OPCODE_NRM4
:
2737 /* 4-component vector normalize */
2739 union tgsi_exec_channel tmp
, dot
;
2741 /* tmp = dp4(src0, src0): */
2742 FETCH( &r
[0], 0, CHAN_X
);
2743 micro_mul( &tmp
, &r
[0], &r
[0] );
2745 FETCH( &r
[1], 0, CHAN_Y
);
2746 micro_mul( &dot
, &r
[1], &r
[1] );
2747 micro_add( &tmp
, &tmp
, &dot
);
2749 FETCH( &r
[2], 0, CHAN_Z
);
2750 micro_mul( &dot
, &r
[2], &r
[2] );
2751 micro_add( &tmp
, &tmp
, &dot
);
2753 FETCH( &r
[3], 0, CHAN_W
);
2754 micro_mul( &dot
, &r
[3], &r
[3] );
2755 micro_add( &tmp
, &tmp
, &dot
);
2757 /* tmp = 1 / sqrt(tmp) */
2758 micro_sqrt( &tmp
, &tmp
);
2759 micro_div( &tmp
, &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &tmp
);
2761 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2762 /* chan = chan * tmp */
2763 micro_mul( &r
[chan_index
], &tmp
, &r
[chan_index
] );
2764 STORE( &r
[chan_index
], 0, chan_index
);
2769 case TGSI_OPCODE_DIV
:
2773 case TGSI_OPCODE_DP2
:
2774 FETCH( &r
[0], 0, CHAN_X
);
2775 FETCH( &r
[1], 1, CHAN_X
);
2776 micro_mul( &r
[0], &r
[0], &r
[1] );
2778 FETCH( &r
[1], 0, CHAN_Y
);
2779 FETCH( &r
[2], 1, CHAN_Y
);
2780 micro_mul( &r
[1], &r
[1], &r
[2] );
2781 micro_add( &r
[0], &r
[0], &r
[1] );
2783 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2784 STORE( &r
[0], 0, chan_index
);
2788 case TGSI_OPCODE_IF
:
2790 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
2791 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
2792 FETCH( &r
[0], 0, CHAN_X
);
2793 /* update CondMask */
2795 mach
->CondMask
&= ~0x1;
2798 mach
->CondMask
&= ~0x2;
2801 mach
->CondMask
&= ~0x4;
2804 mach
->CondMask
&= ~0x8;
2806 UPDATE_EXEC_MASK(mach
);
2807 /* Todo: If CondMask==0, jump to ELSE */
2810 case TGSI_OPCODE_ELSE
:
2811 /* invert CondMask wrt previous mask */
2814 assert(mach
->CondStackTop
> 0);
2815 prevMask
= mach
->CondStack
[mach
->CondStackTop
- 1];
2816 mach
->CondMask
= ~mach
->CondMask
& prevMask
;
2817 UPDATE_EXEC_MASK(mach
);
2818 /* Todo: If CondMask==0, jump to ENDIF */
2822 case TGSI_OPCODE_ENDIF
:
2824 assert(mach
->CondStackTop
> 0);
2825 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
2826 UPDATE_EXEC_MASK(mach
);
2829 case TGSI_OPCODE_END
:
2830 /* halt execution */
2834 case TGSI_OPCODE_REP
:
2838 case TGSI_OPCODE_ENDREP
:
2842 case TGSI_OPCODE_PUSHA
:
2846 case TGSI_OPCODE_POPA
:
2850 case TGSI_OPCODE_CEIL
:
2851 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2852 FETCH( &r
[0], 0, chan_index
);
2853 micro_ceil(&d
[chan_index
], &r
[0]);
2855 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2856 STORE(&d
[chan_index
], 0, chan_index
);
2860 case TGSI_OPCODE_I2F
:
2861 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2862 FETCH( &r
[0], 0, chan_index
);
2863 micro_i2f(&d
[chan_index
], &r
[0]);
2865 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2866 STORE(&d
[chan_index
], 0, chan_index
);
2870 case TGSI_OPCODE_NOT
:
2871 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2872 FETCH( &r
[0], 0, chan_index
);
2873 micro_not(&d
[chan_index
], &r
[0]);
2875 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2876 STORE(&d
[chan_index
], 0, chan_index
);
2880 case TGSI_OPCODE_TRUNC
:
2881 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2882 FETCH( &r
[0], 0, chan_index
);
2883 micro_trunc(&d
[chan_index
], &r
[0]);
2885 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2886 STORE(&d
[chan_index
], 0, chan_index
);
2890 case TGSI_OPCODE_SHL
:
2891 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2892 FETCH( &r
[0], 0, chan_index
);
2893 FETCH( &r
[1], 1, chan_index
);
2894 micro_shl(&d
[chan_index
], &r
[0], &r
[1]);
2896 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2897 STORE(&d
[chan_index
], 0, chan_index
);
2901 case TGSI_OPCODE_SHR
:
2902 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2903 FETCH( &r
[0], 0, chan_index
);
2904 FETCH( &r
[1], 1, chan_index
);
2905 micro_ishr(&d
[chan_index
], &r
[0], &r
[1]);
2907 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2908 STORE(&d
[chan_index
], 0, chan_index
);
2912 case TGSI_OPCODE_AND
:
2913 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2914 FETCH( &r
[0], 0, chan_index
);
2915 FETCH( &r
[1], 1, chan_index
);
2916 micro_and(&d
[chan_index
], &r
[0], &r
[1]);
2918 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2919 STORE(&d
[chan_index
], 0, chan_index
);
2923 case TGSI_OPCODE_OR
:
2924 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2925 FETCH( &r
[0], 0, chan_index
);
2926 FETCH( &r
[1], 1, chan_index
);
2927 micro_or(&d
[chan_index
], &r
[0], &r
[1]);
2929 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2930 STORE(&d
[chan_index
], 0, chan_index
);
2934 case TGSI_OPCODE_MOD
:
2938 case TGSI_OPCODE_XOR
:
2939 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2940 FETCH( &r
[0], 0, chan_index
);
2941 FETCH( &r
[1], 1, chan_index
);
2942 micro_xor(&d
[chan_index
], &r
[0], &r
[1]);
2944 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2945 STORE(&d
[chan_index
], 0, chan_index
);
2949 case TGSI_OPCODE_SAD
:
2953 case TGSI_OPCODE_TXF
:
2957 case TGSI_OPCODE_TXQ
:
2961 case TGSI_OPCODE_EMIT
:
2962 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] += 16;
2963 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]]++;
2966 case TGSI_OPCODE_ENDPRIM
:
2967 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]++;
2968 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]] = 0;
2971 case TGSI_OPCODE_BGNFOR
:
2972 assert(mach
->LoopCounterStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2973 for (chan_index
= 0; chan_index
< 3; chan_index
++) {
2974 FETCH( &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[chan_index
], 0, chan_index
);
2976 STORE( &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[CHAN_Y
], 0, CHAN_X
);
2977 ++mach
->LoopCounterStackTop
;
2978 /* fall-through (for now) */
2979 case TGSI_OPCODE_BGNLOOP
:
2980 /* push LoopMask and ContMasks */
2981 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2982 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
2983 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2984 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
2985 assert(mach
->LoopLabelStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2986 mach
->LoopLabelStack
[mach
->LoopLabelStackTop
++] = *pc
- 1;
2989 case TGSI_OPCODE_ENDFOR
:
2990 assert(mach
->LoopCounterStackTop
> 0);
2991 micro_sub( &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
],
2992 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
],
2993 &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
] );
2994 /* update LoopMask */
2995 if( mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
].f
[0] <= 0) {
2996 mach
->LoopMask
&= ~0x1;
2998 if( mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
].f
[1] <= 0 ) {
2999 mach
->LoopMask
&= ~0x2;
3001 if( mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
].f
[2] <= 0 ) {
3002 mach
->LoopMask
&= ~0x4;
3004 if( mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
].f
[3] <= 0 ) {
3005 mach
->LoopMask
&= ~0x8;
3007 micro_add( &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
],
3008 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
],
3009 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Z
]);
3010 assert(mach
->LoopLabelStackTop
> 0);
3011 inst
= mach
->Instructions
+ mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1];
3012 STORE( &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[CHAN_Y
], 0, CHAN_X
);
3013 /* Restore ContMask, but don't pop */
3014 assert(mach
->ContStackTop
> 0);
3015 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3016 UPDATE_EXEC_MASK(mach
);
3017 if (mach
->ExecMask
) {
3018 /* repeat loop: jump to instruction just past BGNLOOP */
3019 assert(mach
->LoopLabelStackTop
> 0);
3020 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3023 /* exit loop: pop LoopMask */
3024 assert(mach
->LoopStackTop
> 0);
3025 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3027 assert(mach
->ContStackTop
> 0);
3028 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3029 assert(mach
->LoopLabelStackTop
> 0);
3030 --mach
->LoopLabelStackTop
;
3031 assert(mach
->LoopCounterStackTop
> 0);
3032 --mach
->LoopCounterStackTop
;
3034 UPDATE_EXEC_MASK(mach
);
3037 case TGSI_OPCODE_ENDLOOP
:
3038 /* Restore ContMask, but don't pop */
3039 assert(mach
->ContStackTop
> 0);
3040 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3041 UPDATE_EXEC_MASK(mach
);
3042 if (mach
->ExecMask
) {
3043 /* repeat loop: jump to instruction just past BGNLOOP */
3044 assert(mach
->LoopLabelStackTop
> 0);
3045 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3048 /* exit loop: pop LoopMask */
3049 assert(mach
->LoopStackTop
> 0);
3050 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3052 assert(mach
->ContStackTop
> 0);
3053 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3054 assert(mach
->LoopLabelStackTop
> 0);
3055 --mach
->LoopLabelStackTop
;
3057 UPDATE_EXEC_MASK(mach
);
3060 case TGSI_OPCODE_BRK
:
3061 /* turn off loop channels for each enabled exec channel */
3062 mach
->LoopMask
&= ~mach
->ExecMask
;
3063 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3064 UPDATE_EXEC_MASK(mach
);
3067 case TGSI_OPCODE_CONT
:
3068 /* turn off cont channels for each enabled exec channel */
3069 mach
->ContMask
&= ~mach
->ExecMask
;
3070 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3071 UPDATE_EXEC_MASK(mach
);
3074 case TGSI_OPCODE_BGNSUB
:
3078 case TGSI_OPCODE_ENDSUB
:
3082 case TGSI_OPCODE_NOP
:
3092 * Run TGSI interpreter.
3093 * \return bitmask of "alive" quad components
3096 tgsi_exec_machine_run( struct tgsi_exec_machine
*mach
)
3101 mach
->CondMask
= 0xf;
3102 mach
->LoopMask
= 0xf;
3103 mach
->ContMask
= 0xf;
3104 mach
->FuncMask
= 0xf;
3105 mach
->ExecMask
= 0xf;
3107 assert(mach
->CondStackTop
== 0);
3108 assert(mach
->LoopStackTop
== 0);
3109 assert(mach
->ContStackTop
== 0);
3110 assert(mach
->CallStackTop
== 0);
3112 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] = 0;
3113 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] = 0;
3115 if( mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
3116 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0] = 0;
3117 mach
->Primitives
[0] = 0;
3120 for (i
= 0; i
< QUAD_SIZE
; i
++) {
3121 mach
->Temps
[TEMP_CC_I
].xyzw
[TEMP_CC_C
].u
[i
] =
3122 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_X_SHIFT
) |
3123 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Y_SHIFT
) |
3124 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Z_SHIFT
) |
3125 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_W_SHIFT
);
3128 /* execute declarations (interpolants) */
3129 for (i
= 0; i
< mach
->NumDeclarations
; i
++) {
3130 exec_declaration( mach
, mach
->Declarations
+i
);
3133 /* execute instructions, until pc is set to -1 */
3135 assert(pc
< (int) mach
->NumInstructions
);
3136 exec_instruction( mach
, mach
->Instructions
+ pc
, &pc
);
3140 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
3141 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
3143 * Scale back depth component.
3145 for (i
= 0; i
< 4; i
++)
3146 mach
->Outputs
[0].xyzw
[2].f
[i
] *= ctx
->DrawBuffer
->_DepthMaxF
;
3150 return ~mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];