1 /**************************************************************************
3 * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 * TGSI interpreter/executor.
31 * Flow control information:
33 * Since we operate on 'quads' (4 pixels or 4 vertices in parallel)
34 * flow control statements (IF/ELSE/ENDIF, LOOP/ENDLOOP) require special
35 * care since a condition may be true for some quad components but false
36 * for other components.
38 * We basically execute all statements (even if they're in the part of
39 * an IF/ELSE clause that's "not taken") and use a special mask to
40 * control writing to destination registers. This is the ExecMask.
43 * The ExecMask is computed from three other masks (CondMask, LoopMask and
44 * ContMask) which are controlled by the flow control instructions (namely:
45 * (IF/ELSE/ENDIF, LOOP/ENDLOOP and CONT).
53 #include "pipe/p_compiler.h"
54 #include "pipe/p_state.h"
55 #include "pipe/p_shader_tokens.h"
56 #include "tgsi/tgsi_dump.h"
57 #include "tgsi/tgsi_parse.h"
58 #include "tgsi/tgsi_util.h"
59 #include "tgsi_exec.h"
60 #include "util/u_memory.h"
61 #include "util/u_math.h"
65 #define TILE_TOP_LEFT 0
66 #define TILE_TOP_RIGHT 1
67 #define TILE_BOTTOM_LEFT 2
68 #define TILE_BOTTOM_RIGHT 3
76 * Shorthand locations of various utility registers (_I = Index, _C = Channel)
78 #define TEMP_0_I TGSI_EXEC_TEMP_00000000_I
79 #define TEMP_0_C TGSI_EXEC_TEMP_00000000_C
80 #define TEMP_7F_I TGSI_EXEC_TEMP_7FFFFFFF_I
81 #define TEMP_7F_C TGSI_EXEC_TEMP_7FFFFFFF_C
82 #define TEMP_80_I TGSI_EXEC_TEMP_80000000_I
83 #define TEMP_80_C TGSI_EXEC_TEMP_80000000_C
84 #define TEMP_FF_I TGSI_EXEC_TEMP_FFFFFFFF_I
85 #define TEMP_FF_C TGSI_EXEC_TEMP_FFFFFFFF_C
86 #define TEMP_1_I TGSI_EXEC_TEMP_ONE_I
87 #define TEMP_1_C TGSI_EXEC_TEMP_ONE_C
88 #define TEMP_2_I TGSI_EXEC_TEMP_TWO_I
89 #define TEMP_2_C TGSI_EXEC_TEMP_TWO_C
90 #define TEMP_128_I TGSI_EXEC_TEMP_128_I
91 #define TEMP_128_C TGSI_EXEC_TEMP_128_C
92 #define TEMP_M128_I TGSI_EXEC_TEMP_MINUS_128_I
93 #define TEMP_M128_C TGSI_EXEC_TEMP_MINUS_128_C
94 #define TEMP_KILMASK_I TGSI_EXEC_TEMP_KILMASK_I
95 #define TEMP_KILMASK_C TGSI_EXEC_TEMP_KILMASK_C
96 #define TEMP_OUTPUT_I TGSI_EXEC_TEMP_OUTPUT_I
97 #define TEMP_OUTPUT_C TGSI_EXEC_TEMP_OUTPUT_C
98 #define TEMP_PRIMITIVE_I TGSI_EXEC_TEMP_PRIMITIVE_I
99 #define TEMP_PRIMITIVE_C TGSI_EXEC_TEMP_PRIMITIVE_C
100 #define TEMP_CC_I TGSI_EXEC_TEMP_CC_I
101 #define TEMP_CC_C TGSI_EXEC_TEMP_CC_C
102 #define TEMP_3_I TGSI_EXEC_TEMP_THREE_I
103 #define TEMP_3_C TGSI_EXEC_TEMP_THREE_C
104 #define TEMP_HALF_I TGSI_EXEC_TEMP_HALF_I
105 #define TEMP_HALF_C TGSI_EXEC_TEMP_HALF_C
106 #define TEMP_R0 TGSI_EXEC_TEMP_R0
107 #define TEMP_P0 TGSI_EXEC_TEMP_P0
109 #define IS_CHANNEL_ENABLED(INST, CHAN)\
110 ((INST).Dst[0].Register.WriteMask & (1 << (CHAN)))
112 #define IS_CHANNEL_ENABLED2(INST, CHAN)\
113 ((INST).Dst[1].Register.WriteMask & (1 << (CHAN)))
115 #define FOR_EACH_ENABLED_CHANNEL(INST, CHAN)\
116 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)\
117 if (IS_CHANNEL_ENABLED( INST, CHAN ))
119 #define FOR_EACH_ENABLED_CHANNEL2(INST, CHAN)\
120 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)\
121 if (IS_CHANNEL_ENABLED2( INST, CHAN ))
124 /** The execution mask depends on the conditional mask and the loop mask */
125 #define UPDATE_EXEC_MASK(MACH) \
126 MACH->ExecMask = MACH->CondMask & MACH->LoopMask & MACH->ContMask & MACH->FuncMask
129 static const union tgsi_exec_channel ZeroVec
=
130 { { 0.0, 0.0, 0.0, 0.0 } };
135 check_inf_or_nan(const union tgsi_exec_channel
*chan
)
137 assert(!util_is_inf_or_nan(chan
->f
[0]));
138 assert(!util_is_inf_or_nan(chan
->f
[1]));
139 assert(!util_is_inf_or_nan(chan
->f
[2]));
140 assert(!util_is_inf_or_nan(chan
->f
[3]));
147 print_chan(const char *msg
, const union tgsi_exec_channel
*chan
)
149 debug_printf("%s = {%f, %f, %f, %f}\n",
150 msg
, chan
->f
[0], chan
->f
[1], chan
->f
[2], chan
->f
[3]);
157 print_temp(const struct tgsi_exec_machine
*mach
, uint index
)
159 const struct tgsi_exec_vector
*tmp
= &mach
->Temps
[index
];
161 debug_printf("Temp[%u] =\n", index
);
162 for (i
= 0; i
< 4; i
++) {
163 debug_printf(" %c: { %f, %f, %f, %f }\n",
175 * Check if there's a potential src/dst register data dependency when
176 * using SOA execution.
179 * This would expand into:
184 * The second instruction will have the wrong value for t0 if executed as-is.
187 tgsi_check_soa_dependencies(const struct tgsi_full_instruction
*inst
)
191 uint writemask
= inst
->Dst
[0].Register
.WriteMask
;
192 if (writemask
== TGSI_WRITEMASK_X
||
193 writemask
== TGSI_WRITEMASK_Y
||
194 writemask
== TGSI_WRITEMASK_Z
||
195 writemask
== TGSI_WRITEMASK_W
||
196 writemask
== TGSI_WRITEMASK_NONE
) {
197 /* no chance of data dependency */
201 /* loop over src regs */
202 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
203 if ((inst
->Src
[i
].Register
.File
==
204 inst
->Dst
[0].Register
.File
) &&
205 (inst
->Src
[i
].Register
.Index
==
206 inst
->Dst
[0].Register
.Index
)) {
207 /* loop over dest channels */
208 uint channelsWritten
= 0x0;
209 FOR_EACH_ENABLED_CHANNEL(*inst
, chan
) {
210 /* check if we're reading a channel that's been written */
211 uint swizzle
= tgsi_util_get_full_src_register_swizzle(&inst
->Src
[i
], chan
);
212 if (channelsWritten
& (1 << swizzle
)) {
216 channelsWritten
|= (1 << chan
);
225 * Initialize machine state by expanding tokens to full instructions,
226 * allocating temporary storage, setting up constants, etc.
227 * After this, we can call tgsi_exec_machine_run() many times.
230 tgsi_exec_machine_bind_shader(
231 struct tgsi_exec_machine
*mach
,
232 const struct tgsi_token
*tokens
,
234 struct tgsi_sampler
**samplers
)
237 struct tgsi_parse_context parse
;
238 struct tgsi_exec_labels
*labels
= &mach
->Labels
;
239 struct tgsi_full_instruction
*instructions
;
240 struct tgsi_full_declaration
*declarations
;
241 uint maxInstructions
= 10, numInstructions
= 0;
242 uint maxDeclarations
= 10, numDeclarations
= 0;
246 tgsi_dump(tokens
, 0);
251 mach
->Tokens
= tokens
;
252 mach
->Samplers
= samplers
;
254 k
= tgsi_parse_init (&parse
, mach
->Tokens
);
255 if (k
!= TGSI_PARSE_OK
) {
256 debug_printf( "Problem parsing!\n" );
260 mach
->Processor
= parse
.FullHeader
.Processor
.Processor
;
264 declarations
= (struct tgsi_full_declaration
*)
265 MALLOC( maxDeclarations
* sizeof(struct tgsi_full_declaration
) );
271 instructions
= (struct tgsi_full_instruction
*)
272 MALLOC( maxInstructions
* sizeof(struct tgsi_full_instruction
) );
275 FREE( declarations
);
279 while( !tgsi_parse_end_of_tokens( &parse
) ) {
280 uint pointer
= parse
.Position
;
283 tgsi_parse_token( &parse
);
284 switch( parse
.FullToken
.Token
.Type
) {
285 case TGSI_TOKEN_TYPE_DECLARATION
:
286 /* save expanded declaration */
287 if (numDeclarations
== maxDeclarations
) {
288 declarations
= REALLOC(declarations
,
290 * sizeof(struct tgsi_full_declaration
),
291 (maxDeclarations
+ 10)
292 * sizeof(struct tgsi_full_declaration
));
293 maxDeclarations
+= 10;
295 if (parse
.FullToken
.FullDeclaration
.Declaration
.File
== TGSI_FILE_OUTPUT
) {
297 for (reg
= parse
.FullToken
.FullDeclaration
.Range
.First
;
298 reg
<= parse
.FullToken
.FullDeclaration
.Range
.Last
;
303 memcpy(declarations
+ numDeclarations
,
304 &parse
.FullToken
.FullDeclaration
,
305 sizeof(declarations
[0]));
309 case TGSI_TOKEN_TYPE_IMMEDIATE
:
311 uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
313 assert( mach
->ImmLimit
+ 1 <= TGSI_EXEC_NUM_IMMEDIATES
);
315 for( i
= 0; i
< size
; i
++ ) {
316 mach
->Imms
[mach
->ImmLimit
][i
] =
317 parse
.FullToken
.FullImmediate
.u
[i
].Float
;
323 case TGSI_TOKEN_TYPE_INSTRUCTION
:
324 assert( labels
->count
< MAX_LABELS
);
326 labels
->labels
[labels
->count
][0] = instno
;
327 labels
->labels
[labels
->count
][1] = pointer
;
330 /* save expanded instruction */
331 if (numInstructions
== maxInstructions
) {
332 instructions
= REALLOC(instructions
,
334 * sizeof(struct tgsi_full_instruction
),
335 (maxInstructions
+ 10)
336 * sizeof(struct tgsi_full_instruction
));
337 maxInstructions
+= 10;
340 memcpy(instructions
+ numInstructions
,
341 &parse
.FullToken
.FullInstruction
,
342 sizeof(instructions
[0]));
347 case TGSI_TOKEN_TYPE_PROPERTY
:
354 tgsi_parse_free (&parse
);
356 if (mach
->Declarations
) {
357 FREE( mach
->Declarations
);
359 mach
->Declarations
= declarations
;
360 mach
->NumDeclarations
= numDeclarations
;
362 if (mach
->Instructions
) {
363 FREE( mach
->Instructions
);
365 mach
->Instructions
= instructions
;
366 mach
->NumInstructions
= numInstructions
;
370 struct tgsi_exec_machine
*
371 tgsi_exec_machine_create( void )
373 struct tgsi_exec_machine
*mach
;
376 mach
= align_malloc( sizeof *mach
, 16 );
380 memset(mach
, 0, sizeof(*mach
));
382 mach
->Addrs
= &mach
->Temps
[TGSI_EXEC_TEMP_ADDR
];
383 mach
->MaxGeometryShaderOutputs
= TGSI_MAX_TOTAL_VERTICES
;
384 mach
->Predicates
= &mach
->Temps
[TGSI_EXEC_TEMP_P0
];
386 /* Setup constants. */
387 for( i
= 0; i
< 4; i
++ ) {
388 mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
].u
[i
] = 0x00000000;
389 mach
->Temps
[TEMP_7F_I
].xyzw
[TEMP_7F_C
].u
[i
] = 0x7FFFFFFF;
390 mach
->Temps
[TEMP_80_I
].xyzw
[TEMP_80_C
].u
[i
] = 0x80000000;
391 mach
->Temps
[TEMP_FF_I
].xyzw
[TEMP_FF_C
].u
[i
] = 0xFFFFFFFF;
392 mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
].f
[i
] = 1.0f
;
393 mach
->Temps
[TEMP_2_I
].xyzw
[TEMP_2_C
].f
[i
] = 2.0f
;
394 mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
].f
[i
] = 128.0f
;
395 mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
].f
[i
] = -128.0f
;
396 mach
->Temps
[TEMP_3_I
].xyzw
[TEMP_3_C
].f
[i
] = 3.0f
;
397 mach
->Temps
[TEMP_HALF_I
].xyzw
[TEMP_HALF_C
].f
[i
] = 0.5f
;
401 /* silence warnings */
415 tgsi_exec_machine_destroy(struct tgsi_exec_machine
*mach
)
418 FREE(mach
->Instructions
);
419 FREE(mach
->Declarations
);
428 union tgsi_exec_channel
*dst
,
429 const union tgsi_exec_channel
*src
)
431 dst
->f
[0] = fabsf( src
->f
[0] );
432 dst
->f
[1] = fabsf( src
->f
[1] );
433 dst
->f
[2] = fabsf( src
->f
[2] );
434 dst
->f
[3] = fabsf( src
->f
[3] );
439 union tgsi_exec_channel
*dst
,
440 const union tgsi_exec_channel
*src0
,
441 const union tgsi_exec_channel
*src1
)
443 dst
->f
[0] = src0
->f
[0] + src1
->f
[0];
444 dst
->f
[1] = src0
->f
[1] + src1
->f
[1];
445 dst
->f
[2] = src0
->f
[2] + src1
->f
[2];
446 dst
->f
[3] = src0
->f
[3] + src1
->f
[3];
451 union tgsi_exec_channel
*dst
,
452 const union tgsi_exec_channel
*src
)
454 dst
->f
[0] = ceilf( src
->f
[0] );
455 dst
->f
[1] = ceilf( src
->f
[1] );
456 dst
->f
[2] = ceilf( src
->f
[2] );
457 dst
->f
[3] = ceilf( src
->f
[3] );
462 union tgsi_exec_channel
*dst
,
463 const union tgsi_exec_channel
*src
)
465 dst
->f
[0] = cosf( src
->f
[0] );
466 dst
->f
[1] = cosf( src
->f
[1] );
467 dst
->f
[2] = cosf( src
->f
[2] );
468 dst
->f
[3] = cosf( src
->f
[3] );
473 union tgsi_exec_channel
*dst
,
474 const union tgsi_exec_channel
*src
)
479 dst
->f
[3] = src
->f
[TILE_BOTTOM_RIGHT
] - src
->f
[TILE_BOTTOM_LEFT
];
484 union tgsi_exec_channel
*dst
,
485 const union tgsi_exec_channel
*src
)
490 dst
->f
[3] = src
->f
[TILE_BOTTOM_LEFT
] - src
->f
[TILE_TOP_LEFT
];
495 union tgsi_exec_channel
*dst
,
496 const union tgsi_exec_channel
*src0
,
497 const union tgsi_exec_channel
*src1
)
499 if (src1
->f
[0] != 0) {
500 dst
->f
[0] = src0
->f
[0] / src1
->f
[0];
502 if (src1
->f
[1] != 0) {
503 dst
->f
[1] = src0
->f
[1] / src1
->f
[1];
505 if (src1
->f
[2] != 0) {
506 dst
->f
[2] = src0
->f
[2] / src1
->f
[2];
508 if (src1
->f
[3] != 0) {
509 dst
->f
[3] = src0
->f
[3] / src1
->f
[3];
515 union tgsi_exec_channel
*dst
,
516 const union tgsi_exec_channel
*src0
,
517 const union tgsi_exec_channel
*src1
,
518 const union tgsi_exec_channel
*src2
,
519 const union tgsi_exec_channel
*src3
)
521 dst
->f
[0] = src0
->f
[0] == src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
522 dst
->f
[1] = src0
->f
[1] == src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
523 dst
->f
[2] = src0
->f
[2] == src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
524 dst
->f
[3] = src0
->f
[3] == src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
529 union tgsi_exec_channel
*dst
,
530 const union tgsi_exec_channel
*src
)
533 dst
->f
[0] = util_fast_exp2( src
->f
[0] );
534 dst
->f
[1] = util_fast_exp2( src
->f
[1] );
535 dst
->f
[2] = util_fast_exp2( src
->f
[2] );
536 dst
->f
[3] = util_fast_exp2( src
->f
[3] );
540 /* Inf is okay for this instruction, so clamp it to silence assertions. */
542 union tgsi_exec_channel clamped
;
544 for (i
= 0; i
< 4; i
++) {
545 if (src
->f
[i
] > 127.99999f
) {
546 clamped
.f
[i
] = 127.99999f
;
547 } else if (src
->f
[i
] < -126.99999f
) {
548 clamped
.f
[i
] = -126.99999f
;
550 clamped
.f
[i
] = src
->f
[i
];
556 dst
->f
[0] = powf( 2.0f
, src
->f
[0] );
557 dst
->f
[1] = powf( 2.0f
, src
->f
[1] );
558 dst
->f
[2] = powf( 2.0f
, src
->f
[2] );
559 dst
->f
[3] = powf( 2.0f
, src
->f
[3] );
564 micro_float_clamp(union tgsi_exec_channel
*dst
,
565 const union tgsi_exec_channel
*src
)
569 for (i
= 0; i
< 4; i
++) {
570 if (src
->f
[i
] > 0.0f
) {
571 if (src
->f
[i
] > 1.884467e+019f
)
572 dst
->f
[i
] = 1.884467e+019f
;
573 else if (src
->f
[i
] < 5.42101e-020f
)
574 dst
->f
[i
] = 5.42101e-020f
;
576 dst
->f
[i
] = src
->f
[i
];
579 if (src
->f
[i
] < -1.884467e+019f
)
580 dst
->f
[i
] = -1.884467e+019f
;
581 else if (src
->f
[i
] > -5.42101e-020f
)
582 dst
->f
[i
] = -5.42101e-020f
;
584 dst
->f
[i
] = src
->f
[i
];
591 union tgsi_exec_channel
*dst
,
592 const union tgsi_exec_channel
*src
)
594 dst
->f
[0] = floorf( src
->f
[0] );
595 dst
->f
[1] = floorf( src
->f
[1] );
596 dst
->f
[2] = floorf( src
->f
[2] );
597 dst
->f
[3] = floorf( src
->f
[3] );
602 union tgsi_exec_channel
*dst
,
603 const union tgsi_exec_channel
*src
)
605 dst
->f
[0] = src
->f
[0] - floorf( src
->f
[0] );
606 dst
->f
[1] = src
->f
[1] - floorf( src
->f
[1] );
607 dst
->f
[2] = src
->f
[2] - floorf( src
->f
[2] );
608 dst
->f
[3] = src
->f
[3] - floorf( src
->f
[3] );
613 union tgsi_exec_channel
*dst
,
614 const union tgsi_exec_channel
*src
)
617 dst
->f
[0] = util_fast_log2( src
->f
[0] );
618 dst
->f
[1] = util_fast_log2( src
->f
[1] );
619 dst
->f
[2] = util_fast_log2( src
->f
[2] );
620 dst
->f
[3] = util_fast_log2( src
->f
[3] );
622 dst
->f
[0] = logf( src
->f
[0] ) * 1.442695f
;
623 dst
->f
[1] = logf( src
->f
[1] ) * 1.442695f
;
624 dst
->f
[2] = logf( src
->f
[2] ) * 1.442695f
;
625 dst
->f
[3] = logf( src
->f
[3] ) * 1.442695f
;
631 union tgsi_exec_channel
*dst
,
632 const union tgsi_exec_channel
*src0
,
633 const union tgsi_exec_channel
*src1
,
634 const union tgsi_exec_channel
*src2
,
635 const union tgsi_exec_channel
*src3
)
637 dst
->f
[0] = src0
->f
[0] <= src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
638 dst
->f
[1] = src0
->f
[1] <= src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
639 dst
->f
[2] = src0
->f
[2] <= src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
640 dst
->f
[3] = src0
->f
[3] <= src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
645 union tgsi_exec_channel
*dst
,
646 const union tgsi_exec_channel
*src0
,
647 const union tgsi_exec_channel
*src1
,
648 const union tgsi_exec_channel
*src2
,
649 const union tgsi_exec_channel
*src3
)
651 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
652 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
653 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
654 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
659 union tgsi_exec_channel
*dst
,
660 const union tgsi_exec_channel
*src0
,
661 const union tgsi_exec_channel
*src1
)
663 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
664 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
665 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
666 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
671 union tgsi_exec_channel
*dst
,
672 const union tgsi_exec_channel
*src0
,
673 const union tgsi_exec_channel
*src1
)
675 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
676 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
677 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
678 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
684 union tgsi_exec_channel
*dst
,
685 const union tgsi_exec_channel
*src0
,
686 const union tgsi_exec_channel
*src1
)
688 dst
->u
[0] = src0
->u
[0] % src1
->u
[0];
689 dst
->u
[1] = src0
->u
[1] % src1
->u
[1];
690 dst
->u
[2] = src0
->u
[2] % src1
->u
[2];
691 dst
->u
[3] = src0
->u
[3] % src1
->u
[3];
697 union tgsi_exec_channel
*dst
,
698 const union tgsi_exec_channel
*src0
,
699 const union tgsi_exec_channel
*src1
)
701 dst
->f
[0] = src0
->f
[0] * src1
->f
[0];
702 dst
->f
[1] = src0
->f
[1] * src1
->f
[1];
703 dst
->f
[2] = src0
->f
[2] * src1
->f
[2];
704 dst
->f
[3] = src0
->f
[3] * src1
->f
[3];
710 union tgsi_exec_channel
*dst0
,
711 union tgsi_exec_channel
*dst1
,
712 const union tgsi_exec_channel
*src0
,
713 const union tgsi_exec_channel
*src1
)
715 dst1
->i
[0] = src0
->i
[0] * src1
->i
[0];
716 dst1
->i
[1] = src0
->i
[1] * src1
->i
[1];
717 dst1
->i
[2] = src0
->i
[2] * src1
->i
[2];
718 dst1
->i
[3] = src0
->i
[3] * src1
->i
[3];
729 union tgsi_exec_channel
*dst0
,
730 union tgsi_exec_channel
*dst1
,
731 const union tgsi_exec_channel
*src0
,
732 const union tgsi_exec_channel
*src1
)
734 dst1
->u
[0] = src0
->u
[0] * src1
->u
[0];
735 dst1
->u
[1] = src0
->u
[1] * src1
->u
[1];
736 dst1
->u
[2] = src0
->u
[2] * src1
->u
[2];
737 dst1
->u
[3] = src0
->u
[3] * src1
->u
[3];
749 union tgsi_exec_channel
*dst
,
750 const union tgsi_exec_channel
*src0
,
751 const union tgsi_exec_channel
*src1
,
752 const union tgsi_exec_channel
*src2
)
754 dst
->u
[0] = src0
->u
[0] ? src1
->u
[0] : src2
->u
[0];
755 dst
->u
[1] = src0
->u
[1] ? src1
->u
[1] : src2
->u
[1];
756 dst
->u
[2] = src0
->u
[2] ? src1
->u
[2] : src2
->u
[2];
757 dst
->u
[3] = src0
->u
[3] ? src1
->u
[3] : src2
->u
[3];
763 union tgsi_exec_channel
*dst
,
764 const union tgsi_exec_channel
*src
)
766 dst
->f
[0] = -src
->f
[0];
767 dst
->f
[1] = -src
->f
[1];
768 dst
->f
[2] = -src
->f
[2];
769 dst
->f
[3] = -src
->f
[3];
774 union tgsi_exec_channel
*dst
,
775 const union tgsi_exec_channel
*src0
,
776 const union tgsi_exec_channel
*src1
)
779 dst
->f
[0] = util_fast_pow( src0
->f
[0], src1
->f
[0] );
780 dst
->f
[1] = util_fast_pow( src0
->f
[1], src1
->f
[1] );
781 dst
->f
[2] = util_fast_pow( src0
->f
[2], src1
->f
[2] );
782 dst
->f
[3] = util_fast_pow( src0
->f
[3], src1
->f
[3] );
784 dst
->f
[0] = powf( src0
->f
[0], src1
->f
[0] );
785 dst
->f
[1] = powf( src0
->f
[1], src1
->f
[1] );
786 dst
->f
[2] = powf( src0
->f
[2], src1
->f
[2] );
787 dst
->f
[3] = powf( src0
->f
[3], src1
->f
[3] );
793 union tgsi_exec_channel
*dst
,
794 const union tgsi_exec_channel
*src
)
796 dst
->f
[0] = floorf( src
->f
[0] + 0.5f
);
797 dst
->f
[1] = floorf( src
->f
[1] + 0.5f
);
798 dst
->f
[2] = floorf( src
->f
[2] + 0.5f
);
799 dst
->f
[3] = floorf( src
->f
[3] + 0.5f
);
804 union tgsi_exec_channel
*dst
,
805 const union tgsi_exec_channel
*src
)
807 dst
->f
[0] = src
->f
[0] < 0.0f
? -1.0f
: src
->f
[0] > 0.0f
? 1.0f
: 0.0f
;
808 dst
->f
[1] = src
->f
[1] < 0.0f
? -1.0f
: src
->f
[1] > 0.0f
? 1.0f
: 0.0f
;
809 dst
->f
[2] = src
->f
[2] < 0.0f
? -1.0f
: src
->f
[2] > 0.0f
? 1.0f
: 0.0f
;
810 dst
->f
[3] = src
->f
[3] < 0.0f
? -1.0f
: src
->f
[3] > 0.0f
? 1.0f
: 0.0f
;
815 union tgsi_exec_channel
*dst
,
816 const union tgsi_exec_channel
*src0
)
818 dst
->f
[0] = (float) (int) src0
->f
[0];
819 dst
->f
[1] = (float) (int) src0
->f
[1];
820 dst
->f
[2] = (float) (int) src0
->f
[2];
821 dst
->f
[3] = (float) (int) src0
->f
[3];
826 union tgsi_exec_channel
*dst
,
827 const union tgsi_exec_channel
*src
)
829 dst
->f
[0] = sinf( src
->f
[0] );
830 dst
->f
[1] = sinf( src
->f
[1] );
831 dst
->f
[2] = sinf( src
->f
[2] );
832 dst
->f
[3] = sinf( src
->f
[3] );
836 micro_sqrt( union tgsi_exec_channel
*dst
,
837 const union tgsi_exec_channel
*src
)
839 dst
->f
[0] = sqrtf( src
->f
[0] );
840 dst
->f
[1] = sqrtf( src
->f
[1] );
841 dst
->f
[2] = sqrtf( src
->f
[2] );
842 dst
->f
[3] = sqrtf( src
->f
[3] );
847 union tgsi_exec_channel
*dst
,
848 const union tgsi_exec_channel
*src0
,
849 const union tgsi_exec_channel
*src1
)
851 dst
->f
[0] = src0
->f
[0] - src1
->f
[0];
852 dst
->f
[1] = src0
->f
[1] - src1
->f
[1];
853 dst
->f
[2] = src0
->f
[2] - src1
->f
[2];
854 dst
->f
[3] = src0
->f
[3] - src1
->f
[3];
858 fetch_src_file_channel(
859 const struct tgsi_exec_machine
*mach
,
862 const union tgsi_exec_channel
*index
,
863 union tgsi_exec_channel
*chan
)
871 case TGSI_FILE_CONSTANT
:
872 assert(mach
->Consts
);
876 chan
->f
[0] = mach
->Consts
[index
->i
[0]][swizzle
];
880 chan
->f
[1] = mach
->Consts
[index
->i
[1]][swizzle
];
884 chan
->f
[2] = mach
->Consts
[index
->i
[2]][swizzle
];
888 chan
->f
[3] = mach
->Consts
[index
->i
[3]][swizzle
];
891 case TGSI_FILE_INPUT
:
892 case TGSI_FILE_SYSTEM_VALUE
:
893 chan
->u
[0] = mach
->Inputs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
894 chan
->u
[1] = mach
->Inputs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
895 chan
->u
[2] = mach
->Inputs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
896 chan
->u
[3] = mach
->Inputs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
899 case TGSI_FILE_TEMPORARY
:
900 assert(index
->i
[0] < TGSI_EXEC_NUM_TEMPS
);
901 chan
->u
[0] = mach
->Temps
[index
->i
[0]].xyzw
[swizzle
].u
[0];
902 chan
->u
[1] = mach
->Temps
[index
->i
[1]].xyzw
[swizzle
].u
[1];
903 chan
->u
[2] = mach
->Temps
[index
->i
[2]].xyzw
[swizzle
].u
[2];
904 chan
->u
[3] = mach
->Temps
[index
->i
[3]].xyzw
[swizzle
].u
[3];
907 case TGSI_FILE_IMMEDIATE
:
908 assert( index
->i
[0] < (int) mach
->ImmLimit
);
909 chan
->f
[0] = mach
->Imms
[index
->i
[0]][swizzle
];
910 assert( index
->i
[1] < (int) mach
->ImmLimit
);
911 chan
->f
[1] = mach
->Imms
[index
->i
[1]][swizzle
];
912 assert( index
->i
[2] < (int) mach
->ImmLimit
);
913 chan
->f
[2] = mach
->Imms
[index
->i
[2]][swizzle
];
914 assert( index
->i
[3] < (int) mach
->ImmLimit
);
915 chan
->f
[3] = mach
->Imms
[index
->i
[3]][swizzle
];
918 case TGSI_FILE_ADDRESS
:
919 chan
->u
[0] = mach
->Addrs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
920 chan
->u
[1] = mach
->Addrs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
921 chan
->u
[2] = mach
->Addrs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
922 chan
->u
[3] = mach
->Addrs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
925 case TGSI_FILE_PREDICATE
:
926 assert(index
->i
[0] < TGSI_EXEC_NUM_PREDS
);
927 assert(index
->i
[1] < TGSI_EXEC_NUM_PREDS
);
928 assert(index
->i
[2] < TGSI_EXEC_NUM_PREDS
);
929 assert(index
->i
[3] < TGSI_EXEC_NUM_PREDS
);
930 chan
->u
[0] = mach
->Predicates
[0].xyzw
[swizzle
].u
[0];
931 chan
->u
[1] = mach
->Predicates
[0].xyzw
[swizzle
].u
[1];
932 chan
->u
[2] = mach
->Predicates
[0].xyzw
[swizzle
].u
[2];
933 chan
->u
[3] = mach
->Predicates
[0].xyzw
[swizzle
].u
[3];
936 case TGSI_FILE_OUTPUT
:
937 /* vertex/fragment output vars can be read too */
938 chan
->u
[0] = mach
->Outputs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
939 chan
->u
[1] = mach
->Outputs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
940 chan
->u
[2] = mach
->Outputs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
941 chan
->u
[3] = mach
->Outputs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
956 const struct tgsi_exec_machine
*mach
,
957 union tgsi_exec_channel
*chan
,
958 const struct tgsi_full_src_register
*reg
,
959 const uint chan_index
)
961 union tgsi_exec_channel index
;
964 /* We start with a direct index into a register file.
968 * file = Register.File
969 * [1] = Register.Index
974 index
.i
[3] = reg
->Register
.Index
;
976 /* There is an extra source register that indirectly subscripts
977 * a register file. The direct index now becomes an offset
978 * that is being added to the indirect register.
982 * ind = Indirect.File
983 * [2] = Indirect.Index
984 * .x = Indirect.SwizzleX
986 if (reg
->Register
.Indirect
) {
987 union tgsi_exec_channel index2
;
988 union tgsi_exec_channel indir_index
;
989 const uint execmask
= mach
->ExecMask
;
992 /* which address register (always zero now) */
996 index2
.i
[3] = reg
->Indirect
.Index
;
998 /* get current value of address register[swizzle] */
999 swizzle
= tgsi_util_get_src_register_swizzle( ®
->Indirect
, CHAN_X
);
1000 fetch_src_file_channel(
1007 /* add value of address register to the offset */
1008 index
.i
[0] += (int) indir_index
.f
[0];
1009 index
.i
[1] += (int) indir_index
.f
[1];
1010 index
.i
[2] += (int) indir_index
.f
[2];
1011 index
.i
[3] += (int) indir_index
.f
[3];
1013 /* for disabled execution channels, zero-out the index to
1014 * avoid using a potential garbage value.
1016 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1017 if ((execmask
& (1 << i
)) == 0)
1022 /* There is an extra source register that is a second
1023 * subscript to a register file. Effectively it means that
1024 * the register file is actually a 2D array of registers.
1026 * file[1][3] == file[1*sizeof(file[1])+3],
1028 * [3] = Dimension.Index
1030 if (reg
->Register
.Dimension
) {
1031 /* The size of the first-order array depends on the register file type.
1032 * We need to multiply the index to the first array to get an effective,
1033 * "flat" index that points to the beginning of the second-order array.
1035 switch (reg
->Register
.File
) {
1036 case TGSI_FILE_INPUT
:
1037 case TGSI_FILE_SYSTEM_VALUE
:
1038 index
.i
[0] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1039 index
.i
[1] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1040 index
.i
[2] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1041 index
.i
[3] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1043 case TGSI_FILE_CONSTANT
:
1044 index
.i
[0] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1045 index
.i
[1] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1046 index
.i
[2] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1047 index
.i
[3] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1053 index
.i
[0] += reg
->Dimension
.Index
;
1054 index
.i
[1] += reg
->Dimension
.Index
;
1055 index
.i
[2] += reg
->Dimension
.Index
;
1056 index
.i
[3] += reg
->Dimension
.Index
;
1058 /* Again, the second subscript index can be addressed indirectly
1059 * identically to the first one.
1060 * Nothing stops us from indirectly addressing the indirect register,
1061 * but there is no need for that, so we won't exercise it.
1063 * file[1][ind[4].y+3],
1065 * ind = DimIndirect.File
1066 * [4] = DimIndirect.Index
1067 * .y = DimIndirect.SwizzleX
1069 if (reg
->Dimension
.Indirect
) {
1070 union tgsi_exec_channel index2
;
1071 union tgsi_exec_channel indir_index
;
1072 const uint execmask
= mach
->ExecMask
;
1078 index2
.i
[3] = reg
->DimIndirect
.Index
;
1080 swizzle
= tgsi_util_get_src_register_swizzle( ®
->DimIndirect
, CHAN_X
);
1081 fetch_src_file_channel(
1083 reg
->DimIndirect
.File
,
1088 index
.i
[0] += (int) indir_index
.f
[0];
1089 index
.i
[1] += (int) indir_index
.f
[1];
1090 index
.i
[2] += (int) indir_index
.f
[2];
1091 index
.i
[3] += (int) indir_index
.f
[3];
1093 /* for disabled execution channels, zero-out the index to
1094 * avoid using a potential garbage value.
1096 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1097 if ((execmask
& (1 << i
)) == 0)
1102 /* If by any chance there was a need for a 3D array of register
1103 * files, we would have to check whether Dimension is followed
1104 * by a dimension register and continue the saga.
1108 swizzle
= tgsi_util_get_full_src_register_swizzle( reg
, chan_index
);
1109 fetch_src_file_channel(
1116 switch (tgsi_util_get_full_src_register_sign_mode( reg
, chan_index
)) {
1117 case TGSI_UTIL_SIGN_CLEAR
:
1118 micro_abs( chan
, chan
);
1121 case TGSI_UTIL_SIGN_SET
:
1122 micro_abs( chan
, chan
);
1123 micro_neg( chan
, chan
);
1126 case TGSI_UTIL_SIGN_TOGGLE
:
1127 micro_neg( chan
, chan
);
1130 case TGSI_UTIL_SIGN_KEEP
:
1137 struct tgsi_exec_machine
*mach
,
1138 const union tgsi_exec_channel
*chan
,
1139 const struct tgsi_full_dst_register
*reg
,
1140 const struct tgsi_full_instruction
*inst
,
1144 union tgsi_exec_channel null
;
1145 union tgsi_exec_channel
*dst
;
1146 uint execmask
= mach
->ExecMask
;
1147 int offset
= 0; /* indirection offset */
1151 check_inf_or_nan(chan
);
1154 /* There is an extra source register that indirectly subscripts
1155 * a register file. The direct index now becomes an offset
1156 * that is being added to the indirect register.
1160 * ind = Indirect.File
1161 * [2] = Indirect.Index
1162 * .x = Indirect.SwizzleX
1164 if (reg
->Register
.Indirect
) {
1165 union tgsi_exec_channel index
;
1166 union tgsi_exec_channel indir_index
;
1169 /* which address register (always zero for now) */
1173 index
.i
[3] = reg
->Indirect
.Index
;
1175 /* get current value of address register[swizzle] */
1176 swizzle
= tgsi_util_get_src_register_swizzle( ®
->Indirect
, CHAN_X
);
1178 /* fetch values from the address/indirection register */
1179 fetch_src_file_channel(
1186 /* save indirection offset */
1187 offset
= (int) indir_index
.f
[0];
1190 switch (reg
->Register
.File
) {
1191 case TGSI_FILE_NULL
:
1195 case TGSI_FILE_OUTPUT
:
1196 index
= mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0]
1197 + reg
->Register
.Index
;
1198 dst
= &mach
->Outputs
[offset
+ index
].xyzw
[chan_index
];
1200 if (TGSI_PROCESSOR_GEOMETRY
== mach
->Processor
) {
1201 fprintf(stderr
, "STORING OUT[%d] mask(%d), = (", offset
+ index
, execmask
);
1202 for (i
= 0; i
< QUAD_SIZE
; i
++)
1203 if (execmask
& (1 << i
))
1204 fprintf(stderr
, "%f, ", chan
->f
[i
]);
1205 fprintf(stderr
, ")\n");
1210 case TGSI_FILE_TEMPORARY
:
1211 index
= reg
->Register
.Index
;
1212 assert( index
< TGSI_EXEC_NUM_TEMPS
);
1213 dst
= &mach
->Temps
[offset
+ index
].xyzw
[chan_index
];
1216 case TGSI_FILE_ADDRESS
:
1217 index
= reg
->Register
.Index
;
1218 dst
= &mach
->Addrs
[index
].xyzw
[chan_index
];
1221 case TGSI_FILE_LOOP
:
1222 assert(reg
->Register
.Index
== 0);
1223 assert(mach
->LoopCounterStackTop
> 0);
1224 assert(chan_index
== CHAN_X
);
1225 dst
= &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[chan_index
];
1228 case TGSI_FILE_PREDICATE
:
1229 index
= reg
->Register
.Index
;
1230 assert(index
< TGSI_EXEC_NUM_PREDS
);
1231 dst
= &mach
->Predicates
[index
].xyzw
[chan_index
];
1239 if (inst
->Instruction
.Predicate
) {
1241 union tgsi_exec_channel
*pred
;
1243 switch (chan_index
) {
1245 swizzle
= inst
->Predicate
.SwizzleX
;
1248 swizzle
= inst
->Predicate
.SwizzleY
;
1251 swizzle
= inst
->Predicate
.SwizzleZ
;
1254 swizzle
= inst
->Predicate
.SwizzleW
;
1261 assert(inst
->Predicate
.Index
== 0);
1263 pred
= &mach
->Predicates
[inst
->Predicate
.Index
].xyzw
[swizzle
];
1265 if (inst
->Predicate
.Negate
) {
1266 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1268 execmask
&= ~(1 << i
);
1272 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1274 execmask
&= ~(1 << i
);
1280 switch (inst
->Instruction
.Saturate
) {
1282 for (i
= 0; i
< QUAD_SIZE
; i
++)
1283 if (execmask
& (1 << i
))
1284 dst
->i
[i
] = chan
->i
[i
];
1287 case TGSI_SAT_ZERO_ONE
:
1288 for (i
= 0; i
< QUAD_SIZE
; i
++)
1289 if (execmask
& (1 << i
)) {
1290 if (chan
->f
[i
] < 0.0f
)
1292 else if (chan
->f
[i
] > 1.0f
)
1295 dst
->i
[i
] = chan
->i
[i
];
1299 case TGSI_SAT_MINUS_PLUS_ONE
:
1300 for (i
= 0; i
< QUAD_SIZE
; i
++)
1301 if (execmask
& (1 << i
)) {
1302 if (chan
->f
[i
] < -1.0f
)
1304 else if (chan
->f
[i
] > 1.0f
)
1307 dst
->i
[i
] = chan
->i
[i
];
1316 #define FETCH(VAL,INDEX,CHAN)\
1317 fetch_source (mach, VAL, &inst->Src[INDEX], CHAN)
1319 #define STORE(VAL,INDEX,CHAN)\
1320 store_dest (mach, VAL, &inst->Dst[INDEX], inst, CHAN )
1324 * Execute ARB-style KIL which is predicated by a src register.
1325 * Kill fragment if any of the four values is less than zero.
1328 exec_kil(struct tgsi_exec_machine
*mach
,
1329 const struct tgsi_full_instruction
*inst
)
1333 uint kilmask
= 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1334 union tgsi_exec_channel r
[1];
1336 /* This mask stores component bits that were already tested. */
1339 for (chan_index
= 0; chan_index
< 4; chan_index
++)
1344 /* unswizzle channel */
1345 swizzle
= tgsi_util_get_full_src_register_swizzle (
1349 /* check if the component has not been already tested */
1350 if (uniquemask
& (1 << swizzle
))
1352 uniquemask
|= 1 << swizzle
;
1354 FETCH(&r
[0], 0, chan_index
);
1355 for (i
= 0; i
< 4; i
++)
1356 if (r
[0].f
[i
] < 0.0f
)
1360 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1364 * Execute NVIDIA-style KIL which is predicated by a condition code.
1365 * Kill fragment if the condition code is TRUE.
1368 exec_kilp(struct tgsi_exec_machine
*mach
,
1369 const struct tgsi_full_instruction
*inst
)
1371 uint kilmask
; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1373 /* "unconditional" kil */
1374 kilmask
= mach
->ExecMask
;
1375 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1379 emit_vertex(struct tgsi_exec_machine
*mach
)
1381 /* FIXME: check for exec mask correctly
1383 for (i = 0; i < QUAD_SIZE; ++i) {
1384 if ((mach->ExecMask & (1 << i)))
1386 if (mach
->ExecMask
) {
1387 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] += mach
->NumOutputs
;
1388 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]]++;
1393 emit_primitive(struct tgsi_exec_machine
*mach
)
1395 unsigned *prim_count
= &mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0];
1396 /* FIXME: check for exec mask correctly
1398 for (i = 0; i < QUAD_SIZE; ++i) {
1399 if ((mach->ExecMask & (1 << i)))
1401 if (mach
->ExecMask
) {
1403 debug_assert((*prim_count
* mach
->NumOutputs
) < mach
->MaxGeometryShaderOutputs
);
1404 mach
->Primitives
[*prim_count
] = 0;
1409 * Fetch a four texture samples using STR texture coordinates.
1412 fetch_texel( struct tgsi_sampler
*sampler
,
1413 const union tgsi_exec_channel
*s
,
1414 const union tgsi_exec_channel
*t
,
1415 const union tgsi_exec_channel
*p
,
1416 float lodbias
, /* XXX should be float[4] */
1417 union tgsi_exec_channel
*r
,
1418 union tgsi_exec_channel
*g
,
1419 union tgsi_exec_channel
*b
,
1420 union tgsi_exec_channel
*a
)
1423 float rgba
[NUM_CHANNELS
][QUAD_SIZE
];
1425 sampler
->get_samples(sampler
, s
->f
, t
->f
, p
->f
, lodbias
, rgba
);
1427 for (j
= 0; j
< 4; j
++) {
1428 r
->f
[j
] = rgba
[0][j
];
1429 g
->f
[j
] = rgba
[1][j
];
1430 b
->f
[j
] = rgba
[2][j
];
1431 a
->f
[j
] = rgba
[3][j
];
1437 exec_tex(struct tgsi_exec_machine
*mach
,
1438 const struct tgsi_full_instruction
*inst
,
1442 const uint unit
= inst
->Src
[1].Register
.Index
;
1443 union tgsi_exec_channel r
[4];
1447 /* debug_printf("Sampler %u unit %u\n", sampler, unit); */
1449 switch (inst
->Texture
.Texture
) {
1450 case TGSI_TEXTURE_1D
:
1451 case TGSI_TEXTURE_SHADOW1D
:
1453 FETCH(&r
[0], 0, CHAN_X
);
1456 FETCH(&r
[1], 0, CHAN_W
);
1457 micro_div( &r
[0], &r
[0], &r
[1] );
1461 FETCH(&r
[1], 0, CHAN_W
);
1462 lodBias
= r
[2].f
[0];
1467 fetch_texel(mach
->Samplers
[unit
],
1468 &r
[0], &ZeroVec
, &ZeroVec
, lodBias
, /* S, T, P, BIAS */
1469 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1472 case TGSI_TEXTURE_2D
:
1473 case TGSI_TEXTURE_RECT
:
1474 case TGSI_TEXTURE_SHADOW2D
:
1475 case TGSI_TEXTURE_SHADOWRECT
:
1477 FETCH(&r
[0], 0, CHAN_X
);
1478 FETCH(&r
[1], 0, CHAN_Y
);
1479 FETCH(&r
[2], 0, CHAN_Z
);
1482 FETCH(&r
[3], 0, CHAN_W
);
1483 micro_div( &r
[0], &r
[0], &r
[3] );
1484 micro_div( &r
[1], &r
[1], &r
[3] );
1485 micro_div( &r
[2], &r
[2], &r
[3] );
1489 FETCH(&r
[3], 0, CHAN_W
);
1490 lodBias
= r
[3].f
[0];
1495 fetch_texel(mach
->Samplers
[unit
],
1496 &r
[0], &r
[1], &r
[2], lodBias
, /* inputs */
1497 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1500 case TGSI_TEXTURE_3D
:
1501 case TGSI_TEXTURE_CUBE
:
1503 FETCH(&r
[0], 0, CHAN_X
);
1504 FETCH(&r
[1], 0, CHAN_Y
);
1505 FETCH(&r
[2], 0, CHAN_Z
);
1508 FETCH(&r
[3], 0, CHAN_W
);
1509 micro_div( &r
[0], &r
[0], &r
[3] );
1510 micro_div( &r
[1], &r
[1], &r
[3] );
1511 micro_div( &r
[2], &r
[2], &r
[3] );
1515 FETCH(&r
[3], 0, CHAN_W
);
1516 lodBias
= r
[3].f
[0];
1521 fetch_texel(mach
->Samplers
[unit
],
1522 &r
[0], &r
[1], &r
[2], lodBias
,
1523 &r
[0], &r
[1], &r
[2], &r
[3]);
1530 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1531 STORE( &r
[chan_index
], 0, chan_index
);
1536 exec_txd(struct tgsi_exec_machine
*mach
,
1537 const struct tgsi_full_instruction
*inst
)
1539 const uint unit
= inst
->Src
[3].Register
.Index
;
1540 union tgsi_exec_channel r
[4];
1544 * XXX: This is fake TXD -- the derivatives are not taken into account, yet.
1547 switch (inst
->Texture
.Texture
) {
1548 case TGSI_TEXTURE_1D
:
1549 case TGSI_TEXTURE_SHADOW1D
:
1551 FETCH(&r
[0], 0, CHAN_X
);
1553 fetch_texel(mach
->Samplers
[unit
],
1554 &r
[0], &ZeroVec
, &ZeroVec
, 0.0f
, /* S, T, P, BIAS */
1555 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1558 case TGSI_TEXTURE_2D
:
1559 case TGSI_TEXTURE_RECT
:
1560 case TGSI_TEXTURE_SHADOW2D
:
1561 case TGSI_TEXTURE_SHADOWRECT
:
1563 FETCH(&r
[0], 0, CHAN_X
);
1564 FETCH(&r
[1], 0, CHAN_Y
);
1565 FETCH(&r
[2], 0, CHAN_Z
);
1567 fetch_texel(mach
->Samplers
[unit
],
1568 &r
[0], &r
[1], &r
[2], 0.0f
, /* inputs */
1569 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1572 case TGSI_TEXTURE_3D
:
1573 case TGSI_TEXTURE_CUBE
:
1575 FETCH(&r
[0], 0, CHAN_X
);
1576 FETCH(&r
[1], 0, CHAN_Y
);
1577 FETCH(&r
[2], 0, CHAN_Z
);
1579 fetch_texel(mach
->Samplers
[unit
],
1580 &r
[0], &r
[1], &r
[2], 0.0f
,
1581 &r
[0], &r
[1], &r
[2], &r
[3]);
1588 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
1589 STORE(&r
[chan_index
], 0, chan_index
);
1595 * Evaluate a constant-valued coefficient at the position of the
1600 struct tgsi_exec_machine
*mach
,
1606 for( i
= 0; i
< QUAD_SIZE
; i
++ ) {
1607 mach
->Inputs
[attrib
].xyzw
[chan
].f
[i
] = mach
->InterpCoefs
[attrib
].a0
[chan
];
1612 * Evaluate a linear-valued coefficient at the position of the
1617 struct tgsi_exec_machine
*mach
,
1621 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1622 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1623 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1624 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1625 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1626 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
;
1627 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = a0
+ dadx
;
1628 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = a0
+ dady
;
1629 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = a0
+ dadx
+ dady
;
1633 * Evaluate a perspective-valued coefficient at the position of the
1637 eval_perspective_coef(
1638 struct tgsi_exec_machine
*mach
,
1642 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1643 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1644 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1645 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1646 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1647 const float *w
= mach
->QuadPos
.xyzw
[3].f
;
1648 /* divide by W here */
1649 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
/ w
[0];
1650 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = (a0
+ dadx
) / w
[1];
1651 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = (a0
+ dady
) / w
[2];
1652 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = (a0
+ dadx
+ dady
) / w
[3];
1656 typedef void (* eval_coef_func
)(
1657 struct tgsi_exec_machine
*mach
,
1662 exec_declaration(struct tgsi_exec_machine
*mach
,
1663 const struct tgsi_full_declaration
*decl
)
1665 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
1666 if (decl
->Declaration
.File
== TGSI_FILE_INPUT
||
1667 decl
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1668 uint first
, last
, mask
;
1670 first
= decl
->Range
.First
;
1671 last
= decl
->Range
.Last
;
1672 mask
= decl
->Declaration
.UsageMask
;
1674 if (decl
->Semantic
.Name
== TGSI_SEMANTIC_POSITION
) {
1675 assert(decl
->Semantic
.Index
== 0);
1676 assert(first
== last
);
1677 assert(mask
== TGSI_WRITEMASK_XYZW
);
1679 mach
->Inputs
[first
] = mach
->QuadPos
;
1680 } else if (decl
->Semantic
.Name
== TGSI_SEMANTIC_FACE
) {
1683 assert(decl
->Semantic
.Index
== 0);
1684 assert(first
== last
);
1686 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1687 mach
->Inputs
[first
].xyzw
[0].f
[i
] = mach
->Face
;
1690 eval_coef_func eval
;
1693 switch (decl
->Declaration
.Interpolate
) {
1694 case TGSI_INTERPOLATE_CONSTANT
:
1695 eval
= eval_constant_coef
;
1698 case TGSI_INTERPOLATE_LINEAR
:
1699 eval
= eval_linear_coef
;
1702 case TGSI_INTERPOLATE_PERSPECTIVE
:
1703 eval
= eval_perspective_coef
;
1711 for (j
= 0; j
< NUM_CHANNELS
; j
++) {
1712 if (mask
& (1 << j
)) {
1713 for (i
= first
; i
<= last
; i
++) {
1723 typedef void (* micro_op
)(union tgsi_exec_channel
*dst
,
1724 const union tgsi_exec_channel
*src
);
1727 exec_vector_unary(struct tgsi_exec_machine
*mach
,
1728 const struct tgsi_full_instruction
*inst
,
1732 struct tgsi_exec_vector dst
;
1734 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1735 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1736 union tgsi_exec_channel src
;
1738 fetch_source(mach
, &src
, &inst
->Src
[0], chan
);
1739 op(&dst
.xyzw
[chan
], &src
);
1742 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1743 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1744 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
);
1750 exec_vector_binary(struct tgsi_exec_machine
*mach
,
1751 const struct tgsi_full_instruction
*inst
,
1755 struct tgsi_exec_vector dst
;
1757 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1758 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1759 union tgsi_exec_channel src
[2];
1761 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
);
1762 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
);
1763 op(&dst
.xyzw
[chan
], src
);
1766 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1767 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1768 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
);
1774 exec_vector_trinary(struct tgsi_exec_machine
*mach
,
1775 const struct tgsi_full_instruction
*inst
,
1779 struct tgsi_exec_vector dst
;
1781 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1782 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1783 union tgsi_exec_channel src
[3];
1785 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
);
1786 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
);
1787 fetch_source(mach
, &src
[2], &inst
->Src
[2], chan
);
1788 op(&dst
.xyzw
[chan
], src
);
1791 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1792 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1793 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
);
1799 micro_i2f(union tgsi_exec_channel
*dst
,
1800 const union tgsi_exec_channel
*src
)
1802 dst
->f
[0] = (float)src
->i
[0];
1803 dst
->f
[1] = (float)src
->i
[1];
1804 dst
->f
[2] = (float)src
->i
[2];
1805 dst
->f
[3] = (float)src
->i
[3];
1809 micro_not(union tgsi_exec_channel
*dst
,
1810 const union tgsi_exec_channel
*src
)
1812 dst
->u
[0] = ~src
->u
[0];
1813 dst
->u
[1] = ~src
->u
[1];
1814 dst
->u
[2] = ~src
->u
[2];
1815 dst
->u
[3] = ~src
->u
[3];
1819 micro_shl(union tgsi_exec_channel
*dst
,
1820 const union tgsi_exec_channel
*src
)
1822 dst
->u
[0] = src
[0].u
[0] << src
[1].u
[0];
1823 dst
->u
[1] = src
[0].u
[1] << src
[1].u
[1];
1824 dst
->u
[2] = src
[0].u
[2] << src
[1].u
[2];
1825 dst
->u
[3] = src
[0].u
[3] << src
[1].u
[3];
1829 micro_and(union tgsi_exec_channel
*dst
,
1830 const union tgsi_exec_channel
*src
)
1832 dst
->u
[0] = src
[0].u
[0] & src
[1].u
[0];
1833 dst
->u
[1] = src
[0].u
[1] & src
[1].u
[1];
1834 dst
->u
[2] = src
[0].u
[2] & src
[1].u
[2];
1835 dst
->u
[3] = src
[0].u
[3] & src
[1].u
[3];
1839 micro_or(union tgsi_exec_channel
*dst
,
1840 const union tgsi_exec_channel
*src
)
1842 dst
->u
[0] = src
[0].u
[0] | src
[1].u
[0];
1843 dst
->u
[1] = src
[0].u
[1] | src
[1].u
[1];
1844 dst
->u
[2] = src
[0].u
[2] | src
[1].u
[2];
1845 dst
->u
[3] = src
[0].u
[3] | src
[1].u
[3];
1849 micro_xor(union tgsi_exec_channel
*dst
,
1850 const union tgsi_exec_channel
*src
)
1852 dst
->u
[0] = src
[0].u
[0] ^ src
[1].u
[0];
1853 dst
->u
[1] = src
[0].u
[1] ^ src
[1].u
[1];
1854 dst
->u
[2] = src
[0].u
[2] ^ src
[1].u
[2];
1855 dst
->u
[3] = src
[0].u
[3] ^ src
[1].u
[3];
1859 micro_f2i(union tgsi_exec_channel
*dst
,
1860 const union tgsi_exec_channel
*src
)
1862 dst
->i
[0] = (int)src
->f
[0];
1863 dst
->i
[1] = (int)src
->f
[1];
1864 dst
->i
[2] = (int)src
->f
[2];
1865 dst
->i
[3] = (int)src
->f
[3];
1869 micro_idiv(union tgsi_exec_channel
*dst
,
1870 const union tgsi_exec_channel
*src
)
1872 dst
->i
[0] = src
[0].i
[0] / src
[1].i
[0];
1873 dst
->i
[1] = src
[0].i
[1] / src
[1].i
[1];
1874 dst
->i
[2] = src
[0].i
[2] / src
[1].i
[2];
1875 dst
->i
[3] = src
[0].i
[3] / src
[1].i
[3];
1879 micro_imax(union tgsi_exec_channel
*dst
,
1880 const union tgsi_exec_channel
*src
)
1882 dst
->i
[0] = src
[0].i
[0] > src
[1].i
[0] ? src
[0].i
[0] : src
[1].i
[0];
1883 dst
->i
[1] = src
[0].i
[1] > src
[1].i
[1] ? src
[0].i
[1] : src
[1].i
[1];
1884 dst
->i
[2] = src
[0].i
[2] > src
[1].i
[2] ? src
[0].i
[2] : src
[1].i
[2];
1885 dst
->i
[3] = src
[0].i
[3] > src
[1].i
[3] ? src
[0].i
[3] : src
[1].i
[3];
1889 micro_imin(union tgsi_exec_channel
*dst
,
1890 const union tgsi_exec_channel
*src
)
1892 dst
->i
[0] = src
[0].i
[0] < src
[1].i
[0] ? src
[0].i
[0] : src
[1].i
[0];
1893 dst
->i
[1] = src
[0].i
[1] < src
[1].i
[1] ? src
[0].i
[1] : src
[1].i
[1];
1894 dst
->i
[2] = src
[0].i
[2] < src
[1].i
[2] ? src
[0].i
[2] : src
[1].i
[2];
1895 dst
->i
[3] = src
[0].i
[3] < src
[1].i
[3] ? src
[0].i
[3] : src
[1].i
[3];
1899 micro_ineg(union tgsi_exec_channel
*dst
,
1900 const union tgsi_exec_channel
*src
)
1902 dst
->i
[0] = -src
->i
[0];
1903 dst
->i
[1] = -src
->i
[1];
1904 dst
->i
[2] = -src
->i
[2];
1905 dst
->i
[3] = -src
->i
[3];
1909 micro_isge(union tgsi_exec_channel
*dst
,
1910 const union tgsi_exec_channel
*src
)
1912 dst
->i
[0] = src
[0].i
[0] >= src
[1].i
[0] ? -1 : 0;
1913 dst
->i
[1] = src
[0].i
[1] >= src
[1].i
[1] ? -1 : 0;
1914 dst
->i
[2] = src
[0].i
[2] >= src
[1].i
[2] ? -1 : 0;
1915 dst
->i
[3] = src
[0].i
[3] >= src
[1].i
[3] ? -1 : 0;
1919 micro_ishr(union tgsi_exec_channel
*dst
,
1920 const union tgsi_exec_channel
*src
)
1922 dst
->i
[0] = src
[0].i
[0] >> src
[1].i
[0];
1923 dst
->i
[1] = src
[0].i
[1] >> src
[1].i
[1];
1924 dst
->i
[2] = src
[0].i
[2] >> src
[1].i
[2];
1925 dst
->i
[3] = src
[0].i
[3] >> src
[1].i
[3];
1929 micro_islt(union tgsi_exec_channel
*dst
,
1930 const union tgsi_exec_channel
*src
)
1932 dst
->i
[0] = src
[0].i
[0] < src
[1].i
[0] ? -1 : 0;
1933 dst
->i
[1] = src
[0].i
[1] < src
[1].i
[1] ? -1 : 0;
1934 dst
->i
[2] = src
[0].i
[2] < src
[1].i
[2] ? -1 : 0;
1935 dst
->i
[3] = src
[0].i
[3] < src
[1].i
[3] ? -1 : 0;
1939 micro_f2u(union tgsi_exec_channel
*dst
,
1940 const union tgsi_exec_channel
*src
)
1942 dst
->u
[0] = (uint
)src
->f
[0];
1943 dst
->u
[1] = (uint
)src
->f
[1];
1944 dst
->u
[2] = (uint
)src
->f
[2];
1945 dst
->u
[3] = (uint
)src
->f
[3];
1949 micro_u2f(union tgsi_exec_channel
*dst
,
1950 const union tgsi_exec_channel
*src
)
1952 dst
->f
[0] = (float)src
->u
[0];
1953 dst
->f
[1] = (float)src
->u
[1];
1954 dst
->f
[2] = (float)src
->u
[2];
1955 dst
->f
[3] = (float)src
->u
[3];
1959 micro_uadd(union tgsi_exec_channel
*dst
,
1960 const union tgsi_exec_channel
*src
)
1962 dst
->u
[0] = src
[0].u
[0] + src
[1].u
[0];
1963 dst
->u
[1] = src
[0].u
[1] + src
[1].u
[1];
1964 dst
->u
[2] = src
[0].u
[2] + src
[1].u
[2];
1965 dst
->u
[3] = src
[0].u
[3] + src
[1].u
[3];
1969 micro_udiv(union tgsi_exec_channel
*dst
,
1970 const union tgsi_exec_channel
*src
)
1972 dst
->u
[0] = src
[0].u
[0] / src
[1].u
[0];
1973 dst
->u
[1] = src
[0].u
[1] / src
[1].u
[1];
1974 dst
->u
[2] = src
[0].u
[2] / src
[1].u
[2];
1975 dst
->u
[3] = src
[0].u
[3] / src
[1].u
[3];
1979 micro_umad(union tgsi_exec_channel
*dst
,
1980 const union tgsi_exec_channel
*src
)
1982 dst
->u
[0] = src
[0].u
[0] * src
[1].u
[0] + src
[2].u
[0];
1983 dst
->u
[1] = src
[0].u
[1] * src
[1].u
[1] + src
[2].u
[1];
1984 dst
->u
[2] = src
[0].u
[2] * src
[1].u
[2] + src
[2].u
[2];
1985 dst
->u
[3] = src
[0].u
[3] * src
[1].u
[3] + src
[2].u
[3];
1989 micro_umax(union tgsi_exec_channel
*dst
,
1990 const union tgsi_exec_channel
*src
)
1992 dst
->u
[0] = src
[0].u
[0] > src
[1].u
[0] ? src
[0].u
[0] : src
[1].u
[0];
1993 dst
->u
[1] = src
[0].u
[1] > src
[1].u
[1] ? src
[0].u
[1] : src
[1].u
[1];
1994 dst
->u
[2] = src
[0].u
[2] > src
[1].u
[2] ? src
[0].u
[2] : src
[1].u
[2];
1995 dst
->u
[3] = src
[0].u
[3] > src
[1].u
[3] ? src
[0].u
[3] : src
[1].u
[3];
1999 micro_umin(union tgsi_exec_channel
*dst
,
2000 const union tgsi_exec_channel
*src
)
2002 dst
->u
[0] = src
[0].u
[0] < src
[1].u
[0] ? src
[0].u
[0] : src
[1].u
[0];
2003 dst
->u
[1] = src
[0].u
[1] < src
[1].u
[1] ? src
[0].u
[1] : src
[1].u
[1];
2004 dst
->u
[2] = src
[0].u
[2] < src
[1].u
[2] ? src
[0].u
[2] : src
[1].u
[2];
2005 dst
->u
[3] = src
[0].u
[3] < src
[1].u
[3] ? src
[0].u
[3] : src
[1].u
[3];
2009 micro_umul(union tgsi_exec_channel
*dst
,
2010 const union tgsi_exec_channel
*src
)
2012 dst
->u
[0] = src
[0].u
[0] * src
[1].u
[0];
2013 dst
->u
[1] = src
[0].u
[1] * src
[1].u
[1];
2014 dst
->u
[2] = src
[0].u
[2] * src
[1].u
[2];
2015 dst
->u
[3] = src
[0].u
[3] * src
[1].u
[3];
2019 micro_useq(union tgsi_exec_channel
*dst
,
2020 const union tgsi_exec_channel
*src
)
2022 dst
->u
[0] = src
[0].u
[0] == src
[1].u
[0] ? ~0 : 0;
2023 dst
->u
[1] = src
[0].u
[1] == src
[1].u
[1] ? ~0 : 0;
2024 dst
->u
[2] = src
[0].u
[2] == src
[1].u
[2] ? ~0 : 0;
2025 dst
->u
[3] = src
[0].u
[3] == src
[1].u
[3] ? ~0 : 0;
2029 micro_usge(union tgsi_exec_channel
*dst
,
2030 const union tgsi_exec_channel
*src
)
2032 dst
->u
[0] = src
[0].u
[0] >= src
[1].u
[0] ? ~0 : 0;
2033 dst
->u
[1] = src
[0].u
[1] >= src
[1].u
[1] ? ~0 : 0;
2034 dst
->u
[2] = src
[0].u
[2] >= src
[1].u
[2] ? ~0 : 0;
2035 dst
->u
[3] = src
[0].u
[3] >= src
[1].u
[3] ? ~0 : 0;
2039 micro_ushr(union tgsi_exec_channel
*dst
,
2040 const union tgsi_exec_channel
*src
)
2042 dst
->u
[0] = src
[0].u
[0] >> src
[1].u
[0];
2043 dst
->u
[1] = src
[0].u
[1] >> src
[1].u
[1];
2044 dst
->u
[2] = src
[0].u
[2] >> src
[1].u
[2];
2045 dst
->u
[3] = src
[0].u
[3] >> src
[1].u
[3];
2049 micro_uslt(union tgsi_exec_channel
*dst
,
2050 const union tgsi_exec_channel
*src
)
2052 dst
->u
[0] = src
[0].u
[0] < src
[1].u
[0] ? ~0 : 0;
2053 dst
->u
[1] = src
[0].u
[1] < src
[1].u
[1] ? ~0 : 0;
2054 dst
->u
[2] = src
[0].u
[2] < src
[1].u
[2] ? ~0 : 0;
2055 dst
->u
[3] = src
[0].u
[3] < src
[1].u
[3] ? ~0 : 0;
2059 micro_usne(union tgsi_exec_channel
*dst
,
2060 const union tgsi_exec_channel
*src
)
2062 dst
->u
[0] = src
[0].u
[0] != src
[1].u
[0] ? ~0 : 0;
2063 dst
->u
[1] = src
[0].u
[1] != src
[1].u
[1] ? ~0 : 0;
2064 dst
->u
[2] = src
[0].u
[2] != src
[1].u
[2] ? ~0 : 0;
2065 dst
->u
[3] = src
[0].u
[3] != src
[1].u
[3] ? ~0 : 0;
2070 struct tgsi_exec_machine
*mach
,
2071 const struct tgsi_full_instruction
*inst
,
2075 union tgsi_exec_channel r
[10];
2076 union tgsi_exec_channel d
[8];
2080 switch (inst
->Instruction
.Opcode
) {
2081 case TGSI_OPCODE_ARL
:
2082 case TGSI_OPCODE_FLR
:
2083 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2084 FETCH( &r
[0], 0, chan_index
);
2085 micro_flr(&d
[chan_index
], &r
[0]);
2087 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2088 STORE(&d
[chan_index
], 0, chan_index
);
2092 case TGSI_OPCODE_MOV
:
2093 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2094 FETCH(&d
[chan_index
], 0, chan_index
);
2096 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2097 STORE(&d
[chan_index
], 0, chan_index
);
2101 case TGSI_OPCODE_LIT
:
2102 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2103 FETCH( &r
[0], 0, CHAN_X
);
2104 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2105 micro_max(&d
[CHAN_Y
], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
2108 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2109 FETCH( &r
[1], 0, CHAN_Y
);
2110 micro_max( &r
[1], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
2112 FETCH( &r
[2], 0, CHAN_W
);
2113 micro_min( &r
[2], &r
[2], &mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
] );
2114 micro_max( &r
[2], &r
[2], &mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
] );
2115 micro_pow( &r
[1], &r
[1], &r
[2] );
2116 micro_lt(&d
[CHAN_Z
], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &r
[0], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
2119 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2120 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2122 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2123 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2126 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2127 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2129 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2130 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2134 case TGSI_OPCODE_RCP
:
2135 /* TGSI_OPCODE_RECIP */
2136 FETCH( &r
[0], 0, CHAN_X
);
2137 micro_div( &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0] );
2138 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2139 STORE( &r
[0], 0, chan_index
);
2143 case TGSI_OPCODE_RSQ
:
2144 /* TGSI_OPCODE_RECIPSQRT */
2145 FETCH( &r
[0], 0, CHAN_X
);
2146 micro_abs( &r
[0], &r
[0] );
2147 micro_sqrt( &r
[0], &r
[0] );
2148 micro_div( &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0] );
2149 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2150 STORE( &r
[0], 0, chan_index
);
2154 case TGSI_OPCODE_EXP
:
2155 FETCH( &r
[0], 0, CHAN_X
);
2156 micro_flr( &r
[1], &r
[0] ); /* r1 = floor(r0) */
2157 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2158 micro_exp2( &r
[2], &r
[1] ); /* r2 = 2 ^ r1 */
2159 STORE( &r
[2], 0, CHAN_X
); /* store r2 */
2161 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2162 micro_sub( &r
[2], &r
[0], &r
[1] ); /* r2 = r0 - r1 */
2163 STORE( &r
[2], 0, CHAN_Y
); /* store r2 */
2165 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2166 micro_exp2( &r
[2], &r
[0] ); /* r2 = 2 ^ r0 */
2167 STORE( &r
[2], 0, CHAN_Z
); /* store r2 */
2169 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2170 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2174 case TGSI_OPCODE_LOG
:
2175 FETCH( &r
[0], 0, CHAN_X
);
2176 micro_abs( &r
[2], &r
[0] ); /* r2 = abs(r0) */
2177 micro_lg2( &r
[1], &r
[2] ); /* r1 = lg2(r2) */
2178 micro_flr( &r
[0], &r
[1] ); /* r0 = floor(r1) */
2179 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2180 STORE( &r
[0], 0, CHAN_X
);
2182 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2183 micro_exp2( &r
[0], &r
[0] ); /* r0 = 2 ^ r0 */
2184 micro_div( &r
[0], &r
[2], &r
[0] ); /* r0 = r2 / r0 */
2185 STORE( &r
[0], 0, CHAN_Y
);
2187 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2188 STORE( &r
[1], 0, CHAN_Z
);
2190 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2191 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2195 case TGSI_OPCODE_MUL
:
2196 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2197 FETCH(&r
[0], 0, chan_index
);
2198 FETCH(&r
[1], 1, chan_index
);
2199 micro_mul(&d
[chan_index
], &r
[0], &r
[1]);
2201 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2202 STORE(&d
[chan_index
], 0, chan_index
);
2206 case TGSI_OPCODE_ADD
:
2207 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2208 FETCH( &r
[0], 0, chan_index
);
2209 FETCH( &r
[1], 1, chan_index
);
2210 micro_add(&d
[chan_index
], &r
[0], &r
[1]);
2212 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2213 STORE(&d
[chan_index
], 0, chan_index
);
2217 case TGSI_OPCODE_DP3
:
2218 /* TGSI_OPCODE_DOT3 */
2219 FETCH( &r
[0], 0, CHAN_X
);
2220 FETCH( &r
[1], 1, CHAN_X
);
2221 micro_mul( &r
[0], &r
[0], &r
[1] );
2223 FETCH( &r
[1], 0, CHAN_Y
);
2224 FETCH( &r
[2], 1, CHAN_Y
);
2225 micro_mul( &r
[1], &r
[1], &r
[2] );
2226 micro_add( &r
[0], &r
[0], &r
[1] );
2228 FETCH( &r
[1], 0, CHAN_Z
);
2229 FETCH( &r
[2], 1, CHAN_Z
);
2230 micro_mul( &r
[1], &r
[1], &r
[2] );
2231 micro_add( &r
[0], &r
[0], &r
[1] );
2233 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2234 STORE( &r
[0], 0, chan_index
);
2238 case TGSI_OPCODE_DP4
:
2239 /* TGSI_OPCODE_DOT4 */
2240 FETCH(&r
[0], 0, CHAN_X
);
2241 FETCH(&r
[1], 1, CHAN_X
);
2243 micro_mul( &r
[0], &r
[0], &r
[1] );
2245 FETCH(&r
[1], 0, CHAN_Y
);
2246 FETCH(&r
[2], 1, CHAN_Y
);
2248 micro_mul( &r
[1], &r
[1], &r
[2] );
2249 micro_add( &r
[0], &r
[0], &r
[1] );
2251 FETCH(&r
[1], 0, CHAN_Z
);
2252 FETCH(&r
[2], 1, CHAN_Z
);
2254 micro_mul( &r
[1], &r
[1], &r
[2] );
2255 micro_add( &r
[0], &r
[0], &r
[1] );
2257 FETCH(&r
[1], 0, CHAN_W
);
2258 FETCH(&r
[2], 1, CHAN_W
);
2260 micro_mul( &r
[1], &r
[1], &r
[2] );
2261 micro_add( &r
[0], &r
[0], &r
[1] );
2263 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2264 STORE( &r
[0], 0, chan_index
);
2268 case TGSI_OPCODE_DST
:
2269 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2270 FETCH( &r
[0], 0, CHAN_Y
);
2271 FETCH( &r
[1], 1, CHAN_Y
);
2272 micro_mul(&d
[CHAN_Y
], &r
[0], &r
[1]);
2274 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2275 FETCH(&d
[CHAN_Z
], 0, CHAN_Z
);
2277 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2278 FETCH(&d
[CHAN_W
], 1, CHAN_W
);
2281 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2282 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2284 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2285 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2287 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2288 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2290 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2291 STORE(&d
[CHAN_W
], 0, CHAN_W
);
2295 case TGSI_OPCODE_MIN
:
2296 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2297 FETCH(&r
[0], 0, chan_index
);
2298 FETCH(&r
[1], 1, chan_index
);
2300 /* XXX use micro_min()?? */
2301 micro_lt(&d
[chan_index
], &r
[0], &r
[1], &r
[0], &r
[1]);
2303 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2304 STORE(&d
[chan_index
], 0, chan_index
);
2308 case TGSI_OPCODE_MAX
:
2309 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2310 FETCH(&r
[0], 0, chan_index
);
2311 FETCH(&r
[1], 1, chan_index
);
2313 /* XXX use micro_max()?? */
2314 micro_lt(&d
[chan_index
], &r
[0], &r
[1], &r
[1], &r
[0] );
2316 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2317 STORE(&d
[chan_index
], 0, chan_index
);
2321 case TGSI_OPCODE_SLT
:
2322 /* TGSI_OPCODE_SETLT */
2323 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2324 FETCH( &r
[0], 0, chan_index
);
2325 FETCH( &r
[1], 1, chan_index
);
2326 micro_lt(&d
[chan_index
], &r
[0], &r
[1], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
2328 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2329 STORE(&d
[chan_index
], 0, chan_index
);
2333 case TGSI_OPCODE_SGE
:
2334 /* TGSI_OPCODE_SETGE */
2335 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2336 FETCH( &r
[0], 0, chan_index
);
2337 FETCH( &r
[1], 1, chan_index
);
2338 micro_le(&d
[chan_index
], &r
[1], &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
2340 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2341 STORE(&d
[chan_index
], 0, chan_index
);
2345 case TGSI_OPCODE_MAD
:
2346 /* TGSI_OPCODE_MADD */
2347 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2348 FETCH( &r
[0], 0, chan_index
);
2349 FETCH( &r
[1], 1, chan_index
);
2350 micro_mul( &r
[0], &r
[0], &r
[1] );
2351 FETCH( &r
[1], 2, chan_index
);
2352 micro_add(&d
[chan_index
], &r
[0], &r
[1]);
2354 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2355 STORE(&d
[chan_index
], 0, chan_index
);
2359 case TGSI_OPCODE_SUB
:
2360 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2361 FETCH(&r
[0], 0, chan_index
);
2362 FETCH(&r
[1], 1, chan_index
);
2363 micro_sub(&d
[chan_index
], &r
[0], &r
[1]);
2365 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2366 STORE(&d
[chan_index
], 0, chan_index
);
2370 case TGSI_OPCODE_LRP
:
2371 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2372 FETCH(&r
[0], 0, chan_index
);
2373 FETCH(&r
[1], 1, chan_index
);
2374 FETCH(&r
[2], 2, chan_index
);
2375 micro_sub( &r
[1], &r
[1], &r
[2] );
2376 micro_mul( &r
[0], &r
[0], &r
[1] );
2377 micro_add(&d
[chan_index
], &r
[0], &r
[2]);
2379 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2380 STORE(&d
[chan_index
], 0, chan_index
);
2384 case TGSI_OPCODE_CND
:
2385 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2386 FETCH(&r
[0], 0, chan_index
);
2387 FETCH(&r
[1], 1, chan_index
);
2388 FETCH(&r
[2], 2, chan_index
);
2389 micro_lt(&d
[chan_index
], &mach
->Temps
[TEMP_HALF_I
].xyzw
[TEMP_HALF_C
], &r
[2], &r
[0], &r
[1]);
2391 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2392 STORE(&d
[chan_index
], 0, chan_index
);
2396 case TGSI_OPCODE_DP2A
:
2397 FETCH( &r
[0], 0, CHAN_X
);
2398 FETCH( &r
[1], 1, CHAN_X
);
2399 micro_mul( &r
[0], &r
[0], &r
[1] );
2401 FETCH( &r
[1], 0, CHAN_Y
);
2402 FETCH( &r
[2], 1, CHAN_Y
);
2403 micro_mul( &r
[1], &r
[1], &r
[2] );
2404 micro_add( &r
[0], &r
[0], &r
[1] );
2406 FETCH( &r
[2], 2, CHAN_X
);
2407 micro_add( &r
[0], &r
[0], &r
[2] );
2409 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2410 STORE( &r
[0], 0, chan_index
);
2414 case TGSI_OPCODE_FRC
:
2415 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2416 FETCH( &r
[0], 0, chan_index
);
2417 micro_frc(&d
[chan_index
], &r
[0]);
2419 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2420 STORE(&d
[chan_index
], 0, chan_index
);
2424 case TGSI_OPCODE_CLAMP
:
2425 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2426 FETCH(&r
[0], 0, chan_index
);
2427 FETCH(&r
[1], 1, chan_index
);
2428 micro_max(&r
[0], &r
[0], &r
[1]);
2429 FETCH(&r
[1], 2, chan_index
);
2430 micro_min(&d
[chan_index
], &r
[0], &r
[1]);
2432 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2433 STORE(&d
[chan_index
], 0, chan_index
);
2437 case TGSI_OPCODE_ROUND
:
2438 case TGSI_OPCODE_ARR
:
2439 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2440 FETCH( &r
[0], 0, chan_index
);
2441 micro_rnd(&d
[chan_index
], &r
[0]);
2443 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2444 STORE(&d
[chan_index
], 0, chan_index
);
2448 case TGSI_OPCODE_EX2
:
2449 FETCH(&r
[0], 0, CHAN_X
);
2451 micro_exp2( &r
[0], &r
[0] );
2453 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2454 STORE( &r
[0], 0, chan_index
);
2458 case TGSI_OPCODE_LG2
:
2459 FETCH( &r
[0], 0, CHAN_X
);
2460 micro_lg2( &r
[0], &r
[0] );
2461 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2462 STORE( &r
[0], 0, chan_index
);
2466 case TGSI_OPCODE_POW
:
2467 FETCH(&r
[0], 0, CHAN_X
);
2468 FETCH(&r
[1], 1, CHAN_X
);
2470 micro_pow( &r
[0], &r
[0], &r
[1] );
2472 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2473 STORE( &r
[0], 0, chan_index
);
2477 case TGSI_OPCODE_XPD
:
2478 FETCH(&r
[0], 0, CHAN_Y
);
2479 FETCH(&r
[1], 1, CHAN_Z
);
2481 micro_mul( &r
[2], &r
[0], &r
[1] );
2483 FETCH(&r
[3], 0, CHAN_Z
);
2484 FETCH(&r
[4], 1, CHAN_Y
);
2486 micro_mul( &r
[5], &r
[3], &r
[4] );
2487 micro_sub(&d
[CHAN_X
], &r
[2], &r
[5]);
2489 FETCH(&r
[2], 1, CHAN_X
);
2491 micro_mul( &r
[3], &r
[3], &r
[2] );
2493 FETCH(&r
[5], 0, CHAN_X
);
2495 micro_mul( &r
[1], &r
[1], &r
[5] );
2496 micro_sub(&d
[CHAN_Y
], &r
[3], &r
[1]);
2498 micro_mul( &r
[5], &r
[5], &r
[4] );
2499 micro_mul( &r
[0], &r
[0], &r
[2] );
2500 micro_sub(&d
[CHAN_Z
], &r
[5], &r
[0]);
2502 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2503 STORE(&d
[CHAN_X
], 0, CHAN_X
);
2505 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2506 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2508 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2509 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2511 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2512 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2516 case TGSI_OPCODE_ABS
:
2517 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2518 FETCH(&r
[0], 0, chan_index
);
2519 micro_abs(&d
[chan_index
], &r
[0]);
2521 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2522 STORE(&d
[chan_index
], 0, chan_index
);
2526 case TGSI_OPCODE_RCC
:
2527 FETCH(&r
[0], 0, CHAN_X
);
2528 micro_div(&r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0]);
2529 micro_float_clamp(&r
[0], &r
[0]);
2530 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2531 STORE(&r
[0], 0, chan_index
);
2535 case TGSI_OPCODE_DPH
:
2536 FETCH(&r
[0], 0, CHAN_X
);
2537 FETCH(&r
[1], 1, CHAN_X
);
2539 micro_mul( &r
[0], &r
[0], &r
[1] );
2541 FETCH(&r
[1], 0, CHAN_Y
);
2542 FETCH(&r
[2], 1, CHAN_Y
);
2544 micro_mul( &r
[1], &r
[1], &r
[2] );
2545 micro_add( &r
[0], &r
[0], &r
[1] );
2547 FETCH(&r
[1], 0, CHAN_Z
);
2548 FETCH(&r
[2], 1, CHAN_Z
);
2550 micro_mul( &r
[1], &r
[1], &r
[2] );
2551 micro_add( &r
[0], &r
[0], &r
[1] );
2553 FETCH(&r
[1], 1, CHAN_W
);
2555 micro_add( &r
[0], &r
[0], &r
[1] );
2557 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2558 STORE( &r
[0], 0, chan_index
);
2562 case TGSI_OPCODE_COS
:
2563 FETCH(&r
[0], 0, CHAN_X
);
2565 micro_cos( &r
[0], &r
[0] );
2567 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2568 STORE( &r
[0], 0, chan_index
);
2572 case TGSI_OPCODE_DDX
:
2573 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2574 FETCH( &r
[0], 0, chan_index
);
2575 micro_ddx(&d
[chan_index
], &r
[0]);
2577 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2578 STORE(&d
[chan_index
], 0, chan_index
);
2582 case TGSI_OPCODE_DDY
:
2583 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2584 FETCH( &r
[0], 0, chan_index
);
2585 micro_ddy(&d
[chan_index
], &r
[0]);
2587 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2588 STORE(&d
[chan_index
], 0, chan_index
);
2592 case TGSI_OPCODE_KILP
:
2593 exec_kilp (mach
, inst
);
2596 case TGSI_OPCODE_KIL
:
2597 exec_kil (mach
, inst
);
2600 case TGSI_OPCODE_PK2H
:
2604 case TGSI_OPCODE_PK2US
:
2608 case TGSI_OPCODE_PK4B
:
2612 case TGSI_OPCODE_PK4UB
:
2616 case TGSI_OPCODE_RFL
:
2617 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2618 IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2619 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2620 /* r0 = dp3(src0, src0) */
2621 FETCH(&r
[2], 0, CHAN_X
);
2622 micro_mul(&r
[0], &r
[2], &r
[2]);
2623 FETCH(&r
[4], 0, CHAN_Y
);
2624 micro_mul(&r
[8], &r
[4], &r
[4]);
2625 micro_add(&r
[0], &r
[0], &r
[8]);
2626 FETCH(&r
[6], 0, CHAN_Z
);
2627 micro_mul(&r
[8], &r
[6], &r
[6]);
2628 micro_add(&r
[0], &r
[0], &r
[8]);
2630 /* r1 = dp3(src0, src1) */
2631 FETCH(&r
[3], 1, CHAN_X
);
2632 micro_mul(&r
[1], &r
[2], &r
[3]);
2633 FETCH(&r
[5], 1, CHAN_Y
);
2634 micro_mul(&r
[8], &r
[4], &r
[5]);
2635 micro_add(&r
[1], &r
[1], &r
[8]);
2636 FETCH(&r
[7], 1, CHAN_Z
);
2637 micro_mul(&r
[8], &r
[6], &r
[7]);
2638 micro_add(&r
[1], &r
[1], &r
[8]);
2640 /* r1 = 2 * r1 / r0 */
2641 micro_add(&r
[1], &r
[1], &r
[1]);
2642 micro_div(&r
[1], &r
[1], &r
[0]);
2644 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2645 micro_mul(&r
[2], &r
[2], &r
[1]);
2646 micro_sub(&r
[2], &r
[2], &r
[3]);
2647 STORE(&r
[2], 0, CHAN_X
);
2649 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2650 micro_mul(&r
[4], &r
[4], &r
[1]);
2651 micro_sub(&r
[4], &r
[4], &r
[5]);
2652 STORE(&r
[4], 0, CHAN_Y
);
2654 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2655 micro_mul(&r
[6], &r
[6], &r
[1]);
2656 micro_sub(&r
[6], &r
[6], &r
[7]);
2657 STORE(&r
[6], 0, CHAN_Z
);
2660 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2661 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2665 case TGSI_OPCODE_SEQ
:
2666 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2667 FETCH( &r
[0], 0, chan_index
);
2668 FETCH( &r
[1], 1, chan_index
);
2669 micro_eq(&d
[chan_index
], &r
[0], &r
[1], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
2671 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2672 STORE(&d
[chan_index
], 0, chan_index
);
2676 case TGSI_OPCODE_SFL
:
2677 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2678 STORE(&mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, chan_index
);
2682 case TGSI_OPCODE_SGT
:
2683 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2684 FETCH( &r
[0], 0, chan_index
);
2685 FETCH( &r
[1], 1, chan_index
);
2686 micro_le(&d
[chan_index
], &r
[0], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
]);
2688 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2689 STORE(&d
[chan_index
], 0, chan_index
);
2693 case TGSI_OPCODE_SIN
:
2694 FETCH( &r
[0], 0, CHAN_X
);
2695 micro_sin( &r
[0], &r
[0] );
2696 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2697 STORE( &r
[0], 0, chan_index
);
2701 case TGSI_OPCODE_SLE
:
2702 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2703 FETCH( &r
[0], 0, chan_index
);
2704 FETCH( &r
[1], 1, chan_index
);
2705 micro_le(&d
[chan_index
], &r
[0], &r
[1], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
2707 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2708 STORE(&d
[chan_index
], 0, chan_index
);
2712 case TGSI_OPCODE_SNE
:
2713 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2714 FETCH( &r
[0], 0, chan_index
);
2715 FETCH( &r
[1], 1, chan_index
);
2716 micro_eq(&d
[chan_index
], &r
[0], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
]);
2718 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2719 STORE(&d
[chan_index
], 0, chan_index
);
2723 case TGSI_OPCODE_STR
:
2724 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2725 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, chan_index
);
2729 case TGSI_OPCODE_TEX
:
2730 /* simple texture lookup */
2731 /* src[0] = texcoord */
2732 /* src[1] = sampler unit */
2733 exec_tex(mach
, inst
, FALSE
, FALSE
);
2736 case TGSI_OPCODE_TXB
:
2737 /* Texture lookup with lod bias */
2738 /* src[0] = texcoord (src[0].w = LOD bias) */
2739 /* src[1] = sampler unit */
2740 exec_tex(mach
, inst
, TRUE
, FALSE
);
2743 case TGSI_OPCODE_TXD
:
2744 /* Texture lookup with explict partial derivatives */
2745 /* src[0] = texcoord */
2746 /* src[1] = d[strq]/dx */
2747 /* src[2] = d[strq]/dy */
2748 /* src[3] = sampler unit */
2749 exec_txd(mach
, inst
);
2752 case TGSI_OPCODE_TXL
:
2753 /* Texture lookup with explit LOD */
2754 /* src[0] = texcoord (src[0].w = LOD) */
2755 /* src[1] = sampler unit */
2756 exec_tex(mach
, inst
, TRUE
, FALSE
);
2759 case TGSI_OPCODE_TXP
:
2760 /* Texture lookup with projection */
2761 /* src[0] = texcoord (src[0].w = projection) */
2762 /* src[1] = sampler unit */
2763 exec_tex(mach
, inst
, FALSE
, TRUE
);
2766 case TGSI_OPCODE_UP2H
:
2770 case TGSI_OPCODE_UP2US
:
2774 case TGSI_OPCODE_UP4B
:
2778 case TGSI_OPCODE_UP4UB
:
2782 case TGSI_OPCODE_X2D
:
2783 FETCH(&r
[0], 1, CHAN_X
);
2784 FETCH(&r
[1], 1, CHAN_Y
);
2785 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2786 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2787 FETCH(&r
[2], 2, CHAN_X
);
2788 micro_mul(&r
[2], &r
[2], &r
[0]);
2789 FETCH(&r
[3], 2, CHAN_Y
);
2790 micro_mul(&r
[3], &r
[3], &r
[1]);
2791 micro_add(&r
[2], &r
[2], &r
[3]);
2792 FETCH(&r
[3], 0, CHAN_X
);
2793 micro_add(&d
[CHAN_X
], &r
[2], &r
[3]);
2796 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2797 IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2798 FETCH(&r
[2], 2, CHAN_Z
);
2799 micro_mul(&r
[2], &r
[2], &r
[0]);
2800 FETCH(&r
[3], 2, CHAN_W
);
2801 micro_mul(&r
[3], &r
[3], &r
[1]);
2802 micro_add(&r
[2], &r
[2], &r
[3]);
2803 FETCH(&r
[3], 0, CHAN_Y
);
2804 micro_add(&d
[CHAN_Y
], &r
[2], &r
[3]);
2807 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2808 STORE(&d
[CHAN_X
], 0, CHAN_X
);
2810 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2811 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2813 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2814 STORE(&d
[CHAN_X
], 0, CHAN_Z
);
2816 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2817 STORE(&d
[CHAN_Y
], 0, CHAN_W
);
2821 case TGSI_OPCODE_ARA
:
2825 case TGSI_OPCODE_BRA
:
2829 case TGSI_OPCODE_CAL
:
2830 /* skip the call if no execution channels are enabled */
2831 if (mach
->ExecMask
) {
2834 /* First, record the depths of the execution stacks.
2835 * This is important for deeply nested/looped return statements.
2836 * We have to unwind the stacks by the correct amount. For a
2837 * real code generator, we could determine the number of entries
2838 * to pop off each stack with simple static analysis and avoid
2839 * implementing this data structure at run time.
2841 mach
->CallStack
[mach
->CallStackTop
].CondStackTop
= mach
->CondStackTop
;
2842 mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
= mach
->LoopStackTop
;
2843 mach
->CallStack
[mach
->CallStackTop
].ContStackTop
= mach
->ContStackTop
;
2844 /* note that PC was already incremented above */
2845 mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
= *pc
;
2847 mach
->CallStackTop
++;
2849 /* Second, push the Cond, Loop, Cont, Func stacks */
2850 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
2851 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
2852 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2853 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
2854 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2855 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
2856 assert(mach
->FuncStackTop
< TGSI_EXEC_MAX_CALL_NESTING
);
2857 mach
->FuncStack
[mach
->FuncStackTop
++] = mach
->FuncMask
;
2859 /* Finally, jump to the subroutine */
2860 *pc
= inst
->Label
.Label
;
2864 case TGSI_OPCODE_RET
:
2865 mach
->FuncMask
&= ~mach
->ExecMask
;
2866 UPDATE_EXEC_MASK(mach
);
2868 if (mach
->FuncMask
== 0x0) {
2869 /* really return now (otherwise, keep executing */
2871 if (mach
->CallStackTop
== 0) {
2872 /* returning from main() */
2877 assert(mach
->CallStackTop
> 0);
2878 mach
->CallStackTop
--;
2880 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
2881 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
2883 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
2884 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
2886 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
2887 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
2889 assert(mach
->FuncStackTop
> 0);
2890 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
2892 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
2894 UPDATE_EXEC_MASK(mach
);
2898 case TGSI_OPCODE_SSG
:
2899 /* TGSI_OPCODE_SGN */
2900 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2901 FETCH( &r
[0], 0, chan_index
);
2902 micro_sgn(&d
[chan_index
], &r
[0]);
2904 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2905 STORE(&d
[chan_index
], 0, chan_index
);
2909 case TGSI_OPCODE_CMP
:
2910 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2911 FETCH(&r
[0], 0, chan_index
);
2912 FETCH(&r
[1], 1, chan_index
);
2913 FETCH(&r
[2], 2, chan_index
);
2914 micro_lt(&d
[chan_index
], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &r
[1], &r
[2]);
2916 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2917 STORE(&d
[chan_index
], 0, chan_index
);
2921 case TGSI_OPCODE_SCS
:
2922 if( IS_CHANNEL_ENABLED( *inst
, CHAN_X
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) ) {
2923 FETCH( &r
[0], 0, CHAN_X
);
2924 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2925 micro_cos(&r
[1], &r
[0]);
2926 STORE(&r
[1], 0, CHAN_X
);
2928 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2929 micro_sin(&r
[1], &r
[0]);
2930 STORE(&r
[1], 0, CHAN_Y
);
2933 if( IS_CHANNEL_ENABLED( *inst
, CHAN_Z
) ) {
2934 STORE( &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, CHAN_Z
);
2936 if( IS_CHANNEL_ENABLED( *inst
, CHAN_W
) ) {
2937 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2941 case TGSI_OPCODE_NRM
:
2942 /* 3-component vector normalize */
2943 if(IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2944 IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2945 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2946 /* r3 = sqrt(dp3(src0, src0)) */
2947 FETCH(&r
[0], 0, CHAN_X
);
2948 micro_mul(&r
[3], &r
[0], &r
[0]);
2949 FETCH(&r
[1], 0, CHAN_Y
);
2950 micro_mul(&r
[4], &r
[1], &r
[1]);
2951 micro_add(&r
[3], &r
[3], &r
[4]);
2952 FETCH(&r
[2], 0, CHAN_Z
);
2953 micro_mul(&r
[4], &r
[2], &r
[2]);
2954 micro_add(&r
[3], &r
[3], &r
[4]);
2955 micro_sqrt(&r
[3], &r
[3]);
2957 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2958 micro_div(&r
[0], &r
[0], &r
[3]);
2959 STORE(&r
[0], 0, CHAN_X
);
2961 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2962 micro_div(&r
[1], &r
[1], &r
[3]);
2963 STORE(&r
[1], 0, CHAN_Y
);
2965 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2966 micro_div(&r
[2], &r
[2], &r
[3]);
2967 STORE(&r
[2], 0, CHAN_Z
);
2970 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2971 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2975 case TGSI_OPCODE_NRM4
:
2976 /* 4-component vector normalize */
2978 union tgsi_exec_channel tmp
, dot
;
2980 /* tmp = dp4(src0, src0): */
2981 FETCH( &r
[0], 0, CHAN_X
);
2982 micro_mul( &tmp
, &r
[0], &r
[0] );
2984 FETCH( &r
[1], 0, CHAN_Y
);
2985 micro_mul( &dot
, &r
[1], &r
[1] );
2986 micro_add( &tmp
, &tmp
, &dot
);
2988 FETCH( &r
[2], 0, CHAN_Z
);
2989 micro_mul( &dot
, &r
[2], &r
[2] );
2990 micro_add( &tmp
, &tmp
, &dot
);
2992 FETCH( &r
[3], 0, CHAN_W
);
2993 micro_mul( &dot
, &r
[3], &r
[3] );
2994 micro_add( &tmp
, &tmp
, &dot
);
2996 /* tmp = 1 / sqrt(tmp) */
2997 micro_sqrt( &tmp
, &tmp
);
2998 micro_div( &tmp
, &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &tmp
);
3000 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3001 /* chan = chan * tmp */
3002 micro_mul( &r
[chan_index
], &tmp
, &r
[chan_index
] );
3003 STORE( &r
[chan_index
], 0, chan_index
);
3008 case TGSI_OPCODE_DIV
:
3012 case TGSI_OPCODE_DP2
:
3013 FETCH( &r
[0], 0, CHAN_X
);
3014 FETCH( &r
[1], 1, CHAN_X
);
3015 micro_mul( &r
[0], &r
[0], &r
[1] );
3017 FETCH( &r
[1], 0, CHAN_Y
);
3018 FETCH( &r
[2], 1, CHAN_Y
);
3019 micro_mul( &r
[1], &r
[1], &r
[2] );
3020 micro_add( &r
[0], &r
[0], &r
[1] );
3022 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3023 STORE( &r
[0], 0, chan_index
);
3027 case TGSI_OPCODE_IF
:
3029 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
3030 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
3031 FETCH( &r
[0], 0, CHAN_X
);
3032 /* update CondMask */
3034 mach
->CondMask
&= ~0x1;
3037 mach
->CondMask
&= ~0x2;
3040 mach
->CondMask
&= ~0x4;
3043 mach
->CondMask
&= ~0x8;
3045 UPDATE_EXEC_MASK(mach
);
3046 /* Todo: If CondMask==0, jump to ELSE */
3049 case TGSI_OPCODE_ELSE
:
3050 /* invert CondMask wrt previous mask */
3053 assert(mach
->CondStackTop
> 0);
3054 prevMask
= mach
->CondStack
[mach
->CondStackTop
- 1];
3055 mach
->CondMask
= ~mach
->CondMask
& prevMask
;
3056 UPDATE_EXEC_MASK(mach
);
3057 /* Todo: If CondMask==0, jump to ENDIF */
3061 case TGSI_OPCODE_ENDIF
:
3063 assert(mach
->CondStackTop
> 0);
3064 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
3065 UPDATE_EXEC_MASK(mach
);
3068 case TGSI_OPCODE_END
:
3069 /* halt execution */
3073 case TGSI_OPCODE_REP
:
3077 case TGSI_OPCODE_ENDREP
:
3081 case TGSI_OPCODE_PUSHA
:
3085 case TGSI_OPCODE_POPA
:
3089 case TGSI_OPCODE_CEIL
:
3090 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3091 FETCH( &r
[0], 0, chan_index
);
3092 micro_ceil(&d
[chan_index
], &r
[0]);
3094 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3095 STORE(&d
[chan_index
], 0, chan_index
);
3099 case TGSI_OPCODE_I2F
:
3100 exec_vector_unary(mach
, inst
, micro_i2f
);
3103 case TGSI_OPCODE_NOT
:
3104 exec_vector_unary(mach
, inst
, micro_not
);
3107 case TGSI_OPCODE_TRUNC
:
3108 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3109 FETCH( &r
[0], 0, chan_index
);
3110 micro_trunc(&d
[chan_index
], &r
[0]);
3112 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3113 STORE(&d
[chan_index
], 0, chan_index
);
3117 case TGSI_OPCODE_SHL
:
3118 exec_vector_binary(mach
, inst
, micro_shl
);
3121 case TGSI_OPCODE_AND
:
3122 exec_vector_binary(mach
, inst
, micro_and
);
3125 case TGSI_OPCODE_OR
:
3126 exec_vector_binary(mach
, inst
, micro_or
);
3129 case TGSI_OPCODE_MOD
:
3133 case TGSI_OPCODE_XOR
:
3134 exec_vector_binary(mach
, inst
, micro_xor
);
3137 case TGSI_OPCODE_SAD
:
3141 case TGSI_OPCODE_TXF
:
3145 case TGSI_OPCODE_TXQ
:
3149 case TGSI_OPCODE_EMIT
:
3153 case TGSI_OPCODE_ENDPRIM
:
3154 emit_primitive(mach
);
3157 case TGSI_OPCODE_BGNFOR
:
3158 assert(mach
->LoopCounterStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3159 for (chan_index
= 0; chan_index
< 3; chan_index
++) {
3160 FETCH( &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[chan_index
], 0, chan_index
);
3162 ++mach
->LoopCounterStackTop
;
3163 STORE(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
], 0, CHAN_X
);
3164 /* update LoopMask */
3165 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[0] <= 0.0f
) {
3166 mach
->LoopMask
&= ~0x1;
3168 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[1] <= 0.0f
) {
3169 mach
->LoopMask
&= ~0x2;
3171 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[2] <= 0.0f
) {
3172 mach
->LoopMask
&= ~0x4;
3174 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[3] <= 0.0f
) {
3175 mach
->LoopMask
&= ~0x8;
3177 /* TODO: if mach->LoopMask == 0, jump to end of loop */
3178 UPDATE_EXEC_MASK(mach
);
3179 /* fall-through (for now) */
3180 case TGSI_OPCODE_BGNLOOP
:
3181 /* push LoopMask and ContMasks */
3182 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3183 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
3184 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3185 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
3186 assert(mach
->LoopLabelStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3187 mach
->LoopLabelStack
[mach
->LoopLabelStackTop
++] = *pc
- 1;
3190 case TGSI_OPCODE_ENDFOR
:
3191 assert(mach
->LoopCounterStackTop
> 0);
3192 micro_sub(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
],
3193 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
],
3194 &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
]);
3195 /* update LoopMask */
3196 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[0] <= 0.0f
) {
3197 mach
->LoopMask
&= ~0x1;
3199 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[1] <= 0.0f
) {
3200 mach
->LoopMask
&= ~0x2;
3202 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[2] <= 0.0f
) {
3203 mach
->LoopMask
&= ~0x4;
3205 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[3] <= 0.0f
) {
3206 mach
->LoopMask
&= ~0x8;
3208 micro_add(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
],
3209 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
],
3210 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Z
]);
3211 assert(mach
->LoopLabelStackTop
> 0);
3212 inst
= mach
->Instructions
+ mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1];
3213 STORE(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[CHAN_X
], 0, CHAN_X
);
3214 /* Restore ContMask, but don't pop */
3215 assert(mach
->ContStackTop
> 0);
3216 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3217 UPDATE_EXEC_MASK(mach
);
3218 if (mach
->ExecMask
) {
3219 /* repeat loop: jump to instruction just past BGNLOOP */
3220 assert(mach
->LoopLabelStackTop
> 0);
3221 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3224 /* exit loop: pop LoopMask */
3225 assert(mach
->LoopStackTop
> 0);
3226 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3228 assert(mach
->ContStackTop
> 0);
3229 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3230 assert(mach
->LoopLabelStackTop
> 0);
3231 --mach
->LoopLabelStackTop
;
3232 assert(mach
->LoopCounterStackTop
> 0);
3233 --mach
->LoopCounterStackTop
;
3235 UPDATE_EXEC_MASK(mach
);
3238 case TGSI_OPCODE_ENDLOOP
:
3239 /* Restore ContMask, but don't pop */
3240 assert(mach
->ContStackTop
> 0);
3241 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3242 UPDATE_EXEC_MASK(mach
);
3243 if (mach
->ExecMask
) {
3244 /* repeat loop: jump to instruction just past BGNLOOP */
3245 assert(mach
->LoopLabelStackTop
> 0);
3246 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3249 /* exit loop: pop LoopMask */
3250 assert(mach
->LoopStackTop
> 0);
3251 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3253 assert(mach
->ContStackTop
> 0);
3254 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3255 assert(mach
->LoopLabelStackTop
> 0);
3256 --mach
->LoopLabelStackTop
;
3258 UPDATE_EXEC_MASK(mach
);
3261 case TGSI_OPCODE_BRK
:
3262 /* turn off loop channels for each enabled exec channel */
3263 mach
->LoopMask
&= ~mach
->ExecMask
;
3264 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3265 UPDATE_EXEC_MASK(mach
);
3268 case TGSI_OPCODE_CONT
:
3269 /* turn off cont channels for each enabled exec channel */
3270 mach
->ContMask
&= ~mach
->ExecMask
;
3271 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3272 UPDATE_EXEC_MASK(mach
);
3275 case TGSI_OPCODE_BGNSUB
:
3279 case TGSI_OPCODE_ENDSUB
:
3281 * XXX: This really should be a no-op. We should never reach this opcode.
3284 assert(mach
->CallStackTop
> 0);
3285 mach
->CallStackTop
--;
3287 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
3288 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
3290 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
3291 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
3293 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
3294 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
3296 assert(mach
->FuncStackTop
> 0);
3297 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
3299 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
3301 UPDATE_EXEC_MASK(mach
);
3304 case TGSI_OPCODE_NOP
:
3307 case TGSI_OPCODE_BREAKC
:
3308 FETCH(&r
[0], 0, CHAN_X
);
3309 /* update CondMask */
3310 if (r
[0].u
[0] && (mach
->ExecMask
& 0x1)) {
3311 mach
->LoopMask
&= ~0x1;
3313 if (r
[0].u
[1] && (mach
->ExecMask
& 0x2)) {
3314 mach
->LoopMask
&= ~0x2;
3316 if (r
[0].u
[2] && (mach
->ExecMask
& 0x4)) {
3317 mach
->LoopMask
&= ~0x4;
3319 if (r
[0].u
[3] && (mach
->ExecMask
& 0x8)) {
3320 mach
->LoopMask
&= ~0x8;
3322 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3323 UPDATE_EXEC_MASK(mach
);
3326 case TGSI_OPCODE_F2I
:
3327 exec_vector_unary(mach
, inst
, micro_f2i
);
3330 case TGSI_OPCODE_IDIV
:
3331 exec_vector_binary(mach
, inst
, micro_idiv
);
3334 case TGSI_OPCODE_IMAX
:
3335 exec_vector_binary(mach
, inst
, micro_imax
);
3338 case TGSI_OPCODE_IMIN
:
3339 exec_vector_binary(mach
, inst
, micro_imin
);
3342 case TGSI_OPCODE_INEG
:
3343 exec_vector_unary(mach
, inst
, micro_ineg
);
3346 case TGSI_OPCODE_ISGE
:
3347 exec_vector_binary(mach
, inst
, micro_isge
);
3350 case TGSI_OPCODE_ISHR
:
3351 exec_vector_binary(mach
, inst
, micro_ishr
);
3354 case TGSI_OPCODE_ISLT
:
3355 exec_vector_binary(mach
, inst
, micro_islt
);
3358 case TGSI_OPCODE_F2U
:
3359 exec_vector_unary(mach
, inst
, micro_f2u
);
3362 case TGSI_OPCODE_U2F
:
3363 exec_vector_unary(mach
, inst
, micro_u2f
);
3366 case TGSI_OPCODE_UADD
:
3367 exec_vector_binary(mach
, inst
, micro_uadd
);
3370 case TGSI_OPCODE_UDIV
:
3371 exec_vector_binary(mach
, inst
, micro_udiv
);
3374 case TGSI_OPCODE_UMAD
:
3375 exec_vector_trinary(mach
, inst
, micro_umad
);
3378 case TGSI_OPCODE_UMAX
:
3379 exec_vector_binary(mach
, inst
, micro_umax
);
3382 case TGSI_OPCODE_UMIN
:
3383 exec_vector_binary(mach
, inst
, micro_umin
);
3386 case TGSI_OPCODE_UMUL
:
3387 exec_vector_binary(mach
, inst
, micro_umul
);
3390 case TGSI_OPCODE_USEQ
:
3391 exec_vector_binary(mach
, inst
, micro_useq
);
3394 case TGSI_OPCODE_USGE
:
3395 exec_vector_binary(mach
, inst
, micro_usge
);
3398 case TGSI_OPCODE_USHR
:
3399 exec_vector_binary(mach
, inst
, micro_ushr
);
3402 case TGSI_OPCODE_USLT
:
3403 exec_vector_binary(mach
, inst
, micro_uslt
);
3406 case TGSI_OPCODE_USNE
:
3407 exec_vector_binary(mach
, inst
, micro_usne
);
3415 #define DEBUG_EXECUTION 0
3419 * Run TGSI interpreter.
3420 * \return bitmask of "alive" quad components
3423 tgsi_exec_machine_run( struct tgsi_exec_machine
*mach
)
3428 mach
->CondMask
= 0xf;
3429 mach
->LoopMask
= 0xf;
3430 mach
->ContMask
= 0xf;
3431 mach
->FuncMask
= 0xf;
3432 mach
->ExecMask
= 0xf;
3434 assert(mach
->CondStackTop
== 0);
3435 assert(mach
->LoopStackTop
== 0);
3436 assert(mach
->ContStackTop
== 0);
3437 assert(mach
->CallStackTop
== 0);
3439 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] = 0;
3440 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] = 0;
3442 if( mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
3443 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0] = 0;
3444 mach
->Primitives
[0] = 0;
3447 for (i
= 0; i
< QUAD_SIZE
; i
++) {
3448 mach
->Temps
[TEMP_CC_I
].xyzw
[TEMP_CC_C
].u
[i
] =
3449 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_X_SHIFT
) |
3450 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Y_SHIFT
) |
3451 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Z_SHIFT
) |
3452 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_W_SHIFT
);
3455 /* execute declarations (interpolants) */
3456 for (i
= 0; i
< mach
->NumDeclarations
; i
++) {
3457 exec_declaration( mach
, mach
->Declarations
+i
);
3462 struct tgsi_exec_vector temps
[TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
];
3463 struct tgsi_exec_vector outputs
[PIPE_MAX_ATTRIBS
];
3466 memcpy(temps
, mach
->Temps
, sizeof(temps
));
3467 memcpy(outputs
, mach
->Outputs
, sizeof(outputs
));
3470 /* execute instructions, until pc is set to -1 */
3476 tgsi_dump_instruction(&mach
->Instructions
[pc
], inst
++);
3479 assert(pc
< (int) mach
->NumInstructions
);
3480 exec_instruction(mach
, mach
->Instructions
+ pc
, &pc
);
3483 for (i
= 0; i
< TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
; i
++) {
3484 if (memcmp(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]))) {
3487 memcpy(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]));
3488 debug_printf("TEMP[%2u] = ", i
);
3489 for (j
= 0; j
< 4; j
++) {
3493 debug_printf("(%6f, %6f, %6f, %6f)\n",
3494 temps
[i
].xyzw
[0].f
[j
],
3495 temps
[i
].xyzw
[1].f
[j
],
3496 temps
[i
].xyzw
[2].f
[j
],
3497 temps
[i
].xyzw
[3].f
[j
]);
3501 for (i
= 0; i
< PIPE_MAX_ATTRIBS
; i
++) {
3502 if (memcmp(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]))) {
3505 memcpy(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]));
3506 debug_printf("OUT[%2u] = ", i
);
3507 for (j
= 0; j
< 4; j
++) {
3511 debug_printf("{%6f, %6f, %6f, %6f}\n",
3512 outputs
[i
].xyzw
[0].f
[j
],
3513 outputs
[i
].xyzw
[1].f
[j
],
3514 outputs
[i
].xyzw
[2].f
[j
],
3515 outputs
[i
].xyzw
[3].f
[j
]);
3524 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
3525 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
3527 * Scale back depth component.
3529 for (i
= 0; i
< 4; i
++)
3530 mach
->Outputs
[0].xyzw
[2].f
[i
] *= ctx
->DrawBuffer
->_DepthMaxF
;
3534 assert(mach
->CondStackTop
== 0);
3535 assert(mach
->LoopStackTop
== 0);
3536 assert(mach
->ContStackTop
== 0);
3537 assert(mach
->CallStackTop
== 0);
3539 return ~mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];