1 /**************************************************************************
3 * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 * TGSI interpreter/executor.
31 * Flow control information:
33 * Since we operate on 'quads' (4 pixels or 4 vertices in parallel)
34 * flow control statements (IF/ELSE/ENDIF, LOOP/ENDLOOP) require special
35 * care since a condition may be true for some quad components but false
36 * for other components.
38 * We basically execute all statements (even if they're in the part of
39 * an IF/ELSE clause that's "not taken") and use a special mask to
40 * control writing to destination registers. This is the ExecMask.
43 * The ExecMask is computed from three other masks (CondMask, LoopMask and
44 * ContMask) which are controlled by the flow control instructions (namely:
45 * (IF/ELSE/ENDIF, LOOP/ENDLOOP and CONT).
53 #include "pipe/p_compiler.h"
54 #include "pipe/p_state.h"
55 #include "pipe/p_shader_tokens.h"
56 #include "tgsi/tgsi_parse.h"
57 #include "tgsi/tgsi_util.h"
58 #include "tgsi_exec.h"
59 #include "util/u_memory.h"
60 #include "util/u_math.h"
64 #define TILE_TOP_LEFT 0
65 #define TILE_TOP_RIGHT 1
66 #define TILE_BOTTOM_LEFT 2
67 #define TILE_BOTTOM_RIGHT 3
75 * Shorthand locations of various utility registers (_I = Index, _C = Channel)
77 #define TEMP_0_I TGSI_EXEC_TEMP_00000000_I
78 #define TEMP_0_C TGSI_EXEC_TEMP_00000000_C
79 #define TEMP_7F_I TGSI_EXEC_TEMP_7FFFFFFF_I
80 #define TEMP_7F_C TGSI_EXEC_TEMP_7FFFFFFF_C
81 #define TEMP_80_I TGSI_EXEC_TEMP_80000000_I
82 #define TEMP_80_C TGSI_EXEC_TEMP_80000000_C
83 #define TEMP_FF_I TGSI_EXEC_TEMP_FFFFFFFF_I
84 #define TEMP_FF_C TGSI_EXEC_TEMP_FFFFFFFF_C
85 #define TEMP_1_I TGSI_EXEC_TEMP_ONE_I
86 #define TEMP_1_C TGSI_EXEC_TEMP_ONE_C
87 #define TEMP_2_I TGSI_EXEC_TEMP_TWO_I
88 #define TEMP_2_C TGSI_EXEC_TEMP_TWO_C
89 #define TEMP_128_I TGSI_EXEC_TEMP_128_I
90 #define TEMP_128_C TGSI_EXEC_TEMP_128_C
91 #define TEMP_M128_I TGSI_EXEC_TEMP_MINUS_128_I
92 #define TEMP_M128_C TGSI_EXEC_TEMP_MINUS_128_C
93 #define TEMP_KILMASK_I TGSI_EXEC_TEMP_KILMASK_I
94 #define TEMP_KILMASK_C TGSI_EXEC_TEMP_KILMASK_C
95 #define TEMP_OUTPUT_I TGSI_EXEC_TEMP_OUTPUT_I
96 #define TEMP_OUTPUT_C TGSI_EXEC_TEMP_OUTPUT_C
97 #define TEMP_PRIMITIVE_I TGSI_EXEC_TEMP_PRIMITIVE_I
98 #define TEMP_PRIMITIVE_C TGSI_EXEC_TEMP_PRIMITIVE_C
99 #define TEMP_CC_I TGSI_EXEC_TEMP_CC_I
100 #define TEMP_CC_C TGSI_EXEC_TEMP_CC_C
101 #define TEMP_3_I TGSI_EXEC_TEMP_THREE_I
102 #define TEMP_3_C TGSI_EXEC_TEMP_THREE_C
103 #define TEMP_HALF_I TGSI_EXEC_TEMP_HALF_I
104 #define TEMP_HALF_C TGSI_EXEC_TEMP_HALF_C
105 #define TEMP_R0 TGSI_EXEC_TEMP_R0
107 #define IS_CHANNEL_ENABLED(INST, CHAN)\
108 ((INST).FullDstRegisters[0].DstRegister.WriteMask & (1 << (CHAN)))
110 #define IS_CHANNEL_ENABLED2(INST, CHAN)\
111 ((INST).FullDstRegisters[1].DstRegister.WriteMask & (1 << (CHAN)))
113 #define FOR_EACH_ENABLED_CHANNEL(INST, CHAN)\
114 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)\
115 if (IS_CHANNEL_ENABLED( INST, CHAN ))
117 #define FOR_EACH_ENABLED_CHANNEL2(INST, CHAN)\
118 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)\
119 if (IS_CHANNEL_ENABLED2( INST, CHAN ))
122 /** The execution mask depends on the conditional mask and the loop mask */
123 #define UPDATE_EXEC_MASK(MACH) \
124 MACH->ExecMask = MACH->CondMask & MACH->LoopMask & MACH->ContMask & MACH->FuncMask
127 * Initialize machine state by expanding tokens to full instructions,
128 * allocating temporary storage, setting up constants, etc.
129 * After this, we can call tgsi_exec_machine_run() many times.
132 tgsi_exec_machine_bind_shader(
133 struct tgsi_exec_machine
*mach
,
134 const struct tgsi_token
*tokens
,
136 struct tgsi_sampler
**samplers
)
139 struct tgsi_parse_context parse
;
140 struct tgsi_exec_labels
*labels
= &mach
->Labels
;
141 struct tgsi_full_instruction
*instructions
;
142 struct tgsi_full_declaration
*declarations
;
143 uint maxInstructions
= 10, numInstructions
= 0;
144 uint maxDeclarations
= 10, numDeclarations
= 0;
148 tgsi_dump(tokens
, 0);
153 mach
->Tokens
= tokens
;
154 mach
->Samplers
= samplers
;
156 k
= tgsi_parse_init (&parse
, mach
->Tokens
);
157 if (k
!= TGSI_PARSE_OK
) {
158 debug_printf( "Problem parsing!\n" );
162 mach
->Processor
= parse
.FullHeader
.Processor
.Processor
;
166 declarations
= (struct tgsi_full_declaration
*)
167 MALLOC( maxDeclarations
* sizeof(struct tgsi_full_declaration
) );
173 instructions
= (struct tgsi_full_instruction
*)
174 MALLOC( maxInstructions
* sizeof(struct tgsi_full_instruction
) );
177 FREE( declarations
);
181 while( !tgsi_parse_end_of_tokens( &parse
) ) {
182 uint pointer
= parse
.Position
;
185 tgsi_parse_token( &parse
);
186 switch( parse
.FullToken
.Token
.Type
) {
187 case TGSI_TOKEN_TYPE_DECLARATION
:
188 /* save expanded declaration */
189 if (numDeclarations
== maxDeclarations
) {
190 declarations
= REALLOC(declarations
,
192 * sizeof(struct tgsi_full_declaration
),
193 (maxDeclarations
+ 10)
194 * sizeof(struct tgsi_full_declaration
));
195 maxDeclarations
+= 10;
197 memcpy(declarations
+ numDeclarations
,
198 &parse
.FullToken
.FullDeclaration
,
199 sizeof(declarations
[0]));
203 case TGSI_TOKEN_TYPE_IMMEDIATE
:
205 uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
206 assert( size
% 4 == 0 );
207 assert( mach
->ImmLimit
+ size
/ 4 <= TGSI_EXEC_NUM_IMMEDIATES
);
209 for( i
= 0; i
< size
; i
++ ) {
210 mach
->Imms
[mach
->ImmLimit
+ i
/ 4][i
% 4] =
211 parse
.FullToken
.FullImmediate
.u
.ImmediateFloat32
[i
].Float
;
213 mach
->ImmLimit
+= size
/ 4;
217 case TGSI_TOKEN_TYPE_INSTRUCTION
:
218 assert( labels
->count
< MAX_LABELS
);
220 labels
->labels
[labels
->count
][0] = instno
;
221 labels
->labels
[labels
->count
][1] = pointer
;
224 /* save expanded instruction */
225 if (numInstructions
== maxInstructions
) {
226 instructions
= REALLOC(instructions
,
228 * sizeof(struct tgsi_full_instruction
),
229 (maxInstructions
+ 10)
230 * sizeof(struct tgsi_full_instruction
));
231 maxInstructions
+= 10;
233 memcpy(instructions
+ numInstructions
,
234 &parse
.FullToken
.FullInstruction
,
235 sizeof(instructions
[0]));
243 tgsi_parse_free (&parse
);
245 if (mach
->Declarations
) {
246 FREE( mach
->Declarations
);
248 mach
->Declarations
= declarations
;
249 mach
->NumDeclarations
= numDeclarations
;
251 if (mach
->Instructions
) {
252 FREE( mach
->Instructions
);
254 mach
->Instructions
= instructions
;
255 mach
->NumInstructions
= numInstructions
;
260 tgsi_exec_machine_init(
261 struct tgsi_exec_machine
*mach
)
265 mach
->Temps
= (struct tgsi_exec_vector
*) tgsi_align_128bit( mach
->_Temps
);
266 mach
->Addrs
= &mach
->Temps
[TGSI_EXEC_TEMP_ADDR
];
268 /* Setup constants. */
269 for( i
= 0; i
< 4; i
++ ) {
270 mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
].u
[i
] = 0x00000000;
271 mach
->Temps
[TEMP_7F_I
].xyzw
[TEMP_7F_C
].u
[i
] = 0x7FFFFFFF;
272 mach
->Temps
[TEMP_80_I
].xyzw
[TEMP_80_C
].u
[i
] = 0x80000000;
273 mach
->Temps
[TEMP_FF_I
].xyzw
[TEMP_FF_C
].u
[i
] = 0xFFFFFFFF;
274 mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
].f
[i
] = 1.0f
;
275 mach
->Temps
[TEMP_2_I
].xyzw
[TEMP_2_C
].f
[i
] = 2.0f
;
276 mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
].f
[i
] = 128.0f
;
277 mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
].f
[i
] = -128.0f
;
278 mach
->Temps
[TEMP_3_I
].xyzw
[TEMP_3_C
].f
[i
] = 3.0f
;
279 mach
->Temps
[TEMP_HALF_I
].xyzw
[TEMP_HALF_C
].f
[i
] = 0.5f
;
285 tgsi_exec_machine_free_data(struct tgsi_exec_machine
*mach
)
287 if (mach
->Instructions
) {
288 FREE(mach
->Instructions
);
289 mach
->Instructions
= NULL
;
290 mach
->NumInstructions
= 0;
292 if (mach
->Declarations
) {
293 FREE(mach
->Declarations
);
294 mach
->Declarations
= NULL
;
295 mach
->NumDeclarations
= 0;
302 union tgsi_exec_channel
*dst
,
303 const union tgsi_exec_channel
*src
)
305 dst
->f
[0] = fabsf( src
->f
[0] );
306 dst
->f
[1] = fabsf( src
->f
[1] );
307 dst
->f
[2] = fabsf( src
->f
[2] );
308 dst
->f
[3] = fabsf( src
->f
[3] );
313 union tgsi_exec_channel
*dst
,
314 const union tgsi_exec_channel
*src0
,
315 const union tgsi_exec_channel
*src1
)
317 dst
->f
[0] = src0
->f
[0] + src1
->f
[0];
318 dst
->f
[1] = src0
->f
[1] + src1
->f
[1];
319 dst
->f
[2] = src0
->f
[2] + src1
->f
[2];
320 dst
->f
[3] = src0
->f
[3] + src1
->f
[3];
326 union tgsi_exec_channel
*dst
,
327 const union tgsi_exec_channel
*src0
,
328 const union tgsi_exec_channel
*src1
)
330 dst
->i
[0] = src0
->i
[0] + src1
->i
[0];
331 dst
->i
[1] = src0
->i
[1] + src1
->i
[1];
332 dst
->i
[2] = src0
->i
[2] + src1
->i
[2];
333 dst
->i
[3] = src0
->i
[3] + src1
->i
[3];
339 union tgsi_exec_channel
*dst
,
340 const union tgsi_exec_channel
*src0
,
341 const union tgsi_exec_channel
*src1
)
343 dst
->u
[0] = src0
->u
[0] & src1
->u
[0];
344 dst
->u
[1] = src0
->u
[1] & src1
->u
[1];
345 dst
->u
[2] = src0
->u
[2] & src1
->u
[2];
346 dst
->u
[3] = src0
->u
[3] & src1
->u
[3];
351 union tgsi_exec_channel
*dst
,
352 const union tgsi_exec_channel
*src
)
354 dst
->f
[0] = ceilf( src
->f
[0] );
355 dst
->f
[1] = ceilf( src
->f
[1] );
356 dst
->f
[2] = ceilf( src
->f
[2] );
357 dst
->f
[3] = ceilf( src
->f
[3] );
362 union tgsi_exec_channel
*dst
,
363 const union tgsi_exec_channel
*src
)
365 dst
->f
[0] = cosf( src
->f
[0] );
366 dst
->f
[1] = cosf( src
->f
[1] );
367 dst
->f
[2] = cosf( src
->f
[2] );
368 dst
->f
[3] = cosf( src
->f
[3] );
373 union tgsi_exec_channel
*dst
,
374 const union tgsi_exec_channel
*src
)
379 dst
->f
[3] = src
->f
[TILE_BOTTOM_RIGHT
] - src
->f
[TILE_BOTTOM_LEFT
];
384 union tgsi_exec_channel
*dst
,
385 const union tgsi_exec_channel
*src
)
390 dst
->f
[3] = src
->f
[TILE_TOP_LEFT
] - src
->f
[TILE_BOTTOM_LEFT
];
395 union tgsi_exec_channel
*dst
,
396 const union tgsi_exec_channel
*src0
,
397 const union tgsi_exec_channel
*src1
)
399 if (src1
->f
[0] != 0) {
400 dst
->f
[0] = src0
->f
[0] / src1
->f
[0];
402 if (src1
->f
[1] != 0) {
403 dst
->f
[1] = src0
->f
[1] / src1
->f
[1];
405 if (src1
->f
[2] != 0) {
406 dst
->f
[2] = src0
->f
[2] / src1
->f
[2];
408 if (src1
->f
[3] != 0) {
409 dst
->f
[3] = src0
->f
[3] / src1
->f
[3];
416 union tgsi_exec_channel
*dst
,
417 const union tgsi_exec_channel
*src0
,
418 const union tgsi_exec_channel
*src1
)
420 dst
->u
[0] = src0
->u
[0] / src1
->u
[0];
421 dst
->u
[1] = src0
->u
[1] / src1
->u
[1];
422 dst
->u
[2] = src0
->u
[2] / src1
->u
[2];
423 dst
->u
[3] = src0
->u
[3] / src1
->u
[3];
429 union tgsi_exec_channel
*dst
,
430 const union tgsi_exec_channel
*src0
,
431 const union tgsi_exec_channel
*src1
,
432 const union tgsi_exec_channel
*src2
,
433 const union tgsi_exec_channel
*src3
)
435 dst
->f
[0] = src0
->f
[0] == src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
436 dst
->f
[1] = src0
->f
[1] == src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
437 dst
->f
[2] = src0
->f
[2] == src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
438 dst
->f
[3] = src0
->f
[3] == src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
444 union tgsi_exec_channel
*dst
,
445 const union tgsi_exec_channel
*src0
,
446 const union tgsi_exec_channel
*src1
,
447 const union tgsi_exec_channel
*src2
,
448 const union tgsi_exec_channel
*src3
)
450 dst
->i
[0] = src0
->i
[0] == src1
->i
[0] ? src2
->i
[0] : src3
->i
[0];
451 dst
->i
[1] = src0
->i
[1] == src1
->i
[1] ? src2
->i
[1] : src3
->i
[1];
452 dst
->i
[2] = src0
->i
[2] == src1
->i
[2] ? src2
->i
[2] : src3
->i
[2];
453 dst
->i
[3] = src0
->i
[3] == src1
->i
[3] ? src2
->i
[3] : src3
->i
[3];
459 union tgsi_exec_channel
*dst
,
460 const union tgsi_exec_channel
*src
)
463 dst
->f
[0] = util_fast_exp2( src
->f
[0] );
464 dst
->f
[1] = util_fast_exp2( src
->f
[1] );
465 dst
->f
[2] = util_fast_exp2( src
->f
[2] );
466 dst
->f
[3] = util_fast_exp2( src
->f
[3] );
468 dst
->f
[0] = powf( 2.0f
, src
->f
[0] );
469 dst
->f
[1] = powf( 2.0f
, src
->f
[1] );
470 dst
->f
[2] = powf( 2.0f
, src
->f
[2] );
471 dst
->f
[3] = powf( 2.0f
, src
->f
[3] );
478 union tgsi_exec_channel
*dst
,
479 const union tgsi_exec_channel
*src
)
481 dst
->u
[0] = (uint
) src
->f
[0];
482 dst
->u
[1] = (uint
) src
->f
[1];
483 dst
->u
[2] = (uint
) src
->f
[2];
484 dst
->u
[3] = (uint
) src
->f
[3];
490 union tgsi_exec_channel
*dst
,
491 const union tgsi_exec_channel
*src
)
493 dst
->f
[0] = floorf( src
->f
[0] );
494 dst
->f
[1] = floorf( src
->f
[1] );
495 dst
->f
[2] = floorf( src
->f
[2] );
496 dst
->f
[3] = floorf( src
->f
[3] );
501 union tgsi_exec_channel
*dst
,
502 const union tgsi_exec_channel
*src
)
504 dst
->f
[0] = src
->f
[0] - floorf( src
->f
[0] );
505 dst
->f
[1] = src
->f
[1] - floorf( src
->f
[1] );
506 dst
->f
[2] = src
->f
[2] - floorf( src
->f
[2] );
507 dst
->f
[3] = src
->f
[3] - floorf( src
->f
[3] );
512 union tgsi_exec_channel
*dst
,
513 const union tgsi_exec_channel
*src0
,
514 const union tgsi_exec_channel
*src1
,
515 const union tgsi_exec_channel
*src2
,
516 const union tgsi_exec_channel
*src3
)
518 dst
->f
[0] = src0
->f
[0] >= src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
519 dst
->f
[1] = src0
->f
[1] >= src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
520 dst
->f
[2] = src0
->f
[2] >= src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
521 dst
->f
[3] = src0
->f
[3] >= src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
526 union tgsi_exec_channel
*dst
,
527 const union tgsi_exec_channel
*src
)
529 dst
->f
[0] = (float) src
->i
[0];
530 dst
->f
[1] = (float) src
->i
[1];
531 dst
->f
[2] = (float) src
->i
[2];
532 dst
->f
[3] = (float) src
->i
[3];
537 union tgsi_exec_channel
*dst
,
538 const union tgsi_exec_channel
*src
)
541 dst
->f
[0] = util_fast_log2( src
->f
[0] );
542 dst
->f
[1] = util_fast_log2( src
->f
[1] );
543 dst
->f
[2] = util_fast_log2( src
->f
[2] );
544 dst
->f
[3] = util_fast_log2( src
->f
[3] );
546 dst
->f
[0] = logf( src
->f
[0] ) * 1.442695f
;
547 dst
->f
[1] = logf( src
->f
[1] ) * 1.442695f
;
548 dst
->f
[2] = logf( src
->f
[2] ) * 1.442695f
;
549 dst
->f
[3] = logf( src
->f
[3] ) * 1.442695f
;
555 union tgsi_exec_channel
*dst
,
556 const union tgsi_exec_channel
*src0
,
557 const union tgsi_exec_channel
*src1
,
558 const union tgsi_exec_channel
*src2
,
559 const union tgsi_exec_channel
*src3
)
561 dst
->f
[0] = src0
->f
[0] <= src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
562 dst
->f
[1] = src0
->f
[1] <= src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
563 dst
->f
[2] = src0
->f
[2] <= src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
564 dst
->f
[3] = src0
->f
[3] <= src1
->f
[3] ? src2
->f
[3] : src3
->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];
584 union tgsi_exec_channel
*dst
,
585 const union tgsi_exec_channel
*src0
,
586 const union tgsi_exec_channel
*src1
,
587 const union tgsi_exec_channel
*src2
,
588 const union tgsi_exec_channel
*src3
)
590 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? src2
->i
[0] : src3
->i
[0];
591 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? src2
->i
[1] : src3
->i
[1];
592 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? src2
->i
[2] : src3
->i
[2];
593 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? src2
->i
[3] : src3
->i
[3];
600 union tgsi_exec_channel
*dst
,
601 const union tgsi_exec_channel
*src0
,
602 const union tgsi_exec_channel
*src1
,
603 const union tgsi_exec_channel
*src2
,
604 const union tgsi_exec_channel
*src3
)
606 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? src2
->u
[0] : src3
->u
[0];
607 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? src2
->u
[1] : src3
->u
[1];
608 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? src2
->u
[2] : src3
->u
[2];
609 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? src2
->u
[3] : src3
->u
[3];
615 union tgsi_exec_channel
*dst
,
616 const union tgsi_exec_channel
*src0
,
617 const union tgsi_exec_channel
*src1
)
619 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
620 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
621 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
622 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
628 union tgsi_exec_channel
*dst
,
629 const union tgsi_exec_channel
*src0
,
630 const union tgsi_exec_channel
*src1
)
632 dst
->i
[0] = src0
->i
[0] > src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
633 dst
->i
[1] = src0
->i
[1] > src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
634 dst
->i
[2] = src0
->i
[2] > src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
635 dst
->i
[3] = src0
->i
[3] > src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
642 union tgsi_exec_channel
*dst
,
643 const union tgsi_exec_channel
*src0
,
644 const union tgsi_exec_channel
*src1
)
646 dst
->u
[0] = src0
->u
[0] > src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
647 dst
->u
[1] = src0
->u
[1] > src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
648 dst
->u
[2] = src0
->u
[2] > src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
649 dst
->u
[3] = src0
->u
[3] > src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
655 union tgsi_exec_channel
*dst
,
656 const union tgsi_exec_channel
*src0
,
657 const union tgsi_exec_channel
*src1
)
659 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
660 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
661 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
662 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
668 union tgsi_exec_channel
*dst
,
669 const union tgsi_exec_channel
*src0
,
670 const union tgsi_exec_channel
*src1
)
672 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
673 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
674 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
675 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
682 union tgsi_exec_channel
*dst
,
683 const union tgsi_exec_channel
*src0
,
684 const union tgsi_exec_channel
*src1
)
686 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
687 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
688 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
689 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
696 union tgsi_exec_channel
*dst
,
697 const union tgsi_exec_channel
*src0
,
698 const union tgsi_exec_channel
*src1
)
700 dst
->u
[0] = src0
->u
[0] % src1
->u
[0];
701 dst
->u
[1] = src0
->u
[1] % src1
->u
[1];
702 dst
->u
[2] = src0
->u
[2] % src1
->u
[2];
703 dst
->u
[3] = src0
->u
[3] % src1
->u
[3];
709 union tgsi_exec_channel
*dst
,
710 const union tgsi_exec_channel
*src0
,
711 const union tgsi_exec_channel
*src1
)
713 dst
->f
[0] = src0
->f
[0] * src1
->f
[0];
714 dst
->f
[1] = src0
->f
[1] * src1
->f
[1];
715 dst
->f
[2] = src0
->f
[2] * src1
->f
[2];
716 dst
->f
[3] = src0
->f
[3] * src1
->f
[3];
722 union tgsi_exec_channel
*dst
,
723 const union tgsi_exec_channel
*src0
,
724 const union tgsi_exec_channel
*src1
)
726 dst
->i
[0] = src0
->i
[0] * src1
->i
[0];
727 dst
->i
[1] = src0
->i
[1] * src1
->i
[1];
728 dst
->i
[2] = src0
->i
[2] * src1
->i
[2];
729 dst
->i
[3] = src0
->i
[3] * src1
->i
[3];
736 union tgsi_exec_channel
*dst0
,
737 union tgsi_exec_channel
*dst1
,
738 const union tgsi_exec_channel
*src0
,
739 const union tgsi_exec_channel
*src1
)
741 dst1
->i
[0] = src0
->i
[0] * src1
->i
[0];
742 dst1
->i
[1] = src0
->i
[1] * src1
->i
[1];
743 dst1
->i
[2] = src0
->i
[2] * src1
->i
[2];
744 dst1
->i
[3] = src0
->i
[3] * src1
->i
[3];
755 union tgsi_exec_channel
*dst0
,
756 union tgsi_exec_channel
*dst1
,
757 const union tgsi_exec_channel
*src0
,
758 const union tgsi_exec_channel
*src1
)
760 dst1
->u
[0] = src0
->u
[0] * src1
->u
[0];
761 dst1
->u
[1] = src0
->u
[1] * src1
->u
[1];
762 dst1
->u
[2] = src0
->u
[2] * src1
->u
[2];
763 dst1
->u
[3] = src0
->u
[3] * src1
->u
[3];
775 union tgsi_exec_channel
*dst
,
776 const union tgsi_exec_channel
*src0
,
777 const union tgsi_exec_channel
*src1
,
778 const union tgsi_exec_channel
*src2
)
780 dst
->u
[0] = src0
->u
[0] ? src1
->u
[0] : src2
->u
[0];
781 dst
->u
[1] = src0
->u
[1] ? src1
->u
[1] : src2
->u
[1];
782 dst
->u
[2] = src0
->u
[2] ? src1
->u
[2] : src2
->u
[2];
783 dst
->u
[3] = src0
->u
[3] ? src1
->u
[3] : src2
->u
[3];
789 union tgsi_exec_channel
*dst
,
790 const union tgsi_exec_channel
*src
)
792 dst
->f
[0] = -src
->f
[0];
793 dst
->f
[1] = -src
->f
[1];
794 dst
->f
[2] = -src
->f
[2];
795 dst
->f
[3] = -src
->f
[3];
801 union tgsi_exec_channel
*dst
,
802 const union tgsi_exec_channel
*src
)
804 dst
->i
[0] = -src
->i
[0];
805 dst
->i
[1] = -src
->i
[1];
806 dst
->i
[2] = -src
->i
[2];
807 dst
->i
[3] = -src
->i
[3];
813 union tgsi_exec_channel
*dst
,
814 const union tgsi_exec_channel
*src
)
816 dst
->u
[0] = ~src
->u
[0];
817 dst
->u
[1] = ~src
->u
[1];
818 dst
->u
[2] = ~src
->u
[2];
819 dst
->u
[3] = ~src
->u
[3];
824 union tgsi_exec_channel
*dst
,
825 const union tgsi_exec_channel
*src0
,
826 const union tgsi_exec_channel
*src1
)
828 dst
->u
[0] = src0
->u
[0] | src1
->u
[0];
829 dst
->u
[1] = src0
->u
[1] | src1
->u
[1];
830 dst
->u
[2] = src0
->u
[2] | src1
->u
[2];
831 dst
->u
[3] = src0
->u
[3] | src1
->u
[3];
836 union tgsi_exec_channel
*dst
,
837 const union tgsi_exec_channel
*src0
,
838 const union tgsi_exec_channel
*src1
)
841 dst
->f
[0] = util_fast_pow( src0
->f
[0], src1
->f
[0] );
842 dst
->f
[1] = util_fast_pow( src0
->f
[1], src1
->f
[1] );
843 dst
->f
[2] = util_fast_pow( src0
->f
[2], src1
->f
[2] );
844 dst
->f
[3] = util_fast_pow( src0
->f
[3], src1
->f
[3] );
846 dst
->f
[0] = powf( src0
->f
[0], src1
->f
[0] );
847 dst
->f
[1] = powf( src0
->f
[1], src1
->f
[1] );
848 dst
->f
[2] = powf( src0
->f
[2], src1
->f
[2] );
849 dst
->f
[3] = powf( src0
->f
[3], src1
->f
[3] );
855 union tgsi_exec_channel
*dst
,
856 const union tgsi_exec_channel
*src
)
858 dst
->f
[0] = floorf( src
->f
[0] + 0.5f
);
859 dst
->f
[1] = floorf( src
->f
[1] + 0.5f
);
860 dst
->f
[2] = floorf( src
->f
[2] + 0.5f
);
861 dst
->f
[3] = floorf( src
->f
[3] + 0.5f
);
866 union tgsi_exec_channel
*dst
,
867 const union tgsi_exec_channel
*src
)
869 dst
->f
[0] = src
->f
[0] < 0.0f
? -1.0f
: src
->f
[0] > 0.0f
? 1.0f
: 0.0f
;
870 dst
->f
[1] = src
->f
[1] < 0.0f
? -1.0f
: src
->f
[1] > 0.0f
? 1.0f
: 0.0f
;
871 dst
->f
[2] = src
->f
[2] < 0.0f
? -1.0f
: src
->f
[2] > 0.0f
? 1.0f
: 0.0f
;
872 dst
->f
[3] = src
->f
[3] < 0.0f
? -1.0f
: src
->f
[3] > 0.0f
? 1.0f
: 0.0f
;
877 union tgsi_exec_channel
*dst
,
878 const union tgsi_exec_channel
*src0
,
879 const union tgsi_exec_channel
*src1
)
881 dst
->i
[0] = src0
->i
[0] << src1
->i
[0];
882 dst
->i
[1] = src0
->i
[1] << src1
->i
[1];
883 dst
->i
[2] = src0
->i
[2] << src1
->i
[2];
884 dst
->i
[3] = src0
->i
[3] << src1
->i
[3];
889 union tgsi_exec_channel
*dst
,
890 const union tgsi_exec_channel
*src0
,
891 const union tgsi_exec_channel
*src1
)
893 dst
->i
[0] = src0
->i
[0] >> src1
->i
[0];
894 dst
->i
[1] = src0
->i
[1] >> src1
->i
[1];
895 dst
->i
[2] = src0
->i
[2] >> src1
->i
[2];
896 dst
->i
[3] = src0
->i
[3] >> src1
->i
[3];
901 union tgsi_exec_channel
*dst
,
902 const union tgsi_exec_channel
*src0
)
904 dst
->f
[0] = (float) (int) src0
->f
[0];
905 dst
->f
[1] = (float) (int) src0
->f
[1];
906 dst
->f
[2] = (float) (int) src0
->f
[2];
907 dst
->f
[3] = (float) (int) src0
->f
[3];
913 union tgsi_exec_channel
*dst
,
914 const union tgsi_exec_channel
*src0
,
915 const union tgsi_exec_channel
*src1
)
917 dst
->u
[0] = src0
->u
[0] >> src1
->u
[0];
918 dst
->u
[1] = src0
->u
[1] >> src1
->u
[1];
919 dst
->u
[2] = src0
->u
[2] >> src1
->u
[2];
920 dst
->u
[3] = src0
->u
[3] >> src1
->u
[3];
926 union tgsi_exec_channel
*dst
,
927 const union tgsi_exec_channel
*src
)
929 dst
->f
[0] = sinf( src
->f
[0] );
930 dst
->f
[1] = sinf( src
->f
[1] );
931 dst
->f
[2] = sinf( src
->f
[2] );
932 dst
->f
[3] = sinf( src
->f
[3] );
936 micro_sqrt( union tgsi_exec_channel
*dst
,
937 const union tgsi_exec_channel
*src
)
939 dst
->f
[0] = sqrtf( src
->f
[0] );
940 dst
->f
[1] = sqrtf( src
->f
[1] );
941 dst
->f
[2] = sqrtf( src
->f
[2] );
942 dst
->f
[3] = sqrtf( src
->f
[3] );
947 union tgsi_exec_channel
*dst
,
948 const union tgsi_exec_channel
*src0
,
949 const union tgsi_exec_channel
*src1
)
951 dst
->f
[0] = src0
->f
[0] - src1
->f
[0];
952 dst
->f
[1] = src0
->f
[1] - src1
->f
[1];
953 dst
->f
[2] = src0
->f
[2] - src1
->f
[2];
954 dst
->f
[3] = src0
->f
[3] - src1
->f
[3];
960 union tgsi_exec_channel
*dst
,
961 const union tgsi_exec_channel
*src
)
963 dst
->f
[0] = (float) src
->u
[0];
964 dst
->f
[1] = (float) src
->u
[1];
965 dst
->f
[2] = (float) src
->u
[2];
966 dst
->f
[3] = (float) src
->u
[3];
972 union tgsi_exec_channel
*dst
,
973 const union tgsi_exec_channel
*src0
,
974 const union tgsi_exec_channel
*src1
)
976 dst
->u
[0] = src0
->u
[0] ^ src1
->u
[0];
977 dst
->u
[1] = src0
->u
[1] ^ src1
->u
[1];
978 dst
->u
[2] = src0
->u
[2] ^ src1
->u
[2];
979 dst
->u
[3] = src0
->u
[3] ^ src1
->u
[3];
983 fetch_src_file_channel(
984 const struct tgsi_exec_machine
*mach
,
987 const union tgsi_exec_channel
*index
,
988 union tgsi_exec_channel
*chan
)
991 case TGSI_EXTSWIZZLE_X
:
992 case TGSI_EXTSWIZZLE_Y
:
993 case TGSI_EXTSWIZZLE_Z
:
994 case TGSI_EXTSWIZZLE_W
:
996 case TGSI_FILE_CONSTANT
:
997 assert(mach
->Consts
);
1001 chan
->f
[0] = mach
->Consts
[index
->i
[0]][swizzle
];
1002 if (index
->i
[1] < 0)
1005 chan
->f
[1] = mach
->Consts
[index
->i
[1]][swizzle
];
1006 if (index
->i
[2] < 0)
1009 chan
->f
[2] = mach
->Consts
[index
->i
[2]][swizzle
];
1010 if (index
->i
[3] < 0)
1013 chan
->f
[3] = mach
->Consts
[index
->i
[3]][swizzle
];
1016 case TGSI_FILE_INPUT
:
1017 chan
->u
[0] = mach
->Inputs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1018 chan
->u
[1] = mach
->Inputs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1019 chan
->u
[2] = mach
->Inputs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1020 chan
->u
[3] = mach
->Inputs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1023 case TGSI_FILE_TEMPORARY
:
1024 assert(index
->i
[0] < TGSI_EXEC_NUM_TEMPS
);
1025 chan
->u
[0] = mach
->Temps
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1026 chan
->u
[1] = mach
->Temps
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1027 chan
->u
[2] = mach
->Temps
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1028 chan
->u
[3] = mach
->Temps
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1031 case TGSI_FILE_IMMEDIATE
:
1032 assert( index
->i
[0] < (int) mach
->ImmLimit
);
1033 chan
->f
[0] = mach
->Imms
[index
->i
[0]][swizzle
];
1034 assert( index
->i
[1] < (int) mach
->ImmLimit
);
1035 chan
->f
[1] = mach
->Imms
[index
->i
[1]][swizzle
];
1036 assert( index
->i
[2] < (int) mach
->ImmLimit
);
1037 chan
->f
[2] = mach
->Imms
[index
->i
[2]][swizzle
];
1038 assert( index
->i
[3] < (int) mach
->ImmLimit
);
1039 chan
->f
[3] = mach
->Imms
[index
->i
[3]][swizzle
];
1042 case TGSI_FILE_ADDRESS
:
1043 chan
->u
[0] = mach
->Addrs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1044 chan
->u
[1] = mach
->Addrs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1045 chan
->u
[2] = mach
->Addrs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1046 chan
->u
[3] = mach
->Addrs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1049 case TGSI_FILE_OUTPUT
:
1050 /* vertex/fragment output vars can be read too */
1051 chan
->u
[0] = mach
->Outputs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1052 chan
->u
[1] = mach
->Outputs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1053 chan
->u
[2] = mach
->Outputs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1054 chan
->u
[3] = mach
->Outputs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1062 case TGSI_EXTSWIZZLE_ZERO
:
1063 *chan
= mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
];
1066 case TGSI_EXTSWIZZLE_ONE
:
1067 *chan
= mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
];
1077 const struct tgsi_exec_machine
*mach
,
1078 union tgsi_exec_channel
*chan
,
1079 const struct tgsi_full_src_register
*reg
,
1080 const uint chan_index
)
1082 union tgsi_exec_channel index
;
1085 /* We start with a direct index into a register file.
1089 * file = SrcRegister.File
1090 * [1] = SrcRegister.Index
1095 index
.i
[3] = reg
->SrcRegister
.Index
;
1097 /* There is an extra source register that indirectly subscripts
1098 * a register file. The direct index now becomes an offset
1099 * that is being added to the indirect register.
1103 * ind = SrcRegisterInd.File
1104 * [2] = SrcRegisterInd.Index
1105 * .x = SrcRegisterInd.SwizzleX
1107 if (reg
->SrcRegister
.Indirect
) {
1108 union tgsi_exec_channel index2
;
1109 union tgsi_exec_channel indir_index
;
1110 const uint execmask
= mach
->ExecMask
;
1113 /* which address register (always zero now) */
1117 index2
.i
[3] = reg
->SrcRegisterInd
.Index
;
1119 /* get current value of address register[swizzle] */
1120 swizzle
= tgsi_util_get_src_register_swizzle( ®
->SrcRegisterInd
, CHAN_X
);
1121 fetch_src_file_channel(
1123 reg
->SrcRegisterInd
.File
,
1128 /* add value of address register to the offset */
1129 index
.i
[0] += (int) indir_index
.f
[0];
1130 index
.i
[1] += (int) indir_index
.f
[1];
1131 index
.i
[2] += (int) indir_index
.f
[2];
1132 index
.i
[3] += (int) indir_index
.f
[3];
1134 /* for disabled execution channels, zero-out the index to
1135 * avoid using a potential garbage value.
1137 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1138 if ((execmask
& (1 << i
)) == 0)
1143 /* There is an extra source register that is a second
1144 * subscript to a register file. Effectively it means that
1145 * the register file is actually a 2D array of registers.
1147 * file[1][3] == file[1*sizeof(file[1])+3],
1149 * [3] = SrcRegisterDim.Index
1151 if (reg
->SrcRegister
.Dimension
) {
1152 /* The size of the first-order array depends on the register file type.
1153 * We need to multiply the index to the first array to get an effective,
1154 * "flat" index that points to the beginning of the second-order array.
1156 switch (reg
->SrcRegister
.File
) {
1157 case TGSI_FILE_INPUT
:
1158 index
.i
[0] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1159 index
.i
[1] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1160 index
.i
[2] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1161 index
.i
[3] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1163 case TGSI_FILE_CONSTANT
:
1164 index
.i
[0] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1165 index
.i
[1] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1166 index
.i
[2] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1167 index
.i
[3] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1173 index
.i
[0] += reg
->SrcRegisterDim
.Index
;
1174 index
.i
[1] += reg
->SrcRegisterDim
.Index
;
1175 index
.i
[2] += reg
->SrcRegisterDim
.Index
;
1176 index
.i
[3] += reg
->SrcRegisterDim
.Index
;
1178 /* Again, the second subscript index can be addressed indirectly
1179 * identically to the first one.
1180 * Nothing stops us from indirectly addressing the indirect register,
1181 * but there is no need for that, so we won't exercise it.
1183 * file[1][ind[4].y+3],
1185 * ind = SrcRegisterDimInd.File
1186 * [4] = SrcRegisterDimInd.Index
1187 * .y = SrcRegisterDimInd.SwizzleX
1189 if (reg
->SrcRegisterDim
.Indirect
) {
1190 union tgsi_exec_channel index2
;
1191 union tgsi_exec_channel indir_index
;
1192 const uint execmask
= mach
->ExecMask
;
1198 index2
.i
[3] = reg
->SrcRegisterDimInd
.Index
;
1200 swizzle
= tgsi_util_get_src_register_swizzle( ®
->SrcRegisterDimInd
, CHAN_X
);
1201 fetch_src_file_channel(
1203 reg
->SrcRegisterDimInd
.File
,
1208 index
.i
[0] += (int) indir_index
.f
[0];
1209 index
.i
[1] += (int) indir_index
.f
[1];
1210 index
.i
[2] += (int) indir_index
.f
[2];
1211 index
.i
[3] += (int) indir_index
.f
[3];
1213 /* for disabled execution channels, zero-out the index to
1214 * avoid using a potential garbage value.
1216 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1217 if ((execmask
& (1 << i
)) == 0)
1222 /* If by any chance there was a need for a 3D array of register
1223 * files, we would have to check whether SrcRegisterDim is followed
1224 * by a dimension register and continue the saga.
1228 swizzle
= tgsi_util_get_full_src_register_extswizzle( reg
, chan_index
);
1229 fetch_src_file_channel(
1231 reg
->SrcRegister
.File
,
1236 switch (tgsi_util_get_full_src_register_sign_mode( reg
, chan_index
)) {
1237 case TGSI_UTIL_SIGN_CLEAR
:
1238 micro_abs( chan
, chan
);
1241 case TGSI_UTIL_SIGN_SET
:
1242 micro_abs( chan
, chan
);
1243 micro_neg( chan
, chan
);
1246 case TGSI_UTIL_SIGN_TOGGLE
:
1247 micro_neg( chan
, chan
);
1250 case TGSI_UTIL_SIGN_KEEP
:
1254 if (reg
->SrcRegisterExtMod
.Complement
) {
1255 micro_sub( chan
, &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], chan
);
1261 struct tgsi_exec_machine
*mach
,
1262 const union tgsi_exec_channel
*chan
,
1263 const struct tgsi_full_dst_register
*reg
,
1264 const struct tgsi_full_instruction
*inst
,
1268 union tgsi_exec_channel null
;
1269 union tgsi_exec_channel
*dst
;
1270 uint execmask
= mach
->ExecMask
;
1272 switch (reg
->DstRegister
.File
) {
1273 case TGSI_FILE_NULL
:
1277 case TGSI_FILE_OUTPUT
:
1278 dst
= &mach
->Outputs
[mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0]
1279 + reg
->DstRegister
.Index
].xyzw
[chan_index
];
1282 case TGSI_FILE_TEMPORARY
:
1283 assert( reg
->DstRegister
.Index
< TGSI_EXEC_NUM_TEMPS
);
1284 dst
= &mach
->Temps
[reg
->DstRegister
.Index
].xyzw
[chan_index
];
1287 case TGSI_FILE_ADDRESS
:
1288 dst
= &mach
->Addrs
[reg
->DstRegister
.Index
].xyzw
[chan_index
];
1296 if (inst
->InstructionExtNv
.CondFlowEnable
) {
1297 union tgsi_exec_channel
*cc
= &mach
->Temps
[TEMP_CC_I
].xyzw
[TEMP_CC_C
];
1303 /* Only CC0 supported.
1305 assert( inst
->InstructionExtNv
.CondFlowIndex
< 1 );
1307 switch (chan_index
) {
1309 swizzle
= inst
->InstructionExtNv
.CondSwizzleX
;
1312 swizzle
= inst
->InstructionExtNv
.CondSwizzleY
;
1315 swizzle
= inst
->InstructionExtNv
.CondSwizzleZ
;
1318 swizzle
= inst
->InstructionExtNv
.CondSwizzleW
;
1326 case TGSI_SWIZZLE_X
:
1327 shift
= TGSI_EXEC_CC_X_SHIFT
;
1328 mask
= TGSI_EXEC_CC_X_MASK
;
1330 case TGSI_SWIZZLE_Y
:
1331 shift
= TGSI_EXEC_CC_Y_SHIFT
;
1332 mask
= TGSI_EXEC_CC_Y_MASK
;
1334 case TGSI_SWIZZLE_Z
:
1335 shift
= TGSI_EXEC_CC_Z_SHIFT
;
1336 mask
= TGSI_EXEC_CC_Z_MASK
;
1338 case TGSI_SWIZZLE_W
:
1339 shift
= TGSI_EXEC_CC_W_SHIFT
;
1340 mask
= TGSI_EXEC_CC_W_MASK
;
1347 switch (inst
->InstructionExtNv
.CondMask
) {
1349 test
= ~(TGSI_EXEC_CC_GT
<< shift
) & mask
;
1350 for (i
= 0; i
< QUAD_SIZE
; i
++)
1351 if (cc
->u
[i
] & test
)
1352 execmask
&= ~(1 << i
);
1356 test
= ~(TGSI_EXEC_CC_EQ
<< shift
) & mask
;
1357 for (i
= 0; i
< QUAD_SIZE
; i
++)
1358 if (cc
->u
[i
] & test
)
1359 execmask
&= ~(1 << i
);
1363 test
= ~(TGSI_EXEC_CC_LT
<< shift
) & mask
;
1364 for (i
= 0; i
< QUAD_SIZE
; i
++)
1365 if (cc
->u
[i
] & test
)
1366 execmask
&= ~(1 << i
);
1370 test
= ~((TGSI_EXEC_CC_GT
| TGSI_EXEC_CC_EQ
) << shift
) & mask
;
1371 for (i
= 0; i
< QUAD_SIZE
; i
++)
1372 if (cc
->u
[i
] & test
)
1373 execmask
&= ~(1 << i
);
1377 test
= ~((TGSI_EXEC_CC_LT
| TGSI_EXEC_CC_EQ
) << shift
) & mask
;
1378 for (i
= 0; i
< QUAD_SIZE
; i
++)
1379 if (cc
->u
[i
] & test
)
1380 execmask
&= ~(1 << i
);
1384 test
= ~((TGSI_EXEC_CC_GT
| TGSI_EXEC_CC_LT
| TGSI_EXEC_CC_UN
) << shift
) & mask
;
1385 for (i
= 0; i
< QUAD_SIZE
; i
++)
1386 if (cc
->u
[i
] & test
)
1387 execmask
&= ~(1 << i
);
1394 for (i
= 0; i
< QUAD_SIZE
; i
++)
1395 execmask
&= ~(1 << i
);
1404 switch (inst
->Instruction
.Saturate
) {
1406 for (i
= 0; i
< QUAD_SIZE
; i
++)
1407 if (execmask
& (1 << i
))
1408 dst
->i
[i
] = chan
->i
[i
];
1411 case TGSI_SAT_ZERO_ONE
:
1412 for (i
= 0; i
< QUAD_SIZE
; i
++)
1413 if (execmask
& (1 << i
)) {
1414 if (chan
->f
[i
] < 0.0f
)
1416 else if (chan
->f
[i
] > 1.0f
)
1419 dst
->i
[i
] = chan
->i
[i
];
1423 case TGSI_SAT_MINUS_PLUS_ONE
:
1424 for (i
= 0; i
< QUAD_SIZE
; i
++)
1425 if (execmask
& (1 << i
)) {
1426 if (chan
->f
[i
] < -1.0f
)
1428 else if (chan
->f
[i
] > 1.0f
)
1431 dst
->i
[i
] = chan
->i
[i
];
1439 if (inst
->InstructionExtNv
.CondDstUpdate
) {
1440 union tgsi_exec_channel
*cc
= &mach
->Temps
[TEMP_CC_I
].xyzw
[TEMP_CC_C
];
1444 /* Only CC0 supported.
1446 assert( inst
->InstructionExtNv
.CondDstIndex
< 1 );
1448 switch (chan_index
) {
1450 shift
= TGSI_EXEC_CC_X_SHIFT
;
1451 mask
= ~TGSI_EXEC_CC_X_MASK
;
1454 shift
= TGSI_EXEC_CC_Y_SHIFT
;
1455 mask
= ~TGSI_EXEC_CC_Y_MASK
;
1458 shift
= TGSI_EXEC_CC_Z_SHIFT
;
1459 mask
= ~TGSI_EXEC_CC_Z_MASK
;
1462 shift
= TGSI_EXEC_CC_W_SHIFT
;
1463 mask
= ~TGSI_EXEC_CC_W_MASK
;
1470 for (i
= 0; i
< QUAD_SIZE
; i
++)
1471 if (execmask
& (1 << i
)) {
1473 if (dst
->f
[i
] < 0.0f
)
1474 cc
->u
[i
] |= TGSI_EXEC_CC_LT
<< shift
;
1475 else if (dst
->f
[i
] > 0.0f
)
1476 cc
->u
[i
] |= TGSI_EXEC_CC_GT
<< shift
;
1477 else if (dst
->f
[i
] == 0.0f
)
1478 cc
->u
[i
] |= TGSI_EXEC_CC_EQ
<< shift
;
1480 cc
->u
[i
] |= TGSI_EXEC_CC_UN
<< shift
;
1485 #define FETCH(VAL,INDEX,CHAN)\
1486 fetch_source (mach, VAL, &inst->FullSrcRegisters[INDEX], CHAN)
1488 #define STORE(VAL,INDEX,CHAN)\
1489 store_dest (mach, VAL, &inst->FullDstRegisters[INDEX], inst, CHAN )
1493 * Execute ARB-style KIL which is predicated by a src register.
1494 * Kill fragment if any of the four values is less than zero.
1497 exec_kil(struct tgsi_exec_machine
*mach
,
1498 const struct tgsi_full_instruction
*inst
)
1502 uint kilmask
= 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1503 union tgsi_exec_channel r
[1];
1505 /* This mask stores component bits that were already tested. Note that
1506 * we test if the value is less than zero, so 1.0 and 0.0 need not to be
1508 uniquemask
= (1 << TGSI_EXTSWIZZLE_ZERO
) | (1 << TGSI_EXTSWIZZLE_ONE
);
1510 for (chan_index
= 0; chan_index
< 4; chan_index
++)
1515 /* unswizzle channel */
1516 swizzle
= tgsi_util_get_full_src_register_extswizzle (
1517 &inst
->FullSrcRegisters
[0],
1520 /* check if the component has not been already tested */
1521 if (uniquemask
& (1 << swizzle
))
1523 uniquemask
|= 1 << swizzle
;
1525 FETCH(&r
[0], 0, chan_index
);
1526 for (i
= 0; i
< 4; i
++)
1527 if (r
[0].f
[i
] < 0.0f
)
1531 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1535 * Execute NVIDIA-style KIL which is predicated by a condition code.
1536 * Kill fragment if the condition code is TRUE.
1539 exec_kilp(struct tgsi_exec_machine
*mach
,
1540 const struct tgsi_full_instruction
*inst
)
1542 uint kilmask
; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1544 if (inst
->InstructionExtNv
.CondFlowEnable
) {
1550 swizzle
[0] = inst
->InstructionExtNv
.CondSwizzleX
;
1551 swizzle
[1] = inst
->InstructionExtNv
.CondSwizzleY
;
1552 swizzle
[2] = inst
->InstructionExtNv
.CondSwizzleZ
;
1553 swizzle
[3] = inst
->InstructionExtNv
.CondSwizzleW
;
1555 for (chan_index
= 0; chan_index
< 4; chan_index
++)
1559 for (i
= 0; i
< 4; i
++) {
1560 /* TODO: evaluate the condition code */
1567 /* "unconditional" kil */
1568 kilmask
= mach
->ExecMask
;
1570 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1575 * Fetch a four texture samples using STR texture coordinates.
1578 fetch_texel( struct tgsi_sampler
*sampler
,
1579 const union tgsi_exec_channel
*s
,
1580 const union tgsi_exec_channel
*t
,
1581 const union tgsi_exec_channel
*p
,
1582 float lodbias
, /* XXX should be float[4] */
1583 union tgsi_exec_channel
*r
,
1584 union tgsi_exec_channel
*g
,
1585 union tgsi_exec_channel
*b
,
1586 union tgsi_exec_channel
*a
)
1589 float rgba
[NUM_CHANNELS
][QUAD_SIZE
];
1591 sampler
->get_samples(sampler
, s
->f
, t
->f
, p
->f
, lodbias
, rgba
);
1593 for (j
= 0; j
< 4; j
++) {
1594 r
->f
[j
] = rgba
[0][j
];
1595 g
->f
[j
] = rgba
[1][j
];
1596 b
->f
[j
] = rgba
[2][j
];
1597 a
->f
[j
] = rgba
[3][j
];
1603 exec_tex(struct tgsi_exec_machine
*mach
,
1604 const struct tgsi_full_instruction
*inst
,
1608 const uint unit
= inst
->FullSrcRegisters
[1].SrcRegister
.Index
;
1609 union tgsi_exec_channel r
[4];
1613 /* debug_printf("Sampler %u unit %u\n", sampler, unit); */
1615 switch (inst
->InstructionExtTexture
.Texture
) {
1616 case TGSI_TEXTURE_1D
:
1618 FETCH(&r
[0], 0, CHAN_X
);
1621 FETCH(&r
[1], 0, CHAN_W
);
1622 micro_div( &r
[0], &r
[0], &r
[1] );
1626 FETCH(&r
[1], 0, CHAN_W
);
1627 lodBias
= r
[2].f
[0];
1632 fetch_texel(mach
->Samplers
[unit
],
1633 &r
[0], NULL
, NULL
, lodBias
, /* S, T, P, BIAS */
1634 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1637 case TGSI_TEXTURE_2D
:
1638 case TGSI_TEXTURE_RECT
:
1640 FETCH(&r
[0], 0, CHAN_X
);
1641 FETCH(&r
[1], 0, CHAN_Y
);
1642 FETCH(&r
[2], 0, CHAN_Z
);
1645 FETCH(&r
[3], 0, CHAN_W
);
1646 micro_div( &r
[0], &r
[0], &r
[3] );
1647 micro_div( &r
[1], &r
[1], &r
[3] );
1648 micro_div( &r
[2], &r
[2], &r
[3] );
1652 FETCH(&r
[3], 0, CHAN_W
);
1653 lodBias
= r
[3].f
[0];
1658 fetch_texel(mach
->Samplers
[unit
],
1659 &r
[0], &r
[1], &r
[2], lodBias
, /* inputs */
1660 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1663 case TGSI_TEXTURE_3D
:
1664 case TGSI_TEXTURE_CUBE
:
1666 FETCH(&r
[0], 0, CHAN_X
);
1667 FETCH(&r
[1], 0, CHAN_Y
);
1668 FETCH(&r
[2], 0, CHAN_Z
);
1671 FETCH(&r
[3], 0, CHAN_W
);
1672 micro_div( &r
[0], &r
[0], &r
[3] );
1673 micro_div( &r
[1], &r
[1], &r
[3] );
1674 micro_div( &r
[2], &r
[2], &r
[3] );
1678 FETCH(&r
[3], 0, CHAN_W
);
1679 lodBias
= r
[3].f
[0];
1684 fetch_texel(mach
->Samplers
[unit
],
1685 &r
[0], &r
[1], &r
[2], lodBias
,
1686 &r
[0], &r
[1], &r
[2], &r
[3]);
1693 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1694 STORE( &r
[chan_index
], 0, chan_index
);
1700 * Evaluate a constant-valued coefficient at the position of the
1705 struct tgsi_exec_machine
*mach
,
1711 for( i
= 0; i
< QUAD_SIZE
; i
++ ) {
1712 mach
->Inputs
[attrib
].xyzw
[chan
].f
[i
] = mach
->InterpCoefs
[attrib
].a0
[chan
];
1717 * Evaluate a linear-valued coefficient at the position of the
1722 struct tgsi_exec_machine
*mach
,
1726 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1727 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1728 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1729 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1730 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1731 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
;
1732 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = a0
+ dadx
;
1733 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = a0
+ dady
;
1734 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = a0
+ dadx
+ dady
;
1738 * Evaluate a perspective-valued coefficient at the position of the
1742 eval_perspective_coef(
1743 struct tgsi_exec_machine
*mach
,
1747 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1748 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1749 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1750 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1751 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1752 const float *w
= mach
->QuadPos
.xyzw
[3].f
;
1753 /* divide by W here */
1754 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
/ w
[0];
1755 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = (a0
+ dadx
) / w
[1];
1756 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = (a0
+ dady
) / w
[2];
1757 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = (a0
+ dadx
+ dady
) / w
[3];
1761 typedef void (* eval_coef_func
)(
1762 struct tgsi_exec_machine
*mach
,
1768 struct tgsi_exec_machine
*mach
,
1769 const struct tgsi_full_declaration
*decl
)
1771 if( mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
1772 if( decl
->Declaration
.File
== TGSI_FILE_INPUT
) {
1773 unsigned first
, last
, mask
;
1774 eval_coef_func eval
;
1776 first
= decl
->DeclarationRange
.First
;
1777 last
= decl
->DeclarationRange
.Last
;
1778 mask
= decl
->Declaration
.UsageMask
;
1780 switch( decl
->Declaration
.Interpolate
) {
1781 case TGSI_INTERPOLATE_CONSTANT
:
1782 eval
= eval_constant_coef
;
1785 case TGSI_INTERPOLATE_LINEAR
:
1786 eval
= eval_linear_coef
;
1789 case TGSI_INTERPOLATE_PERSPECTIVE
:
1790 eval
= eval_perspective_coef
;
1798 if( mask
== TGSI_WRITEMASK_XYZW
) {
1801 for( i
= first
; i
<= last
; i
++ ) {
1802 for( j
= 0; j
< NUM_CHANNELS
; j
++ ) {
1810 for( j
= 0; j
< NUM_CHANNELS
; j
++ ) {
1811 if( mask
& (1 << j
) ) {
1812 for( i
= first
; i
<= last
; i
++ ) {
1824 struct tgsi_exec_machine
*mach
,
1825 const struct tgsi_full_instruction
*inst
,
1829 union tgsi_exec_channel r
[8];
1833 switch (inst
->Instruction
.Opcode
) {
1834 case TGSI_OPCODE_ARL
:
1835 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1836 FETCH( &r
[0], 0, chan_index
);
1837 micro_flr( &r
[0], &r
[0] );
1838 STORE( &r
[0], 0, chan_index
);
1842 case TGSI_OPCODE_MOV
:
1843 case TGSI_OPCODE_SWZ
:
1844 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1845 FETCH( &r
[0], 0, chan_index
);
1846 STORE( &r
[0], 0, chan_index
);
1850 case TGSI_OPCODE_LIT
:
1851 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
1852 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
1855 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
1856 FETCH( &r
[0], 0, CHAN_X
);
1857 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
1858 micro_max( &r
[0], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
1859 STORE( &r
[0], 0, CHAN_Y
);
1862 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
1863 FETCH( &r
[1], 0, CHAN_Y
);
1864 micro_max( &r
[1], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
1866 FETCH( &r
[2], 0, CHAN_W
);
1867 micro_min( &r
[2], &r
[2], &mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
] );
1868 micro_max( &r
[2], &r
[2], &mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
] );
1869 micro_pow( &r
[1], &r
[1], &r
[2] );
1870 micro_lt( &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &r
[0], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
1871 STORE( &r
[0], 0, CHAN_Z
);
1875 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
1876 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
1880 case TGSI_OPCODE_RCP
:
1881 /* TGSI_OPCODE_RECIP */
1882 FETCH( &r
[0], 0, CHAN_X
);
1883 micro_div( &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0] );
1884 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1885 STORE( &r
[0], 0, chan_index
);
1889 case TGSI_OPCODE_RSQ
:
1890 /* TGSI_OPCODE_RECIPSQRT */
1891 FETCH( &r
[0], 0, CHAN_X
);
1892 micro_abs( &r
[0], &r
[0] );
1893 micro_sqrt( &r
[0], &r
[0] );
1894 micro_div( &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0] );
1895 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1896 STORE( &r
[0], 0, chan_index
);
1900 case TGSI_OPCODE_EXP
:
1901 FETCH( &r
[0], 0, CHAN_X
);
1902 micro_flr( &r
[1], &r
[0] ); /* r1 = floor(r0) */
1903 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
1904 micro_exp2( &r
[2], &r
[1] ); /* r2 = 2 ^ r1 */
1905 STORE( &r
[2], 0, CHAN_X
); /* store r2 */
1907 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
1908 micro_sub( &r
[2], &r
[0], &r
[1] ); /* r2 = r0 - r1 */
1909 STORE( &r
[2], 0, CHAN_Y
); /* store r2 */
1911 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
1912 micro_exp2( &r
[2], &r
[0] ); /* r2 = 2 ^ r0 */
1913 STORE( &r
[2], 0, CHAN_Z
); /* store r2 */
1915 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
1916 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
1920 case TGSI_OPCODE_LOG
:
1921 FETCH( &r
[0], 0, CHAN_X
);
1922 micro_abs( &r
[2], &r
[0] ); /* r2 = abs(r0) */
1923 micro_lg2( &r
[1], &r
[2] ); /* r1 = lg2(r2) */
1924 micro_flr( &r
[0], &r
[1] ); /* r0 = floor(r1) */
1925 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
1926 STORE( &r
[0], 0, CHAN_X
);
1928 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
1929 micro_exp2( &r
[0], &r
[0] ); /* r0 = 2 ^ r0 */
1930 micro_div( &r
[0], &r
[2], &r
[0] ); /* r0 = r2 / r0 */
1931 STORE( &r
[0], 0, CHAN_Y
);
1933 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
1934 STORE( &r
[1], 0, CHAN_Z
);
1936 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
1937 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
1941 case TGSI_OPCODE_MUL
:
1942 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
)
1944 FETCH(&r
[0], 0, chan_index
);
1945 FETCH(&r
[1], 1, chan_index
);
1947 micro_mul( &r
[0], &r
[0], &r
[1] );
1949 STORE(&r
[0], 0, chan_index
);
1953 case TGSI_OPCODE_ADD
:
1954 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1955 FETCH( &r
[0], 0, chan_index
);
1956 FETCH( &r
[1], 1, chan_index
);
1957 micro_add( &r
[0], &r
[0], &r
[1] );
1958 STORE( &r
[0], 0, chan_index
);
1962 case TGSI_OPCODE_DP3
:
1963 /* TGSI_OPCODE_DOT3 */
1964 FETCH( &r
[0], 0, CHAN_X
);
1965 FETCH( &r
[1], 1, CHAN_X
);
1966 micro_mul( &r
[0], &r
[0], &r
[1] );
1968 FETCH( &r
[1], 0, CHAN_Y
);
1969 FETCH( &r
[2], 1, CHAN_Y
);
1970 micro_mul( &r
[1], &r
[1], &r
[2] );
1971 micro_add( &r
[0], &r
[0], &r
[1] );
1973 FETCH( &r
[1], 0, CHAN_Z
);
1974 FETCH( &r
[2], 1, CHAN_Z
);
1975 micro_mul( &r
[1], &r
[1], &r
[2] );
1976 micro_add( &r
[0], &r
[0], &r
[1] );
1978 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1979 STORE( &r
[0], 0, chan_index
);
1983 case TGSI_OPCODE_DP4
:
1984 /* TGSI_OPCODE_DOT4 */
1985 FETCH(&r
[0], 0, CHAN_X
);
1986 FETCH(&r
[1], 1, CHAN_X
);
1988 micro_mul( &r
[0], &r
[0], &r
[1] );
1990 FETCH(&r
[1], 0, CHAN_Y
);
1991 FETCH(&r
[2], 1, CHAN_Y
);
1993 micro_mul( &r
[1], &r
[1], &r
[2] );
1994 micro_add( &r
[0], &r
[0], &r
[1] );
1996 FETCH(&r
[1], 0, CHAN_Z
);
1997 FETCH(&r
[2], 1, CHAN_Z
);
1999 micro_mul( &r
[1], &r
[1], &r
[2] );
2000 micro_add( &r
[0], &r
[0], &r
[1] );
2002 FETCH(&r
[1], 0, CHAN_W
);
2003 FETCH(&r
[2], 1, CHAN_W
);
2005 micro_mul( &r
[1], &r
[1], &r
[2] );
2006 micro_add( &r
[0], &r
[0], &r
[1] );
2008 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2009 STORE( &r
[0], 0, chan_index
);
2013 case TGSI_OPCODE_DST
:
2014 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2015 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2018 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2019 FETCH( &r
[0], 0, CHAN_Y
);
2020 FETCH( &r
[1], 1, CHAN_Y
);
2021 micro_mul( &r
[0], &r
[0], &r
[1] );
2022 STORE( &r
[0], 0, CHAN_Y
);
2025 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2026 FETCH( &r
[0], 0, CHAN_Z
);
2027 STORE( &r
[0], 0, CHAN_Z
);
2030 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2031 FETCH( &r
[0], 1, CHAN_W
);
2032 STORE( &r
[0], 0, CHAN_W
);
2036 case TGSI_OPCODE_MIN
:
2037 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2038 FETCH(&r
[0], 0, chan_index
);
2039 FETCH(&r
[1], 1, chan_index
);
2041 /* XXX use micro_min()?? */
2042 micro_lt( &r
[0], &r
[0], &r
[1], &r
[0], &r
[1] );
2044 STORE(&r
[0], 0, chan_index
);
2048 case TGSI_OPCODE_MAX
:
2049 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2050 FETCH(&r
[0], 0, chan_index
);
2051 FETCH(&r
[1], 1, chan_index
);
2053 /* XXX use micro_max()?? */
2054 micro_lt( &r
[0], &r
[0], &r
[1], &r
[1], &r
[0] );
2056 STORE(&r
[0], 0, chan_index
);
2060 case TGSI_OPCODE_SLT
:
2061 /* TGSI_OPCODE_SETLT */
2062 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2063 FETCH( &r
[0], 0, chan_index
);
2064 FETCH( &r
[1], 1, chan_index
);
2065 micro_lt( &r
[0], &r
[0], &r
[1], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
2066 STORE( &r
[0], 0, chan_index
);
2070 case TGSI_OPCODE_SGE
:
2071 /* TGSI_OPCODE_SETGE */
2072 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2073 FETCH( &r
[0], 0, chan_index
);
2074 FETCH( &r
[1], 1, chan_index
);
2075 micro_ge( &r
[0], &r
[0], &r
[1], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
2076 STORE( &r
[0], 0, chan_index
);
2080 case TGSI_OPCODE_MAD
:
2081 /* TGSI_OPCODE_MADD */
2082 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2083 FETCH( &r
[0], 0, chan_index
);
2084 FETCH( &r
[1], 1, chan_index
);
2085 micro_mul( &r
[0], &r
[0], &r
[1] );
2086 FETCH( &r
[1], 2, chan_index
);
2087 micro_add( &r
[0], &r
[0], &r
[1] );
2088 STORE( &r
[0], 0, chan_index
);
2092 case TGSI_OPCODE_SUB
:
2093 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2094 FETCH(&r
[0], 0, chan_index
);
2095 FETCH(&r
[1], 1, chan_index
);
2097 micro_sub( &r
[0], &r
[0], &r
[1] );
2099 STORE(&r
[0], 0, chan_index
);
2103 case TGSI_OPCODE_LERP
:
2104 /* TGSI_OPCODE_LRP */
2105 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2106 FETCH(&r
[0], 0, chan_index
);
2107 FETCH(&r
[1], 1, chan_index
);
2108 FETCH(&r
[2], 2, chan_index
);
2110 micro_sub( &r
[1], &r
[1], &r
[2] );
2111 micro_mul( &r
[0], &r
[0], &r
[1] );
2112 micro_add( &r
[0], &r
[0], &r
[2] );
2114 STORE(&r
[0], 0, chan_index
);
2118 case TGSI_OPCODE_CND
:
2122 case TGSI_OPCODE_CND0
:
2126 case TGSI_OPCODE_DOT2ADD
:
2127 /* TGSI_OPCODE_DP2A */
2128 FETCH( &r
[0], 0, CHAN_X
);
2129 FETCH( &r
[1], 1, CHAN_X
);
2130 micro_mul( &r
[0], &r
[0], &r
[1] );
2132 FETCH( &r
[1], 0, CHAN_Y
);
2133 FETCH( &r
[2], 1, CHAN_Y
);
2134 micro_mul( &r
[1], &r
[1], &r
[2] );
2135 micro_add( &r
[0], &r
[0], &r
[1] );
2137 FETCH( &r
[2], 2, CHAN_X
);
2138 micro_add( &r
[0], &r
[0], &r
[2] );
2140 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2141 STORE( &r
[0], 0, chan_index
);
2145 case TGSI_OPCODE_INDEX
:
2149 case TGSI_OPCODE_NEGATE
:
2153 case TGSI_OPCODE_FRAC
:
2154 /* TGSI_OPCODE_FRC */
2155 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2156 FETCH( &r
[0], 0, chan_index
);
2157 micro_frc( &r
[0], &r
[0] );
2158 STORE( &r
[0], 0, chan_index
);
2162 case TGSI_OPCODE_CLAMP
:
2166 case TGSI_OPCODE_FLOOR
:
2167 /* TGSI_OPCODE_FLR */
2168 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2169 FETCH( &r
[0], 0, chan_index
);
2170 micro_flr( &r
[0], &r
[0] );
2171 STORE( &r
[0], 0, chan_index
);
2175 case TGSI_OPCODE_ROUND
:
2176 case TGSI_OPCODE_ARR
:
2177 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2178 FETCH( &r
[0], 0, chan_index
);
2179 micro_rnd( &r
[0], &r
[0] );
2180 STORE( &r
[0], 0, chan_index
);
2184 case TGSI_OPCODE_EXPBASE2
:
2185 /* TGSI_OPCODE_EX2 */
2186 FETCH(&r
[0], 0, CHAN_X
);
2189 micro_exp2( &r
[0], &r
[0] );
2191 micro_pow( &r
[0], &mach
->Temps
[TEMP_2_I
].xyzw
[TEMP_2_C
], &r
[0] );
2194 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2195 STORE( &r
[0], 0, chan_index
);
2199 case TGSI_OPCODE_LOGBASE2
:
2200 /* TGSI_OPCODE_LG2 */
2201 FETCH( &r
[0], 0, CHAN_X
);
2202 micro_lg2( &r
[0], &r
[0] );
2203 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2204 STORE( &r
[0], 0, chan_index
);
2208 case TGSI_OPCODE_POWER
:
2209 /* TGSI_OPCODE_POW */
2210 FETCH(&r
[0], 0, CHAN_X
);
2211 FETCH(&r
[1], 1, CHAN_X
);
2213 micro_pow( &r
[0], &r
[0], &r
[1] );
2215 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2216 STORE( &r
[0], 0, chan_index
);
2220 case TGSI_OPCODE_CROSSPRODUCT
:
2221 /* TGSI_OPCODE_XPD */
2222 FETCH(&r
[0], 0, CHAN_Y
);
2223 FETCH(&r
[1], 1, CHAN_Z
);
2225 micro_mul( &r
[2], &r
[0], &r
[1] );
2227 FETCH(&r
[3], 0, CHAN_Z
);
2228 FETCH(&r
[4], 1, CHAN_Y
);
2230 micro_mul( &r
[5], &r
[3], &r
[4] );
2231 micro_sub( &r
[2], &r
[2], &r
[5] );
2233 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2234 STORE( &r
[2], 0, CHAN_X
);
2237 FETCH(&r
[2], 1, CHAN_X
);
2239 micro_mul( &r
[3], &r
[3], &r
[2] );
2241 FETCH(&r
[5], 0, CHAN_X
);
2243 micro_mul( &r
[1], &r
[1], &r
[5] );
2244 micro_sub( &r
[3], &r
[3], &r
[1] );
2246 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2247 STORE( &r
[3], 0, CHAN_Y
);
2250 micro_mul( &r
[5], &r
[5], &r
[4] );
2251 micro_mul( &r
[0], &r
[0], &r
[2] );
2252 micro_sub( &r
[5], &r
[5], &r
[0] );
2254 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2255 STORE( &r
[5], 0, CHAN_Z
);
2258 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2259 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2263 case TGSI_OPCODE_MULTIPLYMATRIX
:
2267 case TGSI_OPCODE_ABS
:
2268 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2269 FETCH(&r
[0], 0, chan_index
);
2271 micro_abs( &r
[0], &r
[0] );
2273 STORE(&r
[0], 0, chan_index
);
2277 case TGSI_OPCODE_RCC
:
2281 case TGSI_OPCODE_DPH
:
2282 FETCH(&r
[0], 0, CHAN_X
);
2283 FETCH(&r
[1], 1, CHAN_X
);
2285 micro_mul( &r
[0], &r
[0], &r
[1] );
2287 FETCH(&r
[1], 0, CHAN_Y
);
2288 FETCH(&r
[2], 1, CHAN_Y
);
2290 micro_mul( &r
[1], &r
[1], &r
[2] );
2291 micro_add( &r
[0], &r
[0], &r
[1] );
2293 FETCH(&r
[1], 0, CHAN_Z
);
2294 FETCH(&r
[2], 1, CHAN_Z
);
2296 micro_mul( &r
[1], &r
[1], &r
[2] );
2297 micro_add( &r
[0], &r
[0], &r
[1] );
2299 FETCH(&r
[1], 1, CHAN_W
);
2301 micro_add( &r
[0], &r
[0], &r
[1] );
2303 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2304 STORE( &r
[0], 0, chan_index
);
2308 case TGSI_OPCODE_COS
:
2309 FETCH(&r
[0], 0, CHAN_X
);
2311 micro_cos( &r
[0], &r
[0] );
2313 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2314 STORE( &r
[0], 0, chan_index
);
2318 case TGSI_OPCODE_DDX
:
2319 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2320 FETCH( &r
[0], 0, chan_index
);
2321 micro_ddx( &r
[0], &r
[0] );
2322 STORE( &r
[0], 0, chan_index
);
2326 case TGSI_OPCODE_DDY
:
2327 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2328 FETCH( &r
[0], 0, chan_index
);
2329 micro_ddy( &r
[0], &r
[0] );
2330 STORE( &r
[0], 0, chan_index
);
2334 case TGSI_OPCODE_KILP
:
2335 exec_kilp (mach
, inst
);
2338 case TGSI_OPCODE_KIL
:
2339 exec_kil (mach
, inst
);
2342 case TGSI_OPCODE_PK2H
:
2346 case TGSI_OPCODE_PK2US
:
2350 case TGSI_OPCODE_PK4B
:
2354 case TGSI_OPCODE_PK4UB
:
2358 case TGSI_OPCODE_RFL
:
2362 case TGSI_OPCODE_SEQ
:
2363 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2364 FETCH( &r
[0], 0, chan_index
);
2365 FETCH( &r
[1], 1, chan_index
);
2366 micro_eq( &r
[0], &r
[0], &r
[1],
2367 &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
],
2368 &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
2369 STORE( &r
[0], 0, chan_index
);
2373 case TGSI_OPCODE_SFL
:
2377 case TGSI_OPCODE_SGT
:
2378 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2379 FETCH( &r
[0], 0, chan_index
);
2380 FETCH( &r
[1], 1, chan_index
);
2381 micro_le( &r
[0], &r
[0], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
] );
2382 STORE( &r
[0], 0, chan_index
);
2386 case TGSI_OPCODE_SIN
:
2387 FETCH( &r
[0], 0, CHAN_X
);
2388 micro_sin( &r
[0], &r
[0] );
2389 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2390 STORE( &r
[0], 0, chan_index
);
2394 case TGSI_OPCODE_SLE
:
2395 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2396 FETCH( &r
[0], 0, chan_index
);
2397 FETCH( &r
[1], 1, chan_index
);
2398 micro_le( &r
[0], &r
[0], &r
[1], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
2399 STORE( &r
[0], 0, chan_index
);
2403 case TGSI_OPCODE_SNE
:
2404 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2405 FETCH( &r
[0], 0, chan_index
);
2406 FETCH( &r
[1], 1, chan_index
);
2407 micro_eq( &r
[0], &r
[0], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
] );
2408 STORE( &r
[0], 0, chan_index
);
2412 case TGSI_OPCODE_STR
:
2416 case TGSI_OPCODE_TEX
:
2417 /* simple texture lookup */
2418 /* src[0] = texcoord */
2419 /* src[1] = sampler unit */
2420 exec_tex(mach
, inst
, FALSE
, FALSE
);
2423 case TGSI_OPCODE_TXB
:
2424 /* Texture lookup with lod bias */
2425 /* src[0] = texcoord (src[0].w = LOD bias) */
2426 /* src[1] = sampler unit */
2427 exec_tex(mach
, inst
, TRUE
, FALSE
);
2430 case TGSI_OPCODE_TXD
:
2431 /* Texture lookup with explict partial derivatives */
2432 /* src[0] = texcoord */
2433 /* src[1] = d[strq]/dx */
2434 /* src[2] = d[strq]/dy */
2435 /* src[3] = sampler unit */
2439 case TGSI_OPCODE_TXL
:
2440 /* Texture lookup with explit LOD */
2441 /* src[0] = texcoord (src[0].w = LOD) */
2442 /* src[1] = sampler unit */
2443 exec_tex(mach
, inst
, TRUE
, FALSE
);
2446 case TGSI_OPCODE_TXP
:
2447 /* Texture lookup with projection */
2448 /* src[0] = texcoord (src[0].w = projection) */
2449 /* src[1] = sampler unit */
2450 exec_tex(mach
, inst
, FALSE
, TRUE
);
2453 case TGSI_OPCODE_UP2H
:
2457 case TGSI_OPCODE_UP2US
:
2461 case TGSI_OPCODE_UP4B
:
2465 case TGSI_OPCODE_UP4UB
:
2469 case TGSI_OPCODE_X2D
:
2473 case TGSI_OPCODE_ARA
:
2477 case TGSI_OPCODE_BRA
:
2481 case TGSI_OPCODE_CAL
:
2482 /* skip the call if no execution channels are enabled */
2483 if (mach
->ExecMask
) {
2486 /* push the Cond, Loop, Cont stacks */
2487 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
2488 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
2489 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2490 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
2491 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2492 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
2494 assert(mach
->FuncStackTop
< TGSI_EXEC_MAX_CALL_NESTING
);
2495 mach
->FuncStack
[mach
->FuncStackTop
++] = mach
->FuncMask
;
2497 /* note that PC was already incremented above */
2498 mach
->CallStack
[mach
->CallStackTop
++] = *pc
;
2499 *pc
= inst
->InstructionExtLabel
.Label
;
2503 case TGSI_OPCODE_RET
:
2504 mach
->FuncMask
&= ~mach
->ExecMask
;
2505 UPDATE_EXEC_MASK(mach
);
2507 if (mach
->FuncMask
== 0x0) {
2508 /* really return now (otherwise, keep executing */
2510 if (mach
->CallStackTop
== 0) {
2511 /* returning from main() */
2515 *pc
= mach
->CallStack
[--mach
->CallStackTop
];
2517 /* pop the Cond, Loop, Cont stacks */
2518 assert(mach
->CondStackTop
> 0);
2519 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
2520 assert(mach
->LoopStackTop
> 0);
2521 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
2522 assert(mach
->ContStackTop
> 0);
2523 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
2524 assert(mach
->FuncStackTop
> 0);
2525 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
2527 UPDATE_EXEC_MASK(mach
);
2531 case TGSI_OPCODE_SSG
:
2532 /* TGSI_OPCODE_SGN */
2533 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2534 FETCH( &r
[0], 0, chan_index
);
2535 micro_sgn( &r
[0], &r
[0] );
2536 STORE( &r
[0], 0, chan_index
);
2540 case TGSI_OPCODE_CMP
:
2541 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2542 FETCH(&r
[0], 0, chan_index
);
2543 FETCH(&r
[1], 1, chan_index
);
2544 FETCH(&r
[2], 2, chan_index
);
2546 micro_lt( &r
[0], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &r
[1], &r
[2] );
2548 STORE(&r
[0], 0, chan_index
);
2552 case TGSI_OPCODE_SCS
:
2553 if( IS_CHANNEL_ENABLED( *inst
, CHAN_X
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) ) {
2554 FETCH( &r
[0], 0, CHAN_X
);
2556 if( IS_CHANNEL_ENABLED( *inst
, CHAN_X
) ) {
2557 micro_cos( &r
[1], &r
[0] );
2558 STORE( &r
[1], 0, CHAN_X
);
2560 if( IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) ) {
2561 micro_sin( &r
[1], &r
[0] );
2562 STORE( &r
[1], 0, CHAN_Y
);
2564 if( IS_CHANNEL_ENABLED( *inst
, CHAN_Z
) ) {
2565 STORE( &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, CHAN_Z
);
2567 if( IS_CHANNEL_ENABLED( *inst
, CHAN_W
) ) {
2568 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2572 case TGSI_OPCODE_NRM
:
2573 /* 3-component vector normalize */
2575 union tgsi_exec_channel tmp
, dot
;
2577 /* tmp = dp3(src0, src0): */
2578 FETCH( &r
[0], 0, CHAN_X
);
2579 micro_mul( &tmp
, &r
[0], &r
[0] );
2581 FETCH( &r
[1], 0, CHAN_Y
);
2582 micro_mul( &dot
, &r
[1], &r
[1] );
2583 micro_add( &tmp
, &tmp
, &dot
);
2585 FETCH( &r
[2], 0, CHAN_Z
);
2586 micro_mul( &dot
, &r
[2], &r
[2] );
2587 micro_add( &tmp
, &tmp
, &dot
);
2589 /* tmp = 1 / sqrt(tmp) */
2590 micro_sqrt( &tmp
, &tmp
);
2591 micro_div( &tmp
, &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &tmp
);
2593 /* note: w channel is undefined */
2594 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2595 /* chan = chan * tmp */
2596 micro_mul( &r
[chan_index
], &tmp
, &r
[chan_index
] );
2597 STORE( &r
[chan_index
], 0, chan_index
);
2602 case TGSI_OPCODE_NRM4
:
2603 /* 4-component vector normalize */
2605 union tgsi_exec_channel tmp
, dot
;
2607 /* tmp = dp4(src0, src0): */
2608 FETCH( &r
[0], 0, CHAN_X
);
2609 micro_mul( &tmp
, &r
[0], &r
[0] );
2611 FETCH( &r
[1], 0, CHAN_Y
);
2612 micro_mul( &dot
, &r
[1], &r
[1] );
2613 micro_add( &tmp
, &tmp
, &dot
);
2615 FETCH( &r
[2], 0, CHAN_Z
);
2616 micro_mul( &dot
, &r
[2], &r
[2] );
2617 micro_add( &tmp
, &tmp
, &dot
);
2619 FETCH( &r
[3], 0, CHAN_W
);
2620 micro_mul( &dot
, &r
[3], &r
[3] );
2621 micro_add( &tmp
, &tmp
, &dot
);
2623 /* tmp = 1 / sqrt(tmp) */
2624 micro_sqrt( &tmp
, &tmp
);
2625 micro_div( &tmp
, &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &tmp
);
2627 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2628 /* chan = chan * tmp */
2629 micro_mul( &r
[chan_index
], &tmp
, &r
[chan_index
] );
2630 STORE( &r
[chan_index
], 0, chan_index
);
2635 case TGSI_OPCODE_DIV
:
2639 case TGSI_OPCODE_DP2
:
2640 FETCH( &r
[0], 0, CHAN_X
);
2641 FETCH( &r
[1], 1, CHAN_X
);
2642 micro_mul( &r
[0], &r
[0], &r
[1] );
2644 FETCH( &r
[1], 0, CHAN_Y
);
2645 FETCH( &r
[2], 1, CHAN_Y
);
2646 micro_mul( &r
[1], &r
[1], &r
[2] );
2647 micro_add( &r
[0], &r
[0], &r
[1] );
2649 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2650 STORE( &r
[0], 0, chan_index
);
2654 case TGSI_OPCODE_IF
:
2656 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
2657 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
2658 FETCH( &r
[0], 0, CHAN_X
);
2659 /* update CondMask */
2661 mach
->CondMask
&= ~0x1;
2664 mach
->CondMask
&= ~0x2;
2667 mach
->CondMask
&= ~0x4;
2670 mach
->CondMask
&= ~0x8;
2672 UPDATE_EXEC_MASK(mach
);
2673 /* Todo: If CondMask==0, jump to ELSE */
2676 case TGSI_OPCODE_ELSE
:
2677 /* invert CondMask wrt previous mask */
2680 assert(mach
->CondStackTop
> 0);
2681 prevMask
= mach
->CondStack
[mach
->CondStackTop
- 1];
2682 mach
->CondMask
= ~mach
->CondMask
& prevMask
;
2683 UPDATE_EXEC_MASK(mach
);
2684 /* Todo: If CondMask==0, jump to ENDIF */
2688 case TGSI_OPCODE_ENDIF
:
2690 assert(mach
->CondStackTop
> 0);
2691 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
2692 UPDATE_EXEC_MASK(mach
);
2695 case TGSI_OPCODE_END
:
2696 /* halt execution */
2700 case TGSI_OPCODE_REP
:
2704 case TGSI_OPCODE_ENDREP
:
2708 case TGSI_OPCODE_PUSHA
:
2712 case TGSI_OPCODE_POPA
:
2716 case TGSI_OPCODE_CEIL
:
2717 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2718 FETCH( &r
[0], 0, chan_index
);
2719 micro_ceil( &r
[0], &r
[0] );
2720 STORE( &r
[0], 0, chan_index
);
2724 case TGSI_OPCODE_I2F
:
2725 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2726 FETCH( &r
[0], 0, chan_index
);
2727 micro_i2f( &r
[0], &r
[0] );
2728 STORE( &r
[0], 0, chan_index
);
2732 case TGSI_OPCODE_NOT
:
2733 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2734 FETCH( &r
[0], 0, chan_index
);
2735 micro_not( &r
[0], &r
[0] );
2736 STORE( &r
[0], 0, chan_index
);
2740 case TGSI_OPCODE_TRUNC
:
2741 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2742 FETCH( &r
[0], 0, chan_index
);
2743 micro_trunc( &r
[0], &r
[0] );
2744 STORE( &r
[0], 0, chan_index
);
2748 case TGSI_OPCODE_SHL
:
2749 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2750 FETCH( &r
[0], 0, chan_index
);
2751 FETCH( &r
[1], 1, chan_index
);
2752 micro_shl( &r
[0], &r
[0], &r
[1] );
2753 STORE( &r
[0], 0, chan_index
);
2757 case TGSI_OPCODE_SHR
:
2758 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2759 FETCH( &r
[0], 0, chan_index
);
2760 FETCH( &r
[1], 1, chan_index
);
2761 micro_ishr( &r
[0], &r
[0], &r
[1] );
2762 STORE( &r
[0], 0, chan_index
);
2766 case TGSI_OPCODE_AND
:
2767 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2768 FETCH( &r
[0], 0, chan_index
);
2769 FETCH( &r
[1], 1, chan_index
);
2770 micro_and( &r
[0], &r
[0], &r
[1] );
2771 STORE( &r
[0], 0, chan_index
);
2775 case TGSI_OPCODE_OR
:
2776 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2777 FETCH( &r
[0], 0, chan_index
);
2778 FETCH( &r
[1], 1, chan_index
);
2779 micro_or( &r
[0], &r
[0], &r
[1] );
2780 STORE( &r
[0], 0, chan_index
);
2784 case TGSI_OPCODE_MOD
:
2788 case TGSI_OPCODE_XOR
:
2789 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2790 FETCH( &r
[0], 0, chan_index
);
2791 FETCH( &r
[1], 1, chan_index
);
2792 micro_xor( &r
[0], &r
[0], &r
[1] );
2793 STORE( &r
[0], 0, chan_index
);
2797 case TGSI_OPCODE_SAD
:
2801 case TGSI_OPCODE_TXF
:
2805 case TGSI_OPCODE_TXQ
:
2809 case TGSI_OPCODE_EMIT
:
2810 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] += 16;
2811 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]]++;
2814 case TGSI_OPCODE_ENDPRIM
:
2815 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]++;
2816 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]] = 0;
2819 case TGSI_OPCODE_LOOP
:
2820 /* fall-through (for now) */
2821 case TGSI_OPCODE_BGNLOOP2
:
2822 /* push LoopMask and ContMasks */
2823 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2824 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
2825 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2826 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
2829 case TGSI_OPCODE_ENDLOOP
:
2830 /* fall-through (for now at least) */
2831 case TGSI_OPCODE_ENDLOOP2
:
2832 /* Restore ContMask, but don't pop */
2833 assert(mach
->ContStackTop
> 0);
2834 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
2835 UPDATE_EXEC_MASK(mach
);
2836 if (mach
->ExecMask
) {
2837 /* repeat loop: jump to instruction just past BGNLOOP */
2838 *pc
= inst
->InstructionExtLabel
.Label
+ 1;
2841 /* exit loop: pop LoopMask */
2842 assert(mach
->LoopStackTop
> 0);
2843 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
2845 assert(mach
->ContStackTop
> 0);
2846 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
2848 UPDATE_EXEC_MASK(mach
);
2851 case TGSI_OPCODE_BRK
:
2852 /* turn off loop channels for each enabled exec channel */
2853 mach
->LoopMask
&= ~mach
->ExecMask
;
2854 /* Todo: if mach->LoopMask == 0, jump to end of loop */
2855 UPDATE_EXEC_MASK(mach
);
2858 case TGSI_OPCODE_CONT
:
2859 /* turn off cont channels for each enabled exec channel */
2860 mach
->ContMask
&= ~mach
->ExecMask
;
2861 /* Todo: if mach->LoopMask == 0, jump to end of loop */
2862 UPDATE_EXEC_MASK(mach
);
2865 case TGSI_OPCODE_BGNSUB
:
2869 case TGSI_OPCODE_ENDSUB
:
2873 case TGSI_OPCODE_NOISE1
:
2877 case TGSI_OPCODE_NOISE2
:
2881 case TGSI_OPCODE_NOISE3
:
2885 case TGSI_OPCODE_NOISE4
:
2889 case TGSI_OPCODE_NOP
:
2899 * Run TGSI interpreter.
2900 * \return bitmask of "alive" quad components
2903 tgsi_exec_machine_run( struct tgsi_exec_machine
*mach
)
2908 mach
->CondMask
= 0xf;
2909 mach
->LoopMask
= 0xf;
2910 mach
->ContMask
= 0xf;
2911 mach
->FuncMask
= 0xf;
2912 mach
->ExecMask
= 0xf;
2914 mach
->CondStackTop
= 0; /* temporarily subvert this assertion */
2915 assert(mach
->CondStackTop
== 0);
2916 assert(mach
->LoopStackTop
== 0);
2917 assert(mach
->ContStackTop
== 0);
2918 assert(mach
->CallStackTop
== 0);
2920 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] = 0;
2921 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] = 0;
2923 if( mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
2924 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0] = 0;
2925 mach
->Primitives
[0] = 0;
2928 for (i
= 0; i
< QUAD_SIZE
; i
++) {
2929 mach
->Temps
[TEMP_CC_I
].xyzw
[TEMP_CC_C
].u
[i
] =
2930 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_X_SHIFT
) |
2931 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Y_SHIFT
) |
2932 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Z_SHIFT
) |
2933 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_W_SHIFT
);
2936 /* execute declarations (interpolants) */
2937 for (i
= 0; i
< mach
->NumDeclarations
; i
++) {
2938 exec_declaration( mach
, mach
->Declarations
+i
);
2941 /* execute instructions, until pc is set to -1 */
2943 assert(pc
< (int) mach
->NumInstructions
);
2944 exec_instruction( mach
, mach
->Instructions
+ pc
, &pc
);
2948 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
2949 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
2951 * Scale back depth component.
2953 for (i
= 0; i
< 4; i
++)
2954 mach
->Outputs
[0].xyzw
[2].f
[i
] *= ctx
->DrawBuffer
->_DepthMaxF
;
2958 return ~mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];