1 /**************************************************************************
3 * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * Copyright 2009-2010 VMware, Inc. All rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
30 * TGSI interpreter/executor.
32 * Flow control information:
34 * Since we operate on 'quads' (4 pixels or 4 vertices in parallel)
35 * flow control statements (IF/ELSE/ENDIF, LOOP/ENDLOOP) require special
36 * care since a condition may be true for some quad components but false
37 * for other components.
39 * We basically execute all statements (even if they're in the part of
40 * an IF/ELSE clause that's "not taken") and use a special mask to
41 * control writing to destination registers. This is the ExecMask.
44 * The ExecMask is computed from three other masks (CondMask, LoopMask and
45 * ContMask) which are controlled by the flow control instructions (namely:
46 * (IF/ELSE/ENDIF, LOOP/ENDLOOP and CONT).
54 #include "pipe/p_compiler.h"
55 #include "pipe/p_state.h"
56 #include "pipe/p_shader_tokens.h"
57 #include "tgsi/tgsi_dump.h"
58 #include "tgsi/tgsi_parse.h"
59 #include "tgsi/tgsi_util.h"
60 #include "tgsi_exec.h"
61 #include "util/u_memory.h"
62 #include "util/u_math.h"
68 micro_arl(union tgsi_exec_channel
*dst
,
69 const union tgsi_exec_channel
*src
)
71 dst
->i
[0] = (int)floorf(src
->f
[0]);
72 dst
->i
[1] = (int)floorf(src
->f
[1]);
73 dst
->i
[2] = (int)floorf(src
->f
[2]);
74 dst
->i
[3] = (int)floorf(src
->f
[3]);
78 micro_arr(union tgsi_exec_channel
*dst
,
79 const union tgsi_exec_channel
*src
)
81 dst
->i
[0] = (int)floorf(src
->f
[0] + 0.5f
);
82 dst
->i
[1] = (int)floorf(src
->f
[1] + 0.5f
);
83 dst
->i
[2] = (int)floorf(src
->f
[2] + 0.5f
);
84 dst
->i
[3] = (int)floorf(src
->f
[3] + 0.5f
);
88 micro_iabs(union tgsi_exec_channel
*dst
,
89 const union tgsi_exec_channel
*src
)
91 dst
->i
[0] = src
->i
[0] >= 0 ? src
->i
[0] : -src
->i
[0];
92 dst
->i
[1] = src
->i
[1] >= 0 ? src
->i
[1] : -src
->i
[1];
93 dst
->i
[2] = src
->i
[2] >= 0 ? src
->i
[2] : -src
->i
[2];
94 dst
->i
[3] = src
->i
[3] >= 0 ? src
->i
[3] : -src
->i
[3];
98 micro_ineg(union tgsi_exec_channel
*dst
,
99 const union tgsi_exec_channel
*src
)
101 dst
->i
[0] = -src
->i
[0];
102 dst
->i
[1] = -src
->i
[1];
103 dst
->i
[2] = -src
->i
[2];
104 dst
->i
[3] = -src
->i
[3];
108 micro_mov(union tgsi_exec_channel
*dst
,
109 const union tgsi_exec_channel
*src
)
111 dst
->u
[0] = src
->u
[0];
112 dst
->u
[1] = src
->u
[1];
113 dst
->u
[2] = src
->u
[2];
114 dst
->u
[3] = src
->u
[3];
117 #define TILE_TOP_LEFT 0
118 #define TILE_TOP_RIGHT 1
119 #define TILE_BOTTOM_LEFT 2
120 #define TILE_BOTTOM_RIGHT 3
127 enum tgsi_exec_datatype
{
128 TGSI_EXEC_DATA_FLOAT
,
134 * Shorthand locations of various utility registers (_I = Index, _C = Channel)
136 #define TEMP_0_I TGSI_EXEC_TEMP_00000000_I
137 #define TEMP_0_C TGSI_EXEC_TEMP_00000000_C
138 #define TEMP_7F_I TGSI_EXEC_TEMP_7FFFFFFF_I
139 #define TEMP_7F_C TGSI_EXEC_TEMP_7FFFFFFF_C
140 #define TEMP_80_I TGSI_EXEC_TEMP_80000000_I
141 #define TEMP_80_C TGSI_EXEC_TEMP_80000000_C
142 #define TEMP_FF_I TGSI_EXEC_TEMP_FFFFFFFF_I
143 #define TEMP_FF_C TGSI_EXEC_TEMP_FFFFFFFF_C
144 #define TEMP_1_I TGSI_EXEC_TEMP_ONE_I
145 #define TEMP_1_C TGSI_EXEC_TEMP_ONE_C
146 #define TEMP_2_I TGSI_EXEC_TEMP_TWO_I
147 #define TEMP_2_C TGSI_EXEC_TEMP_TWO_C
148 #define TEMP_128_I TGSI_EXEC_TEMP_128_I
149 #define TEMP_128_C TGSI_EXEC_TEMP_128_C
150 #define TEMP_M128_I TGSI_EXEC_TEMP_MINUS_128_I
151 #define TEMP_M128_C TGSI_EXEC_TEMP_MINUS_128_C
152 #define TEMP_KILMASK_I TGSI_EXEC_TEMP_KILMASK_I
153 #define TEMP_KILMASK_C TGSI_EXEC_TEMP_KILMASK_C
154 #define TEMP_OUTPUT_I TGSI_EXEC_TEMP_OUTPUT_I
155 #define TEMP_OUTPUT_C TGSI_EXEC_TEMP_OUTPUT_C
156 #define TEMP_PRIMITIVE_I TGSI_EXEC_TEMP_PRIMITIVE_I
157 #define TEMP_PRIMITIVE_C TGSI_EXEC_TEMP_PRIMITIVE_C
158 #define TEMP_CC_I TGSI_EXEC_TEMP_CC_I
159 #define TEMP_CC_C TGSI_EXEC_TEMP_CC_C
160 #define TEMP_3_I TGSI_EXEC_TEMP_THREE_I
161 #define TEMP_3_C TGSI_EXEC_TEMP_THREE_C
162 #define TEMP_HALF_I TGSI_EXEC_TEMP_HALF_I
163 #define TEMP_HALF_C TGSI_EXEC_TEMP_HALF_C
164 #define TEMP_R0 TGSI_EXEC_TEMP_R0
165 #define TEMP_P0 TGSI_EXEC_TEMP_P0
167 #define IS_CHANNEL_ENABLED(INST, CHAN)\
168 ((INST).Dst[0].Register.WriteMask & (1 << (CHAN)))
170 #define IS_CHANNEL_ENABLED2(INST, CHAN)\
171 ((INST).Dst[1].Register.WriteMask & (1 << (CHAN)))
173 #define FOR_EACH_ENABLED_CHANNEL(INST, CHAN)\
174 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)\
175 if (IS_CHANNEL_ENABLED( INST, CHAN ))
177 #define FOR_EACH_ENABLED_CHANNEL2(INST, CHAN)\
178 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)\
179 if (IS_CHANNEL_ENABLED2( INST, CHAN ))
182 /** The execution mask depends on the conditional mask and the loop mask */
183 #define UPDATE_EXEC_MASK(MACH) \
184 MACH->ExecMask = MACH->CondMask & MACH->LoopMask & MACH->ContMask & MACH->Switch.mask & MACH->FuncMask
187 static const union tgsi_exec_channel ZeroVec
=
188 { { 0.0, 0.0, 0.0, 0.0 } };
191 #define CHECK_INF_OR_NAN(chan) do {\
192 assert(!util_is_inf_or_nan((chan)->f[0]));\
193 assert(!util_is_inf_or_nan((chan)->f[1]));\
194 assert(!util_is_inf_or_nan((chan)->f[2]));\
195 assert(!util_is_inf_or_nan((chan)->f[3]));\
201 print_chan(const char *msg
, const union tgsi_exec_channel
*chan
)
203 debug_printf("%s = {%f, %f, %f, %f}\n",
204 msg
, chan
->f
[0], chan
->f
[1], chan
->f
[2], chan
->f
[3]);
211 print_temp(const struct tgsi_exec_machine
*mach
, uint index
)
213 const struct tgsi_exec_vector
*tmp
= &mach
->Temps
[index
];
215 debug_printf("Temp[%u] =\n", index
);
216 for (i
= 0; i
< 4; i
++) {
217 debug_printf(" %c: { %f, %f, %f, %f }\n",
229 * Check if there's a potential src/dst register data dependency when
230 * using SOA execution.
233 * This would expand into:
238 * The second instruction will have the wrong value for t0 if executed as-is.
241 tgsi_check_soa_dependencies(const struct tgsi_full_instruction
*inst
)
245 uint writemask
= inst
->Dst
[0].Register
.WriteMask
;
246 if (writemask
== TGSI_WRITEMASK_X
||
247 writemask
== TGSI_WRITEMASK_Y
||
248 writemask
== TGSI_WRITEMASK_Z
||
249 writemask
== TGSI_WRITEMASK_W
||
250 writemask
== TGSI_WRITEMASK_NONE
) {
251 /* no chance of data dependency */
255 /* loop over src regs */
256 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
257 if ((inst
->Src
[i
].Register
.File
==
258 inst
->Dst
[0].Register
.File
) &&
259 (inst
->Src
[i
].Register
.Index
==
260 inst
->Dst
[0].Register
.Index
)) {
261 /* loop over dest channels */
262 uint channelsWritten
= 0x0;
263 FOR_EACH_ENABLED_CHANNEL(*inst
, chan
) {
264 /* check if we're reading a channel that's been written */
265 uint swizzle
= tgsi_util_get_full_src_register_swizzle(&inst
->Src
[i
], chan
);
266 if (channelsWritten
& (1 << swizzle
)) {
270 channelsWritten
|= (1 << chan
);
279 * Initialize machine state by expanding tokens to full instructions,
280 * allocating temporary storage, setting up constants, etc.
281 * After this, we can call tgsi_exec_machine_run() many times.
284 tgsi_exec_machine_bind_shader(
285 struct tgsi_exec_machine
*mach
,
286 const struct tgsi_token
*tokens
,
288 struct tgsi_sampler
**samplers
)
291 struct tgsi_parse_context parse
;
292 struct tgsi_exec_labels
*labels
= &mach
->Labels
;
293 struct tgsi_full_instruction
*instructions
;
294 struct tgsi_full_declaration
*declarations
;
295 uint maxInstructions
= 10, numInstructions
= 0;
296 uint maxDeclarations
= 10, numDeclarations
= 0;
300 tgsi_dump(tokens
, 0);
305 mach
->Tokens
= tokens
;
306 mach
->Samplers
= samplers
;
308 k
= tgsi_parse_init (&parse
, mach
->Tokens
);
309 if (k
!= TGSI_PARSE_OK
) {
310 debug_printf( "Problem parsing!\n" );
314 mach
->Processor
= parse
.FullHeader
.Processor
.Processor
;
318 declarations
= (struct tgsi_full_declaration
*)
319 MALLOC( maxDeclarations
* sizeof(struct tgsi_full_declaration
) );
325 instructions
= (struct tgsi_full_instruction
*)
326 MALLOC( maxInstructions
* sizeof(struct tgsi_full_instruction
) );
329 FREE( declarations
);
333 while( !tgsi_parse_end_of_tokens( &parse
) ) {
334 uint pointer
= parse
.Position
;
337 tgsi_parse_token( &parse
);
338 switch( parse
.FullToken
.Token
.Type
) {
339 case TGSI_TOKEN_TYPE_DECLARATION
:
340 /* save expanded declaration */
341 if (numDeclarations
== maxDeclarations
) {
342 declarations
= REALLOC(declarations
,
344 * sizeof(struct tgsi_full_declaration
),
345 (maxDeclarations
+ 10)
346 * sizeof(struct tgsi_full_declaration
));
347 maxDeclarations
+= 10;
349 if (parse
.FullToken
.FullDeclaration
.Declaration
.File
== TGSI_FILE_OUTPUT
) {
351 for (reg
= parse
.FullToken
.FullDeclaration
.Range
.First
;
352 reg
<= parse
.FullToken
.FullDeclaration
.Range
.Last
;
357 memcpy(declarations
+ numDeclarations
,
358 &parse
.FullToken
.FullDeclaration
,
359 sizeof(declarations
[0]));
363 case TGSI_TOKEN_TYPE_IMMEDIATE
:
365 uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
367 assert( mach
->ImmLimit
+ 1 <= TGSI_EXEC_NUM_IMMEDIATES
);
369 for( i
= 0; i
< size
; i
++ ) {
370 mach
->Imms
[mach
->ImmLimit
][i
] =
371 parse
.FullToken
.FullImmediate
.u
[i
].Float
;
377 case TGSI_TOKEN_TYPE_INSTRUCTION
:
378 assert( labels
->count
< MAX_LABELS
);
380 labels
->labels
[labels
->count
][0] = instno
;
381 labels
->labels
[labels
->count
][1] = pointer
;
384 /* save expanded instruction */
385 if (numInstructions
== maxInstructions
) {
386 instructions
= REALLOC(instructions
,
388 * sizeof(struct tgsi_full_instruction
),
389 (maxInstructions
+ 10)
390 * sizeof(struct tgsi_full_instruction
));
391 maxInstructions
+= 10;
394 memcpy(instructions
+ numInstructions
,
395 &parse
.FullToken
.FullInstruction
,
396 sizeof(instructions
[0]));
401 case TGSI_TOKEN_TYPE_PROPERTY
:
408 tgsi_parse_free (&parse
);
410 if (mach
->Declarations
) {
411 FREE( mach
->Declarations
);
413 mach
->Declarations
= declarations
;
414 mach
->NumDeclarations
= numDeclarations
;
416 if (mach
->Instructions
) {
417 FREE( mach
->Instructions
);
419 mach
->Instructions
= instructions
;
420 mach
->NumInstructions
= numInstructions
;
424 struct tgsi_exec_machine
*
425 tgsi_exec_machine_create( void )
427 struct tgsi_exec_machine
*mach
;
430 mach
= align_malloc( sizeof *mach
, 16 );
434 memset(mach
, 0, sizeof(*mach
));
436 mach
->Addrs
= &mach
->Temps
[TGSI_EXEC_TEMP_ADDR
];
437 mach
->MaxGeometryShaderOutputs
= TGSI_MAX_TOTAL_VERTICES
;
438 mach
->Predicates
= &mach
->Temps
[TGSI_EXEC_TEMP_P0
];
440 /* Setup constants. */
441 for( i
= 0; i
< 4; i
++ ) {
442 mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
].u
[i
] = 0x00000000;
443 mach
->Temps
[TEMP_7F_I
].xyzw
[TEMP_7F_C
].u
[i
] = 0x7FFFFFFF;
444 mach
->Temps
[TEMP_80_I
].xyzw
[TEMP_80_C
].u
[i
] = 0x80000000;
445 mach
->Temps
[TEMP_FF_I
].xyzw
[TEMP_FF_C
].u
[i
] = 0xFFFFFFFF;
446 mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
].f
[i
] = 1.0f
;
447 mach
->Temps
[TEMP_2_I
].xyzw
[TEMP_2_C
].f
[i
] = 2.0f
;
448 mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
].f
[i
] = 128.0f
;
449 mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
].f
[i
] = -128.0f
;
450 mach
->Temps
[TEMP_3_I
].xyzw
[TEMP_3_C
].f
[i
] = 3.0f
;
451 mach
->Temps
[TEMP_HALF_I
].xyzw
[TEMP_HALF_C
].f
[i
] = 0.5f
;
455 /* silence warnings */
469 tgsi_exec_machine_destroy(struct tgsi_exec_machine
*mach
)
472 FREE(mach
->Instructions
);
473 FREE(mach
->Declarations
);
482 union tgsi_exec_channel
*dst
,
483 const union tgsi_exec_channel
*src
)
485 dst
->f
[0] = fabsf( src
->f
[0] );
486 dst
->f
[1] = fabsf( src
->f
[1] );
487 dst
->f
[2] = fabsf( src
->f
[2] );
488 dst
->f
[3] = fabsf( src
->f
[3] );
493 union tgsi_exec_channel
*dst
,
494 const union tgsi_exec_channel
*src0
,
495 const union tgsi_exec_channel
*src1
)
497 dst
->f
[0] = src0
->f
[0] + src1
->f
[0];
498 dst
->f
[1] = src0
->f
[1] + src1
->f
[1];
499 dst
->f
[2] = src0
->f
[2] + src1
->f
[2];
500 dst
->f
[3] = src0
->f
[3] + src1
->f
[3];
505 union tgsi_exec_channel
*dst
,
506 const union tgsi_exec_channel
*src
)
508 dst
->f
[0] = ceilf( src
->f
[0] );
509 dst
->f
[1] = ceilf( src
->f
[1] );
510 dst
->f
[2] = ceilf( src
->f
[2] );
511 dst
->f
[3] = ceilf( src
->f
[3] );
516 union tgsi_exec_channel
*dst
,
517 const union tgsi_exec_channel
*src
)
519 dst
->f
[0] = cosf( src
->f
[0] );
520 dst
->f
[1] = cosf( src
->f
[1] );
521 dst
->f
[2] = cosf( src
->f
[2] );
522 dst
->f
[3] = cosf( src
->f
[3] );
527 union tgsi_exec_channel
*dst
,
528 const union tgsi_exec_channel
*src
)
533 dst
->f
[3] = src
->f
[TILE_BOTTOM_RIGHT
] - src
->f
[TILE_BOTTOM_LEFT
];
538 union tgsi_exec_channel
*dst
,
539 const union tgsi_exec_channel
*src
)
544 dst
->f
[3] = src
->f
[TILE_BOTTOM_LEFT
] - src
->f
[TILE_TOP_LEFT
];
549 union tgsi_exec_channel
*dst
,
550 const union tgsi_exec_channel
*src0
,
551 const union tgsi_exec_channel
*src1
)
553 if (src1
->f
[0] != 0) {
554 dst
->f
[0] = src0
->f
[0] / src1
->f
[0];
556 if (src1
->f
[1] != 0) {
557 dst
->f
[1] = src0
->f
[1] / src1
->f
[1];
559 if (src1
->f
[2] != 0) {
560 dst
->f
[2] = src0
->f
[2] / src1
->f
[2];
562 if (src1
->f
[3] != 0) {
563 dst
->f
[3] = src0
->f
[3] / src1
->f
[3];
569 union tgsi_exec_channel
*dst
,
570 const union tgsi_exec_channel
*src0
,
571 const union tgsi_exec_channel
*src1
,
572 const union tgsi_exec_channel
*src2
,
573 const union tgsi_exec_channel
*src3
)
575 dst
->f
[0] = src0
->f
[0] == src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
576 dst
->f
[1] = src0
->f
[1] == src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
577 dst
->f
[2] = src0
->f
[2] == src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
578 dst
->f
[3] = src0
->f
[3] == src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
583 union tgsi_exec_channel
*dst
,
584 const union tgsi_exec_channel
*src
)
587 dst
->f
[0] = util_fast_exp2( src
->f
[0] );
588 dst
->f
[1] = util_fast_exp2( src
->f
[1] );
589 dst
->f
[2] = util_fast_exp2( src
->f
[2] );
590 dst
->f
[3] = util_fast_exp2( src
->f
[3] );
594 /* Inf is okay for this instruction, so clamp it to silence assertions. */
596 union tgsi_exec_channel clamped
;
598 for (i
= 0; i
< 4; i
++) {
599 if (src
->f
[i
] > 127.99999f
) {
600 clamped
.f
[i
] = 127.99999f
;
601 } else if (src
->f
[i
] < -126.99999f
) {
602 clamped
.f
[i
] = -126.99999f
;
604 clamped
.f
[i
] = src
->f
[i
];
610 dst
->f
[0] = powf( 2.0f
, src
->f
[0] );
611 dst
->f
[1] = powf( 2.0f
, src
->f
[1] );
612 dst
->f
[2] = powf( 2.0f
, src
->f
[2] );
613 dst
->f
[3] = powf( 2.0f
, src
->f
[3] );
618 micro_float_clamp(union tgsi_exec_channel
*dst
,
619 const union tgsi_exec_channel
*src
)
623 for (i
= 0; i
< 4; i
++) {
624 if (src
->f
[i
] > 0.0f
) {
625 if (src
->f
[i
] > 1.884467e+019f
)
626 dst
->f
[i
] = 1.884467e+019f
;
627 else if (src
->f
[i
] < 5.42101e-020f
)
628 dst
->f
[i
] = 5.42101e-020f
;
630 dst
->f
[i
] = src
->f
[i
];
633 if (src
->f
[i
] < -1.884467e+019f
)
634 dst
->f
[i
] = -1.884467e+019f
;
635 else if (src
->f
[i
] > -5.42101e-020f
)
636 dst
->f
[i
] = -5.42101e-020f
;
638 dst
->f
[i
] = src
->f
[i
];
645 union tgsi_exec_channel
*dst
,
646 const union tgsi_exec_channel
*src
)
648 dst
->f
[0] = floorf( src
->f
[0] );
649 dst
->f
[1] = floorf( src
->f
[1] );
650 dst
->f
[2] = floorf( src
->f
[2] );
651 dst
->f
[3] = floorf( src
->f
[3] );
656 union tgsi_exec_channel
*dst
,
657 const union tgsi_exec_channel
*src
)
659 dst
->f
[0] = src
->f
[0] - floorf( src
->f
[0] );
660 dst
->f
[1] = src
->f
[1] - floorf( src
->f
[1] );
661 dst
->f
[2] = src
->f
[2] - floorf( src
->f
[2] );
662 dst
->f
[3] = src
->f
[3] - floorf( src
->f
[3] );
667 union tgsi_exec_channel
*dst
,
668 const union tgsi_exec_channel
*src
)
671 dst
->f
[0] = util_fast_log2( src
->f
[0] );
672 dst
->f
[1] = util_fast_log2( src
->f
[1] );
673 dst
->f
[2] = util_fast_log2( src
->f
[2] );
674 dst
->f
[3] = util_fast_log2( src
->f
[3] );
676 dst
->f
[0] = logf( src
->f
[0] ) * 1.442695f
;
677 dst
->f
[1] = logf( src
->f
[1] ) * 1.442695f
;
678 dst
->f
[2] = logf( src
->f
[2] ) * 1.442695f
;
679 dst
->f
[3] = logf( src
->f
[3] ) * 1.442695f
;
685 union tgsi_exec_channel
*dst
,
686 const union tgsi_exec_channel
*src0
,
687 const union tgsi_exec_channel
*src1
,
688 const union tgsi_exec_channel
*src2
,
689 const union tgsi_exec_channel
*src3
)
691 dst
->f
[0] = src0
->f
[0] <= src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
692 dst
->f
[1] = src0
->f
[1] <= src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
693 dst
->f
[2] = src0
->f
[2] <= src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
694 dst
->f
[3] = src0
->f
[3] <= src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
699 union tgsi_exec_channel
*dst
,
700 const union tgsi_exec_channel
*src0
,
701 const union tgsi_exec_channel
*src1
,
702 const union tgsi_exec_channel
*src2
,
703 const union tgsi_exec_channel
*src3
)
705 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
706 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
707 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
708 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
713 union tgsi_exec_channel
*dst
,
714 const union tgsi_exec_channel
*src0
,
715 const union tgsi_exec_channel
*src1
)
717 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
718 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
719 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
720 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
725 union tgsi_exec_channel
*dst
,
726 const union tgsi_exec_channel
*src0
,
727 const union tgsi_exec_channel
*src1
)
729 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
730 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
731 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
732 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
737 union tgsi_exec_channel
*dst
,
738 const union tgsi_exec_channel
*src0
,
739 const union tgsi_exec_channel
*src1
)
741 dst
->f
[0] = src0
->f
[0] * src1
->f
[0];
742 dst
->f
[1] = src0
->f
[1] * src1
->f
[1];
743 dst
->f
[2] = src0
->f
[2] * src1
->f
[2];
744 dst
->f
[3] = src0
->f
[3] * src1
->f
[3];
750 union tgsi_exec_channel
*dst0
,
751 union tgsi_exec_channel
*dst1
,
752 const union tgsi_exec_channel
*src0
,
753 const union tgsi_exec_channel
*src1
)
755 dst1
->i
[0] = src0
->i
[0] * src1
->i
[0];
756 dst1
->i
[1] = src0
->i
[1] * src1
->i
[1];
757 dst1
->i
[2] = src0
->i
[2] * src1
->i
[2];
758 dst1
->i
[3] = src0
->i
[3] * src1
->i
[3];
769 union tgsi_exec_channel
*dst0
,
770 union tgsi_exec_channel
*dst1
,
771 const union tgsi_exec_channel
*src0
,
772 const union tgsi_exec_channel
*src1
)
774 dst1
->u
[0] = src0
->u
[0] * src1
->u
[0];
775 dst1
->u
[1] = src0
->u
[1] * src1
->u
[1];
776 dst1
->u
[2] = src0
->u
[2] * src1
->u
[2];
777 dst1
->u
[3] = src0
->u
[3] * src1
->u
[3];
789 union tgsi_exec_channel
*dst
,
790 const union tgsi_exec_channel
*src0
,
791 const union tgsi_exec_channel
*src1
,
792 const union tgsi_exec_channel
*src2
)
794 dst
->u
[0] = src0
->u
[0] ? src1
->u
[0] : src2
->u
[0];
795 dst
->u
[1] = src0
->u
[1] ? src1
->u
[1] : src2
->u
[1];
796 dst
->u
[2] = src0
->u
[2] ? src1
->u
[2] : src2
->u
[2];
797 dst
->u
[3] = src0
->u
[3] ? src1
->u
[3] : src2
->u
[3];
803 union tgsi_exec_channel
*dst
,
804 const union tgsi_exec_channel
*src
)
806 dst
->f
[0] = -src
->f
[0];
807 dst
->f
[1] = -src
->f
[1];
808 dst
->f
[2] = -src
->f
[2];
809 dst
->f
[3] = -src
->f
[3];
814 union tgsi_exec_channel
*dst
,
815 const union tgsi_exec_channel
*src0
,
816 const union tgsi_exec_channel
*src1
)
819 dst
->f
[0] = util_fast_pow( src0
->f
[0], src1
->f
[0] );
820 dst
->f
[1] = util_fast_pow( src0
->f
[1], src1
->f
[1] );
821 dst
->f
[2] = util_fast_pow( src0
->f
[2], src1
->f
[2] );
822 dst
->f
[3] = util_fast_pow( src0
->f
[3], src1
->f
[3] );
824 dst
->f
[0] = powf( src0
->f
[0], src1
->f
[0] );
825 dst
->f
[1] = powf( src0
->f
[1], src1
->f
[1] );
826 dst
->f
[2] = powf( src0
->f
[2], src1
->f
[2] );
827 dst
->f
[3] = powf( src0
->f
[3], src1
->f
[3] );
833 union tgsi_exec_channel
*dst
,
834 const union tgsi_exec_channel
*src
)
836 dst
->f
[0] = floorf( src
->f
[0] + 0.5f
);
837 dst
->f
[1] = floorf( src
->f
[1] + 0.5f
);
838 dst
->f
[2] = floorf( src
->f
[2] + 0.5f
);
839 dst
->f
[3] = floorf( src
->f
[3] + 0.5f
);
844 union tgsi_exec_channel
*dst
,
845 const union tgsi_exec_channel
*src
)
847 dst
->f
[0] = src
->f
[0] < 0.0f
? -1.0f
: src
->f
[0] > 0.0f
? 1.0f
: 0.0f
;
848 dst
->f
[1] = src
->f
[1] < 0.0f
? -1.0f
: src
->f
[1] > 0.0f
? 1.0f
: 0.0f
;
849 dst
->f
[2] = src
->f
[2] < 0.0f
? -1.0f
: src
->f
[2] > 0.0f
? 1.0f
: 0.0f
;
850 dst
->f
[3] = src
->f
[3] < 0.0f
? -1.0f
: src
->f
[3] > 0.0f
? 1.0f
: 0.0f
;
855 union tgsi_exec_channel
*dst
,
856 const union tgsi_exec_channel
*src0
)
858 dst
->f
[0] = (float) (int) src0
->f
[0];
859 dst
->f
[1] = (float) (int) src0
->f
[1];
860 dst
->f
[2] = (float) (int) src0
->f
[2];
861 dst
->f
[3] = (float) (int) src0
->f
[3];
866 union tgsi_exec_channel
*dst
,
867 const union tgsi_exec_channel
*src
)
869 dst
->f
[0] = sinf( src
->f
[0] );
870 dst
->f
[1] = sinf( src
->f
[1] );
871 dst
->f
[2] = sinf( src
->f
[2] );
872 dst
->f
[3] = sinf( src
->f
[3] );
876 micro_sqrt( union tgsi_exec_channel
*dst
,
877 const union tgsi_exec_channel
*src
)
879 dst
->f
[0] = sqrtf( src
->f
[0] );
880 dst
->f
[1] = sqrtf( src
->f
[1] );
881 dst
->f
[2] = sqrtf( src
->f
[2] );
882 dst
->f
[3] = sqrtf( src
->f
[3] );
887 union tgsi_exec_channel
*dst
,
888 const union tgsi_exec_channel
*src0
,
889 const union tgsi_exec_channel
*src1
)
891 dst
->f
[0] = src0
->f
[0] - src1
->f
[0];
892 dst
->f
[1] = src0
->f
[1] - src1
->f
[1];
893 dst
->f
[2] = src0
->f
[2] - src1
->f
[2];
894 dst
->f
[3] = src0
->f
[3] - src1
->f
[3];
898 fetch_src_file_channel(
899 const struct tgsi_exec_machine
*mach
,
902 const union tgsi_exec_channel
*index
,
903 union tgsi_exec_channel
*chan
)
911 case TGSI_FILE_CONSTANT
:
912 assert(mach
->Consts
);
916 chan
->f
[0] = mach
->Consts
[index
->i
[0]][swizzle
];
920 chan
->f
[1] = mach
->Consts
[index
->i
[1]][swizzle
];
924 chan
->f
[2] = mach
->Consts
[index
->i
[2]][swizzle
];
928 chan
->f
[3] = mach
->Consts
[index
->i
[3]][swizzle
];
931 case TGSI_FILE_INPUT
:
932 case TGSI_FILE_SYSTEM_VALUE
:
933 chan
->u
[0] = mach
->Inputs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
934 chan
->u
[1] = mach
->Inputs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
935 chan
->u
[2] = mach
->Inputs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
936 chan
->u
[3] = mach
->Inputs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
939 case TGSI_FILE_TEMPORARY
:
940 assert(index
->i
[0] < TGSI_EXEC_NUM_TEMPS
);
941 chan
->u
[0] = mach
->Temps
[index
->i
[0]].xyzw
[swizzle
].u
[0];
942 chan
->u
[1] = mach
->Temps
[index
->i
[1]].xyzw
[swizzle
].u
[1];
943 chan
->u
[2] = mach
->Temps
[index
->i
[2]].xyzw
[swizzle
].u
[2];
944 chan
->u
[3] = mach
->Temps
[index
->i
[3]].xyzw
[swizzle
].u
[3];
947 case TGSI_FILE_IMMEDIATE
:
948 assert( index
->i
[0] < (int) mach
->ImmLimit
);
949 chan
->f
[0] = mach
->Imms
[index
->i
[0]][swizzle
];
950 assert( index
->i
[1] < (int) mach
->ImmLimit
);
951 chan
->f
[1] = mach
->Imms
[index
->i
[1]][swizzle
];
952 assert( index
->i
[2] < (int) mach
->ImmLimit
);
953 chan
->f
[2] = mach
->Imms
[index
->i
[2]][swizzle
];
954 assert( index
->i
[3] < (int) mach
->ImmLimit
);
955 chan
->f
[3] = mach
->Imms
[index
->i
[3]][swizzle
];
958 case TGSI_FILE_ADDRESS
:
959 chan
->u
[0] = mach
->Addrs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
960 chan
->u
[1] = mach
->Addrs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
961 chan
->u
[2] = mach
->Addrs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
962 chan
->u
[3] = mach
->Addrs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
965 case TGSI_FILE_PREDICATE
:
966 assert(index
->i
[0] < TGSI_EXEC_NUM_PREDS
);
967 assert(index
->i
[1] < TGSI_EXEC_NUM_PREDS
);
968 assert(index
->i
[2] < TGSI_EXEC_NUM_PREDS
);
969 assert(index
->i
[3] < TGSI_EXEC_NUM_PREDS
);
970 chan
->u
[0] = mach
->Predicates
[0].xyzw
[swizzle
].u
[0];
971 chan
->u
[1] = mach
->Predicates
[0].xyzw
[swizzle
].u
[1];
972 chan
->u
[2] = mach
->Predicates
[0].xyzw
[swizzle
].u
[2];
973 chan
->u
[3] = mach
->Predicates
[0].xyzw
[swizzle
].u
[3];
976 case TGSI_FILE_OUTPUT
:
977 /* vertex/fragment output vars can be read too */
978 chan
->u
[0] = mach
->Outputs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
979 chan
->u
[1] = mach
->Outputs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
980 chan
->u
[2] = mach
->Outputs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
981 chan
->u
[3] = mach
->Outputs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
995 fetch_source(const struct tgsi_exec_machine
*mach
,
996 union tgsi_exec_channel
*chan
,
997 const struct tgsi_full_src_register
*reg
,
998 const uint chan_index
,
999 enum tgsi_exec_datatype src_datatype
)
1001 union tgsi_exec_channel index
;
1004 /* We start with a direct index into a register file.
1008 * file = Register.File
1009 * [1] = Register.Index
1014 index
.i
[3] = reg
->Register
.Index
;
1016 /* There is an extra source register that indirectly subscripts
1017 * a register file. The direct index now becomes an offset
1018 * that is being added to the indirect register.
1022 * ind = Indirect.File
1023 * [2] = Indirect.Index
1024 * .x = Indirect.SwizzleX
1026 if (reg
->Register
.Indirect
) {
1027 union tgsi_exec_channel index2
;
1028 union tgsi_exec_channel indir_index
;
1029 const uint execmask
= mach
->ExecMask
;
1032 /* which address register (always zero now) */
1036 index2
.i
[3] = reg
->Indirect
.Index
;
1038 /* get current value of address register[swizzle] */
1039 swizzle
= tgsi_util_get_src_register_swizzle( ®
->Indirect
, CHAN_X
);
1040 fetch_src_file_channel(
1047 /* add value of address register to the offset */
1048 index
.i
[0] += indir_index
.i
[0];
1049 index
.i
[1] += indir_index
.i
[1];
1050 index
.i
[2] += indir_index
.i
[2];
1051 index
.i
[3] += indir_index
.i
[3];
1053 /* for disabled execution channels, zero-out the index to
1054 * avoid using a potential garbage value.
1056 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1057 if ((execmask
& (1 << i
)) == 0)
1062 /* There is an extra source register that is a second
1063 * subscript to a register file. Effectively it means that
1064 * the register file is actually a 2D array of registers.
1066 * file[1][3] == file[1*sizeof(file[1])+3],
1068 * [3] = Dimension.Index
1070 if (reg
->Register
.Dimension
) {
1071 /* The size of the first-order array depends on the register file type.
1072 * We need to multiply the index to the first array to get an effective,
1073 * "flat" index that points to the beginning of the second-order array.
1075 switch (reg
->Register
.File
) {
1076 case TGSI_FILE_INPUT
:
1077 case TGSI_FILE_SYSTEM_VALUE
:
1078 index
.i
[0] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1079 index
.i
[1] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1080 index
.i
[2] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1081 index
.i
[3] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1083 case TGSI_FILE_CONSTANT
:
1084 index
.i
[0] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1085 index
.i
[1] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1086 index
.i
[2] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1087 index
.i
[3] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1093 index
.i
[0] += reg
->Dimension
.Index
;
1094 index
.i
[1] += reg
->Dimension
.Index
;
1095 index
.i
[2] += reg
->Dimension
.Index
;
1096 index
.i
[3] += reg
->Dimension
.Index
;
1098 /* Again, the second subscript index can be addressed indirectly
1099 * identically to the first one.
1100 * Nothing stops us from indirectly addressing the indirect register,
1101 * but there is no need for that, so we won't exercise it.
1103 * file[1][ind[4].y+3],
1105 * ind = DimIndirect.File
1106 * [4] = DimIndirect.Index
1107 * .y = DimIndirect.SwizzleX
1109 if (reg
->Dimension
.Indirect
) {
1110 union tgsi_exec_channel index2
;
1111 union tgsi_exec_channel indir_index
;
1112 const uint execmask
= mach
->ExecMask
;
1118 index2
.i
[3] = reg
->DimIndirect
.Index
;
1120 swizzle
= tgsi_util_get_src_register_swizzle( ®
->DimIndirect
, CHAN_X
);
1121 fetch_src_file_channel(
1123 reg
->DimIndirect
.File
,
1128 index
.i
[0] += indir_index
.i
[0];
1129 index
.i
[1] += indir_index
.i
[1];
1130 index
.i
[2] += indir_index
.i
[2];
1131 index
.i
[3] += indir_index
.i
[3];
1133 /* for disabled execution channels, zero-out the index to
1134 * avoid using a potential garbage value.
1136 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1137 if ((execmask
& (1 << i
)) == 0)
1142 /* If by any chance there was a need for a 3D array of register
1143 * files, we would have to check whether Dimension is followed
1144 * by a dimension register and continue the saga.
1148 swizzle
= tgsi_util_get_full_src_register_swizzle( reg
, chan_index
);
1149 fetch_src_file_channel(
1156 if (reg
->Register
.Absolute
) {
1157 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1158 micro_abs(chan
, chan
);
1160 micro_iabs(chan
, chan
);
1164 if (reg
->Register
.Negate
) {
1165 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1166 micro_neg(chan
, chan
);
1168 micro_ineg(chan
, chan
);
1174 store_dest(struct tgsi_exec_machine
*mach
,
1175 const union tgsi_exec_channel
*chan
,
1176 const struct tgsi_full_dst_register
*reg
,
1177 const struct tgsi_full_instruction
*inst
,
1179 enum tgsi_exec_datatype dst_datatype
)
1182 union tgsi_exec_channel null
;
1183 union tgsi_exec_channel
*dst
;
1184 uint execmask
= mach
->ExecMask
;
1185 int offset
= 0; /* indirection offset */
1188 if (dst_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1189 CHECK_INF_OR_NAN(chan
);
1192 /* There is an extra source register that indirectly subscripts
1193 * a register file. The direct index now becomes an offset
1194 * that is being added to the indirect register.
1198 * ind = Indirect.File
1199 * [2] = Indirect.Index
1200 * .x = Indirect.SwizzleX
1202 if (reg
->Register
.Indirect
) {
1203 union tgsi_exec_channel index
;
1204 union tgsi_exec_channel indir_index
;
1207 /* which address register (always zero for now) */
1211 index
.i
[3] = reg
->Indirect
.Index
;
1213 /* get current value of address register[swizzle] */
1214 swizzle
= tgsi_util_get_src_register_swizzle( ®
->Indirect
, CHAN_X
);
1216 /* fetch values from the address/indirection register */
1217 fetch_src_file_channel(
1224 /* save indirection offset */
1225 offset
= indir_index
.i
[0];
1228 switch (reg
->Register
.File
) {
1229 case TGSI_FILE_NULL
:
1233 case TGSI_FILE_OUTPUT
:
1234 index
= mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0]
1235 + reg
->Register
.Index
;
1236 dst
= &mach
->Outputs
[offset
+ index
].xyzw
[chan_index
];
1238 if (TGSI_PROCESSOR_GEOMETRY
== mach
->Processor
) {
1239 fprintf(stderr
, "STORING OUT[%d] mask(%d), = (", offset
+ index
, execmask
);
1240 for (i
= 0; i
< QUAD_SIZE
; i
++)
1241 if (execmask
& (1 << i
))
1242 fprintf(stderr
, "%f, ", chan
->f
[i
]);
1243 fprintf(stderr
, ")\n");
1248 case TGSI_FILE_TEMPORARY
:
1249 index
= reg
->Register
.Index
;
1250 assert( index
< TGSI_EXEC_NUM_TEMPS
);
1251 dst
= &mach
->Temps
[offset
+ index
].xyzw
[chan_index
];
1254 case TGSI_FILE_ADDRESS
:
1255 index
= reg
->Register
.Index
;
1256 dst
= &mach
->Addrs
[index
].xyzw
[chan_index
];
1259 case TGSI_FILE_LOOP
:
1260 assert(reg
->Register
.Index
== 0);
1261 assert(mach
->LoopCounterStackTop
> 0);
1262 assert(chan_index
== CHAN_X
);
1263 dst
= &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[chan_index
];
1266 case TGSI_FILE_PREDICATE
:
1267 index
= reg
->Register
.Index
;
1268 assert(index
< TGSI_EXEC_NUM_PREDS
);
1269 dst
= &mach
->Predicates
[index
].xyzw
[chan_index
];
1277 if (inst
->Instruction
.Predicate
) {
1279 union tgsi_exec_channel
*pred
;
1281 switch (chan_index
) {
1283 swizzle
= inst
->Predicate
.SwizzleX
;
1286 swizzle
= inst
->Predicate
.SwizzleY
;
1289 swizzle
= inst
->Predicate
.SwizzleZ
;
1292 swizzle
= inst
->Predicate
.SwizzleW
;
1299 assert(inst
->Predicate
.Index
== 0);
1301 pred
= &mach
->Predicates
[inst
->Predicate
.Index
].xyzw
[swizzle
];
1303 if (inst
->Predicate
.Negate
) {
1304 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1306 execmask
&= ~(1 << i
);
1310 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1312 execmask
&= ~(1 << i
);
1318 switch (inst
->Instruction
.Saturate
) {
1320 for (i
= 0; i
< QUAD_SIZE
; i
++)
1321 if (execmask
& (1 << i
))
1322 dst
->i
[i
] = chan
->i
[i
];
1325 case TGSI_SAT_ZERO_ONE
:
1326 for (i
= 0; i
< QUAD_SIZE
; i
++)
1327 if (execmask
& (1 << i
)) {
1328 if (chan
->f
[i
] < 0.0f
)
1330 else if (chan
->f
[i
] > 1.0f
)
1333 dst
->i
[i
] = chan
->i
[i
];
1337 case TGSI_SAT_MINUS_PLUS_ONE
:
1338 for (i
= 0; i
< QUAD_SIZE
; i
++)
1339 if (execmask
& (1 << i
)) {
1340 if (chan
->f
[i
] < -1.0f
)
1342 else if (chan
->f
[i
] > 1.0f
)
1345 dst
->i
[i
] = chan
->i
[i
];
1354 #define FETCH(VAL,INDEX,CHAN)\
1355 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_FLOAT)
1357 #define STORE(VAL,INDEX,CHAN)\
1358 store_dest(mach, VAL, &inst->Dst[INDEX], inst, CHAN, TGSI_EXEC_DATA_FLOAT)
1362 * Execute ARB-style KIL which is predicated by a src register.
1363 * Kill fragment if any of the four values is less than zero.
1366 exec_kil(struct tgsi_exec_machine
*mach
,
1367 const struct tgsi_full_instruction
*inst
)
1371 uint kilmask
= 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1372 union tgsi_exec_channel r
[1];
1374 /* This mask stores component bits that were already tested. */
1377 for (chan_index
= 0; chan_index
< 4; chan_index
++)
1382 /* unswizzle channel */
1383 swizzle
= tgsi_util_get_full_src_register_swizzle (
1387 /* check if the component has not been already tested */
1388 if (uniquemask
& (1 << swizzle
))
1390 uniquemask
|= 1 << swizzle
;
1392 FETCH(&r
[0], 0, chan_index
);
1393 for (i
= 0; i
< 4; i
++)
1394 if (r
[0].f
[i
] < 0.0f
)
1398 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1402 * Execute NVIDIA-style KIL which is predicated by a condition code.
1403 * Kill fragment if the condition code is TRUE.
1406 exec_kilp(struct tgsi_exec_machine
*mach
,
1407 const struct tgsi_full_instruction
*inst
)
1409 uint kilmask
; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1411 /* "unconditional" kil */
1412 kilmask
= mach
->ExecMask
;
1413 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1417 emit_vertex(struct tgsi_exec_machine
*mach
)
1419 /* FIXME: check for exec mask correctly
1421 for (i = 0; i < QUAD_SIZE; ++i) {
1422 if ((mach->ExecMask & (1 << i)))
1424 if (mach
->ExecMask
) {
1425 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] += mach
->NumOutputs
;
1426 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]]++;
1431 emit_primitive(struct tgsi_exec_machine
*mach
)
1433 unsigned *prim_count
= &mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0];
1434 /* FIXME: check for exec mask correctly
1436 for (i = 0; i < QUAD_SIZE; ++i) {
1437 if ((mach->ExecMask & (1 << i)))
1439 if (mach
->ExecMask
) {
1441 debug_assert((*prim_count
* mach
->NumOutputs
) < mach
->MaxGeometryShaderOutputs
);
1442 mach
->Primitives
[*prim_count
] = 0;
1447 * Fetch a four texture samples using STR texture coordinates.
1450 fetch_texel( struct tgsi_sampler
*sampler
,
1451 const union tgsi_exec_channel
*s
,
1452 const union tgsi_exec_channel
*t
,
1453 const union tgsi_exec_channel
*p
,
1454 float lodbias
, /* XXX should be float[4] */
1455 union tgsi_exec_channel
*r
,
1456 union tgsi_exec_channel
*g
,
1457 union tgsi_exec_channel
*b
,
1458 union tgsi_exec_channel
*a
)
1461 float rgba
[NUM_CHANNELS
][QUAD_SIZE
];
1463 sampler
->get_samples(sampler
, s
->f
, t
->f
, p
->f
, lodbias
, rgba
);
1465 for (j
= 0; j
< 4; j
++) {
1466 r
->f
[j
] = rgba
[0][j
];
1467 g
->f
[j
] = rgba
[1][j
];
1468 b
->f
[j
] = rgba
[2][j
];
1469 a
->f
[j
] = rgba
[3][j
];
1475 exec_tex(struct tgsi_exec_machine
*mach
,
1476 const struct tgsi_full_instruction
*inst
,
1480 const uint unit
= inst
->Src
[1].Register
.Index
;
1481 union tgsi_exec_channel r
[4];
1485 /* debug_printf("Sampler %u unit %u\n", sampler, unit); */
1487 switch (inst
->Texture
.Texture
) {
1488 case TGSI_TEXTURE_1D
:
1489 case TGSI_TEXTURE_SHADOW1D
:
1491 FETCH(&r
[0], 0, CHAN_X
);
1494 FETCH(&r
[1], 0, CHAN_W
);
1495 micro_div( &r
[0], &r
[0], &r
[1] );
1499 FETCH(&r
[1], 0, CHAN_W
);
1500 lodBias
= r
[2].f
[0];
1505 fetch_texel(mach
->Samplers
[unit
],
1506 &r
[0], &ZeroVec
, &ZeroVec
, lodBias
, /* S, T, P, BIAS */
1507 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1510 case TGSI_TEXTURE_2D
:
1511 case TGSI_TEXTURE_RECT
:
1512 case TGSI_TEXTURE_SHADOW2D
:
1513 case TGSI_TEXTURE_SHADOWRECT
:
1515 FETCH(&r
[0], 0, CHAN_X
);
1516 FETCH(&r
[1], 0, CHAN_Y
);
1517 FETCH(&r
[2], 0, CHAN_Z
);
1520 FETCH(&r
[3], 0, CHAN_W
);
1521 micro_div( &r
[0], &r
[0], &r
[3] );
1522 micro_div( &r
[1], &r
[1], &r
[3] );
1523 micro_div( &r
[2], &r
[2], &r
[3] );
1527 FETCH(&r
[3], 0, CHAN_W
);
1528 lodBias
= r
[3].f
[0];
1533 fetch_texel(mach
->Samplers
[unit
],
1534 &r
[0], &r
[1], &r
[2], lodBias
, /* inputs */
1535 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1538 case TGSI_TEXTURE_3D
:
1539 case TGSI_TEXTURE_CUBE
:
1541 FETCH(&r
[0], 0, CHAN_X
);
1542 FETCH(&r
[1], 0, CHAN_Y
);
1543 FETCH(&r
[2], 0, CHAN_Z
);
1546 FETCH(&r
[3], 0, CHAN_W
);
1547 micro_div( &r
[0], &r
[0], &r
[3] );
1548 micro_div( &r
[1], &r
[1], &r
[3] );
1549 micro_div( &r
[2], &r
[2], &r
[3] );
1553 FETCH(&r
[3], 0, CHAN_W
);
1554 lodBias
= r
[3].f
[0];
1559 fetch_texel(mach
->Samplers
[unit
],
1560 &r
[0], &r
[1], &r
[2], lodBias
,
1561 &r
[0], &r
[1], &r
[2], &r
[3]);
1568 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1569 STORE( &r
[chan_index
], 0, chan_index
);
1574 exec_txd(struct tgsi_exec_machine
*mach
,
1575 const struct tgsi_full_instruction
*inst
)
1577 const uint unit
= inst
->Src
[3].Register
.Index
;
1578 union tgsi_exec_channel r
[4];
1582 * XXX: This is fake TXD -- the derivatives are not taken into account, yet.
1585 switch (inst
->Texture
.Texture
) {
1586 case TGSI_TEXTURE_1D
:
1587 case TGSI_TEXTURE_SHADOW1D
:
1589 FETCH(&r
[0], 0, CHAN_X
);
1591 fetch_texel(mach
->Samplers
[unit
],
1592 &r
[0], &ZeroVec
, &ZeroVec
, 0.0f
, /* S, T, P, BIAS */
1593 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1596 case TGSI_TEXTURE_2D
:
1597 case TGSI_TEXTURE_RECT
:
1598 case TGSI_TEXTURE_SHADOW2D
:
1599 case TGSI_TEXTURE_SHADOWRECT
:
1601 FETCH(&r
[0], 0, CHAN_X
);
1602 FETCH(&r
[1], 0, CHAN_Y
);
1603 FETCH(&r
[2], 0, CHAN_Z
);
1605 fetch_texel(mach
->Samplers
[unit
],
1606 &r
[0], &r
[1], &r
[2], 0.0f
, /* inputs */
1607 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1610 case TGSI_TEXTURE_3D
:
1611 case TGSI_TEXTURE_CUBE
:
1613 FETCH(&r
[0], 0, CHAN_X
);
1614 FETCH(&r
[1], 0, CHAN_Y
);
1615 FETCH(&r
[2], 0, CHAN_Z
);
1617 fetch_texel(mach
->Samplers
[unit
],
1618 &r
[0], &r
[1], &r
[2], 0.0f
,
1619 &r
[0], &r
[1], &r
[2], &r
[3]);
1626 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
1627 STORE(&r
[chan_index
], 0, chan_index
);
1633 * Evaluate a constant-valued coefficient at the position of the
1638 struct tgsi_exec_machine
*mach
,
1644 for( i
= 0; i
< QUAD_SIZE
; i
++ ) {
1645 mach
->Inputs
[attrib
].xyzw
[chan
].f
[i
] = mach
->InterpCoefs
[attrib
].a0
[chan
];
1650 * Evaluate a linear-valued coefficient at the position of the
1655 struct tgsi_exec_machine
*mach
,
1659 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1660 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1661 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1662 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1663 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1664 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
;
1665 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = a0
+ dadx
;
1666 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = a0
+ dady
;
1667 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = a0
+ dadx
+ dady
;
1671 * Evaluate a perspective-valued coefficient at the position of the
1675 eval_perspective_coef(
1676 struct tgsi_exec_machine
*mach
,
1680 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1681 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1682 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1683 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1684 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1685 const float *w
= mach
->QuadPos
.xyzw
[3].f
;
1686 /* divide by W here */
1687 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
/ w
[0];
1688 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = (a0
+ dadx
) / w
[1];
1689 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = (a0
+ dady
) / w
[2];
1690 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = (a0
+ dadx
+ dady
) / w
[3];
1694 typedef void (* eval_coef_func
)(
1695 struct tgsi_exec_machine
*mach
,
1700 exec_declaration(struct tgsi_exec_machine
*mach
,
1701 const struct tgsi_full_declaration
*decl
)
1703 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
1704 if (decl
->Declaration
.File
== TGSI_FILE_INPUT
||
1705 decl
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1706 uint first
, last
, mask
;
1708 first
= decl
->Range
.First
;
1709 last
= decl
->Range
.Last
;
1710 mask
= decl
->Declaration
.UsageMask
;
1712 if (decl
->Semantic
.Name
== TGSI_SEMANTIC_POSITION
) {
1713 assert(decl
->Semantic
.Index
== 0);
1714 assert(first
== last
);
1715 assert(mask
== TGSI_WRITEMASK_XYZW
);
1717 mach
->Inputs
[first
] = mach
->QuadPos
;
1718 } else if (decl
->Semantic
.Name
== TGSI_SEMANTIC_FACE
) {
1721 assert(decl
->Semantic
.Index
== 0);
1722 assert(first
== last
);
1724 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1725 mach
->Inputs
[first
].xyzw
[0].f
[i
] = mach
->Face
;
1728 eval_coef_func eval
;
1731 switch (decl
->Declaration
.Interpolate
) {
1732 case TGSI_INTERPOLATE_CONSTANT
:
1733 eval
= eval_constant_coef
;
1736 case TGSI_INTERPOLATE_LINEAR
:
1737 eval
= eval_linear_coef
;
1740 case TGSI_INTERPOLATE_PERSPECTIVE
:
1741 eval
= eval_perspective_coef
;
1749 for (j
= 0; j
< NUM_CHANNELS
; j
++) {
1750 if (mask
& (1 << j
)) {
1751 for (i
= first
; i
<= last
; i
++) {
1761 typedef void (* micro_op
)(union tgsi_exec_channel
*dst
,
1762 const union tgsi_exec_channel
*src
);
1765 exec_vector_unary(struct tgsi_exec_machine
*mach
,
1766 const struct tgsi_full_instruction
*inst
,
1768 enum tgsi_exec_datatype dst_datatype
,
1769 enum tgsi_exec_datatype src_datatype
)
1772 struct tgsi_exec_vector dst
;
1774 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1775 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1776 union tgsi_exec_channel src
;
1778 fetch_source(mach
, &src
, &inst
->Src
[0], chan
, src_datatype
);
1779 op(&dst
.xyzw
[chan
], &src
);
1782 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1783 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1784 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
1790 exec_vector_binary(struct tgsi_exec_machine
*mach
,
1791 const struct tgsi_full_instruction
*inst
,
1793 enum tgsi_exec_datatype dst_datatype
,
1794 enum tgsi_exec_datatype src_datatype
)
1797 struct tgsi_exec_vector dst
;
1799 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1800 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1801 union tgsi_exec_channel src
[2];
1803 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
1804 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
1805 op(&dst
.xyzw
[chan
], src
);
1808 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1809 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1810 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
1816 exec_vector_trinary(struct tgsi_exec_machine
*mach
,
1817 const struct tgsi_full_instruction
*inst
,
1819 enum tgsi_exec_datatype dst_datatype
,
1820 enum tgsi_exec_datatype src_datatype
)
1823 struct tgsi_exec_vector dst
;
1825 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1826 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1827 union tgsi_exec_channel src
[3];
1829 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
1830 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
1831 fetch_source(mach
, &src
[2], &inst
->Src
[2], chan
, src_datatype
);
1832 op(&dst
.xyzw
[chan
], src
);
1835 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1836 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1837 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
1843 exec_break(struct tgsi_exec_machine
*mach
)
1845 if (mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_LOOP
) {
1846 /* turn off loop channels for each enabled exec channel */
1847 mach
->LoopMask
&= ~mach
->ExecMask
;
1848 /* Todo: if mach->LoopMask == 0, jump to end of loop */
1849 UPDATE_EXEC_MASK(mach
);
1851 assert(mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_SWITCH
);
1853 mach
->Switch
.mask
= 0x0;
1855 UPDATE_EXEC_MASK(mach
);
1860 exec_switch(struct tgsi_exec_machine
*mach
,
1861 const struct tgsi_full_instruction
*inst
)
1863 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
1864 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
1866 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
1867 fetch_source(mach
, &mach
->Switch
.selector
, &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_UINT
);
1868 mach
->Switch
.mask
= 0x0;
1869 mach
->Switch
.defaultMask
= 0x0;
1871 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
1872 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_SWITCH
;
1874 UPDATE_EXEC_MASK(mach
);
1878 exec_case(struct tgsi_exec_machine
*mach
,
1879 const struct tgsi_full_instruction
*inst
)
1881 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
1882 union tgsi_exec_channel src
;
1885 fetch_source(mach
, &src
, &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_UINT
);
1887 if (mach
->Switch
.selector
.u
[0] == src
.u
[0]) {
1890 if (mach
->Switch
.selector
.u
[1] == src
.u
[1]) {
1893 if (mach
->Switch
.selector
.u
[2] == src
.u
[2]) {
1896 if (mach
->Switch
.selector
.u
[3] == src
.u
[3]) {
1900 mach
->Switch
.defaultMask
|= mask
;
1902 mach
->Switch
.mask
|= mask
& prevMask
;
1904 UPDATE_EXEC_MASK(mach
);
1908 exec_default(struct tgsi_exec_machine
*mach
)
1910 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
1912 mach
->Switch
.mask
|= ~mach
->Switch
.defaultMask
& prevMask
;
1914 UPDATE_EXEC_MASK(mach
);
1918 exec_endswitch(struct tgsi_exec_machine
*mach
)
1920 mach
->Switch
= mach
->SwitchStack
[--mach
->SwitchStackTop
];
1921 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
1923 UPDATE_EXEC_MASK(mach
);
1927 micro_i2f(union tgsi_exec_channel
*dst
,
1928 const union tgsi_exec_channel
*src
)
1930 dst
->f
[0] = (float)src
->i
[0];
1931 dst
->f
[1] = (float)src
->i
[1];
1932 dst
->f
[2] = (float)src
->i
[2];
1933 dst
->f
[3] = (float)src
->i
[3];
1937 micro_not(union tgsi_exec_channel
*dst
,
1938 const union tgsi_exec_channel
*src
)
1940 dst
->u
[0] = ~src
->u
[0];
1941 dst
->u
[1] = ~src
->u
[1];
1942 dst
->u
[2] = ~src
->u
[2];
1943 dst
->u
[3] = ~src
->u
[3];
1947 micro_shl(union tgsi_exec_channel
*dst
,
1948 const union tgsi_exec_channel
*src
)
1950 dst
->u
[0] = src
[0].u
[0] << src
[1].u
[0];
1951 dst
->u
[1] = src
[0].u
[1] << src
[1].u
[1];
1952 dst
->u
[2] = src
[0].u
[2] << src
[1].u
[2];
1953 dst
->u
[3] = src
[0].u
[3] << src
[1].u
[3];
1957 micro_and(union tgsi_exec_channel
*dst
,
1958 const union tgsi_exec_channel
*src
)
1960 dst
->u
[0] = src
[0].u
[0] & src
[1].u
[0];
1961 dst
->u
[1] = src
[0].u
[1] & src
[1].u
[1];
1962 dst
->u
[2] = src
[0].u
[2] & src
[1].u
[2];
1963 dst
->u
[3] = src
[0].u
[3] & src
[1].u
[3];
1967 micro_or(union tgsi_exec_channel
*dst
,
1968 const union tgsi_exec_channel
*src
)
1970 dst
->u
[0] = src
[0].u
[0] | src
[1].u
[0];
1971 dst
->u
[1] = src
[0].u
[1] | src
[1].u
[1];
1972 dst
->u
[2] = src
[0].u
[2] | src
[1].u
[2];
1973 dst
->u
[3] = src
[0].u
[3] | src
[1].u
[3];
1977 micro_xor(union tgsi_exec_channel
*dst
,
1978 const union tgsi_exec_channel
*src
)
1980 dst
->u
[0] = src
[0].u
[0] ^ src
[1].u
[0];
1981 dst
->u
[1] = src
[0].u
[1] ^ src
[1].u
[1];
1982 dst
->u
[2] = src
[0].u
[2] ^ src
[1].u
[2];
1983 dst
->u
[3] = src
[0].u
[3] ^ src
[1].u
[3];
1987 micro_f2i(union tgsi_exec_channel
*dst
,
1988 const union tgsi_exec_channel
*src
)
1990 dst
->i
[0] = (int)src
->f
[0];
1991 dst
->i
[1] = (int)src
->f
[1];
1992 dst
->i
[2] = (int)src
->f
[2];
1993 dst
->i
[3] = (int)src
->f
[3];
1997 micro_idiv(union tgsi_exec_channel
*dst
,
1998 const union tgsi_exec_channel
*src
)
2000 dst
->i
[0] = src
[0].i
[0] / src
[1].i
[0];
2001 dst
->i
[1] = src
[0].i
[1] / src
[1].i
[1];
2002 dst
->i
[2] = src
[0].i
[2] / src
[1].i
[2];
2003 dst
->i
[3] = src
[0].i
[3] / src
[1].i
[3];
2007 micro_imax(union tgsi_exec_channel
*dst
,
2008 const union tgsi_exec_channel
*src
)
2010 dst
->i
[0] = src
[0].i
[0] > src
[1].i
[0] ? src
[0].i
[0] : src
[1].i
[0];
2011 dst
->i
[1] = src
[0].i
[1] > src
[1].i
[1] ? src
[0].i
[1] : src
[1].i
[1];
2012 dst
->i
[2] = src
[0].i
[2] > src
[1].i
[2] ? src
[0].i
[2] : src
[1].i
[2];
2013 dst
->i
[3] = src
[0].i
[3] > src
[1].i
[3] ? src
[0].i
[3] : src
[1].i
[3];
2017 micro_imin(union tgsi_exec_channel
*dst
,
2018 const union tgsi_exec_channel
*src
)
2020 dst
->i
[0] = src
[0].i
[0] < src
[1].i
[0] ? src
[0].i
[0] : src
[1].i
[0];
2021 dst
->i
[1] = src
[0].i
[1] < src
[1].i
[1] ? src
[0].i
[1] : src
[1].i
[1];
2022 dst
->i
[2] = src
[0].i
[2] < src
[1].i
[2] ? src
[0].i
[2] : src
[1].i
[2];
2023 dst
->i
[3] = src
[0].i
[3] < src
[1].i
[3] ? src
[0].i
[3] : src
[1].i
[3];
2027 micro_isge(union tgsi_exec_channel
*dst
,
2028 const union tgsi_exec_channel
*src
)
2030 dst
->i
[0] = src
[0].i
[0] >= src
[1].i
[0] ? -1 : 0;
2031 dst
->i
[1] = src
[0].i
[1] >= src
[1].i
[1] ? -1 : 0;
2032 dst
->i
[2] = src
[0].i
[2] >= src
[1].i
[2] ? -1 : 0;
2033 dst
->i
[3] = src
[0].i
[3] >= src
[1].i
[3] ? -1 : 0;
2037 micro_ishr(union tgsi_exec_channel
*dst
,
2038 const union tgsi_exec_channel
*src
)
2040 dst
->i
[0] = src
[0].i
[0] >> src
[1].i
[0];
2041 dst
->i
[1] = src
[0].i
[1] >> src
[1].i
[1];
2042 dst
->i
[2] = src
[0].i
[2] >> src
[1].i
[2];
2043 dst
->i
[3] = src
[0].i
[3] >> src
[1].i
[3];
2047 micro_islt(union tgsi_exec_channel
*dst
,
2048 const union tgsi_exec_channel
*src
)
2050 dst
->i
[0] = src
[0].i
[0] < src
[1].i
[0] ? -1 : 0;
2051 dst
->i
[1] = src
[0].i
[1] < src
[1].i
[1] ? -1 : 0;
2052 dst
->i
[2] = src
[0].i
[2] < src
[1].i
[2] ? -1 : 0;
2053 dst
->i
[3] = src
[0].i
[3] < src
[1].i
[3] ? -1 : 0;
2057 micro_f2u(union tgsi_exec_channel
*dst
,
2058 const union tgsi_exec_channel
*src
)
2060 dst
->u
[0] = (uint
)src
->f
[0];
2061 dst
->u
[1] = (uint
)src
->f
[1];
2062 dst
->u
[2] = (uint
)src
->f
[2];
2063 dst
->u
[3] = (uint
)src
->f
[3];
2067 micro_u2f(union tgsi_exec_channel
*dst
,
2068 const union tgsi_exec_channel
*src
)
2070 dst
->f
[0] = (float)src
->u
[0];
2071 dst
->f
[1] = (float)src
->u
[1];
2072 dst
->f
[2] = (float)src
->u
[2];
2073 dst
->f
[3] = (float)src
->u
[3];
2077 micro_uadd(union tgsi_exec_channel
*dst
,
2078 const union tgsi_exec_channel
*src
)
2080 dst
->u
[0] = src
[0].u
[0] + src
[1].u
[0];
2081 dst
->u
[1] = src
[0].u
[1] + src
[1].u
[1];
2082 dst
->u
[2] = src
[0].u
[2] + src
[1].u
[2];
2083 dst
->u
[3] = src
[0].u
[3] + src
[1].u
[3];
2087 micro_udiv(union tgsi_exec_channel
*dst
,
2088 const union tgsi_exec_channel
*src
)
2090 dst
->u
[0] = src
[0].u
[0] / src
[1].u
[0];
2091 dst
->u
[1] = src
[0].u
[1] / src
[1].u
[1];
2092 dst
->u
[2] = src
[0].u
[2] / src
[1].u
[2];
2093 dst
->u
[3] = src
[0].u
[3] / src
[1].u
[3];
2097 micro_umad(union tgsi_exec_channel
*dst
,
2098 const union tgsi_exec_channel
*src
)
2100 dst
->u
[0] = src
[0].u
[0] * src
[1].u
[0] + src
[2].u
[0];
2101 dst
->u
[1] = src
[0].u
[1] * src
[1].u
[1] + src
[2].u
[1];
2102 dst
->u
[2] = src
[0].u
[2] * src
[1].u
[2] + src
[2].u
[2];
2103 dst
->u
[3] = src
[0].u
[3] * src
[1].u
[3] + src
[2].u
[3];
2107 micro_umax(union tgsi_exec_channel
*dst
,
2108 const union tgsi_exec_channel
*src
)
2110 dst
->u
[0] = src
[0].u
[0] > src
[1].u
[0] ? src
[0].u
[0] : src
[1].u
[0];
2111 dst
->u
[1] = src
[0].u
[1] > src
[1].u
[1] ? src
[0].u
[1] : src
[1].u
[1];
2112 dst
->u
[2] = src
[0].u
[2] > src
[1].u
[2] ? src
[0].u
[2] : src
[1].u
[2];
2113 dst
->u
[3] = src
[0].u
[3] > src
[1].u
[3] ? src
[0].u
[3] : src
[1].u
[3];
2117 micro_umin(union tgsi_exec_channel
*dst
,
2118 const union tgsi_exec_channel
*src
)
2120 dst
->u
[0] = src
[0].u
[0] < src
[1].u
[0] ? src
[0].u
[0] : src
[1].u
[0];
2121 dst
->u
[1] = src
[0].u
[1] < src
[1].u
[1] ? src
[0].u
[1] : src
[1].u
[1];
2122 dst
->u
[2] = src
[0].u
[2] < src
[1].u
[2] ? src
[0].u
[2] : src
[1].u
[2];
2123 dst
->u
[3] = src
[0].u
[3] < src
[1].u
[3] ? src
[0].u
[3] : src
[1].u
[3];
2127 micro_umod(union tgsi_exec_channel
*dst
,
2128 const union tgsi_exec_channel
*src
)
2130 dst
->u
[0] = src
[0].u
[0] % src
[1].u
[0];
2131 dst
->u
[1] = src
[0].u
[1] % src
[1].u
[1];
2132 dst
->u
[2] = src
[0].u
[2] % src
[1].u
[2];
2133 dst
->u
[3] = src
[0].u
[3] % src
[1].u
[3];
2137 micro_umul(union tgsi_exec_channel
*dst
,
2138 const union tgsi_exec_channel
*src
)
2140 dst
->u
[0] = src
[0].u
[0] * src
[1].u
[0];
2141 dst
->u
[1] = src
[0].u
[1] * src
[1].u
[1];
2142 dst
->u
[2] = src
[0].u
[2] * src
[1].u
[2];
2143 dst
->u
[3] = src
[0].u
[3] * src
[1].u
[3];
2147 micro_useq(union tgsi_exec_channel
*dst
,
2148 const union tgsi_exec_channel
*src
)
2150 dst
->u
[0] = src
[0].u
[0] == src
[1].u
[0] ? ~0 : 0;
2151 dst
->u
[1] = src
[0].u
[1] == src
[1].u
[1] ? ~0 : 0;
2152 dst
->u
[2] = src
[0].u
[2] == src
[1].u
[2] ? ~0 : 0;
2153 dst
->u
[3] = src
[0].u
[3] == src
[1].u
[3] ? ~0 : 0;
2157 micro_usge(union tgsi_exec_channel
*dst
,
2158 const union tgsi_exec_channel
*src
)
2160 dst
->u
[0] = src
[0].u
[0] >= src
[1].u
[0] ? ~0 : 0;
2161 dst
->u
[1] = src
[0].u
[1] >= src
[1].u
[1] ? ~0 : 0;
2162 dst
->u
[2] = src
[0].u
[2] >= src
[1].u
[2] ? ~0 : 0;
2163 dst
->u
[3] = src
[0].u
[3] >= src
[1].u
[3] ? ~0 : 0;
2167 micro_ushr(union tgsi_exec_channel
*dst
,
2168 const union tgsi_exec_channel
*src
)
2170 dst
->u
[0] = src
[0].u
[0] >> src
[1].u
[0];
2171 dst
->u
[1] = src
[0].u
[1] >> src
[1].u
[1];
2172 dst
->u
[2] = src
[0].u
[2] >> src
[1].u
[2];
2173 dst
->u
[3] = src
[0].u
[3] >> src
[1].u
[3];
2177 micro_uslt(union tgsi_exec_channel
*dst
,
2178 const union tgsi_exec_channel
*src
)
2180 dst
->u
[0] = src
[0].u
[0] < src
[1].u
[0] ? ~0 : 0;
2181 dst
->u
[1] = src
[0].u
[1] < src
[1].u
[1] ? ~0 : 0;
2182 dst
->u
[2] = src
[0].u
[2] < src
[1].u
[2] ? ~0 : 0;
2183 dst
->u
[3] = src
[0].u
[3] < src
[1].u
[3] ? ~0 : 0;
2187 micro_usne(union tgsi_exec_channel
*dst
,
2188 const union tgsi_exec_channel
*src
)
2190 dst
->u
[0] = src
[0].u
[0] != src
[1].u
[0] ? ~0 : 0;
2191 dst
->u
[1] = src
[0].u
[1] != src
[1].u
[1] ? ~0 : 0;
2192 dst
->u
[2] = src
[0].u
[2] != src
[1].u
[2] ? ~0 : 0;
2193 dst
->u
[3] = src
[0].u
[3] != src
[1].u
[3] ? ~0 : 0;
2198 struct tgsi_exec_machine
*mach
,
2199 const struct tgsi_full_instruction
*inst
,
2203 union tgsi_exec_channel r
[10];
2204 union tgsi_exec_channel d
[8];
2208 switch (inst
->Instruction
.Opcode
) {
2209 case TGSI_OPCODE_ARL
:
2210 exec_vector_unary(mach
, inst
, micro_arl
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
2213 case TGSI_OPCODE_MOV
:
2214 exec_vector_unary(mach
, inst
, micro_mov
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
2217 case TGSI_OPCODE_LIT
:
2218 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2219 FETCH( &r
[0], 0, CHAN_X
);
2220 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2221 micro_max(&d
[CHAN_Y
], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
2224 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2225 FETCH( &r
[1], 0, CHAN_Y
);
2226 micro_max( &r
[1], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
2228 FETCH( &r
[2], 0, CHAN_W
);
2229 micro_min( &r
[2], &r
[2], &mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
] );
2230 micro_max( &r
[2], &r
[2], &mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
] );
2231 micro_pow( &r
[1], &r
[1], &r
[2] );
2232 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
]);
2235 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2236 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2238 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2239 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2242 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2243 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2245 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2246 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2250 case TGSI_OPCODE_RCP
:
2251 /* TGSI_OPCODE_RECIP */
2252 FETCH( &r
[0], 0, CHAN_X
);
2253 micro_div( &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0] );
2254 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2255 STORE( &r
[0], 0, chan_index
);
2259 case TGSI_OPCODE_RSQ
:
2260 /* TGSI_OPCODE_RECIPSQRT */
2261 FETCH( &r
[0], 0, CHAN_X
);
2262 micro_abs( &r
[0], &r
[0] );
2263 micro_sqrt( &r
[0], &r
[0] );
2264 micro_div( &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0] );
2265 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2266 STORE( &r
[0], 0, chan_index
);
2270 case TGSI_OPCODE_EXP
:
2271 FETCH( &r
[0], 0, CHAN_X
);
2272 micro_flr( &r
[1], &r
[0] ); /* r1 = floor(r0) */
2273 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2274 micro_exp2( &r
[2], &r
[1] ); /* r2 = 2 ^ r1 */
2275 STORE( &r
[2], 0, CHAN_X
); /* store r2 */
2277 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2278 micro_sub( &r
[2], &r
[0], &r
[1] ); /* r2 = r0 - r1 */
2279 STORE( &r
[2], 0, CHAN_Y
); /* store r2 */
2281 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2282 micro_exp2( &r
[2], &r
[0] ); /* r2 = 2 ^ r0 */
2283 STORE( &r
[2], 0, CHAN_Z
); /* store r2 */
2285 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2286 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2290 case TGSI_OPCODE_LOG
:
2291 FETCH( &r
[0], 0, CHAN_X
);
2292 micro_abs( &r
[2], &r
[0] ); /* r2 = abs(r0) */
2293 micro_lg2( &r
[1], &r
[2] ); /* r1 = lg2(r2) */
2294 micro_flr( &r
[0], &r
[1] ); /* r0 = floor(r1) */
2295 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2296 STORE( &r
[0], 0, CHAN_X
);
2298 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2299 micro_exp2( &r
[0], &r
[0] ); /* r0 = 2 ^ r0 */
2300 micro_div( &r
[0], &r
[2], &r
[0] ); /* r0 = r2 / r0 */
2301 STORE( &r
[0], 0, CHAN_Y
);
2303 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2304 STORE( &r
[1], 0, CHAN_Z
);
2306 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2307 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2311 case TGSI_OPCODE_MUL
:
2312 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2313 FETCH(&r
[0], 0, chan_index
);
2314 FETCH(&r
[1], 1, chan_index
);
2315 micro_mul(&d
[chan_index
], &r
[0], &r
[1]);
2317 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2318 STORE(&d
[chan_index
], 0, chan_index
);
2322 case TGSI_OPCODE_ADD
:
2323 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2324 FETCH( &r
[0], 0, chan_index
);
2325 FETCH( &r
[1], 1, chan_index
);
2326 micro_add(&d
[chan_index
], &r
[0], &r
[1]);
2328 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2329 STORE(&d
[chan_index
], 0, chan_index
);
2333 case TGSI_OPCODE_DP3
:
2334 /* TGSI_OPCODE_DOT3 */
2335 FETCH( &r
[0], 0, CHAN_X
);
2336 FETCH( &r
[1], 1, CHAN_X
);
2337 micro_mul( &r
[0], &r
[0], &r
[1] );
2339 FETCH( &r
[1], 0, CHAN_Y
);
2340 FETCH( &r
[2], 1, CHAN_Y
);
2341 micro_mul( &r
[1], &r
[1], &r
[2] );
2342 micro_add( &r
[0], &r
[0], &r
[1] );
2344 FETCH( &r
[1], 0, CHAN_Z
);
2345 FETCH( &r
[2], 1, CHAN_Z
);
2346 micro_mul( &r
[1], &r
[1], &r
[2] );
2347 micro_add( &r
[0], &r
[0], &r
[1] );
2349 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2350 STORE( &r
[0], 0, chan_index
);
2354 case TGSI_OPCODE_DP4
:
2355 /* TGSI_OPCODE_DOT4 */
2356 FETCH(&r
[0], 0, CHAN_X
);
2357 FETCH(&r
[1], 1, CHAN_X
);
2359 micro_mul( &r
[0], &r
[0], &r
[1] );
2361 FETCH(&r
[1], 0, CHAN_Y
);
2362 FETCH(&r
[2], 1, CHAN_Y
);
2364 micro_mul( &r
[1], &r
[1], &r
[2] );
2365 micro_add( &r
[0], &r
[0], &r
[1] );
2367 FETCH(&r
[1], 0, CHAN_Z
);
2368 FETCH(&r
[2], 1, CHAN_Z
);
2370 micro_mul( &r
[1], &r
[1], &r
[2] );
2371 micro_add( &r
[0], &r
[0], &r
[1] );
2373 FETCH(&r
[1], 0, CHAN_W
);
2374 FETCH(&r
[2], 1, CHAN_W
);
2376 micro_mul( &r
[1], &r
[1], &r
[2] );
2377 micro_add( &r
[0], &r
[0], &r
[1] );
2379 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2380 STORE( &r
[0], 0, chan_index
);
2384 case TGSI_OPCODE_DST
:
2385 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2386 FETCH( &r
[0], 0, CHAN_Y
);
2387 FETCH( &r
[1], 1, CHAN_Y
);
2388 micro_mul(&d
[CHAN_Y
], &r
[0], &r
[1]);
2390 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2391 FETCH(&d
[CHAN_Z
], 0, CHAN_Z
);
2393 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2394 FETCH(&d
[CHAN_W
], 1, CHAN_W
);
2397 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2398 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2400 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2401 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2403 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2404 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2406 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2407 STORE(&d
[CHAN_W
], 0, CHAN_W
);
2411 case TGSI_OPCODE_MIN
:
2412 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2413 FETCH(&r
[0], 0, chan_index
);
2414 FETCH(&r
[1], 1, chan_index
);
2416 /* XXX use micro_min()?? */
2417 micro_lt(&d
[chan_index
], &r
[0], &r
[1], &r
[0], &r
[1]);
2419 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2420 STORE(&d
[chan_index
], 0, chan_index
);
2424 case TGSI_OPCODE_MAX
:
2425 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2426 FETCH(&r
[0], 0, chan_index
);
2427 FETCH(&r
[1], 1, chan_index
);
2429 /* XXX use micro_max()?? */
2430 micro_lt(&d
[chan_index
], &r
[0], &r
[1], &r
[1], &r
[0] );
2432 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2433 STORE(&d
[chan_index
], 0, chan_index
);
2437 case TGSI_OPCODE_SLT
:
2438 /* TGSI_OPCODE_SETLT */
2439 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2440 FETCH( &r
[0], 0, chan_index
);
2441 FETCH( &r
[1], 1, chan_index
);
2442 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
]);
2444 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2445 STORE(&d
[chan_index
], 0, chan_index
);
2449 case TGSI_OPCODE_SGE
:
2450 /* TGSI_OPCODE_SETGE */
2451 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2452 FETCH( &r
[0], 0, chan_index
);
2453 FETCH( &r
[1], 1, chan_index
);
2454 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
]);
2456 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2457 STORE(&d
[chan_index
], 0, chan_index
);
2461 case TGSI_OPCODE_MAD
:
2462 /* TGSI_OPCODE_MADD */
2463 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2464 FETCH( &r
[0], 0, chan_index
);
2465 FETCH( &r
[1], 1, chan_index
);
2466 micro_mul( &r
[0], &r
[0], &r
[1] );
2467 FETCH( &r
[1], 2, chan_index
);
2468 micro_add(&d
[chan_index
], &r
[0], &r
[1]);
2470 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2471 STORE(&d
[chan_index
], 0, chan_index
);
2475 case TGSI_OPCODE_SUB
:
2476 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2477 FETCH(&r
[0], 0, chan_index
);
2478 FETCH(&r
[1], 1, chan_index
);
2479 micro_sub(&d
[chan_index
], &r
[0], &r
[1]);
2481 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2482 STORE(&d
[chan_index
], 0, chan_index
);
2486 case TGSI_OPCODE_LRP
:
2487 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2488 FETCH(&r
[0], 0, chan_index
);
2489 FETCH(&r
[1], 1, chan_index
);
2490 FETCH(&r
[2], 2, chan_index
);
2491 micro_sub( &r
[1], &r
[1], &r
[2] );
2492 micro_mul( &r
[0], &r
[0], &r
[1] );
2493 micro_add(&d
[chan_index
], &r
[0], &r
[2]);
2495 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2496 STORE(&d
[chan_index
], 0, chan_index
);
2500 case TGSI_OPCODE_CND
:
2501 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2502 FETCH(&r
[0], 0, chan_index
);
2503 FETCH(&r
[1], 1, chan_index
);
2504 FETCH(&r
[2], 2, chan_index
);
2505 micro_lt(&d
[chan_index
], &mach
->Temps
[TEMP_HALF_I
].xyzw
[TEMP_HALF_C
], &r
[2], &r
[0], &r
[1]);
2507 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2508 STORE(&d
[chan_index
], 0, chan_index
);
2512 case TGSI_OPCODE_DP2A
:
2513 FETCH( &r
[0], 0, CHAN_X
);
2514 FETCH( &r
[1], 1, CHAN_X
);
2515 micro_mul( &r
[0], &r
[0], &r
[1] );
2517 FETCH( &r
[1], 0, CHAN_Y
);
2518 FETCH( &r
[2], 1, CHAN_Y
);
2519 micro_mul( &r
[1], &r
[1], &r
[2] );
2520 micro_add( &r
[0], &r
[0], &r
[1] );
2522 FETCH( &r
[2], 2, CHAN_X
);
2523 micro_add( &r
[0], &r
[0], &r
[2] );
2525 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2526 STORE( &r
[0], 0, chan_index
);
2530 case TGSI_OPCODE_FRC
:
2531 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2532 FETCH( &r
[0], 0, chan_index
);
2533 micro_frc(&d
[chan_index
], &r
[0]);
2535 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2536 STORE(&d
[chan_index
], 0, chan_index
);
2540 case TGSI_OPCODE_CLAMP
:
2541 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2542 FETCH(&r
[0], 0, chan_index
);
2543 FETCH(&r
[1], 1, chan_index
);
2544 micro_max(&r
[0], &r
[0], &r
[1]);
2545 FETCH(&r
[1], 2, chan_index
);
2546 micro_min(&d
[chan_index
], &r
[0], &r
[1]);
2548 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2549 STORE(&d
[chan_index
], 0, chan_index
);
2553 case TGSI_OPCODE_FLR
:
2554 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2555 FETCH( &r
[0], 0, chan_index
);
2556 micro_flr(&d
[chan_index
], &r
[0]);
2558 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2559 STORE(&d
[chan_index
], 0, chan_index
);
2563 case TGSI_OPCODE_ROUND
:
2564 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2565 FETCH( &r
[0], 0, chan_index
);
2566 micro_rnd(&d
[chan_index
], &r
[0]);
2568 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2569 STORE(&d
[chan_index
], 0, chan_index
);
2573 case TGSI_OPCODE_EX2
:
2574 FETCH(&r
[0], 0, CHAN_X
);
2576 micro_exp2( &r
[0], &r
[0] );
2578 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2579 STORE( &r
[0], 0, chan_index
);
2583 case TGSI_OPCODE_LG2
:
2584 FETCH( &r
[0], 0, CHAN_X
);
2585 micro_lg2( &r
[0], &r
[0] );
2586 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2587 STORE( &r
[0], 0, chan_index
);
2591 case TGSI_OPCODE_POW
:
2592 FETCH(&r
[0], 0, CHAN_X
);
2593 FETCH(&r
[1], 1, CHAN_X
);
2595 micro_pow( &r
[0], &r
[0], &r
[1] );
2597 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2598 STORE( &r
[0], 0, chan_index
);
2602 case TGSI_OPCODE_XPD
:
2603 FETCH(&r
[0], 0, CHAN_Y
);
2604 FETCH(&r
[1], 1, CHAN_Z
);
2606 micro_mul( &r
[2], &r
[0], &r
[1] );
2608 FETCH(&r
[3], 0, CHAN_Z
);
2609 FETCH(&r
[4], 1, CHAN_Y
);
2611 micro_mul( &r
[5], &r
[3], &r
[4] );
2612 micro_sub(&d
[CHAN_X
], &r
[2], &r
[5]);
2614 FETCH(&r
[2], 1, CHAN_X
);
2616 micro_mul( &r
[3], &r
[3], &r
[2] );
2618 FETCH(&r
[5], 0, CHAN_X
);
2620 micro_mul( &r
[1], &r
[1], &r
[5] );
2621 micro_sub(&d
[CHAN_Y
], &r
[3], &r
[1]);
2623 micro_mul( &r
[5], &r
[5], &r
[4] );
2624 micro_mul( &r
[0], &r
[0], &r
[2] );
2625 micro_sub(&d
[CHAN_Z
], &r
[5], &r
[0]);
2627 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2628 STORE(&d
[CHAN_X
], 0, CHAN_X
);
2630 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2631 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2633 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2634 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2636 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2637 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2641 case TGSI_OPCODE_ABS
:
2642 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2643 FETCH(&r
[0], 0, chan_index
);
2644 micro_abs(&d
[chan_index
], &r
[0]);
2646 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2647 STORE(&d
[chan_index
], 0, chan_index
);
2651 case TGSI_OPCODE_RCC
:
2652 FETCH(&r
[0], 0, CHAN_X
);
2653 micro_div(&r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0]);
2654 micro_float_clamp(&r
[0], &r
[0]);
2655 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2656 STORE(&r
[0], 0, chan_index
);
2660 case TGSI_OPCODE_DPH
:
2661 FETCH(&r
[0], 0, CHAN_X
);
2662 FETCH(&r
[1], 1, CHAN_X
);
2664 micro_mul( &r
[0], &r
[0], &r
[1] );
2666 FETCH(&r
[1], 0, CHAN_Y
);
2667 FETCH(&r
[2], 1, CHAN_Y
);
2669 micro_mul( &r
[1], &r
[1], &r
[2] );
2670 micro_add( &r
[0], &r
[0], &r
[1] );
2672 FETCH(&r
[1], 0, CHAN_Z
);
2673 FETCH(&r
[2], 1, CHAN_Z
);
2675 micro_mul( &r
[1], &r
[1], &r
[2] );
2676 micro_add( &r
[0], &r
[0], &r
[1] );
2678 FETCH(&r
[1], 1, CHAN_W
);
2680 micro_add( &r
[0], &r
[0], &r
[1] );
2682 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2683 STORE( &r
[0], 0, chan_index
);
2687 case TGSI_OPCODE_COS
:
2688 FETCH(&r
[0], 0, CHAN_X
);
2690 micro_cos( &r
[0], &r
[0] );
2692 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2693 STORE( &r
[0], 0, chan_index
);
2697 case TGSI_OPCODE_DDX
:
2698 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2699 FETCH( &r
[0], 0, chan_index
);
2700 micro_ddx(&d
[chan_index
], &r
[0]);
2702 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2703 STORE(&d
[chan_index
], 0, chan_index
);
2707 case TGSI_OPCODE_DDY
:
2708 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2709 FETCH( &r
[0], 0, chan_index
);
2710 micro_ddy(&d
[chan_index
], &r
[0]);
2712 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2713 STORE(&d
[chan_index
], 0, chan_index
);
2717 case TGSI_OPCODE_KILP
:
2718 exec_kilp (mach
, inst
);
2721 case TGSI_OPCODE_KIL
:
2722 exec_kil (mach
, inst
);
2725 case TGSI_OPCODE_PK2H
:
2729 case TGSI_OPCODE_PK2US
:
2733 case TGSI_OPCODE_PK4B
:
2737 case TGSI_OPCODE_PK4UB
:
2741 case TGSI_OPCODE_RFL
:
2742 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2743 IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2744 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2745 /* r0 = dp3(src0, src0) */
2746 FETCH(&r
[2], 0, CHAN_X
);
2747 micro_mul(&r
[0], &r
[2], &r
[2]);
2748 FETCH(&r
[4], 0, CHAN_Y
);
2749 micro_mul(&r
[8], &r
[4], &r
[4]);
2750 micro_add(&r
[0], &r
[0], &r
[8]);
2751 FETCH(&r
[6], 0, CHAN_Z
);
2752 micro_mul(&r
[8], &r
[6], &r
[6]);
2753 micro_add(&r
[0], &r
[0], &r
[8]);
2755 /* r1 = dp3(src0, src1) */
2756 FETCH(&r
[3], 1, CHAN_X
);
2757 micro_mul(&r
[1], &r
[2], &r
[3]);
2758 FETCH(&r
[5], 1, CHAN_Y
);
2759 micro_mul(&r
[8], &r
[4], &r
[5]);
2760 micro_add(&r
[1], &r
[1], &r
[8]);
2761 FETCH(&r
[7], 1, CHAN_Z
);
2762 micro_mul(&r
[8], &r
[6], &r
[7]);
2763 micro_add(&r
[1], &r
[1], &r
[8]);
2765 /* r1 = 2 * r1 / r0 */
2766 micro_add(&r
[1], &r
[1], &r
[1]);
2767 micro_div(&r
[1], &r
[1], &r
[0]);
2769 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2770 micro_mul(&r
[2], &r
[2], &r
[1]);
2771 micro_sub(&r
[2], &r
[2], &r
[3]);
2772 STORE(&r
[2], 0, CHAN_X
);
2774 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2775 micro_mul(&r
[4], &r
[4], &r
[1]);
2776 micro_sub(&r
[4], &r
[4], &r
[5]);
2777 STORE(&r
[4], 0, CHAN_Y
);
2779 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2780 micro_mul(&r
[6], &r
[6], &r
[1]);
2781 micro_sub(&r
[6], &r
[6], &r
[7]);
2782 STORE(&r
[6], 0, CHAN_Z
);
2785 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2786 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2790 case TGSI_OPCODE_SEQ
:
2791 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2792 FETCH( &r
[0], 0, chan_index
);
2793 FETCH( &r
[1], 1, chan_index
);
2794 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
]);
2796 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2797 STORE(&d
[chan_index
], 0, chan_index
);
2801 case TGSI_OPCODE_SFL
:
2802 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2803 STORE(&mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, chan_index
);
2807 case TGSI_OPCODE_SGT
:
2808 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2809 FETCH( &r
[0], 0, chan_index
);
2810 FETCH( &r
[1], 1, chan_index
);
2811 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
]);
2813 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2814 STORE(&d
[chan_index
], 0, chan_index
);
2818 case TGSI_OPCODE_SIN
:
2819 FETCH( &r
[0], 0, CHAN_X
);
2820 micro_sin( &r
[0], &r
[0] );
2821 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2822 STORE( &r
[0], 0, chan_index
);
2826 case TGSI_OPCODE_SLE
:
2827 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2828 FETCH( &r
[0], 0, chan_index
);
2829 FETCH( &r
[1], 1, chan_index
);
2830 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
]);
2832 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2833 STORE(&d
[chan_index
], 0, chan_index
);
2837 case TGSI_OPCODE_SNE
:
2838 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2839 FETCH( &r
[0], 0, chan_index
);
2840 FETCH( &r
[1], 1, chan_index
);
2841 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
]);
2843 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2844 STORE(&d
[chan_index
], 0, chan_index
);
2848 case TGSI_OPCODE_STR
:
2849 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2850 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, chan_index
);
2854 case TGSI_OPCODE_TEX
:
2855 /* simple texture lookup */
2856 /* src[0] = texcoord */
2857 /* src[1] = sampler unit */
2858 exec_tex(mach
, inst
, FALSE
, FALSE
);
2861 case TGSI_OPCODE_TXB
:
2862 /* Texture lookup with lod bias */
2863 /* src[0] = texcoord (src[0].w = LOD bias) */
2864 /* src[1] = sampler unit */
2865 exec_tex(mach
, inst
, TRUE
, FALSE
);
2868 case TGSI_OPCODE_TXD
:
2869 /* Texture lookup with explict partial derivatives */
2870 /* src[0] = texcoord */
2871 /* src[1] = d[strq]/dx */
2872 /* src[2] = d[strq]/dy */
2873 /* src[3] = sampler unit */
2874 exec_txd(mach
, inst
);
2877 case TGSI_OPCODE_TXL
:
2878 /* Texture lookup with explit LOD */
2879 /* src[0] = texcoord (src[0].w = LOD) */
2880 /* src[1] = sampler unit */
2881 exec_tex(mach
, inst
, TRUE
, FALSE
);
2884 case TGSI_OPCODE_TXP
:
2885 /* Texture lookup with projection */
2886 /* src[0] = texcoord (src[0].w = projection) */
2887 /* src[1] = sampler unit */
2888 exec_tex(mach
, inst
, FALSE
, TRUE
);
2891 case TGSI_OPCODE_UP2H
:
2895 case TGSI_OPCODE_UP2US
:
2899 case TGSI_OPCODE_UP4B
:
2903 case TGSI_OPCODE_UP4UB
:
2907 case TGSI_OPCODE_X2D
:
2908 FETCH(&r
[0], 1, CHAN_X
);
2909 FETCH(&r
[1], 1, CHAN_Y
);
2910 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2911 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2912 FETCH(&r
[2], 2, CHAN_X
);
2913 micro_mul(&r
[2], &r
[2], &r
[0]);
2914 FETCH(&r
[3], 2, CHAN_Y
);
2915 micro_mul(&r
[3], &r
[3], &r
[1]);
2916 micro_add(&r
[2], &r
[2], &r
[3]);
2917 FETCH(&r
[3], 0, CHAN_X
);
2918 micro_add(&d
[CHAN_X
], &r
[2], &r
[3]);
2921 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2922 IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2923 FETCH(&r
[2], 2, CHAN_Z
);
2924 micro_mul(&r
[2], &r
[2], &r
[0]);
2925 FETCH(&r
[3], 2, CHAN_W
);
2926 micro_mul(&r
[3], &r
[3], &r
[1]);
2927 micro_add(&r
[2], &r
[2], &r
[3]);
2928 FETCH(&r
[3], 0, CHAN_Y
);
2929 micro_add(&d
[CHAN_Y
], &r
[2], &r
[3]);
2932 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2933 STORE(&d
[CHAN_X
], 0, CHAN_X
);
2935 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2936 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2938 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2939 STORE(&d
[CHAN_X
], 0, CHAN_Z
);
2941 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2942 STORE(&d
[CHAN_Y
], 0, CHAN_W
);
2946 case TGSI_OPCODE_ARA
:
2950 case TGSI_OPCODE_ARR
:
2951 exec_vector_unary(mach
, inst
, micro_arr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
2954 case TGSI_OPCODE_BRA
:
2958 case TGSI_OPCODE_CAL
:
2959 /* skip the call if no execution channels are enabled */
2960 if (mach
->ExecMask
) {
2963 /* First, record the depths of the execution stacks.
2964 * This is important for deeply nested/looped return statements.
2965 * We have to unwind the stacks by the correct amount. For a
2966 * real code generator, we could determine the number of entries
2967 * to pop off each stack with simple static analysis and avoid
2968 * implementing this data structure at run time.
2970 mach
->CallStack
[mach
->CallStackTop
].CondStackTop
= mach
->CondStackTop
;
2971 mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
= mach
->LoopStackTop
;
2972 mach
->CallStack
[mach
->CallStackTop
].ContStackTop
= mach
->ContStackTop
;
2973 mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
= mach
->SwitchStackTop
;
2974 mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
= mach
->BreakStackTop
;
2975 /* note that PC was already incremented above */
2976 mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
= *pc
;
2978 mach
->CallStackTop
++;
2980 /* Second, push the Cond, Loop, Cont, Func stacks */
2981 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
2982 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2983 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2984 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
2985 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
2986 assert(mach
->FuncStackTop
< TGSI_EXEC_MAX_CALL_NESTING
);
2988 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
2989 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
2990 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
2991 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
2992 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
2993 mach
->FuncStack
[mach
->FuncStackTop
++] = mach
->FuncMask
;
2995 /* Finally, jump to the subroutine */
2996 *pc
= inst
->Label
.Label
;
3000 case TGSI_OPCODE_RET
:
3001 mach
->FuncMask
&= ~mach
->ExecMask
;
3002 UPDATE_EXEC_MASK(mach
);
3004 if (mach
->FuncMask
== 0x0) {
3005 /* really return now (otherwise, keep executing */
3007 if (mach
->CallStackTop
== 0) {
3008 /* returning from main() */
3013 assert(mach
->CallStackTop
> 0);
3014 mach
->CallStackTop
--;
3016 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
3017 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
3019 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
3020 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
3022 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
3023 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
3025 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
3026 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
3028 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
3029 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
3031 assert(mach
->FuncStackTop
> 0);
3032 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
3034 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
3036 UPDATE_EXEC_MASK(mach
);
3040 case TGSI_OPCODE_SSG
:
3041 /* TGSI_OPCODE_SGN */
3042 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3043 FETCH( &r
[0], 0, chan_index
);
3044 micro_sgn(&d
[chan_index
], &r
[0]);
3046 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3047 STORE(&d
[chan_index
], 0, chan_index
);
3051 case TGSI_OPCODE_CMP
:
3052 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3053 FETCH(&r
[0], 0, chan_index
);
3054 FETCH(&r
[1], 1, chan_index
);
3055 FETCH(&r
[2], 2, chan_index
);
3056 micro_lt(&d
[chan_index
], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &r
[1], &r
[2]);
3058 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3059 STORE(&d
[chan_index
], 0, chan_index
);
3063 case TGSI_OPCODE_SCS
:
3064 if( IS_CHANNEL_ENABLED( *inst
, CHAN_X
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) ) {
3065 FETCH( &r
[0], 0, CHAN_X
);
3066 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
3067 micro_cos(&r
[1], &r
[0]);
3068 STORE(&r
[1], 0, CHAN_X
);
3070 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
3071 micro_sin(&r
[1], &r
[0]);
3072 STORE(&r
[1], 0, CHAN_Y
);
3075 if( IS_CHANNEL_ENABLED( *inst
, CHAN_Z
) ) {
3076 STORE( &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, CHAN_Z
);
3078 if( IS_CHANNEL_ENABLED( *inst
, CHAN_W
) ) {
3079 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
3083 case TGSI_OPCODE_NRM
:
3084 /* 3-component vector normalize */
3085 if(IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
3086 IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
3087 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
3088 /* r3 = sqrt(dp3(src0, src0)) */
3089 FETCH(&r
[0], 0, CHAN_X
);
3090 micro_mul(&r
[3], &r
[0], &r
[0]);
3091 FETCH(&r
[1], 0, CHAN_Y
);
3092 micro_mul(&r
[4], &r
[1], &r
[1]);
3093 micro_add(&r
[3], &r
[3], &r
[4]);
3094 FETCH(&r
[2], 0, CHAN_Z
);
3095 micro_mul(&r
[4], &r
[2], &r
[2]);
3096 micro_add(&r
[3], &r
[3], &r
[4]);
3097 micro_sqrt(&r
[3], &r
[3]);
3099 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
3100 micro_div(&r
[0], &r
[0], &r
[3]);
3101 STORE(&r
[0], 0, CHAN_X
);
3103 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
3104 micro_div(&r
[1], &r
[1], &r
[3]);
3105 STORE(&r
[1], 0, CHAN_Y
);
3107 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
3108 micro_div(&r
[2], &r
[2], &r
[3]);
3109 STORE(&r
[2], 0, CHAN_Z
);
3112 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
3113 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
3117 case TGSI_OPCODE_NRM4
:
3118 /* 4-component vector normalize */
3120 union tgsi_exec_channel tmp
, dot
;
3122 /* tmp = dp4(src0, src0): */
3123 FETCH( &r
[0], 0, CHAN_X
);
3124 micro_mul( &tmp
, &r
[0], &r
[0] );
3126 FETCH( &r
[1], 0, CHAN_Y
);
3127 micro_mul( &dot
, &r
[1], &r
[1] );
3128 micro_add( &tmp
, &tmp
, &dot
);
3130 FETCH( &r
[2], 0, CHAN_Z
);
3131 micro_mul( &dot
, &r
[2], &r
[2] );
3132 micro_add( &tmp
, &tmp
, &dot
);
3134 FETCH( &r
[3], 0, CHAN_W
);
3135 micro_mul( &dot
, &r
[3], &r
[3] );
3136 micro_add( &tmp
, &tmp
, &dot
);
3138 /* tmp = 1 / sqrt(tmp) */
3139 micro_sqrt( &tmp
, &tmp
);
3140 micro_div( &tmp
, &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &tmp
);
3142 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3143 /* chan = chan * tmp */
3144 micro_mul( &r
[chan_index
], &tmp
, &r
[chan_index
] );
3145 STORE( &r
[chan_index
], 0, chan_index
);
3150 case TGSI_OPCODE_DIV
:
3154 case TGSI_OPCODE_DP2
:
3155 FETCH( &r
[0], 0, CHAN_X
);
3156 FETCH( &r
[1], 1, CHAN_X
);
3157 micro_mul( &r
[0], &r
[0], &r
[1] );
3159 FETCH( &r
[1], 0, CHAN_Y
);
3160 FETCH( &r
[2], 1, CHAN_Y
);
3161 micro_mul( &r
[1], &r
[1], &r
[2] );
3162 micro_add( &r
[0], &r
[0], &r
[1] );
3164 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3165 STORE( &r
[0], 0, chan_index
);
3169 case TGSI_OPCODE_IF
:
3171 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
3172 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
3173 FETCH( &r
[0], 0, CHAN_X
);
3174 /* update CondMask */
3176 mach
->CondMask
&= ~0x1;
3179 mach
->CondMask
&= ~0x2;
3182 mach
->CondMask
&= ~0x4;
3185 mach
->CondMask
&= ~0x8;
3187 UPDATE_EXEC_MASK(mach
);
3188 /* Todo: If CondMask==0, jump to ELSE */
3191 case TGSI_OPCODE_ELSE
:
3192 /* invert CondMask wrt previous mask */
3195 assert(mach
->CondStackTop
> 0);
3196 prevMask
= mach
->CondStack
[mach
->CondStackTop
- 1];
3197 mach
->CondMask
= ~mach
->CondMask
& prevMask
;
3198 UPDATE_EXEC_MASK(mach
);
3199 /* Todo: If CondMask==0, jump to ENDIF */
3203 case TGSI_OPCODE_ENDIF
:
3205 assert(mach
->CondStackTop
> 0);
3206 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
3207 UPDATE_EXEC_MASK(mach
);
3210 case TGSI_OPCODE_END
:
3211 /* halt execution */
3215 case TGSI_OPCODE_REP
:
3219 case TGSI_OPCODE_ENDREP
:
3223 case TGSI_OPCODE_PUSHA
:
3227 case TGSI_OPCODE_POPA
:
3231 case TGSI_OPCODE_CEIL
:
3232 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3233 FETCH( &r
[0], 0, chan_index
);
3234 micro_ceil(&d
[chan_index
], &r
[0]);
3236 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3237 STORE(&d
[chan_index
], 0, chan_index
);
3241 case TGSI_OPCODE_I2F
:
3242 exec_vector_unary(mach
, inst
, micro_i2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_INT
);
3245 case TGSI_OPCODE_NOT
:
3246 exec_vector_unary(mach
, inst
, micro_not
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3249 case TGSI_OPCODE_TRUNC
:
3250 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3251 FETCH( &r
[0], 0, chan_index
);
3252 micro_trunc(&d
[chan_index
], &r
[0]);
3254 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3255 STORE(&d
[chan_index
], 0, chan_index
);
3259 case TGSI_OPCODE_SHL
:
3260 exec_vector_binary(mach
, inst
, micro_shl
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3263 case TGSI_OPCODE_AND
:
3264 exec_vector_binary(mach
, inst
, micro_and
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3267 case TGSI_OPCODE_OR
:
3268 exec_vector_binary(mach
, inst
, micro_or
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3271 case TGSI_OPCODE_MOD
:
3275 case TGSI_OPCODE_XOR
:
3276 exec_vector_binary(mach
, inst
, micro_xor
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3279 case TGSI_OPCODE_SAD
:
3283 case TGSI_OPCODE_TXF
:
3287 case TGSI_OPCODE_TXQ
:
3291 case TGSI_OPCODE_EMIT
:
3295 case TGSI_OPCODE_ENDPRIM
:
3296 emit_primitive(mach
);
3299 case TGSI_OPCODE_BGNFOR
:
3300 assert(mach
->LoopCounterStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3301 for (chan_index
= 0; chan_index
< 3; chan_index
++) {
3302 FETCH( &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[chan_index
], 0, chan_index
);
3304 ++mach
->LoopCounterStackTop
;
3305 STORE(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
], 0, CHAN_X
);
3306 /* update LoopMask */
3307 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[0] <= 0.0f
) {
3308 mach
->LoopMask
&= ~0x1;
3310 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[1] <= 0.0f
) {
3311 mach
->LoopMask
&= ~0x2;
3313 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[2] <= 0.0f
) {
3314 mach
->LoopMask
&= ~0x4;
3316 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[3] <= 0.0f
) {
3317 mach
->LoopMask
&= ~0x8;
3319 /* TODO: if mach->LoopMask == 0, jump to end of loop */
3320 UPDATE_EXEC_MASK(mach
);
3321 /* fall-through (for now) */
3322 case TGSI_OPCODE_BGNLOOP
:
3323 /* push LoopMask and ContMasks */
3324 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3325 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3326 assert(mach
->LoopLabelStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3327 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
3329 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
3330 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
3331 mach
->LoopLabelStack
[mach
->LoopLabelStackTop
++] = *pc
- 1;
3332 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
3333 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_LOOP
;
3336 case TGSI_OPCODE_ENDFOR
:
3337 assert(mach
->LoopCounterStackTop
> 0);
3338 micro_sub(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
],
3339 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
],
3340 &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
]);
3341 /* update LoopMask */
3342 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[0] <= 0.0f
) {
3343 mach
->LoopMask
&= ~0x1;
3345 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[1] <= 0.0f
) {
3346 mach
->LoopMask
&= ~0x2;
3348 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[2] <= 0.0f
) {
3349 mach
->LoopMask
&= ~0x4;
3351 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[3] <= 0.0f
) {
3352 mach
->LoopMask
&= ~0x8;
3354 micro_add(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
],
3355 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
],
3356 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Z
]);
3357 assert(mach
->LoopLabelStackTop
> 0);
3358 inst
= mach
->Instructions
+ mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1];
3359 STORE(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[CHAN_X
], 0, CHAN_X
);
3360 /* Restore ContMask, but don't pop */
3361 assert(mach
->ContStackTop
> 0);
3362 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3363 UPDATE_EXEC_MASK(mach
);
3364 if (mach
->ExecMask
) {
3365 /* repeat loop: jump to instruction just past BGNLOOP */
3366 assert(mach
->LoopLabelStackTop
> 0);
3367 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3370 /* exit loop: pop LoopMask */
3371 assert(mach
->LoopStackTop
> 0);
3372 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3374 assert(mach
->ContStackTop
> 0);
3375 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3376 assert(mach
->LoopLabelStackTop
> 0);
3377 --mach
->LoopLabelStackTop
;
3378 assert(mach
->LoopCounterStackTop
> 0);
3379 --mach
->LoopCounterStackTop
;
3381 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
3383 UPDATE_EXEC_MASK(mach
);
3386 case TGSI_OPCODE_ENDLOOP
:
3387 /* Restore ContMask, but don't pop */
3388 assert(mach
->ContStackTop
> 0);
3389 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3390 UPDATE_EXEC_MASK(mach
);
3391 if (mach
->ExecMask
) {
3392 /* repeat loop: jump to instruction just past BGNLOOP */
3393 assert(mach
->LoopLabelStackTop
> 0);
3394 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3397 /* exit loop: pop LoopMask */
3398 assert(mach
->LoopStackTop
> 0);
3399 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3401 assert(mach
->ContStackTop
> 0);
3402 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3403 assert(mach
->LoopLabelStackTop
> 0);
3404 --mach
->LoopLabelStackTop
;
3406 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
3408 UPDATE_EXEC_MASK(mach
);
3411 case TGSI_OPCODE_BRK
:
3415 case TGSI_OPCODE_CONT
:
3416 /* turn off cont channels for each enabled exec channel */
3417 mach
->ContMask
&= ~mach
->ExecMask
;
3418 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3419 UPDATE_EXEC_MASK(mach
);
3422 case TGSI_OPCODE_BGNSUB
:
3426 case TGSI_OPCODE_ENDSUB
:
3428 * XXX: This really should be a no-op. We should never reach this opcode.
3431 assert(mach
->CallStackTop
> 0);
3432 mach
->CallStackTop
--;
3434 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
3435 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
3437 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
3438 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
3440 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
3441 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
3443 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
3444 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
3446 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
3447 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
3449 assert(mach
->FuncStackTop
> 0);
3450 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
3452 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
3454 UPDATE_EXEC_MASK(mach
);
3457 case TGSI_OPCODE_NOP
:
3460 case TGSI_OPCODE_BREAKC
:
3461 FETCH(&r
[0], 0, CHAN_X
);
3462 /* update CondMask */
3463 if (r
[0].u
[0] && (mach
->ExecMask
& 0x1)) {
3464 mach
->LoopMask
&= ~0x1;
3466 if (r
[0].u
[1] && (mach
->ExecMask
& 0x2)) {
3467 mach
->LoopMask
&= ~0x2;
3469 if (r
[0].u
[2] && (mach
->ExecMask
& 0x4)) {
3470 mach
->LoopMask
&= ~0x4;
3472 if (r
[0].u
[3] && (mach
->ExecMask
& 0x8)) {
3473 mach
->LoopMask
&= ~0x8;
3475 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3476 UPDATE_EXEC_MASK(mach
);
3479 case TGSI_OPCODE_F2I
:
3480 exec_vector_unary(mach
, inst
, micro_f2i
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
3483 case TGSI_OPCODE_IDIV
:
3484 exec_vector_binary(mach
, inst
, micro_idiv
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3487 case TGSI_OPCODE_IMAX
:
3488 exec_vector_binary(mach
, inst
, micro_imax
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3491 case TGSI_OPCODE_IMIN
:
3492 exec_vector_binary(mach
, inst
, micro_imin
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3495 case TGSI_OPCODE_INEG
:
3496 exec_vector_unary(mach
, inst
, micro_ineg
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3499 case TGSI_OPCODE_ISGE
:
3500 exec_vector_binary(mach
, inst
, micro_isge
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3503 case TGSI_OPCODE_ISHR
:
3504 exec_vector_binary(mach
, inst
, micro_ishr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3507 case TGSI_OPCODE_ISLT
:
3508 exec_vector_binary(mach
, inst
, micro_islt
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3511 case TGSI_OPCODE_F2U
:
3512 exec_vector_unary(mach
, inst
, micro_f2u
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
3515 case TGSI_OPCODE_U2F
:
3516 exec_vector_unary(mach
, inst
, micro_u2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_UINT
);
3519 case TGSI_OPCODE_UADD
:
3520 exec_vector_binary(mach
, inst
, micro_uadd
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3523 case TGSI_OPCODE_UDIV
:
3524 exec_vector_binary(mach
, inst
, micro_udiv
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3527 case TGSI_OPCODE_UMAD
:
3528 exec_vector_trinary(mach
, inst
, micro_umad
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3531 case TGSI_OPCODE_UMAX
:
3532 exec_vector_binary(mach
, inst
, micro_umax
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3535 case TGSI_OPCODE_UMIN
:
3536 exec_vector_binary(mach
, inst
, micro_umin
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3539 case TGSI_OPCODE_UMOD
:
3540 exec_vector_binary(mach
, inst
, micro_umod
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3543 case TGSI_OPCODE_UMUL
:
3544 exec_vector_binary(mach
, inst
, micro_umul
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3547 case TGSI_OPCODE_USEQ
:
3548 exec_vector_binary(mach
, inst
, micro_useq
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3551 case TGSI_OPCODE_USGE
:
3552 exec_vector_binary(mach
, inst
, micro_usge
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3555 case TGSI_OPCODE_USHR
:
3556 exec_vector_binary(mach
, inst
, micro_ushr
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3559 case TGSI_OPCODE_USLT
:
3560 exec_vector_binary(mach
, inst
, micro_uslt
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3563 case TGSI_OPCODE_USNE
:
3564 exec_vector_binary(mach
, inst
, micro_usne
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3567 case TGSI_OPCODE_SWITCH
:
3568 exec_switch(mach
, inst
);
3571 case TGSI_OPCODE_CASE
:
3572 exec_case(mach
, inst
);
3575 case TGSI_OPCODE_DEFAULT
:
3579 case TGSI_OPCODE_ENDSWITCH
:
3580 exec_endswitch(mach
);
3589 #define DEBUG_EXECUTION 0
3593 * Run TGSI interpreter.
3594 * \return bitmask of "alive" quad components
3597 tgsi_exec_machine_run( struct tgsi_exec_machine
*mach
)
3602 mach
->CondMask
= 0xf;
3603 mach
->LoopMask
= 0xf;
3604 mach
->ContMask
= 0xf;
3605 mach
->FuncMask
= 0xf;
3606 mach
->ExecMask
= 0xf;
3608 mach
->Switch
.mask
= 0xf;
3610 assert(mach
->CondStackTop
== 0);
3611 assert(mach
->LoopStackTop
== 0);
3612 assert(mach
->ContStackTop
== 0);
3613 assert(mach
->SwitchStackTop
== 0);
3614 assert(mach
->BreakStackTop
== 0);
3615 assert(mach
->CallStackTop
== 0);
3617 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] = 0;
3618 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] = 0;
3620 if( mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
3621 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0] = 0;
3622 mach
->Primitives
[0] = 0;
3625 for (i
= 0; i
< QUAD_SIZE
; i
++) {
3626 mach
->Temps
[TEMP_CC_I
].xyzw
[TEMP_CC_C
].u
[i
] =
3627 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_X_SHIFT
) |
3628 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Y_SHIFT
) |
3629 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Z_SHIFT
) |
3630 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_W_SHIFT
);
3633 /* execute declarations (interpolants) */
3634 for (i
= 0; i
< mach
->NumDeclarations
; i
++) {
3635 exec_declaration( mach
, mach
->Declarations
+i
);
3640 struct tgsi_exec_vector temps
[TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
];
3641 struct tgsi_exec_vector outputs
[PIPE_MAX_ATTRIBS
];
3644 memcpy(temps
, mach
->Temps
, sizeof(temps
));
3645 memcpy(outputs
, mach
->Outputs
, sizeof(outputs
));
3648 /* execute instructions, until pc is set to -1 */
3654 tgsi_dump_instruction(&mach
->Instructions
[pc
], inst
++);
3657 assert(pc
< (int) mach
->NumInstructions
);
3658 exec_instruction(mach
, mach
->Instructions
+ pc
, &pc
);
3661 for (i
= 0; i
< TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
; i
++) {
3662 if (memcmp(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]))) {
3665 memcpy(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]));
3666 debug_printf("TEMP[%2u] = ", i
);
3667 for (j
= 0; j
< 4; j
++) {
3671 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
3672 temps
[i
].xyzw
[0].f
[j
], temps
[i
].xyzw
[0].u
[j
],
3673 temps
[i
].xyzw
[1].f
[j
], temps
[i
].xyzw
[1].u
[j
],
3674 temps
[i
].xyzw
[2].f
[j
], temps
[i
].xyzw
[2].u
[j
],
3675 temps
[i
].xyzw
[3].f
[j
], temps
[i
].xyzw
[3].u
[j
]);
3679 for (i
= 0; i
< PIPE_MAX_ATTRIBS
; i
++) {
3680 if (memcmp(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]))) {
3683 memcpy(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]));
3684 debug_printf("OUT[%2u] = ", i
);
3685 for (j
= 0; j
< 4; j
++) {
3689 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
3690 outputs
[i
].xyzw
[0].f
[j
], outputs
[i
].xyzw
[0].u
[j
],
3691 outputs
[i
].xyzw
[1].f
[j
], outputs
[i
].xyzw
[1].u
[j
],
3692 outputs
[i
].xyzw
[2].f
[j
], outputs
[i
].xyzw
[2].u
[j
],
3693 outputs
[i
].xyzw
[3].f
[j
], outputs
[i
].xyzw
[3].u
[j
]);
3702 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
3703 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
3705 * Scale back depth component.
3707 for (i
= 0; i
< 4; i
++)
3708 mach
->Outputs
[0].xyzw
[2].f
[i
] *= ctx
->DrawBuffer
->_DepthMaxF
;
3712 assert(mach
->CondStackTop
== 0);
3713 assert(mach
->LoopStackTop
== 0);
3714 assert(mach
->ContStackTop
== 0);
3715 assert(mach
->SwitchStackTop
== 0);
3716 assert(mach
->BreakStackTop
== 0);
3717 assert(mach
->CallStackTop
== 0);
3719 return ~mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];