1 /**************************************************************************
3 * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 * TGSI interpreter/executor.
31 * Flow control information:
33 * Since we operate on 'quads' (4 pixels or 4 vertices in parallel)
34 * flow control statements (IF/ELSE/ENDIF, LOOP/ENDLOOP) require special
35 * care since a condition may be true for some quad components but false
36 * for other components.
38 * We basically execute all statements (even if they're in the part of
39 * an IF/ELSE clause that's "not taken") and use a special mask to
40 * control writing to destination registers. This is the ExecMask.
43 * The ExecMask is computed from three other masks (CondMask, LoopMask and
44 * ContMask) which are controlled by the flow control instructions (namely:
45 * (IF/ELSE/ENDIF, LOOP/ENDLOOP and CONT).
53 #include "pipe/p_compiler.h"
54 #include "pipe/p_state.h"
55 #include "pipe/p_shader_tokens.h"
56 #include "tgsi/tgsi_dump.h"
57 #include "tgsi/tgsi_parse.h"
58 #include "tgsi/tgsi_util.h"
59 #include "tgsi_exec.h"
60 #include "util/u_memory.h"
61 #include "util/u_math.h"
65 #define TILE_TOP_LEFT 0
66 #define TILE_TOP_RIGHT 1
67 #define TILE_BOTTOM_LEFT 2
68 #define TILE_BOTTOM_RIGHT 3
76 * Shorthand locations of various utility registers (_I = Index, _C = Channel)
78 #define TEMP_0_I TGSI_EXEC_TEMP_00000000_I
79 #define TEMP_0_C TGSI_EXEC_TEMP_00000000_C
80 #define TEMP_7F_I TGSI_EXEC_TEMP_7FFFFFFF_I
81 #define TEMP_7F_C TGSI_EXEC_TEMP_7FFFFFFF_C
82 #define TEMP_80_I TGSI_EXEC_TEMP_80000000_I
83 #define TEMP_80_C TGSI_EXEC_TEMP_80000000_C
84 #define TEMP_FF_I TGSI_EXEC_TEMP_FFFFFFFF_I
85 #define TEMP_FF_C TGSI_EXEC_TEMP_FFFFFFFF_C
86 #define TEMP_1_I TGSI_EXEC_TEMP_ONE_I
87 #define TEMP_1_C TGSI_EXEC_TEMP_ONE_C
88 #define TEMP_2_I TGSI_EXEC_TEMP_TWO_I
89 #define TEMP_2_C TGSI_EXEC_TEMP_TWO_C
90 #define TEMP_128_I TGSI_EXEC_TEMP_128_I
91 #define TEMP_128_C TGSI_EXEC_TEMP_128_C
92 #define TEMP_M128_I TGSI_EXEC_TEMP_MINUS_128_I
93 #define TEMP_M128_C TGSI_EXEC_TEMP_MINUS_128_C
94 #define TEMP_KILMASK_I TGSI_EXEC_TEMP_KILMASK_I
95 #define TEMP_KILMASK_C TGSI_EXEC_TEMP_KILMASK_C
96 #define TEMP_OUTPUT_I TGSI_EXEC_TEMP_OUTPUT_I
97 #define TEMP_OUTPUT_C TGSI_EXEC_TEMP_OUTPUT_C
98 #define TEMP_PRIMITIVE_I TGSI_EXEC_TEMP_PRIMITIVE_I
99 #define TEMP_PRIMITIVE_C TGSI_EXEC_TEMP_PRIMITIVE_C
100 #define TEMP_CC_I TGSI_EXEC_TEMP_CC_I
101 #define TEMP_CC_C TGSI_EXEC_TEMP_CC_C
102 #define TEMP_3_I TGSI_EXEC_TEMP_THREE_I
103 #define TEMP_3_C TGSI_EXEC_TEMP_THREE_C
104 #define TEMP_HALF_I TGSI_EXEC_TEMP_HALF_I
105 #define TEMP_HALF_C TGSI_EXEC_TEMP_HALF_C
106 #define TEMP_R0 TGSI_EXEC_TEMP_R0
107 #define TEMP_P0 TGSI_EXEC_TEMP_P0
109 #define IS_CHANNEL_ENABLED(INST, CHAN)\
110 ((INST).Dst[0].Register.WriteMask & (1 << (CHAN)))
112 #define IS_CHANNEL_ENABLED2(INST, CHAN)\
113 ((INST).Dst[1].Register.WriteMask & (1 << (CHAN)))
115 #define FOR_EACH_ENABLED_CHANNEL(INST, CHAN)\
116 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)\
117 if (IS_CHANNEL_ENABLED( INST, CHAN ))
119 #define FOR_EACH_ENABLED_CHANNEL2(INST, CHAN)\
120 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)\
121 if (IS_CHANNEL_ENABLED2( INST, CHAN ))
124 /** The execution mask depends on the conditional mask and the loop mask */
125 #define UPDATE_EXEC_MASK(MACH) \
126 MACH->ExecMask = MACH->CondMask & MACH->LoopMask & MACH->ContMask & MACH->FuncMask
129 static const union tgsi_exec_channel ZeroVec
=
130 { { 0.0, 0.0, 0.0, 0.0 } };
135 check_inf_or_nan(const union tgsi_exec_channel
*chan
)
137 assert(!util_is_inf_or_nan(chan
->f
[0]));
138 assert(!util_is_inf_or_nan(chan
->f
[1]));
139 assert(!util_is_inf_or_nan(chan
->f
[2]));
140 assert(!util_is_inf_or_nan(chan
->f
[3]));
147 print_chan(const char *msg
, const union tgsi_exec_channel
*chan
)
149 debug_printf("%s = {%f, %f, %f, %f}\n",
150 msg
, chan
->f
[0], chan
->f
[1], chan
->f
[2], chan
->f
[3]);
157 print_temp(const struct tgsi_exec_machine
*mach
, uint index
)
159 const struct tgsi_exec_vector
*tmp
= &mach
->Temps
[index
];
161 debug_printf("Temp[%u] =\n", index
);
162 for (i
= 0; i
< 4; i
++) {
163 debug_printf(" %c: { %f, %f, %f, %f }\n",
175 * Check if there's a potential src/dst register data dependency when
176 * using SOA execution.
179 * This would expand into:
184 * The second instruction will have the wrong value for t0 if executed as-is.
187 tgsi_check_soa_dependencies(const struct tgsi_full_instruction
*inst
)
191 uint writemask
= inst
->Dst
[0].Register
.WriteMask
;
192 if (writemask
== TGSI_WRITEMASK_X
||
193 writemask
== TGSI_WRITEMASK_Y
||
194 writemask
== TGSI_WRITEMASK_Z
||
195 writemask
== TGSI_WRITEMASK_W
||
196 writemask
== TGSI_WRITEMASK_NONE
) {
197 /* no chance of data dependency */
201 /* loop over src regs */
202 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
203 if ((inst
->Src
[i
].Register
.File
==
204 inst
->Dst
[0].Register
.File
) &&
205 (inst
->Src
[i
].Register
.Index
==
206 inst
->Dst
[0].Register
.Index
)) {
207 /* loop over dest channels */
208 uint channelsWritten
= 0x0;
209 FOR_EACH_ENABLED_CHANNEL(*inst
, chan
) {
210 /* check if we're reading a channel that's been written */
211 uint swizzle
= tgsi_util_get_full_src_register_swizzle(&inst
->Src
[i
], chan
);
212 if (channelsWritten
& (1 << swizzle
)) {
216 channelsWritten
|= (1 << chan
);
225 * Initialize machine state by expanding tokens to full instructions,
226 * allocating temporary storage, setting up constants, etc.
227 * After this, we can call tgsi_exec_machine_run() many times.
230 tgsi_exec_machine_bind_shader(
231 struct tgsi_exec_machine
*mach
,
232 const struct tgsi_token
*tokens
,
234 struct tgsi_sampler
**samplers
)
237 struct tgsi_parse_context parse
;
238 struct tgsi_exec_labels
*labels
= &mach
->Labels
;
239 struct tgsi_full_instruction
*instructions
;
240 struct tgsi_full_declaration
*declarations
;
241 uint maxInstructions
= 10, numInstructions
= 0;
242 uint maxDeclarations
= 10, numDeclarations
= 0;
246 tgsi_dump(tokens
, 0);
251 mach
->Tokens
= tokens
;
252 mach
->Samplers
= samplers
;
254 k
= tgsi_parse_init (&parse
, mach
->Tokens
);
255 if (k
!= TGSI_PARSE_OK
) {
256 debug_printf( "Problem parsing!\n" );
260 mach
->Processor
= parse
.FullHeader
.Processor
.Processor
;
264 declarations
= (struct tgsi_full_declaration
*)
265 MALLOC( maxDeclarations
* sizeof(struct tgsi_full_declaration
) );
271 instructions
= (struct tgsi_full_instruction
*)
272 MALLOC( maxInstructions
* sizeof(struct tgsi_full_instruction
) );
275 FREE( declarations
);
279 while( !tgsi_parse_end_of_tokens( &parse
) ) {
280 uint pointer
= parse
.Position
;
283 tgsi_parse_token( &parse
);
284 switch( parse
.FullToken
.Token
.Type
) {
285 case TGSI_TOKEN_TYPE_DECLARATION
:
286 /* save expanded declaration */
287 if (numDeclarations
== maxDeclarations
) {
288 declarations
= REALLOC(declarations
,
290 * sizeof(struct tgsi_full_declaration
),
291 (maxDeclarations
+ 10)
292 * sizeof(struct tgsi_full_declaration
));
293 maxDeclarations
+= 10;
295 if (parse
.FullToken
.FullDeclaration
.Declaration
.File
== TGSI_FILE_OUTPUT
) {
297 for (reg
= parse
.FullToken
.FullDeclaration
.Range
.First
;
298 reg
<= parse
.FullToken
.FullDeclaration
.Range
.Last
;
303 memcpy(declarations
+ numDeclarations
,
304 &parse
.FullToken
.FullDeclaration
,
305 sizeof(declarations
[0]));
309 case TGSI_TOKEN_TYPE_IMMEDIATE
:
311 uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
313 assert( mach
->ImmLimit
+ 1 <= TGSI_EXEC_NUM_IMMEDIATES
);
315 for( i
= 0; i
< size
; i
++ ) {
316 mach
->Imms
[mach
->ImmLimit
][i
] =
317 parse
.FullToken
.FullImmediate
.u
[i
].Float
;
323 case TGSI_TOKEN_TYPE_INSTRUCTION
:
324 assert( labels
->count
< MAX_LABELS
);
326 labels
->labels
[labels
->count
][0] = instno
;
327 labels
->labels
[labels
->count
][1] = pointer
;
330 /* save expanded instruction */
331 if (numInstructions
== maxInstructions
) {
332 instructions
= REALLOC(instructions
,
334 * sizeof(struct tgsi_full_instruction
),
335 (maxInstructions
+ 10)
336 * sizeof(struct tgsi_full_instruction
));
337 maxInstructions
+= 10;
340 memcpy(instructions
+ numInstructions
,
341 &parse
.FullToken
.FullInstruction
,
342 sizeof(instructions
[0]));
347 case TGSI_TOKEN_TYPE_PROPERTY
:
354 tgsi_parse_free (&parse
);
356 if (mach
->Declarations
) {
357 FREE( mach
->Declarations
);
359 mach
->Declarations
= declarations
;
360 mach
->NumDeclarations
= numDeclarations
;
362 if (mach
->Instructions
) {
363 FREE( mach
->Instructions
);
365 mach
->Instructions
= instructions
;
366 mach
->NumInstructions
= numInstructions
;
370 struct tgsi_exec_machine
*
371 tgsi_exec_machine_create( void )
373 struct tgsi_exec_machine
*mach
;
376 mach
= align_malloc( sizeof *mach
, 16 );
380 memset(mach
, 0, sizeof(*mach
));
382 mach
->Addrs
= &mach
->Temps
[TGSI_EXEC_TEMP_ADDR
];
383 mach
->MaxGeometryShaderOutputs
= TGSI_MAX_TOTAL_VERTICES
;
384 mach
->Predicates
= &mach
->Temps
[TGSI_EXEC_TEMP_P0
];
386 /* Setup constants. */
387 for( i
= 0; i
< 4; i
++ ) {
388 mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
].u
[i
] = 0x00000000;
389 mach
->Temps
[TEMP_7F_I
].xyzw
[TEMP_7F_C
].u
[i
] = 0x7FFFFFFF;
390 mach
->Temps
[TEMP_80_I
].xyzw
[TEMP_80_C
].u
[i
] = 0x80000000;
391 mach
->Temps
[TEMP_FF_I
].xyzw
[TEMP_FF_C
].u
[i
] = 0xFFFFFFFF;
392 mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
].f
[i
] = 1.0f
;
393 mach
->Temps
[TEMP_2_I
].xyzw
[TEMP_2_C
].f
[i
] = 2.0f
;
394 mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
].f
[i
] = 128.0f
;
395 mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
].f
[i
] = -128.0f
;
396 mach
->Temps
[TEMP_3_I
].xyzw
[TEMP_3_C
].f
[i
] = 3.0f
;
397 mach
->Temps
[TEMP_HALF_I
].xyzw
[TEMP_HALF_C
].f
[i
] = 0.5f
;
401 /* silence warnings */
415 tgsi_exec_machine_destroy(struct tgsi_exec_machine
*mach
)
418 FREE(mach
->Instructions
);
419 FREE(mach
->Declarations
);
428 union tgsi_exec_channel
*dst
,
429 const union tgsi_exec_channel
*src
)
431 dst
->f
[0] = fabsf( src
->f
[0] );
432 dst
->f
[1] = fabsf( src
->f
[1] );
433 dst
->f
[2] = fabsf( src
->f
[2] );
434 dst
->f
[3] = fabsf( src
->f
[3] );
439 union tgsi_exec_channel
*dst
,
440 const union tgsi_exec_channel
*src0
,
441 const union tgsi_exec_channel
*src1
)
443 dst
->f
[0] = src0
->f
[0] + src1
->f
[0];
444 dst
->f
[1] = src0
->f
[1] + src1
->f
[1];
445 dst
->f
[2] = src0
->f
[2] + src1
->f
[2];
446 dst
->f
[3] = src0
->f
[3] + src1
->f
[3];
451 union tgsi_exec_channel
*dst
,
452 const union tgsi_exec_channel
*src0
,
453 const union tgsi_exec_channel
*src1
)
455 dst
->u
[0] = src0
->u
[0] & src1
->u
[0];
456 dst
->u
[1] = src0
->u
[1] & src1
->u
[1];
457 dst
->u
[2] = src0
->u
[2] & src1
->u
[2];
458 dst
->u
[3] = src0
->u
[3] & src1
->u
[3];
463 union tgsi_exec_channel
*dst
,
464 const union tgsi_exec_channel
*src
)
466 dst
->f
[0] = ceilf( src
->f
[0] );
467 dst
->f
[1] = ceilf( src
->f
[1] );
468 dst
->f
[2] = ceilf( src
->f
[2] );
469 dst
->f
[3] = ceilf( src
->f
[3] );
474 union tgsi_exec_channel
*dst
,
475 const union tgsi_exec_channel
*src
)
477 dst
->f
[0] = cosf( src
->f
[0] );
478 dst
->f
[1] = cosf( src
->f
[1] );
479 dst
->f
[2] = cosf( src
->f
[2] );
480 dst
->f
[3] = cosf( src
->f
[3] );
485 union tgsi_exec_channel
*dst
,
486 const union tgsi_exec_channel
*src
)
491 dst
->f
[3] = src
->f
[TILE_BOTTOM_RIGHT
] - src
->f
[TILE_BOTTOM_LEFT
];
496 union tgsi_exec_channel
*dst
,
497 const union tgsi_exec_channel
*src
)
502 dst
->f
[3] = src
->f
[TILE_BOTTOM_LEFT
] - src
->f
[TILE_TOP_LEFT
];
507 union tgsi_exec_channel
*dst
,
508 const union tgsi_exec_channel
*src0
,
509 const union tgsi_exec_channel
*src1
)
511 if (src1
->f
[0] != 0) {
512 dst
->f
[0] = src0
->f
[0] / src1
->f
[0];
514 if (src1
->f
[1] != 0) {
515 dst
->f
[1] = src0
->f
[1] / src1
->f
[1];
517 if (src1
->f
[2] != 0) {
518 dst
->f
[2] = src0
->f
[2] / src1
->f
[2];
520 if (src1
->f
[3] != 0) {
521 dst
->f
[3] = src0
->f
[3] / src1
->f
[3];
527 union tgsi_exec_channel
*dst
,
528 const union tgsi_exec_channel
*src0
,
529 const union tgsi_exec_channel
*src1
,
530 const union tgsi_exec_channel
*src2
,
531 const union tgsi_exec_channel
*src3
)
533 dst
->f
[0] = src0
->f
[0] == src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
534 dst
->f
[1] = src0
->f
[1] == src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
535 dst
->f
[2] = src0
->f
[2] == src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
536 dst
->f
[3] = src0
->f
[3] == src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
541 union tgsi_exec_channel
*dst
,
542 const union tgsi_exec_channel
*src
)
545 dst
->f
[0] = util_fast_exp2( src
->f
[0] );
546 dst
->f
[1] = util_fast_exp2( src
->f
[1] );
547 dst
->f
[2] = util_fast_exp2( src
->f
[2] );
548 dst
->f
[3] = util_fast_exp2( src
->f
[3] );
552 /* Inf is okay for this instruction, so clamp it to silence assertions. */
554 union tgsi_exec_channel clamped
;
556 for (i
= 0; i
< 4; i
++) {
557 if (src
->f
[i
] > 127.99999f
) {
558 clamped
.f
[i
] = 127.99999f
;
559 } else if (src
->f
[i
] < -126.99999f
) {
560 clamped
.f
[i
] = -126.99999f
;
562 clamped
.f
[i
] = src
->f
[i
];
568 dst
->f
[0] = powf( 2.0f
, src
->f
[0] );
569 dst
->f
[1] = powf( 2.0f
, src
->f
[1] );
570 dst
->f
[2] = powf( 2.0f
, src
->f
[2] );
571 dst
->f
[3] = powf( 2.0f
, src
->f
[3] );
576 micro_float_clamp(union tgsi_exec_channel
*dst
,
577 const union tgsi_exec_channel
*src
)
581 for (i
= 0; i
< 4; i
++) {
582 if (src
->f
[i
] > 0.0f
) {
583 if (src
->f
[i
] > 1.884467e+019f
)
584 dst
->f
[i
] = 1.884467e+019f
;
585 else if (src
->f
[i
] < 5.42101e-020f
)
586 dst
->f
[i
] = 5.42101e-020f
;
588 dst
->f
[i
] = src
->f
[i
];
591 if (src
->f
[i
] < -1.884467e+019f
)
592 dst
->f
[i
] = -1.884467e+019f
;
593 else if (src
->f
[i
] > -5.42101e-020f
)
594 dst
->f
[i
] = -5.42101e-020f
;
596 dst
->f
[i
] = src
->f
[i
];
603 union tgsi_exec_channel
*dst
,
604 const union tgsi_exec_channel
*src
)
606 dst
->f
[0] = floorf( src
->f
[0] );
607 dst
->f
[1] = floorf( src
->f
[1] );
608 dst
->f
[2] = floorf( src
->f
[2] );
609 dst
->f
[3] = floorf( src
->f
[3] );
614 union tgsi_exec_channel
*dst
,
615 const union tgsi_exec_channel
*src
)
617 dst
->f
[0] = src
->f
[0] - floorf( src
->f
[0] );
618 dst
->f
[1] = src
->f
[1] - floorf( src
->f
[1] );
619 dst
->f
[2] = src
->f
[2] - floorf( src
->f
[2] );
620 dst
->f
[3] = src
->f
[3] - floorf( src
->f
[3] );
625 union tgsi_exec_channel
*dst
,
626 const union tgsi_exec_channel
*src
)
628 dst
->f
[0] = (float) src
->i
[0];
629 dst
->f
[1] = (float) src
->i
[1];
630 dst
->f
[2] = (float) src
->i
[2];
631 dst
->f
[3] = (float) src
->i
[3];
636 union tgsi_exec_channel
*dst
,
637 const union tgsi_exec_channel
*src
)
640 dst
->f
[0] = util_fast_log2( src
->f
[0] );
641 dst
->f
[1] = util_fast_log2( src
->f
[1] );
642 dst
->f
[2] = util_fast_log2( src
->f
[2] );
643 dst
->f
[3] = util_fast_log2( src
->f
[3] );
645 dst
->f
[0] = logf( src
->f
[0] ) * 1.442695f
;
646 dst
->f
[1] = logf( src
->f
[1] ) * 1.442695f
;
647 dst
->f
[2] = logf( src
->f
[2] ) * 1.442695f
;
648 dst
->f
[3] = logf( src
->f
[3] ) * 1.442695f
;
654 union tgsi_exec_channel
*dst
,
655 const union tgsi_exec_channel
*src0
,
656 const union tgsi_exec_channel
*src1
,
657 const union tgsi_exec_channel
*src2
,
658 const union tgsi_exec_channel
*src3
)
660 dst
->f
[0] = src0
->f
[0] <= src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
661 dst
->f
[1] = src0
->f
[1] <= src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
662 dst
->f
[2] = src0
->f
[2] <= src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
663 dst
->f
[3] = src0
->f
[3] <= src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
668 union tgsi_exec_channel
*dst
,
669 const union tgsi_exec_channel
*src0
,
670 const union tgsi_exec_channel
*src1
,
671 const union tgsi_exec_channel
*src2
,
672 const union tgsi_exec_channel
*src3
)
674 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
675 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
676 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
677 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
682 union tgsi_exec_channel
*dst
,
683 const union tgsi_exec_channel
*src0
,
684 const union tgsi_exec_channel
*src1
)
686 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
687 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
688 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
689 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
694 union tgsi_exec_channel
*dst
,
695 const union tgsi_exec_channel
*src0
,
696 const union tgsi_exec_channel
*src1
)
698 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
699 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
700 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
701 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
707 union tgsi_exec_channel
*dst
,
708 const union tgsi_exec_channel
*src0
,
709 const union tgsi_exec_channel
*src1
)
711 dst
->u
[0] = src0
->u
[0] % src1
->u
[0];
712 dst
->u
[1] = src0
->u
[1] % src1
->u
[1];
713 dst
->u
[2] = src0
->u
[2] % src1
->u
[2];
714 dst
->u
[3] = src0
->u
[3] % src1
->u
[3];
720 union tgsi_exec_channel
*dst
,
721 const union tgsi_exec_channel
*src0
,
722 const union tgsi_exec_channel
*src1
)
724 dst
->f
[0] = src0
->f
[0] * src1
->f
[0];
725 dst
->f
[1] = src0
->f
[1] * src1
->f
[1];
726 dst
->f
[2] = src0
->f
[2] * src1
->f
[2];
727 dst
->f
[3] = src0
->f
[3] * src1
->f
[3];
733 union tgsi_exec_channel
*dst0
,
734 union tgsi_exec_channel
*dst1
,
735 const union tgsi_exec_channel
*src0
,
736 const union tgsi_exec_channel
*src1
)
738 dst1
->i
[0] = src0
->i
[0] * src1
->i
[0];
739 dst1
->i
[1] = src0
->i
[1] * src1
->i
[1];
740 dst1
->i
[2] = src0
->i
[2] * src1
->i
[2];
741 dst1
->i
[3] = src0
->i
[3] * src1
->i
[3];
752 union tgsi_exec_channel
*dst0
,
753 union tgsi_exec_channel
*dst1
,
754 const union tgsi_exec_channel
*src0
,
755 const union tgsi_exec_channel
*src1
)
757 dst1
->u
[0] = src0
->u
[0] * src1
->u
[0];
758 dst1
->u
[1] = src0
->u
[1] * src1
->u
[1];
759 dst1
->u
[2] = src0
->u
[2] * src1
->u
[2];
760 dst1
->u
[3] = src0
->u
[3] * src1
->u
[3];
772 union tgsi_exec_channel
*dst
,
773 const union tgsi_exec_channel
*src0
,
774 const union tgsi_exec_channel
*src1
,
775 const union tgsi_exec_channel
*src2
)
777 dst
->u
[0] = src0
->u
[0] ? src1
->u
[0] : src2
->u
[0];
778 dst
->u
[1] = src0
->u
[1] ? src1
->u
[1] : src2
->u
[1];
779 dst
->u
[2] = src0
->u
[2] ? src1
->u
[2] : src2
->u
[2];
780 dst
->u
[3] = src0
->u
[3] ? src1
->u
[3] : src2
->u
[3];
786 union tgsi_exec_channel
*dst
,
787 const union tgsi_exec_channel
*src
)
789 dst
->f
[0] = -src
->f
[0];
790 dst
->f
[1] = -src
->f
[1];
791 dst
->f
[2] = -src
->f
[2];
792 dst
->f
[3] = -src
->f
[3];
797 union tgsi_exec_channel
*dst
,
798 const union tgsi_exec_channel
*src
)
800 dst
->u
[0] = ~src
->u
[0];
801 dst
->u
[1] = ~src
->u
[1];
802 dst
->u
[2] = ~src
->u
[2];
803 dst
->u
[3] = ~src
->u
[3];
808 union tgsi_exec_channel
*dst
,
809 const union tgsi_exec_channel
*src0
,
810 const union tgsi_exec_channel
*src1
)
812 dst
->u
[0] = src0
->u
[0] | src1
->u
[0];
813 dst
->u
[1] = src0
->u
[1] | src1
->u
[1];
814 dst
->u
[2] = src0
->u
[2] | src1
->u
[2];
815 dst
->u
[3] = src0
->u
[3] | src1
->u
[3];
820 union tgsi_exec_channel
*dst
,
821 const union tgsi_exec_channel
*src0
,
822 const union tgsi_exec_channel
*src1
)
825 dst
->f
[0] = util_fast_pow( src0
->f
[0], src1
->f
[0] );
826 dst
->f
[1] = util_fast_pow( src0
->f
[1], src1
->f
[1] );
827 dst
->f
[2] = util_fast_pow( src0
->f
[2], src1
->f
[2] );
828 dst
->f
[3] = util_fast_pow( src0
->f
[3], src1
->f
[3] );
830 dst
->f
[0] = powf( src0
->f
[0], src1
->f
[0] );
831 dst
->f
[1] = powf( src0
->f
[1], src1
->f
[1] );
832 dst
->f
[2] = powf( src0
->f
[2], src1
->f
[2] );
833 dst
->f
[3] = powf( src0
->f
[3], src1
->f
[3] );
839 union tgsi_exec_channel
*dst
,
840 const union tgsi_exec_channel
*src
)
842 dst
->f
[0] = floorf( src
->f
[0] + 0.5f
);
843 dst
->f
[1] = floorf( src
->f
[1] + 0.5f
);
844 dst
->f
[2] = floorf( src
->f
[2] + 0.5f
);
845 dst
->f
[3] = floorf( src
->f
[3] + 0.5f
);
850 union tgsi_exec_channel
*dst
,
851 const union tgsi_exec_channel
*src
)
853 dst
->f
[0] = src
->f
[0] < 0.0f
? -1.0f
: src
->f
[0] > 0.0f
? 1.0f
: 0.0f
;
854 dst
->f
[1] = src
->f
[1] < 0.0f
? -1.0f
: src
->f
[1] > 0.0f
? 1.0f
: 0.0f
;
855 dst
->f
[2] = src
->f
[2] < 0.0f
? -1.0f
: src
->f
[2] > 0.0f
? 1.0f
: 0.0f
;
856 dst
->f
[3] = src
->f
[3] < 0.0f
? -1.0f
: src
->f
[3] > 0.0f
? 1.0f
: 0.0f
;
861 union tgsi_exec_channel
*dst
,
862 const union tgsi_exec_channel
*src0
,
863 const union tgsi_exec_channel
*src1
)
865 dst
->i
[0] = src0
->i
[0] << src1
->i
[0];
866 dst
->i
[1] = src0
->i
[1] << src1
->i
[1];
867 dst
->i
[2] = src0
->i
[2] << src1
->i
[2];
868 dst
->i
[3] = src0
->i
[3] << src1
->i
[3];
873 union tgsi_exec_channel
*dst
,
874 const union tgsi_exec_channel
*src0
)
876 dst
->f
[0] = (float) (int) src0
->f
[0];
877 dst
->f
[1] = (float) (int) src0
->f
[1];
878 dst
->f
[2] = (float) (int) src0
->f
[2];
879 dst
->f
[3] = (float) (int) src0
->f
[3];
884 union tgsi_exec_channel
*dst
,
885 const union tgsi_exec_channel
*src
)
887 dst
->f
[0] = sinf( src
->f
[0] );
888 dst
->f
[1] = sinf( src
->f
[1] );
889 dst
->f
[2] = sinf( src
->f
[2] );
890 dst
->f
[3] = sinf( src
->f
[3] );
894 micro_sqrt( union tgsi_exec_channel
*dst
,
895 const union tgsi_exec_channel
*src
)
897 dst
->f
[0] = sqrtf( src
->f
[0] );
898 dst
->f
[1] = sqrtf( src
->f
[1] );
899 dst
->f
[2] = sqrtf( src
->f
[2] );
900 dst
->f
[3] = sqrtf( src
->f
[3] );
905 union tgsi_exec_channel
*dst
,
906 const union tgsi_exec_channel
*src0
,
907 const union tgsi_exec_channel
*src1
)
909 dst
->f
[0] = src0
->f
[0] - src1
->f
[0];
910 dst
->f
[1] = src0
->f
[1] - src1
->f
[1];
911 dst
->f
[2] = src0
->f
[2] - src1
->f
[2];
912 dst
->f
[3] = src0
->f
[3] - src1
->f
[3];
917 union tgsi_exec_channel
*dst
,
918 const union tgsi_exec_channel
*src0
,
919 const union tgsi_exec_channel
*src1
)
921 dst
->u
[0] = src0
->u
[0] ^ src1
->u
[0];
922 dst
->u
[1] = src0
->u
[1] ^ src1
->u
[1];
923 dst
->u
[2] = src0
->u
[2] ^ src1
->u
[2];
924 dst
->u
[3] = src0
->u
[3] ^ src1
->u
[3];
928 fetch_src_file_channel(
929 const struct tgsi_exec_machine
*mach
,
932 const union tgsi_exec_channel
*index
,
933 union tgsi_exec_channel
*chan
)
941 case TGSI_FILE_CONSTANT
:
942 assert(mach
->Consts
);
946 chan
->f
[0] = mach
->Consts
[index
->i
[0]][swizzle
];
950 chan
->f
[1] = mach
->Consts
[index
->i
[1]][swizzle
];
954 chan
->f
[2] = mach
->Consts
[index
->i
[2]][swizzle
];
958 chan
->f
[3] = mach
->Consts
[index
->i
[3]][swizzle
];
961 case TGSI_FILE_INPUT
:
962 case TGSI_FILE_SYSTEM_VALUE
:
963 chan
->u
[0] = mach
->Inputs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
964 chan
->u
[1] = mach
->Inputs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
965 chan
->u
[2] = mach
->Inputs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
966 chan
->u
[3] = mach
->Inputs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
969 case TGSI_FILE_TEMPORARY
:
970 assert(index
->i
[0] < TGSI_EXEC_NUM_TEMPS
);
971 chan
->u
[0] = mach
->Temps
[index
->i
[0]].xyzw
[swizzle
].u
[0];
972 chan
->u
[1] = mach
->Temps
[index
->i
[1]].xyzw
[swizzle
].u
[1];
973 chan
->u
[2] = mach
->Temps
[index
->i
[2]].xyzw
[swizzle
].u
[2];
974 chan
->u
[3] = mach
->Temps
[index
->i
[3]].xyzw
[swizzle
].u
[3];
977 case TGSI_FILE_IMMEDIATE
:
978 assert( index
->i
[0] < (int) mach
->ImmLimit
);
979 chan
->f
[0] = mach
->Imms
[index
->i
[0]][swizzle
];
980 assert( index
->i
[1] < (int) mach
->ImmLimit
);
981 chan
->f
[1] = mach
->Imms
[index
->i
[1]][swizzle
];
982 assert( index
->i
[2] < (int) mach
->ImmLimit
);
983 chan
->f
[2] = mach
->Imms
[index
->i
[2]][swizzle
];
984 assert( index
->i
[3] < (int) mach
->ImmLimit
);
985 chan
->f
[3] = mach
->Imms
[index
->i
[3]][swizzle
];
988 case TGSI_FILE_ADDRESS
:
989 chan
->u
[0] = mach
->Addrs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
990 chan
->u
[1] = mach
->Addrs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
991 chan
->u
[2] = mach
->Addrs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
992 chan
->u
[3] = mach
->Addrs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
995 case TGSI_FILE_PREDICATE
:
996 assert(index
->i
[0] < TGSI_EXEC_NUM_PREDS
);
997 assert(index
->i
[1] < TGSI_EXEC_NUM_PREDS
);
998 assert(index
->i
[2] < TGSI_EXEC_NUM_PREDS
);
999 assert(index
->i
[3] < TGSI_EXEC_NUM_PREDS
);
1000 chan
->u
[0] = mach
->Predicates
[0].xyzw
[swizzle
].u
[0];
1001 chan
->u
[1] = mach
->Predicates
[0].xyzw
[swizzle
].u
[1];
1002 chan
->u
[2] = mach
->Predicates
[0].xyzw
[swizzle
].u
[2];
1003 chan
->u
[3] = mach
->Predicates
[0].xyzw
[swizzle
].u
[3];
1006 case TGSI_FILE_OUTPUT
:
1007 /* vertex/fragment output vars can be read too */
1008 chan
->u
[0] = mach
->Outputs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1009 chan
->u
[1] = mach
->Outputs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1010 chan
->u
[2] = mach
->Outputs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1011 chan
->u
[3] = mach
->Outputs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1026 const struct tgsi_exec_machine
*mach
,
1027 union tgsi_exec_channel
*chan
,
1028 const struct tgsi_full_src_register
*reg
,
1029 const uint chan_index
)
1031 union tgsi_exec_channel index
;
1034 /* We start with a direct index into a register file.
1038 * file = Register.File
1039 * [1] = Register.Index
1044 index
.i
[3] = reg
->Register
.Index
;
1046 /* There is an extra source register that indirectly subscripts
1047 * a register file. The direct index now becomes an offset
1048 * that is being added to the indirect register.
1052 * ind = Indirect.File
1053 * [2] = Indirect.Index
1054 * .x = Indirect.SwizzleX
1056 if (reg
->Register
.Indirect
) {
1057 union tgsi_exec_channel index2
;
1058 union tgsi_exec_channel indir_index
;
1059 const uint execmask
= mach
->ExecMask
;
1062 /* which address register (always zero now) */
1066 index2
.i
[3] = reg
->Indirect
.Index
;
1068 /* get current value of address register[swizzle] */
1069 swizzle
= tgsi_util_get_src_register_swizzle( ®
->Indirect
, CHAN_X
);
1070 fetch_src_file_channel(
1077 /* add value of address register to the offset */
1078 index
.i
[0] += (int) indir_index
.f
[0];
1079 index
.i
[1] += (int) indir_index
.f
[1];
1080 index
.i
[2] += (int) indir_index
.f
[2];
1081 index
.i
[3] += (int) indir_index
.f
[3];
1083 /* for disabled execution channels, zero-out the index to
1084 * avoid using a potential garbage value.
1086 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1087 if ((execmask
& (1 << i
)) == 0)
1092 /* There is an extra source register that is a second
1093 * subscript to a register file. Effectively it means that
1094 * the register file is actually a 2D array of registers.
1096 * file[1][3] == file[1*sizeof(file[1])+3],
1098 * [3] = Dimension.Index
1100 if (reg
->Register
.Dimension
) {
1101 /* The size of the first-order array depends on the register file type.
1102 * We need to multiply the index to the first array to get an effective,
1103 * "flat" index that points to the beginning of the second-order array.
1105 switch (reg
->Register
.File
) {
1106 case TGSI_FILE_INPUT
:
1107 case TGSI_FILE_SYSTEM_VALUE
:
1108 index
.i
[0] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1109 index
.i
[1] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1110 index
.i
[2] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1111 index
.i
[3] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1113 case TGSI_FILE_CONSTANT
:
1114 index
.i
[0] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1115 index
.i
[1] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1116 index
.i
[2] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1117 index
.i
[3] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1123 index
.i
[0] += reg
->Dimension
.Index
;
1124 index
.i
[1] += reg
->Dimension
.Index
;
1125 index
.i
[2] += reg
->Dimension
.Index
;
1126 index
.i
[3] += reg
->Dimension
.Index
;
1128 /* Again, the second subscript index can be addressed indirectly
1129 * identically to the first one.
1130 * Nothing stops us from indirectly addressing the indirect register,
1131 * but there is no need for that, so we won't exercise it.
1133 * file[1][ind[4].y+3],
1135 * ind = DimIndirect.File
1136 * [4] = DimIndirect.Index
1137 * .y = DimIndirect.SwizzleX
1139 if (reg
->Dimension
.Indirect
) {
1140 union tgsi_exec_channel index2
;
1141 union tgsi_exec_channel indir_index
;
1142 const uint execmask
= mach
->ExecMask
;
1148 index2
.i
[3] = reg
->DimIndirect
.Index
;
1150 swizzle
= tgsi_util_get_src_register_swizzle( ®
->DimIndirect
, CHAN_X
);
1151 fetch_src_file_channel(
1153 reg
->DimIndirect
.File
,
1158 index
.i
[0] += (int) indir_index
.f
[0];
1159 index
.i
[1] += (int) indir_index
.f
[1];
1160 index
.i
[2] += (int) indir_index
.f
[2];
1161 index
.i
[3] += (int) indir_index
.f
[3];
1163 /* for disabled execution channels, zero-out the index to
1164 * avoid using a potential garbage value.
1166 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1167 if ((execmask
& (1 << i
)) == 0)
1172 /* If by any chance there was a need for a 3D array of register
1173 * files, we would have to check whether Dimension is followed
1174 * by a dimension register and continue the saga.
1178 swizzle
= tgsi_util_get_full_src_register_swizzle( reg
, chan_index
);
1179 fetch_src_file_channel(
1186 switch (tgsi_util_get_full_src_register_sign_mode( reg
, chan_index
)) {
1187 case TGSI_UTIL_SIGN_CLEAR
:
1188 micro_abs( chan
, chan
);
1191 case TGSI_UTIL_SIGN_SET
:
1192 micro_abs( chan
, chan
);
1193 micro_neg( chan
, chan
);
1196 case TGSI_UTIL_SIGN_TOGGLE
:
1197 micro_neg( chan
, chan
);
1200 case TGSI_UTIL_SIGN_KEEP
:
1207 struct tgsi_exec_machine
*mach
,
1208 const union tgsi_exec_channel
*chan
,
1209 const struct tgsi_full_dst_register
*reg
,
1210 const struct tgsi_full_instruction
*inst
,
1214 union tgsi_exec_channel null
;
1215 union tgsi_exec_channel
*dst
;
1216 uint execmask
= mach
->ExecMask
;
1217 int offset
= 0; /* indirection offset */
1221 check_inf_or_nan(chan
);
1224 /* There is an extra source register that indirectly subscripts
1225 * a register file. The direct index now becomes an offset
1226 * that is being added to the indirect register.
1230 * ind = Indirect.File
1231 * [2] = Indirect.Index
1232 * .x = Indirect.SwizzleX
1234 if (reg
->Register
.Indirect
) {
1235 union tgsi_exec_channel index
;
1236 union tgsi_exec_channel indir_index
;
1239 /* which address register (always zero for now) */
1243 index
.i
[3] = reg
->Indirect
.Index
;
1245 /* get current value of address register[swizzle] */
1246 swizzle
= tgsi_util_get_src_register_swizzle( ®
->Indirect
, CHAN_X
);
1248 /* fetch values from the address/indirection register */
1249 fetch_src_file_channel(
1256 /* save indirection offset */
1257 offset
= (int) indir_index
.f
[0];
1260 switch (reg
->Register
.File
) {
1261 case TGSI_FILE_NULL
:
1265 case TGSI_FILE_OUTPUT
:
1266 index
= mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0]
1267 + reg
->Register
.Index
;
1268 dst
= &mach
->Outputs
[offset
+ index
].xyzw
[chan_index
];
1270 if (TGSI_PROCESSOR_GEOMETRY
== mach
->Processor
) {
1271 fprintf(stderr
, "STORING OUT[%d] mask(%d), = (", offset
+ index
, execmask
);
1272 for (i
= 0; i
< QUAD_SIZE
; i
++)
1273 if (execmask
& (1 << i
))
1274 fprintf(stderr
, "%f, ", chan
->f
[i
]);
1275 fprintf(stderr
, ")\n");
1280 case TGSI_FILE_TEMPORARY
:
1281 index
= reg
->Register
.Index
;
1282 assert( index
< TGSI_EXEC_NUM_TEMPS
);
1283 dst
= &mach
->Temps
[offset
+ index
].xyzw
[chan_index
];
1286 case TGSI_FILE_ADDRESS
:
1287 index
= reg
->Register
.Index
;
1288 dst
= &mach
->Addrs
[index
].xyzw
[chan_index
];
1291 case TGSI_FILE_LOOP
:
1292 assert(reg
->Register
.Index
== 0);
1293 assert(mach
->LoopCounterStackTop
> 0);
1294 assert(chan_index
== CHAN_X
);
1295 dst
= &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[chan_index
];
1298 case TGSI_FILE_PREDICATE
:
1299 index
= reg
->Register
.Index
;
1300 assert(index
< TGSI_EXEC_NUM_PREDS
);
1301 dst
= &mach
->Predicates
[index
].xyzw
[chan_index
];
1309 if (inst
->Instruction
.Predicate
) {
1311 union tgsi_exec_channel
*pred
;
1313 switch (chan_index
) {
1315 swizzle
= inst
->Predicate
.SwizzleX
;
1318 swizzle
= inst
->Predicate
.SwizzleY
;
1321 swizzle
= inst
->Predicate
.SwizzleZ
;
1324 swizzle
= inst
->Predicate
.SwizzleW
;
1331 assert(inst
->Predicate
.Index
== 0);
1333 pred
= &mach
->Predicates
[inst
->Predicate
.Index
].xyzw
[swizzle
];
1335 if (inst
->Predicate
.Negate
) {
1336 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1338 execmask
&= ~(1 << i
);
1342 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1344 execmask
&= ~(1 << i
);
1350 switch (inst
->Instruction
.Saturate
) {
1352 for (i
= 0; i
< QUAD_SIZE
; i
++)
1353 if (execmask
& (1 << i
))
1354 dst
->i
[i
] = chan
->i
[i
];
1357 case TGSI_SAT_ZERO_ONE
:
1358 for (i
= 0; i
< QUAD_SIZE
; i
++)
1359 if (execmask
& (1 << i
)) {
1360 if (chan
->f
[i
] < 0.0f
)
1362 else if (chan
->f
[i
] > 1.0f
)
1365 dst
->i
[i
] = chan
->i
[i
];
1369 case TGSI_SAT_MINUS_PLUS_ONE
:
1370 for (i
= 0; i
< QUAD_SIZE
; i
++)
1371 if (execmask
& (1 << i
)) {
1372 if (chan
->f
[i
] < -1.0f
)
1374 else if (chan
->f
[i
] > 1.0f
)
1377 dst
->i
[i
] = chan
->i
[i
];
1386 #define FETCH(VAL,INDEX,CHAN)\
1387 fetch_source (mach, VAL, &inst->Src[INDEX], CHAN)
1389 #define STORE(VAL,INDEX,CHAN)\
1390 store_dest (mach, VAL, &inst->Dst[INDEX], inst, CHAN )
1394 * Execute ARB-style KIL which is predicated by a src register.
1395 * Kill fragment if any of the four values is less than zero.
1398 exec_kil(struct tgsi_exec_machine
*mach
,
1399 const struct tgsi_full_instruction
*inst
)
1403 uint kilmask
= 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1404 union tgsi_exec_channel r
[1];
1406 /* This mask stores component bits that were already tested. */
1409 for (chan_index
= 0; chan_index
< 4; chan_index
++)
1414 /* unswizzle channel */
1415 swizzle
= tgsi_util_get_full_src_register_swizzle (
1419 /* check if the component has not been already tested */
1420 if (uniquemask
& (1 << swizzle
))
1422 uniquemask
|= 1 << swizzle
;
1424 FETCH(&r
[0], 0, chan_index
);
1425 for (i
= 0; i
< 4; i
++)
1426 if (r
[0].f
[i
] < 0.0f
)
1430 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1434 * Execute NVIDIA-style KIL which is predicated by a condition code.
1435 * Kill fragment if the condition code is TRUE.
1438 exec_kilp(struct tgsi_exec_machine
*mach
,
1439 const struct tgsi_full_instruction
*inst
)
1441 uint kilmask
; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1443 /* "unconditional" kil */
1444 kilmask
= mach
->ExecMask
;
1445 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1449 emit_vertex(struct tgsi_exec_machine
*mach
)
1451 /* FIXME: check for exec mask correctly
1453 for (i = 0; i < QUAD_SIZE; ++i) {
1454 if ((mach->ExecMask & (1 << i)))
1456 if (mach
->ExecMask
) {
1457 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] += mach
->NumOutputs
;
1458 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]]++;
1463 emit_primitive(struct tgsi_exec_machine
*mach
)
1465 unsigned *prim_count
= &mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0];
1466 /* FIXME: check for exec mask correctly
1468 for (i = 0; i < QUAD_SIZE; ++i) {
1469 if ((mach->ExecMask & (1 << i)))
1471 if (mach
->ExecMask
) {
1473 debug_assert((*prim_count
* mach
->NumOutputs
) < mach
->MaxGeometryShaderOutputs
);
1474 mach
->Primitives
[*prim_count
] = 0;
1479 * Fetch a four texture samples using STR texture coordinates.
1482 fetch_texel( struct tgsi_sampler
*sampler
,
1483 const union tgsi_exec_channel
*s
,
1484 const union tgsi_exec_channel
*t
,
1485 const union tgsi_exec_channel
*p
,
1486 float lodbias
, /* XXX should be float[4] */
1487 union tgsi_exec_channel
*r
,
1488 union tgsi_exec_channel
*g
,
1489 union tgsi_exec_channel
*b
,
1490 union tgsi_exec_channel
*a
)
1493 float rgba
[NUM_CHANNELS
][QUAD_SIZE
];
1495 sampler
->get_samples(sampler
, s
->f
, t
->f
, p
->f
, lodbias
, rgba
);
1497 for (j
= 0; j
< 4; j
++) {
1498 r
->f
[j
] = rgba
[0][j
];
1499 g
->f
[j
] = rgba
[1][j
];
1500 b
->f
[j
] = rgba
[2][j
];
1501 a
->f
[j
] = rgba
[3][j
];
1507 exec_tex(struct tgsi_exec_machine
*mach
,
1508 const struct tgsi_full_instruction
*inst
,
1512 const uint unit
= inst
->Src
[1].Register
.Index
;
1513 union tgsi_exec_channel r
[4];
1517 /* debug_printf("Sampler %u unit %u\n", sampler, unit); */
1519 switch (inst
->Texture
.Texture
) {
1520 case TGSI_TEXTURE_1D
:
1521 case TGSI_TEXTURE_SHADOW1D
:
1523 FETCH(&r
[0], 0, CHAN_X
);
1526 FETCH(&r
[1], 0, CHAN_W
);
1527 micro_div( &r
[0], &r
[0], &r
[1] );
1531 FETCH(&r
[1], 0, CHAN_W
);
1532 lodBias
= r
[2].f
[0];
1537 fetch_texel(mach
->Samplers
[unit
],
1538 &r
[0], &ZeroVec
, &ZeroVec
, lodBias
, /* S, T, P, BIAS */
1539 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1542 case TGSI_TEXTURE_2D
:
1543 case TGSI_TEXTURE_RECT
:
1544 case TGSI_TEXTURE_SHADOW2D
:
1545 case TGSI_TEXTURE_SHADOWRECT
:
1547 FETCH(&r
[0], 0, CHAN_X
);
1548 FETCH(&r
[1], 0, CHAN_Y
);
1549 FETCH(&r
[2], 0, CHAN_Z
);
1552 FETCH(&r
[3], 0, CHAN_W
);
1553 micro_div( &r
[0], &r
[0], &r
[3] );
1554 micro_div( &r
[1], &r
[1], &r
[3] );
1555 micro_div( &r
[2], &r
[2], &r
[3] );
1559 FETCH(&r
[3], 0, CHAN_W
);
1560 lodBias
= r
[3].f
[0];
1565 fetch_texel(mach
->Samplers
[unit
],
1566 &r
[0], &r
[1], &r
[2], lodBias
, /* inputs */
1567 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1570 case TGSI_TEXTURE_3D
:
1571 case TGSI_TEXTURE_CUBE
:
1573 FETCH(&r
[0], 0, CHAN_X
);
1574 FETCH(&r
[1], 0, CHAN_Y
);
1575 FETCH(&r
[2], 0, CHAN_Z
);
1578 FETCH(&r
[3], 0, CHAN_W
);
1579 micro_div( &r
[0], &r
[0], &r
[3] );
1580 micro_div( &r
[1], &r
[1], &r
[3] );
1581 micro_div( &r
[2], &r
[2], &r
[3] );
1585 FETCH(&r
[3], 0, CHAN_W
);
1586 lodBias
= r
[3].f
[0];
1591 fetch_texel(mach
->Samplers
[unit
],
1592 &r
[0], &r
[1], &r
[2], lodBias
,
1593 &r
[0], &r
[1], &r
[2], &r
[3]);
1600 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
1601 STORE( &r
[chan_index
], 0, chan_index
);
1606 exec_txd(struct tgsi_exec_machine
*mach
,
1607 const struct tgsi_full_instruction
*inst
)
1609 const uint unit
= inst
->Src
[3].Register
.Index
;
1610 union tgsi_exec_channel r
[4];
1614 * XXX: This is fake TXD -- the derivatives are not taken into account, yet.
1617 switch (inst
->Texture
.Texture
) {
1618 case TGSI_TEXTURE_1D
:
1619 case TGSI_TEXTURE_SHADOW1D
:
1621 FETCH(&r
[0], 0, CHAN_X
);
1623 fetch_texel(mach
->Samplers
[unit
],
1624 &r
[0], &ZeroVec
, &ZeroVec
, 0.0f
, /* S, T, P, BIAS */
1625 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1628 case TGSI_TEXTURE_2D
:
1629 case TGSI_TEXTURE_RECT
:
1630 case TGSI_TEXTURE_SHADOW2D
:
1631 case TGSI_TEXTURE_SHADOWRECT
:
1633 FETCH(&r
[0], 0, CHAN_X
);
1634 FETCH(&r
[1], 0, CHAN_Y
);
1635 FETCH(&r
[2], 0, CHAN_Z
);
1637 fetch_texel(mach
->Samplers
[unit
],
1638 &r
[0], &r
[1], &r
[2], 0.0f
, /* inputs */
1639 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1642 case TGSI_TEXTURE_3D
:
1643 case TGSI_TEXTURE_CUBE
:
1645 FETCH(&r
[0], 0, CHAN_X
);
1646 FETCH(&r
[1], 0, CHAN_Y
);
1647 FETCH(&r
[2], 0, CHAN_Z
);
1649 fetch_texel(mach
->Samplers
[unit
],
1650 &r
[0], &r
[1], &r
[2], 0.0f
,
1651 &r
[0], &r
[1], &r
[2], &r
[3]);
1658 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
1659 STORE(&r
[chan_index
], 0, chan_index
);
1665 * Evaluate a constant-valued coefficient at the position of the
1670 struct tgsi_exec_machine
*mach
,
1676 for( i
= 0; i
< QUAD_SIZE
; i
++ ) {
1677 mach
->Inputs
[attrib
].xyzw
[chan
].f
[i
] = mach
->InterpCoefs
[attrib
].a0
[chan
];
1682 * Evaluate a linear-valued coefficient at the position of the
1687 struct tgsi_exec_machine
*mach
,
1691 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1692 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1693 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1694 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1695 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1696 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
;
1697 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = a0
+ dadx
;
1698 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = a0
+ dady
;
1699 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = a0
+ dadx
+ dady
;
1703 * Evaluate a perspective-valued coefficient at the position of the
1707 eval_perspective_coef(
1708 struct tgsi_exec_machine
*mach
,
1712 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1713 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1714 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1715 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1716 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1717 const float *w
= mach
->QuadPos
.xyzw
[3].f
;
1718 /* divide by W here */
1719 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
/ w
[0];
1720 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = (a0
+ dadx
) / w
[1];
1721 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = (a0
+ dady
) / w
[2];
1722 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = (a0
+ dadx
+ dady
) / w
[3];
1726 typedef void (* eval_coef_func
)(
1727 struct tgsi_exec_machine
*mach
,
1732 exec_declaration(struct tgsi_exec_machine
*mach
,
1733 const struct tgsi_full_declaration
*decl
)
1735 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
1736 if (decl
->Declaration
.File
== TGSI_FILE_INPUT
||
1737 decl
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1738 uint first
, last
, mask
;
1740 first
= decl
->Range
.First
;
1741 last
= decl
->Range
.Last
;
1742 mask
= decl
->Declaration
.UsageMask
;
1744 if (decl
->Semantic
.Name
== TGSI_SEMANTIC_POSITION
) {
1745 assert(decl
->Semantic
.Index
== 0);
1746 assert(first
== last
);
1747 assert(mask
== TGSI_WRITEMASK_XYZW
);
1749 mach
->Inputs
[first
] = mach
->QuadPos
;
1750 } else if (decl
->Semantic
.Name
== TGSI_SEMANTIC_FACE
) {
1753 assert(decl
->Semantic
.Index
== 0);
1754 assert(first
== last
);
1756 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1757 mach
->Inputs
[first
].xyzw
[0].f
[i
] = mach
->Face
;
1760 eval_coef_func eval
;
1763 switch (decl
->Declaration
.Interpolate
) {
1764 case TGSI_INTERPOLATE_CONSTANT
:
1765 eval
= eval_constant_coef
;
1768 case TGSI_INTERPOLATE_LINEAR
:
1769 eval
= eval_linear_coef
;
1772 case TGSI_INTERPOLATE_PERSPECTIVE
:
1773 eval
= eval_perspective_coef
;
1781 for (j
= 0; j
< NUM_CHANNELS
; j
++) {
1782 if (mask
& (1 << j
)) {
1783 for (i
= first
; i
<= last
; i
++) {
1793 typedef void (* micro_op
)(union tgsi_exec_channel
*dst
,
1794 const union tgsi_exec_channel
*src
);
1797 exec_vector_unary(struct tgsi_exec_machine
*mach
,
1798 const struct tgsi_full_instruction
*inst
,
1802 struct tgsi_exec_vector dst
;
1804 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1805 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1806 union tgsi_exec_channel src
;
1808 fetch_source(mach
, &src
, &inst
->Src
[0], chan
);
1809 op(&dst
.xyzw
[chan
], &src
);
1812 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1813 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1814 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
);
1820 exec_vector_binary(struct tgsi_exec_machine
*mach
,
1821 const struct tgsi_full_instruction
*inst
,
1825 struct tgsi_exec_vector dst
;
1827 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1828 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1829 union tgsi_exec_channel src
[2];
1831 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
);
1832 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
);
1833 op(&dst
.xyzw
[chan
], src
);
1836 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1837 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1838 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
);
1844 exec_vector_trinary(struct tgsi_exec_machine
*mach
,
1845 const struct tgsi_full_instruction
*inst
,
1849 struct tgsi_exec_vector dst
;
1851 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1852 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1853 union tgsi_exec_channel src
[3];
1855 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
);
1856 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
);
1857 fetch_source(mach
, &src
[2], &inst
->Src
[2], chan
);
1858 op(&dst
.xyzw
[chan
], src
);
1861 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1862 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1863 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
);
1869 micro_f2i(union tgsi_exec_channel
*dst
,
1870 const union tgsi_exec_channel
*src
)
1872 dst
->i
[0] = (int)src
->f
[0];
1873 dst
->i
[1] = (int)src
->f
[1];
1874 dst
->i
[2] = (int)src
->f
[2];
1875 dst
->i
[3] = (int)src
->f
[3];
1879 micro_idiv(union tgsi_exec_channel
*dst
,
1880 const union tgsi_exec_channel
*src
)
1882 dst
->i
[0] = src
[0].i
[0] / src
[1].i
[0];
1883 dst
->i
[1] = src
[0].i
[1] / src
[1].i
[1];
1884 dst
->i
[2] = src
[0].i
[2] / src
[1].i
[2];
1885 dst
->i
[3] = src
[0].i
[3] / src
[1].i
[3];
1889 micro_imax(union tgsi_exec_channel
*dst
,
1890 const union tgsi_exec_channel
*src
)
1892 dst
->i
[0] = src
[0].i
[0] > src
[1].i
[0] ? src
[0].i
[0] : src
[1].i
[0];
1893 dst
->i
[1] = src
[0].i
[1] > src
[1].i
[1] ? src
[0].i
[1] : src
[1].i
[1];
1894 dst
->i
[2] = src
[0].i
[2] > src
[1].i
[2] ? src
[0].i
[2] : src
[1].i
[2];
1895 dst
->i
[3] = src
[0].i
[3] > src
[1].i
[3] ? src
[0].i
[3] : src
[1].i
[3];
1899 micro_imin(union tgsi_exec_channel
*dst
,
1900 const union tgsi_exec_channel
*src
)
1902 dst
->i
[0] = src
[0].i
[0] < src
[1].i
[0] ? src
[0].i
[0] : src
[1].i
[0];
1903 dst
->i
[1] = src
[0].i
[1] < src
[1].i
[1] ? src
[0].i
[1] : src
[1].i
[1];
1904 dst
->i
[2] = src
[0].i
[2] < src
[1].i
[2] ? src
[0].i
[2] : src
[1].i
[2];
1905 dst
->i
[3] = src
[0].i
[3] < src
[1].i
[3] ? src
[0].i
[3] : src
[1].i
[3];
1909 micro_ineg(union tgsi_exec_channel
*dst
,
1910 const union tgsi_exec_channel
*src
)
1912 dst
->i
[0] = -src
->i
[0];
1913 dst
->i
[1] = -src
->i
[1];
1914 dst
->i
[2] = -src
->i
[2];
1915 dst
->i
[3] = -src
->i
[3];
1919 micro_isge(union tgsi_exec_channel
*dst
,
1920 const union tgsi_exec_channel
*src
)
1922 dst
->i
[0] = src
[0].i
[0] >= src
[1].i
[0] ? -1 : 0;
1923 dst
->i
[1] = src
[0].i
[1] >= src
[1].i
[1] ? -1 : 0;
1924 dst
->i
[2] = src
[0].i
[2] >= src
[1].i
[2] ? -1 : 0;
1925 dst
->i
[3] = src
[0].i
[3] >= src
[1].i
[3] ? -1 : 0;
1929 micro_ishr(union tgsi_exec_channel
*dst
,
1930 const union tgsi_exec_channel
*src
)
1932 dst
->i
[0] = src
[0].i
[0] >> src
[1].i
[0];
1933 dst
->i
[1] = src
[0].i
[1] >> src
[1].i
[1];
1934 dst
->i
[2] = src
[0].i
[2] >> src
[1].i
[2];
1935 dst
->i
[3] = src
[0].i
[3] >> src
[1].i
[3];
1939 micro_islt(union tgsi_exec_channel
*dst
,
1940 const union tgsi_exec_channel
*src
)
1942 dst
->i
[0] = src
[0].i
[0] < src
[1].i
[0] ? -1 : 0;
1943 dst
->i
[1] = src
[0].i
[1] < src
[1].i
[1] ? -1 : 0;
1944 dst
->i
[2] = src
[0].i
[2] < src
[1].i
[2] ? -1 : 0;
1945 dst
->i
[3] = src
[0].i
[3] < src
[1].i
[3] ? -1 : 0;
1949 micro_f2u(union tgsi_exec_channel
*dst
,
1950 const union tgsi_exec_channel
*src
)
1952 dst
->u
[0] = (uint
)src
->f
[0];
1953 dst
->u
[1] = (uint
)src
->f
[1];
1954 dst
->u
[2] = (uint
)src
->f
[2];
1955 dst
->u
[3] = (uint
)src
->f
[3];
1959 micro_u2f(union tgsi_exec_channel
*dst
,
1960 const union tgsi_exec_channel
*src
)
1962 dst
->f
[0] = (float)src
->u
[0];
1963 dst
->f
[1] = (float)src
->u
[1];
1964 dst
->f
[2] = (float)src
->u
[2];
1965 dst
->f
[3] = (float)src
->u
[3];
1969 micro_uadd(union tgsi_exec_channel
*dst
,
1970 const union tgsi_exec_channel
*src
)
1972 dst
->u
[0] = src
[0].u
[0] + src
[1].u
[0];
1973 dst
->u
[1] = src
[0].u
[1] + src
[1].u
[1];
1974 dst
->u
[2] = src
[0].u
[2] + src
[1].u
[2];
1975 dst
->u
[3] = src
[0].u
[3] + src
[1].u
[3];
1979 micro_udiv(union tgsi_exec_channel
*dst
,
1980 const union tgsi_exec_channel
*src
)
1982 dst
->u
[0] = src
[0].u
[0] / src
[1].u
[0];
1983 dst
->u
[1] = src
[0].u
[1] / src
[1].u
[1];
1984 dst
->u
[2] = src
[0].u
[2] / src
[1].u
[2];
1985 dst
->u
[3] = src
[0].u
[3] / src
[1].u
[3];
1989 micro_umad(union tgsi_exec_channel
*dst
,
1990 const union tgsi_exec_channel
*src
)
1992 dst
->u
[0] = src
[0].u
[0] * src
[1].u
[0] + src
[2].u
[0];
1993 dst
->u
[1] = src
[0].u
[1] * src
[1].u
[1] + src
[2].u
[1];
1994 dst
->u
[2] = src
[0].u
[2] * src
[1].u
[2] + src
[2].u
[2];
1995 dst
->u
[3] = src
[0].u
[3] * src
[1].u
[3] + src
[2].u
[3];
1999 micro_umax(union tgsi_exec_channel
*dst
,
2000 const union tgsi_exec_channel
*src
)
2002 dst
->u
[0] = src
[0].u
[0] > src
[1].u
[0] ? src
[0].u
[0] : src
[1].u
[0];
2003 dst
->u
[1] = src
[0].u
[1] > src
[1].u
[1] ? src
[0].u
[1] : src
[1].u
[1];
2004 dst
->u
[2] = src
[0].u
[2] > src
[1].u
[2] ? src
[0].u
[2] : src
[1].u
[2];
2005 dst
->u
[3] = src
[0].u
[3] > src
[1].u
[3] ? src
[0].u
[3] : src
[1].u
[3];
2009 micro_umin(union tgsi_exec_channel
*dst
,
2010 const union tgsi_exec_channel
*src
)
2012 dst
->u
[0] = src
[0].u
[0] < src
[1].u
[0] ? src
[0].u
[0] : src
[1].u
[0];
2013 dst
->u
[1] = src
[0].u
[1] < src
[1].u
[1] ? src
[0].u
[1] : src
[1].u
[1];
2014 dst
->u
[2] = src
[0].u
[2] < src
[1].u
[2] ? src
[0].u
[2] : src
[1].u
[2];
2015 dst
->u
[3] = src
[0].u
[3] < src
[1].u
[3] ? src
[0].u
[3] : src
[1].u
[3];
2019 micro_umul(union tgsi_exec_channel
*dst
,
2020 const union tgsi_exec_channel
*src
)
2022 dst
->u
[0] = src
[0].u
[0] * src
[1].u
[0];
2023 dst
->u
[1] = src
[0].u
[1] * src
[1].u
[1];
2024 dst
->u
[2] = src
[0].u
[2] * src
[1].u
[2];
2025 dst
->u
[3] = src
[0].u
[3] * src
[1].u
[3];
2029 micro_useq(union tgsi_exec_channel
*dst
,
2030 const union tgsi_exec_channel
*src
)
2032 dst
->u
[0] = src
[0].u
[0] == src
[1].u
[0] ? ~0 : 0;
2033 dst
->u
[1] = src
[0].u
[1] == src
[1].u
[1] ? ~0 : 0;
2034 dst
->u
[2] = src
[0].u
[2] == src
[1].u
[2] ? ~0 : 0;
2035 dst
->u
[3] = src
[0].u
[3] == src
[1].u
[3] ? ~0 : 0;
2039 micro_usge(union tgsi_exec_channel
*dst
,
2040 const union tgsi_exec_channel
*src
)
2042 dst
->u
[0] = src
[0].u
[0] >= src
[1].u
[0] ? ~0 : 0;
2043 dst
->u
[1] = src
[0].u
[1] >= src
[1].u
[1] ? ~0 : 0;
2044 dst
->u
[2] = src
[0].u
[2] >= src
[1].u
[2] ? ~0 : 0;
2045 dst
->u
[3] = src
[0].u
[3] >= src
[1].u
[3] ? ~0 : 0;
2049 micro_ushr(union tgsi_exec_channel
*dst
,
2050 const union tgsi_exec_channel
*src
)
2052 dst
->u
[0] = src
[0].u
[0] >> src
[1].u
[0];
2053 dst
->u
[1] = src
[0].u
[1] >> src
[1].u
[1];
2054 dst
->u
[2] = src
[0].u
[2] >> src
[1].u
[2];
2055 dst
->u
[3] = src
[0].u
[3] >> src
[1].u
[3];
2059 micro_uslt(union tgsi_exec_channel
*dst
,
2060 const union tgsi_exec_channel
*src
)
2062 dst
->u
[0] = src
[0].u
[0] < src
[1].u
[0] ? ~0 : 0;
2063 dst
->u
[1] = src
[0].u
[1] < src
[1].u
[1] ? ~0 : 0;
2064 dst
->u
[2] = src
[0].u
[2] < src
[1].u
[2] ? ~0 : 0;
2065 dst
->u
[3] = src
[0].u
[3] < src
[1].u
[3] ? ~0 : 0;
2069 micro_usne(union tgsi_exec_channel
*dst
,
2070 const union tgsi_exec_channel
*src
)
2072 dst
->u
[0] = src
[0].u
[0] != src
[1].u
[0] ? ~0 : 0;
2073 dst
->u
[1] = src
[0].u
[1] != src
[1].u
[1] ? ~0 : 0;
2074 dst
->u
[2] = src
[0].u
[2] != src
[1].u
[2] ? ~0 : 0;
2075 dst
->u
[3] = src
[0].u
[3] != src
[1].u
[3] ? ~0 : 0;
2080 struct tgsi_exec_machine
*mach
,
2081 const struct tgsi_full_instruction
*inst
,
2085 union tgsi_exec_channel r
[10];
2086 union tgsi_exec_channel d
[8];
2090 switch (inst
->Instruction
.Opcode
) {
2091 case TGSI_OPCODE_ARL
:
2092 case TGSI_OPCODE_FLR
:
2093 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2094 FETCH( &r
[0], 0, chan_index
);
2095 micro_flr(&d
[chan_index
], &r
[0]);
2097 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2098 STORE(&d
[chan_index
], 0, chan_index
);
2102 case TGSI_OPCODE_MOV
:
2103 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2104 FETCH(&d
[chan_index
], 0, chan_index
);
2106 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2107 STORE(&d
[chan_index
], 0, chan_index
);
2111 case TGSI_OPCODE_LIT
:
2112 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2113 FETCH( &r
[0], 0, CHAN_X
);
2114 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2115 micro_max(&d
[CHAN_Y
], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
2118 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2119 FETCH( &r
[1], 0, CHAN_Y
);
2120 micro_max( &r
[1], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
2122 FETCH( &r
[2], 0, CHAN_W
);
2123 micro_min( &r
[2], &r
[2], &mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
] );
2124 micro_max( &r
[2], &r
[2], &mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
] );
2125 micro_pow( &r
[1], &r
[1], &r
[2] );
2126 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
]);
2129 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2130 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2132 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2133 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2136 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2137 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2139 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2140 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2144 case TGSI_OPCODE_RCP
:
2145 /* TGSI_OPCODE_RECIP */
2146 FETCH( &r
[0], 0, CHAN_X
);
2147 micro_div( &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0] );
2148 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2149 STORE( &r
[0], 0, chan_index
);
2153 case TGSI_OPCODE_RSQ
:
2154 /* TGSI_OPCODE_RECIPSQRT */
2155 FETCH( &r
[0], 0, CHAN_X
);
2156 micro_abs( &r
[0], &r
[0] );
2157 micro_sqrt( &r
[0], &r
[0] );
2158 micro_div( &r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0] );
2159 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2160 STORE( &r
[0], 0, chan_index
);
2164 case TGSI_OPCODE_EXP
:
2165 FETCH( &r
[0], 0, CHAN_X
);
2166 micro_flr( &r
[1], &r
[0] ); /* r1 = floor(r0) */
2167 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2168 micro_exp2( &r
[2], &r
[1] ); /* r2 = 2 ^ r1 */
2169 STORE( &r
[2], 0, CHAN_X
); /* store r2 */
2171 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2172 micro_sub( &r
[2], &r
[0], &r
[1] ); /* r2 = r0 - r1 */
2173 STORE( &r
[2], 0, CHAN_Y
); /* store r2 */
2175 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2176 micro_exp2( &r
[2], &r
[0] ); /* r2 = 2 ^ r0 */
2177 STORE( &r
[2], 0, CHAN_Z
); /* store r2 */
2179 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2180 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2184 case TGSI_OPCODE_LOG
:
2185 FETCH( &r
[0], 0, CHAN_X
);
2186 micro_abs( &r
[2], &r
[0] ); /* r2 = abs(r0) */
2187 micro_lg2( &r
[1], &r
[2] ); /* r1 = lg2(r2) */
2188 micro_flr( &r
[0], &r
[1] ); /* r0 = floor(r1) */
2189 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2190 STORE( &r
[0], 0, CHAN_X
);
2192 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2193 micro_exp2( &r
[0], &r
[0] ); /* r0 = 2 ^ r0 */
2194 micro_div( &r
[0], &r
[2], &r
[0] ); /* r0 = r2 / r0 */
2195 STORE( &r
[0], 0, CHAN_Y
);
2197 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2198 STORE( &r
[1], 0, CHAN_Z
);
2200 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2201 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2205 case TGSI_OPCODE_MUL
:
2206 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2207 FETCH(&r
[0], 0, chan_index
);
2208 FETCH(&r
[1], 1, chan_index
);
2209 micro_mul(&d
[chan_index
], &r
[0], &r
[1]);
2211 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2212 STORE(&d
[chan_index
], 0, chan_index
);
2216 case TGSI_OPCODE_ADD
:
2217 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2218 FETCH( &r
[0], 0, chan_index
);
2219 FETCH( &r
[1], 1, chan_index
);
2220 micro_add(&d
[chan_index
], &r
[0], &r
[1]);
2222 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2223 STORE(&d
[chan_index
], 0, chan_index
);
2227 case TGSI_OPCODE_DP3
:
2228 /* TGSI_OPCODE_DOT3 */
2229 FETCH( &r
[0], 0, CHAN_X
);
2230 FETCH( &r
[1], 1, CHAN_X
);
2231 micro_mul( &r
[0], &r
[0], &r
[1] );
2233 FETCH( &r
[1], 0, CHAN_Y
);
2234 FETCH( &r
[2], 1, CHAN_Y
);
2235 micro_mul( &r
[1], &r
[1], &r
[2] );
2236 micro_add( &r
[0], &r
[0], &r
[1] );
2238 FETCH( &r
[1], 0, CHAN_Z
);
2239 FETCH( &r
[2], 1, CHAN_Z
);
2240 micro_mul( &r
[1], &r
[1], &r
[2] );
2241 micro_add( &r
[0], &r
[0], &r
[1] );
2243 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2244 STORE( &r
[0], 0, chan_index
);
2248 case TGSI_OPCODE_DP4
:
2249 /* TGSI_OPCODE_DOT4 */
2250 FETCH(&r
[0], 0, CHAN_X
);
2251 FETCH(&r
[1], 1, CHAN_X
);
2253 micro_mul( &r
[0], &r
[0], &r
[1] );
2255 FETCH(&r
[1], 0, CHAN_Y
);
2256 FETCH(&r
[2], 1, CHAN_Y
);
2258 micro_mul( &r
[1], &r
[1], &r
[2] );
2259 micro_add( &r
[0], &r
[0], &r
[1] );
2261 FETCH(&r
[1], 0, CHAN_Z
);
2262 FETCH(&r
[2], 1, CHAN_Z
);
2264 micro_mul( &r
[1], &r
[1], &r
[2] );
2265 micro_add( &r
[0], &r
[0], &r
[1] );
2267 FETCH(&r
[1], 0, CHAN_W
);
2268 FETCH(&r
[2], 1, CHAN_W
);
2270 micro_mul( &r
[1], &r
[1], &r
[2] );
2271 micro_add( &r
[0], &r
[0], &r
[1] );
2273 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2274 STORE( &r
[0], 0, chan_index
);
2278 case TGSI_OPCODE_DST
:
2279 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2280 FETCH( &r
[0], 0, CHAN_Y
);
2281 FETCH( &r
[1], 1, CHAN_Y
);
2282 micro_mul(&d
[CHAN_Y
], &r
[0], &r
[1]);
2284 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2285 FETCH(&d
[CHAN_Z
], 0, CHAN_Z
);
2287 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2288 FETCH(&d
[CHAN_W
], 1, CHAN_W
);
2291 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2292 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2294 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2295 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2297 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2298 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2300 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2301 STORE(&d
[CHAN_W
], 0, CHAN_W
);
2305 case TGSI_OPCODE_MIN
:
2306 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2307 FETCH(&r
[0], 0, chan_index
);
2308 FETCH(&r
[1], 1, chan_index
);
2310 /* XXX use micro_min()?? */
2311 micro_lt(&d
[chan_index
], &r
[0], &r
[1], &r
[0], &r
[1]);
2313 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2314 STORE(&d
[chan_index
], 0, chan_index
);
2318 case TGSI_OPCODE_MAX
:
2319 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2320 FETCH(&r
[0], 0, chan_index
);
2321 FETCH(&r
[1], 1, chan_index
);
2323 /* XXX use micro_max()?? */
2324 micro_lt(&d
[chan_index
], &r
[0], &r
[1], &r
[1], &r
[0] );
2326 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2327 STORE(&d
[chan_index
], 0, chan_index
);
2331 case TGSI_OPCODE_SLT
:
2332 /* TGSI_OPCODE_SETLT */
2333 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2334 FETCH( &r
[0], 0, chan_index
);
2335 FETCH( &r
[1], 1, chan_index
);
2336 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
]);
2338 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2339 STORE(&d
[chan_index
], 0, chan_index
);
2343 case TGSI_OPCODE_SGE
:
2344 /* TGSI_OPCODE_SETGE */
2345 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2346 FETCH( &r
[0], 0, chan_index
);
2347 FETCH( &r
[1], 1, chan_index
);
2348 micro_le(&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
]);
2350 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2351 STORE(&d
[chan_index
], 0, chan_index
);
2355 case TGSI_OPCODE_MAD
:
2356 /* TGSI_OPCODE_MADD */
2357 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2358 FETCH( &r
[0], 0, chan_index
);
2359 FETCH( &r
[1], 1, chan_index
);
2360 micro_mul( &r
[0], &r
[0], &r
[1] );
2361 FETCH( &r
[1], 2, chan_index
);
2362 micro_add(&d
[chan_index
], &r
[0], &r
[1]);
2364 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2365 STORE(&d
[chan_index
], 0, chan_index
);
2369 case TGSI_OPCODE_SUB
:
2370 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2371 FETCH(&r
[0], 0, chan_index
);
2372 FETCH(&r
[1], 1, chan_index
);
2373 micro_sub(&d
[chan_index
], &r
[0], &r
[1]);
2375 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2376 STORE(&d
[chan_index
], 0, chan_index
);
2380 case TGSI_OPCODE_LRP
:
2381 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2382 FETCH(&r
[0], 0, chan_index
);
2383 FETCH(&r
[1], 1, chan_index
);
2384 FETCH(&r
[2], 2, chan_index
);
2385 micro_sub( &r
[1], &r
[1], &r
[2] );
2386 micro_mul( &r
[0], &r
[0], &r
[1] );
2387 micro_add(&d
[chan_index
], &r
[0], &r
[2]);
2389 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2390 STORE(&d
[chan_index
], 0, chan_index
);
2394 case TGSI_OPCODE_CND
:
2395 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2396 FETCH(&r
[0], 0, chan_index
);
2397 FETCH(&r
[1], 1, chan_index
);
2398 FETCH(&r
[2], 2, chan_index
);
2399 micro_lt(&d
[chan_index
], &mach
->Temps
[TEMP_HALF_I
].xyzw
[TEMP_HALF_C
], &r
[2], &r
[0], &r
[1]);
2401 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2402 STORE(&d
[chan_index
], 0, chan_index
);
2406 case TGSI_OPCODE_DP2A
:
2407 FETCH( &r
[0], 0, CHAN_X
);
2408 FETCH( &r
[1], 1, CHAN_X
);
2409 micro_mul( &r
[0], &r
[0], &r
[1] );
2411 FETCH( &r
[1], 0, CHAN_Y
);
2412 FETCH( &r
[2], 1, CHAN_Y
);
2413 micro_mul( &r
[1], &r
[1], &r
[2] );
2414 micro_add( &r
[0], &r
[0], &r
[1] );
2416 FETCH( &r
[2], 2, CHAN_X
);
2417 micro_add( &r
[0], &r
[0], &r
[2] );
2419 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2420 STORE( &r
[0], 0, chan_index
);
2424 case TGSI_OPCODE_FRC
:
2425 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2426 FETCH( &r
[0], 0, chan_index
);
2427 micro_frc(&d
[chan_index
], &r
[0]);
2429 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2430 STORE(&d
[chan_index
], 0, chan_index
);
2434 case TGSI_OPCODE_CLAMP
:
2435 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2436 FETCH(&r
[0], 0, chan_index
);
2437 FETCH(&r
[1], 1, chan_index
);
2438 micro_max(&r
[0], &r
[0], &r
[1]);
2439 FETCH(&r
[1], 2, chan_index
);
2440 micro_min(&d
[chan_index
], &r
[0], &r
[1]);
2442 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2443 STORE(&d
[chan_index
], 0, chan_index
);
2447 case TGSI_OPCODE_ROUND
:
2448 case TGSI_OPCODE_ARR
:
2449 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2450 FETCH( &r
[0], 0, chan_index
);
2451 micro_rnd(&d
[chan_index
], &r
[0]);
2453 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2454 STORE(&d
[chan_index
], 0, chan_index
);
2458 case TGSI_OPCODE_EX2
:
2459 FETCH(&r
[0], 0, CHAN_X
);
2461 micro_exp2( &r
[0], &r
[0] );
2463 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2464 STORE( &r
[0], 0, chan_index
);
2468 case TGSI_OPCODE_LG2
:
2469 FETCH( &r
[0], 0, CHAN_X
);
2470 micro_lg2( &r
[0], &r
[0] );
2471 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2472 STORE( &r
[0], 0, chan_index
);
2476 case TGSI_OPCODE_POW
:
2477 FETCH(&r
[0], 0, CHAN_X
);
2478 FETCH(&r
[1], 1, CHAN_X
);
2480 micro_pow( &r
[0], &r
[0], &r
[1] );
2482 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2483 STORE( &r
[0], 0, chan_index
);
2487 case TGSI_OPCODE_XPD
:
2488 FETCH(&r
[0], 0, CHAN_Y
);
2489 FETCH(&r
[1], 1, CHAN_Z
);
2491 micro_mul( &r
[2], &r
[0], &r
[1] );
2493 FETCH(&r
[3], 0, CHAN_Z
);
2494 FETCH(&r
[4], 1, CHAN_Y
);
2496 micro_mul( &r
[5], &r
[3], &r
[4] );
2497 micro_sub(&d
[CHAN_X
], &r
[2], &r
[5]);
2499 FETCH(&r
[2], 1, CHAN_X
);
2501 micro_mul( &r
[3], &r
[3], &r
[2] );
2503 FETCH(&r
[5], 0, CHAN_X
);
2505 micro_mul( &r
[1], &r
[1], &r
[5] );
2506 micro_sub(&d
[CHAN_Y
], &r
[3], &r
[1]);
2508 micro_mul( &r
[5], &r
[5], &r
[4] );
2509 micro_mul( &r
[0], &r
[0], &r
[2] );
2510 micro_sub(&d
[CHAN_Z
], &r
[5], &r
[0]);
2512 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2513 STORE(&d
[CHAN_X
], 0, CHAN_X
);
2515 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2516 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2518 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2519 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2521 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2522 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2526 case TGSI_OPCODE_ABS
:
2527 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2528 FETCH(&r
[0], 0, chan_index
);
2529 micro_abs(&d
[chan_index
], &r
[0]);
2531 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2532 STORE(&d
[chan_index
], 0, chan_index
);
2536 case TGSI_OPCODE_RCC
:
2537 FETCH(&r
[0], 0, CHAN_X
);
2538 micro_div(&r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0]);
2539 micro_float_clamp(&r
[0], &r
[0]);
2540 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2541 STORE(&r
[0], 0, chan_index
);
2545 case TGSI_OPCODE_DPH
:
2546 FETCH(&r
[0], 0, CHAN_X
);
2547 FETCH(&r
[1], 1, CHAN_X
);
2549 micro_mul( &r
[0], &r
[0], &r
[1] );
2551 FETCH(&r
[1], 0, CHAN_Y
);
2552 FETCH(&r
[2], 1, CHAN_Y
);
2554 micro_mul( &r
[1], &r
[1], &r
[2] );
2555 micro_add( &r
[0], &r
[0], &r
[1] );
2557 FETCH(&r
[1], 0, CHAN_Z
);
2558 FETCH(&r
[2], 1, CHAN_Z
);
2560 micro_mul( &r
[1], &r
[1], &r
[2] );
2561 micro_add( &r
[0], &r
[0], &r
[1] );
2563 FETCH(&r
[1], 1, CHAN_W
);
2565 micro_add( &r
[0], &r
[0], &r
[1] );
2567 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2568 STORE( &r
[0], 0, chan_index
);
2572 case TGSI_OPCODE_COS
:
2573 FETCH(&r
[0], 0, CHAN_X
);
2575 micro_cos( &r
[0], &r
[0] );
2577 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2578 STORE( &r
[0], 0, chan_index
);
2582 case TGSI_OPCODE_DDX
:
2583 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2584 FETCH( &r
[0], 0, chan_index
);
2585 micro_ddx(&d
[chan_index
], &r
[0]);
2587 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2588 STORE(&d
[chan_index
], 0, chan_index
);
2592 case TGSI_OPCODE_DDY
:
2593 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2594 FETCH( &r
[0], 0, chan_index
);
2595 micro_ddy(&d
[chan_index
], &r
[0]);
2597 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2598 STORE(&d
[chan_index
], 0, chan_index
);
2602 case TGSI_OPCODE_KILP
:
2603 exec_kilp (mach
, inst
);
2606 case TGSI_OPCODE_KIL
:
2607 exec_kil (mach
, inst
);
2610 case TGSI_OPCODE_PK2H
:
2614 case TGSI_OPCODE_PK2US
:
2618 case TGSI_OPCODE_PK4B
:
2622 case TGSI_OPCODE_PK4UB
:
2626 case TGSI_OPCODE_RFL
:
2627 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2628 IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2629 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2630 /* r0 = dp3(src0, src0) */
2631 FETCH(&r
[2], 0, CHAN_X
);
2632 micro_mul(&r
[0], &r
[2], &r
[2]);
2633 FETCH(&r
[4], 0, CHAN_Y
);
2634 micro_mul(&r
[8], &r
[4], &r
[4]);
2635 micro_add(&r
[0], &r
[0], &r
[8]);
2636 FETCH(&r
[6], 0, CHAN_Z
);
2637 micro_mul(&r
[8], &r
[6], &r
[6]);
2638 micro_add(&r
[0], &r
[0], &r
[8]);
2640 /* r1 = dp3(src0, src1) */
2641 FETCH(&r
[3], 1, CHAN_X
);
2642 micro_mul(&r
[1], &r
[2], &r
[3]);
2643 FETCH(&r
[5], 1, CHAN_Y
);
2644 micro_mul(&r
[8], &r
[4], &r
[5]);
2645 micro_add(&r
[1], &r
[1], &r
[8]);
2646 FETCH(&r
[7], 1, CHAN_Z
);
2647 micro_mul(&r
[8], &r
[6], &r
[7]);
2648 micro_add(&r
[1], &r
[1], &r
[8]);
2650 /* r1 = 2 * r1 / r0 */
2651 micro_add(&r
[1], &r
[1], &r
[1]);
2652 micro_div(&r
[1], &r
[1], &r
[0]);
2654 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2655 micro_mul(&r
[2], &r
[2], &r
[1]);
2656 micro_sub(&r
[2], &r
[2], &r
[3]);
2657 STORE(&r
[2], 0, CHAN_X
);
2659 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2660 micro_mul(&r
[4], &r
[4], &r
[1]);
2661 micro_sub(&r
[4], &r
[4], &r
[5]);
2662 STORE(&r
[4], 0, CHAN_Y
);
2664 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2665 micro_mul(&r
[6], &r
[6], &r
[1]);
2666 micro_sub(&r
[6], &r
[6], &r
[7]);
2667 STORE(&r
[6], 0, CHAN_Z
);
2670 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2671 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2675 case TGSI_OPCODE_SEQ
:
2676 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2677 FETCH( &r
[0], 0, chan_index
);
2678 FETCH( &r
[1], 1, chan_index
);
2679 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
]);
2681 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2682 STORE(&d
[chan_index
], 0, chan_index
);
2686 case TGSI_OPCODE_SFL
:
2687 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2688 STORE(&mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, chan_index
);
2692 case TGSI_OPCODE_SGT
:
2693 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2694 FETCH( &r
[0], 0, chan_index
);
2695 FETCH( &r
[1], 1, chan_index
);
2696 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
]);
2698 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2699 STORE(&d
[chan_index
], 0, chan_index
);
2703 case TGSI_OPCODE_SIN
:
2704 FETCH( &r
[0], 0, CHAN_X
);
2705 micro_sin( &r
[0], &r
[0] );
2706 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2707 STORE( &r
[0], 0, chan_index
);
2711 case TGSI_OPCODE_SLE
:
2712 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2713 FETCH( &r
[0], 0, chan_index
);
2714 FETCH( &r
[1], 1, chan_index
);
2715 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
]);
2717 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2718 STORE(&d
[chan_index
], 0, chan_index
);
2722 case TGSI_OPCODE_SNE
:
2723 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2724 FETCH( &r
[0], 0, chan_index
);
2725 FETCH( &r
[1], 1, chan_index
);
2726 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
]);
2728 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2729 STORE(&d
[chan_index
], 0, chan_index
);
2733 case TGSI_OPCODE_STR
:
2734 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2735 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, chan_index
);
2739 case TGSI_OPCODE_TEX
:
2740 /* simple texture lookup */
2741 /* src[0] = texcoord */
2742 /* src[1] = sampler unit */
2743 exec_tex(mach
, inst
, FALSE
, FALSE
);
2746 case TGSI_OPCODE_TXB
:
2747 /* Texture lookup with lod bias */
2748 /* src[0] = texcoord (src[0].w = LOD bias) */
2749 /* src[1] = sampler unit */
2750 exec_tex(mach
, inst
, TRUE
, FALSE
);
2753 case TGSI_OPCODE_TXD
:
2754 /* Texture lookup with explict partial derivatives */
2755 /* src[0] = texcoord */
2756 /* src[1] = d[strq]/dx */
2757 /* src[2] = d[strq]/dy */
2758 /* src[3] = sampler unit */
2759 exec_txd(mach
, inst
);
2762 case TGSI_OPCODE_TXL
:
2763 /* Texture lookup with explit LOD */
2764 /* src[0] = texcoord (src[0].w = LOD) */
2765 /* src[1] = sampler unit */
2766 exec_tex(mach
, inst
, TRUE
, FALSE
);
2769 case TGSI_OPCODE_TXP
:
2770 /* Texture lookup with projection */
2771 /* src[0] = texcoord (src[0].w = projection) */
2772 /* src[1] = sampler unit */
2773 exec_tex(mach
, inst
, FALSE
, TRUE
);
2776 case TGSI_OPCODE_UP2H
:
2780 case TGSI_OPCODE_UP2US
:
2784 case TGSI_OPCODE_UP4B
:
2788 case TGSI_OPCODE_UP4UB
:
2792 case TGSI_OPCODE_X2D
:
2793 FETCH(&r
[0], 1, CHAN_X
);
2794 FETCH(&r
[1], 1, CHAN_Y
);
2795 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2796 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2797 FETCH(&r
[2], 2, CHAN_X
);
2798 micro_mul(&r
[2], &r
[2], &r
[0]);
2799 FETCH(&r
[3], 2, CHAN_Y
);
2800 micro_mul(&r
[3], &r
[3], &r
[1]);
2801 micro_add(&r
[2], &r
[2], &r
[3]);
2802 FETCH(&r
[3], 0, CHAN_X
);
2803 micro_add(&d
[CHAN_X
], &r
[2], &r
[3]);
2806 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2807 IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2808 FETCH(&r
[2], 2, CHAN_Z
);
2809 micro_mul(&r
[2], &r
[2], &r
[0]);
2810 FETCH(&r
[3], 2, CHAN_W
);
2811 micro_mul(&r
[3], &r
[3], &r
[1]);
2812 micro_add(&r
[2], &r
[2], &r
[3]);
2813 FETCH(&r
[3], 0, CHAN_Y
);
2814 micro_add(&d
[CHAN_Y
], &r
[2], &r
[3]);
2817 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2818 STORE(&d
[CHAN_X
], 0, CHAN_X
);
2820 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2821 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2823 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2824 STORE(&d
[CHAN_X
], 0, CHAN_Z
);
2826 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2827 STORE(&d
[CHAN_Y
], 0, CHAN_W
);
2831 case TGSI_OPCODE_ARA
:
2835 case TGSI_OPCODE_BRA
:
2839 case TGSI_OPCODE_CAL
:
2840 /* skip the call if no execution channels are enabled */
2841 if (mach
->ExecMask
) {
2844 /* First, record the depths of the execution stacks.
2845 * This is important for deeply nested/looped return statements.
2846 * We have to unwind the stacks by the correct amount. For a
2847 * real code generator, we could determine the number of entries
2848 * to pop off each stack with simple static analysis and avoid
2849 * implementing this data structure at run time.
2851 mach
->CallStack
[mach
->CallStackTop
].CondStackTop
= mach
->CondStackTop
;
2852 mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
= mach
->LoopStackTop
;
2853 mach
->CallStack
[mach
->CallStackTop
].ContStackTop
= mach
->ContStackTop
;
2854 /* note that PC was already incremented above */
2855 mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
= *pc
;
2857 mach
->CallStackTop
++;
2859 /* Second, push the Cond, Loop, Cont, Func stacks */
2860 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
2861 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
2862 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2863 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
2864 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2865 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
2866 assert(mach
->FuncStackTop
< TGSI_EXEC_MAX_CALL_NESTING
);
2867 mach
->FuncStack
[mach
->FuncStackTop
++] = mach
->FuncMask
;
2869 /* Finally, jump to the subroutine */
2870 *pc
= inst
->Label
.Label
;
2874 case TGSI_OPCODE_RET
:
2875 mach
->FuncMask
&= ~mach
->ExecMask
;
2876 UPDATE_EXEC_MASK(mach
);
2878 if (mach
->FuncMask
== 0x0) {
2879 /* really return now (otherwise, keep executing */
2881 if (mach
->CallStackTop
== 0) {
2882 /* returning from main() */
2887 assert(mach
->CallStackTop
> 0);
2888 mach
->CallStackTop
--;
2890 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
2891 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
2893 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
2894 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
2896 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
2897 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
2899 assert(mach
->FuncStackTop
> 0);
2900 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
2902 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
2904 UPDATE_EXEC_MASK(mach
);
2908 case TGSI_OPCODE_SSG
:
2909 /* TGSI_OPCODE_SGN */
2910 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2911 FETCH( &r
[0], 0, chan_index
);
2912 micro_sgn(&d
[chan_index
], &r
[0]);
2914 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2915 STORE(&d
[chan_index
], 0, chan_index
);
2919 case TGSI_OPCODE_CMP
:
2920 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2921 FETCH(&r
[0], 0, chan_index
);
2922 FETCH(&r
[1], 1, chan_index
);
2923 FETCH(&r
[2], 2, chan_index
);
2924 micro_lt(&d
[chan_index
], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &r
[1], &r
[2]);
2926 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2927 STORE(&d
[chan_index
], 0, chan_index
);
2931 case TGSI_OPCODE_SCS
:
2932 if( IS_CHANNEL_ENABLED( *inst
, CHAN_X
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) ) {
2933 FETCH( &r
[0], 0, CHAN_X
);
2934 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2935 micro_cos(&r
[1], &r
[0]);
2936 STORE(&r
[1], 0, CHAN_X
);
2938 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2939 micro_sin(&r
[1], &r
[0]);
2940 STORE(&r
[1], 0, CHAN_Y
);
2943 if( IS_CHANNEL_ENABLED( *inst
, CHAN_Z
) ) {
2944 STORE( &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, CHAN_Z
);
2946 if( IS_CHANNEL_ENABLED( *inst
, CHAN_W
) ) {
2947 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2951 case TGSI_OPCODE_NRM
:
2952 /* 3-component vector normalize */
2953 if(IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2954 IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2955 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2956 /* r3 = sqrt(dp3(src0, src0)) */
2957 FETCH(&r
[0], 0, CHAN_X
);
2958 micro_mul(&r
[3], &r
[0], &r
[0]);
2959 FETCH(&r
[1], 0, CHAN_Y
);
2960 micro_mul(&r
[4], &r
[1], &r
[1]);
2961 micro_add(&r
[3], &r
[3], &r
[4]);
2962 FETCH(&r
[2], 0, CHAN_Z
);
2963 micro_mul(&r
[4], &r
[2], &r
[2]);
2964 micro_add(&r
[3], &r
[3], &r
[4]);
2965 micro_sqrt(&r
[3], &r
[3]);
2967 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2968 micro_div(&r
[0], &r
[0], &r
[3]);
2969 STORE(&r
[0], 0, CHAN_X
);
2971 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2972 micro_div(&r
[1], &r
[1], &r
[3]);
2973 STORE(&r
[1], 0, CHAN_Y
);
2975 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2976 micro_div(&r
[2], &r
[2], &r
[3]);
2977 STORE(&r
[2], 0, CHAN_Z
);
2980 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2981 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2985 case TGSI_OPCODE_NRM4
:
2986 /* 4-component vector normalize */
2988 union tgsi_exec_channel tmp
, dot
;
2990 /* tmp = dp4(src0, src0): */
2991 FETCH( &r
[0], 0, CHAN_X
);
2992 micro_mul( &tmp
, &r
[0], &r
[0] );
2994 FETCH( &r
[1], 0, CHAN_Y
);
2995 micro_mul( &dot
, &r
[1], &r
[1] );
2996 micro_add( &tmp
, &tmp
, &dot
);
2998 FETCH( &r
[2], 0, CHAN_Z
);
2999 micro_mul( &dot
, &r
[2], &r
[2] );
3000 micro_add( &tmp
, &tmp
, &dot
);
3002 FETCH( &r
[3], 0, CHAN_W
);
3003 micro_mul( &dot
, &r
[3], &r
[3] );
3004 micro_add( &tmp
, &tmp
, &dot
);
3006 /* tmp = 1 / sqrt(tmp) */
3007 micro_sqrt( &tmp
, &tmp
);
3008 micro_div( &tmp
, &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &tmp
);
3010 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3011 /* chan = chan * tmp */
3012 micro_mul( &r
[chan_index
], &tmp
, &r
[chan_index
] );
3013 STORE( &r
[chan_index
], 0, chan_index
);
3018 case TGSI_OPCODE_DIV
:
3022 case TGSI_OPCODE_DP2
:
3023 FETCH( &r
[0], 0, CHAN_X
);
3024 FETCH( &r
[1], 1, CHAN_X
);
3025 micro_mul( &r
[0], &r
[0], &r
[1] );
3027 FETCH( &r
[1], 0, CHAN_Y
);
3028 FETCH( &r
[2], 1, CHAN_Y
);
3029 micro_mul( &r
[1], &r
[1], &r
[2] );
3030 micro_add( &r
[0], &r
[0], &r
[1] );
3032 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3033 STORE( &r
[0], 0, chan_index
);
3037 case TGSI_OPCODE_IF
:
3039 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
3040 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
3041 FETCH( &r
[0], 0, CHAN_X
);
3042 /* update CondMask */
3044 mach
->CondMask
&= ~0x1;
3047 mach
->CondMask
&= ~0x2;
3050 mach
->CondMask
&= ~0x4;
3053 mach
->CondMask
&= ~0x8;
3055 UPDATE_EXEC_MASK(mach
);
3056 /* Todo: If CondMask==0, jump to ELSE */
3059 case TGSI_OPCODE_ELSE
:
3060 /* invert CondMask wrt previous mask */
3063 assert(mach
->CondStackTop
> 0);
3064 prevMask
= mach
->CondStack
[mach
->CondStackTop
- 1];
3065 mach
->CondMask
= ~mach
->CondMask
& prevMask
;
3066 UPDATE_EXEC_MASK(mach
);
3067 /* Todo: If CondMask==0, jump to ENDIF */
3071 case TGSI_OPCODE_ENDIF
:
3073 assert(mach
->CondStackTop
> 0);
3074 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
3075 UPDATE_EXEC_MASK(mach
);
3078 case TGSI_OPCODE_END
:
3079 /* halt execution */
3083 case TGSI_OPCODE_REP
:
3087 case TGSI_OPCODE_ENDREP
:
3091 case TGSI_OPCODE_PUSHA
:
3095 case TGSI_OPCODE_POPA
:
3099 case TGSI_OPCODE_CEIL
:
3100 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3101 FETCH( &r
[0], 0, chan_index
);
3102 micro_ceil(&d
[chan_index
], &r
[0]);
3104 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3105 STORE(&d
[chan_index
], 0, chan_index
);
3109 case TGSI_OPCODE_I2F
:
3110 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3111 FETCH( &r
[0], 0, chan_index
);
3112 micro_i2f(&d
[chan_index
], &r
[0]);
3114 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3115 STORE(&d
[chan_index
], 0, chan_index
);
3119 case TGSI_OPCODE_NOT
:
3120 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3121 FETCH( &r
[0], 0, chan_index
);
3122 micro_not(&d
[chan_index
], &r
[0]);
3124 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3125 STORE(&d
[chan_index
], 0, chan_index
);
3129 case TGSI_OPCODE_TRUNC
:
3130 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3131 FETCH( &r
[0], 0, chan_index
);
3132 micro_trunc(&d
[chan_index
], &r
[0]);
3134 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3135 STORE(&d
[chan_index
], 0, chan_index
);
3139 case TGSI_OPCODE_SHL
:
3140 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3141 FETCH( &r
[0], 0, chan_index
);
3142 FETCH( &r
[1], 1, chan_index
);
3143 micro_shl(&d
[chan_index
], &r
[0], &r
[1]);
3145 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3146 STORE(&d
[chan_index
], 0, chan_index
);
3150 case TGSI_OPCODE_AND
:
3151 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3152 FETCH( &r
[0], 0, chan_index
);
3153 FETCH( &r
[1], 1, chan_index
);
3154 micro_and(&d
[chan_index
], &r
[0], &r
[1]);
3156 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3157 STORE(&d
[chan_index
], 0, chan_index
);
3161 case TGSI_OPCODE_OR
:
3162 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3163 FETCH( &r
[0], 0, chan_index
);
3164 FETCH( &r
[1], 1, chan_index
);
3165 micro_or(&d
[chan_index
], &r
[0], &r
[1]);
3167 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3168 STORE(&d
[chan_index
], 0, chan_index
);
3172 case TGSI_OPCODE_MOD
:
3176 case TGSI_OPCODE_XOR
:
3177 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3178 FETCH( &r
[0], 0, chan_index
);
3179 FETCH( &r
[1], 1, chan_index
);
3180 micro_xor(&d
[chan_index
], &r
[0], &r
[1]);
3182 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3183 STORE(&d
[chan_index
], 0, chan_index
);
3187 case TGSI_OPCODE_SAD
:
3191 case TGSI_OPCODE_TXF
:
3195 case TGSI_OPCODE_TXQ
:
3199 case TGSI_OPCODE_EMIT
:
3203 case TGSI_OPCODE_ENDPRIM
:
3204 emit_primitive(mach
);
3207 case TGSI_OPCODE_BGNFOR
:
3208 assert(mach
->LoopCounterStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3209 for (chan_index
= 0; chan_index
< 3; chan_index
++) {
3210 FETCH( &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[chan_index
], 0, chan_index
);
3212 ++mach
->LoopCounterStackTop
;
3213 STORE(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
], 0, CHAN_X
);
3214 /* update LoopMask */
3215 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[0] <= 0.0f
) {
3216 mach
->LoopMask
&= ~0x1;
3218 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[1] <= 0.0f
) {
3219 mach
->LoopMask
&= ~0x2;
3221 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[2] <= 0.0f
) {
3222 mach
->LoopMask
&= ~0x4;
3224 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[3] <= 0.0f
) {
3225 mach
->LoopMask
&= ~0x8;
3227 /* TODO: if mach->LoopMask == 0, jump to end of loop */
3228 UPDATE_EXEC_MASK(mach
);
3229 /* fall-through (for now) */
3230 case TGSI_OPCODE_BGNLOOP
:
3231 /* push LoopMask and ContMasks */
3232 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3233 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
3234 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3235 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
3236 assert(mach
->LoopLabelStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3237 mach
->LoopLabelStack
[mach
->LoopLabelStackTop
++] = *pc
- 1;
3240 case TGSI_OPCODE_ENDFOR
:
3241 assert(mach
->LoopCounterStackTop
> 0);
3242 micro_sub(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
],
3243 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
],
3244 &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
]);
3245 /* update LoopMask */
3246 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[0] <= 0.0f
) {
3247 mach
->LoopMask
&= ~0x1;
3249 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[1] <= 0.0f
) {
3250 mach
->LoopMask
&= ~0x2;
3252 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[2] <= 0.0f
) {
3253 mach
->LoopMask
&= ~0x4;
3255 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[3] <= 0.0f
) {
3256 mach
->LoopMask
&= ~0x8;
3258 micro_add(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
],
3259 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
],
3260 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Z
]);
3261 assert(mach
->LoopLabelStackTop
> 0);
3262 inst
= mach
->Instructions
+ mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1];
3263 STORE(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[CHAN_X
], 0, CHAN_X
);
3264 /* Restore ContMask, but don't pop */
3265 assert(mach
->ContStackTop
> 0);
3266 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3267 UPDATE_EXEC_MASK(mach
);
3268 if (mach
->ExecMask
) {
3269 /* repeat loop: jump to instruction just past BGNLOOP */
3270 assert(mach
->LoopLabelStackTop
> 0);
3271 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3274 /* exit loop: pop LoopMask */
3275 assert(mach
->LoopStackTop
> 0);
3276 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3278 assert(mach
->ContStackTop
> 0);
3279 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3280 assert(mach
->LoopLabelStackTop
> 0);
3281 --mach
->LoopLabelStackTop
;
3282 assert(mach
->LoopCounterStackTop
> 0);
3283 --mach
->LoopCounterStackTop
;
3285 UPDATE_EXEC_MASK(mach
);
3288 case TGSI_OPCODE_ENDLOOP
:
3289 /* Restore ContMask, but don't pop */
3290 assert(mach
->ContStackTop
> 0);
3291 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3292 UPDATE_EXEC_MASK(mach
);
3293 if (mach
->ExecMask
) {
3294 /* repeat loop: jump to instruction just past BGNLOOP */
3295 assert(mach
->LoopLabelStackTop
> 0);
3296 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3299 /* exit loop: pop LoopMask */
3300 assert(mach
->LoopStackTop
> 0);
3301 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3303 assert(mach
->ContStackTop
> 0);
3304 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3305 assert(mach
->LoopLabelStackTop
> 0);
3306 --mach
->LoopLabelStackTop
;
3308 UPDATE_EXEC_MASK(mach
);
3311 case TGSI_OPCODE_BRK
:
3312 /* turn off loop channels for each enabled exec channel */
3313 mach
->LoopMask
&= ~mach
->ExecMask
;
3314 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3315 UPDATE_EXEC_MASK(mach
);
3318 case TGSI_OPCODE_CONT
:
3319 /* turn off cont channels for each enabled exec channel */
3320 mach
->ContMask
&= ~mach
->ExecMask
;
3321 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3322 UPDATE_EXEC_MASK(mach
);
3325 case TGSI_OPCODE_BGNSUB
:
3329 case TGSI_OPCODE_ENDSUB
:
3331 * XXX: This really should be a no-op. We should never reach this opcode.
3334 assert(mach
->CallStackTop
> 0);
3335 mach
->CallStackTop
--;
3337 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
3338 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
3340 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
3341 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
3343 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
3344 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
3346 assert(mach
->FuncStackTop
> 0);
3347 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
3349 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
3351 UPDATE_EXEC_MASK(mach
);
3354 case TGSI_OPCODE_NOP
:
3357 case TGSI_OPCODE_BREAKC
:
3358 FETCH(&r
[0], 0, CHAN_X
);
3359 /* update CondMask */
3360 if (r
[0].u
[0] && (mach
->ExecMask
& 0x1)) {
3361 mach
->LoopMask
&= ~0x1;
3363 if (r
[0].u
[1] && (mach
->ExecMask
& 0x2)) {
3364 mach
->LoopMask
&= ~0x2;
3366 if (r
[0].u
[2] && (mach
->ExecMask
& 0x4)) {
3367 mach
->LoopMask
&= ~0x4;
3369 if (r
[0].u
[3] && (mach
->ExecMask
& 0x8)) {
3370 mach
->LoopMask
&= ~0x8;
3372 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3373 UPDATE_EXEC_MASK(mach
);
3376 case TGSI_OPCODE_F2I
:
3377 exec_vector_unary(mach
, inst
, micro_f2i
);
3380 case TGSI_OPCODE_IDIV
:
3381 exec_vector_binary(mach
, inst
, micro_idiv
);
3384 case TGSI_OPCODE_IMAX
:
3385 exec_vector_binary(mach
, inst
, micro_imax
);
3388 case TGSI_OPCODE_IMIN
:
3389 exec_vector_binary(mach
, inst
, micro_imin
);
3392 case TGSI_OPCODE_INEG
:
3393 exec_vector_unary(mach
, inst
, micro_ineg
);
3396 case TGSI_OPCODE_ISGE
:
3397 exec_vector_binary(mach
, inst
, micro_isge
);
3400 case TGSI_OPCODE_ISHR
:
3401 exec_vector_binary(mach
, inst
, micro_ishr
);
3404 case TGSI_OPCODE_ISLT
:
3405 exec_vector_binary(mach
, inst
, micro_islt
);
3408 case TGSI_OPCODE_F2U
:
3409 exec_vector_unary(mach
, inst
, micro_f2u
);
3412 case TGSI_OPCODE_U2F
:
3413 exec_vector_unary(mach
, inst
, micro_u2f
);
3416 case TGSI_OPCODE_UADD
:
3417 exec_vector_binary(mach
, inst
, micro_uadd
);
3420 case TGSI_OPCODE_UDIV
:
3421 exec_vector_binary(mach
, inst
, micro_udiv
);
3424 case TGSI_OPCODE_UMAD
:
3425 exec_vector_trinary(mach
, inst
, micro_umad
);
3428 case TGSI_OPCODE_UMAX
:
3429 exec_vector_binary(mach
, inst
, micro_umax
);
3432 case TGSI_OPCODE_UMIN
:
3433 exec_vector_binary(mach
, inst
, micro_umin
);
3436 case TGSI_OPCODE_UMUL
:
3437 exec_vector_binary(mach
, inst
, micro_umul
);
3440 case TGSI_OPCODE_USEQ
:
3441 exec_vector_binary(mach
, inst
, micro_useq
);
3444 case TGSI_OPCODE_USGE
:
3445 exec_vector_binary(mach
, inst
, micro_usge
);
3448 case TGSI_OPCODE_USHR
:
3449 exec_vector_binary(mach
, inst
, micro_ushr
);
3452 case TGSI_OPCODE_USLT
:
3453 exec_vector_binary(mach
, inst
, micro_uslt
);
3456 case TGSI_OPCODE_USNE
:
3457 exec_vector_binary(mach
, inst
, micro_usne
);
3465 #define DEBUG_EXECUTION 0
3469 * Run TGSI interpreter.
3470 * \return bitmask of "alive" quad components
3473 tgsi_exec_machine_run( struct tgsi_exec_machine
*mach
)
3478 mach
->CondMask
= 0xf;
3479 mach
->LoopMask
= 0xf;
3480 mach
->ContMask
= 0xf;
3481 mach
->FuncMask
= 0xf;
3482 mach
->ExecMask
= 0xf;
3484 assert(mach
->CondStackTop
== 0);
3485 assert(mach
->LoopStackTop
== 0);
3486 assert(mach
->ContStackTop
== 0);
3487 assert(mach
->CallStackTop
== 0);
3489 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] = 0;
3490 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] = 0;
3492 if( mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
3493 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0] = 0;
3494 mach
->Primitives
[0] = 0;
3497 for (i
= 0; i
< QUAD_SIZE
; i
++) {
3498 mach
->Temps
[TEMP_CC_I
].xyzw
[TEMP_CC_C
].u
[i
] =
3499 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_X_SHIFT
) |
3500 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Y_SHIFT
) |
3501 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Z_SHIFT
) |
3502 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_W_SHIFT
);
3505 /* execute declarations (interpolants) */
3506 for (i
= 0; i
< mach
->NumDeclarations
; i
++) {
3507 exec_declaration( mach
, mach
->Declarations
+i
);
3512 struct tgsi_exec_vector temps
[TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
];
3513 struct tgsi_exec_vector outputs
[PIPE_MAX_ATTRIBS
];
3516 memcpy(temps
, mach
->Temps
, sizeof(temps
));
3517 memcpy(outputs
, mach
->Outputs
, sizeof(outputs
));
3520 /* execute instructions, until pc is set to -1 */
3526 tgsi_dump_instruction(&mach
->Instructions
[pc
], inst
++);
3529 assert(pc
< (int) mach
->NumInstructions
);
3530 exec_instruction(mach
, mach
->Instructions
+ pc
, &pc
);
3533 for (i
= 0; i
< TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
; i
++) {
3534 if (memcmp(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]))) {
3537 memcpy(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]));
3538 debug_printf("TEMP[%2u] = ", i
);
3539 for (j
= 0; j
< 4; j
++) {
3543 debug_printf("(%6f, %6f, %6f, %6f)\n",
3544 temps
[i
].xyzw
[0].f
[j
],
3545 temps
[i
].xyzw
[1].f
[j
],
3546 temps
[i
].xyzw
[2].f
[j
],
3547 temps
[i
].xyzw
[3].f
[j
]);
3551 for (i
= 0; i
< PIPE_MAX_ATTRIBS
; i
++) {
3552 if (memcmp(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]))) {
3555 memcpy(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]));
3556 debug_printf("OUT[%2u] = ", i
);
3557 for (j
= 0; j
< 4; j
++) {
3561 debug_printf("{%6f, %6f, %6f, %6f}\n",
3562 outputs
[i
].xyzw
[0].f
[j
],
3563 outputs
[i
].xyzw
[1].f
[j
],
3564 outputs
[i
].xyzw
[2].f
[j
],
3565 outputs
[i
].xyzw
[3].f
[j
]);
3574 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
3575 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
3577 * Scale back depth component.
3579 for (i
= 0; i
< 4; i
++)
3580 mach
->Outputs
[0].xyzw
[2].f
[i
] *= ctx
->DrawBuffer
->_DepthMaxF
;
3584 assert(mach
->CondStackTop
== 0);
3585 assert(mach
->LoopStackTop
== 0);
3586 assert(mach
->ContStackTop
== 0);
3587 assert(mach
->CallStackTop
== 0);
3589 return ~mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];