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 /** for tgsi_full_instruction::Flags */
66 #define SOA_DEPENDENCY_FLAG 0x1
68 #define TILE_TOP_LEFT 0
69 #define TILE_TOP_RIGHT 1
70 #define TILE_BOTTOM_LEFT 2
71 #define TILE_BOTTOM_RIGHT 3
79 * Shorthand locations of various utility registers (_I = Index, _C = Channel)
81 #define TEMP_0_I TGSI_EXEC_TEMP_00000000_I
82 #define TEMP_0_C TGSI_EXEC_TEMP_00000000_C
83 #define TEMP_7F_I TGSI_EXEC_TEMP_7FFFFFFF_I
84 #define TEMP_7F_C TGSI_EXEC_TEMP_7FFFFFFF_C
85 #define TEMP_80_I TGSI_EXEC_TEMP_80000000_I
86 #define TEMP_80_C TGSI_EXEC_TEMP_80000000_C
87 #define TEMP_FF_I TGSI_EXEC_TEMP_FFFFFFFF_I
88 #define TEMP_FF_C TGSI_EXEC_TEMP_FFFFFFFF_C
89 #define TEMP_1_I TGSI_EXEC_TEMP_ONE_I
90 #define TEMP_1_C TGSI_EXEC_TEMP_ONE_C
91 #define TEMP_2_I TGSI_EXEC_TEMP_TWO_I
92 #define TEMP_2_C TGSI_EXEC_TEMP_TWO_C
93 #define TEMP_128_I TGSI_EXEC_TEMP_128_I
94 #define TEMP_128_C TGSI_EXEC_TEMP_128_C
95 #define TEMP_M128_I TGSI_EXEC_TEMP_MINUS_128_I
96 #define TEMP_M128_C TGSI_EXEC_TEMP_MINUS_128_C
97 #define TEMP_KILMASK_I TGSI_EXEC_TEMP_KILMASK_I
98 #define TEMP_KILMASK_C TGSI_EXEC_TEMP_KILMASK_C
99 #define TEMP_OUTPUT_I TGSI_EXEC_TEMP_OUTPUT_I
100 #define TEMP_OUTPUT_C TGSI_EXEC_TEMP_OUTPUT_C
101 #define TEMP_PRIMITIVE_I TGSI_EXEC_TEMP_PRIMITIVE_I
102 #define TEMP_PRIMITIVE_C TGSI_EXEC_TEMP_PRIMITIVE_C
103 #define TEMP_CC_I TGSI_EXEC_TEMP_CC_I
104 #define TEMP_CC_C TGSI_EXEC_TEMP_CC_C
105 #define TEMP_3_I TGSI_EXEC_TEMP_THREE_I
106 #define TEMP_3_C TGSI_EXEC_TEMP_THREE_C
107 #define TEMP_HALF_I TGSI_EXEC_TEMP_HALF_I
108 #define TEMP_HALF_C TGSI_EXEC_TEMP_HALF_C
109 #define TEMP_R0 TGSI_EXEC_TEMP_R0
111 #define IS_CHANNEL_ENABLED(INST, CHAN)\
112 ((INST).FullDstRegisters[0].DstRegister.WriteMask & (1 << (CHAN)))
114 #define IS_CHANNEL_ENABLED2(INST, CHAN)\
115 ((INST).FullDstRegisters[1].DstRegister.WriteMask & (1 << (CHAN)))
117 #define FOR_EACH_ENABLED_CHANNEL(INST, CHAN)\
118 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)\
119 if (IS_CHANNEL_ENABLED( INST, CHAN ))
121 #define FOR_EACH_ENABLED_CHANNEL2(INST, CHAN)\
122 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)\
123 if (IS_CHANNEL_ENABLED2( INST, CHAN ))
126 /** The execution mask depends on the conditional mask and the loop mask */
127 #define UPDATE_EXEC_MASK(MACH) \
128 MACH->ExecMask = MACH->CondMask & MACH->LoopMask & MACH->ContMask & MACH->FuncMask
131 static const union tgsi_exec_channel ZeroVec
=
132 { { 0.0, 0.0, 0.0, 0.0 } };
137 check_inf_or_nan(const union tgsi_exec_channel
*chan
)
139 assert(!util_is_inf_or_nan(chan
->f
[0]));
140 assert(!util_is_inf_or_nan(chan
->f
[1]));
141 assert(!util_is_inf_or_nan(chan
->f
[2]));
142 assert(!util_is_inf_or_nan(chan
->f
[3]));
149 print_chan(const char *msg
, const union tgsi_exec_channel
*chan
)
151 debug_printf("%s = {%f, %f, %f, %f}\n",
152 msg
, chan
->f
[0], chan
->f
[1], chan
->f
[2], chan
->f
[3]);
159 print_temp(const struct tgsi_exec_machine
*mach
, uint index
)
161 const struct tgsi_exec_vector
*tmp
= &mach
->Temps
[index
];
163 debug_printf("Temp[%u] =\n", index
);
164 for (i
= 0; i
< 4; i
++) {
165 debug_printf(" %c: { %f, %f, %f, %f }\n",
177 * Check if there's a potential src/dst register data dependency when
178 * using SOA execution.
181 * This would expand into:
186 * The second instruction will have the wrong value for t0 if executed as-is.
189 tgsi_check_soa_dependencies(const struct tgsi_full_instruction
*inst
)
193 uint writemask
= inst
->FullDstRegisters
[0].DstRegister
.WriteMask
;
194 if (writemask
== TGSI_WRITEMASK_X
||
195 writemask
== TGSI_WRITEMASK_Y
||
196 writemask
== TGSI_WRITEMASK_Z
||
197 writemask
== TGSI_WRITEMASK_W
||
198 writemask
== TGSI_WRITEMASK_NONE
) {
199 /* no chance of data dependency */
203 /* loop over src regs */
204 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
205 if ((inst
->FullSrcRegisters
[i
].SrcRegister
.File
==
206 inst
->FullDstRegisters
[0].DstRegister
.File
) &&
207 (inst
->FullSrcRegisters
[i
].SrcRegister
.Index
==
208 inst
->FullDstRegisters
[0].DstRegister
.Index
)) {
209 /* loop over dest channels */
210 uint channelsWritten
= 0x0;
211 FOR_EACH_ENABLED_CHANNEL(*inst
, chan
) {
212 /* check if we're reading a channel that's been written */
213 uint swizzle
= tgsi_util_get_full_src_register_extswizzle(&inst
->FullSrcRegisters
[i
], chan
);
214 if (swizzle
<= TGSI_SWIZZLE_W
&&
215 (channelsWritten
& (1 << swizzle
))) {
219 channelsWritten
|= (1 << chan
);
228 * Initialize machine state by expanding tokens to full instructions,
229 * allocating temporary storage, setting up constants, etc.
230 * After this, we can call tgsi_exec_machine_run() many times.
233 tgsi_exec_machine_bind_shader(
234 struct tgsi_exec_machine
*mach
,
235 const struct tgsi_token
*tokens
,
237 struct tgsi_sampler
**samplers
)
240 struct tgsi_parse_context parse
;
241 struct tgsi_exec_labels
*labels
= &mach
->Labels
;
242 struct tgsi_full_instruction
*instructions
;
243 struct tgsi_full_declaration
*declarations
;
244 uint maxInstructions
= 10, numInstructions
= 0;
245 uint maxDeclarations
= 10, numDeclarations
= 0;
249 tgsi_dump(tokens
, 0);
254 mach
->Tokens
= tokens
;
255 mach
->Samplers
= samplers
;
257 k
= tgsi_parse_init (&parse
, mach
->Tokens
);
258 if (k
!= TGSI_PARSE_OK
) {
259 debug_printf( "Problem parsing!\n" );
263 mach
->Processor
= parse
.FullHeader
.Processor
.Processor
;
267 declarations
= (struct tgsi_full_declaration
*)
268 MALLOC( maxDeclarations
* sizeof(struct tgsi_full_declaration
) );
274 instructions
= (struct tgsi_full_instruction
*)
275 MALLOC( maxInstructions
* sizeof(struct tgsi_full_instruction
) );
278 FREE( declarations
);
282 while( !tgsi_parse_end_of_tokens( &parse
) ) {
283 uint pointer
= parse
.Position
;
286 tgsi_parse_token( &parse
);
287 switch( parse
.FullToken
.Token
.Type
) {
288 case TGSI_TOKEN_TYPE_DECLARATION
:
289 /* save expanded declaration */
290 if (numDeclarations
== maxDeclarations
) {
291 declarations
= REALLOC(declarations
,
293 * sizeof(struct tgsi_full_declaration
),
294 (maxDeclarations
+ 10)
295 * sizeof(struct tgsi_full_declaration
));
296 maxDeclarations
+= 10;
298 memcpy(declarations
+ numDeclarations
,
299 &parse
.FullToken
.FullDeclaration
,
300 sizeof(declarations
[0]));
304 case TGSI_TOKEN_TYPE_IMMEDIATE
:
306 uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
308 assert( mach
->ImmLimit
+ 1 <= TGSI_EXEC_NUM_IMMEDIATES
);
310 for( i
= 0; i
< size
; i
++ ) {
311 mach
->Imms
[mach
->ImmLimit
][i
] =
312 parse
.FullToken
.FullImmediate
.u
[i
].Float
;
318 case TGSI_TOKEN_TYPE_INSTRUCTION
:
319 assert( labels
->count
< MAX_LABELS
);
321 labels
->labels
[labels
->count
][0] = instno
;
322 labels
->labels
[labels
->count
][1] = pointer
;
325 /* save expanded instruction */
326 if (numInstructions
== maxInstructions
) {
327 instructions
= REALLOC(instructions
,
329 * sizeof(struct tgsi_full_instruction
),
330 (maxInstructions
+ 10)
331 * sizeof(struct tgsi_full_instruction
));
332 maxInstructions
+= 10;
335 if (tgsi_check_soa_dependencies(&parse
.FullToken
.FullInstruction
)) {
336 uint opcode
= parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
337 parse
.FullToken
.FullInstruction
.Flags
= SOA_DEPENDENCY_FLAG
;
338 /* XXX we only handle SOA dependencies properly for MOV/SWZ
341 if (opcode
!= TGSI_OPCODE_MOV
&& opcode
!= TGSI_OPCODE_SWZ
) {
342 debug_printf("Warning: SOA dependency in instruction"
343 " is not handled:\n");
344 tgsi_dump_instruction(&parse
.FullToken
.FullInstruction
,
349 memcpy(instructions
+ numInstructions
,
350 &parse
.FullToken
.FullInstruction
,
351 sizeof(instructions
[0]));
360 tgsi_parse_free (&parse
);
362 if (mach
->Declarations
) {
363 FREE( mach
->Declarations
);
365 mach
->Declarations
= declarations
;
366 mach
->NumDeclarations
= numDeclarations
;
368 if (mach
->Instructions
) {
369 FREE( mach
->Instructions
);
371 mach
->Instructions
= instructions
;
372 mach
->NumInstructions
= numInstructions
;
376 struct tgsi_exec_machine
*
377 tgsi_exec_machine_create( void )
379 struct tgsi_exec_machine
*mach
;
382 mach
= align_malloc( sizeof *mach
, 16 );
386 memset(mach
, 0, sizeof(*mach
));
388 mach
->Addrs
= &mach
->Temps
[TGSI_EXEC_TEMP_ADDR
];
390 /* Setup constants. */
391 for( i
= 0; i
< 4; i
++ ) {
392 mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
].u
[i
] = 0x00000000;
393 mach
->Temps
[TEMP_7F_I
].xyzw
[TEMP_7F_C
].u
[i
] = 0x7FFFFFFF;
394 mach
->Temps
[TEMP_80_I
].xyzw
[TEMP_80_C
].u
[i
] = 0x80000000;
395 mach
->Temps
[TEMP_FF_I
].xyzw
[TEMP_FF_C
].u
[i
] = 0xFFFFFFFF;
396 mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
].f
[i
] = 1.0f
;
397 mach
->Temps
[TEMP_2_I
].xyzw
[TEMP_2_C
].f
[i
] = 2.0f
;
398 mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
].f
[i
] = 128.0f
;
399 mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
].f
[i
] = -128.0f
;
400 mach
->Temps
[TEMP_3_I
].xyzw
[TEMP_3_C
].f
[i
] = 3.0f
;
401 mach
->Temps
[TEMP_HALF_I
].xyzw
[TEMP_HALF_C
].f
[i
] = 0.5f
;
405 /* silence warnings */
419 tgsi_exec_machine_destroy(struct tgsi_exec_machine
*mach
)
422 FREE(mach
->Instructions
);
423 FREE(mach
->Declarations
);
432 union tgsi_exec_channel
*dst
,
433 const union tgsi_exec_channel
*src
)
435 dst
->f
[0] = fabsf( src
->f
[0] );
436 dst
->f
[1] = fabsf( src
->f
[1] );
437 dst
->f
[2] = fabsf( src
->f
[2] );
438 dst
->f
[3] = fabsf( src
->f
[3] );
443 union tgsi_exec_channel
*dst
,
444 const union tgsi_exec_channel
*src0
,
445 const union tgsi_exec_channel
*src1
)
447 dst
->f
[0] = src0
->f
[0] + src1
->f
[0];
448 dst
->f
[1] = src0
->f
[1] + src1
->f
[1];
449 dst
->f
[2] = src0
->f
[2] + src1
->f
[2];
450 dst
->f
[3] = src0
->f
[3] + src1
->f
[3];
456 union tgsi_exec_channel
*dst
,
457 const union tgsi_exec_channel
*src0
,
458 const union tgsi_exec_channel
*src1
)
460 dst
->i
[0] = src0
->i
[0] + src1
->i
[0];
461 dst
->i
[1] = src0
->i
[1] + src1
->i
[1];
462 dst
->i
[2] = src0
->i
[2] + src1
->i
[2];
463 dst
->i
[3] = src0
->i
[3] + src1
->i
[3];
469 union tgsi_exec_channel
*dst
,
470 const union tgsi_exec_channel
*src0
,
471 const union tgsi_exec_channel
*src1
)
473 dst
->u
[0] = src0
->u
[0] & src1
->u
[0];
474 dst
->u
[1] = src0
->u
[1] & src1
->u
[1];
475 dst
->u
[2] = src0
->u
[2] & src1
->u
[2];
476 dst
->u
[3] = src0
->u
[3] & src1
->u
[3];
481 union tgsi_exec_channel
*dst
,
482 const union tgsi_exec_channel
*src
)
484 dst
->f
[0] = ceilf( src
->f
[0] );
485 dst
->f
[1] = ceilf( src
->f
[1] );
486 dst
->f
[2] = ceilf( src
->f
[2] );
487 dst
->f
[3] = ceilf( src
->f
[3] );
492 union tgsi_exec_channel
*dst
,
493 const union tgsi_exec_channel
*src
)
495 dst
->f
[0] = cosf( src
->f
[0] );
496 dst
->f
[1] = cosf( src
->f
[1] );
497 dst
->f
[2] = cosf( src
->f
[2] );
498 dst
->f
[3] = cosf( src
->f
[3] );
503 union tgsi_exec_channel
*dst
,
504 const union tgsi_exec_channel
*src
)
509 dst
->f
[3] = src
->f
[TILE_BOTTOM_RIGHT
] - src
->f
[TILE_BOTTOM_LEFT
];
514 union tgsi_exec_channel
*dst
,
515 const union tgsi_exec_channel
*src
)
520 dst
->f
[3] = src
->f
[TILE_TOP_LEFT
] - src
->f
[TILE_BOTTOM_LEFT
];
525 union tgsi_exec_channel
*dst
,
526 const union tgsi_exec_channel
*src0
,
527 const union tgsi_exec_channel
*src1
)
529 if (src1
->f
[0] != 0) {
530 dst
->f
[0] = src0
->f
[0] / src1
->f
[0];
532 if (src1
->f
[1] != 0) {
533 dst
->f
[1] = src0
->f
[1] / src1
->f
[1];
535 if (src1
->f
[2] != 0) {
536 dst
->f
[2] = src0
->f
[2] / src1
->f
[2];
538 if (src1
->f
[3] != 0) {
539 dst
->f
[3] = src0
->f
[3] / src1
->f
[3];
546 union tgsi_exec_channel
*dst
,
547 const union tgsi_exec_channel
*src0
,
548 const union tgsi_exec_channel
*src1
)
550 dst
->u
[0] = src0
->u
[0] / src1
->u
[0];
551 dst
->u
[1] = src0
->u
[1] / src1
->u
[1];
552 dst
->u
[2] = src0
->u
[2] / src1
->u
[2];
553 dst
->u
[3] = src0
->u
[3] / src1
->u
[3];
559 union tgsi_exec_channel
*dst
,
560 const union tgsi_exec_channel
*src0
,
561 const union tgsi_exec_channel
*src1
,
562 const union tgsi_exec_channel
*src2
,
563 const union tgsi_exec_channel
*src3
)
565 dst
->f
[0] = src0
->f
[0] == src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
566 dst
->f
[1] = src0
->f
[1] == src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
567 dst
->f
[2] = src0
->f
[2] == src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
568 dst
->f
[3] = src0
->f
[3] == src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
574 union tgsi_exec_channel
*dst
,
575 const union tgsi_exec_channel
*src0
,
576 const union tgsi_exec_channel
*src1
,
577 const union tgsi_exec_channel
*src2
,
578 const union tgsi_exec_channel
*src3
)
580 dst
->i
[0] = src0
->i
[0] == src1
->i
[0] ? src2
->i
[0] : src3
->i
[0];
581 dst
->i
[1] = src0
->i
[1] == src1
->i
[1] ? src2
->i
[1] : src3
->i
[1];
582 dst
->i
[2] = src0
->i
[2] == src1
->i
[2] ? src2
->i
[2] : src3
->i
[2];
583 dst
->i
[3] = src0
->i
[3] == src1
->i
[3] ? src2
->i
[3] : src3
->i
[3];
589 union tgsi_exec_channel
*dst
,
590 const union tgsi_exec_channel
*src
)
593 dst
->f
[0] = util_fast_exp2( src
->f
[0] );
594 dst
->f
[1] = util_fast_exp2( src
->f
[1] );
595 dst
->f
[2] = util_fast_exp2( src
->f
[2] );
596 dst
->f
[3] = util_fast_exp2( src
->f
[3] );
598 dst
->f
[0] = powf( 2.0f
, src
->f
[0] );
599 dst
->f
[1] = powf( 2.0f
, src
->f
[1] );
600 dst
->f
[2] = powf( 2.0f
, src
->f
[2] );
601 dst
->f
[3] = powf( 2.0f
, src
->f
[3] );
608 union tgsi_exec_channel
*dst
,
609 const union tgsi_exec_channel
*src
)
611 dst
->u
[0] = (uint
) src
->f
[0];
612 dst
->u
[1] = (uint
) src
->f
[1];
613 dst
->u
[2] = (uint
) src
->f
[2];
614 dst
->u
[3] = (uint
) src
->f
[3];
619 micro_float_clamp(union tgsi_exec_channel
*dst
,
620 const union tgsi_exec_channel
*src
)
624 for (i
= 0; i
< 4; i
++) {
625 if (src
->f
[i
] > 0.0f
) {
626 if (src
->f
[i
] > 1.884467e+019f
)
627 dst
->f
[i
] = 1.884467e+019f
;
628 else if (src
->f
[i
] < 5.42101e-020f
)
629 dst
->f
[i
] = 5.42101e-020f
;
631 dst
->f
[i
] = src
->f
[i
];
634 if (src
->f
[i
] < -1.884467e+019f
)
635 dst
->f
[i
] = -1.884467e+019f
;
636 else if (src
->f
[i
] > -5.42101e-020f
)
637 dst
->f
[i
] = -5.42101e-020f
;
639 dst
->f
[i
] = src
->f
[i
];
646 union tgsi_exec_channel
*dst
,
647 const union tgsi_exec_channel
*src
)
649 dst
->f
[0] = floorf( src
->f
[0] );
650 dst
->f
[1] = floorf( src
->f
[1] );
651 dst
->f
[2] = floorf( src
->f
[2] );
652 dst
->f
[3] = floorf( src
->f
[3] );
657 union tgsi_exec_channel
*dst
,
658 const union tgsi_exec_channel
*src
)
660 dst
->f
[0] = src
->f
[0] - floorf( src
->f
[0] );
661 dst
->f
[1] = src
->f
[1] - floorf( src
->f
[1] );
662 dst
->f
[2] = src
->f
[2] - floorf( src
->f
[2] );
663 dst
->f
[3] = src
->f
[3] - floorf( src
->f
[3] );
668 union tgsi_exec_channel
*dst
,
669 const union tgsi_exec_channel
*src
)
671 dst
->f
[0] = (float) src
->i
[0];
672 dst
->f
[1] = (float) src
->i
[1];
673 dst
->f
[2] = (float) src
->i
[2];
674 dst
->f
[3] = (float) src
->i
[3];
679 union tgsi_exec_channel
*dst
,
680 const union tgsi_exec_channel
*src
)
683 dst
->f
[0] = util_fast_log2( src
->f
[0] );
684 dst
->f
[1] = util_fast_log2( src
->f
[1] );
685 dst
->f
[2] = util_fast_log2( src
->f
[2] );
686 dst
->f
[3] = util_fast_log2( src
->f
[3] );
688 dst
->f
[0] = logf( src
->f
[0] ) * 1.442695f
;
689 dst
->f
[1] = logf( src
->f
[1] ) * 1.442695f
;
690 dst
->f
[2] = logf( src
->f
[2] ) * 1.442695f
;
691 dst
->f
[3] = logf( src
->f
[3] ) * 1.442695f
;
697 union tgsi_exec_channel
*dst
,
698 const union tgsi_exec_channel
*src0
,
699 const union tgsi_exec_channel
*src1
,
700 const union tgsi_exec_channel
*src2
,
701 const union tgsi_exec_channel
*src3
)
703 dst
->f
[0] = src0
->f
[0] <= src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
704 dst
->f
[1] = src0
->f
[1] <= src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
705 dst
->f
[2] = src0
->f
[2] <= src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
706 dst
->f
[3] = src0
->f
[3] <= src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
711 union tgsi_exec_channel
*dst
,
712 const union tgsi_exec_channel
*src0
,
713 const union tgsi_exec_channel
*src1
,
714 const union tgsi_exec_channel
*src2
,
715 const union tgsi_exec_channel
*src3
)
717 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
718 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
719 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
720 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
726 union tgsi_exec_channel
*dst
,
727 const union tgsi_exec_channel
*src0
,
728 const union tgsi_exec_channel
*src1
,
729 const union tgsi_exec_channel
*src2
,
730 const union tgsi_exec_channel
*src3
)
732 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? src2
->i
[0] : src3
->i
[0];
733 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? src2
->i
[1] : src3
->i
[1];
734 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? src2
->i
[2] : src3
->i
[2];
735 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? src2
->i
[3] : src3
->i
[3];
742 union tgsi_exec_channel
*dst
,
743 const union tgsi_exec_channel
*src0
,
744 const union tgsi_exec_channel
*src1
,
745 const union tgsi_exec_channel
*src2
,
746 const union tgsi_exec_channel
*src3
)
748 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? src2
->u
[0] : src3
->u
[0];
749 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? src2
->u
[1] : src3
->u
[1];
750 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? src2
->u
[2] : src3
->u
[2];
751 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? src2
->u
[3] : src3
->u
[3];
757 union tgsi_exec_channel
*dst
,
758 const union tgsi_exec_channel
*src0
,
759 const union tgsi_exec_channel
*src1
)
761 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
762 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
763 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
764 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
770 union tgsi_exec_channel
*dst
,
771 const union tgsi_exec_channel
*src0
,
772 const union tgsi_exec_channel
*src1
)
774 dst
->i
[0] = src0
->i
[0] > src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
775 dst
->i
[1] = src0
->i
[1] > src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
776 dst
->i
[2] = src0
->i
[2] > src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
777 dst
->i
[3] = src0
->i
[3] > src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
784 union tgsi_exec_channel
*dst
,
785 const union tgsi_exec_channel
*src0
,
786 const union tgsi_exec_channel
*src1
)
788 dst
->u
[0] = src0
->u
[0] > src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
789 dst
->u
[1] = src0
->u
[1] > src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
790 dst
->u
[2] = src0
->u
[2] > src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
791 dst
->u
[3] = src0
->u
[3] > src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
797 union tgsi_exec_channel
*dst
,
798 const union tgsi_exec_channel
*src0
,
799 const union tgsi_exec_channel
*src1
)
801 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
802 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
803 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
804 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
810 union tgsi_exec_channel
*dst
,
811 const union tgsi_exec_channel
*src0
,
812 const union tgsi_exec_channel
*src1
)
814 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
815 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
816 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
817 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
824 union tgsi_exec_channel
*dst
,
825 const union tgsi_exec_channel
*src0
,
826 const union tgsi_exec_channel
*src1
)
828 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
829 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
830 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
831 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
838 union tgsi_exec_channel
*dst
,
839 const union tgsi_exec_channel
*src0
,
840 const union tgsi_exec_channel
*src1
)
842 dst
->u
[0] = src0
->u
[0] % src1
->u
[0];
843 dst
->u
[1] = src0
->u
[1] % src1
->u
[1];
844 dst
->u
[2] = src0
->u
[2] % src1
->u
[2];
845 dst
->u
[3] = src0
->u
[3] % src1
->u
[3];
851 union tgsi_exec_channel
*dst
,
852 const union tgsi_exec_channel
*src0
,
853 const union tgsi_exec_channel
*src1
)
855 dst
->f
[0] = src0
->f
[0] * src1
->f
[0];
856 dst
->f
[1] = src0
->f
[1] * src1
->f
[1];
857 dst
->f
[2] = src0
->f
[2] * src1
->f
[2];
858 dst
->f
[3] = src0
->f
[3] * src1
->f
[3];
864 union tgsi_exec_channel
*dst
,
865 const union tgsi_exec_channel
*src0
,
866 const union tgsi_exec_channel
*src1
)
868 dst
->i
[0] = src0
->i
[0] * src1
->i
[0];
869 dst
->i
[1] = src0
->i
[1] * src1
->i
[1];
870 dst
->i
[2] = src0
->i
[2] * src1
->i
[2];
871 dst
->i
[3] = src0
->i
[3] * src1
->i
[3];
878 union tgsi_exec_channel
*dst0
,
879 union tgsi_exec_channel
*dst1
,
880 const union tgsi_exec_channel
*src0
,
881 const union tgsi_exec_channel
*src1
)
883 dst1
->i
[0] = src0
->i
[0] * src1
->i
[0];
884 dst1
->i
[1] = src0
->i
[1] * src1
->i
[1];
885 dst1
->i
[2] = src0
->i
[2] * src1
->i
[2];
886 dst1
->i
[3] = src0
->i
[3] * src1
->i
[3];
897 union tgsi_exec_channel
*dst0
,
898 union tgsi_exec_channel
*dst1
,
899 const union tgsi_exec_channel
*src0
,
900 const union tgsi_exec_channel
*src1
)
902 dst1
->u
[0] = src0
->u
[0] * src1
->u
[0];
903 dst1
->u
[1] = src0
->u
[1] * src1
->u
[1];
904 dst1
->u
[2] = src0
->u
[2] * src1
->u
[2];
905 dst1
->u
[3] = src0
->u
[3] * src1
->u
[3];
917 union tgsi_exec_channel
*dst
,
918 const union tgsi_exec_channel
*src0
,
919 const union tgsi_exec_channel
*src1
,
920 const union tgsi_exec_channel
*src2
)
922 dst
->u
[0] = src0
->u
[0] ? src1
->u
[0] : src2
->u
[0];
923 dst
->u
[1] = src0
->u
[1] ? src1
->u
[1] : src2
->u
[1];
924 dst
->u
[2] = src0
->u
[2] ? src1
->u
[2] : src2
->u
[2];
925 dst
->u
[3] = src0
->u
[3] ? src1
->u
[3] : src2
->u
[3];
931 union tgsi_exec_channel
*dst
,
932 const union tgsi_exec_channel
*src
)
934 dst
->f
[0] = -src
->f
[0];
935 dst
->f
[1] = -src
->f
[1];
936 dst
->f
[2] = -src
->f
[2];
937 dst
->f
[3] = -src
->f
[3];
943 union tgsi_exec_channel
*dst
,
944 const union tgsi_exec_channel
*src
)
946 dst
->i
[0] = -src
->i
[0];
947 dst
->i
[1] = -src
->i
[1];
948 dst
->i
[2] = -src
->i
[2];
949 dst
->i
[3] = -src
->i
[3];
955 union tgsi_exec_channel
*dst
,
956 const union tgsi_exec_channel
*src
)
958 dst
->u
[0] = ~src
->u
[0];
959 dst
->u
[1] = ~src
->u
[1];
960 dst
->u
[2] = ~src
->u
[2];
961 dst
->u
[3] = ~src
->u
[3];
966 union tgsi_exec_channel
*dst
,
967 const union tgsi_exec_channel
*src0
,
968 const union tgsi_exec_channel
*src1
)
970 dst
->u
[0] = src0
->u
[0] | src1
->u
[0];
971 dst
->u
[1] = src0
->u
[1] | src1
->u
[1];
972 dst
->u
[2] = src0
->u
[2] | src1
->u
[2];
973 dst
->u
[3] = src0
->u
[3] | src1
->u
[3];
978 union tgsi_exec_channel
*dst
,
979 const union tgsi_exec_channel
*src0
,
980 const union tgsi_exec_channel
*src1
)
983 dst
->f
[0] = util_fast_pow( src0
->f
[0], src1
->f
[0] );
984 dst
->f
[1] = util_fast_pow( src0
->f
[1], src1
->f
[1] );
985 dst
->f
[2] = util_fast_pow( src0
->f
[2], src1
->f
[2] );
986 dst
->f
[3] = util_fast_pow( src0
->f
[3], src1
->f
[3] );
988 dst
->f
[0] = powf( src0
->f
[0], src1
->f
[0] );
989 dst
->f
[1] = powf( src0
->f
[1], src1
->f
[1] );
990 dst
->f
[2] = powf( src0
->f
[2], src1
->f
[2] );
991 dst
->f
[3] = powf( src0
->f
[3], src1
->f
[3] );
997 union tgsi_exec_channel
*dst
,
998 const union tgsi_exec_channel
*src
)
1000 dst
->f
[0] = floorf( src
->f
[0] + 0.5f
);
1001 dst
->f
[1] = floorf( src
->f
[1] + 0.5f
);
1002 dst
->f
[2] = floorf( src
->f
[2] + 0.5f
);
1003 dst
->f
[3] = floorf( src
->f
[3] + 0.5f
);
1008 union tgsi_exec_channel
*dst
,
1009 const union tgsi_exec_channel
*src
)
1011 dst
->f
[0] = src
->f
[0] < 0.0f
? -1.0f
: src
->f
[0] > 0.0f
? 1.0f
: 0.0f
;
1012 dst
->f
[1] = src
->f
[1] < 0.0f
? -1.0f
: src
->f
[1] > 0.0f
? 1.0f
: 0.0f
;
1013 dst
->f
[2] = src
->f
[2] < 0.0f
? -1.0f
: src
->f
[2] > 0.0f
? 1.0f
: 0.0f
;
1014 dst
->f
[3] = src
->f
[3] < 0.0f
? -1.0f
: src
->f
[3] > 0.0f
? 1.0f
: 0.0f
;
1019 union tgsi_exec_channel
*dst
,
1020 const union tgsi_exec_channel
*src0
,
1021 const union tgsi_exec_channel
*src1
)
1023 dst
->i
[0] = src0
->i
[0] << src1
->i
[0];
1024 dst
->i
[1] = src0
->i
[1] << src1
->i
[1];
1025 dst
->i
[2] = src0
->i
[2] << src1
->i
[2];
1026 dst
->i
[3] = src0
->i
[3] << src1
->i
[3];
1031 union tgsi_exec_channel
*dst
,
1032 const union tgsi_exec_channel
*src0
,
1033 const union tgsi_exec_channel
*src1
)
1035 dst
->i
[0] = src0
->i
[0] >> src1
->i
[0];
1036 dst
->i
[1] = src0
->i
[1] >> src1
->i
[1];
1037 dst
->i
[2] = src0
->i
[2] >> src1
->i
[2];
1038 dst
->i
[3] = src0
->i
[3] >> src1
->i
[3];
1043 union tgsi_exec_channel
*dst
,
1044 const union tgsi_exec_channel
*src0
)
1046 dst
->f
[0] = (float) (int) src0
->f
[0];
1047 dst
->f
[1] = (float) (int) src0
->f
[1];
1048 dst
->f
[2] = (float) (int) src0
->f
[2];
1049 dst
->f
[3] = (float) (int) src0
->f
[3];
1055 union tgsi_exec_channel
*dst
,
1056 const union tgsi_exec_channel
*src0
,
1057 const union tgsi_exec_channel
*src1
)
1059 dst
->u
[0] = src0
->u
[0] >> src1
->u
[0];
1060 dst
->u
[1] = src0
->u
[1] >> src1
->u
[1];
1061 dst
->u
[2] = src0
->u
[2] >> src1
->u
[2];
1062 dst
->u
[3] = src0
->u
[3] >> src1
->u
[3];
1068 union tgsi_exec_channel
*dst
,
1069 const union tgsi_exec_channel
*src
)
1071 dst
->f
[0] = sinf( src
->f
[0] );
1072 dst
->f
[1] = sinf( src
->f
[1] );
1073 dst
->f
[2] = sinf( src
->f
[2] );
1074 dst
->f
[3] = sinf( src
->f
[3] );
1078 micro_sqrt( union tgsi_exec_channel
*dst
,
1079 const union tgsi_exec_channel
*src
)
1081 dst
->f
[0] = sqrtf( src
->f
[0] );
1082 dst
->f
[1] = sqrtf( src
->f
[1] );
1083 dst
->f
[2] = sqrtf( src
->f
[2] );
1084 dst
->f
[3] = sqrtf( src
->f
[3] );
1089 union tgsi_exec_channel
*dst
,
1090 const union tgsi_exec_channel
*src0
,
1091 const union tgsi_exec_channel
*src1
)
1093 dst
->f
[0] = src0
->f
[0] - src1
->f
[0];
1094 dst
->f
[1] = src0
->f
[1] - src1
->f
[1];
1095 dst
->f
[2] = src0
->f
[2] - src1
->f
[2];
1096 dst
->f
[3] = src0
->f
[3] - src1
->f
[3];
1102 union tgsi_exec_channel
*dst
,
1103 const union tgsi_exec_channel
*src
)
1105 dst
->f
[0] = (float) src
->u
[0];
1106 dst
->f
[1] = (float) src
->u
[1];
1107 dst
->f
[2] = (float) src
->u
[2];
1108 dst
->f
[3] = (float) src
->u
[3];
1114 union tgsi_exec_channel
*dst
,
1115 const union tgsi_exec_channel
*src0
,
1116 const union tgsi_exec_channel
*src1
)
1118 dst
->u
[0] = src0
->u
[0] ^ src1
->u
[0];
1119 dst
->u
[1] = src0
->u
[1] ^ src1
->u
[1];
1120 dst
->u
[2] = src0
->u
[2] ^ src1
->u
[2];
1121 dst
->u
[3] = src0
->u
[3] ^ src1
->u
[3];
1125 fetch_src_file_channel(
1126 const struct tgsi_exec_machine
*mach
,
1129 const union tgsi_exec_channel
*index
,
1130 union tgsi_exec_channel
*chan
)
1133 case TGSI_EXTSWIZZLE_X
:
1134 case TGSI_EXTSWIZZLE_Y
:
1135 case TGSI_EXTSWIZZLE_Z
:
1136 case TGSI_EXTSWIZZLE_W
:
1138 case TGSI_FILE_CONSTANT
:
1139 assert(mach
->Consts
);
1140 if (index
->i
[0] < 0)
1143 chan
->f
[0] = mach
->Consts
[index
->i
[0]][swizzle
];
1144 if (index
->i
[1] < 0)
1147 chan
->f
[1] = mach
->Consts
[index
->i
[1]][swizzle
];
1148 if (index
->i
[2] < 0)
1151 chan
->f
[2] = mach
->Consts
[index
->i
[2]][swizzle
];
1152 if (index
->i
[3] < 0)
1155 chan
->f
[3] = mach
->Consts
[index
->i
[3]][swizzle
];
1158 case TGSI_FILE_INPUT
:
1159 chan
->u
[0] = mach
->Inputs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1160 chan
->u
[1] = mach
->Inputs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1161 chan
->u
[2] = mach
->Inputs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1162 chan
->u
[3] = mach
->Inputs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1165 case TGSI_FILE_TEMPORARY
:
1166 assert(index
->i
[0] < TGSI_EXEC_NUM_TEMPS
);
1167 chan
->u
[0] = mach
->Temps
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1168 chan
->u
[1] = mach
->Temps
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1169 chan
->u
[2] = mach
->Temps
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1170 chan
->u
[3] = mach
->Temps
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1173 case TGSI_FILE_IMMEDIATE
:
1174 assert( index
->i
[0] < (int) mach
->ImmLimit
);
1175 chan
->f
[0] = mach
->Imms
[index
->i
[0]][swizzle
];
1176 assert( index
->i
[1] < (int) mach
->ImmLimit
);
1177 chan
->f
[1] = mach
->Imms
[index
->i
[1]][swizzle
];
1178 assert( index
->i
[2] < (int) mach
->ImmLimit
);
1179 chan
->f
[2] = mach
->Imms
[index
->i
[2]][swizzle
];
1180 assert( index
->i
[3] < (int) mach
->ImmLimit
);
1181 chan
->f
[3] = mach
->Imms
[index
->i
[3]][swizzle
];
1184 case TGSI_FILE_ADDRESS
:
1185 chan
->u
[0] = mach
->Addrs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1186 chan
->u
[1] = mach
->Addrs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1187 chan
->u
[2] = mach
->Addrs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1188 chan
->u
[3] = mach
->Addrs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1191 case TGSI_FILE_OUTPUT
:
1192 /* vertex/fragment output vars can be read too */
1193 chan
->u
[0] = mach
->Outputs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1194 chan
->u
[1] = mach
->Outputs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1195 chan
->u
[2] = mach
->Outputs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1196 chan
->u
[3] = mach
->Outputs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1204 case TGSI_EXTSWIZZLE_ZERO
:
1205 *chan
= mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
];
1208 case TGSI_EXTSWIZZLE_ONE
:
1209 *chan
= mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
];
1219 const struct tgsi_exec_machine
*mach
,
1220 union tgsi_exec_channel
*chan
,
1221 const struct tgsi_full_src_register
*reg
,
1222 const uint chan_index
)
1224 union tgsi_exec_channel index
;
1227 /* We start with a direct index into a register file.
1231 * file = SrcRegister.File
1232 * [1] = SrcRegister.Index
1237 index
.i
[3] = reg
->SrcRegister
.Index
;
1239 /* There is an extra source register that indirectly subscripts
1240 * a register file. The direct index now becomes an offset
1241 * that is being added to the indirect register.
1245 * ind = SrcRegisterInd.File
1246 * [2] = SrcRegisterInd.Index
1247 * .x = SrcRegisterInd.SwizzleX
1249 if (reg
->SrcRegister
.Indirect
) {
1250 union tgsi_exec_channel index2
;
1251 union tgsi_exec_channel indir_index
;
1252 const uint execmask
= mach
->ExecMask
;
1255 /* which address register (always zero now) */
1259 index2
.i
[3] = reg
->SrcRegisterInd
.Index
;
1261 /* get current value of address register[swizzle] */
1262 swizzle
= tgsi_util_get_src_register_swizzle( ®
->SrcRegisterInd
, CHAN_X
);
1263 fetch_src_file_channel(
1265 reg
->SrcRegisterInd
.File
,
1270 /* add value of address register to the offset */
1271 index
.i
[0] += (int) indir_index
.f
[0];
1272 index
.i
[1] += (int) indir_index
.f
[1];
1273 index
.i
[2] += (int) indir_index
.f
[2];
1274 index
.i
[3] += (int) indir_index
.f
[3];
1276 /* for disabled execution channels, zero-out the index to
1277 * avoid using a potential garbage value.
1279 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1280 if ((execmask
& (1 << i
)) == 0)
1285 /* There is an extra source register that is a second
1286 * subscript to a register file. Effectively it means that
1287 * the register file is actually a 2D array of registers.
1289 * file[1][3] == file[1*sizeof(file[1])+3],
1291 * [3] = SrcRegisterDim.Index
1293 if (reg
->SrcRegister
.Dimension
) {
1294 /* The size of the first-order array depends on the register file type.
1295 * We need to multiply the index to the first array to get an effective,
1296 * "flat" index that points to the beginning of the second-order array.
1298 switch (reg
->SrcRegister
.File
) {
1299 case TGSI_FILE_INPUT
:
1300 index
.i
[0] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1301 index
.i
[1] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1302 index
.i
[2] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1303 index
.i
[3] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1305 case TGSI_FILE_CONSTANT
:
1306 index
.i
[0] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1307 index
.i
[1] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1308 index
.i
[2] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1309 index
.i
[3] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1315 index
.i
[0] += reg
->SrcRegisterDim
.Index
;
1316 index
.i
[1] += reg
->SrcRegisterDim
.Index
;
1317 index
.i
[2] += reg
->SrcRegisterDim
.Index
;
1318 index
.i
[3] += reg
->SrcRegisterDim
.Index
;
1320 /* Again, the second subscript index can be addressed indirectly
1321 * identically to the first one.
1322 * Nothing stops us from indirectly addressing the indirect register,
1323 * but there is no need for that, so we won't exercise it.
1325 * file[1][ind[4].y+3],
1327 * ind = SrcRegisterDimInd.File
1328 * [4] = SrcRegisterDimInd.Index
1329 * .y = SrcRegisterDimInd.SwizzleX
1331 if (reg
->SrcRegisterDim
.Indirect
) {
1332 union tgsi_exec_channel index2
;
1333 union tgsi_exec_channel indir_index
;
1334 const uint execmask
= mach
->ExecMask
;
1340 index2
.i
[3] = reg
->SrcRegisterDimInd
.Index
;
1342 swizzle
= tgsi_util_get_src_register_swizzle( ®
->SrcRegisterDimInd
, CHAN_X
);
1343 fetch_src_file_channel(
1345 reg
->SrcRegisterDimInd
.File
,
1350 index
.i
[0] += (int) indir_index
.f
[0];
1351 index
.i
[1] += (int) indir_index
.f
[1];
1352 index
.i
[2] += (int) indir_index
.f
[2];
1353 index
.i
[3] += (int) indir_index
.f
[3];
1355 /* for disabled execution channels, zero-out the index to
1356 * avoid using a potential garbage value.
1358 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1359 if ((execmask
& (1 << i
)) == 0)
1364 /* If by any chance there was a need for a 3D array of register
1365 * files, we would have to check whether SrcRegisterDim is followed
1366 * by a dimension register and continue the saga.
1370 swizzle
= tgsi_util_get_full_src_register_extswizzle( reg
, chan_index
);
1371 fetch_src_file_channel(
1373 reg
->SrcRegister
.File
,
1378 switch (tgsi_util_get_full_src_register_sign_mode( reg
, chan_index
)) {
1379 case TGSI_UTIL_SIGN_CLEAR
:
1380 micro_abs( chan
, chan
);
1383 case TGSI_UTIL_SIGN_SET
:
1384 micro_abs( chan
, chan
);
1385 micro_neg( chan
, chan
);
1388 case TGSI_UTIL_SIGN_TOGGLE
:
1389 micro_neg( chan
, chan
);
1392 case TGSI_UTIL_SIGN_KEEP
:
1396 if (reg
->SrcRegisterExtMod
.Complement
) {
1397 micro_sub( chan
, &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], chan
);
1403 struct tgsi_exec_machine
*mach
,
1404 const union tgsi_exec_channel
*chan
,
1405 const struct tgsi_full_dst_register
*reg
,
1406 const struct tgsi_full_instruction
*inst
,
1410 union tgsi_exec_channel null
;
1411 union tgsi_exec_channel
*dst
;
1412 uint execmask
= mach
->ExecMask
;
1413 int offset
= 0; /* indirection offset */
1417 check_inf_or_nan(chan
);
1420 /* There is an extra source register that indirectly subscripts
1421 * a register file. The direct index now becomes an offset
1422 * that is being added to the indirect register.
1426 * ind = DstRegisterInd.File
1427 * [2] = DstRegisterInd.Index
1428 * .x = DstRegisterInd.SwizzleX
1430 if (reg
->DstRegister
.Indirect
) {
1431 union tgsi_exec_channel index
;
1432 union tgsi_exec_channel indir_index
;
1435 /* which address register (always zero for now) */
1439 index
.i
[3] = reg
->DstRegisterInd
.Index
;
1441 /* get current value of address register[swizzle] */
1442 swizzle
= tgsi_util_get_src_register_swizzle( ®
->DstRegisterInd
, CHAN_X
);
1444 /* fetch values from the address/indirection register */
1445 fetch_src_file_channel(
1447 reg
->DstRegisterInd
.File
,
1452 /* save indirection offset */
1453 offset
= (int) indir_index
.f
[0];
1456 switch (reg
->DstRegister
.File
) {
1457 case TGSI_FILE_NULL
:
1461 case TGSI_FILE_OUTPUT
:
1462 index
= mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0]
1463 + reg
->DstRegister
.Index
;
1464 dst
= &mach
->Outputs
[offset
+ index
].xyzw
[chan_index
];
1467 case TGSI_FILE_TEMPORARY
:
1468 index
= reg
->DstRegister
.Index
;
1469 assert( index
< TGSI_EXEC_NUM_TEMPS
);
1470 dst
= &mach
->Temps
[offset
+ index
].xyzw
[chan_index
];
1473 case TGSI_FILE_ADDRESS
:
1474 index
= reg
->DstRegister
.Index
;
1475 dst
= &mach
->Addrs
[index
].xyzw
[chan_index
];
1483 if (inst
->InstructionExtNv
.CondFlowEnable
) {
1484 union tgsi_exec_channel
*cc
= &mach
->Temps
[TEMP_CC_I
].xyzw
[TEMP_CC_C
];
1490 /* Only CC0 supported.
1492 assert( inst
->InstructionExtNv
.CondFlowIndex
< 1 );
1494 switch (chan_index
) {
1496 swizzle
= inst
->InstructionExtNv
.CondSwizzleX
;
1499 swizzle
= inst
->InstructionExtNv
.CondSwizzleY
;
1502 swizzle
= inst
->InstructionExtNv
.CondSwizzleZ
;
1505 swizzle
= inst
->InstructionExtNv
.CondSwizzleW
;
1513 case TGSI_SWIZZLE_X
:
1514 shift
= TGSI_EXEC_CC_X_SHIFT
;
1515 mask
= TGSI_EXEC_CC_X_MASK
;
1517 case TGSI_SWIZZLE_Y
:
1518 shift
= TGSI_EXEC_CC_Y_SHIFT
;
1519 mask
= TGSI_EXEC_CC_Y_MASK
;
1521 case TGSI_SWIZZLE_Z
:
1522 shift
= TGSI_EXEC_CC_Z_SHIFT
;
1523 mask
= TGSI_EXEC_CC_Z_MASK
;
1525 case TGSI_SWIZZLE_W
:
1526 shift
= TGSI_EXEC_CC_W_SHIFT
;
1527 mask
= TGSI_EXEC_CC_W_MASK
;
1534 switch (inst
->InstructionExtNv
.CondMask
) {
1536 test
= ~(TGSI_EXEC_CC_GT
<< shift
) & mask
;
1537 for (i
= 0; i
< QUAD_SIZE
; i
++)
1538 if (cc
->u
[i
] & test
)
1539 execmask
&= ~(1 << i
);
1543 test
= ~(TGSI_EXEC_CC_EQ
<< shift
) & mask
;
1544 for (i
= 0; i
< QUAD_SIZE
; i
++)
1545 if (cc
->u
[i
] & test
)
1546 execmask
&= ~(1 << i
);
1550 test
= ~(TGSI_EXEC_CC_LT
<< shift
) & mask
;
1551 for (i
= 0; i
< QUAD_SIZE
; i
++)
1552 if (cc
->u
[i
] & test
)
1553 execmask
&= ~(1 << i
);
1557 test
= ~((TGSI_EXEC_CC_GT
| TGSI_EXEC_CC_EQ
) << shift
) & mask
;
1558 for (i
= 0; i
< QUAD_SIZE
; i
++)
1559 if (cc
->u
[i
] & test
)
1560 execmask
&= ~(1 << i
);
1564 test
= ~((TGSI_EXEC_CC_LT
| TGSI_EXEC_CC_EQ
) << shift
) & mask
;
1565 for (i
= 0; i
< QUAD_SIZE
; i
++)
1566 if (cc
->u
[i
] & test
)
1567 execmask
&= ~(1 << i
);
1571 test
= ~((TGSI_EXEC_CC_GT
| TGSI_EXEC_CC_LT
| TGSI_EXEC_CC_UN
) << shift
) & mask
;
1572 for (i
= 0; i
< QUAD_SIZE
; i
++)
1573 if (cc
->u
[i
] & test
)
1574 execmask
&= ~(1 << i
);
1581 for (i
= 0; i
< QUAD_SIZE
; i
++)
1582 execmask
&= ~(1 << i
);
1591 switch (inst
->Instruction
.Saturate
) {
1593 for (i
= 0; i
< QUAD_SIZE
; i
++)
1594 if (execmask
& (1 << i
))
1595 dst
->i
[i
] = chan
->i
[i
];
1598 case TGSI_SAT_ZERO_ONE
:
1599 for (i
= 0; i
< QUAD_SIZE
; i
++)
1600 if (execmask
& (1 << i
)) {
1601 if (chan
->f
[i
] < 0.0f
)
1603 else if (chan
->f
[i
] > 1.0f
)
1606 dst
->i
[i
] = chan
->i
[i
];
1610 case TGSI_SAT_MINUS_PLUS_ONE
:
1611 for (i
= 0; i
< QUAD_SIZE
; i
++)
1612 if (execmask
& (1 << i
)) {
1613 if (chan
->f
[i
] < -1.0f
)
1615 else if (chan
->f
[i
] > 1.0f
)
1618 dst
->i
[i
] = chan
->i
[i
];
1626 if (inst
->InstructionExtNv
.CondDstUpdate
) {
1627 union tgsi_exec_channel
*cc
= &mach
->Temps
[TEMP_CC_I
].xyzw
[TEMP_CC_C
];
1631 /* Only CC0 supported.
1633 assert( inst
->InstructionExtNv
.CondDstIndex
< 1 );
1635 switch (chan_index
) {
1637 shift
= TGSI_EXEC_CC_X_SHIFT
;
1638 mask
= ~TGSI_EXEC_CC_X_MASK
;
1641 shift
= TGSI_EXEC_CC_Y_SHIFT
;
1642 mask
= ~TGSI_EXEC_CC_Y_MASK
;
1645 shift
= TGSI_EXEC_CC_Z_SHIFT
;
1646 mask
= ~TGSI_EXEC_CC_Z_MASK
;
1649 shift
= TGSI_EXEC_CC_W_SHIFT
;
1650 mask
= ~TGSI_EXEC_CC_W_MASK
;
1657 for (i
= 0; i
< QUAD_SIZE
; i
++)
1658 if (execmask
& (1 << i
)) {
1660 if (dst
->f
[i
] < 0.0f
)
1661 cc
->u
[i
] |= TGSI_EXEC_CC_LT
<< shift
;
1662 else if (dst
->f
[i
] > 0.0f
)
1663 cc
->u
[i
] |= TGSI_EXEC_CC_GT
<< shift
;
1664 else if (dst
->f
[i
] == 0.0f
)
1665 cc
->u
[i
] |= TGSI_EXEC_CC_EQ
<< shift
;
1667 cc
->u
[i
] |= TGSI_EXEC_CC_UN
<< shift
;
1672 #define FETCH(VAL,INDEX,CHAN)\
1673 fetch_source (mach, VAL, &inst->FullSrcRegisters[INDEX], CHAN)
1675 #define STORE(VAL,INDEX,CHAN)\
1676 store_dest (mach, VAL, &inst->FullDstRegisters[INDEX], inst, CHAN )
1680 * Execute ARB-style KIL which is predicated by a src register.
1681 * Kill fragment if any of the four values is less than zero.
1684 exec_kil(struct tgsi_exec_machine
*mach
,
1685 const struct tgsi_full_instruction
*inst
)
1689 uint kilmask
= 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1690 union tgsi_exec_channel r
[1];
1692 /* This mask stores component bits that were already tested. Note that
1693 * we test if the value is less than zero, so 1.0 and 0.0 need not to be
1695 uniquemask
= (1 << TGSI_EXTSWIZZLE_ZERO
) | (1 << TGSI_EXTSWIZZLE_ONE
);
1697 for (chan_index
= 0; chan_index
< 4; chan_index
++)
1702 /* unswizzle channel */
1703 swizzle
= tgsi_util_get_full_src_register_extswizzle (
1704 &inst
->FullSrcRegisters
[0],
1707 /* check if the component has not been already tested */
1708 if (uniquemask
& (1 << swizzle
))
1710 uniquemask
|= 1 << swizzle
;
1712 FETCH(&r
[0], 0, chan_index
);
1713 for (i
= 0; i
< 4; i
++)
1714 if (r
[0].f
[i
] < 0.0f
)
1718 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1722 * Execute NVIDIA-style KIL which is predicated by a condition code.
1723 * Kill fragment if the condition code is TRUE.
1726 exec_kilp(struct tgsi_exec_machine
*mach
,
1727 const struct tgsi_full_instruction
*inst
)
1729 uint kilmask
; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1731 if (inst
->InstructionExtNv
.CondFlowEnable
) {
1737 swizzle
[0] = inst
->InstructionExtNv
.CondSwizzleX
;
1738 swizzle
[1] = inst
->InstructionExtNv
.CondSwizzleY
;
1739 swizzle
[2] = inst
->InstructionExtNv
.CondSwizzleZ
;
1740 swizzle
[3] = inst
->InstructionExtNv
.CondSwizzleW
;
1742 for (chan_index
= 0; chan_index
< 4; chan_index
++)
1746 for (i
= 0; i
< 4; i
++) {
1747 /* TODO: evaluate the condition code */
1754 /* "unconditional" kil */
1755 kilmask
= mach
->ExecMask
;
1757 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1762 * Fetch a four texture samples using STR texture coordinates.
1765 fetch_texel( struct tgsi_sampler
*sampler
,
1766 const union tgsi_exec_channel
*s
,
1767 const union tgsi_exec_channel
*t
,
1768 const union tgsi_exec_channel
*p
,
1769 float lodbias
, /* XXX should be float[4] */
1770 union tgsi_exec_channel
*r
,
1771 union tgsi_exec_channel
*g
,
1772 union tgsi_exec_channel
*b
,
1773 union tgsi_exec_channel
*a
)
1776 float rgba
[NUM_CHANNELS
][QUAD_SIZE
];
1778 sampler
->get_samples(sampler
, s
->f
, t
->f
, p
->f
, lodbias
, rgba
);
1780 for (j
= 0; j
< 4; j
++) {
1781 r
->f
[j
] = rgba
[0][j
];
1782 g
->f
[j
] = rgba
[1][j
];
1783 b
->f
[j
] = rgba
[2][j
];
1784 a
->f
[j
] = rgba
[3][j
];
1790 exec_tex(struct tgsi_exec_machine
*mach
,
1791 const struct tgsi_full_instruction
*inst
,
1795 const uint unit
= inst
->FullSrcRegisters
[1].SrcRegister
.Index
;
1796 union tgsi_exec_channel r
[4];
1800 /* debug_printf("Sampler %u unit %u\n", sampler, unit); */
1802 switch (inst
->InstructionExtTexture
.Texture
) {
1803 case TGSI_TEXTURE_1D
:
1804 case TGSI_TEXTURE_SHADOW1D
:
1806 FETCH(&r
[0], 0, CHAN_X
);
1809 FETCH(&r
[1], 0, CHAN_W
);
1810 micro_div( &r
[0], &r
[0], &r
[1] );
1814 FETCH(&r
[1], 0, CHAN_W
);
1815 lodBias
= r
[2].f
[0];
1820 fetch_texel(mach
->Samplers
[unit
],
1821 &r
[0], &ZeroVec
, &ZeroVec
, lodBias
, /* S, T, P, BIAS */
1822 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1825 case TGSI_TEXTURE_2D
:
1826 case TGSI_TEXTURE_RECT
:
1827 case TGSI_TEXTURE_SHADOW2D
:
1828 case TGSI_TEXTURE_SHADOWRECT
:
1830 FETCH(&r
[0], 0, CHAN_X
);
1831 FETCH(&r
[1], 0, CHAN_Y
);
1832 FETCH(&r
[2], 0, CHAN_Z
);
1835 FETCH(&r
[3], 0, CHAN_W
);
1836 micro_div( &r
[0], &r
[0], &r
[3] );
1837 micro_div( &r
[1], &r
[1], &r
[3] );
1838 micro_div( &r
[2], &r
[2], &r
[3] );
1842 FETCH(&r
[3], 0, CHAN_W
);
1843 lodBias
= r
[3].f
[0];
1848 fetch_texel(mach
->Samplers
[unit
],
1849 &r
[0], &r
[1], &r
[2], lodBias
, /* inputs */
1850 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1853 case TGSI_TEXTURE_3D
:
1854 case TGSI_TEXTURE_CUBE
:
1856 FETCH(&r
[0], 0, CHAN_X
);
1857 FETCH(&r
[1], 0, CHAN_Y
);
1858 FETCH(&r
[2], 0, CHAN_Z
);
1861 FETCH(&r
[3], 0, CHAN_W
);
1862 micro_div( &r
[0], &r
[0], &r
[3] );
1863 micro_div( &r
[1], &r
[1], &r
[3] );
1864 micro_div( &r
[2], &r
[2], &r
[3] );
1868 FETCH(&r
[3], 0, CHAN_W
);
1869 lodBias
= r
[3].f
[0];
1874 fetch_texel(mach
->Samplers
[unit
],
1875 &r
[0], &r
[1], &r
[2], lodBias
,
1876 &r
[0], &r
[1], &r
[2], &r
[3]);
1883 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1884 STORE( &r
[chan_index
], 0, chan_index
);
1890 * Evaluate a constant-valued coefficient at the position of the
1895 struct tgsi_exec_machine
*mach
,
1901 for( i
= 0; i
< QUAD_SIZE
; i
++ ) {
1902 mach
->Inputs
[attrib
].xyzw
[chan
].f
[i
] = mach
->InterpCoefs
[attrib
].a0
[chan
];
1907 * Evaluate a linear-valued coefficient at the position of the
1912 struct tgsi_exec_machine
*mach
,
1916 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1917 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1918 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1919 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1920 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1921 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
;
1922 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = a0
+ dadx
;
1923 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = a0
+ dady
;
1924 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = a0
+ dadx
+ dady
;
1928 * Evaluate a perspective-valued coefficient at the position of the
1932 eval_perspective_coef(
1933 struct tgsi_exec_machine
*mach
,
1937 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1938 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1939 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1940 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1941 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1942 const float *w
= mach
->QuadPos
.xyzw
[3].f
;
1943 /* divide by W here */
1944 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
/ w
[0];
1945 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = (a0
+ dadx
) / w
[1];
1946 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = (a0
+ dady
) / w
[2];
1947 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = (a0
+ dadx
+ dady
) / w
[3];
1951 typedef void (* eval_coef_func
)(
1952 struct tgsi_exec_machine
*mach
,
1958 struct tgsi_exec_machine
*mach
,
1959 const struct tgsi_full_declaration
*decl
)
1961 if( mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
1962 if( decl
->Declaration
.File
== TGSI_FILE_INPUT
) {
1963 unsigned first
, last
, mask
;
1964 eval_coef_func eval
;
1966 first
= decl
->DeclarationRange
.First
;
1967 last
= decl
->DeclarationRange
.Last
;
1968 mask
= decl
->Declaration
.UsageMask
;
1970 switch( decl
->Declaration
.Interpolate
) {
1971 case TGSI_INTERPOLATE_CONSTANT
:
1972 eval
= eval_constant_coef
;
1975 case TGSI_INTERPOLATE_LINEAR
:
1976 eval
= eval_linear_coef
;
1979 case TGSI_INTERPOLATE_PERSPECTIVE
:
1980 eval
= eval_perspective_coef
;
1988 if( mask
== TGSI_WRITEMASK_XYZW
) {
1991 for( i
= first
; i
<= last
; i
++ ) {
1992 for( j
= 0; j
< NUM_CHANNELS
; j
++ ) {
2000 for( j
= 0; j
< NUM_CHANNELS
; j
++ ) {
2001 if( mask
& (1 << j
) ) {
2002 for( i
= first
; i
<= last
; i
++ ) {
2014 struct tgsi_exec_machine
*mach
,
2015 const struct tgsi_full_instruction
*inst
,
2019 union tgsi_exec_channel r
[10];
2023 switch (inst
->Instruction
.Opcode
) {
2024 case TGSI_OPCODE_ARL
:
2025 case TGSI_OPCODE_FLR
:
2026 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2027 FETCH( &r
[0], 0, chan_index
);
2028 micro_flr( &r
[0], &r
[0] );
2029 STORE( &r
[0], 0, chan_index
);
2033 case TGSI_OPCODE_MOV
:
2034 case TGSI_OPCODE_SWZ
:
2035 if (inst
->Flags
& SOA_DEPENDENCY_FLAG
) {
2036 /* Do all fetches into temp regs, then do all stores to avoid
2037 * intermediate/accidental clobbering. This could be done all the
2038 * time for MOV but for other instructions we'll need more temps...
2040 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2041 FETCH( &r
[chan_index
], 0, chan_index
);
2043 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2044 STORE( &r
[chan_index
], 0, chan_index
);
2048 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2049 FETCH( &r
[0], 0, chan_index
);
2050 STORE( &r
[0], 0, chan_index
);
2055 case TGSI_OPCODE_LIT
:
2056 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2057 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2060 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2061 FETCH( &r
[0], 0, CHAN_X
);
2062 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2063 micro_max( &r
[0], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
2064 STORE( &r
[0], 0, CHAN_Y
);
2067 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2068 FETCH( &r
[1], 0, CHAN_Y
);
2069 micro_max( &r
[1], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
2071 FETCH( &r
[2], 0, CHAN_W
);
2072 micro_min( &r
[2], &r
[2], &mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
] );
2073 micro_max( &r
[2], &r
[2], &mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
] );
2074 micro_pow( &r
[1], &r
[1], &r
[2] );
2075 micro_lt( &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &r
[0], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
2076 STORE( &r
[0], 0, CHAN_Z
);
2080 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2081 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2085 case TGSI_OPCODE_RCP
:
2086 /* TGSI_OPCODE_RECIP */
2087 FETCH( &r
[0], 0, CHAN_X
);
2088 micro_div( &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0] );
2089 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2090 STORE( &r
[0], 0, chan_index
);
2094 case TGSI_OPCODE_RSQ
:
2095 /* TGSI_OPCODE_RECIPSQRT */
2096 FETCH( &r
[0], 0, CHAN_X
);
2097 micro_abs( &r
[0], &r
[0] );
2098 micro_sqrt( &r
[0], &r
[0] );
2099 micro_div( &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0] );
2100 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2101 STORE( &r
[0], 0, chan_index
);
2105 case TGSI_OPCODE_EXP
:
2106 FETCH( &r
[0], 0, CHAN_X
);
2107 micro_flr( &r
[1], &r
[0] ); /* r1 = floor(r0) */
2108 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2109 micro_exp2( &r
[2], &r
[1] ); /* r2 = 2 ^ r1 */
2110 STORE( &r
[2], 0, CHAN_X
); /* store r2 */
2112 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2113 micro_sub( &r
[2], &r
[0], &r
[1] ); /* r2 = r0 - r1 */
2114 STORE( &r
[2], 0, CHAN_Y
); /* store r2 */
2116 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2117 micro_exp2( &r
[2], &r
[0] ); /* r2 = 2 ^ r0 */
2118 STORE( &r
[2], 0, CHAN_Z
); /* store r2 */
2120 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2121 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2125 case TGSI_OPCODE_LOG
:
2126 FETCH( &r
[0], 0, CHAN_X
);
2127 micro_abs( &r
[2], &r
[0] ); /* r2 = abs(r0) */
2128 micro_lg2( &r
[1], &r
[2] ); /* r1 = lg2(r2) */
2129 micro_flr( &r
[0], &r
[1] ); /* r0 = floor(r1) */
2130 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2131 STORE( &r
[0], 0, CHAN_X
);
2133 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2134 micro_exp2( &r
[0], &r
[0] ); /* r0 = 2 ^ r0 */
2135 micro_div( &r
[0], &r
[2], &r
[0] ); /* r0 = r2 / r0 */
2136 STORE( &r
[0], 0, CHAN_Y
);
2138 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2139 STORE( &r
[1], 0, CHAN_Z
);
2141 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2142 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2146 case TGSI_OPCODE_MUL
:
2147 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
)
2149 FETCH(&r
[0], 0, chan_index
);
2150 FETCH(&r
[1], 1, chan_index
);
2152 micro_mul( &r
[0], &r
[0], &r
[1] );
2154 STORE(&r
[0], 0, chan_index
);
2158 case TGSI_OPCODE_ADD
:
2159 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2160 FETCH( &r
[0], 0, chan_index
);
2161 FETCH( &r
[1], 1, chan_index
);
2162 micro_add( &r
[0], &r
[0], &r
[1] );
2163 STORE( &r
[0], 0, chan_index
);
2167 case TGSI_OPCODE_DP3
:
2168 /* TGSI_OPCODE_DOT3 */
2169 FETCH( &r
[0], 0, CHAN_X
);
2170 FETCH( &r
[1], 1, CHAN_X
);
2171 micro_mul( &r
[0], &r
[0], &r
[1] );
2173 FETCH( &r
[1], 0, CHAN_Y
);
2174 FETCH( &r
[2], 1, CHAN_Y
);
2175 micro_mul( &r
[1], &r
[1], &r
[2] );
2176 micro_add( &r
[0], &r
[0], &r
[1] );
2178 FETCH( &r
[1], 0, CHAN_Z
);
2179 FETCH( &r
[2], 1, CHAN_Z
);
2180 micro_mul( &r
[1], &r
[1], &r
[2] );
2181 micro_add( &r
[0], &r
[0], &r
[1] );
2183 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2184 STORE( &r
[0], 0, chan_index
);
2188 case TGSI_OPCODE_DP4
:
2189 /* TGSI_OPCODE_DOT4 */
2190 FETCH(&r
[0], 0, CHAN_X
);
2191 FETCH(&r
[1], 1, CHAN_X
);
2193 micro_mul( &r
[0], &r
[0], &r
[1] );
2195 FETCH(&r
[1], 0, CHAN_Y
);
2196 FETCH(&r
[2], 1, CHAN_Y
);
2198 micro_mul( &r
[1], &r
[1], &r
[2] );
2199 micro_add( &r
[0], &r
[0], &r
[1] );
2201 FETCH(&r
[1], 0, CHAN_Z
);
2202 FETCH(&r
[2], 1, CHAN_Z
);
2204 micro_mul( &r
[1], &r
[1], &r
[2] );
2205 micro_add( &r
[0], &r
[0], &r
[1] );
2207 FETCH(&r
[1], 0, CHAN_W
);
2208 FETCH(&r
[2], 1, CHAN_W
);
2210 micro_mul( &r
[1], &r
[1], &r
[2] );
2211 micro_add( &r
[0], &r
[0], &r
[1] );
2213 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2214 STORE( &r
[0], 0, chan_index
);
2218 case TGSI_OPCODE_DST
:
2219 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2220 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2223 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2224 FETCH( &r
[0], 0, CHAN_Y
);
2225 FETCH( &r
[1], 1, CHAN_Y
);
2226 micro_mul( &r
[0], &r
[0], &r
[1] );
2227 STORE( &r
[0], 0, CHAN_Y
);
2230 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2231 FETCH( &r
[0], 0, CHAN_Z
);
2232 STORE( &r
[0], 0, CHAN_Z
);
2235 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2236 FETCH( &r
[0], 1, CHAN_W
);
2237 STORE( &r
[0], 0, CHAN_W
);
2241 case TGSI_OPCODE_MIN
:
2242 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2243 FETCH(&r
[0], 0, chan_index
);
2244 FETCH(&r
[1], 1, chan_index
);
2246 /* XXX use micro_min()?? */
2247 micro_lt( &r
[0], &r
[0], &r
[1], &r
[0], &r
[1] );
2249 STORE(&r
[0], 0, chan_index
);
2253 case TGSI_OPCODE_MAX
:
2254 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2255 FETCH(&r
[0], 0, chan_index
);
2256 FETCH(&r
[1], 1, chan_index
);
2258 /* XXX use micro_max()?? */
2259 micro_lt( &r
[0], &r
[0], &r
[1], &r
[1], &r
[0] );
2261 STORE(&r
[0], 0, chan_index
);
2265 case TGSI_OPCODE_SLT
:
2266 /* TGSI_OPCODE_SETLT */
2267 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2268 FETCH( &r
[0], 0, chan_index
);
2269 FETCH( &r
[1], 1, chan_index
);
2270 micro_lt( &r
[0], &r
[0], &r
[1], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
2271 STORE( &r
[0], 0, chan_index
);
2275 case TGSI_OPCODE_SGE
:
2276 /* TGSI_OPCODE_SETGE */
2277 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2278 FETCH( &r
[0], 0, chan_index
);
2279 FETCH( &r
[1], 1, chan_index
);
2280 micro_le( &r
[0], &r
[1], &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
2281 STORE( &r
[0], 0, chan_index
);
2285 case TGSI_OPCODE_MAD
:
2286 /* TGSI_OPCODE_MADD */
2287 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2288 FETCH( &r
[0], 0, chan_index
);
2289 FETCH( &r
[1], 1, chan_index
);
2290 micro_mul( &r
[0], &r
[0], &r
[1] );
2291 FETCH( &r
[1], 2, chan_index
);
2292 micro_add( &r
[0], &r
[0], &r
[1] );
2293 STORE( &r
[0], 0, chan_index
);
2297 case TGSI_OPCODE_SUB
:
2298 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2299 FETCH(&r
[0], 0, chan_index
);
2300 FETCH(&r
[1], 1, chan_index
);
2302 micro_sub( &r
[0], &r
[0], &r
[1] );
2304 STORE(&r
[0], 0, chan_index
);
2308 case TGSI_OPCODE_LRP
:
2309 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2310 FETCH(&r
[0], 0, chan_index
);
2311 FETCH(&r
[1], 1, chan_index
);
2312 FETCH(&r
[2], 2, chan_index
);
2314 micro_sub( &r
[1], &r
[1], &r
[2] );
2315 micro_mul( &r
[0], &r
[0], &r
[1] );
2316 micro_add( &r
[0], &r
[0], &r
[2] );
2318 STORE(&r
[0], 0, chan_index
);
2322 case TGSI_OPCODE_CND
:
2323 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2324 FETCH(&r
[0], 0, chan_index
);
2325 FETCH(&r
[1], 1, chan_index
);
2326 FETCH(&r
[2], 2, chan_index
);
2327 micro_lt(&r
[0], &mach
->Temps
[TEMP_HALF_I
].xyzw
[TEMP_HALF_C
], &r
[2], &r
[0], &r
[1]);
2328 STORE(&r
[0], 0, chan_index
);
2332 case TGSI_OPCODE_DP2A
:
2333 FETCH( &r
[0], 0, CHAN_X
);
2334 FETCH( &r
[1], 1, CHAN_X
);
2335 micro_mul( &r
[0], &r
[0], &r
[1] );
2337 FETCH( &r
[1], 0, CHAN_Y
);
2338 FETCH( &r
[2], 1, CHAN_Y
);
2339 micro_mul( &r
[1], &r
[1], &r
[2] );
2340 micro_add( &r
[0], &r
[0], &r
[1] );
2342 FETCH( &r
[2], 2, CHAN_X
);
2343 micro_add( &r
[0], &r
[0], &r
[2] );
2345 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2346 STORE( &r
[0], 0, chan_index
);
2350 case TGSI_OPCODE_FRC
:
2351 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2352 FETCH( &r
[0], 0, chan_index
);
2353 micro_frc( &r
[0], &r
[0] );
2354 STORE( &r
[0], 0, chan_index
);
2358 case TGSI_OPCODE_CLAMP
:
2359 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2360 FETCH(&r
[0], 0, chan_index
);
2361 FETCH(&r
[1], 1, chan_index
);
2362 micro_max(&r
[0], &r
[0], &r
[1]);
2363 FETCH(&r
[1], 2, chan_index
);
2364 micro_min(&r
[0], &r
[0], &r
[1]);
2365 STORE(&r
[0], 0, chan_index
);
2369 case TGSI_OPCODE_ROUND
:
2370 case TGSI_OPCODE_ARR
:
2371 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2372 FETCH( &r
[0], 0, chan_index
);
2373 micro_rnd( &r
[0], &r
[0] );
2374 STORE( &r
[0], 0, chan_index
);
2378 case TGSI_OPCODE_EX2
:
2379 FETCH(&r
[0], 0, CHAN_X
);
2382 micro_exp2( &r
[0], &r
[0] );
2384 micro_pow( &r
[0], &mach
->Temps
[TEMP_2_I
].xyzw
[TEMP_2_C
], &r
[0] );
2387 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2388 STORE( &r
[0], 0, chan_index
);
2392 case TGSI_OPCODE_LG2
:
2393 FETCH( &r
[0], 0, CHAN_X
);
2394 micro_lg2( &r
[0], &r
[0] );
2395 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2396 STORE( &r
[0], 0, chan_index
);
2400 case TGSI_OPCODE_POW
:
2401 FETCH(&r
[0], 0, CHAN_X
);
2402 FETCH(&r
[1], 1, CHAN_X
);
2404 micro_pow( &r
[0], &r
[0], &r
[1] );
2406 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2407 STORE( &r
[0], 0, chan_index
);
2411 case TGSI_OPCODE_XPD
:
2412 FETCH(&r
[0], 0, CHAN_Y
);
2413 FETCH(&r
[1], 1, CHAN_Z
);
2415 micro_mul( &r
[2], &r
[0], &r
[1] );
2417 FETCH(&r
[3], 0, CHAN_Z
);
2418 FETCH(&r
[4], 1, CHAN_Y
);
2420 micro_mul( &r
[5], &r
[3], &r
[4] );
2421 micro_sub( &r
[2], &r
[2], &r
[5] );
2423 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2424 STORE( &r
[2], 0, CHAN_X
);
2427 FETCH(&r
[2], 1, CHAN_X
);
2429 micro_mul( &r
[3], &r
[3], &r
[2] );
2431 FETCH(&r
[5], 0, CHAN_X
);
2433 micro_mul( &r
[1], &r
[1], &r
[5] );
2434 micro_sub( &r
[3], &r
[3], &r
[1] );
2436 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2437 STORE( &r
[3], 0, CHAN_Y
);
2440 micro_mul( &r
[5], &r
[5], &r
[4] );
2441 micro_mul( &r
[0], &r
[0], &r
[2] );
2442 micro_sub( &r
[5], &r
[5], &r
[0] );
2444 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2445 STORE( &r
[5], 0, CHAN_Z
);
2448 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2449 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2453 case TGSI_OPCODE_ABS
:
2454 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2455 FETCH(&r
[0], 0, chan_index
);
2457 micro_abs( &r
[0], &r
[0] );
2459 STORE(&r
[0], 0, chan_index
);
2463 case TGSI_OPCODE_RCC
:
2464 FETCH(&r
[0], 0, CHAN_X
);
2465 micro_div(&r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0]);
2466 micro_float_clamp(&r
[0], &r
[0]);
2467 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2468 STORE(&r
[0], 0, chan_index
);
2472 case TGSI_OPCODE_DPH
:
2473 FETCH(&r
[0], 0, CHAN_X
);
2474 FETCH(&r
[1], 1, CHAN_X
);
2476 micro_mul( &r
[0], &r
[0], &r
[1] );
2478 FETCH(&r
[1], 0, CHAN_Y
);
2479 FETCH(&r
[2], 1, CHAN_Y
);
2481 micro_mul( &r
[1], &r
[1], &r
[2] );
2482 micro_add( &r
[0], &r
[0], &r
[1] );
2484 FETCH(&r
[1], 0, CHAN_Z
);
2485 FETCH(&r
[2], 1, CHAN_Z
);
2487 micro_mul( &r
[1], &r
[1], &r
[2] );
2488 micro_add( &r
[0], &r
[0], &r
[1] );
2490 FETCH(&r
[1], 1, CHAN_W
);
2492 micro_add( &r
[0], &r
[0], &r
[1] );
2494 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2495 STORE( &r
[0], 0, chan_index
);
2499 case TGSI_OPCODE_COS
:
2500 FETCH(&r
[0], 0, CHAN_X
);
2502 micro_cos( &r
[0], &r
[0] );
2504 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2505 STORE( &r
[0], 0, chan_index
);
2509 case TGSI_OPCODE_DDX
:
2510 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2511 FETCH( &r
[0], 0, chan_index
);
2512 micro_ddx( &r
[0], &r
[0] );
2513 STORE( &r
[0], 0, chan_index
);
2517 case TGSI_OPCODE_DDY
:
2518 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2519 FETCH( &r
[0], 0, chan_index
);
2520 micro_ddy( &r
[0], &r
[0] );
2521 STORE( &r
[0], 0, chan_index
);
2525 case TGSI_OPCODE_KILP
:
2526 exec_kilp (mach
, inst
);
2529 case TGSI_OPCODE_KIL
:
2530 exec_kil (mach
, inst
);
2533 case TGSI_OPCODE_PK2H
:
2537 case TGSI_OPCODE_PK2US
:
2541 case TGSI_OPCODE_PK4B
:
2545 case TGSI_OPCODE_PK4UB
:
2549 case TGSI_OPCODE_RFL
:
2550 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2551 IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2552 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2553 /* r0 = dp3(src0, src0) */
2554 FETCH(&r
[2], 0, CHAN_X
);
2555 micro_mul(&r
[0], &r
[2], &r
[2]);
2556 FETCH(&r
[4], 0, CHAN_Y
);
2557 micro_mul(&r
[8], &r
[4], &r
[4]);
2558 micro_add(&r
[0], &r
[0], &r
[8]);
2559 FETCH(&r
[6], 0, CHAN_Z
);
2560 micro_mul(&r
[8], &r
[6], &r
[6]);
2561 micro_add(&r
[0], &r
[0], &r
[8]);
2563 /* r1 = dp3(src0, src1) */
2564 FETCH(&r
[3], 1, CHAN_X
);
2565 micro_mul(&r
[1], &r
[2], &r
[3]);
2566 FETCH(&r
[5], 1, CHAN_Y
);
2567 micro_mul(&r
[8], &r
[4], &r
[5]);
2568 micro_add(&r
[1], &r
[1], &r
[8]);
2569 FETCH(&r
[7], 1, CHAN_Z
);
2570 micro_mul(&r
[8], &r
[6], &r
[7]);
2571 micro_add(&r
[1], &r
[1], &r
[8]);
2573 /* r1 = 2 * r1 / r0 */
2574 micro_add(&r
[1], &r
[1], &r
[1]);
2575 micro_div(&r
[1], &r
[1], &r
[0]);
2577 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2578 micro_mul(&r
[2], &r
[2], &r
[1]);
2579 micro_sub(&r
[2], &r
[2], &r
[3]);
2580 STORE(&r
[2], 0, CHAN_X
);
2582 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2583 micro_mul(&r
[4], &r
[4], &r
[1]);
2584 micro_sub(&r
[4], &r
[4], &r
[5]);
2585 STORE(&r
[4], 0, CHAN_Y
);
2587 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2588 micro_mul(&r
[6], &r
[6], &r
[1]);
2589 micro_sub(&r
[6], &r
[6], &r
[7]);
2590 STORE(&r
[6], 0, CHAN_Z
);
2593 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2594 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2598 case TGSI_OPCODE_SEQ
:
2599 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2600 FETCH( &r
[0], 0, chan_index
);
2601 FETCH( &r
[1], 1, chan_index
);
2602 micro_eq( &r
[0], &r
[0], &r
[1],
2603 &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
],
2604 &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
2605 STORE( &r
[0], 0, chan_index
);
2609 case TGSI_OPCODE_SFL
:
2610 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2611 STORE(&mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, chan_index
);
2615 case TGSI_OPCODE_SGT
:
2616 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2617 FETCH( &r
[0], 0, chan_index
);
2618 FETCH( &r
[1], 1, chan_index
);
2619 micro_le( &r
[0], &r
[0], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
] );
2620 STORE( &r
[0], 0, chan_index
);
2624 case TGSI_OPCODE_SIN
:
2625 FETCH( &r
[0], 0, CHAN_X
);
2626 micro_sin( &r
[0], &r
[0] );
2627 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2628 STORE( &r
[0], 0, chan_index
);
2632 case TGSI_OPCODE_SLE
:
2633 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2634 FETCH( &r
[0], 0, chan_index
);
2635 FETCH( &r
[1], 1, chan_index
);
2636 micro_le( &r
[0], &r
[0], &r
[1], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
2637 STORE( &r
[0], 0, chan_index
);
2641 case TGSI_OPCODE_SNE
:
2642 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2643 FETCH( &r
[0], 0, chan_index
);
2644 FETCH( &r
[1], 1, chan_index
);
2645 micro_eq( &r
[0], &r
[0], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
] );
2646 STORE( &r
[0], 0, chan_index
);
2650 case TGSI_OPCODE_STR
:
2651 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2652 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, chan_index
);
2656 case TGSI_OPCODE_TEX
:
2657 /* simple texture lookup */
2658 /* src[0] = texcoord */
2659 /* src[1] = sampler unit */
2660 exec_tex(mach
, inst
, FALSE
, FALSE
);
2663 case TGSI_OPCODE_TXB
:
2664 /* Texture lookup with lod bias */
2665 /* src[0] = texcoord (src[0].w = LOD bias) */
2666 /* src[1] = sampler unit */
2667 exec_tex(mach
, inst
, TRUE
, FALSE
);
2670 case TGSI_OPCODE_TXD
:
2671 /* Texture lookup with explict partial derivatives */
2672 /* src[0] = texcoord */
2673 /* src[1] = d[strq]/dx */
2674 /* src[2] = d[strq]/dy */
2675 /* src[3] = sampler unit */
2679 case TGSI_OPCODE_TXL
:
2680 /* Texture lookup with explit LOD */
2681 /* src[0] = texcoord (src[0].w = LOD) */
2682 /* src[1] = sampler unit */
2683 exec_tex(mach
, inst
, TRUE
, FALSE
);
2686 case TGSI_OPCODE_TXP
:
2687 /* Texture lookup with projection */
2688 /* src[0] = texcoord (src[0].w = projection) */
2689 /* src[1] = sampler unit */
2690 exec_tex(mach
, inst
, FALSE
, TRUE
);
2693 case TGSI_OPCODE_UP2H
:
2697 case TGSI_OPCODE_UP2US
:
2701 case TGSI_OPCODE_UP4B
:
2705 case TGSI_OPCODE_UP4UB
:
2709 case TGSI_OPCODE_X2D
:
2710 FETCH(&r
[0], 1, CHAN_X
);
2711 FETCH(&r
[1], 1, CHAN_Y
);
2712 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2713 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2714 FETCH(&r
[2], 2, CHAN_X
);
2715 micro_mul(&r
[2], &r
[2], &r
[0]);
2716 FETCH(&r
[3], 2, CHAN_Y
);
2717 micro_mul(&r
[3], &r
[3], &r
[1]);
2718 micro_add(&r
[2], &r
[2], &r
[3]);
2719 FETCH(&r
[3], 0, CHAN_X
);
2720 micro_add(&r
[2], &r
[2], &r
[3]);
2721 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2722 STORE(&r
[2], 0, CHAN_X
);
2724 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2725 STORE(&r
[2], 0, CHAN_Z
);
2728 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2729 IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2730 FETCH(&r
[2], 2, CHAN_Z
);
2731 micro_mul(&r
[2], &r
[2], &r
[0]);
2732 FETCH(&r
[3], 2, CHAN_W
);
2733 micro_mul(&r
[3], &r
[3], &r
[1]);
2734 micro_add(&r
[2], &r
[2], &r
[3]);
2735 FETCH(&r
[3], 0, CHAN_Y
);
2736 micro_add(&r
[2], &r
[2], &r
[3]);
2737 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2738 STORE(&r
[2], 0, CHAN_Y
);
2740 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2741 STORE(&r
[2], 0, CHAN_W
);
2746 case TGSI_OPCODE_ARA
:
2750 case TGSI_OPCODE_BRA
:
2754 case TGSI_OPCODE_CAL
:
2755 /* skip the call if no execution channels are enabled */
2756 if (mach
->ExecMask
) {
2759 /* First, record the depths of the execution stacks.
2760 * This is important for deeply nested/looped return statements.
2761 * We have to unwind the stacks by the correct amount. For a
2762 * real code generator, we could determine the number of entries
2763 * to pop off each stack with simple static analysis and avoid
2764 * implementing this data structure at run time.
2766 mach
->CallStack
[mach
->CallStackTop
].CondStackTop
= mach
->CondStackTop
;
2767 mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
= mach
->LoopStackTop
;
2768 mach
->CallStack
[mach
->CallStackTop
].ContStackTop
= mach
->ContStackTop
;
2769 /* note that PC was already incremented above */
2770 mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
= *pc
;
2772 mach
->CallStackTop
++;
2774 /* Second, push the Cond, Loop, Cont, Func stacks */
2775 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
2776 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
2777 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2778 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
2779 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2780 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
2781 assert(mach
->FuncStackTop
< TGSI_EXEC_MAX_CALL_NESTING
);
2782 mach
->FuncStack
[mach
->FuncStackTop
++] = mach
->FuncMask
;
2784 /* Finally, jump to the subroutine */
2785 *pc
= inst
->InstructionExtLabel
.Label
;
2789 case TGSI_OPCODE_RET
:
2790 mach
->FuncMask
&= ~mach
->ExecMask
;
2791 UPDATE_EXEC_MASK(mach
);
2793 if (mach
->FuncMask
== 0x0) {
2794 /* really return now (otherwise, keep executing */
2796 if (mach
->CallStackTop
== 0) {
2797 /* returning from main() */
2802 assert(mach
->CallStackTop
> 0);
2803 mach
->CallStackTop
--;
2805 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
2806 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
2808 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
2809 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
2811 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
2812 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
2814 assert(mach
->FuncStackTop
> 0);
2815 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
2817 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
2819 UPDATE_EXEC_MASK(mach
);
2823 case TGSI_OPCODE_SSG
:
2824 /* TGSI_OPCODE_SGN */
2825 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2826 FETCH( &r
[0], 0, chan_index
);
2827 micro_sgn( &r
[0], &r
[0] );
2828 STORE( &r
[0], 0, chan_index
);
2832 case TGSI_OPCODE_CMP
:
2833 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2834 FETCH(&r
[0], 0, chan_index
);
2835 FETCH(&r
[1], 1, chan_index
);
2836 FETCH(&r
[2], 2, chan_index
);
2838 micro_lt( &r
[0], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &r
[1], &r
[2] );
2840 STORE(&r
[0], 0, chan_index
);
2844 case TGSI_OPCODE_SCS
:
2845 if( IS_CHANNEL_ENABLED( *inst
, CHAN_X
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) ) {
2846 FETCH( &r
[0], 0, CHAN_X
);
2847 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2848 micro_cos(&r
[1], &r
[0]);
2849 STORE(&r
[1], 0, CHAN_X
);
2851 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2852 micro_sin(&r
[1], &r
[0]);
2853 STORE(&r
[1], 0, CHAN_Y
);
2856 if( IS_CHANNEL_ENABLED( *inst
, CHAN_Z
) ) {
2857 STORE( &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, CHAN_Z
);
2859 if( IS_CHANNEL_ENABLED( *inst
, CHAN_W
) ) {
2860 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2864 case TGSI_OPCODE_NRM
:
2865 /* 3-component vector normalize */
2866 if(IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2867 IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2868 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2869 /* r3 = sqrt(dp3(src0, src0)) */
2870 FETCH(&r
[0], 0, CHAN_X
);
2871 micro_mul(&r
[3], &r
[0], &r
[0]);
2872 FETCH(&r
[1], 0, CHAN_Y
);
2873 micro_mul(&r
[4], &r
[1], &r
[1]);
2874 micro_add(&r
[3], &r
[3], &r
[4]);
2875 FETCH(&r
[2], 0, CHAN_Z
);
2876 micro_mul(&r
[4], &r
[2], &r
[2]);
2877 micro_add(&r
[3], &r
[3], &r
[4]);
2878 micro_sqrt(&r
[3], &r
[3]);
2880 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2881 micro_div(&r
[0], &r
[0], &r
[3]);
2882 STORE(&r
[0], 0, CHAN_X
);
2884 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2885 micro_div(&r
[1], &r
[1], &r
[3]);
2886 STORE(&r
[1], 0, CHAN_Y
);
2888 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2889 micro_div(&r
[2], &r
[2], &r
[3]);
2890 STORE(&r
[2], 0, CHAN_Z
);
2893 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2894 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2898 case TGSI_OPCODE_NRM4
:
2899 /* 4-component vector normalize */
2901 union tgsi_exec_channel tmp
, dot
;
2903 /* tmp = dp4(src0, src0): */
2904 FETCH( &r
[0], 0, CHAN_X
);
2905 micro_mul( &tmp
, &r
[0], &r
[0] );
2907 FETCH( &r
[1], 0, CHAN_Y
);
2908 micro_mul( &dot
, &r
[1], &r
[1] );
2909 micro_add( &tmp
, &tmp
, &dot
);
2911 FETCH( &r
[2], 0, CHAN_Z
);
2912 micro_mul( &dot
, &r
[2], &r
[2] );
2913 micro_add( &tmp
, &tmp
, &dot
);
2915 FETCH( &r
[3], 0, CHAN_W
);
2916 micro_mul( &dot
, &r
[3], &r
[3] );
2917 micro_add( &tmp
, &tmp
, &dot
);
2919 /* tmp = 1 / sqrt(tmp) */
2920 micro_sqrt( &tmp
, &tmp
);
2921 micro_div( &tmp
, &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &tmp
);
2923 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2924 /* chan = chan * tmp */
2925 micro_mul( &r
[chan_index
], &tmp
, &r
[chan_index
] );
2926 STORE( &r
[chan_index
], 0, chan_index
);
2931 case TGSI_OPCODE_DIV
:
2935 case TGSI_OPCODE_DP2
:
2936 FETCH( &r
[0], 0, CHAN_X
);
2937 FETCH( &r
[1], 1, CHAN_X
);
2938 micro_mul( &r
[0], &r
[0], &r
[1] );
2940 FETCH( &r
[1], 0, CHAN_Y
);
2941 FETCH( &r
[2], 1, CHAN_Y
);
2942 micro_mul( &r
[1], &r
[1], &r
[2] );
2943 micro_add( &r
[0], &r
[0], &r
[1] );
2945 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2946 STORE( &r
[0], 0, chan_index
);
2950 case TGSI_OPCODE_IF
:
2952 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
2953 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
2954 FETCH( &r
[0], 0, CHAN_X
);
2955 /* update CondMask */
2957 mach
->CondMask
&= ~0x1;
2960 mach
->CondMask
&= ~0x2;
2963 mach
->CondMask
&= ~0x4;
2966 mach
->CondMask
&= ~0x8;
2968 UPDATE_EXEC_MASK(mach
);
2969 /* Todo: If CondMask==0, jump to ELSE */
2972 case TGSI_OPCODE_ELSE
:
2973 /* invert CondMask wrt previous mask */
2976 assert(mach
->CondStackTop
> 0);
2977 prevMask
= mach
->CondStack
[mach
->CondStackTop
- 1];
2978 mach
->CondMask
= ~mach
->CondMask
& prevMask
;
2979 UPDATE_EXEC_MASK(mach
);
2980 /* Todo: If CondMask==0, jump to ENDIF */
2984 case TGSI_OPCODE_ENDIF
:
2986 assert(mach
->CondStackTop
> 0);
2987 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
2988 UPDATE_EXEC_MASK(mach
);
2991 case TGSI_OPCODE_END
:
2992 /* halt execution */
2996 case TGSI_OPCODE_REP
:
3000 case TGSI_OPCODE_ENDREP
:
3004 case TGSI_OPCODE_PUSHA
:
3008 case TGSI_OPCODE_POPA
:
3012 case TGSI_OPCODE_CEIL
:
3013 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3014 FETCH( &r
[0], 0, chan_index
);
3015 micro_ceil( &r
[0], &r
[0] );
3016 STORE( &r
[0], 0, chan_index
);
3020 case TGSI_OPCODE_I2F
:
3021 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3022 FETCH( &r
[0], 0, chan_index
);
3023 micro_i2f( &r
[0], &r
[0] );
3024 STORE( &r
[0], 0, chan_index
);
3028 case TGSI_OPCODE_NOT
:
3029 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3030 FETCH( &r
[0], 0, chan_index
);
3031 micro_not( &r
[0], &r
[0] );
3032 STORE( &r
[0], 0, chan_index
);
3036 case TGSI_OPCODE_TRUNC
:
3037 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3038 FETCH( &r
[0], 0, chan_index
);
3039 micro_trunc( &r
[0], &r
[0] );
3040 STORE( &r
[0], 0, chan_index
);
3044 case TGSI_OPCODE_SHL
:
3045 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3046 FETCH( &r
[0], 0, chan_index
);
3047 FETCH( &r
[1], 1, chan_index
);
3048 micro_shl( &r
[0], &r
[0], &r
[1] );
3049 STORE( &r
[0], 0, chan_index
);
3053 case TGSI_OPCODE_SHR
:
3054 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3055 FETCH( &r
[0], 0, chan_index
);
3056 FETCH( &r
[1], 1, chan_index
);
3057 micro_ishr( &r
[0], &r
[0], &r
[1] );
3058 STORE( &r
[0], 0, chan_index
);
3062 case TGSI_OPCODE_AND
:
3063 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3064 FETCH( &r
[0], 0, chan_index
);
3065 FETCH( &r
[1], 1, chan_index
);
3066 micro_and( &r
[0], &r
[0], &r
[1] );
3067 STORE( &r
[0], 0, chan_index
);
3071 case TGSI_OPCODE_OR
:
3072 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3073 FETCH( &r
[0], 0, chan_index
);
3074 FETCH( &r
[1], 1, chan_index
);
3075 micro_or( &r
[0], &r
[0], &r
[1] );
3076 STORE( &r
[0], 0, chan_index
);
3080 case TGSI_OPCODE_MOD
:
3084 case TGSI_OPCODE_XOR
:
3085 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3086 FETCH( &r
[0], 0, chan_index
);
3087 FETCH( &r
[1], 1, chan_index
);
3088 micro_xor( &r
[0], &r
[0], &r
[1] );
3089 STORE( &r
[0], 0, chan_index
);
3093 case TGSI_OPCODE_SAD
:
3097 case TGSI_OPCODE_TXF
:
3101 case TGSI_OPCODE_TXQ
:
3105 case TGSI_OPCODE_EMIT
:
3106 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] += 16;
3107 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]]++;
3110 case TGSI_OPCODE_ENDPRIM
:
3111 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]++;
3112 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]] = 0;
3115 case TGSI_OPCODE_BGNFOR
:
3116 assert(mach
->LoopCounterStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3117 for (chan_index
= 0; chan_index
< 3; chan_index
++) {
3118 FETCH( &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[chan_index
], 0, chan_index
);
3120 STORE( &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[CHAN_Y
], 0, CHAN_X
);
3121 ++mach
->LoopCounterStackTop
;
3122 /* fall-through (for now) */
3123 case TGSI_OPCODE_BGNLOOP
:
3124 /* push LoopMask and ContMasks */
3125 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3126 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
3127 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3128 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
3129 assert(mach
->LoopLabelStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3130 mach
->LoopLabelStack
[mach
->LoopLabelStackTop
++] = *pc
- 1;
3133 case TGSI_OPCODE_ENDFOR
:
3134 assert(mach
->LoopCounterStackTop
> 0);
3135 micro_sub( &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
],
3136 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
],
3137 &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
] );
3138 /* update LoopMask */
3139 if( mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
].f
[0] <= 0) {
3140 mach
->LoopMask
&= ~0x1;
3142 if( mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
].f
[1] <= 0 ) {
3143 mach
->LoopMask
&= ~0x2;
3145 if( mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
].f
[2] <= 0 ) {
3146 mach
->LoopMask
&= ~0x4;
3148 if( mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
].f
[3] <= 0 ) {
3149 mach
->LoopMask
&= ~0x8;
3151 micro_add( &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
],
3152 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
],
3153 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Z
]);
3154 assert(mach
->LoopLabelStackTop
> 0);
3155 inst
= mach
->Instructions
+ mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1];
3156 STORE( &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[CHAN_Y
], 0, CHAN_X
);
3157 /* Restore ContMask, but don't pop */
3158 assert(mach
->ContStackTop
> 0);
3159 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3160 UPDATE_EXEC_MASK(mach
);
3161 if (mach
->ExecMask
) {
3162 /* repeat loop: jump to instruction just past BGNLOOP */
3163 assert(mach
->LoopLabelStackTop
> 0);
3164 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3167 /* exit loop: pop LoopMask */
3168 assert(mach
->LoopStackTop
> 0);
3169 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3171 assert(mach
->ContStackTop
> 0);
3172 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3173 assert(mach
->LoopLabelStackTop
> 0);
3174 --mach
->LoopLabelStackTop
;
3175 assert(mach
->LoopCounterStackTop
> 0);
3176 --mach
->LoopCounterStackTop
;
3178 UPDATE_EXEC_MASK(mach
);
3181 case TGSI_OPCODE_ENDLOOP
:
3182 /* Restore ContMask, but don't pop */
3183 assert(mach
->ContStackTop
> 0);
3184 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3185 UPDATE_EXEC_MASK(mach
);
3186 if (mach
->ExecMask
) {
3187 /* repeat loop: jump to instruction just past BGNLOOP */
3188 assert(mach
->LoopLabelStackTop
> 0);
3189 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3192 /* exit loop: pop LoopMask */
3193 assert(mach
->LoopStackTop
> 0);
3194 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3196 assert(mach
->ContStackTop
> 0);
3197 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3198 assert(mach
->LoopLabelStackTop
> 0);
3199 --mach
->LoopLabelStackTop
;
3201 UPDATE_EXEC_MASK(mach
);
3204 case TGSI_OPCODE_BRK
:
3205 /* turn off loop channels for each enabled exec channel */
3206 mach
->LoopMask
&= ~mach
->ExecMask
;
3207 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3208 UPDATE_EXEC_MASK(mach
);
3211 case TGSI_OPCODE_CONT
:
3212 /* turn off cont channels for each enabled exec channel */
3213 mach
->ContMask
&= ~mach
->ExecMask
;
3214 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3215 UPDATE_EXEC_MASK(mach
);
3218 case TGSI_OPCODE_BGNSUB
:
3222 case TGSI_OPCODE_ENDSUB
:
3226 case TGSI_OPCODE_NOISE1
:
3230 case TGSI_OPCODE_NOISE2
:
3234 case TGSI_OPCODE_NOISE3
:
3238 case TGSI_OPCODE_NOISE4
:
3242 case TGSI_OPCODE_NOP
:
3252 * Run TGSI interpreter.
3253 * \return bitmask of "alive" quad components
3256 tgsi_exec_machine_run( struct tgsi_exec_machine
*mach
)
3261 mach
->CondMask
= 0xf;
3262 mach
->LoopMask
= 0xf;
3263 mach
->ContMask
= 0xf;
3264 mach
->FuncMask
= 0xf;
3265 mach
->ExecMask
= 0xf;
3267 assert(mach
->CondStackTop
== 0);
3268 assert(mach
->LoopStackTop
== 0);
3269 assert(mach
->ContStackTop
== 0);
3270 assert(mach
->CallStackTop
== 0);
3272 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] = 0;
3273 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] = 0;
3275 if( mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
3276 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0] = 0;
3277 mach
->Primitives
[0] = 0;
3280 for (i
= 0; i
< QUAD_SIZE
; i
++) {
3281 mach
->Temps
[TEMP_CC_I
].xyzw
[TEMP_CC_C
].u
[i
] =
3282 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_X_SHIFT
) |
3283 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Y_SHIFT
) |
3284 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Z_SHIFT
) |
3285 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_W_SHIFT
);
3288 /* execute declarations (interpolants) */
3289 for (i
= 0; i
< mach
->NumDeclarations
; i
++) {
3290 exec_declaration( mach
, mach
->Declarations
+i
);
3293 /* execute instructions, until pc is set to -1 */
3295 assert(pc
< (int) mach
->NumInstructions
);
3296 exec_instruction( mach
, mach
->Instructions
+ pc
, &pc
);
3300 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
3301 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
3303 * Scale back depth component.
3305 for (i
= 0; i
< 4; i
++)
3306 mach
->Outputs
[0].xyzw
[2].f
[i
] *= ctx
->DrawBuffer
->_DepthMaxF
;
3310 return ~mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];