1 /**************************************************************************
3 * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * Copyright 2009-2010 VMware, Inc. All rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
30 * TGSI interpreter/executor.
32 * Flow control information:
34 * Since we operate on 'quads' (4 pixels or 4 vertices in parallel)
35 * flow control statements (IF/ELSE/ENDIF, LOOP/ENDLOOP) require special
36 * care since a condition may be true for some quad components but false
37 * for other components.
39 * We basically execute all statements (even if they're in the part of
40 * an IF/ELSE clause that's "not taken") and use a special mask to
41 * control writing to destination registers. This is the ExecMask.
44 * The ExecMask is computed from three other masks (CondMask, LoopMask and
45 * ContMask) which are controlled by the flow control instructions (namely:
46 * (IF/ELSE/ENDIF, LOOP/ENDLOOP and CONT).
54 #include "pipe/p_compiler.h"
55 #include "pipe/p_state.h"
56 #include "pipe/p_shader_tokens.h"
57 #include "tgsi/tgsi_dump.h"
58 #include "tgsi/tgsi_parse.h"
59 #include "tgsi/tgsi_util.h"
60 #include "tgsi_exec.h"
61 #include "util/u_memory.h"
62 #include "util/u_math.h"
67 #define TILE_TOP_LEFT 0
68 #define TILE_TOP_RIGHT 1
69 #define TILE_BOTTOM_LEFT 2
70 #define TILE_BOTTOM_RIGHT 3
73 micro_abs(union tgsi_exec_channel
*dst
,
74 const union tgsi_exec_channel
*src
)
76 dst
->f
[0] = fabsf(src
->f
[0]);
77 dst
->f
[1] = fabsf(src
->f
[1]);
78 dst
->f
[2] = fabsf(src
->f
[2]);
79 dst
->f
[3] = fabsf(src
->f
[3]);
83 micro_arl(union tgsi_exec_channel
*dst
,
84 const union tgsi_exec_channel
*src
)
86 dst
->i
[0] = (int)floorf(src
->f
[0]);
87 dst
->i
[1] = (int)floorf(src
->f
[1]);
88 dst
->i
[2] = (int)floorf(src
->f
[2]);
89 dst
->i
[3] = (int)floorf(src
->f
[3]);
93 micro_arr(union tgsi_exec_channel
*dst
,
94 const union tgsi_exec_channel
*src
)
96 dst
->i
[0] = (int)floorf(src
->f
[0] + 0.5f
);
97 dst
->i
[1] = (int)floorf(src
->f
[1] + 0.5f
);
98 dst
->i
[2] = (int)floorf(src
->f
[2] + 0.5f
);
99 dst
->i
[3] = (int)floorf(src
->f
[3] + 0.5f
);
103 micro_ceil(union tgsi_exec_channel
*dst
,
104 const union tgsi_exec_channel
*src
)
106 dst
->f
[0] = ceilf(src
->f
[0]);
107 dst
->f
[1] = ceilf(src
->f
[1]);
108 dst
->f
[2] = ceilf(src
->f
[2]);
109 dst
->f
[3] = ceilf(src
->f
[3]);
113 micro_cos(union tgsi_exec_channel
*dst
,
114 const union tgsi_exec_channel
*src
)
116 dst
->f
[0] = cosf(src
->f
[0]);
117 dst
->f
[1] = cosf(src
->f
[1]);
118 dst
->f
[2] = cosf(src
->f
[2]);
119 dst
->f
[3] = cosf(src
->f
[3]);
123 micro_ddx(union tgsi_exec_channel
*dst
,
124 const union tgsi_exec_channel
*src
)
129 dst
->f
[3] = src
->f
[TILE_BOTTOM_RIGHT
] - src
->f
[TILE_BOTTOM_LEFT
];
133 micro_ddy(union tgsi_exec_channel
*dst
,
134 const union tgsi_exec_channel
*src
)
139 dst
->f
[3] = src
->f
[TILE_BOTTOM_LEFT
] - src
->f
[TILE_TOP_LEFT
];
143 micro_exp2(union tgsi_exec_channel
*dst
,
144 const union tgsi_exec_channel
*src
)
147 dst
->f
[0] = util_fast_exp2(src
->f
[0]);
148 dst
->f
[1] = util_fast_exp2(src
->f
[1]);
149 dst
->f
[2] = util_fast_exp2(src
->f
[2]);
150 dst
->f
[3] = util_fast_exp2(src
->f
[3]);
153 /* Inf is okay for this instruction, so clamp it to silence assertions. */
155 union tgsi_exec_channel clamped
;
157 for (i
= 0; i
< 4; i
++) {
158 if (src
->f
[i
] > 127.99999f
) {
159 clamped
.f
[i
] = 127.99999f
;
160 } else if (src
->f
[i
] < -126.99999f
) {
161 clamped
.f
[i
] = -126.99999f
;
163 clamped
.f
[i
] = src
->f
[i
];
169 dst
->f
[0] = powf(2.0f
, src
->f
[0]);
170 dst
->f
[1] = powf(2.0f
, src
->f
[1]);
171 dst
->f
[2] = powf(2.0f
, src
->f
[2]);
172 dst
->f
[3] = powf(2.0f
, src
->f
[3]);
173 #endif /* FAST_MATH */
177 micro_flr(union tgsi_exec_channel
*dst
,
178 const union tgsi_exec_channel
*src
)
180 dst
->f
[0] = floorf(src
->f
[0]);
181 dst
->f
[1] = floorf(src
->f
[1]);
182 dst
->f
[2] = floorf(src
->f
[2]);
183 dst
->f
[3] = floorf(src
->f
[3]);
187 micro_frc(union tgsi_exec_channel
*dst
,
188 const union tgsi_exec_channel
*src
)
190 dst
->f
[0] = src
->f
[0] - floorf(src
->f
[0]);
191 dst
->f
[1] = src
->f
[1] - floorf(src
->f
[1]);
192 dst
->f
[2] = src
->f
[2] - floorf(src
->f
[2]);
193 dst
->f
[3] = src
->f
[3] - floorf(src
->f
[3]);
197 micro_iabs(union tgsi_exec_channel
*dst
,
198 const union tgsi_exec_channel
*src
)
200 dst
->i
[0] = src
->i
[0] >= 0 ? src
->i
[0] : -src
->i
[0];
201 dst
->i
[1] = src
->i
[1] >= 0 ? src
->i
[1] : -src
->i
[1];
202 dst
->i
[2] = src
->i
[2] >= 0 ? src
->i
[2] : -src
->i
[2];
203 dst
->i
[3] = src
->i
[3] >= 0 ? src
->i
[3] : -src
->i
[3];
207 micro_ineg(union tgsi_exec_channel
*dst
,
208 const union tgsi_exec_channel
*src
)
210 dst
->i
[0] = -src
->i
[0];
211 dst
->i
[1] = -src
->i
[1];
212 dst
->i
[2] = -src
->i
[2];
213 dst
->i
[3] = -src
->i
[3];
217 micro_lg2(union tgsi_exec_channel
*dst
,
218 const union tgsi_exec_channel
*src
)
221 dst
->f
[0] = util_fast_log2(src
->f
[0]);
222 dst
->f
[1] = util_fast_log2(src
->f
[1]);
223 dst
->f
[2] = util_fast_log2(src
->f
[2]);
224 dst
->f
[3] = util_fast_log2(src
->f
[3]);
226 dst
->f
[0] = logf(src
->f
[0]) * 1.442695f
;
227 dst
->f
[1] = logf(src
->f
[1]) * 1.442695f
;
228 dst
->f
[2] = logf(src
->f
[2]) * 1.442695f
;
229 dst
->f
[3] = logf(src
->f
[3]) * 1.442695f
;
234 micro_lrp(union tgsi_exec_channel
*dst
,
235 const union tgsi_exec_channel
*src0
,
236 const union tgsi_exec_channel
*src1
,
237 const union tgsi_exec_channel
*src2
)
239 dst
->f
[0] = src0
->f
[0] * (src1
->f
[0] - src2
->f
[0]) + src2
->f
[0];
240 dst
->f
[1] = src0
->f
[1] * (src1
->f
[1] - src2
->f
[1]) + src2
->f
[1];
241 dst
->f
[2] = src0
->f
[2] * (src1
->f
[2] - src2
->f
[2]) + src2
->f
[2];
242 dst
->f
[3] = src0
->f
[3] * (src1
->f
[3] - src2
->f
[3]) + src2
->f
[3];
246 micro_mad(union tgsi_exec_channel
*dst
,
247 const union tgsi_exec_channel
*src0
,
248 const union tgsi_exec_channel
*src1
,
249 const union tgsi_exec_channel
*src2
)
251 dst
->f
[0] = src0
->f
[0] * src1
->f
[0] + src2
->f
[0];
252 dst
->f
[1] = src0
->f
[1] * src1
->f
[1] + src2
->f
[1];
253 dst
->f
[2] = src0
->f
[2] * src1
->f
[2] + src2
->f
[2];
254 dst
->f
[3] = src0
->f
[3] * src1
->f
[3] + src2
->f
[3];
258 micro_mov(union tgsi_exec_channel
*dst
,
259 const union tgsi_exec_channel
*src
)
261 dst
->u
[0] = src
->u
[0];
262 dst
->u
[1] = src
->u
[1];
263 dst
->u
[2] = src
->u
[2];
264 dst
->u
[3] = src
->u
[3];
268 micro_rcp(union tgsi_exec_channel
*dst
,
269 const union tgsi_exec_channel
*src
)
271 #if 0 /* for debugging */
272 assert(src
->f
[0] != 0.0f
);
273 assert(src
->f
[1] != 0.0f
);
274 assert(src
->f
[2] != 0.0f
);
275 assert(src
->f
[3] != 0.0f
);
277 dst
->f
[0] = 1.0f
/ src
->f
[0];
278 dst
->f
[1] = 1.0f
/ src
->f
[1];
279 dst
->f
[2] = 1.0f
/ src
->f
[2];
280 dst
->f
[3] = 1.0f
/ src
->f
[3];
284 micro_rnd(union tgsi_exec_channel
*dst
,
285 const union tgsi_exec_channel
*src
)
287 dst
->f
[0] = floorf(src
->f
[0] + 0.5f
);
288 dst
->f
[1] = floorf(src
->f
[1] + 0.5f
);
289 dst
->f
[2] = floorf(src
->f
[2] + 0.5f
);
290 dst
->f
[3] = floorf(src
->f
[3] + 0.5f
);
294 micro_rsq(union tgsi_exec_channel
*dst
,
295 const union tgsi_exec_channel
*src
)
297 #if 0 /* for debugging */
298 assert(src
->f
[0] != 0.0f
);
299 assert(src
->f
[1] != 0.0f
);
300 assert(src
->f
[2] != 0.0f
);
301 assert(src
->f
[3] != 0.0f
);
303 dst
->f
[0] = 1.0f
/ sqrtf(fabsf(src
->f
[0]));
304 dst
->f
[1] = 1.0f
/ sqrtf(fabsf(src
->f
[1]));
305 dst
->f
[2] = 1.0f
/ sqrtf(fabsf(src
->f
[2]));
306 dst
->f
[3] = 1.0f
/ sqrtf(fabsf(src
->f
[3]));
310 micro_seq(union tgsi_exec_channel
*dst
,
311 const union tgsi_exec_channel
*src0
,
312 const union tgsi_exec_channel
*src1
)
314 dst
->f
[0] = src0
->f
[0] == src1
->f
[0] ? 1.0f
: 0.0f
;
315 dst
->f
[1] = src0
->f
[1] == src1
->f
[1] ? 1.0f
: 0.0f
;
316 dst
->f
[2] = src0
->f
[2] == src1
->f
[2] ? 1.0f
: 0.0f
;
317 dst
->f
[3] = src0
->f
[3] == src1
->f
[3] ? 1.0f
: 0.0f
;
321 micro_sge(union tgsi_exec_channel
*dst
,
322 const union tgsi_exec_channel
*src0
,
323 const union tgsi_exec_channel
*src1
)
325 dst
->f
[0] = src0
->f
[0] >= src1
->f
[0] ? 1.0f
: 0.0f
;
326 dst
->f
[1] = src0
->f
[1] >= src1
->f
[1] ? 1.0f
: 0.0f
;
327 dst
->f
[2] = src0
->f
[2] >= src1
->f
[2] ? 1.0f
: 0.0f
;
328 dst
->f
[3] = src0
->f
[3] >= src1
->f
[3] ? 1.0f
: 0.0f
;
332 micro_sgn(union tgsi_exec_channel
*dst
,
333 const union tgsi_exec_channel
*src
)
335 dst
->f
[0] = src
->f
[0] < 0.0f
? -1.0f
: src
->f
[0] > 0.0f
? 1.0f
: 0.0f
;
336 dst
->f
[1] = src
->f
[1] < 0.0f
? -1.0f
: src
->f
[1] > 0.0f
? 1.0f
: 0.0f
;
337 dst
->f
[2] = src
->f
[2] < 0.0f
? -1.0f
: src
->f
[2] > 0.0f
? 1.0f
: 0.0f
;
338 dst
->f
[3] = src
->f
[3] < 0.0f
? -1.0f
: src
->f
[3] > 0.0f
? 1.0f
: 0.0f
;
342 micro_sgt(union tgsi_exec_channel
*dst
,
343 const union tgsi_exec_channel
*src0
,
344 const union tgsi_exec_channel
*src1
)
346 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? 1.0f
: 0.0f
;
347 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? 1.0f
: 0.0f
;
348 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? 1.0f
: 0.0f
;
349 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? 1.0f
: 0.0f
;
353 micro_sin(union tgsi_exec_channel
*dst
,
354 const union tgsi_exec_channel
*src
)
356 dst
->f
[0] = sinf(src
->f
[0]);
357 dst
->f
[1] = sinf(src
->f
[1]);
358 dst
->f
[2] = sinf(src
->f
[2]);
359 dst
->f
[3] = sinf(src
->f
[3]);
363 micro_sle(union tgsi_exec_channel
*dst
,
364 const union tgsi_exec_channel
*src0
,
365 const union tgsi_exec_channel
*src1
)
367 dst
->f
[0] = src0
->f
[0] <= src1
->f
[0] ? 1.0f
: 0.0f
;
368 dst
->f
[1] = src0
->f
[1] <= src1
->f
[1] ? 1.0f
: 0.0f
;
369 dst
->f
[2] = src0
->f
[2] <= src1
->f
[2] ? 1.0f
: 0.0f
;
370 dst
->f
[3] = src0
->f
[3] <= src1
->f
[3] ? 1.0f
: 0.0f
;
374 micro_slt(union tgsi_exec_channel
*dst
,
375 const union tgsi_exec_channel
*src0
,
376 const union tgsi_exec_channel
*src1
)
378 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? 1.0f
: 0.0f
;
379 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? 1.0f
: 0.0f
;
380 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? 1.0f
: 0.0f
;
381 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? 1.0f
: 0.0f
;
385 micro_sne(union tgsi_exec_channel
*dst
,
386 const union tgsi_exec_channel
*src0
,
387 const union tgsi_exec_channel
*src1
)
389 dst
->f
[0] = src0
->f
[0] != src1
->f
[0] ? 1.0f
: 0.0f
;
390 dst
->f
[1] = src0
->f
[1] != src1
->f
[1] ? 1.0f
: 0.0f
;
391 dst
->f
[2] = src0
->f
[2] != src1
->f
[2] ? 1.0f
: 0.0f
;
392 dst
->f
[3] = src0
->f
[3] != src1
->f
[3] ? 1.0f
: 0.0f
;
396 micro_trunc(union tgsi_exec_channel
*dst
,
397 const union tgsi_exec_channel
*src
)
399 dst
->f
[0] = (float)(int)src
->f
[0];
400 dst
->f
[1] = (float)(int)src
->f
[1];
401 dst
->f
[2] = (float)(int)src
->f
[2];
402 dst
->f
[3] = (float)(int)src
->f
[3];
411 enum tgsi_exec_datatype
{
412 TGSI_EXEC_DATA_FLOAT
,
418 * Shorthand locations of various utility registers (_I = Index, _C = Channel)
420 #define TEMP_0_I TGSI_EXEC_TEMP_00000000_I
421 #define TEMP_0_C TGSI_EXEC_TEMP_00000000_C
422 #define TEMP_7F_I TGSI_EXEC_TEMP_7FFFFFFF_I
423 #define TEMP_7F_C TGSI_EXEC_TEMP_7FFFFFFF_C
424 #define TEMP_80_I TGSI_EXEC_TEMP_80000000_I
425 #define TEMP_80_C TGSI_EXEC_TEMP_80000000_C
426 #define TEMP_FF_I TGSI_EXEC_TEMP_FFFFFFFF_I
427 #define TEMP_FF_C TGSI_EXEC_TEMP_FFFFFFFF_C
428 #define TEMP_1_I TGSI_EXEC_TEMP_ONE_I
429 #define TEMP_1_C TGSI_EXEC_TEMP_ONE_C
430 #define TEMP_2_I TGSI_EXEC_TEMP_TWO_I
431 #define TEMP_2_C TGSI_EXEC_TEMP_TWO_C
432 #define TEMP_128_I TGSI_EXEC_TEMP_128_I
433 #define TEMP_128_C TGSI_EXEC_TEMP_128_C
434 #define TEMP_M128_I TGSI_EXEC_TEMP_MINUS_128_I
435 #define TEMP_M128_C TGSI_EXEC_TEMP_MINUS_128_C
436 #define TEMP_KILMASK_I TGSI_EXEC_TEMP_KILMASK_I
437 #define TEMP_KILMASK_C TGSI_EXEC_TEMP_KILMASK_C
438 #define TEMP_OUTPUT_I TGSI_EXEC_TEMP_OUTPUT_I
439 #define TEMP_OUTPUT_C TGSI_EXEC_TEMP_OUTPUT_C
440 #define TEMP_PRIMITIVE_I TGSI_EXEC_TEMP_PRIMITIVE_I
441 #define TEMP_PRIMITIVE_C TGSI_EXEC_TEMP_PRIMITIVE_C
442 #define TEMP_CC_I TGSI_EXEC_TEMP_CC_I
443 #define TEMP_CC_C TGSI_EXEC_TEMP_CC_C
444 #define TEMP_3_I TGSI_EXEC_TEMP_THREE_I
445 #define TEMP_3_C TGSI_EXEC_TEMP_THREE_C
446 #define TEMP_HALF_I TGSI_EXEC_TEMP_HALF_I
447 #define TEMP_HALF_C TGSI_EXEC_TEMP_HALF_C
448 #define TEMP_R0 TGSI_EXEC_TEMP_R0
449 #define TEMP_P0 TGSI_EXEC_TEMP_P0
451 #define IS_CHANNEL_ENABLED(INST, CHAN)\
452 ((INST).Dst[0].Register.WriteMask & (1 << (CHAN)))
454 #define IS_CHANNEL_ENABLED2(INST, CHAN)\
455 ((INST).Dst[1].Register.WriteMask & (1 << (CHAN)))
457 #define FOR_EACH_ENABLED_CHANNEL(INST, CHAN)\
458 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)\
459 if (IS_CHANNEL_ENABLED( INST, CHAN ))
461 #define FOR_EACH_ENABLED_CHANNEL2(INST, CHAN)\
462 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)\
463 if (IS_CHANNEL_ENABLED2( INST, CHAN ))
466 /** The execution mask depends on the conditional mask and the loop mask */
467 #define UPDATE_EXEC_MASK(MACH) \
468 MACH->ExecMask = MACH->CondMask & MACH->LoopMask & MACH->ContMask & MACH->Switch.mask & MACH->FuncMask
471 static const union tgsi_exec_channel ZeroVec
=
472 { { 0.0, 0.0, 0.0, 0.0 } };
474 static const union tgsi_exec_channel OneVec
= {
475 {1.0f
, 1.0f
, 1.0f
, 1.0f
}
480 * Assert that none of the float values in 'chan' are infinite or NaN.
481 * NaN and Inf may occur normally during program execution and should
482 * not lead to crashes, etc. But when debugging, it's helpful to catch
486 check_inf_or_nan(const union tgsi_exec_channel
*chan
)
488 assert(!util_is_inf_or_nan((chan
)->f
[0]));
489 assert(!util_is_inf_or_nan((chan
)->f
[1]));
490 assert(!util_is_inf_or_nan((chan
)->f
[2]));
491 assert(!util_is_inf_or_nan((chan
)->f
[3]));
497 print_chan(const char *msg
, const union tgsi_exec_channel
*chan
)
499 debug_printf("%s = {%f, %f, %f, %f}\n",
500 msg
, chan
->f
[0], chan
->f
[1], chan
->f
[2], chan
->f
[3]);
507 print_temp(const struct tgsi_exec_machine
*mach
, uint index
)
509 const struct tgsi_exec_vector
*tmp
= &mach
->Temps
[index
];
511 debug_printf("Temp[%u] =\n", index
);
512 for (i
= 0; i
< 4; i
++) {
513 debug_printf(" %c: { %f, %f, %f, %f }\n",
525 * Check if there's a potential src/dst register data dependency when
526 * using SOA execution.
529 * This would expand into:
534 * The second instruction will have the wrong value for t0 if executed as-is.
537 tgsi_check_soa_dependencies(const struct tgsi_full_instruction
*inst
)
541 uint writemask
= inst
->Dst
[0].Register
.WriteMask
;
542 if (writemask
== TGSI_WRITEMASK_X
||
543 writemask
== TGSI_WRITEMASK_Y
||
544 writemask
== TGSI_WRITEMASK_Z
||
545 writemask
== TGSI_WRITEMASK_W
||
546 writemask
== TGSI_WRITEMASK_NONE
) {
547 /* no chance of data dependency */
551 /* loop over src regs */
552 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
553 if ((inst
->Src
[i
].Register
.File
==
554 inst
->Dst
[0].Register
.File
) &&
555 (inst
->Src
[i
].Register
.Index
==
556 inst
->Dst
[0].Register
.Index
)) {
557 /* loop over dest channels */
558 uint channelsWritten
= 0x0;
559 FOR_EACH_ENABLED_CHANNEL(*inst
, chan
) {
560 /* check if we're reading a channel that's been written */
561 uint swizzle
= tgsi_util_get_full_src_register_swizzle(&inst
->Src
[i
], chan
);
562 if (channelsWritten
& (1 << swizzle
)) {
566 channelsWritten
|= (1 << chan
);
575 * Initialize machine state by expanding tokens to full instructions,
576 * allocating temporary storage, setting up constants, etc.
577 * After this, we can call tgsi_exec_machine_run() many times.
580 tgsi_exec_machine_bind_shader(
581 struct tgsi_exec_machine
*mach
,
582 const struct tgsi_token
*tokens
,
584 struct tgsi_sampler
**samplers
)
587 struct tgsi_parse_context parse
;
588 struct tgsi_exec_labels
*labels
= &mach
->Labels
;
589 struct tgsi_full_instruction
*instructions
;
590 struct tgsi_full_declaration
*declarations
;
591 uint maxInstructions
= 10, numInstructions
= 0;
592 uint maxDeclarations
= 10, numDeclarations
= 0;
596 tgsi_dump(tokens
, 0);
601 mach
->Tokens
= tokens
;
602 mach
->Samplers
= samplers
;
604 k
= tgsi_parse_init (&parse
, mach
->Tokens
);
605 if (k
!= TGSI_PARSE_OK
) {
606 debug_printf( "Problem parsing!\n" );
610 mach
->Processor
= parse
.FullHeader
.Processor
.Processor
;
614 declarations
= (struct tgsi_full_declaration
*)
615 MALLOC( maxDeclarations
* sizeof(struct tgsi_full_declaration
) );
621 instructions
= (struct tgsi_full_instruction
*)
622 MALLOC( maxInstructions
* sizeof(struct tgsi_full_instruction
) );
625 FREE( declarations
);
629 while( !tgsi_parse_end_of_tokens( &parse
) ) {
630 uint pointer
= parse
.Position
;
633 tgsi_parse_token( &parse
);
634 switch( parse
.FullToken
.Token
.Type
) {
635 case TGSI_TOKEN_TYPE_DECLARATION
:
636 /* save expanded declaration */
637 if (numDeclarations
== maxDeclarations
) {
638 declarations
= REALLOC(declarations
,
640 * sizeof(struct tgsi_full_declaration
),
641 (maxDeclarations
+ 10)
642 * sizeof(struct tgsi_full_declaration
));
643 maxDeclarations
+= 10;
645 if (parse
.FullToken
.FullDeclaration
.Declaration
.File
== TGSI_FILE_OUTPUT
) {
647 for (reg
= parse
.FullToken
.FullDeclaration
.Range
.First
;
648 reg
<= parse
.FullToken
.FullDeclaration
.Range
.Last
;
653 memcpy(declarations
+ numDeclarations
,
654 &parse
.FullToken
.FullDeclaration
,
655 sizeof(declarations
[0]));
659 case TGSI_TOKEN_TYPE_IMMEDIATE
:
661 uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
663 assert( mach
->ImmLimit
+ 1 <= TGSI_EXEC_NUM_IMMEDIATES
);
665 for( i
= 0; i
< size
; i
++ ) {
666 mach
->Imms
[mach
->ImmLimit
][i
] =
667 parse
.FullToken
.FullImmediate
.u
[i
].Float
;
673 case TGSI_TOKEN_TYPE_INSTRUCTION
:
674 assert( labels
->count
< MAX_LABELS
);
676 labels
->labels
[labels
->count
][0] = instno
;
677 labels
->labels
[labels
->count
][1] = pointer
;
680 /* save expanded instruction */
681 if (numInstructions
== maxInstructions
) {
682 instructions
= REALLOC(instructions
,
684 * sizeof(struct tgsi_full_instruction
),
685 (maxInstructions
+ 10)
686 * sizeof(struct tgsi_full_instruction
));
687 maxInstructions
+= 10;
690 memcpy(instructions
+ numInstructions
,
691 &parse
.FullToken
.FullInstruction
,
692 sizeof(instructions
[0]));
697 case TGSI_TOKEN_TYPE_PROPERTY
:
704 tgsi_parse_free (&parse
);
706 if (mach
->Declarations
) {
707 FREE( mach
->Declarations
);
709 mach
->Declarations
= declarations
;
710 mach
->NumDeclarations
= numDeclarations
;
712 if (mach
->Instructions
) {
713 FREE( mach
->Instructions
);
715 mach
->Instructions
= instructions
;
716 mach
->NumInstructions
= numInstructions
;
720 struct tgsi_exec_machine
*
721 tgsi_exec_machine_create( void )
723 struct tgsi_exec_machine
*mach
;
726 mach
= align_malloc( sizeof *mach
, 16 );
730 memset(mach
, 0, sizeof(*mach
));
732 mach
->Addrs
= &mach
->Temps
[TGSI_EXEC_TEMP_ADDR
];
733 mach
->MaxGeometryShaderOutputs
= TGSI_MAX_TOTAL_VERTICES
;
734 mach
->Predicates
= &mach
->Temps
[TGSI_EXEC_TEMP_P0
];
736 /* Setup constants. */
737 for( i
= 0; i
< 4; i
++ ) {
738 mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
].u
[i
] = 0x00000000;
739 mach
->Temps
[TEMP_7F_I
].xyzw
[TEMP_7F_C
].u
[i
] = 0x7FFFFFFF;
740 mach
->Temps
[TEMP_80_I
].xyzw
[TEMP_80_C
].u
[i
] = 0x80000000;
741 mach
->Temps
[TEMP_FF_I
].xyzw
[TEMP_FF_C
].u
[i
] = 0xFFFFFFFF;
742 mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
].f
[i
] = 1.0f
;
743 mach
->Temps
[TEMP_2_I
].xyzw
[TEMP_2_C
].f
[i
] = 2.0f
;
744 mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
].f
[i
] = 128.0f
;
745 mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
].f
[i
] = -128.0f
;
746 mach
->Temps
[TEMP_3_I
].xyzw
[TEMP_3_C
].f
[i
] = 3.0f
;
747 mach
->Temps
[TEMP_HALF_I
].xyzw
[TEMP_HALF_C
].f
[i
] = 0.5f
;
751 /* silence warnings */
765 tgsi_exec_machine_destroy(struct tgsi_exec_machine
*mach
)
768 FREE(mach
->Instructions
);
769 FREE(mach
->Declarations
);
776 micro_add(union tgsi_exec_channel
*dst
,
777 const union tgsi_exec_channel
*src0
,
778 const union tgsi_exec_channel
*src1
)
780 dst
->f
[0] = src0
->f
[0] + src1
->f
[0];
781 dst
->f
[1] = src0
->f
[1] + src1
->f
[1];
782 dst
->f
[2] = src0
->f
[2] + src1
->f
[2];
783 dst
->f
[3] = src0
->f
[3] + src1
->f
[3];
788 union tgsi_exec_channel
*dst
,
789 const union tgsi_exec_channel
*src0
,
790 const union tgsi_exec_channel
*src1
)
792 if (src1
->f
[0] != 0) {
793 dst
->f
[0] = src0
->f
[0] / src1
->f
[0];
795 if (src1
->f
[1] != 0) {
796 dst
->f
[1] = src0
->f
[1] / src1
->f
[1];
798 if (src1
->f
[2] != 0) {
799 dst
->f
[2] = src0
->f
[2] / src1
->f
[2];
801 if (src1
->f
[3] != 0) {
802 dst
->f
[3] = src0
->f
[3] / src1
->f
[3];
807 micro_float_clamp(union tgsi_exec_channel
*dst
,
808 const union tgsi_exec_channel
*src
)
812 for (i
= 0; i
< 4; i
++) {
813 if (src
->f
[i
] > 0.0f
) {
814 if (src
->f
[i
] > 1.884467e+019f
)
815 dst
->f
[i
] = 1.884467e+019f
;
816 else if (src
->f
[i
] < 5.42101e-020f
)
817 dst
->f
[i
] = 5.42101e-020f
;
819 dst
->f
[i
] = src
->f
[i
];
822 if (src
->f
[i
] < -1.884467e+019f
)
823 dst
->f
[i
] = -1.884467e+019f
;
824 else if (src
->f
[i
] > -5.42101e-020f
)
825 dst
->f
[i
] = -5.42101e-020f
;
827 dst
->f
[i
] = src
->f
[i
];
834 union tgsi_exec_channel
*dst
,
835 const union tgsi_exec_channel
*src0
,
836 const union tgsi_exec_channel
*src1
,
837 const union tgsi_exec_channel
*src2
,
838 const union tgsi_exec_channel
*src3
)
840 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
841 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
842 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
843 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
847 micro_max(union tgsi_exec_channel
*dst
,
848 const union tgsi_exec_channel
*src0
,
849 const union tgsi_exec_channel
*src1
)
851 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
852 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
853 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
854 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
858 micro_min(union tgsi_exec_channel
*dst
,
859 const union tgsi_exec_channel
*src0
,
860 const union tgsi_exec_channel
*src1
)
862 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
863 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
864 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
865 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
869 micro_mul(union tgsi_exec_channel
*dst
,
870 const union tgsi_exec_channel
*src0
,
871 const union tgsi_exec_channel
*src1
)
873 dst
->f
[0] = src0
->f
[0] * src1
->f
[0];
874 dst
->f
[1] = src0
->f
[1] * src1
->f
[1];
875 dst
->f
[2] = src0
->f
[2] * src1
->f
[2];
876 dst
->f
[3] = src0
->f
[3] * src1
->f
[3];
882 union tgsi_exec_channel
*dst0
,
883 union tgsi_exec_channel
*dst1
,
884 const union tgsi_exec_channel
*src0
,
885 const union tgsi_exec_channel
*src1
)
887 dst1
->i
[0] = src0
->i
[0] * src1
->i
[0];
888 dst1
->i
[1] = src0
->i
[1] * src1
->i
[1];
889 dst1
->i
[2] = src0
->i
[2] * src1
->i
[2];
890 dst1
->i
[3] = src0
->i
[3] * src1
->i
[3];
901 union tgsi_exec_channel
*dst0
,
902 union tgsi_exec_channel
*dst1
,
903 const union tgsi_exec_channel
*src0
,
904 const union tgsi_exec_channel
*src1
)
906 dst1
->u
[0] = src0
->u
[0] * src1
->u
[0];
907 dst1
->u
[1] = src0
->u
[1] * src1
->u
[1];
908 dst1
->u
[2] = src0
->u
[2] * src1
->u
[2];
909 dst1
->u
[3] = src0
->u
[3] * src1
->u
[3];
921 union tgsi_exec_channel
*dst
,
922 const union tgsi_exec_channel
*src0
,
923 const union tgsi_exec_channel
*src1
,
924 const union tgsi_exec_channel
*src2
)
926 dst
->u
[0] = src0
->u
[0] ? src1
->u
[0] : src2
->u
[0];
927 dst
->u
[1] = src0
->u
[1] ? src1
->u
[1] : src2
->u
[1];
928 dst
->u
[2] = src0
->u
[2] ? src1
->u
[2] : src2
->u
[2];
929 dst
->u
[3] = src0
->u
[3] ? src1
->u
[3] : src2
->u
[3];
935 union tgsi_exec_channel
*dst
,
936 const union tgsi_exec_channel
*src
)
938 dst
->f
[0] = -src
->f
[0];
939 dst
->f
[1] = -src
->f
[1];
940 dst
->f
[2] = -src
->f
[2];
941 dst
->f
[3] = -src
->f
[3];
946 union tgsi_exec_channel
*dst
,
947 const union tgsi_exec_channel
*src0
,
948 const union tgsi_exec_channel
*src1
)
951 dst
->f
[0] = util_fast_pow( src0
->f
[0], src1
->f
[0] );
952 dst
->f
[1] = util_fast_pow( src0
->f
[1], src1
->f
[1] );
953 dst
->f
[2] = util_fast_pow( src0
->f
[2], src1
->f
[2] );
954 dst
->f
[3] = util_fast_pow( src0
->f
[3], src1
->f
[3] );
956 dst
->f
[0] = powf( src0
->f
[0], src1
->f
[0] );
957 dst
->f
[1] = powf( src0
->f
[1], src1
->f
[1] );
958 dst
->f
[2] = powf( src0
->f
[2], src1
->f
[2] );
959 dst
->f
[3] = powf( src0
->f
[3], src1
->f
[3] );
964 micro_sub(union tgsi_exec_channel
*dst
,
965 const union tgsi_exec_channel
*src0
,
966 const union tgsi_exec_channel
*src1
)
968 dst
->f
[0] = src0
->f
[0] - src1
->f
[0];
969 dst
->f
[1] = src0
->f
[1] - src1
->f
[1];
970 dst
->f
[2] = src0
->f
[2] - src1
->f
[2];
971 dst
->f
[3] = src0
->f
[3] - src1
->f
[3];
975 fetch_src_file_channel(const struct tgsi_exec_machine
*mach
,
978 const union tgsi_exec_channel
*index
,
979 const union tgsi_exec_channel
*index2D
,
980 union tgsi_exec_channel
*chan
)
985 case TGSI_FILE_CONSTANT
:
986 for (i
= 0; i
< QUAD_SIZE
; i
++) {
987 assert(index2D
->i
[i
] >= 0 && index2D
->i
[i
] < PIPE_MAX_CONSTANT_BUFFERS
);
988 assert(mach
->Consts
[index2D
->i
[i
]]);
990 if (index
->i
[i
] < 0) {
993 const uint
*p
= (const uint
*)mach
->Consts
[index2D
->i
[i
]];
995 chan
->u
[i
] = p
[index
->i
[i
] * 4 + swizzle
];
1000 case TGSI_FILE_INPUT
:
1001 case TGSI_FILE_SYSTEM_VALUE
:
1002 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1003 /* XXX: 2D indexing */
1004 chan
->u
[i
] = mach
->Inputs
[index2D
->i
[i
] * TGSI_EXEC_MAX_INPUT_ATTRIBS
+ index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1008 case TGSI_FILE_TEMPORARY
:
1009 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1010 assert(index
->i
[i
] < TGSI_EXEC_NUM_TEMPS
);
1011 assert(index2D
->i
[i
] == 0);
1013 chan
->u
[i
] = mach
->Temps
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1017 case TGSI_FILE_IMMEDIATE
:
1018 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1019 assert(index
->i
[i
] >= 0 && index
->i
[i
] < (int)mach
->ImmLimit
);
1020 assert(index2D
->i
[i
] == 0);
1022 chan
->f
[i
] = mach
->Imms
[index
->i
[i
]][swizzle
];
1026 case TGSI_FILE_ADDRESS
:
1027 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1028 assert(index
->i
[i
] >= 0);
1029 assert(index2D
->i
[i
] == 0);
1031 chan
->u
[i
] = mach
->Addrs
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1035 case TGSI_FILE_PREDICATE
:
1036 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1037 assert(index
->i
[i
] >= 0 && index
->i
[i
] < TGSI_EXEC_NUM_PREDS
);
1038 assert(index2D
->i
[i
] == 0);
1040 chan
->u
[i
] = mach
->Predicates
[0].xyzw
[swizzle
].u
[i
];
1044 case TGSI_FILE_OUTPUT
:
1045 /* vertex/fragment output vars can be read too */
1046 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1047 assert(index
->i
[i
] >= 0);
1048 assert(index2D
->i
[i
] == 0);
1050 chan
->u
[i
] = mach
->Outputs
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1056 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1063 fetch_source(const struct tgsi_exec_machine
*mach
,
1064 union tgsi_exec_channel
*chan
,
1065 const struct tgsi_full_src_register
*reg
,
1066 const uint chan_index
,
1067 enum tgsi_exec_datatype src_datatype
)
1069 union tgsi_exec_channel index
;
1070 union tgsi_exec_channel index2D
;
1073 /* We start with a direct index into a register file.
1077 * file = Register.File
1078 * [1] = Register.Index
1083 index
.i
[3] = reg
->Register
.Index
;
1085 /* There is an extra source register that indirectly subscripts
1086 * a register file. The direct index now becomes an offset
1087 * that is being added to the indirect register.
1091 * ind = Indirect.File
1092 * [2] = Indirect.Index
1093 * .x = Indirect.SwizzleX
1095 if (reg
->Register
.Indirect
) {
1096 union tgsi_exec_channel index2
;
1097 union tgsi_exec_channel indir_index
;
1098 const uint execmask
= mach
->ExecMask
;
1101 /* which address register (always zero now) */
1105 index2
.i
[3] = reg
->Indirect
.Index
;
1107 /* get current value of address register[swizzle] */
1108 swizzle
= tgsi_util_get_src_register_swizzle( ®
->Indirect
, CHAN_X
);
1109 fetch_src_file_channel(mach
,
1116 /* add value of address register to the offset */
1117 index
.i
[0] += indir_index
.i
[0];
1118 index
.i
[1] += indir_index
.i
[1];
1119 index
.i
[2] += indir_index
.i
[2];
1120 index
.i
[3] += indir_index
.i
[3];
1122 /* for disabled execution channels, zero-out the index to
1123 * avoid using a potential garbage value.
1125 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1126 if ((execmask
& (1 << i
)) == 0)
1131 /* There is an extra source register that is a second
1132 * subscript to a register file. Effectively it means that
1133 * the register file is actually a 2D array of registers.
1137 * [3] = Dimension.Index
1139 if (reg
->Register
.Dimension
) {
1143 index2D
.i
[3] = reg
->Dimension
.Index
;
1145 /* Again, the second subscript index can be addressed indirectly
1146 * identically to the first one.
1147 * Nothing stops us from indirectly addressing the indirect register,
1148 * but there is no need for that, so we won't exercise it.
1150 * file[ind[4].y+3][1],
1152 * ind = DimIndirect.File
1153 * [4] = DimIndirect.Index
1154 * .y = DimIndirect.SwizzleX
1156 if (reg
->Dimension
.Indirect
) {
1157 union tgsi_exec_channel index2
;
1158 union tgsi_exec_channel indir_index
;
1159 const uint execmask
= mach
->ExecMask
;
1165 index2
.i
[3] = reg
->DimIndirect
.Index
;
1167 swizzle
= tgsi_util_get_src_register_swizzle( ®
->DimIndirect
, CHAN_X
);
1168 fetch_src_file_channel(mach
,
1169 reg
->DimIndirect
.File
,
1175 index2D
.i
[0] += indir_index
.i
[0];
1176 index2D
.i
[1] += indir_index
.i
[1];
1177 index2D
.i
[2] += indir_index
.i
[2];
1178 index2D
.i
[3] += indir_index
.i
[3];
1180 /* for disabled execution channels, zero-out the index to
1181 * avoid using a potential garbage value.
1183 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1184 if ((execmask
& (1 << i
)) == 0) {
1190 /* If by any chance there was a need for a 3D array of register
1191 * files, we would have to check whether Dimension is followed
1192 * by a dimension register and continue the saga.
1201 swizzle
= tgsi_util_get_full_src_register_swizzle( reg
, chan_index
);
1202 fetch_src_file_channel(mach
,
1209 if (reg
->Register
.Absolute
) {
1210 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1211 micro_abs(chan
, chan
);
1213 micro_iabs(chan
, chan
);
1217 if (reg
->Register
.Negate
) {
1218 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1219 micro_neg(chan
, chan
);
1221 micro_ineg(chan
, chan
);
1227 store_dest(struct tgsi_exec_machine
*mach
,
1228 const union tgsi_exec_channel
*chan
,
1229 const struct tgsi_full_dst_register
*reg
,
1230 const struct tgsi_full_instruction
*inst
,
1232 enum tgsi_exec_datatype dst_datatype
)
1235 union tgsi_exec_channel null
;
1236 union tgsi_exec_channel
*dst
;
1237 uint execmask
= mach
->ExecMask
;
1238 int offset
= 0; /* indirection offset */
1242 if (0 && dst_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1243 check_inf_or_nan(chan
);
1246 /* There is an extra source register that indirectly subscripts
1247 * a register file. The direct index now becomes an offset
1248 * that is being added to the indirect register.
1252 * ind = Indirect.File
1253 * [2] = Indirect.Index
1254 * .x = Indirect.SwizzleX
1256 if (reg
->Register
.Indirect
) {
1257 union tgsi_exec_channel index
;
1258 union tgsi_exec_channel indir_index
;
1261 /* which address register (always zero for now) */
1265 index
.i
[3] = reg
->Indirect
.Index
;
1267 /* get current value of address register[swizzle] */
1268 swizzle
= tgsi_util_get_src_register_swizzle( ®
->Indirect
, CHAN_X
);
1270 /* fetch values from the address/indirection register */
1271 fetch_src_file_channel(mach
,
1278 /* save indirection offset */
1279 offset
= indir_index
.i
[0];
1282 switch (reg
->Register
.File
) {
1283 case TGSI_FILE_NULL
:
1287 case TGSI_FILE_OUTPUT
:
1288 index
= mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0]
1289 + reg
->Register
.Index
;
1290 dst
= &mach
->Outputs
[offset
+ index
].xyzw
[chan_index
];
1292 if (TGSI_PROCESSOR_GEOMETRY
== mach
->Processor
) {
1293 fprintf(stderr
, "STORING OUT[%d] mask(%d), = (", offset
+ index
, execmask
);
1294 for (i
= 0; i
< QUAD_SIZE
; i
++)
1295 if (execmask
& (1 << i
))
1296 fprintf(stderr
, "%f, ", chan
->f
[i
]);
1297 fprintf(stderr
, ")\n");
1302 case TGSI_FILE_TEMPORARY
:
1303 index
= reg
->Register
.Index
;
1304 assert( index
< TGSI_EXEC_NUM_TEMPS
);
1305 dst
= &mach
->Temps
[offset
+ index
].xyzw
[chan_index
];
1308 case TGSI_FILE_ADDRESS
:
1309 index
= reg
->Register
.Index
;
1310 dst
= &mach
->Addrs
[index
].xyzw
[chan_index
];
1313 case TGSI_FILE_LOOP
:
1314 assert(reg
->Register
.Index
== 0);
1315 assert(mach
->LoopCounterStackTop
> 0);
1316 assert(chan_index
== CHAN_X
);
1317 dst
= &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[chan_index
];
1320 case TGSI_FILE_PREDICATE
:
1321 index
= reg
->Register
.Index
;
1322 assert(index
< TGSI_EXEC_NUM_PREDS
);
1323 dst
= &mach
->Predicates
[index
].xyzw
[chan_index
];
1331 if (inst
->Instruction
.Predicate
) {
1333 union tgsi_exec_channel
*pred
;
1335 switch (chan_index
) {
1337 swizzle
= inst
->Predicate
.SwizzleX
;
1340 swizzle
= inst
->Predicate
.SwizzleY
;
1343 swizzle
= inst
->Predicate
.SwizzleZ
;
1346 swizzle
= inst
->Predicate
.SwizzleW
;
1353 assert(inst
->Predicate
.Index
== 0);
1355 pred
= &mach
->Predicates
[inst
->Predicate
.Index
].xyzw
[swizzle
];
1357 if (inst
->Predicate
.Negate
) {
1358 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1360 execmask
&= ~(1 << i
);
1364 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1366 execmask
&= ~(1 << i
);
1372 switch (inst
->Instruction
.Saturate
) {
1374 for (i
= 0; i
< QUAD_SIZE
; i
++)
1375 if (execmask
& (1 << i
))
1376 dst
->i
[i
] = chan
->i
[i
];
1379 case TGSI_SAT_ZERO_ONE
:
1380 for (i
= 0; i
< QUAD_SIZE
; i
++)
1381 if (execmask
& (1 << i
)) {
1382 if (chan
->f
[i
] < 0.0f
)
1384 else if (chan
->f
[i
] > 1.0f
)
1387 dst
->i
[i
] = chan
->i
[i
];
1391 case TGSI_SAT_MINUS_PLUS_ONE
:
1392 for (i
= 0; i
< QUAD_SIZE
; i
++)
1393 if (execmask
& (1 << i
)) {
1394 if (chan
->f
[i
] < -1.0f
)
1396 else if (chan
->f
[i
] > 1.0f
)
1399 dst
->i
[i
] = chan
->i
[i
];
1408 #define FETCH(VAL,INDEX,CHAN)\
1409 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_FLOAT)
1411 #define STORE(VAL,INDEX,CHAN)\
1412 store_dest(mach, VAL, &inst->Dst[INDEX], inst, CHAN, TGSI_EXEC_DATA_FLOAT)
1416 * Execute ARB-style KIL which is predicated by a src register.
1417 * Kill fragment if any of the four values is less than zero.
1420 exec_kil(struct tgsi_exec_machine
*mach
,
1421 const struct tgsi_full_instruction
*inst
)
1425 uint kilmask
= 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1426 union tgsi_exec_channel r
[1];
1428 /* This mask stores component bits that were already tested. */
1431 for (chan_index
= 0; chan_index
< 4; chan_index
++)
1436 /* unswizzle channel */
1437 swizzle
= tgsi_util_get_full_src_register_swizzle (
1441 /* check if the component has not been already tested */
1442 if (uniquemask
& (1 << swizzle
))
1444 uniquemask
|= 1 << swizzle
;
1446 FETCH(&r
[0], 0, chan_index
);
1447 for (i
= 0; i
< 4; i
++)
1448 if (r
[0].f
[i
] < 0.0f
)
1452 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1456 * Execute NVIDIA-style KIL which is predicated by a condition code.
1457 * Kill fragment if the condition code is TRUE.
1460 exec_kilp(struct tgsi_exec_machine
*mach
,
1461 const struct tgsi_full_instruction
*inst
)
1463 uint kilmask
; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1465 /* "unconditional" kil */
1466 kilmask
= mach
->ExecMask
;
1467 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1471 emit_vertex(struct tgsi_exec_machine
*mach
)
1473 /* FIXME: check for exec mask correctly
1475 for (i = 0; i < QUAD_SIZE; ++i) {
1476 if ((mach->ExecMask & (1 << i)))
1478 if (mach
->ExecMask
) {
1479 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] += mach
->NumOutputs
;
1480 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]]++;
1485 emit_primitive(struct tgsi_exec_machine
*mach
)
1487 unsigned *prim_count
= &mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0];
1488 /* FIXME: check for exec mask correctly
1490 for (i = 0; i < QUAD_SIZE; ++i) {
1491 if ((mach->ExecMask & (1 << i)))
1493 if (mach
->ExecMask
) {
1495 debug_assert((*prim_count
* mach
->NumOutputs
) < mach
->MaxGeometryShaderOutputs
);
1496 mach
->Primitives
[*prim_count
] = 0;
1501 * Fetch four texture samples using STR texture coordinates.
1504 fetch_texel( struct tgsi_sampler
*sampler
,
1505 const union tgsi_exec_channel
*s
,
1506 const union tgsi_exec_channel
*t
,
1507 const union tgsi_exec_channel
*p
,
1508 const union tgsi_exec_channel
*c0
,
1509 enum tgsi_sampler_control control
,
1510 union tgsi_exec_channel
*r
,
1511 union tgsi_exec_channel
*g
,
1512 union tgsi_exec_channel
*b
,
1513 union tgsi_exec_channel
*a
)
1516 float rgba
[NUM_CHANNELS
][QUAD_SIZE
];
1518 sampler
->get_samples(sampler
, s
->f
, t
->f
, p
->f
, c0
->f
, control
, rgba
);
1520 for (j
= 0; j
< 4; j
++) {
1521 r
->f
[j
] = rgba
[0][j
];
1522 g
->f
[j
] = rgba
[1][j
];
1523 b
->f
[j
] = rgba
[2][j
];
1524 a
->f
[j
] = rgba
[3][j
];
1529 #define TEX_MODIFIER_NONE 0
1530 #define TEX_MODIFIER_PROJECTED 1
1531 #define TEX_MODIFIER_LOD_BIAS 2
1532 #define TEX_MODIFIER_EXPLICIT_LOD 3
1536 exec_tex(struct tgsi_exec_machine
*mach
,
1537 const struct tgsi_full_instruction
*inst
,
1540 const uint unit
= inst
->Src
[1].Register
.Index
;
1541 union tgsi_exec_channel r
[4];
1542 const union tgsi_exec_channel
*lod
= &ZeroVec
;
1543 enum tgsi_sampler_control control
;
1546 if (modifier
!= TEX_MODIFIER_NONE
) {
1547 FETCH(&r
[3], 0, CHAN_W
);
1548 if (modifier
!= TEX_MODIFIER_PROJECTED
) {
1553 if (modifier
== TEX_MODIFIER_EXPLICIT_LOD
) {
1554 control
= tgsi_sampler_lod_explicit
;
1556 control
= tgsi_sampler_lod_bias
;
1559 switch (inst
->Texture
.Texture
) {
1560 case TGSI_TEXTURE_1D
:
1561 case TGSI_TEXTURE_SHADOW1D
:
1562 FETCH(&r
[0], 0, CHAN_X
);
1564 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1565 micro_div(&r
[0], &r
[0], &r
[3]);
1568 fetch_texel(mach
->Samplers
[unit
],
1569 &r
[0], &ZeroVec
, &ZeroVec
, lod
, /* S, T, P, LOD */
1571 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1574 case TGSI_TEXTURE_2D
:
1575 case TGSI_TEXTURE_RECT
:
1576 case TGSI_TEXTURE_SHADOW2D
:
1577 case TGSI_TEXTURE_SHADOWRECT
:
1578 FETCH(&r
[0], 0, CHAN_X
);
1579 FETCH(&r
[1], 0, CHAN_Y
);
1580 FETCH(&r
[2], 0, CHAN_Z
);
1582 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1583 micro_div(&r
[0], &r
[0], &r
[3]);
1584 micro_div(&r
[1], &r
[1], &r
[3]);
1585 micro_div(&r
[2], &r
[2], &r
[3]);
1588 fetch_texel(mach
->Samplers
[unit
],
1589 &r
[0], &r
[1], &r
[2], lod
, /* S, T, P, LOD */
1591 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1594 case TGSI_TEXTURE_3D
:
1595 case TGSI_TEXTURE_CUBE
:
1596 FETCH(&r
[0], 0, CHAN_X
);
1597 FETCH(&r
[1], 0, CHAN_Y
);
1598 FETCH(&r
[2], 0, CHAN_Z
);
1600 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1601 micro_div(&r
[0], &r
[0], &r
[3]);
1602 micro_div(&r
[1], &r
[1], &r
[3]);
1603 micro_div(&r
[2], &r
[2], &r
[3]);
1606 fetch_texel(mach
->Samplers
[unit
],
1607 &r
[0], &r
[1], &r
[2], lod
,
1609 &r
[0], &r
[1], &r
[2], &r
[3]);
1616 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
1617 STORE(&r
[chan_index
], 0, chan_index
);
1622 exec_txd(struct tgsi_exec_machine
*mach
,
1623 const struct tgsi_full_instruction
*inst
)
1625 const uint unit
= inst
->Src
[3].Register
.Index
;
1626 union tgsi_exec_channel r
[4];
1630 * XXX: This is fake TXD -- the derivatives are not taken into account, yet.
1633 switch (inst
->Texture
.Texture
) {
1634 case TGSI_TEXTURE_1D
:
1635 case TGSI_TEXTURE_SHADOW1D
:
1637 FETCH(&r
[0], 0, CHAN_X
);
1639 fetch_texel(mach
->Samplers
[unit
],
1640 &r
[0], &ZeroVec
, &ZeroVec
, &ZeroVec
, /* S, T, P, BIAS */
1641 tgsi_sampler_lod_bias
,
1642 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1645 case TGSI_TEXTURE_2D
:
1646 case TGSI_TEXTURE_RECT
:
1647 case TGSI_TEXTURE_SHADOW2D
:
1648 case TGSI_TEXTURE_SHADOWRECT
:
1650 FETCH(&r
[0], 0, CHAN_X
);
1651 FETCH(&r
[1], 0, CHAN_Y
);
1652 FETCH(&r
[2], 0, CHAN_Z
);
1654 fetch_texel(mach
->Samplers
[unit
],
1655 &r
[0], &r
[1], &r
[2], &ZeroVec
, /* inputs */
1656 tgsi_sampler_lod_bias
,
1657 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1660 case TGSI_TEXTURE_3D
:
1661 case TGSI_TEXTURE_CUBE
:
1663 FETCH(&r
[0], 0, CHAN_X
);
1664 FETCH(&r
[1], 0, CHAN_Y
);
1665 FETCH(&r
[2], 0, CHAN_Z
);
1667 fetch_texel(mach
->Samplers
[unit
],
1668 &r
[0], &r
[1], &r
[2], &ZeroVec
,
1669 tgsi_sampler_lod_bias
,
1670 &r
[0], &r
[1], &r
[2], &r
[3]);
1677 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
1678 STORE(&r
[chan_index
], 0, chan_index
);
1684 * Evaluate a constant-valued coefficient at the position of the
1689 struct tgsi_exec_machine
*mach
,
1695 for( i
= 0; i
< QUAD_SIZE
; i
++ ) {
1696 mach
->Inputs
[attrib
].xyzw
[chan
].f
[i
] = mach
->InterpCoefs
[attrib
].a0
[chan
];
1701 * Evaluate a linear-valued coefficient at the position of the
1706 struct tgsi_exec_machine
*mach
,
1710 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1711 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1712 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1713 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1714 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1715 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
;
1716 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = a0
+ dadx
;
1717 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = a0
+ dady
;
1718 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = a0
+ dadx
+ dady
;
1722 * Evaluate a perspective-valued coefficient at the position of the
1726 eval_perspective_coef(
1727 struct tgsi_exec_machine
*mach
,
1731 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1732 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1733 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1734 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1735 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1736 const float *w
= mach
->QuadPos
.xyzw
[3].f
;
1737 /* divide by W here */
1738 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
/ w
[0];
1739 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = (a0
+ dadx
) / w
[1];
1740 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = (a0
+ dady
) / w
[2];
1741 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = (a0
+ dadx
+ dady
) / w
[3];
1745 typedef void (* eval_coef_func
)(
1746 struct tgsi_exec_machine
*mach
,
1751 exec_declaration(struct tgsi_exec_machine
*mach
,
1752 const struct tgsi_full_declaration
*decl
)
1754 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
1755 if (decl
->Declaration
.File
== TGSI_FILE_INPUT
||
1756 decl
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1757 uint first
, last
, mask
;
1759 first
= decl
->Range
.First
;
1760 last
= decl
->Range
.Last
;
1761 mask
= decl
->Declaration
.UsageMask
;
1763 if (decl
->Semantic
.Name
== TGSI_SEMANTIC_FACE
) {
1766 assert(decl
->Semantic
.Index
== 0);
1767 assert(first
== last
);
1769 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1770 mach
->Inputs
[first
].xyzw
[0].f
[i
] = mach
->Face
;
1773 eval_coef_func eval
;
1776 switch (decl
->Declaration
.Interpolate
) {
1777 case TGSI_INTERPOLATE_CONSTANT
:
1778 eval
= eval_constant_coef
;
1781 case TGSI_INTERPOLATE_LINEAR
:
1782 eval
= eval_linear_coef
;
1785 case TGSI_INTERPOLATE_PERSPECTIVE
:
1786 eval
= eval_perspective_coef
;
1794 for (j
= 0; j
< NUM_CHANNELS
; j
++) {
1795 if (mask
& (1 << j
)) {
1796 for (i
= first
; i
<= last
; i
++) {
1806 typedef void (* micro_unary_op
)(union tgsi_exec_channel
*dst
,
1807 const union tgsi_exec_channel
*src
);
1810 exec_scalar_unary(struct tgsi_exec_machine
*mach
,
1811 const struct tgsi_full_instruction
*inst
,
1813 enum tgsi_exec_datatype dst_datatype
,
1814 enum tgsi_exec_datatype src_datatype
)
1817 union tgsi_exec_channel src
;
1818 union tgsi_exec_channel dst
;
1820 fetch_source(mach
, &src
, &inst
->Src
[0], CHAN_X
, src_datatype
);
1822 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1823 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1824 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, dst_datatype
);
1830 exec_vector_unary(struct tgsi_exec_machine
*mach
,
1831 const struct tgsi_full_instruction
*inst
,
1833 enum tgsi_exec_datatype dst_datatype
,
1834 enum tgsi_exec_datatype src_datatype
)
1837 struct tgsi_exec_vector dst
;
1839 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1840 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1841 union tgsi_exec_channel src
;
1843 fetch_source(mach
, &src
, &inst
->Src
[0], chan
, src_datatype
);
1844 op(&dst
.xyzw
[chan
], &src
);
1847 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1848 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1849 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
1854 typedef void (* micro_binary_op
)(union tgsi_exec_channel
*dst
,
1855 const union tgsi_exec_channel
*src0
,
1856 const union tgsi_exec_channel
*src1
);
1859 exec_vector_binary(struct tgsi_exec_machine
*mach
,
1860 const struct tgsi_full_instruction
*inst
,
1862 enum tgsi_exec_datatype dst_datatype
,
1863 enum tgsi_exec_datatype src_datatype
)
1866 struct tgsi_exec_vector dst
;
1868 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1869 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1870 union tgsi_exec_channel src
[2];
1872 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
1873 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
1874 op(&dst
.xyzw
[chan
], &src
[0], &src
[1]);
1877 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1878 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1879 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
1884 typedef void (* micro_trinary_op
)(union tgsi_exec_channel
*dst
,
1885 const union tgsi_exec_channel
*src0
,
1886 const union tgsi_exec_channel
*src1
,
1887 const union tgsi_exec_channel
*src2
);
1890 exec_vector_trinary(struct tgsi_exec_machine
*mach
,
1891 const struct tgsi_full_instruction
*inst
,
1892 micro_trinary_op op
,
1893 enum tgsi_exec_datatype dst_datatype
,
1894 enum tgsi_exec_datatype src_datatype
)
1897 struct tgsi_exec_vector dst
;
1899 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1900 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1901 union tgsi_exec_channel src
[3];
1903 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
1904 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
1905 fetch_source(mach
, &src
[2], &inst
->Src
[2], chan
, src_datatype
);
1906 op(&dst
.xyzw
[chan
], &src
[0], &src
[1], &src
[2]);
1909 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1910 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1911 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
1917 exec_dp3(struct tgsi_exec_machine
*mach
,
1918 const struct tgsi_full_instruction
*inst
)
1921 union tgsi_exec_channel arg
[3];
1923 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
1924 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
1925 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
1927 for (chan
= CHAN_Y
; chan
<= CHAN_Z
; chan
++) {
1928 fetch_source(mach
, &arg
[0], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
1929 fetch_source(mach
, &arg
[1], &inst
->Src
[1], chan
, TGSI_EXEC_DATA_FLOAT
);
1930 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
1933 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1934 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1935 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
1941 exec_dp4(struct tgsi_exec_machine
*mach
,
1942 const struct tgsi_full_instruction
*inst
)
1945 union tgsi_exec_channel arg
[3];
1947 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
1948 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
1949 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
1951 for (chan
= CHAN_Y
; chan
<= CHAN_W
; chan
++) {
1952 fetch_source(mach
, &arg
[0], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
1953 fetch_source(mach
, &arg
[1], &inst
->Src
[1], chan
, TGSI_EXEC_DATA_FLOAT
);
1954 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
1957 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1958 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1959 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
1965 exec_dp2a(struct tgsi_exec_machine
*mach
,
1966 const struct tgsi_full_instruction
*inst
)
1969 union tgsi_exec_channel arg
[3];
1971 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
1972 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
1973 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
1975 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
1976 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
1977 micro_mad(&arg
[0], &arg
[0], &arg
[1], &arg
[2]);
1979 fetch_source(mach
, &arg
[1], &inst
->Src
[2], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
1980 micro_add(&arg
[0], &arg
[0], &arg
[1]);
1982 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1983 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1984 store_dest(mach
, &arg
[0], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
1990 exec_dph(struct tgsi_exec_machine
*mach
,
1991 const struct tgsi_full_instruction
*inst
)
1994 union tgsi_exec_channel arg
[3];
1996 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
1997 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
1998 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2000 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2001 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2002 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2004 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2005 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2006 micro_mad(&arg
[0], &arg
[0], &arg
[1], &arg
[2]);
2008 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2009 micro_add(&arg
[0], &arg
[0], &arg
[1]);
2011 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
2012 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2013 store_dest(mach
, &arg
[0], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2019 exec_dp2(struct tgsi_exec_machine
*mach
,
2020 const struct tgsi_full_instruction
*inst
)
2023 union tgsi_exec_channel arg
[3];
2025 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2026 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2027 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2029 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2030 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2031 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2033 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
2034 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2035 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2041 exec_nrm4(struct tgsi_exec_machine
*mach
,
2042 const struct tgsi_full_instruction
*inst
)
2045 union tgsi_exec_channel arg
[4];
2046 union tgsi_exec_channel scale
;
2048 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2049 micro_mul(&scale
, &arg
[0], &arg
[0]);
2051 for (chan
= CHAN_Y
; chan
<= CHAN_W
; chan
++) {
2052 union tgsi_exec_channel product
;
2054 fetch_source(mach
, &arg
[chan
], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2055 micro_mul(&product
, &arg
[chan
], &arg
[chan
]);
2056 micro_add(&scale
, &scale
, &product
);
2059 micro_rsq(&scale
, &scale
);
2061 for (chan
= CHAN_X
; chan
<= CHAN_W
; chan
++) {
2062 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2063 micro_mul(&arg
[chan
], &arg
[chan
], &scale
);
2064 store_dest(mach
, &arg
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2070 exec_nrm3(struct tgsi_exec_machine
*mach
,
2071 const struct tgsi_full_instruction
*inst
)
2073 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XYZ
) {
2075 union tgsi_exec_channel arg
[3];
2076 union tgsi_exec_channel scale
;
2078 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2079 micro_mul(&scale
, &arg
[0], &arg
[0]);
2081 for (chan
= CHAN_Y
; chan
<= CHAN_Z
; chan
++) {
2082 union tgsi_exec_channel product
;
2084 fetch_source(mach
, &arg
[chan
], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2085 micro_mul(&product
, &arg
[chan
], &arg
[chan
]);
2086 micro_add(&scale
, &scale
, &product
);
2089 micro_rsq(&scale
, &scale
);
2091 for (chan
= CHAN_X
; chan
<= CHAN_Z
; chan
++) {
2092 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2093 micro_mul(&arg
[chan
], &arg
[chan
], &scale
);
2094 store_dest(mach
, &arg
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2099 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2100 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2105 exec_break(struct tgsi_exec_machine
*mach
)
2107 if (mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_LOOP
) {
2108 /* turn off loop channels for each enabled exec channel */
2109 mach
->LoopMask
&= ~mach
->ExecMask
;
2110 /* Todo: if mach->LoopMask == 0, jump to end of loop */
2111 UPDATE_EXEC_MASK(mach
);
2113 assert(mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_SWITCH
);
2115 mach
->Switch
.mask
= 0x0;
2117 UPDATE_EXEC_MASK(mach
);
2122 exec_switch(struct tgsi_exec_machine
*mach
,
2123 const struct tgsi_full_instruction
*inst
)
2125 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
2126 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
2128 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
2129 fetch_source(mach
, &mach
->Switch
.selector
, &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_UINT
);
2130 mach
->Switch
.mask
= 0x0;
2131 mach
->Switch
.defaultMask
= 0x0;
2133 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
2134 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_SWITCH
;
2136 UPDATE_EXEC_MASK(mach
);
2140 exec_case(struct tgsi_exec_machine
*mach
,
2141 const struct tgsi_full_instruction
*inst
)
2143 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
2144 union tgsi_exec_channel src
;
2147 fetch_source(mach
, &src
, &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_UINT
);
2149 if (mach
->Switch
.selector
.u
[0] == src
.u
[0]) {
2152 if (mach
->Switch
.selector
.u
[1] == src
.u
[1]) {
2155 if (mach
->Switch
.selector
.u
[2] == src
.u
[2]) {
2158 if (mach
->Switch
.selector
.u
[3] == src
.u
[3]) {
2162 mach
->Switch
.defaultMask
|= mask
;
2164 mach
->Switch
.mask
|= mask
& prevMask
;
2166 UPDATE_EXEC_MASK(mach
);
2170 exec_default(struct tgsi_exec_machine
*mach
)
2172 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
2174 mach
->Switch
.mask
|= ~mach
->Switch
.defaultMask
& prevMask
;
2176 UPDATE_EXEC_MASK(mach
);
2180 exec_endswitch(struct tgsi_exec_machine
*mach
)
2182 mach
->Switch
= mach
->SwitchStack
[--mach
->SwitchStackTop
];
2183 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
2185 UPDATE_EXEC_MASK(mach
);
2189 micro_i2f(union tgsi_exec_channel
*dst
,
2190 const union tgsi_exec_channel
*src
)
2192 dst
->f
[0] = (float)src
->i
[0];
2193 dst
->f
[1] = (float)src
->i
[1];
2194 dst
->f
[2] = (float)src
->i
[2];
2195 dst
->f
[3] = (float)src
->i
[3];
2199 micro_not(union tgsi_exec_channel
*dst
,
2200 const union tgsi_exec_channel
*src
)
2202 dst
->u
[0] = ~src
->u
[0];
2203 dst
->u
[1] = ~src
->u
[1];
2204 dst
->u
[2] = ~src
->u
[2];
2205 dst
->u
[3] = ~src
->u
[3];
2209 micro_shl(union tgsi_exec_channel
*dst
,
2210 const union tgsi_exec_channel
*src0
,
2211 const union tgsi_exec_channel
*src1
)
2213 dst
->u
[0] = src0
->u
[0] << src1
->u
[0];
2214 dst
->u
[1] = src0
->u
[1] << src1
->u
[1];
2215 dst
->u
[2] = src0
->u
[2] << src1
->u
[2];
2216 dst
->u
[3] = src0
->u
[3] << src1
->u
[3];
2220 micro_and(union tgsi_exec_channel
*dst
,
2221 const union tgsi_exec_channel
*src0
,
2222 const union tgsi_exec_channel
*src1
)
2224 dst
->u
[0] = src0
->u
[0] & src1
->u
[0];
2225 dst
->u
[1] = src0
->u
[1] & src1
->u
[1];
2226 dst
->u
[2] = src0
->u
[2] & src1
->u
[2];
2227 dst
->u
[3] = src0
->u
[3] & src1
->u
[3];
2231 micro_or(union tgsi_exec_channel
*dst
,
2232 const union tgsi_exec_channel
*src0
,
2233 const union tgsi_exec_channel
*src1
)
2235 dst
->u
[0] = src0
->u
[0] | src1
->u
[0];
2236 dst
->u
[1] = src0
->u
[1] | src1
->u
[1];
2237 dst
->u
[2] = src0
->u
[2] | src1
->u
[2];
2238 dst
->u
[3] = src0
->u
[3] | src1
->u
[3];
2242 micro_xor(union tgsi_exec_channel
*dst
,
2243 const union tgsi_exec_channel
*src0
,
2244 const union tgsi_exec_channel
*src1
)
2246 dst
->u
[0] = src0
->u
[0] ^ src1
->u
[0];
2247 dst
->u
[1] = src0
->u
[1] ^ src1
->u
[1];
2248 dst
->u
[2] = src0
->u
[2] ^ src1
->u
[2];
2249 dst
->u
[3] = src0
->u
[3] ^ src1
->u
[3];
2253 micro_f2i(union tgsi_exec_channel
*dst
,
2254 const union tgsi_exec_channel
*src
)
2256 dst
->i
[0] = (int)src
->f
[0];
2257 dst
->i
[1] = (int)src
->f
[1];
2258 dst
->i
[2] = (int)src
->f
[2];
2259 dst
->i
[3] = (int)src
->f
[3];
2263 micro_idiv(union tgsi_exec_channel
*dst
,
2264 const union tgsi_exec_channel
*src0
,
2265 const union tgsi_exec_channel
*src1
)
2267 dst
->i
[0] = src0
->i
[0] / src1
->i
[0];
2268 dst
->i
[1] = src0
->i
[1] / src1
->i
[1];
2269 dst
->i
[2] = src0
->i
[2] / src1
->i
[2];
2270 dst
->i
[3] = src0
->i
[3] / src1
->i
[3];
2274 micro_imax(union tgsi_exec_channel
*dst
,
2275 const union tgsi_exec_channel
*src0
,
2276 const union tgsi_exec_channel
*src1
)
2278 dst
->i
[0] = src0
->i
[0] > src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
2279 dst
->i
[1] = src0
->i
[1] > src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
2280 dst
->i
[2] = src0
->i
[2] > src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
2281 dst
->i
[3] = src0
->i
[3] > src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
2285 micro_imin(union tgsi_exec_channel
*dst
,
2286 const union tgsi_exec_channel
*src0
,
2287 const union tgsi_exec_channel
*src1
)
2289 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
2290 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
2291 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
2292 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
2296 micro_isge(union tgsi_exec_channel
*dst
,
2297 const union tgsi_exec_channel
*src0
,
2298 const union tgsi_exec_channel
*src1
)
2300 dst
->i
[0] = src0
->i
[0] >= src1
->i
[0] ? -1 : 0;
2301 dst
->i
[1] = src0
->i
[1] >= src1
->i
[1] ? -1 : 0;
2302 dst
->i
[2] = src0
->i
[2] >= src1
->i
[2] ? -1 : 0;
2303 dst
->i
[3] = src0
->i
[3] >= src1
->i
[3] ? -1 : 0;
2307 micro_ishr(union tgsi_exec_channel
*dst
,
2308 const union tgsi_exec_channel
*src0
,
2309 const union tgsi_exec_channel
*src1
)
2311 dst
->i
[0] = src0
->i
[0] >> src1
->i
[0];
2312 dst
->i
[1] = src0
->i
[1] >> src1
->i
[1];
2313 dst
->i
[2] = src0
->i
[2] >> src1
->i
[2];
2314 dst
->i
[3] = src0
->i
[3] >> src1
->i
[3];
2318 micro_islt(union tgsi_exec_channel
*dst
,
2319 const union tgsi_exec_channel
*src0
,
2320 const union tgsi_exec_channel
*src1
)
2322 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? -1 : 0;
2323 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? -1 : 0;
2324 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? -1 : 0;
2325 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? -1 : 0;
2329 micro_f2u(union tgsi_exec_channel
*dst
,
2330 const union tgsi_exec_channel
*src
)
2332 dst
->u
[0] = (uint
)src
->f
[0];
2333 dst
->u
[1] = (uint
)src
->f
[1];
2334 dst
->u
[2] = (uint
)src
->f
[2];
2335 dst
->u
[3] = (uint
)src
->f
[3];
2339 micro_u2f(union tgsi_exec_channel
*dst
,
2340 const union tgsi_exec_channel
*src
)
2342 dst
->f
[0] = (float)src
->u
[0];
2343 dst
->f
[1] = (float)src
->u
[1];
2344 dst
->f
[2] = (float)src
->u
[2];
2345 dst
->f
[3] = (float)src
->u
[3];
2349 micro_uadd(union tgsi_exec_channel
*dst
,
2350 const union tgsi_exec_channel
*src0
,
2351 const union tgsi_exec_channel
*src1
)
2353 dst
->u
[0] = src0
->u
[0] + src1
->u
[0];
2354 dst
->u
[1] = src0
->u
[1] + src1
->u
[1];
2355 dst
->u
[2] = src0
->u
[2] + src1
->u
[2];
2356 dst
->u
[3] = src0
->u
[3] + src1
->u
[3];
2360 micro_udiv(union tgsi_exec_channel
*dst
,
2361 const union tgsi_exec_channel
*src0
,
2362 const union tgsi_exec_channel
*src1
)
2364 dst
->u
[0] = src0
->u
[0] / src1
->u
[0];
2365 dst
->u
[1] = src0
->u
[1] / src1
->u
[1];
2366 dst
->u
[2] = src0
->u
[2] / src1
->u
[2];
2367 dst
->u
[3] = src0
->u
[3] / src1
->u
[3];
2371 micro_umad(union tgsi_exec_channel
*dst
,
2372 const union tgsi_exec_channel
*src0
,
2373 const union tgsi_exec_channel
*src1
,
2374 const union tgsi_exec_channel
*src2
)
2376 dst
->u
[0] = src0
->u
[0] * src1
->u
[0] + src2
->u
[0];
2377 dst
->u
[1] = src0
->u
[1] * src1
->u
[1] + src2
->u
[1];
2378 dst
->u
[2] = src0
->u
[2] * src1
->u
[2] + src2
->u
[2];
2379 dst
->u
[3] = src0
->u
[3] * src1
->u
[3] + src2
->u
[3];
2383 micro_umax(union tgsi_exec_channel
*dst
,
2384 const union tgsi_exec_channel
*src0
,
2385 const union tgsi_exec_channel
*src1
)
2387 dst
->u
[0] = src0
->u
[0] > src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
2388 dst
->u
[1] = src0
->u
[1] > src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
2389 dst
->u
[2] = src0
->u
[2] > src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
2390 dst
->u
[3] = src0
->u
[3] > src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
2394 micro_umin(union tgsi_exec_channel
*dst
,
2395 const union tgsi_exec_channel
*src0
,
2396 const union tgsi_exec_channel
*src1
)
2398 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
2399 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
2400 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
2401 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
2405 micro_umod(union tgsi_exec_channel
*dst
,
2406 const union tgsi_exec_channel
*src0
,
2407 const union tgsi_exec_channel
*src1
)
2409 dst
->u
[0] = src0
->u
[0] % src1
->u
[0];
2410 dst
->u
[1] = src0
->u
[1] % src1
->u
[1];
2411 dst
->u
[2] = src0
->u
[2] % src1
->u
[2];
2412 dst
->u
[3] = src0
->u
[3] % src1
->u
[3];
2416 micro_umul(union tgsi_exec_channel
*dst
,
2417 const union tgsi_exec_channel
*src0
,
2418 const union tgsi_exec_channel
*src1
)
2420 dst
->u
[0] = src0
->u
[0] * src1
->u
[0];
2421 dst
->u
[1] = src0
->u
[1] * src1
->u
[1];
2422 dst
->u
[2] = src0
->u
[2] * src1
->u
[2];
2423 dst
->u
[3] = src0
->u
[3] * src1
->u
[3];
2427 micro_useq(union tgsi_exec_channel
*dst
,
2428 const union tgsi_exec_channel
*src0
,
2429 const union tgsi_exec_channel
*src1
)
2431 dst
->u
[0] = src0
->u
[0] == src1
->u
[0] ? ~0 : 0;
2432 dst
->u
[1] = src0
->u
[1] == src1
->u
[1] ? ~0 : 0;
2433 dst
->u
[2] = src0
->u
[2] == src1
->u
[2] ? ~0 : 0;
2434 dst
->u
[3] = src0
->u
[3] == src1
->u
[3] ? ~0 : 0;
2438 micro_usge(union tgsi_exec_channel
*dst
,
2439 const union tgsi_exec_channel
*src0
,
2440 const union tgsi_exec_channel
*src1
)
2442 dst
->u
[0] = src0
->u
[0] >= src1
->u
[0] ? ~0 : 0;
2443 dst
->u
[1] = src0
->u
[1] >= src1
->u
[1] ? ~0 : 0;
2444 dst
->u
[2] = src0
->u
[2] >= src1
->u
[2] ? ~0 : 0;
2445 dst
->u
[3] = src0
->u
[3] >= src1
->u
[3] ? ~0 : 0;
2449 micro_ushr(union tgsi_exec_channel
*dst
,
2450 const union tgsi_exec_channel
*src0
,
2451 const union tgsi_exec_channel
*src1
)
2453 dst
->u
[0] = src0
->u
[0] >> src1
->u
[0];
2454 dst
->u
[1] = src0
->u
[1] >> src1
->u
[1];
2455 dst
->u
[2] = src0
->u
[2] >> src1
->u
[2];
2456 dst
->u
[3] = src0
->u
[3] >> src1
->u
[3];
2460 micro_uslt(union tgsi_exec_channel
*dst
,
2461 const union tgsi_exec_channel
*src0
,
2462 const union tgsi_exec_channel
*src1
)
2464 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? ~0 : 0;
2465 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? ~0 : 0;
2466 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? ~0 : 0;
2467 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? ~0 : 0;
2471 micro_usne(union tgsi_exec_channel
*dst
,
2472 const union tgsi_exec_channel
*src0
,
2473 const union tgsi_exec_channel
*src1
)
2475 dst
->u
[0] = src0
->u
[0] != src1
->u
[0] ? ~0 : 0;
2476 dst
->u
[1] = src0
->u
[1] != src1
->u
[1] ? ~0 : 0;
2477 dst
->u
[2] = src0
->u
[2] != src1
->u
[2] ? ~0 : 0;
2478 dst
->u
[3] = src0
->u
[3] != src1
->u
[3] ? ~0 : 0;
2483 struct tgsi_exec_machine
*mach
,
2484 const struct tgsi_full_instruction
*inst
,
2488 union tgsi_exec_channel r
[10];
2489 union tgsi_exec_channel d
[8];
2493 switch (inst
->Instruction
.Opcode
) {
2494 case TGSI_OPCODE_ARL
:
2495 exec_vector_unary(mach
, inst
, micro_arl
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
2498 case TGSI_OPCODE_MOV
:
2499 exec_vector_unary(mach
, inst
, micro_mov
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
2502 case TGSI_OPCODE_LIT
:
2503 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2504 FETCH( &r
[0], 0, CHAN_X
);
2505 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2506 micro_max(&d
[CHAN_Y
], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
2509 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2510 FETCH( &r
[1], 0, CHAN_Y
);
2511 micro_max( &r
[1], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
2513 FETCH( &r
[2], 0, CHAN_W
);
2514 micro_min( &r
[2], &r
[2], &mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
] );
2515 micro_max( &r
[2], &r
[2], &mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
] );
2516 micro_pow( &r
[1], &r
[1], &r
[2] );
2517 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
]);
2520 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2521 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2523 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2524 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2527 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2528 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2530 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2531 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2535 case TGSI_OPCODE_RCP
:
2536 exec_scalar_unary(mach
, inst
, micro_rcp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2539 case TGSI_OPCODE_RSQ
:
2540 exec_scalar_unary(mach
, inst
, micro_rsq
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2543 case TGSI_OPCODE_EXP
:
2544 FETCH( &r
[0], 0, CHAN_X
);
2545 micro_flr( &r
[1], &r
[0] ); /* r1 = floor(r0) */
2546 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2547 micro_exp2( &r
[2], &r
[1] ); /* r2 = 2 ^ r1 */
2548 STORE( &r
[2], 0, CHAN_X
); /* store r2 */
2550 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2551 micro_sub( &r
[2], &r
[0], &r
[1] ); /* r2 = r0 - r1 */
2552 STORE( &r
[2], 0, CHAN_Y
); /* store r2 */
2554 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2555 micro_exp2( &r
[2], &r
[0] ); /* r2 = 2 ^ r0 */
2556 STORE( &r
[2], 0, CHAN_Z
); /* store r2 */
2558 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2559 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2563 case TGSI_OPCODE_LOG
:
2564 FETCH( &r
[0], 0, CHAN_X
);
2565 micro_abs( &r
[2], &r
[0] ); /* r2 = abs(r0) */
2566 micro_lg2( &r
[1], &r
[2] ); /* r1 = lg2(r2) */
2567 micro_flr( &r
[0], &r
[1] ); /* r0 = floor(r1) */
2568 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2569 STORE( &r
[0], 0, CHAN_X
);
2571 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2572 micro_exp2( &r
[0], &r
[0] ); /* r0 = 2 ^ r0 */
2573 micro_div( &r
[0], &r
[2], &r
[0] ); /* r0 = r2 / r0 */
2574 STORE( &r
[0], 0, CHAN_Y
);
2576 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2577 STORE( &r
[1], 0, CHAN_Z
);
2579 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2580 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2584 case TGSI_OPCODE_MUL
:
2585 exec_vector_binary(mach
, inst
, micro_mul
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2588 case TGSI_OPCODE_ADD
:
2589 exec_vector_binary(mach
, inst
, micro_add
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2592 case TGSI_OPCODE_DP3
:
2593 exec_dp3(mach
, inst
);
2596 case TGSI_OPCODE_DP4
:
2597 exec_dp4(mach
, inst
);
2600 case TGSI_OPCODE_DST
:
2601 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2602 FETCH( &r
[0], 0, CHAN_Y
);
2603 FETCH( &r
[1], 1, CHAN_Y
);
2604 micro_mul(&d
[CHAN_Y
], &r
[0], &r
[1]);
2606 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2607 FETCH(&d
[CHAN_Z
], 0, CHAN_Z
);
2609 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2610 FETCH(&d
[CHAN_W
], 1, CHAN_W
);
2613 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2614 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2616 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2617 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2619 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2620 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2622 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2623 STORE(&d
[CHAN_W
], 0, CHAN_W
);
2627 case TGSI_OPCODE_MIN
:
2628 exec_vector_binary(mach
, inst
, micro_min
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2631 case TGSI_OPCODE_MAX
:
2632 exec_vector_binary(mach
, inst
, micro_max
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2635 case TGSI_OPCODE_SLT
:
2636 exec_vector_binary(mach
, inst
, micro_slt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2639 case TGSI_OPCODE_SGE
:
2640 exec_vector_binary(mach
, inst
, micro_sge
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2643 case TGSI_OPCODE_MAD
:
2644 exec_vector_trinary(mach
, inst
, micro_mad
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2647 case TGSI_OPCODE_SUB
:
2648 exec_vector_binary(mach
, inst
, micro_sub
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2651 case TGSI_OPCODE_LRP
:
2652 exec_vector_trinary(mach
, inst
, micro_lrp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2655 case TGSI_OPCODE_CND
:
2656 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2657 FETCH(&r
[0], 0, chan_index
);
2658 FETCH(&r
[1], 1, chan_index
);
2659 FETCH(&r
[2], 2, chan_index
);
2660 micro_lt(&d
[chan_index
], &mach
->Temps
[TEMP_HALF_I
].xyzw
[TEMP_HALF_C
], &r
[2], &r
[0], &r
[1]);
2662 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2663 STORE(&d
[chan_index
], 0, chan_index
);
2667 case TGSI_OPCODE_DP2A
:
2668 exec_dp2a(mach
, inst
);
2671 case TGSI_OPCODE_FRC
:
2672 exec_vector_unary(mach
, inst
, micro_frc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2675 case TGSI_OPCODE_CLAMP
:
2676 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2677 FETCH(&r
[0], 0, chan_index
);
2678 FETCH(&r
[1], 1, chan_index
);
2679 micro_max(&r
[0], &r
[0], &r
[1]);
2680 FETCH(&r
[1], 2, chan_index
);
2681 micro_min(&d
[chan_index
], &r
[0], &r
[1]);
2683 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2684 STORE(&d
[chan_index
], 0, chan_index
);
2688 case TGSI_OPCODE_FLR
:
2689 exec_vector_unary(mach
, inst
, micro_flr
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2692 case TGSI_OPCODE_ROUND
:
2693 exec_vector_unary(mach
, inst
, micro_rnd
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2696 case TGSI_OPCODE_EX2
:
2697 exec_scalar_unary(mach
, inst
, micro_exp2
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2700 case TGSI_OPCODE_LG2
:
2701 exec_scalar_unary(mach
, inst
, micro_lg2
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2704 case TGSI_OPCODE_POW
:
2705 FETCH(&r
[0], 0, CHAN_X
);
2706 FETCH(&r
[1], 1, CHAN_X
);
2708 micro_pow( &r
[0], &r
[0], &r
[1] );
2710 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2711 STORE( &r
[0], 0, chan_index
);
2715 case TGSI_OPCODE_XPD
:
2716 FETCH(&r
[0], 0, CHAN_Y
);
2717 FETCH(&r
[1], 1, CHAN_Z
);
2719 micro_mul( &r
[2], &r
[0], &r
[1] );
2721 FETCH(&r
[3], 0, CHAN_Z
);
2722 FETCH(&r
[4], 1, CHAN_Y
);
2724 micro_mul( &r
[5], &r
[3], &r
[4] );
2725 micro_sub(&d
[CHAN_X
], &r
[2], &r
[5]);
2727 FETCH(&r
[2], 1, CHAN_X
);
2729 micro_mul( &r
[3], &r
[3], &r
[2] );
2731 FETCH(&r
[5], 0, CHAN_X
);
2733 micro_mul( &r
[1], &r
[1], &r
[5] );
2734 micro_sub(&d
[CHAN_Y
], &r
[3], &r
[1]);
2736 micro_mul( &r
[5], &r
[5], &r
[4] );
2737 micro_mul( &r
[0], &r
[0], &r
[2] );
2738 micro_sub(&d
[CHAN_Z
], &r
[5], &r
[0]);
2740 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2741 STORE(&d
[CHAN_X
], 0, CHAN_X
);
2743 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2744 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2746 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2747 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2749 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2750 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2754 case TGSI_OPCODE_ABS
:
2755 exec_vector_unary(mach
, inst
, micro_abs
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2758 case TGSI_OPCODE_RCC
:
2759 FETCH(&r
[0], 0, CHAN_X
);
2760 micro_div(&r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0]);
2761 micro_float_clamp(&r
[0], &r
[0]);
2762 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2763 STORE(&r
[0], 0, chan_index
);
2767 case TGSI_OPCODE_DPH
:
2768 exec_dph(mach
, inst
);
2771 case TGSI_OPCODE_COS
:
2772 exec_scalar_unary(mach
, inst
, micro_cos
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2775 case TGSI_OPCODE_DDX
:
2776 exec_vector_unary(mach
, inst
, micro_ddx
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2779 case TGSI_OPCODE_DDY
:
2780 exec_vector_unary(mach
, inst
, micro_ddy
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2783 case TGSI_OPCODE_KILP
:
2784 exec_kilp (mach
, inst
);
2787 case TGSI_OPCODE_KIL
:
2788 exec_kil (mach
, inst
);
2791 case TGSI_OPCODE_PK2H
:
2795 case TGSI_OPCODE_PK2US
:
2799 case TGSI_OPCODE_PK4B
:
2803 case TGSI_OPCODE_PK4UB
:
2807 case TGSI_OPCODE_RFL
:
2808 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2809 IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2810 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2811 /* r0 = dp3(src0, src0) */
2812 FETCH(&r
[2], 0, CHAN_X
);
2813 micro_mul(&r
[0], &r
[2], &r
[2]);
2814 FETCH(&r
[4], 0, CHAN_Y
);
2815 micro_mul(&r
[8], &r
[4], &r
[4]);
2816 micro_add(&r
[0], &r
[0], &r
[8]);
2817 FETCH(&r
[6], 0, CHAN_Z
);
2818 micro_mul(&r
[8], &r
[6], &r
[6]);
2819 micro_add(&r
[0], &r
[0], &r
[8]);
2821 /* r1 = dp3(src0, src1) */
2822 FETCH(&r
[3], 1, CHAN_X
);
2823 micro_mul(&r
[1], &r
[2], &r
[3]);
2824 FETCH(&r
[5], 1, CHAN_Y
);
2825 micro_mul(&r
[8], &r
[4], &r
[5]);
2826 micro_add(&r
[1], &r
[1], &r
[8]);
2827 FETCH(&r
[7], 1, CHAN_Z
);
2828 micro_mul(&r
[8], &r
[6], &r
[7]);
2829 micro_add(&r
[1], &r
[1], &r
[8]);
2831 /* r1 = 2 * r1 / r0 */
2832 micro_add(&r
[1], &r
[1], &r
[1]);
2833 micro_div(&r
[1], &r
[1], &r
[0]);
2835 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2836 micro_mul(&r
[2], &r
[2], &r
[1]);
2837 micro_sub(&r
[2], &r
[2], &r
[3]);
2838 STORE(&r
[2], 0, CHAN_X
);
2840 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2841 micro_mul(&r
[4], &r
[4], &r
[1]);
2842 micro_sub(&r
[4], &r
[4], &r
[5]);
2843 STORE(&r
[4], 0, CHAN_Y
);
2845 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2846 micro_mul(&r
[6], &r
[6], &r
[1]);
2847 micro_sub(&r
[6], &r
[6], &r
[7]);
2848 STORE(&r
[6], 0, CHAN_Z
);
2851 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2852 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2856 case TGSI_OPCODE_SEQ
:
2857 exec_vector_binary(mach
, inst
, micro_seq
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2860 case TGSI_OPCODE_SFL
:
2861 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2862 STORE(&mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, chan_index
);
2866 case TGSI_OPCODE_SGT
:
2867 exec_vector_binary(mach
, inst
, micro_sgt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2870 case TGSI_OPCODE_SIN
:
2871 exec_scalar_unary(mach
, inst
, micro_sin
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2874 case TGSI_OPCODE_SLE
:
2875 exec_vector_binary(mach
, inst
, micro_sle
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2878 case TGSI_OPCODE_SNE
:
2879 exec_vector_binary(mach
, inst
, micro_sne
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2882 case TGSI_OPCODE_STR
:
2883 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2884 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, chan_index
);
2888 case TGSI_OPCODE_TEX
:
2889 /* simple texture lookup */
2890 /* src[0] = texcoord */
2891 /* src[1] = sampler unit */
2892 exec_tex(mach
, inst
, TEX_MODIFIER_NONE
);
2895 case TGSI_OPCODE_TXB
:
2896 /* Texture lookup with lod bias */
2897 /* src[0] = texcoord (src[0].w = LOD bias) */
2898 /* src[1] = sampler unit */
2899 exec_tex(mach
, inst
, TEX_MODIFIER_LOD_BIAS
);
2902 case TGSI_OPCODE_TXD
:
2903 /* Texture lookup with explict partial derivatives */
2904 /* src[0] = texcoord */
2905 /* src[1] = d[strq]/dx */
2906 /* src[2] = d[strq]/dy */
2907 /* src[3] = sampler unit */
2908 exec_txd(mach
, inst
);
2911 case TGSI_OPCODE_TXL
:
2912 /* Texture lookup with explit LOD */
2913 /* src[0] = texcoord (src[0].w = LOD) */
2914 /* src[1] = sampler unit */
2915 exec_tex(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
);
2918 case TGSI_OPCODE_TXP
:
2919 /* Texture lookup with projection */
2920 /* src[0] = texcoord (src[0].w = projection) */
2921 /* src[1] = sampler unit */
2922 exec_tex(mach
, inst
, TEX_MODIFIER_PROJECTED
);
2925 case TGSI_OPCODE_UP2H
:
2929 case TGSI_OPCODE_UP2US
:
2933 case TGSI_OPCODE_UP4B
:
2937 case TGSI_OPCODE_UP4UB
:
2941 case TGSI_OPCODE_X2D
:
2942 FETCH(&r
[0], 1, CHAN_X
);
2943 FETCH(&r
[1], 1, CHAN_Y
);
2944 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2945 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2946 FETCH(&r
[2], 2, CHAN_X
);
2947 micro_mul(&r
[2], &r
[2], &r
[0]);
2948 FETCH(&r
[3], 2, CHAN_Y
);
2949 micro_mul(&r
[3], &r
[3], &r
[1]);
2950 micro_add(&r
[2], &r
[2], &r
[3]);
2951 FETCH(&r
[3], 0, CHAN_X
);
2952 micro_add(&d
[CHAN_X
], &r
[2], &r
[3]);
2955 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2956 IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2957 FETCH(&r
[2], 2, CHAN_Z
);
2958 micro_mul(&r
[2], &r
[2], &r
[0]);
2959 FETCH(&r
[3], 2, CHAN_W
);
2960 micro_mul(&r
[3], &r
[3], &r
[1]);
2961 micro_add(&r
[2], &r
[2], &r
[3]);
2962 FETCH(&r
[3], 0, CHAN_Y
);
2963 micro_add(&d
[CHAN_Y
], &r
[2], &r
[3]);
2966 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2967 STORE(&d
[CHAN_X
], 0, CHAN_X
);
2969 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2970 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2972 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2973 STORE(&d
[CHAN_X
], 0, CHAN_Z
);
2975 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2976 STORE(&d
[CHAN_Y
], 0, CHAN_W
);
2980 case TGSI_OPCODE_ARA
:
2984 case TGSI_OPCODE_ARR
:
2985 exec_vector_unary(mach
, inst
, micro_arr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
2988 case TGSI_OPCODE_BRA
:
2992 case TGSI_OPCODE_CAL
:
2993 /* skip the call if no execution channels are enabled */
2994 if (mach
->ExecMask
) {
2997 /* First, record the depths of the execution stacks.
2998 * This is important for deeply nested/looped return statements.
2999 * We have to unwind the stacks by the correct amount. For a
3000 * real code generator, we could determine the number of entries
3001 * to pop off each stack with simple static analysis and avoid
3002 * implementing this data structure at run time.
3004 mach
->CallStack
[mach
->CallStackTop
].CondStackTop
= mach
->CondStackTop
;
3005 mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
= mach
->LoopStackTop
;
3006 mach
->CallStack
[mach
->CallStackTop
].ContStackTop
= mach
->ContStackTop
;
3007 mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
= mach
->SwitchStackTop
;
3008 mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
= mach
->BreakStackTop
;
3009 /* note that PC was already incremented above */
3010 mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
= *pc
;
3012 mach
->CallStackTop
++;
3014 /* Second, push the Cond, Loop, Cont, Func stacks */
3015 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
3016 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3017 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3018 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
3019 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
3020 assert(mach
->FuncStackTop
< TGSI_EXEC_MAX_CALL_NESTING
);
3022 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
3023 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
3024 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
3025 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
3026 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
3027 mach
->FuncStack
[mach
->FuncStackTop
++] = mach
->FuncMask
;
3029 /* Finally, jump to the subroutine */
3030 *pc
= inst
->Label
.Label
;
3034 case TGSI_OPCODE_RET
:
3035 mach
->FuncMask
&= ~mach
->ExecMask
;
3036 UPDATE_EXEC_MASK(mach
);
3038 if (mach
->FuncMask
== 0x0) {
3039 /* really return now (otherwise, keep executing */
3041 if (mach
->CallStackTop
== 0) {
3042 /* returning from main() */
3047 assert(mach
->CallStackTop
> 0);
3048 mach
->CallStackTop
--;
3050 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
3051 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
3053 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
3054 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
3056 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
3057 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
3059 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
3060 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
3062 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
3063 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
3065 assert(mach
->FuncStackTop
> 0);
3066 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
3068 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
3070 UPDATE_EXEC_MASK(mach
);
3074 case TGSI_OPCODE_SSG
:
3075 exec_vector_unary(mach
, inst
, micro_sgn
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3078 case TGSI_OPCODE_CMP
:
3079 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3080 FETCH(&r
[0], 0, chan_index
);
3081 FETCH(&r
[1], 1, chan_index
);
3082 FETCH(&r
[2], 2, chan_index
);
3083 micro_lt(&d
[chan_index
], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &r
[1], &r
[2]);
3085 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3086 STORE(&d
[chan_index
], 0, chan_index
);
3090 case TGSI_OPCODE_SCS
:
3091 if( IS_CHANNEL_ENABLED( *inst
, CHAN_X
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) ) {
3092 FETCH( &r
[0], 0, CHAN_X
);
3093 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
3094 micro_cos(&r
[1], &r
[0]);
3095 STORE(&r
[1], 0, CHAN_X
);
3097 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
3098 micro_sin(&r
[1], &r
[0]);
3099 STORE(&r
[1], 0, CHAN_Y
);
3102 if( IS_CHANNEL_ENABLED( *inst
, CHAN_Z
) ) {
3103 STORE( &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, CHAN_Z
);
3105 if( IS_CHANNEL_ENABLED( *inst
, CHAN_W
) ) {
3106 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
3110 case TGSI_OPCODE_NRM
:
3111 exec_nrm3(mach
, inst
);
3114 case TGSI_OPCODE_NRM4
:
3115 exec_nrm4(mach
, inst
);
3118 case TGSI_OPCODE_DIV
:
3122 case TGSI_OPCODE_DP2
:
3123 exec_dp2(mach
, inst
);
3126 case TGSI_OPCODE_IF
:
3128 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
3129 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
3130 FETCH( &r
[0], 0, CHAN_X
);
3131 /* update CondMask */
3133 mach
->CondMask
&= ~0x1;
3136 mach
->CondMask
&= ~0x2;
3139 mach
->CondMask
&= ~0x4;
3142 mach
->CondMask
&= ~0x8;
3144 UPDATE_EXEC_MASK(mach
);
3145 /* Todo: If CondMask==0, jump to ELSE */
3148 case TGSI_OPCODE_ELSE
:
3149 /* invert CondMask wrt previous mask */
3152 assert(mach
->CondStackTop
> 0);
3153 prevMask
= mach
->CondStack
[mach
->CondStackTop
- 1];
3154 mach
->CondMask
= ~mach
->CondMask
& prevMask
;
3155 UPDATE_EXEC_MASK(mach
);
3156 /* Todo: If CondMask==0, jump to ENDIF */
3160 case TGSI_OPCODE_ENDIF
:
3162 assert(mach
->CondStackTop
> 0);
3163 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
3164 UPDATE_EXEC_MASK(mach
);
3167 case TGSI_OPCODE_END
:
3168 /* halt execution */
3172 case TGSI_OPCODE_REP
:
3176 case TGSI_OPCODE_ENDREP
:
3180 case TGSI_OPCODE_PUSHA
:
3184 case TGSI_OPCODE_POPA
:
3188 case TGSI_OPCODE_CEIL
:
3189 exec_vector_unary(mach
, inst
, micro_ceil
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3192 case TGSI_OPCODE_I2F
:
3193 exec_vector_unary(mach
, inst
, micro_i2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_INT
);
3196 case TGSI_OPCODE_NOT
:
3197 exec_vector_unary(mach
, inst
, micro_not
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3200 case TGSI_OPCODE_TRUNC
:
3201 exec_vector_unary(mach
, inst
, micro_trunc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3204 case TGSI_OPCODE_SHL
:
3205 exec_vector_binary(mach
, inst
, micro_shl
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3208 case TGSI_OPCODE_AND
:
3209 exec_vector_binary(mach
, inst
, micro_and
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3212 case TGSI_OPCODE_OR
:
3213 exec_vector_binary(mach
, inst
, micro_or
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3216 case TGSI_OPCODE_MOD
:
3220 case TGSI_OPCODE_XOR
:
3221 exec_vector_binary(mach
, inst
, micro_xor
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3224 case TGSI_OPCODE_SAD
:
3228 case TGSI_OPCODE_TXF
:
3232 case TGSI_OPCODE_TXQ
:
3236 case TGSI_OPCODE_EMIT
:
3240 case TGSI_OPCODE_ENDPRIM
:
3241 emit_primitive(mach
);
3244 case TGSI_OPCODE_BGNFOR
:
3245 assert(mach
->LoopCounterStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3246 for (chan_index
= 0; chan_index
< 3; chan_index
++) {
3247 FETCH( &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[chan_index
], 0, chan_index
);
3249 ++mach
->LoopCounterStackTop
;
3250 STORE(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
], 0, CHAN_X
);
3251 /* update LoopMask */
3252 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[0] <= 0.0f
) {
3253 mach
->LoopMask
&= ~0x1;
3255 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[1] <= 0.0f
) {
3256 mach
->LoopMask
&= ~0x2;
3258 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[2] <= 0.0f
) {
3259 mach
->LoopMask
&= ~0x4;
3261 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[3] <= 0.0f
) {
3262 mach
->LoopMask
&= ~0x8;
3264 /* TODO: if mach->LoopMask == 0, jump to end of loop */
3265 UPDATE_EXEC_MASK(mach
);
3266 /* fall-through (for now) */
3267 case TGSI_OPCODE_BGNLOOP
:
3268 /* push LoopMask and ContMasks */
3269 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3270 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3271 assert(mach
->LoopLabelStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3272 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
3274 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
3275 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
3276 mach
->LoopLabelStack
[mach
->LoopLabelStackTop
++] = *pc
- 1;
3277 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
3278 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_LOOP
;
3281 case TGSI_OPCODE_ENDFOR
:
3282 assert(mach
->LoopCounterStackTop
> 0);
3283 micro_sub(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
],
3284 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
],
3285 &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
]);
3286 /* update LoopMask */
3287 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[0] <= 0.0f
) {
3288 mach
->LoopMask
&= ~0x1;
3290 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[1] <= 0.0f
) {
3291 mach
->LoopMask
&= ~0x2;
3293 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[2] <= 0.0f
) {
3294 mach
->LoopMask
&= ~0x4;
3296 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[3] <= 0.0f
) {
3297 mach
->LoopMask
&= ~0x8;
3299 micro_add(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
],
3300 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
],
3301 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Z
]);
3302 assert(mach
->LoopLabelStackTop
> 0);
3303 inst
= mach
->Instructions
+ mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1];
3304 STORE(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[CHAN_X
], 0, CHAN_X
);
3305 /* Restore ContMask, but don't pop */
3306 assert(mach
->ContStackTop
> 0);
3307 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3308 UPDATE_EXEC_MASK(mach
);
3309 if (mach
->ExecMask
) {
3310 /* repeat loop: jump to instruction just past BGNLOOP */
3311 assert(mach
->LoopLabelStackTop
> 0);
3312 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3315 /* exit loop: pop LoopMask */
3316 assert(mach
->LoopStackTop
> 0);
3317 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3319 assert(mach
->ContStackTop
> 0);
3320 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3321 assert(mach
->LoopLabelStackTop
> 0);
3322 --mach
->LoopLabelStackTop
;
3323 assert(mach
->LoopCounterStackTop
> 0);
3324 --mach
->LoopCounterStackTop
;
3326 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
3328 UPDATE_EXEC_MASK(mach
);
3331 case TGSI_OPCODE_ENDLOOP
:
3332 /* Restore ContMask, but don't pop */
3333 assert(mach
->ContStackTop
> 0);
3334 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3335 UPDATE_EXEC_MASK(mach
);
3336 if (mach
->ExecMask
) {
3337 /* repeat loop: jump to instruction just past BGNLOOP */
3338 assert(mach
->LoopLabelStackTop
> 0);
3339 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3342 /* exit loop: pop LoopMask */
3343 assert(mach
->LoopStackTop
> 0);
3344 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3346 assert(mach
->ContStackTop
> 0);
3347 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3348 assert(mach
->LoopLabelStackTop
> 0);
3349 --mach
->LoopLabelStackTop
;
3351 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
3353 UPDATE_EXEC_MASK(mach
);
3356 case TGSI_OPCODE_BRK
:
3360 case TGSI_OPCODE_CONT
:
3361 /* turn off cont channels for each enabled exec channel */
3362 mach
->ContMask
&= ~mach
->ExecMask
;
3363 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3364 UPDATE_EXEC_MASK(mach
);
3367 case TGSI_OPCODE_BGNSUB
:
3371 case TGSI_OPCODE_ENDSUB
:
3373 * XXX: This really should be a no-op. We should never reach this opcode.
3376 assert(mach
->CallStackTop
> 0);
3377 mach
->CallStackTop
--;
3379 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
3380 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
3382 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
3383 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
3385 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
3386 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
3388 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
3389 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
3391 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
3392 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
3394 assert(mach
->FuncStackTop
> 0);
3395 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
3397 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
3399 UPDATE_EXEC_MASK(mach
);
3402 case TGSI_OPCODE_NOP
:
3405 case TGSI_OPCODE_BREAKC
:
3406 FETCH(&r
[0], 0, CHAN_X
);
3407 /* update CondMask */
3408 if (r
[0].u
[0] && (mach
->ExecMask
& 0x1)) {
3409 mach
->LoopMask
&= ~0x1;
3411 if (r
[0].u
[1] && (mach
->ExecMask
& 0x2)) {
3412 mach
->LoopMask
&= ~0x2;
3414 if (r
[0].u
[2] && (mach
->ExecMask
& 0x4)) {
3415 mach
->LoopMask
&= ~0x4;
3417 if (r
[0].u
[3] && (mach
->ExecMask
& 0x8)) {
3418 mach
->LoopMask
&= ~0x8;
3420 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3421 UPDATE_EXEC_MASK(mach
);
3424 case TGSI_OPCODE_F2I
:
3425 exec_vector_unary(mach
, inst
, micro_f2i
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
3428 case TGSI_OPCODE_IDIV
:
3429 exec_vector_binary(mach
, inst
, micro_idiv
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3432 case TGSI_OPCODE_IMAX
:
3433 exec_vector_binary(mach
, inst
, micro_imax
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3436 case TGSI_OPCODE_IMIN
:
3437 exec_vector_binary(mach
, inst
, micro_imin
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3440 case TGSI_OPCODE_INEG
:
3441 exec_vector_unary(mach
, inst
, micro_ineg
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3444 case TGSI_OPCODE_ISGE
:
3445 exec_vector_binary(mach
, inst
, micro_isge
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3448 case TGSI_OPCODE_ISHR
:
3449 exec_vector_binary(mach
, inst
, micro_ishr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3452 case TGSI_OPCODE_ISLT
:
3453 exec_vector_binary(mach
, inst
, micro_islt
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3456 case TGSI_OPCODE_F2U
:
3457 exec_vector_unary(mach
, inst
, micro_f2u
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
3460 case TGSI_OPCODE_U2F
:
3461 exec_vector_unary(mach
, inst
, micro_u2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_UINT
);
3464 case TGSI_OPCODE_UADD
:
3465 exec_vector_binary(mach
, inst
, micro_uadd
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3468 case TGSI_OPCODE_UDIV
:
3469 exec_vector_binary(mach
, inst
, micro_udiv
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3472 case TGSI_OPCODE_UMAD
:
3473 exec_vector_trinary(mach
, inst
, micro_umad
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3476 case TGSI_OPCODE_UMAX
:
3477 exec_vector_binary(mach
, inst
, micro_umax
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3480 case TGSI_OPCODE_UMIN
:
3481 exec_vector_binary(mach
, inst
, micro_umin
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3484 case TGSI_OPCODE_UMOD
:
3485 exec_vector_binary(mach
, inst
, micro_umod
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3488 case TGSI_OPCODE_UMUL
:
3489 exec_vector_binary(mach
, inst
, micro_umul
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3492 case TGSI_OPCODE_USEQ
:
3493 exec_vector_binary(mach
, inst
, micro_useq
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3496 case TGSI_OPCODE_USGE
:
3497 exec_vector_binary(mach
, inst
, micro_usge
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3500 case TGSI_OPCODE_USHR
:
3501 exec_vector_binary(mach
, inst
, micro_ushr
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3504 case TGSI_OPCODE_USLT
:
3505 exec_vector_binary(mach
, inst
, micro_uslt
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3508 case TGSI_OPCODE_USNE
:
3509 exec_vector_binary(mach
, inst
, micro_usne
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3512 case TGSI_OPCODE_SWITCH
:
3513 exec_switch(mach
, inst
);
3516 case TGSI_OPCODE_CASE
:
3517 exec_case(mach
, inst
);
3520 case TGSI_OPCODE_DEFAULT
:
3524 case TGSI_OPCODE_ENDSWITCH
:
3525 exec_endswitch(mach
);
3534 #define DEBUG_EXECUTION 0
3538 * Run TGSI interpreter.
3539 * \return bitmask of "alive" quad components
3542 tgsi_exec_machine_run( struct tgsi_exec_machine
*mach
)
3547 mach
->CondMask
= 0xf;
3548 mach
->LoopMask
= 0xf;
3549 mach
->ContMask
= 0xf;
3550 mach
->FuncMask
= 0xf;
3551 mach
->ExecMask
= 0xf;
3553 mach
->Switch
.mask
= 0xf;
3555 assert(mach
->CondStackTop
== 0);
3556 assert(mach
->LoopStackTop
== 0);
3557 assert(mach
->ContStackTop
== 0);
3558 assert(mach
->SwitchStackTop
== 0);
3559 assert(mach
->BreakStackTop
== 0);
3560 assert(mach
->CallStackTop
== 0);
3562 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] = 0;
3563 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] = 0;
3565 if( mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
3566 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0] = 0;
3567 mach
->Primitives
[0] = 0;
3570 for (i
= 0; i
< QUAD_SIZE
; i
++) {
3571 mach
->Temps
[TEMP_CC_I
].xyzw
[TEMP_CC_C
].u
[i
] =
3572 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_X_SHIFT
) |
3573 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Y_SHIFT
) |
3574 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Z_SHIFT
) |
3575 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_W_SHIFT
);
3578 /* execute declarations (interpolants) */
3579 for (i
= 0; i
< mach
->NumDeclarations
; i
++) {
3580 exec_declaration( mach
, mach
->Declarations
+i
);
3585 struct tgsi_exec_vector temps
[TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
];
3586 struct tgsi_exec_vector outputs
[PIPE_MAX_ATTRIBS
];
3589 memcpy(temps
, mach
->Temps
, sizeof(temps
));
3590 memcpy(outputs
, mach
->Outputs
, sizeof(outputs
));
3593 /* execute instructions, until pc is set to -1 */
3599 tgsi_dump_instruction(&mach
->Instructions
[pc
], inst
++);
3602 assert(pc
< (int) mach
->NumInstructions
);
3603 exec_instruction(mach
, mach
->Instructions
+ pc
, &pc
);
3606 for (i
= 0; i
< TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
; i
++) {
3607 if (memcmp(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]))) {
3610 memcpy(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]));
3611 debug_printf("TEMP[%2u] = ", i
);
3612 for (j
= 0; j
< 4; j
++) {
3616 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
3617 temps
[i
].xyzw
[0].f
[j
], temps
[i
].xyzw
[0].u
[j
],
3618 temps
[i
].xyzw
[1].f
[j
], temps
[i
].xyzw
[1].u
[j
],
3619 temps
[i
].xyzw
[2].f
[j
], temps
[i
].xyzw
[2].u
[j
],
3620 temps
[i
].xyzw
[3].f
[j
], temps
[i
].xyzw
[3].u
[j
]);
3624 for (i
= 0; i
< PIPE_MAX_ATTRIBS
; i
++) {
3625 if (memcmp(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]))) {
3628 memcpy(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]));
3629 debug_printf("OUT[%2u] = ", i
);
3630 for (j
= 0; j
< 4; j
++) {
3634 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
3635 outputs
[i
].xyzw
[0].f
[j
], outputs
[i
].xyzw
[0].u
[j
],
3636 outputs
[i
].xyzw
[1].f
[j
], outputs
[i
].xyzw
[1].u
[j
],
3637 outputs
[i
].xyzw
[2].f
[j
], outputs
[i
].xyzw
[2].u
[j
],
3638 outputs
[i
].xyzw
[3].f
[j
], outputs
[i
].xyzw
[3].u
[j
]);
3647 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
3648 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
3650 * Scale back depth component.
3652 for (i
= 0; i
< 4; i
++)
3653 mach
->Outputs
[0].xyzw
[2].f
[i
] *= ctx
->DrawBuffer
->_DepthMaxF
;
3657 assert(mach
->CondStackTop
== 0);
3658 assert(mach
->LoopStackTop
== 0);
3659 assert(mach
->ContStackTop
== 0);
3660 assert(mach
->SwitchStackTop
== 0);
3661 assert(mach
->BreakStackTop
== 0);
3662 assert(mach
->CallStackTop
== 0);
3664 return ~mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];