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->Switch.mask & 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 exec_break(struct tgsi_exec_machine
*mach
)
1801 if (mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_LOOP
) {
1802 /* turn off loop channels for each enabled exec channel */
1803 mach
->LoopMask
&= ~mach
->ExecMask
;
1804 /* Todo: if mach->LoopMask == 0, jump to end of loop */
1805 UPDATE_EXEC_MASK(mach
);
1807 assert(mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_SWITCH
);
1809 mach
->Switch
.mask
= 0x0;
1811 UPDATE_EXEC_MASK(mach
);
1816 exec_switch(struct tgsi_exec_machine
*mach
,
1817 const struct tgsi_full_instruction
*inst
)
1819 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
1820 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
1822 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
1823 fetch_source(mach
, &mach
->Switch
.selector
, &inst
->Src
[0], CHAN_X
);
1824 mach
->Switch
.mask
= 0x0;
1825 mach
->Switch
.defaultMask
= 0x0;
1827 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
1828 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_SWITCH
;
1830 UPDATE_EXEC_MASK(mach
);
1834 exec_case(struct tgsi_exec_machine
*mach
,
1835 const struct tgsi_full_instruction
*inst
)
1837 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
1838 union tgsi_exec_channel src
;
1841 fetch_source(mach
, &src
, &inst
->Src
[0], CHAN_X
);
1843 if (mach
->Switch
.selector
.u
[0] == src
.u
[0]) {
1846 if (mach
->Switch
.selector
.u
[1] == src
.u
[1]) {
1849 if (mach
->Switch
.selector
.u
[2] == src
.u
[2]) {
1852 if (mach
->Switch
.selector
.u
[3] == src
.u
[3]) {
1856 mach
->Switch
.defaultMask
|= mask
;
1858 mach
->Switch
.mask
|= mask
& prevMask
;
1860 UPDATE_EXEC_MASK(mach
);
1864 exec_default(struct tgsi_exec_machine
*mach
)
1866 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
1868 mach
->Switch
.mask
|= ~mach
->Switch
.defaultMask
& prevMask
;
1870 UPDATE_EXEC_MASK(mach
);
1874 exec_endswitch(struct tgsi_exec_machine
*mach
)
1876 mach
->Switch
= mach
->SwitchStack
[--mach
->SwitchStackTop
];
1877 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
1879 UPDATE_EXEC_MASK(mach
);
1883 micro_i2f(union tgsi_exec_channel
*dst
,
1884 const union tgsi_exec_channel
*src
)
1886 dst
->f
[0] = (float)src
->i
[0];
1887 dst
->f
[1] = (float)src
->i
[1];
1888 dst
->f
[2] = (float)src
->i
[2];
1889 dst
->f
[3] = (float)src
->i
[3];
1893 micro_not(union tgsi_exec_channel
*dst
,
1894 const union tgsi_exec_channel
*src
)
1896 dst
->u
[0] = ~src
->u
[0];
1897 dst
->u
[1] = ~src
->u
[1];
1898 dst
->u
[2] = ~src
->u
[2];
1899 dst
->u
[3] = ~src
->u
[3];
1903 micro_shl(union tgsi_exec_channel
*dst
,
1904 const union tgsi_exec_channel
*src
)
1906 dst
->u
[0] = src
[0].u
[0] << src
[1].u
[0];
1907 dst
->u
[1] = src
[0].u
[1] << src
[1].u
[1];
1908 dst
->u
[2] = src
[0].u
[2] << src
[1].u
[2];
1909 dst
->u
[3] = src
[0].u
[3] << src
[1].u
[3];
1913 micro_and(union tgsi_exec_channel
*dst
,
1914 const union tgsi_exec_channel
*src
)
1916 dst
->u
[0] = src
[0].u
[0] & src
[1].u
[0];
1917 dst
->u
[1] = src
[0].u
[1] & src
[1].u
[1];
1918 dst
->u
[2] = src
[0].u
[2] & src
[1].u
[2];
1919 dst
->u
[3] = src
[0].u
[3] & src
[1].u
[3];
1923 micro_or(union tgsi_exec_channel
*dst
,
1924 const union tgsi_exec_channel
*src
)
1926 dst
->u
[0] = src
[0].u
[0] | src
[1].u
[0];
1927 dst
->u
[1] = src
[0].u
[1] | src
[1].u
[1];
1928 dst
->u
[2] = src
[0].u
[2] | src
[1].u
[2];
1929 dst
->u
[3] = src
[0].u
[3] | src
[1].u
[3];
1933 micro_xor(union tgsi_exec_channel
*dst
,
1934 const union tgsi_exec_channel
*src
)
1936 dst
->u
[0] = src
[0].u
[0] ^ src
[1].u
[0];
1937 dst
->u
[1] = src
[0].u
[1] ^ src
[1].u
[1];
1938 dst
->u
[2] = src
[0].u
[2] ^ src
[1].u
[2];
1939 dst
->u
[3] = src
[0].u
[3] ^ src
[1].u
[3];
1943 micro_f2i(union tgsi_exec_channel
*dst
,
1944 const union tgsi_exec_channel
*src
)
1946 dst
->i
[0] = (int)src
->f
[0];
1947 dst
->i
[1] = (int)src
->f
[1];
1948 dst
->i
[2] = (int)src
->f
[2];
1949 dst
->i
[3] = (int)src
->f
[3];
1953 micro_idiv(union tgsi_exec_channel
*dst
,
1954 const union tgsi_exec_channel
*src
)
1956 dst
->i
[0] = src
[0].i
[0] / src
[1].i
[0];
1957 dst
->i
[1] = src
[0].i
[1] / src
[1].i
[1];
1958 dst
->i
[2] = src
[0].i
[2] / src
[1].i
[2];
1959 dst
->i
[3] = src
[0].i
[3] / src
[1].i
[3];
1963 micro_imax(union tgsi_exec_channel
*dst
,
1964 const union tgsi_exec_channel
*src
)
1966 dst
->i
[0] = src
[0].i
[0] > src
[1].i
[0] ? src
[0].i
[0] : src
[1].i
[0];
1967 dst
->i
[1] = src
[0].i
[1] > src
[1].i
[1] ? src
[0].i
[1] : src
[1].i
[1];
1968 dst
->i
[2] = src
[0].i
[2] > src
[1].i
[2] ? src
[0].i
[2] : src
[1].i
[2];
1969 dst
->i
[3] = src
[0].i
[3] > src
[1].i
[3] ? src
[0].i
[3] : src
[1].i
[3];
1973 micro_imin(union tgsi_exec_channel
*dst
,
1974 const union tgsi_exec_channel
*src
)
1976 dst
->i
[0] = src
[0].i
[0] < src
[1].i
[0] ? src
[0].i
[0] : src
[1].i
[0];
1977 dst
->i
[1] = src
[0].i
[1] < src
[1].i
[1] ? src
[0].i
[1] : src
[1].i
[1];
1978 dst
->i
[2] = src
[0].i
[2] < src
[1].i
[2] ? src
[0].i
[2] : src
[1].i
[2];
1979 dst
->i
[3] = src
[0].i
[3] < src
[1].i
[3] ? src
[0].i
[3] : src
[1].i
[3];
1983 micro_ineg(union tgsi_exec_channel
*dst
,
1984 const union tgsi_exec_channel
*src
)
1986 dst
->i
[0] = -src
->i
[0];
1987 dst
->i
[1] = -src
->i
[1];
1988 dst
->i
[2] = -src
->i
[2];
1989 dst
->i
[3] = -src
->i
[3];
1993 micro_isge(union tgsi_exec_channel
*dst
,
1994 const union tgsi_exec_channel
*src
)
1996 dst
->i
[0] = src
[0].i
[0] >= src
[1].i
[0] ? -1 : 0;
1997 dst
->i
[1] = src
[0].i
[1] >= src
[1].i
[1] ? -1 : 0;
1998 dst
->i
[2] = src
[0].i
[2] >= src
[1].i
[2] ? -1 : 0;
1999 dst
->i
[3] = src
[0].i
[3] >= src
[1].i
[3] ? -1 : 0;
2003 micro_ishr(union tgsi_exec_channel
*dst
,
2004 const union tgsi_exec_channel
*src
)
2006 dst
->i
[0] = src
[0].i
[0] >> src
[1].i
[0];
2007 dst
->i
[1] = src
[0].i
[1] >> src
[1].i
[1];
2008 dst
->i
[2] = src
[0].i
[2] >> src
[1].i
[2];
2009 dst
->i
[3] = src
[0].i
[3] >> src
[1].i
[3];
2013 micro_islt(union tgsi_exec_channel
*dst
,
2014 const union tgsi_exec_channel
*src
)
2016 dst
->i
[0] = src
[0].i
[0] < src
[1].i
[0] ? -1 : 0;
2017 dst
->i
[1] = src
[0].i
[1] < src
[1].i
[1] ? -1 : 0;
2018 dst
->i
[2] = src
[0].i
[2] < src
[1].i
[2] ? -1 : 0;
2019 dst
->i
[3] = src
[0].i
[3] < src
[1].i
[3] ? -1 : 0;
2023 micro_f2u(union tgsi_exec_channel
*dst
,
2024 const union tgsi_exec_channel
*src
)
2026 dst
->u
[0] = (uint
)src
->f
[0];
2027 dst
->u
[1] = (uint
)src
->f
[1];
2028 dst
->u
[2] = (uint
)src
->f
[2];
2029 dst
->u
[3] = (uint
)src
->f
[3];
2033 micro_u2f(union tgsi_exec_channel
*dst
,
2034 const union tgsi_exec_channel
*src
)
2036 dst
->f
[0] = (float)src
->u
[0];
2037 dst
->f
[1] = (float)src
->u
[1];
2038 dst
->f
[2] = (float)src
->u
[2];
2039 dst
->f
[3] = (float)src
->u
[3];
2043 micro_uadd(union tgsi_exec_channel
*dst
,
2044 const union tgsi_exec_channel
*src
)
2046 dst
->u
[0] = src
[0].u
[0] + src
[1].u
[0];
2047 dst
->u
[1] = src
[0].u
[1] + src
[1].u
[1];
2048 dst
->u
[2] = src
[0].u
[2] + src
[1].u
[2];
2049 dst
->u
[3] = src
[0].u
[3] + src
[1].u
[3];
2053 micro_udiv(union tgsi_exec_channel
*dst
,
2054 const union tgsi_exec_channel
*src
)
2056 dst
->u
[0] = src
[0].u
[0] / src
[1].u
[0];
2057 dst
->u
[1] = src
[0].u
[1] / src
[1].u
[1];
2058 dst
->u
[2] = src
[0].u
[2] / src
[1].u
[2];
2059 dst
->u
[3] = src
[0].u
[3] / src
[1].u
[3];
2063 micro_umad(union tgsi_exec_channel
*dst
,
2064 const union tgsi_exec_channel
*src
)
2066 dst
->u
[0] = src
[0].u
[0] * src
[1].u
[0] + src
[2].u
[0];
2067 dst
->u
[1] = src
[0].u
[1] * src
[1].u
[1] + src
[2].u
[1];
2068 dst
->u
[2] = src
[0].u
[2] * src
[1].u
[2] + src
[2].u
[2];
2069 dst
->u
[3] = src
[0].u
[3] * src
[1].u
[3] + src
[2].u
[3];
2073 micro_umax(union tgsi_exec_channel
*dst
,
2074 const union tgsi_exec_channel
*src
)
2076 dst
->u
[0] = src
[0].u
[0] > src
[1].u
[0] ? src
[0].u
[0] : src
[1].u
[0];
2077 dst
->u
[1] = src
[0].u
[1] > src
[1].u
[1] ? src
[0].u
[1] : src
[1].u
[1];
2078 dst
->u
[2] = src
[0].u
[2] > src
[1].u
[2] ? src
[0].u
[2] : src
[1].u
[2];
2079 dst
->u
[3] = src
[0].u
[3] > src
[1].u
[3] ? src
[0].u
[3] : src
[1].u
[3];
2083 micro_umin(union tgsi_exec_channel
*dst
,
2084 const union tgsi_exec_channel
*src
)
2086 dst
->u
[0] = src
[0].u
[0] < src
[1].u
[0] ? src
[0].u
[0] : src
[1].u
[0];
2087 dst
->u
[1] = src
[0].u
[1] < src
[1].u
[1] ? src
[0].u
[1] : src
[1].u
[1];
2088 dst
->u
[2] = src
[0].u
[2] < src
[1].u
[2] ? src
[0].u
[2] : src
[1].u
[2];
2089 dst
->u
[3] = src
[0].u
[3] < src
[1].u
[3] ? src
[0].u
[3] : src
[1].u
[3];
2093 micro_umul(union tgsi_exec_channel
*dst
,
2094 const union tgsi_exec_channel
*src
)
2096 dst
->u
[0] = src
[0].u
[0] * src
[1].u
[0];
2097 dst
->u
[1] = src
[0].u
[1] * src
[1].u
[1];
2098 dst
->u
[2] = src
[0].u
[2] * src
[1].u
[2];
2099 dst
->u
[3] = src
[0].u
[3] * src
[1].u
[3];
2103 micro_useq(union tgsi_exec_channel
*dst
,
2104 const union tgsi_exec_channel
*src
)
2106 dst
->u
[0] = src
[0].u
[0] == src
[1].u
[0] ? ~0 : 0;
2107 dst
->u
[1] = src
[0].u
[1] == src
[1].u
[1] ? ~0 : 0;
2108 dst
->u
[2] = src
[0].u
[2] == src
[1].u
[2] ? ~0 : 0;
2109 dst
->u
[3] = src
[0].u
[3] == src
[1].u
[3] ? ~0 : 0;
2113 micro_usge(union tgsi_exec_channel
*dst
,
2114 const union tgsi_exec_channel
*src
)
2116 dst
->u
[0] = src
[0].u
[0] >= src
[1].u
[0] ? ~0 : 0;
2117 dst
->u
[1] = src
[0].u
[1] >= src
[1].u
[1] ? ~0 : 0;
2118 dst
->u
[2] = src
[0].u
[2] >= src
[1].u
[2] ? ~0 : 0;
2119 dst
->u
[3] = src
[0].u
[3] >= src
[1].u
[3] ? ~0 : 0;
2123 micro_ushr(union tgsi_exec_channel
*dst
,
2124 const union tgsi_exec_channel
*src
)
2126 dst
->u
[0] = src
[0].u
[0] >> src
[1].u
[0];
2127 dst
->u
[1] = src
[0].u
[1] >> src
[1].u
[1];
2128 dst
->u
[2] = src
[0].u
[2] >> src
[1].u
[2];
2129 dst
->u
[3] = src
[0].u
[3] >> src
[1].u
[3];
2133 micro_uslt(union tgsi_exec_channel
*dst
,
2134 const union tgsi_exec_channel
*src
)
2136 dst
->u
[0] = src
[0].u
[0] < src
[1].u
[0] ? ~0 : 0;
2137 dst
->u
[1] = src
[0].u
[1] < src
[1].u
[1] ? ~0 : 0;
2138 dst
->u
[2] = src
[0].u
[2] < src
[1].u
[2] ? ~0 : 0;
2139 dst
->u
[3] = src
[0].u
[3] < src
[1].u
[3] ? ~0 : 0;
2143 micro_usne(union tgsi_exec_channel
*dst
,
2144 const union tgsi_exec_channel
*src
)
2146 dst
->u
[0] = src
[0].u
[0] != src
[1].u
[0] ? ~0 : 0;
2147 dst
->u
[1] = src
[0].u
[1] != src
[1].u
[1] ? ~0 : 0;
2148 dst
->u
[2] = src
[0].u
[2] != src
[1].u
[2] ? ~0 : 0;
2149 dst
->u
[3] = src
[0].u
[3] != src
[1].u
[3] ? ~0 : 0;
2154 struct tgsi_exec_machine
*mach
,
2155 const struct tgsi_full_instruction
*inst
,
2159 union tgsi_exec_channel r
[10];
2160 union tgsi_exec_channel d
[8];
2164 switch (inst
->Instruction
.Opcode
) {
2165 case TGSI_OPCODE_ARL
:
2166 case TGSI_OPCODE_FLR
:
2167 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2168 FETCH( &r
[0], 0, chan_index
);
2169 micro_flr(&d
[chan_index
], &r
[0]);
2171 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2172 STORE(&d
[chan_index
], 0, chan_index
);
2176 case TGSI_OPCODE_MOV
:
2177 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2178 FETCH(&d
[chan_index
], 0, chan_index
);
2180 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2181 STORE(&d
[chan_index
], 0, chan_index
);
2185 case TGSI_OPCODE_LIT
:
2186 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2187 FETCH( &r
[0], 0, CHAN_X
);
2188 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2189 micro_max(&d
[CHAN_Y
], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
2192 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2193 FETCH( &r
[1], 0, CHAN_Y
);
2194 micro_max( &r
[1], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
2196 FETCH( &r
[2], 0, CHAN_W
);
2197 micro_min( &r
[2], &r
[2], &mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
] );
2198 micro_max( &r
[2], &r
[2], &mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
] );
2199 micro_pow( &r
[1], &r
[1], &r
[2] );
2200 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
]);
2203 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2204 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2206 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2207 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2210 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2211 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2213 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2214 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2218 case TGSI_OPCODE_RCP
:
2219 /* TGSI_OPCODE_RECIP */
2220 FETCH( &r
[0], 0, CHAN_X
);
2221 micro_div( &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0] );
2222 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2223 STORE( &r
[0], 0, chan_index
);
2227 case TGSI_OPCODE_RSQ
:
2228 /* TGSI_OPCODE_RECIPSQRT */
2229 FETCH( &r
[0], 0, CHAN_X
);
2230 micro_abs( &r
[0], &r
[0] );
2231 micro_sqrt( &r
[0], &r
[0] );
2232 micro_div( &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0] );
2233 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2234 STORE( &r
[0], 0, chan_index
);
2238 case TGSI_OPCODE_EXP
:
2239 FETCH( &r
[0], 0, CHAN_X
);
2240 micro_flr( &r
[1], &r
[0] ); /* r1 = floor(r0) */
2241 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2242 micro_exp2( &r
[2], &r
[1] ); /* r2 = 2 ^ r1 */
2243 STORE( &r
[2], 0, CHAN_X
); /* store r2 */
2245 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2246 micro_sub( &r
[2], &r
[0], &r
[1] ); /* r2 = r0 - r1 */
2247 STORE( &r
[2], 0, CHAN_Y
); /* store r2 */
2249 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2250 micro_exp2( &r
[2], &r
[0] ); /* r2 = 2 ^ r0 */
2251 STORE( &r
[2], 0, CHAN_Z
); /* store r2 */
2253 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2254 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2258 case TGSI_OPCODE_LOG
:
2259 FETCH( &r
[0], 0, CHAN_X
);
2260 micro_abs( &r
[2], &r
[0] ); /* r2 = abs(r0) */
2261 micro_lg2( &r
[1], &r
[2] ); /* r1 = lg2(r2) */
2262 micro_flr( &r
[0], &r
[1] ); /* r0 = floor(r1) */
2263 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2264 STORE( &r
[0], 0, CHAN_X
);
2266 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2267 micro_exp2( &r
[0], &r
[0] ); /* r0 = 2 ^ r0 */
2268 micro_div( &r
[0], &r
[2], &r
[0] ); /* r0 = r2 / r0 */
2269 STORE( &r
[0], 0, CHAN_Y
);
2271 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2272 STORE( &r
[1], 0, CHAN_Z
);
2274 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2275 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2279 case TGSI_OPCODE_MUL
:
2280 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2281 FETCH(&r
[0], 0, chan_index
);
2282 FETCH(&r
[1], 1, chan_index
);
2283 micro_mul(&d
[chan_index
], &r
[0], &r
[1]);
2285 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2286 STORE(&d
[chan_index
], 0, chan_index
);
2290 case TGSI_OPCODE_ADD
:
2291 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2292 FETCH( &r
[0], 0, chan_index
);
2293 FETCH( &r
[1], 1, chan_index
);
2294 micro_add(&d
[chan_index
], &r
[0], &r
[1]);
2296 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2297 STORE(&d
[chan_index
], 0, chan_index
);
2301 case TGSI_OPCODE_DP3
:
2302 /* TGSI_OPCODE_DOT3 */
2303 FETCH( &r
[0], 0, CHAN_X
);
2304 FETCH( &r
[1], 1, CHAN_X
);
2305 micro_mul( &r
[0], &r
[0], &r
[1] );
2307 FETCH( &r
[1], 0, CHAN_Y
);
2308 FETCH( &r
[2], 1, CHAN_Y
);
2309 micro_mul( &r
[1], &r
[1], &r
[2] );
2310 micro_add( &r
[0], &r
[0], &r
[1] );
2312 FETCH( &r
[1], 0, CHAN_Z
);
2313 FETCH( &r
[2], 1, CHAN_Z
);
2314 micro_mul( &r
[1], &r
[1], &r
[2] );
2315 micro_add( &r
[0], &r
[0], &r
[1] );
2317 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2318 STORE( &r
[0], 0, chan_index
);
2322 case TGSI_OPCODE_DP4
:
2323 /* TGSI_OPCODE_DOT4 */
2324 FETCH(&r
[0], 0, CHAN_X
);
2325 FETCH(&r
[1], 1, CHAN_X
);
2327 micro_mul( &r
[0], &r
[0], &r
[1] );
2329 FETCH(&r
[1], 0, CHAN_Y
);
2330 FETCH(&r
[2], 1, CHAN_Y
);
2332 micro_mul( &r
[1], &r
[1], &r
[2] );
2333 micro_add( &r
[0], &r
[0], &r
[1] );
2335 FETCH(&r
[1], 0, CHAN_Z
);
2336 FETCH(&r
[2], 1, CHAN_Z
);
2338 micro_mul( &r
[1], &r
[1], &r
[2] );
2339 micro_add( &r
[0], &r
[0], &r
[1] );
2341 FETCH(&r
[1], 0, CHAN_W
);
2342 FETCH(&r
[2], 1, CHAN_W
);
2344 micro_mul( &r
[1], &r
[1], &r
[2] );
2345 micro_add( &r
[0], &r
[0], &r
[1] );
2347 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2348 STORE( &r
[0], 0, chan_index
);
2352 case TGSI_OPCODE_DST
:
2353 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2354 FETCH( &r
[0], 0, CHAN_Y
);
2355 FETCH( &r
[1], 1, CHAN_Y
);
2356 micro_mul(&d
[CHAN_Y
], &r
[0], &r
[1]);
2358 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2359 FETCH(&d
[CHAN_Z
], 0, CHAN_Z
);
2361 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2362 FETCH(&d
[CHAN_W
], 1, CHAN_W
);
2365 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2366 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2368 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2369 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2371 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2372 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2374 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2375 STORE(&d
[CHAN_W
], 0, CHAN_W
);
2379 case TGSI_OPCODE_MIN
:
2380 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2381 FETCH(&r
[0], 0, chan_index
);
2382 FETCH(&r
[1], 1, chan_index
);
2384 /* XXX use micro_min()?? */
2385 micro_lt(&d
[chan_index
], &r
[0], &r
[1], &r
[0], &r
[1]);
2387 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2388 STORE(&d
[chan_index
], 0, chan_index
);
2392 case TGSI_OPCODE_MAX
:
2393 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2394 FETCH(&r
[0], 0, chan_index
);
2395 FETCH(&r
[1], 1, chan_index
);
2397 /* XXX use micro_max()?? */
2398 micro_lt(&d
[chan_index
], &r
[0], &r
[1], &r
[1], &r
[0] );
2400 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2401 STORE(&d
[chan_index
], 0, chan_index
);
2405 case TGSI_OPCODE_SLT
:
2406 /* TGSI_OPCODE_SETLT */
2407 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2408 FETCH( &r
[0], 0, chan_index
);
2409 FETCH( &r
[1], 1, chan_index
);
2410 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
]);
2412 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2413 STORE(&d
[chan_index
], 0, chan_index
);
2417 case TGSI_OPCODE_SGE
:
2418 /* TGSI_OPCODE_SETGE */
2419 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2420 FETCH( &r
[0], 0, chan_index
);
2421 FETCH( &r
[1], 1, chan_index
);
2422 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
]);
2424 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2425 STORE(&d
[chan_index
], 0, chan_index
);
2429 case TGSI_OPCODE_MAD
:
2430 /* TGSI_OPCODE_MADD */
2431 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2432 FETCH( &r
[0], 0, chan_index
);
2433 FETCH( &r
[1], 1, chan_index
);
2434 micro_mul( &r
[0], &r
[0], &r
[1] );
2435 FETCH( &r
[1], 2, chan_index
);
2436 micro_add(&d
[chan_index
], &r
[0], &r
[1]);
2438 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2439 STORE(&d
[chan_index
], 0, chan_index
);
2443 case TGSI_OPCODE_SUB
:
2444 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2445 FETCH(&r
[0], 0, chan_index
);
2446 FETCH(&r
[1], 1, chan_index
);
2447 micro_sub(&d
[chan_index
], &r
[0], &r
[1]);
2449 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2450 STORE(&d
[chan_index
], 0, chan_index
);
2454 case TGSI_OPCODE_LRP
:
2455 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2456 FETCH(&r
[0], 0, chan_index
);
2457 FETCH(&r
[1], 1, chan_index
);
2458 FETCH(&r
[2], 2, chan_index
);
2459 micro_sub( &r
[1], &r
[1], &r
[2] );
2460 micro_mul( &r
[0], &r
[0], &r
[1] );
2461 micro_add(&d
[chan_index
], &r
[0], &r
[2]);
2463 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2464 STORE(&d
[chan_index
], 0, chan_index
);
2468 case TGSI_OPCODE_CND
:
2469 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2470 FETCH(&r
[0], 0, chan_index
);
2471 FETCH(&r
[1], 1, chan_index
);
2472 FETCH(&r
[2], 2, chan_index
);
2473 micro_lt(&d
[chan_index
], &mach
->Temps
[TEMP_HALF_I
].xyzw
[TEMP_HALF_C
], &r
[2], &r
[0], &r
[1]);
2475 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2476 STORE(&d
[chan_index
], 0, chan_index
);
2480 case TGSI_OPCODE_DP2A
:
2481 FETCH( &r
[0], 0, CHAN_X
);
2482 FETCH( &r
[1], 1, CHAN_X
);
2483 micro_mul( &r
[0], &r
[0], &r
[1] );
2485 FETCH( &r
[1], 0, CHAN_Y
);
2486 FETCH( &r
[2], 1, CHAN_Y
);
2487 micro_mul( &r
[1], &r
[1], &r
[2] );
2488 micro_add( &r
[0], &r
[0], &r
[1] );
2490 FETCH( &r
[2], 2, CHAN_X
);
2491 micro_add( &r
[0], &r
[0], &r
[2] );
2493 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2494 STORE( &r
[0], 0, chan_index
);
2498 case TGSI_OPCODE_FRC
:
2499 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2500 FETCH( &r
[0], 0, chan_index
);
2501 micro_frc(&d
[chan_index
], &r
[0]);
2503 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2504 STORE(&d
[chan_index
], 0, chan_index
);
2508 case TGSI_OPCODE_CLAMP
:
2509 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2510 FETCH(&r
[0], 0, chan_index
);
2511 FETCH(&r
[1], 1, chan_index
);
2512 micro_max(&r
[0], &r
[0], &r
[1]);
2513 FETCH(&r
[1], 2, chan_index
);
2514 micro_min(&d
[chan_index
], &r
[0], &r
[1]);
2516 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2517 STORE(&d
[chan_index
], 0, chan_index
);
2521 case TGSI_OPCODE_ROUND
:
2522 case TGSI_OPCODE_ARR
:
2523 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2524 FETCH( &r
[0], 0, chan_index
);
2525 micro_rnd(&d
[chan_index
], &r
[0]);
2527 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2528 STORE(&d
[chan_index
], 0, chan_index
);
2532 case TGSI_OPCODE_EX2
:
2533 FETCH(&r
[0], 0, CHAN_X
);
2535 micro_exp2( &r
[0], &r
[0] );
2537 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2538 STORE( &r
[0], 0, chan_index
);
2542 case TGSI_OPCODE_LG2
:
2543 FETCH( &r
[0], 0, CHAN_X
);
2544 micro_lg2( &r
[0], &r
[0] );
2545 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2546 STORE( &r
[0], 0, chan_index
);
2550 case TGSI_OPCODE_POW
:
2551 FETCH(&r
[0], 0, CHAN_X
);
2552 FETCH(&r
[1], 1, CHAN_X
);
2554 micro_pow( &r
[0], &r
[0], &r
[1] );
2556 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2557 STORE( &r
[0], 0, chan_index
);
2561 case TGSI_OPCODE_XPD
:
2562 FETCH(&r
[0], 0, CHAN_Y
);
2563 FETCH(&r
[1], 1, CHAN_Z
);
2565 micro_mul( &r
[2], &r
[0], &r
[1] );
2567 FETCH(&r
[3], 0, CHAN_Z
);
2568 FETCH(&r
[4], 1, CHAN_Y
);
2570 micro_mul( &r
[5], &r
[3], &r
[4] );
2571 micro_sub(&d
[CHAN_X
], &r
[2], &r
[5]);
2573 FETCH(&r
[2], 1, CHAN_X
);
2575 micro_mul( &r
[3], &r
[3], &r
[2] );
2577 FETCH(&r
[5], 0, CHAN_X
);
2579 micro_mul( &r
[1], &r
[1], &r
[5] );
2580 micro_sub(&d
[CHAN_Y
], &r
[3], &r
[1]);
2582 micro_mul( &r
[5], &r
[5], &r
[4] );
2583 micro_mul( &r
[0], &r
[0], &r
[2] );
2584 micro_sub(&d
[CHAN_Z
], &r
[5], &r
[0]);
2586 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2587 STORE(&d
[CHAN_X
], 0, CHAN_X
);
2589 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2590 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2592 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2593 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2595 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2596 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2600 case TGSI_OPCODE_ABS
:
2601 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2602 FETCH(&r
[0], 0, chan_index
);
2603 micro_abs(&d
[chan_index
], &r
[0]);
2605 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2606 STORE(&d
[chan_index
], 0, chan_index
);
2610 case TGSI_OPCODE_RCC
:
2611 FETCH(&r
[0], 0, CHAN_X
);
2612 micro_div(&r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0]);
2613 micro_float_clamp(&r
[0], &r
[0]);
2614 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2615 STORE(&r
[0], 0, chan_index
);
2619 case TGSI_OPCODE_DPH
:
2620 FETCH(&r
[0], 0, CHAN_X
);
2621 FETCH(&r
[1], 1, CHAN_X
);
2623 micro_mul( &r
[0], &r
[0], &r
[1] );
2625 FETCH(&r
[1], 0, CHAN_Y
);
2626 FETCH(&r
[2], 1, CHAN_Y
);
2628 micro_mul( &r
[1], &r
[1], &r
[2] );
2629 micro_add( &r
[0], &r
[0], &r
[1] );
2631 FETCH(&r
[1], 0, CHAN_Z
);
2632 FETCH(&r
[2], 1, CHAN_Z
);
2634 micro_mul( &r
[1], &r
[1], &r
[2] );
2635 micro_add( &r
[0], &r
[0], &r
[1] );
2637 FETCH(&r
[1], 1, CHAN_W
);
2639 micro_add( &r
[0], &r
[0], &r
[1] );
2641 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2642 STORE( &r
[0], 0, chan_index
);
2646 case TGSI_OPCODE_COS
:
2647 FETCH(&r
[0], 0, CHAN_X
);
2649 micro_cos( &r
[0], &r
[0] );
2651 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2652 STORE( &r
[0], 0, chan_index
);
2656 case TGSI_OPCODE_DDX
:
2657 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2658 FETCH( &r
[0], 0, chan_index
);
2659 micro_ddx(&d
[chan_index
], &r
[0]);
2661 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2662 STORE(&d
[chan_index
], 0, chan_index
);
2666 case TGSI_OPCODE_DDY
:
2667 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2668 FETCH( &r
[0], 0, chan_index
);
2669 micro_ddy(&d
[chan_index
], &r
[0]);
2671 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2672 STORE(&d
[chan_index
], 0, chan_index
);
2676 case TGSI_OPCODE_KILP
:
2677 exec_kilp (mach
, inst
);
2680 case TGSI_OPCODE_KIL
:
2681 exec_kil (mach
, inst
);
2684 case TGSI_OPCODE_PK2H
:
2688 case TGSI_OPCODE_PK2US
:
2692 case TGSI_OPCODE_PK4B
:
2696 case TGSI_OPCODE_PK4UB
:
2700 case TGSI_OPCODE_RFL
:
2701 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2702 IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2703 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2704 /* r0 = dp3(src0, src0) */
2705 FETCH(&r
[2], 0, CHAN_X
);
2706 micro_mul(&r
[0], &r
[2], &r
[2]);
2707 FETCH(&r
[4], 0, CHAN_Y
);
2708 micro_mul(&r
[8], &r
[4], &r
[4]);
2709 micro_add(&r
[0], &r
[0], &r
[8]);
2710 FETCH(&r
[6], 0, CHAN_Z
);
2711 micro_mul(&r
[8], &r
[6], &r
[6]);
2712 micro_add(&r
[0], &r
[0], &r
[8]);
2714 /* r1 = dp3(src0, src1) */
2715 FETCH(&r
[3], 1, CHAN_X
);
2716 micro_mul(&r
[1], &r
[2], &r
[3]);
2717 FETCH(&r
[5], 1, CHAN_Y
);
2718 micro_mul(&r
[8], &r
[4], &r
[5]);
2719 micro_add(&r
[1], &r
[1], &r
[8]);
2720 FETCH(&r
[7], 1, CHAN_Z
);
2721 micro_mul(&r
[8], &r
[6], &r
[7]);
2722 micro_add(&r
[1], &r
[1], &r
[8]);
2724 /* r1 = 2 * r1 / r0 */
2725 micro_add(&r
[1], &r
[1], &r
[1]);
2726 micro_div(&r
[1], &r
[1], &r
[0]);
2728 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2729 micro_mul(&r
[2], &r
[2], &r
[1]);
2730 micro_sub(&r
[2], &r
[2], &r
[3]);
2731 STORE(&r
[2], 0, CHAN_X
);
2733 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2734 micro_mul(&r
[4], &r
[4], &r
[1]);
2735 micro_sub(&r
[4], &r
[4], &r
[5]);
2736 STORE(&r
[4], 0, CHAN_Y
);
2738 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2739 micro_mul(&r
[6], &r
[6], &r
[1]);
2740 micro_sub(&r
[6], &r
[6], &r
[7]);
2741 STORE(&r
[6], 0, CHAN_Z
);
2744 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2745 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2749 case TGSI_OPCODE_SEQ
:
2750 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2751 FETCH( &r
[0], 0, chan_index
);
2752 FETCH( &r
[1], 1, chan_index
);
2753 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
]);
2755 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2756 STORE(&d
[chan_index
], 0, chan_index
);
2760 case TGSI_OPCODE_SFL
:
2761 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2762 STORE(&mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, chan_index
);
2766 case TGSI_OPCODE_SGT
:
2767 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2768 FETCH( &r
[0], 0, chan_index
);
2769 FETCH( &r
[1], 1, chan_index
);
2770 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
]);
2772 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2773 STORE(&d
[chan_index
], 0, chan_index
);
2777 case TGSI_OPCODE_SIN
:
2778 FETCH( &r
[0], 0, CHAN_X
);
2779 micro_sin( &r
[0], &r
[0] );
2780 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2781 STORE( &r
[0], 0, chan_index
);
2785 case TGSI_OPCODE_SLE
:
2786 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2787 FETCH( &r
[0], 0, chan_index
);
2788 FETCH( &r
[1], 1, chan_index
);
2789 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
]);
2791 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2792 STORE(&d
[chan_index
], 0, chan_index
);
2796 case TGSI_OPCODE_SNE
:
2797 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2798 FETCH( &r
[0], 0, chan_index
);
2799 FETCH( &r
[1], 1, chan_index
);
2800 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
]);
2802 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2803 STORE(&d
[chan_index
], 0, chan_index
);
2807 case TGSI_OPCODE_STR
:
2808 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2809 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, chan_index
);
2813 case TGSI_OPCODE_TEX
:
2814 /* simple texture lookup */
2815 /* src[0] = texcoord */
2816 /* src[1] = sampler unit */
2817 exec_tex(mach
, inst
, FALSE
, FALSE
);
2820 case TGSI_OPCODE_TXB
:
2821 /* Texture lookup with lod bias */
2822 /* src[0] = texcoord (src[0].w = LOD bias) */
2823 /* src[1] = sampler unit */
2824 exec_tex(mach
, inst
, TRUE
, FALSE
);
2827 case TGSI_OPCODE_TXD
:
2828 /* Texture lookup with explict partial derivatives */
2829 /* src[0] = texcoord */
2830 /* src[1] = d[strq]/dx */
2831 /* src[2] = d[strq]/dy */
2832 /* src[3] = sampler unit */
2833 exec_txd(mach
, inst
);
2836 case TGSI_OPCODE_TXL
:
2837 /* Texture lookup with explit LOD */
2838 /* src[0] = texcoord (src[0].w = LOD) */
2839 /* src[1] = sampler unit */
2840 exec_tex(mach
, inst
, TRUE
, FALSE
);
2843 case TGSI_OPCODE_TXP
:
2844 /* Texture lookup with projection */
2845 /* src[0] = texcoord (src[0].w = projection) */
2846 /* src[1] = sampler unit */
2847 exec_tex(mach
, inst
, FALSE
, TRUE
);
2850 case TGSI_OPCODE_UP2H
:
2854 case TGSI_OPCODE_UP2US
:
2858 case TGSI_OPCODE_UP4B
:
2862 case TGSI_OPCODE_UP4UB
:
2866 case TGSI_OPCODE_X2D
:
2867 FETCH(&r
[0], 1, CHAN_X
);
2868 FETCH(&r
[1], 1, CHAN_Y
);
2869 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2870 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2871 FETCH(&r
[2], 2, CHAN_X
);
2872 micro_mul(&r
[2], &r
[2], &r
[0]);
2873 FETCH(&r
[3], 2, CHAN_Y
);
2874 micro_mul(&r
[3], &r
[3], &r
[1]);
2875 micro_add(&r
[2], &r
[2], &r
[3]);
2876 FETCH(&r
[3], 0, CHAN_X
);
2877 micro_add(&d
[CHAN_X
], &r
[2], &r
[3]);
2880 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2881 IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2882 FETCH(&r
[2], 2, CHAN_Z
);
2883 micro_mul(&r
[2], &r
[2], &r
[0]);
2884 FETCH(&r
[3], 2, CHAN_W
);
2885 micro_mul(&r
[3], &r
[3], &r
[1]);
2886 micro_add(&r
[2], &r
[2], &r
[3]);
2887 FETCH(&r
[3], 0, CHAN_Y
);
2888 micro_add(&d
[CHAN_Y
], &r
[2], &r
[3]);
2891 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2892 STORE(&d
[CHAN_X
], 0, CHAN_X
);
2894 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2895 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2897 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2898 STORE(&d
[CHAN_X
], 0, CHAN_Z
);
2900 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2901 STORE(&d
[CHAN_Y
], 0, CHAN_W
);
2905 case TGSI_OPCODE_ARA
:
2909 case TGSI_OPCODE_BRA
:
2913 case TGSI_OPCODE_CAL
:
2914 /* skip the call if no execution channels are enabled */
2915 if (mach
->ExecMask
) {
2918 /* First, record the depths of the execution stacks.
2919 * This is important for deeply nested/looped return statements.
2920 * We have to unwind the stacks by the correct amount. For a
2921 * real code generator, we could determine the number of entries
2922 * to pop off each stack with simple static analysis and avoid
2923 * implementing this data structure at run time.
2925 mach
->CallStack
[mach
->CallStackTop
].CondStackTop
= mach
->CondStackTop
;
2926 mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
= mach
->LoopStackTop
;
2927 mach
->CallStack
[mach
->CallStackTop
].ContStackTop
= mach
->ContStackTop
;
2928 mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
= mach
->SwitchStackTop
;
2929 mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
= mach
->BreakStackTop
;
2930 /* note that PC was already incremented above */
2931 mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
= *pc
;
2933 mach
->CallStackTop
++;
2935 /* Second, push the Cond, Loop, Cont, Func stacks */
2936 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
2937 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2938 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2939 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
2940 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
2941 assert(mach
->FuncStackTop
< TGSI_EXEC_MAX_CALL_NESTING
);
2943 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
2944 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
2945 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
2946 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
2947 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
2948 mach
->FuncStack
[mach
->FuncStackTop
++] = mach
->FuncMask
;
2950 /* Finally, jump to the subroutine */
2951 *pc
= inst
->Label
.Label
;
2955 case TGSI_OPCODE_RET
:
2956 mach
->FuncMask
&= ~mach
->ExecMask
;
2957 UPDATE_EXEC_MASK(mach
);
2959 if (mach
->FuncMask
== 0x0) {
2960 /* really return now (otherwise, keep executing */
2962 if (mach
->CallStackTop
== 0) {
2963 /* returning from main() */
2968 assert(mach
->CallStackTop
> 0);
2969 mach
->CallStackTop
--;
2971 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
2972 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
2974 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
2975 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
2977 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
2978 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
2980 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
2981 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
2983 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
2984 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
2986 assert(mach
->FuncStackTop
> 0);
2987 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
2989 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
2991 UPDATE_EXEC_MASK(mach
);
2995 case TGSI_OPCODE_SSG
:
2996 /* TGSI_OPCODE_SGN */
2997 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2998 FETCH( &r
[0], 0, chan_index
);
2999 micro_sgn(&d
[chan_index
], &r
[0]);
3001 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3002 STORE(&d
[chan_index
], 0, chan_index
);
3006 case TGSI_OPCODE_CMP
:
3007 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3008 FETCH(&r
[0], 0, chan_index
);
3009 FETCH(&r
[1], 1, chan_index
);
3010 FETCH(&r
[2], 2, chan_index
);
3011 micro_lt(&d
[chan_index
], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &r
[1], &r
[2]);
3013 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3014 STORE(&d
[chan_index
], 0, chan_index
);
3018 case TGSI_OPCODE_SCS
:
3019 if( IS_CHANNEL_ENABLED( *inst
, CHAN_X
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) ) {
3020 FETCH( &r
[0], 0, CHAN_X
);
3021 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
3022 micro_cos(&r
[1], &r
[0]);
3023 STORE(&r
[1], 0, CHAN_X
);
3025 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
3026 micro_sin(&r
[1], &r
[0]);
3027 STORE(&r
[1], 0, CHAN_Y
);
3030 if( IS_CHANNEL_ENABLED( *inst
, CHAN_Z
) ) {
3031 STORE( &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, CHAN_Z
);
3033 if( IS_CHANNEL_ENABLED( *inst
, CHAN_W
) ) {
3034 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
3038 case TGSI_OPCODE_NRM
:
3039 /* 3-component vector normalize */
3040 if(IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
3041 IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
3042 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
3043 /* r3 = sqrt(dp3(src0, src0)) */
3044 FETCH(&r
[0], 0, CHAN_X
);
3045 micro_mul(&r
[3], &r
[0], &r
[0]);
3046 FETCH(&r
[1], 0, CHAN_Y
);
3047 micro_mul(&r
[4], &r
[1], &r
[1]);
3048 micro_add(&r
[3], &r
[3], &r
[4]);
3049 FETCH(&r
[2], 0, CHAN_Z
);
3050 micro_mul(&r
[4], &r
[2], &r
[2]);
3051 micro_add(&r
[3], &r
[3], &r
[4]);
3052 micro_sqrt(&r
[3], &r
[3]);
3054 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
3055 micro_div(&r
[0], &r
[0], &r
[3]);
3056 STORE(&r
[0], 0, CHAN_X
);
3058 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
3059 micro_div(&r
[1], &r
[1], &r
[3]);
3060 STORE(&r
[1], 0, CHAN_Y
);
3062 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
3063 micro_div(&r
[2], &r
[2], &r
[3]);
3064 STORE(&r
[2], 0, CHAN_Z
);
3067 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
3068 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
3072 case TGSI_OPCODE_NRM4
:
3073 /* 4-component vector normalize */
3075 union tgsi_exec_channel tmp
, dot
;
3077 /* tmp = dp4(src0, src0): */
3078 FETCH( &r
[0], 0, CHAN_X
);
3079 micro_mul( &tmp
, &r
[0], &r
[0] );
3081 FETCH( &r
[1], 0, CHAN_Y
);
3082 micro_mul( &dot
, &r
[1], &r
[1] );
3083 micro_add( &tmp
, &tmp
, &dot
);
3085 FETCH( &r
[2], 0, CHAN_Z
);
3086 micro_mul( &dot
, &r
[2], &r
[2] );
3087 micro_add( &tmp
, &tmp
, &dot
);
3089 FETCH( &r
[3], 0, CHAN_W
);
3090 micro_mul( &dot
, &r
[3], &r
[3] );
3091 micro_add( &tmp
, &tmp
, &dot
);
3093 /* tmp = 1 / sqrt(tmp) */
3094 micro_sqrt( &tmp
, &tmp
);
3095 micro_div( &tmp
, &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &tmp
);
3097 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3098 /* chan = chan * tmp */
3099 micro_mul( &r
[chan_index
], &tmp
, &r
[chan_index
] );
3100 STORE( &r
[chan_index
], 0, chan_index
);
3105 case TGSI_OPCODE_DIV
:
3109 case TGSI_OPCODE_DP2
:
3110 FETCH( &r
[0], 0, CHAN_X
);
3111 FETCH( &r
[1], 1, CHAN_X
);
3112 micro_mul( &r
[0], &r
[0], &r
[1] );
3114 FETCH( &r
[1], 0, CHAN_Y
);
3115 FETCH( &r
[2], 1, CHAN_Y
);
3116 micro_mul( &r
[1], &r
[1], &r
[2] );
3117 micro_add( &r
[0], &r
[0], &r
[1] );
3119 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3120 STORE( &r
[0], 0, chan_index
);
3124 case TGSI_OPCODE_IF
:
3126 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
3127 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
3128 FETCH( &r
[0], 0, CHAN_X
);
3129 /* update CondMask */
3131 mach
->CondMask
&= ~0x1;
3134 mach
->CondMask
&= ~0x2;
3137 mach
->CondMask
&= ~0x4;
3140 mach
->CondMask
&= ~0x8;
3142 UPDATE_EXEC_MASK(mach
);
3143 /* Todo: If CondMask==0, jump to ELSE */
3146 case TGSI_OPCODE_ELSE
:
3147 /* invert CondMask wrt previous mask */
3150 assert(mach
->CondStackTop
> 0);
3151 prevMask
= mach
->CondStack
[mach
->CondStackTop
- 1];
3152 mach
->CondMask
= ~mach
->CondMask
& prevMask
;
3153 UPDATE_EXEC_MASK(mach
);
3154 /* Todo: If CondMask==0, jump to ENDIF */
3158 case TGSI_OPCODE_ENDIF
:
3160 assert(mach
->CondStackTop
> 0);
3161 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
3162 UPDATE_EXEC_MASK(mach
);
3165 case TGSI_OPCODE_END
:
3166 /* halt execution */
3170 case TGSI_OPCODE_REP
:
3174 case TGSI_OPCODE_ENDREP
:
3178 case TGSI_OPCODE_PUSHA
:
3182 case TGSI_OPCODE_POPA
:
3186 case TGSI_OPCODE_CEIL
:
3187 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3188 FETCH( &r
[0], 0, chan_index
);
3189 micro_ceil(&d
[chan_index
], &r
[0]);
3191 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3192 STORE(&d
[chan_index
], 0, chan_index
);
3196 case TGSI_OPCODE_I2F
:
3197 exec_vector_unary(mach
, inst
, micro_i2f
);
3200 case TGSI_OPCODE_NOT
:
3201 exec_vector_unary(mach
, inst
, micro_not
);
3204 case TGSI_OPCODE_TRUNC
:
3205 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3206 FETCH( &r
[0], 0, chan_index
);
3207 micro_trunc(&d
[chan_index
], &r
[0]);
3209 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3210 STORE(&d
[chan_index
], 0, chan_index
);
3214 case TGSI_OPCODE_SHL
:
3215 exec_vector_binary(mach
, inst
, micro_shl
);
3218 case TGSI_OPCODE_AND
:
3219 exec_vector_binary(mach
, inst
, micro_and
);
3222 case TGSI_OPCODE_OR
:
3223 exec_vector_binary(mach
, inst
, micro_or
);
3226 case TGSI_OPCODE_MOD
:
3230 case TGSI_OPCODE_XOR
:
3231 exec_vector_binary(mach
, inst
, micro_xor
);
3234 case TGSI_OPCODE_SAD
:
3238 case TGSI_OPCODE_TXF
:
3242 case TGSI_OPCODE_TXQ
:
3246 case TGSI_OPCODE_EMIT
:
3250 case TGSI_OPCODE_ENDPRIM
:
3251 emit_primitive(mach
);
3254 case TGSI_OPCODE_BGNFOR
:
3255 assert(mach
->LoopCounterStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3256 for (chan_index
= 0; chan_index
< 3; chan_index
++) {
3257 FETCH( &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[chan_index
], 0, chan_index
);
3259 ++mach
->LoopCounterStackTop
;
3260 STORE(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
], 0, CHAN_X
);
3261 /* update LoopMask */
3262 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[0] <= 0.0f
) {
3263 mach
->LoopMask
&= ~0x1;
3265 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[1] <= 0.0f
) {
3266 mach
->LoopMask
&= ~0x2;
3268 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[2] <= 0.0f
) {
3269 mach
->LoopMask
&= ~0x4;
3271 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[3] <= 0.0f
) {
3272 mach
->LoopMask
&= ~0x8;
3274 /* TODO: if mach->LoopMask == 0, jump to end of loop */
3275 UPDATE_EXEC_MASK(mach
);
3276 /* fall-through (for now) */
3277 case TGSI_OPCODE_BGNLOOP
:
3278 /* push LoopMask and ContMasks */
3279 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3280 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3281 assert(mach
->LoopLabelStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3282 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
3284 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
3285 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
3286 mach
->LoopLabelStack
[mach
->LoopLabelStackTop
++] = *pc
- 1;
3287 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
3288 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_LOOP
;
3291 case TGSI_OPCODE_ENDFOR
:
3292 assert(mach
->LoopCounterStackTop
> 0);
3293 micro_sub(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
],
3294 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
],
3295 &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
]);
3296 /* update LoopMask */
3297 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[0] <= 0.0f
) {
3298 mach
->LoopMask
&= ~0x1;
3300 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[1] <= 0.0f
) {
3301 mach
->LoopMask
&= ~0x2;
3303 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[2] <= 0.0f
) {
3304 mach
->LoopMask
&= ~0x4;
3306 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[3] <= 0.0f
) {
3307 mach
->LoopMask
&= ~0x8;
3309 micro_add(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
],
3310 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
],
3311 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Z
]);
3312 assert(mach
->LoopLabelStackTop
> 0);
3313 inst
= mach
->Instructions
+ mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1];
3314 STORE(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[CHAN_X
], 0, CHAN_X
);
3315 /* Restore ContMask, but don't pop */
3316 assert(mach
->ContStackTop
> 0);
3317 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3318 UPDATE_EXEC_MASK(mach
);
3319 if (mach
->ExecMask
) {
3320 /* repeat loop: jump to instruction just past BGNLOOP */
3321 assert(mach
->LoopLabelStackTop
> 0);
3322 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3325 /* exit loop: pop LoopMask */
3326 assert(mach
->LoopStackTop
> 0);
3327 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3329 assert(mach
->ContStackTop
> 0);
3330 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3331 assert(mach
->LoopLabelStackTop
> 0);
3332 --mach
->LoopLabelStackTop
;
3333 assert(mach
->LoopCounterStackTop
> 0);
3334 --mach
->LoopCounterStackTop
;
3336 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
3338 UPDATE_EXEC_MASK(mach
);
3341 case TGSI_OPCODE_ENDLOOP
:
3342 /* Restore ContMask, but don't pop */
3343 assert(mach
->ContStackTop
> 0);
3344 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3345 UPDATE_EXEC_MASK(mach
);
3346 if (mach
->ExecMask
) {
3347 /* repeat loop: jump to instruction just past BGNLOOP */
3348 assert(mach
->LoopLabelStackTop
> 0);
3349 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3352 /* exit loop: pop LoopMask */
3353 assert(mach
->LoopStackTop
> 0);
3354 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3356 assert(mach
->ContStackTop
> 0);
3357 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3358 assert(mach
->LoopLabelStackTop
> 0);
3359 --mach
->LoopLabelStackTop
;
3361 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
3363 UPDATE_EXEC_MASK(mach
);
3366 case TGSI_OPCODE_BRK
:
3370 case TGSI_OPCODE_CONT
:
3371 /* turn off cont channels for each enabled exec channel */
3372 mach
->ContMask
&= ~mach
->ExecMask
;
3373 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3374 UPDATE_EXEC_MASK(mach
);
3377 case TGSI_OPCODE_BGNSUB
:
3381 case TGSI_OPCODE_ENDSUB
:
3383 * XXX: This really should be a no-op. We should never reach this opcode.
3386 assert(mach
->CallStackTop
> 0);
3387 mach
->CallStackTop
--;
3389 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
3390 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
3392 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
3393 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
3395 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
3396 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
3398 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
3399 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
3401 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
3402 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
3404 assert(mach
->FuncStackTop
> 0);
3405 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
3407 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
3409 UPDATE_EXEC_MASK(mach
);
3412 case TGSI_OPCODE_NOP
:
3415 case TGSI_OPCODE_BREAKC
:
3416 FETCH(&r
[0], 0, CHAN_X
);
3417 /* update CondMask */
3418 if (r
[0].u
[0] && (mach
->ExecMask
& 0x1)) {
3419 mach
->LoopMask
&= ~0x1;
3421 if (r
[0].u
[1] && (mach
->ExecMask
& 0x2)) {
3422 mach
->LoopMask
&= ~0x2;
3424 if (r
[0].u
[2] && (mach
->ExecMask
& 0x4)) {
3425 mach
->LoopMask
&= ~0x4;
3427 if (r
[0].u
[3] && (mach
->ExecMask
& 0x8)) {
3428 mach
->LoopMask
&= ~0x8;
3430 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3431 UPDATE_EXEC_MASK(mach
);
3434 case TGSI_OPCODE_F2I
:
3435 exec_vector_unary(mach
, inst
, micro_f2i
);
3438 case TGSI_OPCODE_IDIV
:
3439 exec_vector_binary(mach
, inst
, micro_idiv
);
3442 case TGSI_OPCODE_IMAX
:
3443 exec_vector_binary(mach
, inst
, micro_imax
);
3446 case TGSI_OPCODE_IMIN
:
3447 exec_vector_binary(mach
, inst
, micro_imin
);
3450 case TGSI_OPCODE_INEG
:
3451 exec_vector_unary(mach
, inst
, micro_ineg
);
3454 case TGSI_OPCODE_ISGE
:
3455 exec_vector_binary(mach
, inst
, micro_isge
);
3458 case TGSI_OPCODE_ISHR
:
3459 exec_vector_binary(mach
, inst
, micro_ishr
);
3462 case TGSI_OPCODE_ISLT
:
3463 exec_vector_binary(mach
, inst
, micro_islt
);
3466 case TGSI_OPCODE_F2U
:
3467 exec_vector_unary(mach
, inst
, micro_f2u
);
3470 case TGSI_OPCODE_U2F
:
3471 exec_vector_unary(mach
, inst
, micro_u2f
);
3474 case TGSI_OPCODE_UADD
:
3475 exec_vector_binary(mach
, inst
, micro_uadd
);
3478 case TGSI_OPCODE_UDIV
:
3479 exec_vector_binary(mach
, inst
, micro_udiv
);
3482 case TGSI_OPCODE_UMAD
:
3483 exec_vector_trinary(mach
, inst
, micro_umad
);
3486 case TGSI_OPCODE_UMAX
:
3487 exec_vector_binary(mach
, inst
, micro_umax
);
3490 case TGSI_OPCODE_UMIN
:
3491 exec_vector_binary(mach
, inst
, micro_umin
);
3494 case TGSI_OPCODE_UMUL
:
3495 exec_vector_binary(mach
, inst
, micro_umul
);
3498 case TGSI_OPCODE_USEQ
:
3499 exec_vector_binary(mach
, inst
, micro_useq
);
3502 case TGSI_OPCODE_USGE
:
3503 exec_vector_binary(mach
, inst
, micro_usge
);
3506 case TGSI_OPCODE_USHR
:
3507 exec_vector_binary(mach
, inst
, micro_ushr
);
3510 case TGSI_OPCODE_USLT
:
3511 exec_vector_binary(mach
, inst
, micro_uslt
);
3514 case TGSI_OPCODE_USNE
:
3515 exec_vector_binary(mach
, inst
, micro_usne
);
3518 case TGSI_OPCODE_SWITCH
:
3519 exec_switch(mach
, inst
);
3522 case TGSI_OPCODE_CASE
:
3523 exec_case(mach
, inst
);
3526 case TGSI_OPCODE_DEFAULT
:
3530 case TGSI_OPCODE_ENDSWITCH
:
3531 exec_endswitch(mach
);
3539 #define DEBUG_EXECUTION 0
3543 * Run TGSI interpreter.
3544 * \return bitmask of "alive" quad components
3547 tgsi_exec_machine_run( struct tgsi_exec_machine
*mach
)
3552 mach
->CondMask
= 0xf;
3553 mach
->LoopMask
= 0xf;
3554 mach
->ContMask
= 0xf;
3555 mach
->FuncMask
= 0xf;
3556 mach
->ExecMask
= 0xf;
3558 mach
->Switch
.mask
= 0xf;
3560 assert(mach
->CondStackTop
== 0);
3561 assert(mach
->LoopStackTop
== 0);
3562 assert(mach
->ContStackTop
== 0);
3563 assert(mach
->SwitchStackTop
== 0);
3564 assert(mach
->BreakStackTop
== 0);
3565 assert(mach
->CallStackTop
== 0);
3567 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] = 0;
3568 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] = 0;
3570 if( mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
3571 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0] = 0;
3572 mach
->Primitives
[0] = 0;
3575 for (i
= 0; i
< QUAD_SIZE
; i
++) {
3576 mach
->Temps
[TEMP_CC_I
].xyzw
[TEMP_CC_C
].u
[i
] =
3577 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_X_SHIFT
) |
3578 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Y_SHIFT
) |
3579 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Z_SHIFT
) |
3580 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_W_SHIFT
);
3583 /* execute declarations (interpolants) */
3584 for (i
= 0; i
< mach
->NumDeclarations
; i
++) {
3585 exec_declaration( mach
, mach
->Declarations
+i
);
3590 struct tgsi_exec_vector temps
[TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
];
3591 struct tgsi_exec_vector outputs
[PIPE_MAX_ATTRIBS
];
3594 memcpy(temps
, mach
->Temps
, sizeof(temps
));
3595 memcpy(outputs
, mach
->Outputs
, sizeof(outputs
));
3598 /* execute instructions, until pc is set to -1 */
3604 tgsi_dump_instruction(&mach
->Instructions
[pc
], inst
++);
3607 assert(pc
< (int) mach
->NumInstructions
);
3608 exec_instruction(mach
, mach
->Instructions
+ pc
, &pc
);
3611 for (i
= 0; i
< TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
; i
++) {
3612 if (memcmp(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]))) {
3615 memcpy(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]));
3616 debug_printf("TEMP[%2u] = ", i
);
3617 for (j
= 0; j
< 4; j
++) {
3621 debug_printf("(%6f, %6f, %6f, %6f)\n",
3622 temps
[i
].xyzw
[0].f
[j
],
3623 temps
[i
].xyzw
[1].f
[j
],
3624 temps
[i
].xyzw
[2].f
[j
],
3625 temps
[i
].xyzw
[3].f
[j
]);
3629 for (i
= 0; i
< PIPE_MAX_ATTRIBS
; i
++) {
3630 if (memcmp(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]))) {
3633 memcpy(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]));
3634 debug_printf("OUT[%2u] = ", i
);
3635 for (j
= 0; j
< 4; j
++) {
3639 debug_printf("{%6f, %6f, %6f, %6f}\n",
3640 outputs
[i
].xyzw
[0].f
[j
],
3641 outputs
[i
].xyzw
[1].f
[j
],
3642 outputs
[i
].xyzw
[2].f
[j
],
3643 outputs
[i
].xyzw
[3].f
[j
]);
3652 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
3653 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
3655 * Scale back depth component.
3657 for (i
= 0; i
< 4; i
++)
3658 mach
->Outputs
[0].xyzw
[2].f
[i
] *= ctx
->DrawBuffer
->_DepthMaxF
;
3662 assert(mach
->CondStackTop
== 0);
3663 assert(mach
->LoopStackTop
== 0);
3664 assert(mach
->ContStackTop
== 0);
3665 assert(mach
->SwitchStackTop
== 0);
3666 assert(mach
->BreakStackTop
== 0);
3667 assert(mach
->CallStackTop
== 0);
3669 return ~mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];