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
.Size
- 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];
325 union tgsi_exec_channel
*dst
,
326 const union tgsi_exec_channel
*src0
,
327 const union tgsi_exec_channel
*src1
)
329 dst
->i
[0] = src0
->i
[0] + src1
->i
[0];
330 dst
->i
[1] = src0
->i
[1] + src1
->i
[1];
331 dst
->i
[2] = src0
->i
[2] + src1
->i
[2];
332 dst
->i
[3] = src0
->i
[3] + src1
->i
[3];
337 union tgsi_exec_channel
*dst
,
338 const union tgsi_exec_channel
*src0
,
339 const union tgsi_exec_channel
*src1
)
341 dst
->u
[0] = src0
->u
[0] & src1
->u
[0];
342 dst
->u
[1] = src0
->u
[1] & src1
->u
[1];
343 dst
->u
[2] = src0
->u
[2] & src1
->u
[2];
344 dst
->u
[3] = src0
->u
[3] & src1
->u
[3];
349 union tgsi_exec_channel
*dst
,
350 const union tgsi_exec_channel
*src
)
352 dst
->f
[0] = ceilf( src
->f
[0] );
353 dst
->f
[1] = ceilf( src
->f
[1] );
354 dst
->f
[2] = ceilf( src
->f
[2] );
355 dst
->f
[3] = ceilf( src
->f
[3] );
360 union tgsi_exec_channel
*dst
,
361 const union tgsi_exec_channel
*src
)
363 dst
->f
[0] = cosf( src
->f
[0] );
364 dst
->f
[1] = cosf( src
->f
[1] );
365 dst
->f
[2] = cosf( src
->f
[2] );
366 dst
->f
[3] = cosf( src
->f
[3] );
371 union tgsi_exec_channel
*dst
,
372 const union tgsi_exec_channel
*src
)
377 dst
->f
[3] = src
->f
[TILE_BOTTOM_RIGHT
] - src
->f
[TILE_BOTTOM_LEFT
];
382 union tgsi_exec_channel
*dst
,
383 const union tgsi_exec_channel
*src
)
388 dst
->f
[3] = src
->f
[TILE_TOP_LEFT
] - src
->f
[TILE_BOTTOM_LEFT
];
393 union tgsi_exec_channel
*dst
,
394 const union tgsi_exec_channel
*src0
,
395 const union tgsi_exec_channel
*src1
)
397 if (src1
->f
[0] != 0) {
398 dst
->f
[0] = src0
->f
[0] / src1
->f
[0];
400 if (src1
->f
[1] != 0) {
401 dst
->f
[1] = src0
->f
[1] / src1
->f
[1];
403 if (src1
->f
[2] != 0) {
404 dst
->f
[2] = src0
->f
[2] / src1
->f
[2];
406 if (src1
->f
[3] != 0) {
407 dst
->f
[3] = src0
->f
[3] / src1
->f
[3];
413 union tgsi_exec_channel
*dst
,
414 const union tgsi_exec_channel
*src0
,
415 const union tgsi_exec_channel
*src1
)
417 dst
->u
[0] = src0
->u
[0] / src1
->u
[0];
418 dst
->u
[1] = src0
->u
[1] / src1
->u
[1];
419 dst
->u
[2] = src0
->u
[2] / src1
->u
[2];
420 dst
->u
[3] = src0
->u
[3] / src1
->u
[3];
425 union tgsi_exec_channel
*dst
,
426 const union tgsi_exec_channel
*src0
,
427 const union tgsi_exec_channel
*src1
,
428 const union tgsi_exec_channel
*src2
,
429 const union tgsi_exec_channel
*src3
)
431 dst
->f
[0] = src0
->f
[0] == src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
432 dst
->f
[1] = src0
->f
[1] == src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
433 dst
->f
[2] = src0
->f
[2] == src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
434 dst
->f
[3] = src0
->f
[3] == src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
439 union tgsi_exec_channel
*dst
,
440 const union tgsi_exec_channel
*src0
,
441 const union tgsi_exec_channel
*src1
,
442 const union tgsi_exec_channel
*src2
,
443 const union tgsi_exec_channel
*src3
)
445 dst
->i
[0] = src0
->i
[0] == src1
->i
[0] ? src2
->i
[0] : src3
->i
[0];
446 dst
->i
[1] = src0
->i
[1] == src1
->i
[1] ? src2
->i
[1] : src3
->i
[1];
447 dst
->i
[2] = src0
->i
[2] == src1
->i
[2] ? src2
->i
[2] : src3
->i
[2];
448 dst
->i
[3] = src0
->i
[3] == src1
->i
[3] ? src2
->i
[3] : src3
->i
[3];
453 union tgsi_exec_channel
*dst
,
454 const union tgsi_exec_channel
*src
)
457 dst
->f
[0] = util_fast_exp2( src
->f
[0] );
458 dst
->f
[1] = util_fast_exp2( src
->f
[1] );
459 dst
->f
[2] = util_fast_exp2( src
->f
[2] );
460 dst
->f
[3] = util_fast_exp2( src
->f
[3] );
462 dst
->f
[0] = powf( 2.0f
, src
->f
[0] );
463 dst
->f
[1] = powf( 2.0f
, src
->f
[1] );
464 dst
->f
[2] = powf( 2.0f
, src
->f
[2] );
465 dst
->f
[3] = powf( 2.0f
, src
->f
[3] );
471 union tgsi_exec_channel
*dst
,
472 const union tgsi_exec_channel
*src
)
474 dst
->u
[0] = (uint
) src
->f
[0];
475 dst
->u
[1] = (uint
) src
->f
[1];
476 dst
->u
[2] = (uint
) src
->f
[2];
477 dst
->u
[3] = (uint
) src
->f
[3];
482 union tgsi_exec_channel
*dst
,
483 const union tgsi_exec_channel
*src
)
485 dst
->f
[0] = floorf( src
->f
[0] );
486 dst
->f
[1] = floorf( src
->f
[1] );
487 dst
->f
[2] = floorf( src
->f
[2] );
488 dst
->f
[3] = floorf( src
->f
[3] );
493 union tgsi_exec_channel
*dst
,
494 const union tgsi_exec_channel
*src
)
496 dst
->f
[0] = src
->f
[0] - floorf( src
->f
[0] );
497 dst
->f
[1] = src
->f
[1] - floorf( src
->f
[1] );
498 dst
->f
[2] = src
->f
[2] - floorf( src
->f
[2] );
499 dst
->f
[3] = src
->f
[3] - floorf( src
->f
[3] );
504 union tgsi_exec_channel
*dst
,
505 const union tgsi_exec_channel
*src0
,
506 const union tgsi_exec_channel
*src1
,
507 const union tgsi_exec_channel
*src2
,
508 const union tgsi_exec_channel
*src3
)
510 dst
->f
[0] = src0
->f
[0] >= src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
511 dst
->f
[1] = src0
->f
[1] >= src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
512 dst
->f
[2] = src0
->f
[2] >= src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
513 dst
->f
[3] = src0
->f
[3] >= src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
518 union tgsi_exec_channel
*dst
,
519 const union tgsi_exec_channel
*src
)
521 dst
->f
[0] = (float) src
->i
[0];
522 dst
->f
[1] = (float) src
->i
[1];
523 dst
->f
[2] = (float) src
->i
[2];
524 dst
->f
[3] = (float) src
->i
[3];
529 union tgsi_exec_channel
*dst
,
530 const union tgsi_exec_channel
*src
)
533 dst
->f
[0] = util_fast_log2( src
->f
[0] );
534 dst
->f
[1] = util_fast_log2( src
->f
[1] );
535 dst
->f
[2] = util_fast_log2( src
->f
[2] );
536 dst
->f
[3] = util_fast_log2( src
->f
[3] );
538 dst
->f
[0] = logf( src
->f
[0] ) * 1.442695f
;
539 dst
->f
[1] = logf( src
->f
[1] ) * 1.442695f
;
540 dst
->f
[2] = logf( src
->f
[2] ) * 1.442695f
;
541 dst
->f
[3] = logf( src
->f
[3] ) * 1.442695f
;
547 union tgsi_exec_channel
*dst
,
548 const union tgsi_exec_channel
*src0
,
549 const union tgsi_exec_channel
*src1
,
550 const union tgsi_exec_channel
*src2
,
551 const union tgsi_exec_channel
*src3
)
553 dst
->f
[0] = src0
->f
[0] <= src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
554 dst
->f
[1] = src0
->f
[1] <= src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
555 dst
->f
[2] = src0
->f
[2] <= src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
556 dst
->f
[3] = src0
->f
[3] <= src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
561 union tgsi_exec_channel
*dst
,
562 const union tgsi_exec_channel
*src0
,
563 const union tgsi_exec_channel
*src1
,
564 const union tgsi_exec_channel
*src2
,
565 const union tgsi_exec_channel
*src3
)
567 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
568 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
569 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
570 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
575 union tgsi_exec_channel
*dst
,
576 const union tgsi_exec_channel
*src0
,
577 const union tgsi_exec_channel
*src1
,
578 const union tgsi_exec_channel
*src2
,
579 const union tgsi_exec_channel
*src3
)
581 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? src2
->i
[0] : src3
->i
[0];
582 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? src2
->i
[1] : src3
->i
[1];
583 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? src2
->i
[2] : src3
->i
[2];
584 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? src2
->i
[3] : src3
->i
[3];
589 union tgsi_exec_channel
*dst
,
590 const union tgsi_exec_channel
*src0
,
591 const union tgsi_exec_channel
*src1
,
592 const union tgsi_exec_channel
*src2
,
593 const union tgsi_exec_channel
*src3
)
595 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? src2
->u
[0] : src3
->u
[0];
596 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? src2
->u
[1] : src3
->u
[1];
597 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? src2
->u
[2] : src3
->u
[2];
598 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? src2
->u
[3] : src3
->u
[3];
603 union tgsi_exec_channel
*dst
,
604 const union tgsi_exec_channel
*src0
,
605 const union tgsi_exec_channel
*src1
)
607 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
608 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
609 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
610 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
615 union tgsi_exec_channel
*dst
,
616 const union tgsi_exec_channel
*src0
,
617 const union tgsi_exec_channel
*src1
)
619 dst
->i
[0] = src0
->i
[0] > src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
620 dst
->i
[1] = src0
->i
[1] > src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
621 dst
->i
[2] = src0
->i
[2] > src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
622 dst
->i
[3] = src0
->i
[3] > src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
627 union tgsi_exec_channel
*dst
,
628 const union tgsi_exec_channel
*src0
,
629 const union tgsi_exec_channel
*src1
)
631 dst
->u
[0] = src0
->u
[0] > src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
632 dst
->u
[1] = src0
->u
[1] > src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
633 dst
->u
[2] = src0
->u
[2] > src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
634 dst
->u
[3] = src0
->u
[3] > src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
639 union tgsi_exec_channel
*dst
,
640 const union tgsi_exec_channel
*src0
,
641 const union tgsi_exec_channel
*src1
)
643 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
644 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
645 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
646 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
651 union tgsi_exec_channel
*dst
,
652 const union tgsi_exec_channel
*src0
,
653 const union tgsi_exec_channel
*src1
)
655 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
656 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
657 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
658 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
663 union tgsi_exec_channel
*dst
,
664 const union tgsi_exec_channel
*src0
,
665 const union tgsi_exec_channel
*src1
)
667 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
668 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
669 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
670 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
675 union tgsi_exec_channel
*dst
,
676 const union tgsi_exec_channel
*src0
,
677 const union tgsi_exec_channel
*src1
)
679 dst
->u
[0] = src0
->u
[0] % src1
->u
[0];
680 dst
->u
[1] = src0
->u
[1] % src1
->u
[1];
681 dst
->u
[2] = src0
->u
[2] % src1
->u
[2];
682 dst
->u
[3] = src0
->u
[3] % src1
->u
[3];
687 union tgsi_exec_channel
*dst
,
688 const union tgsi_exec_channel
*src0
,
689 const union tgsi_exec_channel
*src1
)
691 dst
->f
[0] = src0
->f
[0] * src1
->f
[0];
692 dst
->f
[1] = src0
->f
[1] * src1
->f
[1];
693 dst
->f
[2] = src0
->f
[2] * src1
->f
[2];
694 dst
->f
[3] = src0
->f
[3] * src1
->f
[3];
699 union tgsi_exec_channel
*dst
,
700 const union tgsi_exec_channel
*src0
,
701 const union tgsi_exec_channel
*src1
)
703 dst
->i
[0] = src0
->i
[0] * src1
->i
[0];
704 dst
->i
[1] = src0
->i
[1] * src1
->i
[1];
705 dst
->i
[2] = src0
->i
[2] * src1
->i
[2];
706 dst
->i
[3] = src0
->i
[3] * src1
->i
[3];
711 union tgsi_exec_channel
*dst0
,
712 union tgsi_exec_channel
*dst1
,
713 const union tgsi_exec_channel
*src0
,
714 const union tgsi_exec_channel
*src1
)
716 dst1
->i
[0] = src0
->i
[0] * src1
->i
[0];
717 dst1
->i
[1] = src0
->i
[1] * src1
->i
[1];
718 dst1
->i
[2] = src0
->i
[2] * src1
->i
[2];
719 dst1
->i
[3] = src0
->i
[3] * src1
->i
[3];
728 union tgsi_exec_channel
*dst0
,
729 union tgsi_exec_channel
*dst1
,
730 const union tgsi_exec_channel
*src0
,
731 const union tgsi_exec_channel
*src1
)
733 dst1
->u
[0] = src0
->u
[0] * src1
->u
[0];
734 dst1
->u
[1] = src0
->u
[1] * src1
->u
[1];
735 dst1
->u
[2] = src0
->u
[2] * src1
->u
[2];
736 dst1
->u
[3] = src0
->u
[3] * src1
->u
[3];
745 union tgsi_exec_channel
*dst
,
746 const union tgsi_exec_channel
*src0
,
747 const union tgsi_exec_channel
*src1
,
748 const union tgsi_exec_channel
*src2
)
750 dst
->u
[0] = src0
->u
[0] ? src1
->u
[0] : src2
->u
[0];
751 dst
->u
[1] = src0
->u
[1] ? src1
->u
[1] : src2
->u
[1];
752 dst
->u
[2] = src0
->u
[2] ? src1
->u
[2] : src2
->u
[2];
753 dst
->u
[3] = src0
->u
[3] ? src1
->u
[3] : src2
->u
[3];
758 union tgsi_exec_channel
*dst
,
759 const union tgsi_exec_channel
*src
)
761 dst
->f
[0] = -src
->f
[0];
762 dst
->f
[1] = -src
->f
[1];
763 dst
->f
[2] = -src
->f
[2];
764 dst
->f
[3] = -src
->f
[3];
769 union tgsi_exec_channel
*dst
,
770 const union tgsi_exec_channel
*src
)
772 dst
->i
[0] = -src
->i
[0];
773 dst
->i
[1] = -src
->i
[1];
774 dst
->i
[2] = -src
->i
[2];
775 dst
->i
[3] = -src
->i
[3];
780 union tgsi_exec_channel
*dst
,
781 const union tgsi_exec_channel
*src
)
783 dst
->u
[0] = ~src
->u
[0];
784 dst
->u
[1] = ~src
->u
[1];
785 dst
->u
[2] = ~src
->u
[2];
786 dst
->u
[3] = ~src
->u
[3];
791 union tgsi_exec_channel
*dst
,
792 const union tgsi_exec_channel
*src0
,
793 const union tgsi_exec_channel
*src1
)
795 dst
->u
[0] = src0
->u
[0] | src1
->u
[0];
796 dst
->u
[1] = src0
->u
[1] | src1
->u
[1];
797 dst
->u
[2] = src0
->u
[2] | src1
->u
[2];
798 dst
->u
[3] = src0
->u
[3] | src1
->u
[3];
803 union tgsi_exec_channel
*dst
,
804 const union tgsi_exec_channel
*src0
,
805 const union tgsi_exec_channel
*src1
)
808 dst
->f
[0] = util_fast_pow( src0
->f
[0], src1
->f
[0] );
809 dst
->f
[1] = util_fast_pow( src0
->f
[1], src1
->f
[1] );
810 dst
->f
[2] = util_fast_pow( src0
->f
[2], src1
->f
[2] );
811 dst
->f
[3] = util_fast_pow( src0
->f
[3], src1
->f
[3] );
813 dst
->f
[0] = powf( src0
->f
[0], src1
->f
[0] );
814 dst
->f
[1] = powf( src0
->f
[1], src1
->f
[1] );
815 dst
->f
[2] = powf( src0
->f
[2], src1
->f
[2] );
816 dst
->f
[3] = powf( src0
->f
[3], src1
->f
[3] );
822 union tgsi_exec_channel
*dst
,
823 const union tgsi_exec_channel
*src
)
825 dst
->f
[0] = floorf( src
->f
[0] + 0.5f
);
826 dst
->f
[1] = floorf( src
->f
[1] + 0.5f
);
827 dst
->f
[2] = floorf( src
->f
[2] + 0.5f
);
828 dst
->f
[3] = floorf( src
->f
[3] + 0.5f
);
833 union tgsi_exec_channel
*dst
,
834 const union tgsi_exec_channel
*src0
,
835 const union tgsi_exec_channel
*src1
)
837 dst
->i
[0] = src0
->i
[0] << src1
->i
[0];
838 dst
->i
[1] = src0
->i
[1] << src1
->i
[1];
839 dst
->i
[2] = src0
->i
[2] << src1
->i
[2];
840 dst
->i
[3] = src0
->i
[3] << src1
->i
[3];
845 union tgsi_exec_channel
*dst
,
846 const union tgsi_exec_channel
*src0
,
847 const union tgsi_exec_channel
*src1
)
849 dst
->i
[0] = src0
->i
[0] >> src1
->i
[0];
850 dst
->i
[1] = src0
->i
[1] >> src1
->i
[1];
851 dst
->i
[2] = src0
->i
[2] >> src1
->i
[2];
852 dst
->i
[3] = src0
->i
[3] >> src1
->i
[3];
857 union tgsi_exec_channel
*dst
,
858 const union tgsi_exec_channel
*src0
)
860 dst
->f
[0] = (float) (int) src0
->f
[0];
861 dst
->f
[1] = (float) (int) src0
->f
[1];
862 dst
->f
[2] = (float) (int) src0
->f
[2];
863 dst
->f
[3] = (float) (int) src0
->f
[3];
868 union tgsi_exec_channel
*dst
,
869 const union tgsi_exec_channel
*src0
,
870 const union tgsi_exec_channel
*src1
)
872 dst
->u
[0] = src0
->u
[0] >> src1
->u
[0];
873 dst
->u
[1] = src0
->u
[1] >> src1
->u
[1];
874 dst
->u
[2] = src0
->u
[2] >> src1
->u
[2];
875 dst
->u
[3] = src0
->u
[3] >> src1
->u
[3];
880 union tgsi_exec_channel
*dst
,
881 const union tgsi_exec_channel
*src
)
883 dst
->f
[0] = sinf( src
->f
[0] );
884 dst
->f
[1] = sinf( src
->f
[1] );
885 dst
->f
[2] = sinf( src
->f
[2] );
886 dst
->f
[3] = sinf( src
->f
[3] );
890 micro_sqrt( union tgsi_exec_channel
*dst
,
891 const union tgsi_exec_channel
*src
)
893 dst
->f
[0] = sqrtf( src
->f
[0] );
894 dst
->f
[1] = sqrtf( src
->f
[1] );
895 dst
->f
[2] = sqrtf( src
->f
[2] );
896 dst
->f
[3] = sqrtf( src
->f
[3] );
901 union tgsi_exec_channel
*dst
,
902 const union tgsi_exec_channel
*src0
,
903 const union tgsi_exec_channel
*src1
)
905 dst
->f
[0] = src0
->f
[0] - src1
->f
[0];
906 dst
->f
[1] = src0
->f
[1] - src1
->f
[1];
907 dst
->f
[2] = src0
->f
[2] - src1
->f
[2];
908 dst
->f
[3] = src0
->f
[3] - src1
->f
[3];
913 union tgsi_exec_channel
*dst
,
914 const union tgsi_exec_channel
*src
)
916 dst
->f
[0] = (float) src
->u
[0];
917 dst
->f
[1] = (float) src
->u
[1];
918 dst
->f
[2] = (float) src
->u
[2];
919 dst
->f
[3] = (float) src
->u
[3];
924 union tgsi_exec_channel
*dst
,
925 const union tgsi_exec_channel
*src0
,
926 const union tgsi_exec_channel
*src1
)
928 dst
->u
[0] = src0
->u
[0] ^ src1
->u
[0];
929 dst
->u
[1] = src0
->u
[1] ^ src1
->u
[1];
930 dst
->u
[2] = src0
->u
[2] ^ src1
->u
[2];
931 dst
->u
[3] = src0
->u
[3] ^ src1
->u
[3];
935 fetch_src_file_channel(
936 const struct tgsi_exec_machine
*mach
,
939 const union tgsi_exec_channel
*index
,
940 union tgsi_exec_channel
*chan
)
943 case TGSI_EXTSWIZZLE_X
:
944 case TGSI_EXTSWIZZLE_Y
:
945 case TGSI_EXTSWIZZLE_Z
:
946 case TGSI_EXTSWIZZLE_W
:
948 case TGSI_FILE_CONSTANT
:
949 assert(mach
->Consts
);
953 chan
->f
[0] = mach
->Consts
[index
->i
[0]][swizzle
];
957 chan
->f
[1] = mach
->Consts
[index
->i
[1]][swizzle
];
961 chan
->f
[2] = mach
->Consts
[index
->i
[2]][swizzle
];
965 chan
->f
[3] = mach
->Consts
[index
->i
[3]][swizzle
];
968 case TGSI_FILE_INPUT
:
969 chan
->u
[0] = mach
->Inputs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
970 chan
->u
[1] = mach
->Inputs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
971 chan
->u
[2] = mach
->Inputs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
972 chan
->u
[3] = mach
->Inputs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
975 case TGSI_FILE_TEMPORARY
:
976 assert(index
->i
[0] < TGSI_EXEC_NUM_TEMPS
);
977 chan
->u
[0] = mach
->Temps
[index
->i
[0]].xyzw
[swizzle
].u
[0];
978 chan
->u
[1] = mach
->Temps
[index
->i
[1]].xyzw
[swizzle
].u
[1];
979 chan
->u
[2] = mach
->Temps
[index
->i
[2]].xyzw
[swizzle
].u
[2];
980 chan
->u
[3] = mach
->Temps
[index
->i
[3]].xyzw
[swizzle
].u
[3];
983 case TGSI_FILE_IMMEDIATE
:
984 assert( index
->i
[0] < (int) mach
->ImmLimit
);
985 chan
->f
[0] = mach
->Imms
[index
->i
[0]][swizzle
];
986 assert( index
->i
[1] < (int) mach
->ImmLimit
);
987 chan
->f
[1] = mach
->Imms
[index
->i
[1]][swizzle
];
988 assert( index
->i
[2] < (int) mach
->ImmLimit
);
989 chan
->f
[2] = mach
->Imms
[index
->i
[2]][swizzle
];
990 assert( index
->i
[3] < (int) mach
->ImmLimit
);
991 chan
->f
[3] = mach
->Imms
[index
->i
[3]][swizzle
];
994 case TGSI_FILE_ADDRESS
:
995 chan
->u
[0] = mach
->Addrs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
996 chan
->u
[1] = mach
->Addrs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
997 chan
->u
[2] = mach
->Addrs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
998 chan
->u
[3] = mach
->Addrs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1001 case TGSI_FILE_OUTPUT
:
1002 /* vertex/fragment output vars can be read too */
1003 chan
->u
[0] = mach
->Outputs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1004 chan
->u
[1] = mach
->Outputs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1005 chan
->u
[2] = mach
->Outputs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1006 chan
->u
[3] = mach
->Outputs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1014 case TGSI_EXTSWIZZLE_ZERO
:
1015 *chan
= mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
];
1018 case TGSI_EXTSWIZZLE_ONE
:
1019 *chan
= mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
];
1029 const struct tgsi_exec_machine
*mach
,
1030 union tgsi_exec_channel
*chan
,
1031 const struct tgsi_full_src_register
*reg
,
1032 const uint chan_index
)
1034 union tgsi_exec_channel index
;
1037 /* We start with a direct index into a register file.
1041 * file = SrcRegister.File
1042 * [1] = SrcRegister.Index
1047 index
.i
[3] = reg
->SrcRegister
.Index
;
1049 /* There is an extra source register that indirectly subscripts
1050 * a register file. The direct index now becomes an offset
1051 * that is being added to the indirect register.
1055 * ind = SrcRegisterInd.File
1056 * [2] = SrcRegisterInd.Index
1057 * .x = SrcRegisterInd.SwizzleX
1059 if (reg
->SrcRegister
.Indirect
) {
1060 union tgsi_exec_channel index2
;
1061 union tgsi_exec_channel indir_index
;
1062 const uint execmask
= mach
->ExecMask
;
1065 /* which address register (always zero now) */
1069 index2
.i
[3] = reg
->SrcRegisterInd
.Index
;
1071 /* get current value of address register[swizzle] */
1072 swizzle
= tgsi_util_get_src_register_swizzle( ®
->SrcRegisterInd
, CHAN_X
);
1073 fetch_src_file_channel(
1075 reg
->SrcRegisterInd
.File
,
1080 /* add value of address register to the offset */
1081 index
.i
[0] += (int) indir_index
.f
[0];
1082 index
.i
[1] += (int) indir_index
.f
[1];
1083 index
.i
[2] += (int) indir_index
.f
[2];
1084 index
.i
[3] += (int) indir_index
.f
[3];
1086 /* for disabled execution channels, zero-out the index to
1087 * avoid using a potential garbage value.
1089 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1090 if ((execmask
& (1 << i
)) == 0)
1095 /* There is an extra source register that is a second
1096 * subscript to a register file. Effectively it means that
1097 * the register file is actually a 2D array of registers.
1099 * file[1][3] == file[1*sizeof(file[1])+3],
1101 * [3] = SrcRegisterDim.Index
1103 if (reg
->SrcRegister
.Dimension
) {
1104 /* The size of the first-order array depends on the register file type.
1105 * We need to multiply the index to the first array to get an effective,
1106 * "flat" index that points to the beginning of the second-order array.
1108 switch (reg
->SrcRegister
.File
) {
1109 case TGSI_FILE_INPUT
:
1110 index
.i
[0] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1111 index
.i
[1] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1112 index
.i
[2] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1113 index
.i
[3] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1115 case TGSI_FILE_CONSTANT
:
1116 index
.i
[0] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1117 index
.i
[1] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1118 index
.i
[2] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1119 index
.i
[3] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1125 index
.i
[0] += reg
->SrcRegisterDim
.Index
;
1126 index
.i
[1] += reg
->SrcRegisterDim
.Index
;
1127 index
.i
[2] += reg
->SrcRegisterDim
.Index
;
1128 index
.i
[3] += reg
->SrcRegisterDim
.Index
;
1130 /* Again, the second subscript index can be addressed indirectly
1131 * identically to the first one.
1132 * Nothing stops us from indirectly addressing the indirect register,
1133 * but there is no need for that, so we won't exercise it.
1135 * file[1][ind[4].y+3],
1137 * ind = SrcRegisterDimInd.File
1138 * [4] = SrcRegisterDimInd.Index
1139 * .y = SrcRegisterDimInd.SwizzleX
1141 if (reg
->SrcRegisterDim
.Indirect
) {
1142 union tgsi_exec_channel index2
;
1143 union tgsi_exec_channel indir_index
;
1144 const uint execmask
= mach
->ExecMask
;
1150 index2
.i
[3] = reg
->SrcRegisterDimInd
.Index
;
1152 swizzle
= tgsi_util_get_src_register_swizzle( ®
->SrcRegisterDimInd
, CHAN_X
);
1153 fetch_src_file_channel(
1155 reg
->SrcRegisterDimInd
.File
,
1160 index
.i
[0] += (int) indir_index
.f
[0];
1161 index
.i
[1] += (int) indir_index
.f
[1];
1162 index
.i
[2] += (int) indir_index
.f
[2];
1163 index
.i
[3] += (int) indir_index
.f
[3];
1165 /* for disabled execution channels, zero-out the index to
1166 * avoid using a potential garbage value.
1168 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1169 if ((execmask
& (1 << i
)) == 0)
1174 /* If by any chance there was a need for a 3D array of register
1175 * files, we would have to check whether SrcRegisterDim is followed
1176 * by a dimension register and continue the saga.
1180 swizzle
= tgsi_util_get_full_src_register_extswizzle( reg
, chan_index
);
1181 fetch_src_file_channel(
1183 reg
->SrcRegister
.File
,
1188 switch (tgsi_util_get_full_src_register_sign_mode( reg
, chan_index
)) {
1189 case TGSI_UTIL_SIGN_CLEAR
:
1190 micro_abs( chan
, chan
);
1193 case TGSI_UTIL_SIGN_SET
:
1194 micro_abs( chan
, chan
);
1195 micro_neg( chan
, chan
);
1198 case TGSI_UTIL_SIGN_TOGGLE
:
1199 micro_neg( chan
, chan
);
1202 case TGSI_UTIL_SIGN_KEEP
:
1206 if (reg
->SrcRegisterExtMod
.Complement
) {
1207 micro_sub( chan
, &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], chan
);
1213 struct tgsi_exec_machine
*mach
,
1214 const union tgsi_exec_channel
*chan
,
1215 const struct tgsi_full_dst_register
*reg
,
1216 const struct tgsi_full_instruction
*inst
,
1220 union tgsi_exec_channel null
;
1221 union tgsi_exec_channel
*dst
;
1222 uint execmask
= mach
->ExecMask
;
1224 switch (reg
->DstRegister
.File
) {
1225 case TGSI_FILE_NULL
:
1229 case TGSI_FILE_OUTPUT
:
1230 dst
= &mach
->Outputs
[mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0]
1231 + reg
->DstRegister
.Index
].xyzw
[chan_index
];
1234 case TGSI_FILE_TEMPORARY
:
1235 assert( reg
->DstRegister
.Index
< TGSI_EXEC_NUM_TEMPS
);
1236 dst
= &mach
->Temps
[reg
->DstRegister
.Index
].xyzw
[chan_index
];
1239 case TGSI_FILE_ADDRESS
:
1240 dst
= &mach
->Addrs
[reg
->DstRegister
.Index
].xyzw
[chan_index
];
1248 if (inst
->InstructionExtNv
.CondFlowEnable
) {
1249 union tgsi_exec_channel
*cc
= &mach
->Temps
[TEMP_CC_I
].xyzw
[TEMP_CC_C
];
1255 /* Only CC0 supported.
1257 assert( inst
->InstructionExtNv
.CondFlowIndex
< 1 );
1259 switch (chan_index
) {
1261 swizzle
= inst
->InstructionExtNv
.CondSwizzleX
;
1264 swizzle
= inst
->InstructionExtNv
.CondSwizzleY
;
1267 swizzle
= inst
->InstructionExtNv
.CondSwizzleZ
;
1270 swizzle
= inst
->InstructionExtNv
.CondSwizzleW
;
1278 case TGSI_SWIZZLE_X
:
1279 shift
= TGSI_EXEC_CC_X_SHIFT
;
1280 mask
= TGSI_EXEC_CC_X_MASK
;
1282 case TGSI_SWIZZLE_Y
:
1283 shift
= TGSI_EXEC_CC_Y_SHIFT
;
1284 mask
= TGSI_EXEC_CC_Y_MASK
;
1286 case TGSI_SWIZZLE_Z
:
1287 shift
= TGSI_EXEC_CC_Z_SHIFT
;
1288 mask
= TGSI_EXEC_CC_Z_MASK
;
1290 case TGSI_SWIZZLE_W
:
1291 shift
= TGSI_EXEC_CC_W_SHIFT
;
1292 mask
= TGSI_EXEC_CC_W_MASK
;
1299 switch (inst
->InstructionExtNv
.CondMask
) {
1301 test
= ~(TGSI_EXEC_CC_GT
<< shift
) & mask
;
1302 for (i
= 0; i
< QUAD_SIZE
; i
++)
1303 if (cc
->u
[i
] & test
)
1304 execmask
&= ~(1 << i
);
1308 test
= ~(TGSI_EXEC_CC_EQ
<< shift
) & mask
;
1309 for (i
= 0; i
< QUAD_SIZE
; i
++)
1310 if (cc
->u
[i
] & test
)
1311 execmask
&= ~(1 << i
);
1315 test
= ~(TGSI_EXEC_CC_LT
<< shift
) & mask
;
1316 for (i
= 0; i
< QUAD_SIZE
; i
++)
1317 if (cc
->u
[i
] & test
)
1318 execmask
&= ~(1 << i
);
1322 test
= ~((TGSI_EXEC_CC_GT
| TGSI_EXEC_CC_EQ
) << shift
) & mask
;
1323 for (i
= 0; i
< QUAD_SIZE
; i
++)
1324 if (cc
->u
[i
] & test
)
1325 execmask
&= ~(1 << i
);
1329 test
= ~((TGSI_EXEC_CC_LT
| TGSI_EXEC_CC_EQ
) << shift
) & mask
;
1330 for (i
= 0; i
< QUAD_SIZE
; i
++)
1331 if (cc
->u
[i
] & test
)
1332 execmask
&= ~(1 << i
);
1336 test
= ~((TGSI_EXEC_CC_GT
| TGSI_EXEC_CC_LT
| TGSI_EXEC_CC_UN
) << shift
) & mask
;
1337 for (i
= 0; i
< QUAD_SIZE
; i
++)
1338 if (cc
->u
[i
] & test
)
1339 execmask
&= ~(1 << i
);
1346 for (i
= 0; i
< QUAD_SIZE
; i
++)
1347 execmask
&= ~(1 << i
);
1356 switch (inst
->Instruction
.Saturate
) {
1358 for (i
= 0; i
< QUAD_SIZE
; i
++)
1359 if (execmask
& (1 << i
))
1360 dst
->i
[i
] = chan
->i
[i
];
1363 case TGSI_SAT_ZERO_ONE
:
1364 for (i
= 0; i
< QUAD_SIZE
; i
++)
1365 if (execmask
& (1 << i
)) {
1366 if (chan
->f
[i
] < 0.0f
)
1368 else if (chan
->f
[i
] > 1.0f
)
1371 dst
->i
[i
] = chan
->i
[i
];
1375 case TGSI_SAT_MINUS_PLUS_ONE
:
1376 for (i
= 0; i
< QUAD_SIZE
; i
++)
1377 if (execmask
& (1 << i
)) {
1378 if (chan
->f
[i
] < -1.0f
)
1380 else if (chan
->f
[i
] > 1.0f
)
1383 dst
->i
[i
] = chan
->i
[i
];
1391 if (inst
->InstructionExtNv
.CondDstUpdate
) {
1392 union tgsi_exec_channel
*cc
= &mach
->Temps
[TEMP_CC_I
].xyzw
[TEMP_CC_C
];
1396 /* Only CC0 supported.
1398 assert( inst
->InstructionExtNv
.CondDstIndex
< 1 );
1400 switch (chan_index
) {
1402 shift
= TGSI_EXEC_CC_X_SHIFT
;
1403 mask
= ~TGSI_EXEC_CC_X_MASK
;
1406 shift
= TGSI_EXEC_CC_Y_SHIFT
;
1407 mask
= ~TGSI_EXEC_CC_Y_MASK
;
1410 shift
= TGSI_EXEC_CC_Z_SHIFT
;
1411 mask
= ~TGSI_EXEC_CC_Z_MASK
;
1414 shift
= TGSI_EXEC_CC_W_SHIFT
;
1415 mask
= ~TGSI_EXEC_CC_W_MASK
;
1422 for (i
= 0; i
< QUAD_SIZE
; i
++)
1423 if (execmask
& (1 << i
)) {
1425 if (dst
->f
[i
] < 0.0f
)
1426 cc
->u
[i
] |= TGSI_EXEC_CC_LT
<< shift
;
1427 else if (dst
->f
[i
] > 0.0f
)
1428 cc
->u
[i
] |= TGSI_EXEC_CC_GT
<< shift
;
1429 else if (dst
->f
[i
] == 0.0f
)
1430 cc
->u
[i
] |= TGSI_EXEC_CC_EQ
<< shift
;
1432 cc
->u
[i
] |= TGSI_EXEC_CC_UN
<< shift
;
1437 #define FETCH(VAL,INDEX,CHAN)\
1438 fetch_source (mach, VAL, &inst->FullSrcRegisters[INDEX], CHAN)
1440 #define STORE(VAL,INDEX,CHAN)\
1441 store_dest (mach, VAL, &inst->FullDstRegisters[INDEX], inst, CHAN )
1445 * Execute ARB-style KIL which is predicated by a src register.
1446 * Kill fragment if any of the four values is less than zero.
1449 exec_kil(struct tgsi_exec_machine
*mach
,
1450 const struct tgsi_full_instruction
*inst
)
1454 uint kilmask
= 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1455 union tgsi_exec_channel r
[1];
1457 /* This mask stores component bits that were already tested. Note that
1458 * we test if the value is less than zero, so 1.0 and 0.0 need not to be
1460 uniquemask
= (1 << TGSI_EXTSWIZZLE_ZERO
) | (1 << TGSI_EXTSWIZZLE_ONE
);
1462 for (chan_index
= 0; chan_index
< 4; chan_index
++)
1467 /* unswizzle channel */
1468 swizzle
= tgsi_util_get_full_src_register_extswizzle (
1469 &inst
->FullSrcRegisters
[0],
1472 /* check if the component has not been already tested */
1473 if (uniquemask
& (1 << swizzle
))
1475 uniquemask
|= 1 << swizzle
;
1477 FETCH(&r
[0], 0, chan_index
);
1478 for (i
= 0; i
< 4; i
++)
1479 if (r
[0].f
[i
] < 0.0f
)
1483 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1487 * Execute NVIDIA-style KIL which is predicated by a condition code.
1488 * Kill fragment if the condition code is TRUE.
1491 exec_kilp(struct tgsi_exec_machine
*mach
,
1492 const struct tgsi_full_instruction
*inst
)
1494 uint kilmask
; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1496 if (inst
->InstructionExtNv
.CondFlowEnable
) {
1502 swizzle
[0] = inst
->InstructionExtNv
.CondSwizzleX
;
1503 swizzle
[1] = inst
->InstructionExtNv
.CondSwizzleY
;
1504 swizzle
[2] = inst
->InstructionExtNv
.CondSwizzleZ
;
1505 swizzle
[3] = inst
->InstructionExtNv
.CondSwizzleW
;
1507 for (chan_index
= 0; chan_index
< 4; chan_index
++)
1511 for (i
= 0; i
< 4; i
++) {
1512 /* TODO: evaluate the condition code */
1519 /* "unconditional" kil */
1520 kilmask
= mach
->ExecMask
;
1522 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1527 * Fetch a texel using STR texture coordinates.
1530 fetch_texel( struct tgsi_sampler
*sampler
,
1531 const union tgsi_exec_channel
*s
,
1532 const union tgsi_exec_channel
*t
,
1533 const union tgsi_exec_channel
*p
,
1534 float lodbias
, /* XXX should be float[4] */
1535 union tgsi_exec_channel
*r
,
1536 union tgsi_exec_channel
*g
,
1537 union tgsi_exec_channel
*b
,
1538 union tgsi_exec_channel
*a
)
1541 float rgba
[NUM_CHANNELS
][QUAD_SIZE
];
1543 sampler
->get_samples(sampler
, s
->f
, t
->f
, p
->f
, lodbias
, rgba
);
1545 for (j
= 0; j
< 4; j
++) {
1546 r
->f
[j
] = rgba
[0][j
];
1547 g
->f
[j
] = rgba
[1][j
];
1548 b
->f
[j
] = rgba
[2][j
];
1549 a
->f
[j
] = rgba
[3][j
];
1555 exec_tex(struct tgsi_exec_machine
*mach
,
1556 const struct tgsi_full_instruction
*inst
,
1560 const uint unit
= inst
->FullSrcRegisters
[1].SrcRegister
.Index
;
1561 union tgsi_exec_channel r
[8];
1565 /* debug_printf("Sampler %u unit %u\n", sampler, unit); */
1567 switch (inst
->InstructionExtTexture
.Texture
) {
1568 case TGSI_TEXTURE_1D
:
1570 FETCH(&r
[0], 0, CHAN_X
);
1573 FETCH(&r
[1], 0, CHAN_W
);
1574 micro_div( &r
[0], &r
[0], &r
[1] );
1578 FETCH(&r
[1], 0, CHAN_W
);
1579 lodBias
= r
[2].f
[0];
1584 fetch_texel(mach
->Samplers
[unit
],
1585 &r
[0], NULL
, NULL
, lodBias
, /* S, T, P, BIAS */
1586 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1589 case TGSI_TEXTURE_2D
:
1590 case TGSI_TEXTURE_RECT
:
1592 FETCH(&r
[0], 0, CHAN_X
);
1593 FETCH(&r
[1], 0, CHAN_Y
);
1594 FETCH(&r
[2], 0, CHAN_Z
);
1597 FETCH(&r
[3], 0, CHAN_W
);
1598 micro_div( &r
[0], &r
[0], &r
[3] );
1599 micro_div( &r
[1], &r
[1], &r
[3] );
1600 micro_div( &r
[2], &r
[2], &r
[3] );
1604 FETCH(&r
[3], 0, CHAN_W
);
1605 lodBias
= r
[3].f
[0];
1610 fetch_texel(mach
->Samplers
[unit
],
1611 &r
[0], &r
[1], &r
[2], lodBias
, /* inputs */
1612 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1615 case TGSI_TEXTURE_3D
:
1616 case TGSI_TEXTURE_CUBE
:
1618 FETCH(&r
[0], 0, CHAN_X
);
1619 FETCH(&r
[1], 0, CHAN_Y
);
1620 FETCH(&r
[2], 0, CHAN_Z
);
1623 FETCH(&r
[3], 0, CHAN_W
);
1624 micro_div( &r
[0], &r
[0], &r
[3] );
1625 micro_div( &r
[1], &r
[1], &r
[3] );
1626 micro_div( &r
[2], &r
[2], &r
[3] );
1630 FETCH(&r
[3], 0, CHAN_W
);
1631 lodBias
= r
[3].f
[0];
1636 fetch_texel(mach
->Samplers
[unit
],
1637 &r
[0], &r
[1], &r
[2], lodBias
,
1638 &r
[0], &r
[1], &r
[2], &r
[3]);
1645 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1646 STORE( &r
[chan_index
], 0, chan_index
);
1652 * Evaluate a constant-valued coefficient at the position of the
1657 struct tgsi_exec_machine
*mach
,
1663 for( i
= 0; i
< QUAD_SIZE
; i
++ ) {
1664 mach
->Inputs
[attrib
].xyzw
[chan
].f
[i
] = mach
->InterpCoefs
[attrib
].a0
[chan
];
1669 * Evaluate a linear-valued coefficient at the position of the
1674 struct tgsi_exec_machine
*mach
,
1678 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1679 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1680 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1681 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1682 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1683 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
;
1684 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = a0
+ dadx
;
1685 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = a0
+ dady
;
1686 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = a0
+ dadx
+ dady
;
1690 * Evaluate a perspective-valued coefficient at the position of the
1694 eval_perspective_coef(
1695 struct tgsi_exec_machine
*mach
,
1699 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1700 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1701 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1702 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1703 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1704 const float *w
= mach
->QuadPos
.xyzw
[3].f
;
1705 /* divide by W here */
1706 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
/ w
[0];
1707 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = (a0
+ dadx
) / w
[1];
1708 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = (a0
+ dady
) / w
[2];
1709 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = (a0
+ dadx
+ dady
) / w
[3];
1713 typedef void (* eval_coef_func
)(
1714 struct tgsi_exec_machine
*mach
,
1720 struct tgsi_exec_machine
*mach
,
1721 const struct tgsi_full_declaration
*decl
)
1723 if( mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
1724 if( decl
->Declaration
.File
== TGSI_FILE_INPUT
) {
1725 unsigned first
, last
, mask
;
1726 eval_coef_func eval
;
1728 first
= decl
->DeclarationRange
.First
;
1729 last
= decl
->DeclarationRange
.Last
;
1730 mask
= decl
->Declaration
.UsageMask
;
1732 switch( decl
->Declaration
.Interpolate
) {
1733 case TGSI_INTERPOLATE_CONSTANT
:
1734 eval
= eval_constant_coef
;
1737 case TGSI_INTERPOLATE_LINEAR
:
1738 eval
= eval_linear_coef
;
1741 case TGSI_INTERPOLATE_PERSPECTIVE
:
1742 eval
= eval_perspective_coef
;
1750 if( mask
== TGSI_WRITEMASK_XYZW
) {
1753 for( i
= first
; i
<= last
; i
++ ) {
1754 for( j
= 0; j
< NUM_CHANNELS
; j
++ ) {
1762 for( j
= 0; j
< NUM_CHANNELS
; j
++ ) {
1763 if( mask
& (1 << j
) ) {
1764 for( i
= first
; i
<= last
; i
++ ) {
1776 struct tgsi_exec_machine
*mach
,
1777 const struct tgsi_full_instruction
*inst
,
1781 union tgsi_exec_channel r
[8];
1785 switch (inst
->Instruction
.Opcode
) {
1786 case TGSI_OPCODE_ARL
:
1787 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1788 FETCH( &r
[0], 0, chan_index
);
1789 micro_trunc( &r
[0], &r
[0] );
1790 STORE( &r
[0], 0, chan_index
);
1794 case TGSI_OPCODE_MOV
:
1795 case TGSI_OPCODE_SWZ
:
1796 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1797 FETCH( &r
[0], 0, chan_index
);
1798 STORE( &r
[0], 0, chan_index
);
1802 case TGSI_OPCODE_LIT
:
1803 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
1804 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
1807 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
1808 FETCH( &r
[0], 0, CHAN_X
);
1809 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
1810 micro_max( &r
[0], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
1811 STORE( &r
[0], 0, CHAN_Y
);
1814 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
1815 FETCH( &r
[1], 0, CHAN_Y
);
1816 micro_max( &r
[1], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
1818 FETCH( &r
[2], 0, CHAN_W
);
1819 micro_min( &r
[2], &r
[2], &mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
] );
1820 micro_max( &r
[2], &r
[2], &mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
] );
1821 micro_pow( &r
[1], &r
[1], &r
[2] );
1822 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
] );
1823 STORE( &r
[0], 0, CHAN_Z
);
1827 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
1828 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
1832 case TGSI_OPCODE_RCP
:
1833 /* TGSI_OPCODE_RECIP */
1834 FETCH( &r
[0], 0, CHAN_X
);
1835 micro_div( &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0] );
1836 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1837 STORE( &r
[0], 0, chan_index
);
1841 case TGSI_OPCODE_RSQ
:
1842 /* TGSI_OPCODE_RECIPSQRT */
1843 FETCH( &r
[0], 0, CHAN_X
);
1844 micro_sqrt( &r
[0], &r
[0] );
1845 micro_div( &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0] );
1846 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1847 STORE( &r
[0], 0, chan_index
);
1851 case TGSI_OPCODE_EXP
:
1852 FETCH( &r
[0], 0, CHAN_X
);
1853 micro_flr( &r
[1], &r
[0] ); /* r1 = floor(r0) */
1854 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
1855 micro_exp2( &r
[2], &r
[1] ); /* r2 = 2 ^ r1 */
1856 STORE( &r
[2], 0, CHAN_X
); /* store r2 */
1858 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
1859 micro_sub( &r
[2], &r
[0], &r
[1] ); /* r2 = r0 - r1 */
1860 STORE( &r
[2], 0, CHAN_Y
); /* store r2 */
1862 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
1863 micro_exp2( &r
[2], &r
[0] ); /* r2 = 2 ^ r0 */
1864 STORE( &r
[2], 0, CHAN_Z
); /* store r2 */
1866 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
1867 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
1871 case TGSI_OPCODE_LOG
:
1872 FETCH( &r
[0], 0, CHAN_X
);
1873 micro_abs( &r
[2], &r
[0] ); /* r2 = abs(r0) */
1874 micro_lg2( &r
[1], &r
[2] ); /* r1 = lg2(r2) */
1875 micro_flr( &r
[0], &r
[1] ); /* r0 = floor(r1) */
1876 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
1877 STORE( &r
[0], 0, CHAN_X
);
1879 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
1880 micro_exp2( &r
[0], &r
[0] ); /* r0 = 2 ^ r0 */
1881 micro_div( &r
[0], &r
[2], &r
[0] ); /* r0 = r2 / r0 */
1882 STORE( &r
[0], 0, CHAN_Y
);
1884 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
1885 STORE( &r
[1], 0, CHAN_Z
);
1887 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
1888 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
1892 case TGSI_OPCODE_MUL
:
1893 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
)
1895 FETCH(&r
[0], 0, chan_index
);
1896 FETCH(&r
[1], 1, chan_index
);
1898 micro_mul( &r
[0], &r
[0], &r
[1] );
1900 STORE(&r
[0], 0, chan_index
);
1904 case TGSI_OPCODE_ADD
:
1905 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1906 FETCH( &r
[0], 0, chan_index
);
1907 FETCH( &r
[1], 1, chan_index
);
1908 micro_add( &r
[0], &r
[0], &r
[1] );
1909 STORE( &r
[0], 0, chan_index
);
1913 case TGSI_OPCODE_DP3
:
1914 /* TGSI_OPCODE_DOT3 */
1915 FETCH( &r
[0], 0, CHAN_X
);
1916 FETCH( &r
[1], 1, CHAN_X
);
1917 micro_mul( &r
[0], &r
[0], &r
[1] );
1919 FETCH( &r
[1], 0, CHAN_Y
);
1920 FETCH( &r
[2], 1, CHAN_Y
);
1921 micro_mul( &r
[1], &r
[1], &r
[2] );
1922 micro_add( &r
[0], &r
[0], &r
[1] );
1924 FETCH( &r
[1], 0, CHAN_Z
);
1925 FETCH( &r
[2], 1, CHAN_Z
);
1926 micro_mul( &r
[1], &r
[1], &r
[2] );
1927 micro_add( &r
[0], &r
[0], &r
[1] );
1929 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1930 STORE( &r
[0], 0, chan_index
);
1934 case TGSI_OPCODE_DP4
:
1935 /* TGSI_OPCODE_DOT4 */
1936 FETCH(&r
[0], 0, CHAN_X
);
1937 FETCH(&r
[1], 1, CHAN_X
);
1939 micro_mul( &r
[0], &r
[0], &r
[1] );
1941 FETCH(&r
[1], 0, CHAN_Y
);
1942 FETCH(&r
[2], 1, CHAN_Y
);
1944 micro_mul( &r
[1], &r
[1], &r
[2] );
1945 micro_add( &r
[0], &r
[0], &r
[1] );
1947 FETCH(&r
[1], 0, CHAN_Z
);
1948 FETCH(&r
[2], 1, CHAN_Z
);
1950 micro_mul( &r
[1], &r
[1], &r
[2] );
1951 micro_add( &r
[0], &r
[0], &r
[1] );
1953 FETCH(&r
[1], 0, CHAN_W
);
1954 FETCH(&r
[2], 1, CHAN_W
);
1956 micro_mul( &r
[1], &r
[1], &r
[2] );
1957 micro_add( &r
[0], &r
[0], &r
[1] );
1959 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1960 STORE( &r
[0], 0, chan_index
);
1964 case TGSI_OPCODE_DST
:
1965 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
1966 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
1969 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
1970 FETCH( &r
[0], 0, CHAN_Y
);
1971 FETCH( &r
[1], 1, CHAN_Y
);
1972 micro_mul( &r
[0], &r
[0], &r
[1] );
1973 STORE( &r
[0], 0, CHAN_Y
);
1976 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
1977 FETCH( &r
[0], 0, CHAN_Z
);
1978 STORE( &r
[0], 0, CHAN_Z
);
1981 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
1982 FETCH( &r
[0], 1, CHAN_W
);
1983 STORE( &r
[0], 0, CHAN_W
);
1987 case TGSI_OPCODE_MIN
:
1988 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1989 FETCH(&r
[0], 0, chan_index
);
1990 FETCH(&r
[1], 1, chan_index
);
1992 /* XXX use micro_min()?? */
1993 micro_lt( &r
[0], &r
[0], &r
[1], &r
[0], &r
[1] );
1995 STORE(&r
[0], 0, chan_index
);
1999 case TGSI_OPCODE_MAX
:
2000 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2001 FETCH(&r
[0], 0, chan_index
);
2002 FETCH(&r
[1], 1, chan_index
);
2004 /* XXX use micro_max()?? */
2005 micro_lt( &r
[0], &r
[0], &r
[1], &r
[1], &r
[0] );
2007 STORE(&r
[0], 0, chan_index
);
2011 case TGSI_OPCODE_SLT
:
2012 /* TGSI_OPCODE_SETLT */
2013 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2014 FETCH( &r
[0], 0, chan_index
);
2015 FETCH( &r
[1], 1, chan_index
);
2016 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
] );
2017 STORE( &r
[0], 0, chan_index
);
2021 case TGSI_OPCODE_SGE
:
2022 /* TGSI_OPCODE_SETGE */
2023 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2024 FETCH( &r
[0], 0, chan_index
);
2025 FETCH( &r
[1], 1, chan_index
);
2026 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
] );
2027 STORE( &r
[0], 0, chan_index
);
2031 case TGSI_OPCODE_MAD
:
2032 /* TGSI_OPCODE_MADD */
2033 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2034 FETCH( &r
[0], 0, chan_index
);
2035 FETCH( &r
[1], 1, chan_index
);
2036 micro_mul( &r
[0], &r
[0], &r
[1] );
2037 FETCH( &r
[1], 2, chan_index
);
2038 micro_add( &r
[0], &r
[0], &r
[1] );
2039 STORE( &r
[0], 0, chan_index
);
2043 case TGSI_OPCODE_SUB
:
2044 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2045 FETCH(&r
[0], 0, chan_index
);
2046 FETCH(&r
[1], 1, chan_index
);
2048 micro_sub( &r
[0], &r
[0], &r
[1] );
2050 STORE(&r
[0], 0, chan_index
);
2054 case TGSI_OPCODE_LERP
:
2055 /* TGSI_OPCODE_LRP */
2056 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2057 FETCH(&r
[0], 0, chan_index
);
2058 FETCH(&r
[1], 1, chan_index
);
2059 FETCH(&r
[2], 2, chan_index
);
2061 micro_sub( &r
[1], &r
[1], &r
[2] );
2062 micro_mul( &r
[0], &r
[0], &r
[1] );
2063 micro_add( &r
[0], &r
[0], &r
[2] );
2065 STORE(&r
[0], 0, chan_index
);
2069 case TGSI_OPCODE_CND
:
2073 case TGSI_OPCODE_CND0
:
2077 case TGSI_OPCODE_DOT2ADD
:
2078 /* TGSI_OPCODE_DP2A */
2079 FETCH( &r
[0], 0, CHAN_X
);
2080 FETCH( &r
[1], 1, CHAN_X
);
2081 micro_mul( &r
[0], &r
[0], &r
[1] );
2083 FETCH( &r
[1], 0, CHAN_Y
);
2084 FETCH( &r
[2], 1, CHAN_Y
);
2085 micro_mul( &r
[1], &r
[1], &r
[2] );
2086 micro_add( &r
[0], &r
[0], &r
[1] );
2088 FETCH( &r
[2], 2, CHAN_X
);
2089 micro_add( &r
[0], &r
[0], &r
[2] );
2091 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2092 STORE( &r
[0], 0, chan_index
);
2096 case TGSI_OPCODE_INDEX
:
2100 case TGSI_OPCODE_NEGATE
:
2104 case TGSI_OPCODE_FRAC
:
2105 /* TGSI_OPCODE_FRC */
2106 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2107 FETCH( &r
[0], 0, chan_index
);
2108 micro_frc( &r
[0], &r
[0] );
2109 STORE( &r
[0], 0, chan_index
);
2113 case TGSI_OPCODE_CLAMP
:
2117 case TGSI_OPCODE_FLOOR
:
2118 /* TGSI_OPCODE_FLR */
2119 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2120 FETCH( &r
[0], 0, chan_index
);
2121 micro_flr( &r
[0], &r
[0] );
2122 STORE( &r
[0], 0, chan_index
);
2126 case TGSI_OPCODE_ROUND
:
2127 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2128 FETCH( &r
[0], 0, chan_index
);
2129 micro_rnd( &r
[0], &r
[0] );
2130 STORE( &r
[0], 0, chan_index
);
2134 case TGSI_OPCODE_EXPBASE2
:
2135 /* TGSI_OPCODE_EX2 */
2136 FETCH(&r
[0], 0, CHAN_X
);
2139 micro_exp2( &r
[0], &r
[0] );
2141 micro_pow( &r
[0], &mach
->Temps
[TEMP_2_I
].xyzw
[TEMP_2_C
], &r
[0] );
2144 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2145 STORE( &r
[0], 0, chan_index
);
2149 case TGSI_OPCODE_LOGBASE2
:
2150 /* TGSI_OPCODE_LG2 */
2151 FETCH( &r
[0], 0, CHAN_X
);
2152 micro_lg2( &r
[0], &r
[0] );
2153 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2154 STORE( &r
[0], 0, chan_index
);
2158 case TGSI_OPCODE_POWER
:
2159 /* TGSI_OPCODE_POW */
2160 FETCH(&r
[0], 0, CHAN_X
);
2161 FETCH(&r
[1], 1, CHAN_X
);
2163 micro_pow( &r
[0], &r
[0], &r
[1] );
2165 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2166 STORE( &r
[0], 0, chan_index
);
2170 case TGSI_OPCODE_CROSSPRODUCT
:
2171 /* TGSI_OPCODE_XPD */
2172 FETCH(&r
[0], 0, CHAN_Y
);
2173 FETCH(&r
[1], 1, CHAN_Z
);
2175 micro_mul( &r
[2], &r
[0], &r
[1] );
2177 FETCH(&r
[3], 0, CHAN_Z
);
2178 FETCH(&r
[4], 1, CHAN_Y
);
2180 micro_mul( &r
[5], &r
[3], &r
[4] );
2181 micro_sub( &r
[2], &r
[2], &r
[5] );
2183 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2184 STORE( &r
[2], 0, CHAN_X
);
2187 FETCH(&r
[2], 1, CHAN_X
);
2189 micro_mul( &r
[3], &r
[3], &r
[2] );
2191 FETCH(&r
[5], 0, CHAN_X
);
2193 micro_mul( &r
[1], &r
[1], &r
[5] );
2194 micro_sub( &r
[3], &r
[3], &r
[1] );
2196 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2197 STORE( &r
[3], 0, CHAN_Y
);
2200 micro_mul( &r
[5], &r
[5], &r
[4] );
2201 micro_mul( &r
[0], &r
[0], &r
[2] );
2202 micro_sub( &r
[5], &r
[5], &r
[0] );
2204 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2205 STORE( &r
[5], 0, CHAN_Z
);
2208 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2209 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2213 case TGSI_OPCODE_MULTIPLYMATRIX
:
2217 case TGSI_OPCODE_ABS
:
2218 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2219 FETCH(&r
[0], 0, chan_index
);
2221 micro_abs( &r
[0], &r
[0] );
2223 STORE(&r
[0], 0, chan_index
);
2227 case TGSI_OPCODE_RCC
:
2231 case TGSI_OPCODE_DPH
:
2232 FETCH(&r
[0], 0, CHAN_X
);
2233 FETCH(&r
[1], 1, CHAN_X
);
2235 micro_mul( &r
[0], &r
[0], &r
[1] );
2237 FETCH(&r
[1], 0, CHAN_Y
);
2238 FETCH(&r
[2], 1, CHAN_Y
);
2240 micro_mul( &r
[1], &r
[1], &r
[2] );
2241 micro_add( &r
[0], &r
[0], &r
[1] );
2243 FETCH(&r
[1], 0, CHAN_Z
);
2244 FETCH(&r
[2], 1, CHAN_Z
);
2246 micro_mul( &r
[1], &r
[1], &r
[2] );
2247 micro_add( &r
[0], &r
[0], &r
[1] );
2249 FETCH(&r
[1], 1, CHAN_W
);
2251 micro_add( &r
[0], &r
[0], &r
[1] );
2253 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2254 STORE( &r
[0], 0, chan_index
);
2258 case TGSI_OPCODE_COS
:
2259 FETCH(&r
[0], 0, CHAN_X
);
2261 micro_cos( &r
[0], &r
[0] );
2263 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2264 STORE( &r
[0], 0, chan_index
);
2268 case TGSI_OPCODE_DDX
:
2269 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2270 FETCH( &r
[0], 0, chan_index
);
2271 micro_ddx( &r
[0], &r
[0] );
2272 STORE( &r
[0], 0, chan_index
);
2276 case TGSI_OPCODE_DDY
:
2277 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2278 FETCH( &r
[0], 0, chan_index
);
2279 micro_ddy( &r
[0], &r
[0] );
2280 STORE( &r
[0], 0, chan_index
);
2284 case TGSI_OPCODE_KILP
:
2285 exec_kilp (mach
, inst
);
2288 case TGSI_OPCODE_KIL
:
2289 exec_kil (mach
, inst
);
2292 case TGSI_OPCODE_PK2H
:
2296 case TGSI_OPCODE_PK2US
:
2300 case TGSI_OPCODE_PK4B
:
2304 case TGSI_OPCODE_PK4UB
:
2308 case TGSI_OPCODE_RFL
:
2312 case TGSI_OPCODE_SEQ
:
2313 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2314 FETCH( &r
[0], 0, chan_index
);
2315 FETCH( &r
[1], 1, chan_index
);
2316 micro_eq( &r
[0], &r
[0], &r
[1],
2317 &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
],
2318 &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
2319 STORE( &r
[0], 0, chan_index
);
2323 case TGSI_OPCODE_SFL
:
2327 case TGSI_OPCODE_SGT
:
2328 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2329 FETCH( &r
[0], 0, chan_index
);
2330 FETCH( &r
[1], 1, chan_index
);
2331 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
] );
2332 STORE( &r
[0], 0, chan_index
);
2336 case TGSI_OPCODE_SIN
:
2337 FETCH( &r
[0], 0, CHAN_X
);
2338 micro_sin( &r
[0], &r
[0] );
2339 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2340 STORE( &r
[0], 0, chan_index
);
2344 case TGSI_OPCODE_SLE
:
2345 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2346 FETCH( &r
[0], 0, chan_index
);
2347 FETCH( &r
[1], 1, chan_index
);
2348 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
] );
2349 STORE( &r
[0], 0, chan_index
);
2353 case TGSI_OPCODE_SNE
:
2354 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2355 FETCH( &r
[0], 0, chan_index
);
2356 FETCH( &r
[1], 1, chan_index
);
2357 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
] );
2358 STORE( &r
[0], 0, chan_index
);
2362 case TGSI_OPCODE_STR
:
2366 case TGSI_OPCODE_TEX
:
2367 /* simple texture lookup */
2368 /* src[0] = texcoord */
2369 /* src[1] = sampler unit */
2370 exec_tex(mach
, inst
, FALSE
, FALSE
);
2373 case TGSI_OPCODE_TXB
:
2374 /* Texture lookup with lod bias */
2375 /* src[0] = texcoord (src[0].w = LOD bias) */
2376 /* src[1] = sampler unit */
2377 exec_tex(mach
, inst
, TRUE
, FALSE
);
2380 case TGSI_OPCODE_TXD
:
2381 /* Texture lookup with explict partial derivatives */
2382 /* src[0] = texcoord */
2383 /* src[1] = d[strq]/dx */
2384 /* src[2] = d[strq]/dy */
2385 /* src[3] = sampler unit */
2389 case TGSI_OPCODE_TXL
:
2390 /* Texture lookup with explit LOD */
2391 /* src[0] = texcoord (src[0].w = LOD) */
2392 /* src[1] = sampler unit */
2393 exec_tex(mach
, inst
, TRUE
, FALSE
);
2396 case TGSI_OPCODE_TXP
:
2397 /* Texture lookup with projection */
2398 /* src[0] = texcoord (src[0].w = projection) */
2399 /* src[1] = sampler unit */
2400 exec_tex(mach
, inst
, FALSE
, TRUE
);
2403 case TGSI_OPCODE_UP2H
:
2407 case TGSI_OPCODE_UP2US
:
2411 case TGSI_OPCODE_UP4B
:
2415 case TGSI_OPCODE_UP4UB
:
2419 case TGSI_OPCODE_X2D
:
2423 case TGSI_OPCODE_ARA
:
2427 case TGSI_OPCODE_ARR
:
2431 case TGSI_OPCODE_BRA
:
2435 case TGSI_OPCODE_CAL
:
2436 /* skip the call if no execution channels are enabled */
2437 if (mach
->ExecMask
) {
2440 /* push the Cond, Loop, Cont stacks */
2441 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
2442 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
2443 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2444 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
2445 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2446 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
2448 assert(mach
->FuncStackTop
< TGSI_EXEC_MAX_CALL_NESTING
);
2449 mach
->FuncStack
[mach
->FuncStackTop
++] = mach
->FuncMask
;
2451 /* note that PC was already incremented above */
2452 mach
->CallStack
[mach
->CallStackTop
++] = *pc
;
2453 *pc
= inst
->InstructionExtLabel
.Label
;
2457 case TGSI_OPCODE_RET
:
2458 mach
->FuncMask
&= ~mach
->ExecMask
;
2459 UPDATE_EXEC_MASK(mach
);
2461 if (mach
->FuncMask
== 0x0) {
2462 /* really return now (otherwise, keep executing */
2464 if (mach
->CallStackTop
== 0) {
2465 /* returning from main() */
2469 *pc
= mach
->CallStack
[--mach
->CallStackTop
];
2471 /* pop the Cond, Loop, Cont stacks */
2472 assert(mach
->CondStackTop
> 0);
2473 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
2474 assert(mach
->LoopStackTop
> 0);
2475 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
2476 assert(mach
->ContStackTop
> 0);
2477 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
2478 assert(mach
->FuncStackTop
> 0);
2479 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
2481 UPDATE_EXEC_MASK(mach
);
2485 case TGSI_OPCODE_SSG
:
2489 case TGSI_OPCODE_CMP
:
2490 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2491 FETCH(&r
[0], 0, chan_index
);
2492 FETCH(&r
[1], 1, chan_index
);
2493 FETCH(&r
[2], 2, chan_index
);
2495 micro_lt( &r
[0], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &r
[1], &r
[2] );
2497 STORE(&r
[0], 0, chan_index
);
2501 case TGSI_OPCODE_SCS
:
2502 if( IS_CHANNEL_ENABLED( *inst
, CHAN_X
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) ) {
2503 FETCH( &r
[0], 0, CHAN_X
);
2505 if( IS_CHANNEL_ENABLED( *inst
, CHAN_X
) ) {
2506 micro_cos( &r
[1], &r
[0] );
2507 STORE( &r
[1], 0, CHAN_X
);
2509 if( IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) ) {
2510 micro_sin( &r
[1], &r
[0] );
2511 STORE( &r
[1], 0, CHAN_Y
);
2513 if( IS_CHANNEL_ENABLED( *inst
, CHAN_Z
) ) {
2514 STORE( &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, CHAN_Z
);
2516 if( IS_CHANNEL_ENABLED( *inst
, CHAN_W
) ) {
2517 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2521 case TGSI_OPCODE_NRM
:
2522 /* 3-component vector normalize */
2524 union tgsi_exec_channel tmp
, dot
;
2526 /* tmp = dp3(src0, src0): */
2527 FETCH( &r
[0], 0, CHAN_X
);
2528 micro_mul( &tmp
, &r
[0], &r
[0] );
2530 FETCH( &r
[1], 0, CHAN_Y
);
2531 micro_mul( &dot
, &r
[1], &r
[1] );
2532 micro_add( &tmp
, &tmp
, &dot
);
2534 FETCH( &r
[2], 0, CHAN_Z
);
2535 micro_mul( &dot
, &r
[2], &r
[2] );
2536 micro_add( &tmp
, &tmp
, &dot
);
2538 /* tmp = 1 / sqrt(tmp) */
2539 micro_sqrt( &tmp
, &tmp
);
2540 micro_div( &tmp
, &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &tmp
);
2542 /* note: w channel is undefined */
2543 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2544 /* chan = chan * tmp */
2545 micro_mul( &r
[chan_index
], &tmp
, &r
[chan_index
] );
2546 STORE( &r
[chan_index
], 0, chan_index
);
2551 case TGSI_OPCODE_NRM4
:
2552 /* 4-component vector normalize */
2554 union tgsi_exec_channel tmp
, dot
;
2556 /* tmp = dp4(src0, src0): */
2557 FETCH( &r
[0], 0, CHAN_X
);
2558 micro_mul( &tmp
, &r
[0], &r
[0] );
2560 FETCH( &r
[1], 0, CHAN_Y
);
2561 micro_mul( &dot
, &r
[1], &r
[1] );
2562 micro_add( &tmp
, &tmp
, &dot
);
2564 FETCH( &r
[2], 0, CHAN_Z
);
2565 micro_mul( &dot
, &r
[2], &r
[2] );
2566 micro_add( &tmp
, &tmp
, &dot
);
2568 FETCH( &r
[3], 0, CHAN_W
);
2569 micro_mul( &dot
, &r
[3], &r
[3] );
2570 micro_add( &tmp
, &tmp
, &dot
);
2572 /* tmp = 1 / sqrt(tmp) */
2573 micro_sqrt( &tmp
, &tmp
);
2574 micro_div( &tmp
, &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &tmp
);
2576 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2577 /* chan = chan * tmp */
2578 micro_mul( &r
[chan_index
], &tmp
, &r
[chan_index
] );
2579 STORE( &r
[chan_index
], 0, chan_index
);
2584 case TGSI_OPCODE_DIV
:
2588 case TGSI_OPCODE_DP2
:
2589 FETCH( &r
[0], 0, CHAN_X
);
2590 FETCH( &r
[1], 1, CHAN_X
);
2591 micro_mul( &r
[0], &r
[0], &r
[1] );
2593 FETCH( &r
[1], 0, CHAN_Y
);
2594 FETCH( &r
[2], 1, CHAN_Y
);
2595 micro_mul( &r
[1], &r
[1], &r
[2] );
2596 micro_add( &r
[0], &r
[0], &r
[1] );
2598 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2599 STORE( &r
[0], 0, chan_index
);
2603 case TGSI_OPCODE_IF
:
2605 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
2606 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
2607 FETCH( &r
[0], 0, CHAN_X
);
2608 /* update CondMask */
2610 mach
->CondMask
&= ~0x1;
2613 mach
->CondMask
&= ~0x2;
2616 mach
->CondMask
&= ~0x4;
2619 mach
->CondMask
&= ~0x8;
2621 UPDATE_EXEC_MASK(mach
);
2622 /* Todo: If CondMask==0, jump to ELSE */
2625 case TGSI_OPCODE_ELSE
:
2626 /* invert CondMask wrt previous mask */
2629 assert(mach
->CondStackTop
> 0);
2630 prevMask
= mach
->CondStack
[mach
->CondStackTop
- 1];
2631 mach
->CondMask
= ~mach
->CondMask
& prevMask
;
2632 UPDATE_EXEC_MASK(mach
);
2633 /* Todo: If CondMask==0, jump to ENDIF */
2637 case TGSI_OPCODE_ENDIF
:
2639 assert(mach
->CondStackTop
> 0);
2640 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
2641 UPDATE_EXEC_MASK(mach
);
2644 case TGSI_OPCODE_END
:
2645 /* halt execution */
2649 case TGSI_OPCODE_REP
:
2653 case TGSI_OPCODE_ENDREP
:
2657 case TGSI_OPCODE_PUSHA
:
2661 case TGSI_OPCODE_POPA
:
2665 case TGSI_OPCODE_CEIL
:
2666 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2667 FETCH( &r
[0], 0, chan_index
);
2668 micro_ceil( &r
[0], &r
[0] );
2669 STORE( &r
[0], 0, chan_index
);
2673 case TGSI_OPCODE_I2F
:
2674 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2675 FETCH( &r
[0], 0, chan_index
);
2676 micro_i2f( &r
[0], &r
[0] );
2677 STORE( &r
[0], 0, chan_index
);
2681 case TGSI_OPCODE_NOT
:
2682 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2683 FETCH( &r
[0], 0, chan_index
);
2684 micro_not( &r
[0], &r
[0] );
2685 STORE( &r
[0], 0, chan_index
);
2689 case TGSI_OPCODE_TRUNC
:
2690 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2691 FETCH( &r
[0], 0, chan_index
);
2692 micro_trunc( &r
[0], &r
[0] );
2693 STORE( &r
[0], 0, chan_index
);
2697 case TGSI_OPCODE_SHL
:
2698 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2699 FETCH( &r
[0], 0, chan_index
);
2700 FETCH( &r
[1], 1, chan_index
);
2701 micro_shl( &r
[0], &r
[0], &r
[1] );
2702 STORE( &r
[0], 0, chan_index
);
2706 case TGSI_OPCODE_SHR
:
2707 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2708 FETCH( &r
[0], 0, chan_index
);
2709 FETCH( &r
[1], 1, chan_index
);
2710 micro_ishr( &r
[0], &r
[0], &r
[1] );
2711 STORE( &r
[0], 0, chan_index
);
2715 case TGSI_OPCODE_AND
:
2716 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2717 FETCH( &r
[0], 0, chan_index
);
2718 FETCH( &r
[1], 1, chan_index
);
2719 micro_and( &r
[0], &r
[0], &r
[1] );
2720 STORE( &r
[0], 0, chan_index
);
2724 case TGSI_OPCODE_OR
:
2725 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2726 FETCH( &r
[0], 0, chan_index
);
2727 FETCH( &r
[1], 1, chan_index
);
2728 micro_or( &r
[0], &r
[0], &r
[1] );
2729 STORE( &r
[0], 0, chan_index
);
2733 case TGSI_OPCODE_MOD
:
2737 case TGSI_OPCODE_XOR
:
2738 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2739 FETCH( &r
[0], 0, chan_index
);
2740 FETCH( &r
[1], 1, chan_index
);
2741 micro_xor( &r
[0], &r
[0], &r
[1] );
2742 STORE( &r
[0], 0, chan_index
);
2746 case TGSI_OPCODE_SAD
:
2750 case TGSI_OPCODE_TXF
:
2754 case TGSI_OPCODE_TXQ
:
2758 case TGSI_OPCODE_EMIT
:
2759 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] += 16;
2760 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]]++;
2763 case TGSI_OPCODE_ENDPRIM
:
2764 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]++;
2765 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]] = 0;
2768 case TGSI_OPCODE_LOOP
:
2769 /* fall-through (for now) */
2770 case TGSI_OPCODE_BGNLOOP2
:
2771 /* push LoopMask and ContMasks */
2772 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2773 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
2774 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2775 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
2778 case TGSI_OPCODE_ENDLOOP
:
2779 /* fall-through (for now at least) */
2780 case TGSI_OPCODE_ENDLOOP2
:
2781 /* Restore ContMask, but don't pop */
2782 assert(mach
->ContStackTop
> 0);
2783 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
2784 UPDATE_EXEC_MASK(mach
);
2785 if (mach
->ExecMask
) {
2786 /* repeat loop: jump to instruction just past BGNLOOP */
2787 *pc
= inst
->InstructionExtLabel
.Label
+ 1;
2790 /* exit loop: pop LoopMask */
2791 assert(mach
->LoopStackTop
> 0);
2792 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
2794 assert(mach
->ContStackTop
> 0);
2795 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
2797 UPDATE_EXEC_MASK(mach
);
2800 case TGSI_OPCODE_BRK
:
2801 /* turn off loop channels for each enabled exec channel */
2802 mach
->LoopMask
&= ~mach
->ExecMask
;
2803 /* Todo: if mach->LoopMask == 0, jump to end of loop */
2804 UPDATE_EXEC_MASK(mach
);
2807 case TGSI_OPCODE_CONT
:
2808 /* turn off cont channels for each enabled exec channel */
2809 mach
->ContMask
&= ~mach
->ExecMask
;
2810 /* Todo: if mach->LoopMask == 0, jump to end of loop */
2811 UPDATE_EXEC_MASK(mach
);
2814 case TGSI_OPCODE_BGNSUB
:
2818 case TGSI_OPCODE_ENDSUB
:
2822 case TGSI_OPCODE_NOISE1
:
2826 case TGSI_OPCODE_NOISE2
:
2830 case TGSI_OPCODE_NOISE3
:
2834 case TGSI_OPCODE_NOISE4
:
2838 case TGSI_OPCODE_NOP
:
2848 * Run TGSI interpreter.
2849 * \return bitmask of "alive" quad components
2852 tgsi_exec_machine_run( struct tgsi_exec_machine
*mach
)
2857 mach
->CondMask
= 0xf;
2858 mach
->LoopMask
= 0xf;
2859 mach
->ContMask
= 0xf;
2860 mach
->FuncMask
= 0xf;
2861 mach
->ExecMask
= 0xf;
2863 mach
->CondStackTop
= 0; /* temporarily subvert this assertion */
2864 assert(mach
->CondStackTop
== 0);
2865 assert(mach
->LoopStackTop
== 0);
2866 assert(mach
->ContStackTop
== 0);
2867 assert(mach
->CallStackTop
== 0);
2869 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] = 0;
2870 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] = 0;
2872 if( mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
2873 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0] = 0;
2874 mach
->Primitives
[0] = 0;
2877 for (i
= 0; i
< QUAD_SIZE
; i
++) {
2878 mach
->Temps
[TEMP_CC_I
].xyzw
[TEMP_CC_C
].u
[i
] =
2879 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_X_SHIFT
) |
2880 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Y_SHIFT
) |
2881 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Z_SHIFT
) |
2882 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_W_SHIFT
);
2885 /* execute declarations (interpolants) */
2886 for (i
= 0; i
< mach
->NumDeclarations
; i
++) {
2887 exec_declaration( mach
, mach
->Declarations
+i
);
2890 /* execute instructions, until pc is set to -1 */
2892 assert(pc
< (int) mach
->NumInstructions
);
2893 exec_instruction( mach
, mach
->Instructions
+ pc
, &pc
);
2897 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
2898 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
2900 * Scale back depth component.
2902 for (i
= 0; i
< 4; i
++)
2903 mach
->Outputs
[0].xyzw
[2].f
[i
] *= ctx
->DrawBuffer
->_DepthMaxF
;
2907 return ~mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];