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_clamp(union tgsi_exec_channel
*dst
,
114 const union tgsi_exec_channel
*src0
,
115 const union tgsi_exec_channel
*src1
,
116 const union tgsi_exec_channel
*src2
)
118 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src1
->f
[0] : src0
->f
[0] > src2
->f
[0] ? src2
->f
[0] : src0
->f
[0];
119 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src1
->f
[1] : src0
->f
[1] > src2
->f
[1] ? src2
->f
[1] : src0
->f
[1];
120 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src1
->f
[2] : src0
->f
[2] > src2
->f
[2] ? src2
->f
[2] : src0
->f
[2];
121 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src1
->f
[3] : src0
->f
[3] > src2
->f
[3] ? src2
->f
[3] : src0
->f
[3];
125 micro_cmp(union tgsi_exec_channel
*dst
,
126 const union tgsi_exec_channel
*src0
,
127 const union tgsi_exec_channel
*src1
,
128 const union tgsi_exec_channel
*src2
)
130 dst
->f
[0] = src0
->f
[0] < 0.0f
? src1
->f
[0] : src2
->f
[0];
131 dst
->f
[1] = src0
->f
[1] < 0.0f
? src1
->f
[1] : src2
->f
[1];
132 dst
->f
[2] = src0
->f
[2] < 0.0f
? src1
->f
[2] : src2
->f
[2];
133 dst
->f
[3] = src0
->f
[3] < 0.0f
? src1
->f
[3] : src2
->f
[3];
137 micro_cnd(union tgsi_exec_channel
*dst
,
138 const union tgsi_exec_channel
*src0
,
139 const union tgsi_exec_channel
*src1
,
140 const union tgsi_exec_channel
*src2
)
142 dst
->f
[0] = src2
->f
[0] > 0.5f
? src0
->f
[0] : src1
->f
[0];
143 dst
->f
[1] = src2
->f
[1] > 0.5f
? src0
->f
[1] : src1
->f
[1];
144 dst
->f
[2] = src2
->f
[2] > 0.5f
? src0
->f
[2] : src1
->f
[2];
145 dst
->f
[3] = src2
->f
[3] > 0.5f
? src0
->f
[3] : src1
->f
[3];
149 micro_cos(union tgsi_exec_channel
*dst
,
150 const union tgsi_exec_channel
*src
)
152 dst
->f
[0] = cosf(src
->f
[0]);
153 dst
->f
[1] = cosf(src
->f
[1]);
154 dst
->f
[2] = cosf(src
->f
[2]);
155 dst
->f
[3] = cosf(src
->f
[3]);
159 micro_ddx(union tgsi_exec_channel
*dst
,
160 const union tgsi_exec_channel
*src
)
165 dst
->f
[3] = src
->f
[TILE_BOTTOM_RIGHT
] - src
->f
[TILE_BOTTOM_LEFT
];
169 micro_ddy(union tgsi_exec_channel
*dst
,
170 const union tgsi_exec_channel
*src
)
175 dst
->f
[3] = src
->f
[TILE_BOTTOM_LEFT
] - src
->f
[TILE_TOP_LEFT
];
179 micro_exp2(union tgsi_exec_channel
*dst
,
180 const union tgsi_exec_channel
*src
)
183 dst
->f
[0] = util_fast_exp2(src
->f
[0]);
184 dst
->f
[1] = util_fast_exp2(src
->f
[1]);
185 dst
->f
[2] = util_fast_exp2(src
->f
[2]);
186 dst
->f
[3] = util_fast_exp2(src
->f
[3]);
189 /* Inf is okay for this instruction, so clamp it to silence assertions. */
191 union tgsi_exec_channel clamped
;
193 for (i
= 0; i
< 4; i
++) {
194 if (src
->f
[i
] > 127.99999f
) {
195 clamped
.f
[i
] = 127.99999f
;
196 } else if (src
->f
[i
] < -126.99999f
) {
197 clamped
.f
[i
] = -126.99999f
;
199 clamped
.f
[i
] = src
->f
[i
];
205 dst
->f
[0] = powf(2.0f
, src
->f
[0]);
206 dst
->f
[1] = powf(2.0f
, src
->f
[1]);
207 dst
->f
[2] = powf(2.0f
, src
->f
[2]);
208 dst
->f
[3] = powf(2.0f
, src
->f
[3]);
209 #endif /* FAST_MATH */
213 micro_flr(union tgsi_exec_channel
*dst
,
214 const union tgsi_exec_channel
*src
)
216 dst
->f
[0] = floorf(src
->f
[0]);
217 dst
->f
[1] = floorf(src
->f
[1]);
218 dst
->f
[2] = floorf(src
->f
[2]);
219 dst
->f
[3] = floorf(src
->f
[3]);
223 micro_frc(union tgsi_exec_channel
*dst
,
224 const union tgsi_exec_channel
*src
)
226 dst
->f
[0] = src
->f
[0] - floorf(src
->f
[0]);
227 dst
->f
[1] = src
->f
[1] - floorf(src
->f
[1]);
228 dst
->f
[2] = src
->f
[2] - floorf(src
->f
[2]);
229 dst
->f
[3] = src
->f
[3] - floorf(src
->f
[3]);
233 micro_iabs(union tgsi_exec_channel
*dst
,
234 const union tgsi_exec_channel
*src
)
236 dst
->i
[0] = src
->i
[0] >= 0 ? src
->i
[0] : -src
->i
[0];
237 dst
->i
[1] = src
->i
[1] >= 0 ? src
->i
[1] : -src
->i
[1];
238 dst
->i
[2] = src
->i
[2] >= 0 ? src
->i
[2] : -src
->i
[2];
239 dst
->i
[3] = src
->i
[3] >= 0 ? src
->i
[3] : -src
->i
[3];
243 micro_ineg(union tgsi_exec_channel
*dst
,
244 const union tgsi_exec_channel
*src
)
246 dst
->i
[0] = -src
->i
[0];
247 dst
->i
[1] = -src
->i
[1];
248 dst
->i
[2] = -src
->i
[2];
249 dst
->i
[3] = -src
->i
[3];
253 micro_lg2(union tgsi_exec_channel
*dst
,
254 const union tgsi_exec_channel
*src
)
257 dst
->f
[0] = util_fast_log2(src
->f
[0]);
258 dst
->f
[1] = util_fast_log2(src
->f
[1]);
259 dst
->f
[2] = util_fast_log2(src
->f
[2]);
260 dst
->f
[3] = util_fast_log2(src
->f
[3]);
262 dst
->f
[0] = logf(src
->f
[0]) * 1.442695f
;
263 dst
->f
[1] = logf(src
->f
[1]) * 1.442695f
;
264 dst
->f
[2] = logf(src
->f
[2]) * 1.442695f
;
265 dst
->f
[3] = logf(src
->f
[3]) * 1.442695f
;
270 micro_lrp(union tgsi_exec_channel
*dst
,
271 const union tgsi_exec_channel
*src0
,
272 const union tgsi_exec_channel
*src1
,
273 const union tgsi_exec_channel
*src2
)
275 dst
->f
[0] = src0
->f
[0] * (src1
->f
[0] - src2
->f
[0]) + src2
->f
[0];
276 dst
->f
[1] = src0
->f
[1] * (src1
->f
[1] - src2
->f
[1]) + src2
->f
[1];
277 dst
->f
[2] = src0
->f
[2] * (src1
->f
[2] - src2
->f
[2]) + src2
->f
[2];
278 dst
->f
[3] = src0
->f
[3] * (src1
->f
[3] - src2
->f
[3]) + src2
->f
[3];
282 micro_mad(union tgsi_exec_channel
*dst
,
283 const union tgsi_exec_channel
*src0
,
284 const union tgsi_exec_channel
*src1
,
285 const union tgsi_exec_channel
*src2
)
287 dst
->f
[0] = src0
->f
[0] * src1
->f
[0] + src2
->f
[0];
288 dst
->f
[1] = src0
->f
[1] * src1
->f
[1] + src2
->f
[1];
289 dst
->f
[2] = src0
->f
[2] * src1
->f
[2] + src2
->f
[2];
290 dst
->f
[3] = src0
->f
[3] * src1
->f
[3] + src2
->f
[3];
294 micro_mov(union tgsi_exec_channel
*dst
,
295 const union tgsi_exec_channel
*src
)
297 dst
->u
[0] = src
->u
[0];
298 dst
->u
[1] = src
->u
[1];
299 dst
->u
[2] = src
->u
[2];
300 dst
->u
[3] = src
->u
[3];
304 micro_rcp(union tgsi_exec_channel
*dst
,
305 const union tgsi_exec_channel
*src
)
307 #if 0 /* for debugging */
308 assert(src
->f
[0] != 0.0f
);
309 assert(src
->f
[1] != 0.0f
);
310 assert(src
->f
[2] != 0.0f
);
311 assert(src
->f
[3] != 0.0f
);
313 dst
->f
[0] = 1.0f
/ src
->f
[0];
314 dst
->f
[1] = 1.0f
/ src
->f
[1];
315 dst
->f
[2] = 1.0f
/ src
->f
[2];
316 dst
->f
[3] = 1.0f
/ src
->f
[3];
320 micro_rnd(union tgsi_exec_channel
*dst
,
321 const union tgsi_exec_channel
*src
)
323 dst
->f
[0] = floorf(src
->f
[0] + 0.5f
);
324 dst
->f
[1] = floorf(src
->f
[1] + 0.5f
);
325 dst
->f
[2] = floorf(src
->f
[2] + 0.5f
);
326 dst
->f
[3] = floorf(src
->f
[3] + 0.5f
);
330 micro_rsq(union tgsi_exec_channel
*dst
,
331 const union tgsi_exec_channel
*src
)
333 #if 0 /* for debugging */
334 assert(src
->f
[0] != 0.0f
);
335 assert(src
->f
[1] != 0.0f
);
336 assert(src
->f
[2] != 0.0f
);
337 assert(src
->f
[3] != 0.0f
);
339 dst
->f
[0] = 1.0f
/ sqrtf(fabsf(src
->f
[0]));
340 dst
->f
[1] = 1.0f
/ sqrtf(fabsf(src
->f
[1]));
341 dst
->f
[2] = 1.0f
/ sqrtf(fabsf(src
->f
[2]));
342 dst
->f
[3] = 1.0f
/ sqrtf(fabsf(src
->f
[3]));
346 micro_seq(union tgsi_exec_channel
*dst
,
347 const union tgsi_exec_channel
*src0
,
348 const union tgsi_exec_channel
*src1
)
350 dst
->f
[0] = src0
->f
[0] == src1
->f
[0] ? 1.0f
: 0.0f
;
351 dst
->f
[1] = src0
->f
[1] == src1
->f
[1] ? 1.0f
: 0.0f
;
352 dst
->f
[2] = src0
->f
[2] == src1
->f
[2] ? 1.0f
: 0.0f
;
353 dst
->f
[3] = src0
->f
[3] == src1
->f
[3] ? 1.0f
: 0.0f
;
357 micro_sge(union tgsi_exec_channel
*dst
,
358 const union tgsi_exec_channel
*src0
,
359 const union tgsi_exec_channel
*src1
)
361 dst
->f
[0] = src0
->f
[0] >= src1
->f
[0] ? 1.0f
: 0.0f
;
362 dst
->f
[1] = src0
->f
[1] >= src1
->f
[1] ? 1.0f
: 0.0f
;
363 dst
->f
[2] = src0
->f
[2] >= src1
->f
[2] ? 1.0f
: 0.0f
;
364 dst
->f
[3] = src0
->f
[3] >= src1
->f
[3] ? 1.0f
: 0.0f
;
368 micro_sgn(union tgsi_exec_channel
*dst
,
369 const union tgsi_exec_channel
*src
)
371 dst
->f
[0] = src
->f
[0] < 0.0f
? -1.0f
: src
->f
[0] > 0.0f
? 1.0f
: 0.0f
;
372 dst
->f
[1] = src
->f
[1] < 0.0f
? -1.0f
: src
->f
[1] > 0.0f
? 1.0f
: 0.0f
;
373 dst
->f
[2] = src
->f
[2] < 0.0f
? -1.0f
: src
->f
[2] > 0.0f
? 1.0f
: 0.0f
;
374 dst
->f
[3] = src
->f
[3] < 0.0f
? -1.0f
: src
->f
[3] > 0.0f
? 1.0f
: 0.0f
;
378 micro_sgt(union tgsi_exec_channel
*dst
,
379 const union tgsi_exec_channel
*src0
,
380 const union tgsi_exec_channel
*src1
)
382 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? 1.0f
: 0.0f
;
383 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? 1.0f
: 0.0f
;
384 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? 1.0f
: 0.0f
;
385 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? 1.0f
: 0.0f
;
389 micro_sin(union tgsi_exec_channel
*dst
,
390 const union tgsi_exec_channel
*src
)
392 dst
->f
[0] = sinf(src
->f
[0]);
393 dst
->f
[1] = sinf(src
->f
[1]);
394 dst
->f
[2] = sinf(src
->f
[2]);
395 dst
->f
[3] = sinf(src
->f
[3]);
399 micro_sle(union tgsi_exec_channel
*dst
,
400 const union tgsi_exec_channel
*src0
,
401 const union tgsi_exec_channel
*src1
)
403 dst
->f
[0] = src0
->f
[0] <= src1
->f
[0] ? 1.0f
: 0.0f
;
404 dst
->f
[1] = src0
->f
[1] <= src1
->f
[1] ? 1.0f
: 0.0f
;
405 dst
->f
[2] = src0
->f
[2] <= src1
->f
[2] ? 1.0f
: 0.0f
;
406 dst
->f
[3] = src0
->f
[3] <= src1
->f
[3] ? 1.0f
: 0.0f
;
410 micro_slt(union tgsi_exec_channel
*dst
,
411 const union tgsi_exec_channel
*src0
,
412 const union tgsi_exec_channel
*src1
)
414 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? 1.0f
: 0.0f
;
415 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? 1.0f
: 0.0f
;
416 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? 1.0f
: 0.0f
;
417 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? 1.0f
: 0.0f
;
421 micro_sne(union tgsi_exec_channel
*dst
,
422 const union tgsi_exec_channel
*src0
,
423 const union tgsi_exec_channel
*src1
)
425 dst
->f
[0] = src0
->f
[0] != src1
->f
[0] ? 1.0f
: 0.0f
;
426 dst
->f
[1] = src0
->f
[1] != src1
->f
[1] ? 1.0f
: 0.0f
;
427 dst
->f
[2] = src0
->f
[2] != src1
->f
[2] ? 1.0f
: 0.0f
;
428 dst
->f
[3] = src0
->f
[3] != src1
->f
[3] ? 1.0f
: 0.0f
;
432 micro_trunc(union tgsi_exec_channel
*dst
,
433 const union tgsi_exec_channel
*src
)
435 dst
->f
[0] = (float)(int)src
->f
[0];
436 dst
->f
[1] = (float)(int)src
->f
[1];
437 dst
->f
[2] = (float)(int)src
->f
[2];
438 dst
->f
[3] = (float)(int)src
->f
[3];
447 enum tgsi_exec_datatype
{
448 TGSI_EXEC_DATA_FLOAT
,
454 * Shorthand locations of various utility registers (_I = Index, _C = Channel)
456 #define TEMP_0_I TGSI_EXEC_TEMP_00000000_I
457 #define TEMP_0_C TGSI_EXEC_TEMP_00000000_C
458 #define TEMP_7F_I TGSI_EXEC_TEMP_7FFFFFFF_I
459 #define TEMP_7F_C TGSI_EXEC_TEMP_7FFFFFFF_C
460 #define TEMP_80_I TGSI_EXEC_TEMP_80000000_I
461 #define TEMP_80_C TGSI_EXEC_TEMP_80000000_C
462 #define TEMP_FF_I TGSI_EXEC_TEMP_FFFFFFFF_I
463 #define TEMP_FF_C TGSI_EXEC_TEMP_FFFFFFFF_C
464 #define TEMP_1_I TGSI_EXEC_TEMP_ONE_I
465 #define TEMP_1_C TGSI_EXEC_TEMP_ONE_C
466 #define TEMP_2_I TGSI_EXEC_TEMP_TWO_I
467 #define TEMP_2_C TGSI_EXEC_TEMP_TWO_C
468 #define TEMP_128_I TGSI_EXEC_TEMP_128_I
469 #define TEMP_128_C TGSI_EXEC_TEMP_128_C
470 #define TEMP_M128_I TGSI_EXEC_TEMP_MINUS_128_I
471 #define TEMP_M128_C TGSI_EXEC_TEMP_MINUS_128_C
472 #define TEMP_KILMASK_I TGSI_EXEC_TEMP_KILMASK_I
473 #define TEMP_KILMASK_C TGSI_EXEC_TEMP_KILMASK_C
474 #define TEMP_OUTPUT_I TGSI_EXEC_TEMP_OUTPUT_I
475 #define TEMP_OUTPUT_C TGSI_EXEC_TEMP_OUTPUT_C
476 #define TEMP_PRIMITIVE_I TGSI_EXEC_TEMP_PRIMITIVE_I
477 #define TEMP_PRIMITIVE_C TGSI_EXEC_TEMP_PRIMITIVE_C
478 #define TEMP_CC_I TGSI_EXEC_TEMP_CC_I
479 #define TEMP_CC_C TGSI_EXEC_TEMP_CC_C
480 #define TEMP_3_I TGSI_EXEC_TEMP_THREE_I
481 #define TEMP_3_C TGSI_EXEC_TEMP_THREE_C
482 #define TEMP_HALF_I TGSI_EXEC_TEMP_HALF_I
483 #define TEMP_HALF_C TGSI_EXEC_TEMP_HALF_C
484 #define TEMP_R0 TGSI_EXEC_TEMP_R0
485 #define TEMP_P0 TGSI_EXEC_TEMP_P0
487 #define IS_CHANNEL_ENABLED(INST, CHAN)\
488 ((INST).Dst[0].Register.WriteMask & (1 << (CHAN)))
490 #define IS_CHANNEL_ENABLED2(INST, CHAN)\
491 ((INST).Dst[1].Register.WriteMask & (1 << (CHAN)))
493 #define FOR_EACH_ENABLED_CHANNEL(INST, CHAN)\
494 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)\
495 if (IS_CHANNEL_ENABLED( INST, CHAN ))
497 #define FOR_EACH_ENABLED_CHANNEL2(INST, CHAN)\
498 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)\
499 if (IS_CHANNEL_ENABLED2( INST, CHAN ))
502 /** The execution mask depends on the conditional mask and the loop mask */
503 #define UPDATE_EXEC_MASK(MACH) \
504 MACH->ExecMask = MACH->CondMask & MACH->LoopMask & MACH->ContMask & MACH->Switch.mask & MACH->FuncMask
507 static const union tgsi_exec_channel ZeroVec
=
508 { { 0.0, 0.0, 0.0, 0.0 } };
510 static const union tgsi_exec_channel OneVec
= {
511 {1.0f
, 1.0f
, 1.0f
, 1.0f
}
516 * Assert that none of the float values in 'chan' are infinite or NaN.
517 * NaN and Inf may occur normally during program execution and should
518 * not lead to crashes, etc. But when debugging, it's helpful to catch
522 check_inf_or_nan(const union tgsi_exec_channel
*chan
)
524 assert(!util_is_inf_or_nan((chan
)->f
[0]));
525 assert(!util_is_inf_or_nan((chan
)->f
[1]));
526 assert(!util_is_inf_or_nan((chan
)->f
[2]));
527 assert(!util_is_inf_or_nan((chan
)->f
[3]));
533 print_chan(const char *msg
, const union tgsi_exec_channel
*chan
)
535 debug_printf("%s = {%f, %f, %f, %f}\n",
536 msg
, chan
->f
[0], chan
->f
[1], chan
->f
[2], chan
->f
[3]);
543 print_temp(const struct tgsi_exec_machine
*mach
, uint index
)
545 const struct tgsi_exec_vector
*tmp
= &mach
->Temps
[index
];
547 debug_printf("Temp[%u] =\n", index
);
548 for (i
= 0; i
< 4; i
++) {
549 debug_printf(" %c: { %f, %f, %f, %f }\n",
561 tgsi_exec_set_constant_buffers(struct tgsi_exec_machine
*mach
,
564 const unsigned *buf_sizes
)
568 for (i
= 0; i
< num_bufs
; i
++) {
569 mach
->Consts
[i
] = bufs
[i
];
570 mach
->ConstsSize
[i
] = buf_sizes
[i
];
578 * Check if there's a potential src/dst register data dependency when
579 * using SOA execution.
582 * This would expand into:
587 * The second instruction will have the wrong value for t0 if executed as-is.
590 tgsi_check_soa_dependencies(const struct tgsi_full_instruction
*inst
)
594 uint writemask
= inst
->Dst
[0].Register
.WriteMask
;
595 if (writemask
== TGSI_WRITEMASK_X
||
596 writemask
== TGSI_WRITEMASK_Y
||
597 writemask
== TGSI_WRITEMASK_Z
||
598 writemask
== TGSI_WRITEMASK_W
||
599 writemask
== TGSI_WRITEMASK_NONE
) {
600 /* no chance of data dependency */
604 /* loop over src regs */
605 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
606 if ((inst
->Src
[i
].Register
.File
==
607 inst
->Dst
[0].Register
.File
) &&
608 ((inst
->Src
[i
].Register
.Index
==
609 inst
->Dst
[0].Register
.Index
) ||
610 inst
->Src
[i
].Register
.Indirect
||
611 inst
->Dst
[0].Register
.Indirect
)) {
612 /* loop over dest channels */
613 uint channelsWritten
= 0x0;
614 FOR_EACH_ENABLED_CHANNEL(*inst
, chan
) {
615 /* check if we're reading a channel that's been written */
616 uint swizzle
= tgsi_util_get_full_src_register_swizzle(&inst
->Src
[i
], chan
);
617 if (channelsWritten
& (1 << swizzle
)) {
621 channelsWritten
|= (1 << chan
);
630 * Initialize machine state by expanding tokens to full instructions,
631 * allocating temporary storage, setting up constants, etc.
632 * After this, we can call tgsi_exec_machine_run() many times.
635 tgsi_exec_machine_bind_shader(
636 struct tgsi_exec_machine
*mach
,
637 const struct tgsi_token
*tokens
,
639 struct tgsi_sampler
**samplers
)
642 struct tgsi_parse_context parse
;
643 struct tgsi_full_instruction
*instructions
;
644 struct tgsi_full_declaration
*declarations
;
645 uint maxInstructions
= 10, numInstructions
= 0;
646 uint maxDeclarations
= 10, numDeclarations
= 0;
649 tgsi_dump(tokens
, 0);
658 mach
->Tokens
= tokens
;
659 mach
->Samplers
= samplers
;
662 /* unbind and free all */
663 if (mach
->Declarations
) {
664 FREE( mach
->Declarations
);
666 mach
->Declarations
= NULL
;
667 mach
->NumDeclarations
= 0;
669 if (mach
->Instructions
) {
670 FREE( mach
->Instructions
);
672 mach
->Instructions
= NULL
;
673 mach
->NumInstructions
= 0;
678 k
= tgsi_parse_init (&parse
, mach
->Tokens
);
679 if (k
!= TGSI_PARSE_OK
) {
680 debug_printf( "Problem parsing!\n" );
684 mach
->Processor
= parse
.FullHeader
.Processor
.Processor
;
687 declarations
= (struct tgsi_full_declaration
*)
688 MALLOC( maxDeclarations
* sizeof(struct tgsi_full_declaration
) );
694 instructions
= (struct tgsi_full_instruction
*)
695 MALLOC( maxInstructions
* sizeof(struct tgsi_full_instruction
) );
698 FREE( declarations
);
702 while( !tgsi_parse_end_of_tokens( &parse
) ) {
705 tgsi_parse_token( &parse
);
706 switch( parse
.FullToken
.Token
.Type
) {
707 case TGSI_TOKEN_TYPE_DECLARATION
:
708 /* save expanded declaration */
709 if (numDeclarations
== maxDeclarations
) {
710 declarations
= REALLOC(declarations
,
712 * sizeof(struct tgsi_full_declaration
),
713 (maxDeclarations
+ 10)
714 * sizeof(struct tgsi_full_declaration
));
715 maxDeclarations
+= 10;
717 if (parse
.FullToken
.FullDeclaration
.Declaration
.File
== TGSI_FILE_OUTPUT
) {
719 for (reg
= parse
.FullToken
.FullDeclaration
.Range
.First
;
720 reg
<= parse
.FullToken
.FullDeclaration
.Range
.Last
;
725 if (parse
.FullToken
.FullDeclaration
.Declaration
.File
==
726 TGSI_FILE_IMMEDIATE_ARRAY
) {
728 struct tgsi_full_declaration
*decl
=
729 &parse
.FullToken
.FullDeclaration
;
730 debug_assert(decl
->Range
.Last
< TGSI_EXEC_NUM_IMMEDIATES
);
731 for (reg
= decl
->Range
.First
; reg
<= decl
->Range
.Last
; ++reg
) {
732 for( i
= 0; i
< 4; i
++ ) {
733 int idx
= reg
* 4 + i
;
734 mach
->ImmArray
[reg
][i
] = decl
->ImmediateData
.u
[idx
].Float
;
738 memcpy(declarations
+ numDeclarations
,
739 &parse
.FullToken
.FullDeclaration
,
740 sizeof(declarations
[0]));
744 case TGSI_TOKEN_TYPE_IMMEDIATE
:
746 uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
748 assert( mach
->ImmLimit
+ 1 <= TGSI_EXEC_NUM_IMMEDIATES
);
750 for( i
= 0; i
< size
; i
++ ) {
751 mach
->Imms
[mach
->ImmLimit
][i
] =
752 parse
.FullToken
.FullImmediate
.u
[i
].Float
;
758 case TGSI_TOKEN_TYPE_INSTRUCTION
:
760 /* save expanded instruction */
761 if (numInstructions
== maxInstructions
) {
762 instructions
= REALLOC(instructions
,
764 * sizeof(struct tgsi_full_instruction
),
765 (maxInstructions
+ 10)
766 * sizeof(struct tgsi_full_instruction
));
767 maxInstructions
+= 10;
770 memcpy(instructions
+ numInstructions
,
771 &parse
.FullToken
.FullInstruction
,
772 sizeof(instructions
[0]));
777 case TGSI_TOKEN_TYPE_PROPERTY
:
784 tgsi_parse_free (&parse
);
786 if (mach
->Declarations
) {
787 FREE( mach
->Declarations
);
789 mach
->Declarations
= declarations
;
790 mach
->NumDeclarations
= numDeclarations
;
792 if (mach
->Instructions
) {
793 FREE( mach
->Instructions
);
795 mach
->Instructions
= instructions
;
796 mach
->NumInstructions
= numInstructions
;
800 struct tgsi_exec_machine
*
801 tgsi_exec_machine_create( void )
803 struct tgsi_exec_machine
*mach
;
806 mach
= align_malloc( sizeof *mach
, 16 );
810 memset(mach
, 0, sizeof(*mach
));
812 mach
->Addrs
= &mach
->Temps
[TGSI_EXEC_TEMP_ADDR
];
813 mach
->MaxGeometryShaderOutputs
= TGSI_MAX_TOTAL_VERTICES
;
814 mach
->Predicates
= &mach
->Temps
[TGSI_EXEC_TEMP_P0
];
816 /* Setup constants. */
817 for( i
= 0; i
< 4; i
++ ) {
818 mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
].u
[i
] = 0x00000000;
819 mach
->Temps
[TEMP_7F_I
].xyzw
[TEMP_7F_C
].u
[i
] = 0x7FFFFFFF;
820 mach
->Temps
[TEMP_80_I
].xyzw
[TEMP_80_C
].u
[i
] = 0x80000000;
821 mach
->Temps
[TEMP_FF_I
].xyzw
[TEMP_FF_C
].u
[i
] = 0xFFFFFFFF;
822 mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
].f
[i
] = 1.0f
;
823 mach
->Temps
[TEMP_2_I
].xyzw
[TEMP_2_C
].f
[i
] = 2.0f
;
824 mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
].f
[i
] = 128.0f
;
825 mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
].f
[i
] = -128.0f
;
826 mach
->Temps
[TEMP_3_I
].xyzw
[TEMP_3_C
].f
[i
] = 3.0f
;
827 mach
->Temps
[TEMP_HALF_I
].xyzw
[TEMP_HALF_C
].f
[i
] = 0.5f
;
831 /* silence warnings */
845 tgsi_exec_machine_destroy(struct tgsi_exec_machine
*mach
)
848 if (mach
->Instructions
)
849 FREE(mach
->Instructions
);
850 if (mach
->Declarations
)
851 FREE(mach
->Declarations
);
858 micro_add(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];
863 dst
->f
[1] = src0
->f
[1] + src1
->f
[1];
864 dst
->f
[2] = src0
->f
[2] + src1
->f
[2];
865 dst
->f
[3] = src0
->f
[3] + src1
->f
[3];
870 union tgsi_exec_channel
*dst
,
871 const union tgsi_exec_channel
*src0
,
872 const union tgsi_exec_channel
*src1
)
874 if (src1
->f
[0] != 0) {
875 dst
->f
[0] = src0
->f
[0] / src1
->f
[0];
877 if (src1
->f
[1] != 0) {
878 dst
->f
[1] = src0
->f
[1] / src1
->f
[1];
880 if (src1
->f
[2] != 0) {
881 dst
->f
[2] = src0
->f
[2] / src1
->f
[2];
883 if (src1
->f
[3] != 0) {
884 dst
->f
[3] = src0
->f
[3] / src1
->f
[3];
889 micro_float_clamp(union tgsi_exec_channel
*dst
,
890 const union tgsi_exec_channel
*src
)
894 for (i
= 0; i
< 4; i
++) {
895 if (src
->f
[i
] > 0.0f
) {
896 if (src
->f
[i
] > 1.884467e+019f
)
897 dst
->f
[i
] = 1.884467e+019f
;
898 else if (src
->f
[i
] < 5.42101e-020f
)
899 dst
->f
[i
] = 5.42101e-020f
;
901 dst
->f
[i
] = src
->f
[i
];
904 if (src
->f
[i
] < -1.884467e+019f
)
905 dst
->f
[i
] = -1.884467e+019f
;
906 else if (src
->f
[i
] > -5.42101e-020f
)
907 dst
->f
[i
] = -5.42101e-020f
;
909 dst
->f
[i
] = src
->f
[i
];
916 union tgsi_exec_channel
*dst
,
917 const union tgsi_exec_channel
*src0
,
918 const union tgsi_exec_channel
*src1
,
919 const union tgsi_exec_channel
*src2
,
920 const union tgsi_exec_channel
*src3
)
922 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
923 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
924 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
925 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
929 micro_max(union tgsi_exec_channel
*dst
,
930 const union tgsi_exec_channel
*src0
,
931 const union tgsi_exec_channel
*src1
)
933 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
934 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
935 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
936 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
940 micro_min(union tgsi_exec_channel
*dst
,
941 const union tgsi_exec_channel
*src0
,
942 const union tgsi_exec_channel
*src1
)
944 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
945 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
946 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
947 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
951 micro_mul(union tgsi_exec_channel
*dst
,
952 const union tgsi_exec_channel
*src0
,
953 const union tgsi_exec_channel
*src1
)
955 dst
->f
[0] = src0
->f
[0] * src1
->f
[0];
956 dst
->f
[1] = src0
->f
[1] * src1
->f
[1];
957 dst
->f
[2] = src0
->f
[2] * src1
->f
[2];
958 dst
->f
[3] = src0
->f
[3] * src1
->f
[3];
964 union tgsi_exec_channel
*dst0
,
965 union tgsi_exec_channel
*dst1
,
966 const union tgsi_exec_channel
*src0
,
967 const union tgsi_exec_channel
*src1
)
969 dst1
->i
[0] = src0
->i
[0] * src1
->i
[0];
970 dst1
->i
[1] = src0
->i
[1] * src1
->i
[1];
971 dst1
->i
[2] = src0
->i
[2] * src1
->i
[2];
972 dst1
->i
[3] = src0
->i
[3] * src1
->i
[3];
983 union tgsi_exec_channel
*dst0
,
984 union tgsi_exec_channel
*dst1
,
985 const union tgsi_exec_channel
*src0
,
986 const union tgsi_exec_channel
*src1
)
988 dst1
->u
[0] = src0
->u
[0] * src1
->u
[0];
989 dst1
->u
[1] = src0
->u
[1] * src1
->u
[1];
990 dst1
->u
[2] = src0
->u
[2] * src1
->u
[2];
991 dst1
->u
[3] = src0
->u
[3] * src1
->u
[3];
1003 union tgsi_exec_channel
*dst
,
1004 const union tgsi_exec_channel
*src0
,
1005 const union tgsi_exec_channel
*src1
,
1006 const union tgsi_exec_channel
*src2
)
1008 dst
->u
[0] = src0
->u
[0] ? src1
->u
[0] : src2
->u
[0];
1009 dst
->u
[1] = src0
->u
[1] ? src1
->u
[1] : src2
->u
[1];
1010 dst
->u
[2] = src0
->u
[2] ? src1
->u
[2] : src2
->u
[2];
1011 dst
->u
[3] = src0
->u
[3] ? src1
->u
[3] : src2
->u
[3];
1017 union tgsi_exec_channel
*dst
,
1018 const union tgsi_exec_channel
*src
)
1020 dst
->f
[0] = -src
->f
[0];
1021 dst
->f
[1] = -src
->f
[1];
1022 dst
->f
[2] = -src
->f
[2];
1023 dst
->f
[3] = -src
->f
[3];
1028 union tgsi_exec_channel
*dst
,
1029 const union tgsi_exec_channel
*src0
,
1030 const union tgsi_exec_channel
*src1
)
1033 dst
->f
[0] = util_fast_pow( src0
->f
[0], src1
->f
[0] );
1034 dst
->f
[1] = util_fast_pow( src0
->f
[1], src1
->f
[1] );
1035 dst
->f
[2] = util_fast_pow( src0
->f
[2], src1
->f
[2] );
1036 dst
->f
[3] = util_fast_pow( src0
->f
[3], src1
->f
[3] );
1038 dst
->f
[0] = powf( src0
->f
[0], src1
->f
[0] );
1039 dst
->f
[1] = powf( src0
->f
[1], src1
->f
[1] );
1040 dst
->f
[2] = powf( src0
->f
[2], src1
->f
[2] );
1041 dst
->f
[3] = powf( src0
->f
[3], src1
->f
[3] );
1046 micro_sub(union tgsi_exec_channel
*dst
,
1047 const union tgsi_exec_channel
*src0
,
1048 const union tgsi_exec_channel
*src1
)
1050 dst
->f
[0] = src0
->f
[0] - src1
->f
[0];
1051 dst
->f
[1] = src0
->f
[1] - src1
->f
[1];
1052 dst
->f
[2] = src0
->f
[2] - src1
->f
[2];
1053 dst
->f
[3] = src0
->f
[3] - src1
->f
[3];
1057 fetch_src_file_channel(const struct tgsi_exec_machine
*mach
,
1060 const union tgsi_exec_channel
*index
,
1061 const union tgsi_exec_channel
*index2D
,
1062 union tgsi_exec_channel
*chan
)
1066 assert(swizzle
< 4);
1069 case TGSI_FILE_CONSTANT
:
1070 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1071 assert(index2D
->i
[i
] >= 0 && index2D
->i
[i
] < PIPE_MAX_CONSTANT_BUFFERS
);
1072 assert(mach
->Consts
[index2D
->i
[i
]]);
1074 if (index
->i
[i
] < 0) {
1077 /* NOTE: copying the const value as a uint instead of float */
1078 const uint constbuf
= index2D
->i
[i
];
1079 const uint
*buf
= (const uint
*)mach
->Consts
[constbuf
];
1080 const int pos
= index
->i
[i
] * 4 + swizzle
;
1081 /* const buffer bounds check */
1082 if (pos
< 0 || pos
>= mach
->ConstsSize
[constbuf
]) {
1084 /* Debug: print warning */
1085 static int count
= 0;
1087 debug_printf("TGSI Exec: const buffer index %d"
1088 " out of bounds\n", pos
);
1093 chan
->u
[i
] = buf
[pos
];
1098 case TGSI_FILE_INPUT
:
1099 case TGSI_FILE_SYSTEM_VALUE
:
1100 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1102 if (TGSI_PROCESSOR_GEOMETRY == mach->Processor) {
1103 debug_printf("Fetching Input[%d] (2d=%d, 1d=%d)\n",
1104 index2D->i[i] * TGSI_EXEC_MAX_INPUT_ATTRIBS + index->i[i],
1105 index2D->i[i], index->i[i]);
1107 int pos
= index2D
->i
[i
] * TGSI_EXEC_MAX_INPUT_ATTRIBS
+ index
->i
[i
];
1109 assert(pos
< Elements(mach
->Inputs
));
1110 chan
->u
[i
] = mach
->Inputs
[pos
].xyzw
[swizzle
].u
[i
];
1114 case TGSI_FILE_TEMPORARY
:
1115 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1116 assert(index
->i
[i
] < TGSI_EXEC_NUM_TEMPS
);
1117 assert(index2D
->i
[i
] == 0);
1119 chan
->u
[i
] = mach
->Temps
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1123 case TGSI_FILE_TEMPORARY_ARRAY
:
1124 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1125 assert(index
->i
[i
] < TGSI_EXEC_NUM_TEMPS
);
1126 assert(index2D
->i
[i
] < TGSI_EXEC_NUM_TEMP_ARRAYS
);
1129 mach
->TempArray
[index2D
->i
[i
]][index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1133 case TGSI_FILE_IMMEDIATE
:
1134 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1135 assert(index
->i
[i
] >= 0 && index
->i
[i
] < (int)mach
->ImmLimit
);
1136 assert(index2D
->i
[i
] == 0);
1138 chan
->f
[i
] = mach
->Imms
[index
->i
[i
]][swizzle
];
1142 case TGSI_FILE_IMMEDIATE_ARRAY
:
1143 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1144 assert(index2D
->i
[i
] == 0);
1146 chan
->f
[i
] = mach
->ImmArray
[index
->i
[i
]][swizzle
];
1150 case TGSI_FILE_ADDRESS
:
1151 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1152 assert(index
->i
[i
] >= 0);
1153 assert(index2D
->i
[i
] == 0);
1155 chan
->u
[i
] = mach
->Addrs
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1159 case TGSI_FILE_PREDICATE
:
1160 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1161 assert(index
->i
[i
] >= 0 && index
->i
[i
] < TGSI_EXEC_NUM_PREDS
);
1162 assert(index2D
->i
[i
] == 0);
1164 chan
->u
[i
] = mach
->Predicates
[0].xyzw
[swizzle
].u
[i
];
1168 case TGSI_FILE_OUTPUT
:
1169 /* vertex/fragment output vars can be read too */
1170 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1171 assert(index
->i
[i
] >= 0);
1172 assert(index2D
->i
[i
] == 0);
1174 chan
->u
[i
] = mach
->Outputs
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1180 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1187 fetch_source(const struct tgsi_exec_machine
*mach
,
1188 union tgsi_exec_channel
*chan
,
1189 const struct tgsi_full_src_register
*reg
,
1190 const uint chan_index
,
1191 enum tgsi_exec_datatype src_datatype
)
1193 union tgsi_exec_channel index
;
1194 union tgsi_exec_channel index2D
;
1197 /* We start with a direct index into a register file.
1201 * file = Register.File
1202 * [1] = Register.Index
1207 index
.i
[3] = reg
->Register
.Index
;
1209 /* There is an extra source register that indirectly subscripts
1210 * a register file. The direct index now becomes an offset
1211 * that is being added to the indirect register.
1215 * ind = Indirect.File
1216 * [2] = Indirect.Index
1217 * .x = Indirect.SwizzleX
1219 if (reg
->Register
.Indirect
) {
1220 union tgsi_exec_channel index2
;
1221 union tgsi_exec_channel indir_index
;
1222 const uint execmask
= mach
->ExecMask
;
1225 /* which address register (always zero now) */
1229 index2
.i
[3] = reg
->Indirect
.Index
;
1230 assert(reg
->Indirect
.File
== TGSI_FILE_ADDRESS
);
1231 /* get current value of address register[swizzle] */
1232 swizzle
= tgsi_util_get_src_register_swizzle( ®
->Indirect
, CHAN_X
);
1233 fetch_src_file_channel(mach
,
1240 /* add value of address register to the offset */
1241 index
.i
[0] += indir_index
.i
[0];
1242 index
.i
[1] += indir_index
.i
[1];
1243 index
.i
[2] += indir_index
.i
[2];
1244 index
.i
[3] += indir_index
.i
[3];
1246 /* for disabled execution channels, zero-out the index to
1247 * avoid using a potential garbage value.
1249 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1250 if ((execmask
& (1 << i
)) == 0)
1255 /* There is an extra source register that is a second
1256 * subscript to a register file. Effectively it means that
1257 * the register file is actually a 2D array of registers.
1261 * [3] = Dimension.Index
1263 if (reg
->Register
.Dimension
) {
1267 index2D
.i
[3] = reg
->Dimension
.Index
;
1269 /* Again, the second subscript index can be addressed indirectly
1270 * identically to the first one.
1271 * Nothing stops us from indirectly addressing the indirect register,
1272 * but there is no need for that, so we won't exercise it.
1274 * file[ind[4].y+3][1],
1276 * ind = DimIndirect.File
1277 * [4] = DimIndirect.Index
1278 * .y = DimIndirect.SwizzleX
1280 if (reg
->Dimension
.Indirect
) {
1281 union tgsi_exec_channel index2
;
1282 union tgsi_exec_channel indir_index
;
1283 const uint execmask
= mach
->ExecMask
;
1289 index2
.i
[3] = reg
->DimIndirect
.Index
;
1291 swizzle
= tgsi_util_get_src_register_swizzle( ®
->DimIndirect
, CHAN_X
);
1292 fetch_src_file_channel(mach
,
1293 reg
->DimIndirect
.File
,
1299 index2D
.i
[0] += indir_index
.i
[0];
1300 index2D
.i
[1] += indir_index
.i
[1];
1301 index2D
.i
[2] += indir_index
.i
[2];
1302 index2D
.i
[3] += indir_index
.i
[3];
1304 /* for disabled execution channels, zero-out the index to
1305 * avoid using a potential garbage value.
1307 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1308 if ((execmask
& (1 << i
)) == 0) {
1314 /* If by any chance there was a need for a 3D array of register
1315 * files, we would have to check whether Dimension is followed
1316 * by a dimension register and continue the saga.
1325 swizzle
= tgsi_util_get_full_src_register_swizzle( reg
, chan_index
);
1326 fetch_src_file_channel(mach
,
1333 if (reg
->Register
.Absolute
) {
1334 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1335 micro_abs(chan
, chan
);
1337 micro_iabs(chan
, chan
);
1341 if (reg
->Register
.Negate
) {
1342 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1343 micro_neg(chan
, chan
);
1345 micro_ineg(chan
, chan
);
1351 store_dest(struct tgsi_exec_machine
*mach
,
1352 const union tgsi_exec_channel
*chan
,
1353 const struct tgsi_full_dst_register
*reg
,
1354 const struct tgsi_full_instruction
*inst
,
1356 enum tgsi_exec_datatype dst_datatype
)
1359 union tgsi_exec_channel null
;
1360 union tgsi_exec_channel
*dst
;
1361 union tgsi_exec_channel index2D
;
1362 uint execmask
= mach
->ExecMask
;
1363 int offset
= 0; /* indirection offset */
1367 if (0 && dst_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1368 check_inf_or_nan(chan
);
1371 /* There is an extra source register that indirectly subscripts
1372 * a register file. The direct index now becomes an offset
1373 * that is being added to the indirect register.
1377 * ind = Indirect.File
1378 * [2] = Indirect.Index
1379 * .x = Indirect.SwizzleX
1381 if (reg
->Register
.Indirect
) {
1382 union tgsi_exec_channel index
;
1383 union tgsi_exec_channel indir_index
;
1386 /* which address register (always zero for now) */
1390 index
.i
[3] = reg
->Indirect
.Index
;
1392 /* get current value of address register[swizzle] */
1393 swizzle
= tgsi_util_get_src_register_swizzle( ®
->Indirect
, CHAN_X
);
1395 /* fetch values from the address/indirection register */
1396 fetch_src_file_channel(mach
,
1403 /* save indirection offset */
1404 offset
= indir_index
.i
[0];
1407 /* There is an extra source register that is a second
1408 * subscript to a register file. Effectively it means that
1409 * the register file is actually a 2D array of registers.
1413 * [3] = Dimension.Index
1415 if (reg
->Register
.Dimension
) {
1419 index2D
.i
[3] = reg
->Dimension
.Index
;
1421 /* Again, the second subscript index can be addressed indirectly
1422 * identically to the first one.
1423 * Nothing stops us from indirectly addressing the indirect register,
1424 * but there is no need for that, so we won't exercise it.
1426 * file[ind[4].y+3][1],
1428 * ind = DimIndirect.File
1429 * [4] = DimIndirect.Index
1430 * .y = DimIndirect.SwizzleX
1432 if (reg
->Dimension
.Indirect
) {
1433 union tgsi_exec_channel index2
;
1434 union tgsi_exec_channel indir_index
;
1435 const uint execmask
= mach
->ExecMask
;
1442 index2
.i
[3] = reg
->DimIndirect
.Index
;
1444 swizzle
= tgsi_util_get_src_register_swizzle( ®
->DimIndirect
, CHAN_X
);
1445 fetch_src_file_channel(mach
,
1446 reg
->DimIndirect
.File
,
1452 index2D
.i
[0] += indir_index
.i
[0];
1453 index2D
.i
[1] += indir_index
.i
[1];
1454 index2D
.i
[2] += indir_index
.i
[2];
1455 index2D
.i
[3] += indir_index
.i
[3];
1457 /* for disabled execution channels, zero-out the index to
1458 * avoid using a potential garbage value.
1460 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1461 if ((execmask
& (1 << i
)) == 0) {
1467 /* If by any chance there was a need for a 3D array of register
1468 * files, we would have to check whether Dimension is followed
1469 * by a dimension register and continue the saga.
1478 switch (reg
->Register
.File
) {
1479 case TGSI_FILE_NULL
:
1483 case TGSI_FILE_OUTPUT
:
1484 index
= mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0]
1485 + reg
->Register
.Index
;
1486 dst
= &mach
->Outputs
[offset
+ index
].xyzw
[chan_index
];
1488 if (TGSI_PROCESSOR_GEOMETRY
== mach
->Processor
) {
1489 fprintf(stderr
, "STORING OUT[%d] mask(%d), = (", offset
+ index
, execmask
);
1490 for (i
= 0; i
< QUAD_SIZE
; i
++)
1491 if (execmask
& (1 << i
))
1492 fprintf(stderr
, "%f, ", chan
->f
[i
]);
1493 fprintf(stderr
, ")\n");
1498 case TGSI_FILE_TEMPORARY
:
1499 index
= reg
->Register
.Index
;
1500 assert( index
< TGSI_EXEC_NUM_TEMPS
);
1501 dst
= &mach
->Temps
[offset
+ index
].xyzw
[chan_index
];
1504 case TGSI_FILE_TEMPORARY_ARRAY
:
1505 index
= reg
->Register
.Index
;
1506 assert( index
< TGSI_EXEC_NUM_TEMPS
);
1507 assert( index2D
.i
[0] < TGSI_EXEC_NUM_TEMP_ARRAYS
);
1508 /* XXX we use index2D.i[0] here but somehow we might
1509 * end up with someone trying to store indirectly in
1510 * different buffers */
1511 dst
= &mach
->TempArray
[index2D
.i
[0]][offset
+ index
].xyzw
[chan_index
];
1514 case TGSI_FILE_ADDRESS
:
1515 index
= reg
->Register
.Index
;
1516 dst
= &mach
->Addrs
[index
].xyzw
[chan_index
];
1519 case TGSI_FILE_PREDICATE
:
1520 index
= reg
->Register
.Index
;
1521 assert(index
< TGSI_EXEC_NUM_PREDS
);
1522 dst
= &mach
->Predicates
[index
].xyzw
[chan_index
];
1530 if (inst
->Instruction
.Predicate
) {
1532 union tgsi_exec_channel
*pred
;
1534 switch (chan_index
) {
1536 swizzle
= inst
->Predicate
.SwizzleX
;
1539 swizzle
= inst
->Predicate
.SwizzleY
;
1542 swizzle
= inst
->Predicate
.SwizzleZ
;
1545 swizzle
= inst
->Predicate
.SwizzleW
;
1552 assert(inst
->Predicate
.Index
== 0);
1554 pred
= &mach
->Predicates
[inst
->Predicate
.Index
].xyzw
[swizzle
];
1556 if (inst
->Predicate
.Negate
) {
1557 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1559 execmask
&= ~(1 << i
);
1563 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1565 execmask
&= ~(1 << i
);
1571 switch (inst
->Instruction
.Saturate
) {
1573 for (i
= 0; i
< QUAD_SIZE
; i
++)
1574 if (execmask
& (1 << i
))
1575 dst
->i
[i
] = chan
->i
[i
];
1578 case TGSI_SAT_ZERO_ONE
:
1579 for (i
= 0; i
< QUAD_SIZE
; i
++)
1580 if (execmask
& (1 << i
)) {
1581 if (chan
->f
[i
] < 0.0f
)
1583 else if (chan
->f
[i
] > 1.0f
)
1586 dst
->i
[i
] = chan
->i
[i
];
1590 case TGSI_SAT_MINUS_PLUS_ONE
:
1591 for (i
= 0; i
< QUAD_SIZE
; i
++)
1592 if (execmask
& (1 << i
)) {
1593 if (chan
->f
[i
] < -1.0f
)
1595 else if (chan
->f
[i
] > 1.0f
)
1598 dst
->i
[i
] = chan
->i
[i
];
1607 #define FETCH(VAL,INDEX,CHAN)\
1608 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_FLOAT)
1610 #define STORE(VAL,INDEX,CHAN)\
1611 store_dest(mach, VAL, &inst->Dst[INDEX], inst, CHAN, TGSI_EXEC_DATA_FLOAT)
1615 * Execute ARB-style KIL which is predicated by a src register.
1616 * Kill fragment if any of the four values is less than zero.
1619 exec_kil(struct tgsi_exec_machine
*mach
,
1620 const struct tgsi_full_instruction
*inst
)
1624 uint kilmask
= 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1625 union tgsi_exec_channel r
[1];
1627 /* This mask stores component bits that were already tested. */
1630 for (chan_index
= 0; chan_index
< 4; chan_index
++)
1635 /* unswizzle channel */
1636 swizzle
= tgsi_util_get_full_src_register_swizzle (
1640 /* check if the component has not been already tested */
1641 if (uniquemask
& (1 << swizzle
))
1643 uniquemask
|= 1 << swizzle
;
1645 FETCH(&r
[0], 0, chan_index
);
1646 for (i
= 0; i
< 4; i
++)
1647 if (r
[0].f
[i
] < 0.0f
)
1651 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1655 * Execute NVIDIA-style KIL which is predicated by a condition code.
1656 * Kill fragment if the condition code is TRUE.
1659 exec_kilp(struct tgsi_exec_machine
*mach
,
1660 const struct tgsi_full_instruction
*inst
)
1662 uint kilmask
; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1664 /* "unconditional" kil */
1665 kilmask
= mach
->ExecMask
;
1666 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1670 emit_vertex(struct tgsi_exec_machine
*mach
)
1672 /* FIXME: check for exec mask correctly
1674 for (i = 0; i < QUAD_SIZE; ++i) {
1675 if ((mach->ExecMask & (1 << i)))
1677 if (mach
->ExecMask
) {
1678 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] += mach
->NumOutputs
;
1679 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]]++;
1684 emit_primitive(struct tgsi_exec_machine
*mach
)
1686 unsigned *prim_count
= &mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0];
1687 /* FIXME: check for exec mask correctly
1689 for (i = 0; i < QUAD_SIZE; ++i) {
1690 if ((mach->ExecMask & (1 << i)))
1692 if (mach
->ExecMask
) {
1694 debug_assert((*prim_count
* mach
->NumOutputs
) < mach
->MaxGeometryShaderOutputs
);
1695 mach
->Primitives
[*prim_count
] = 0;
1700 conditional_emit_primitive(struct tgsi_exec_machine
*mach
)
1702 if (TGSI_PROCESSOR_GEOMETRY
== mach
->Processor
) {
1704 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]];
1705 if (emitted_verts
) {
1706 emit_primitive(mach
);
1713 * Fetch four texture samples using STR texture coordinates.
1716 fetch_texel( struct tgsi_sampler
*sampler
,
1717 const union tgsi_exec_channel
*s
,
1718 const union tgsi_exec_channel
*t
,
1719 const union tgsi_exec_channel
*p
,
1720 const union tgsi_exec_channel
*c0
,
1721 enum tgsi_sampler_control control
,
1722 union tgsi_exec_channel
*r
,
1723 union tgsi_exec_channel
*g
,
1724 union tgsi_exec_channel
*b
,
1725 union tgsi_exec_channel
*a
)
1728 float rgba
[NUM_CHANNELS
][QUAD_SIZE
];
1730 sampler
->get_samples(sampler
, s
->f
, t
->f
, p
->f
, c0
->f
, control
, rgba
);
1732 for (j
= 0; j
< 4; j
++) {
1733 r
->f
[j
] = rgba
[0][j
];
1734 g
->f
[j
] = rgba
[1][j
];
1735 b
->f
[j
] = rgba
[2][j
];
1736 a
->f
[j
] = rgba
[3][j
];
1741 #define TEX_MODIFIER_NONE 0
1742 #define TEX_MODIFIER_PROJECTED 1
1743 #define TEX_MODIFIER_LOD_BIAS 2
1744 #define TEX_MODIFIER_EXPLICIT_LOD 3
1748 exec_tex(struct tgsi_exec_machine
*mach
,
1749 const struct tgsi_full_instruction
*inst
,
1752 const uint unit
= inst
->Src
[1].Register
.Index
;
1753 union tgsi_exec_channel r
[4];
1754 const union tgsi_exec_channel
*lod
= &ZeroVec
;
1755 enum tgsi_sampler_control control
;
1758 if (modifier
!= TEX_MODIFIER_NONE
) {
1759 FETCH(&r
[3], 0, CHAN_W
);
1760 if (modifier
!= TEX_MODIFIER_PROJECTED
) {
1765 if (modifier
== TEX_MODIFIER_EXPLICIT_LOD
) {
1766 control
= tgsi_sampler_lod_explicit
;
1768 control
= tgsi_sampler_lod_bias
;
1771 switch (inst
->Texture
.Texture
) {
1772 case TGSI_TEXTURE_1D
:
1773 case TGSI_TEXTURE_SHADOW1D
:
1774 FETCH(&r
[0], 0, CHAN_X
);
1776 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1777 micro_div(&r
[0], &r
[0], &r
[3]);
1780 fetch_texel(mach
->Samplers
[unit
],
1781 &r
[0], &ZeroVec
, &ZeroVec
, lod
, /* S, T, P, LOD */
1783 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1786 case TGSI_TEXTURE_2D
:
1787 case TGSI_TEXTURE_RECT
:
1788 case TGSI_TEXTURE_SHADOW2D
:
1789 case TGSI_TEXTURE_SHADOWRECT
:
1790 FETCH(&r
[0], 0, CHAN_X
);
1791 FETCH(&r
[1], 0, CHAN_Y
);
1792 FETCH(&r
[2], 0, CHAN_Z
);
1794 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1795 micro_div(&r
[0], &r
[0], &r
[3]);
1796 micro_div(&r
[1], &r
[1], &r
[3]);
1797 micro_div(&r
[2], &r
[2], &r
[3]);
1800 fetch_texel(mach
->Samplers
[unit
],
1801 &r
[0], &r
[1], &r
[2], lod
, /* S, T, P, LOD */
1803 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1806 case TGSI_TEXTURE_3D
:
1807 case TGSI_TEXTURE_CUBE
:
1808 FETCH(&r
[0], 0, CHAN_X
);
1809 FETCH(&r
[1], 0, CHAN_Y
);
1810 FETCH(&r
[2], 0, CHAN_Z
);
1812 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1813 micro_div(&r
[0], &r
[0], &r
[3]);
1814 micro_div(&r
[1], &r
[1], &r
[3]);
1815 micro_div(&r
[2], &r
[2], &r
[3]);
1818 fetch_texel(mach
->Samplers
[unit
],
1819 &r
[0], &r
[1], &r
[2], lod
,
1821 &r
[0], &r
[1], &r
[2], &r
[3]);
1828 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
1829 STORE(&r
[chan_index
], 0, chan_index
);
1834 exec_txd(struct tgsi_exec_machine
*mach
,
1835 const struct tgsi_full_instruction
*inst
)
1837 const uint unit
= inst
->Src
[3].Register
.Index
;
1838 union tgsi_exec_channel r
[4];
1842 * XXX: This is fake TXD -- the derivatives are not taken into account, yet.
1845 switch (inst
->Texture
.Texture
) {
1846 case TGSI_TEXTURE_1D
:
1847 case TGSI_TEXTURE_SHADOW1D
:
1849 FETCH(&r
[0], 0, CHAN_X
);
1851 fetch_texel(mach
->Samplers
[unit
],
1852 &r
[0], &ZeroVec
, &ZeroVec
, &ZeroVec
, /* S, T, P, BIAS */
1853 tgsi_sampler_lod_bias
,
1854 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1857 case TGSI_TEXTURE_2D
:
1858 case TGSI_TEXTURE_RECT
:
1859 case TGSI_TEXTURE_SHADOW2D
:
1860 case TGSI_TEXTURE_SHADOWRECT
:
1862 FETCH(&r
[0], 0, CHAN_X
);
1863 FETCH(&r
[1], 0, CHAN_Y
);
1864 FETCH(&r
[2], 0, CHAN_Z
);
1866 fetch_texel(mach
->Samplers
[unit
],
1867 &r
[0], &r
[1], &r
[2], &ZeroVec
, /* inputs */
1868 tgsi_sampler_lod_bias
,
1869 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1872 case TGSI_TEXTURE_3D
:
1873 case TGSI_TEXTURE_CUBE
:
1875 FETCH(&r
[0], 0, CHAN_X
);
1876 FETCH(&r
[1], 0, CHAN_Y
);
1877 FETCH(&r
[2], 0, CHAN_Z
);
1879 fetch_texel(mach
->Samplers
[unit
],
1880 &r
[0], &r
[1], &r
[2], &ZeroVec
,
1881 tgsi_sampler_lod_bias
,
1882 &r
[0], &r
[1], &r
[2], &r
[3]);
1889 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
1890 STORE(&r
[chan_index
], 0, chan_index
);
1896 * Evaluate a constant-valued coefficient at the position of the
1901 struct tgsi_exec_machine
*mach
,
1907 for( i
= 0; i
< QUAD_SIZE
; i
++ ) {
1908 mach
->Inputs
[attrib
].xyzw
[chan
].f
[i
] = mach
->InterpCoefs
[attrib
].a0
[chan
];
1913 * Evaluate a linear-valued coefficient at the position of the
1918 struct tgsi_exec_machine
*mach
,
1922 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1923 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1924 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1925 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1926 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1927 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
;
1928 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = a0
+ dadx
;
1929 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = a0
+ dady
;
1930 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = a0
+ dadx
+ dady
;
1934 * Evaluate a perspective-valued coefficient at the position of the
1938 eval_perspective_coef(
1939 struct tgsi_exec_machine
*mach
,
1943 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1944 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1945 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1946 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1947 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1948 const float *w
= mach
->QuadPos
.xyzw
[3].f
;
1949 /* divide by W here */
1950 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
/ w
[0];
1951 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = (a0
+ dadx
) / w
[1];
1952 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = (a0
+ dady
) / w
[2];
1953 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = (a0
+ dadx
+ dady
) / w
[3];
1957 typedef void (* eval_coef_func
)(
1958 struct tgsi_exec_machine
*mach
,
1963 exec_declaration(struct tgsi_exec_machine
*mach
,
1964 const struct tgsi_full_declaration
*decl
)
1966 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
1967 if (decl
->Declaration
.File
== TGSI_FILE_INPUT
||
1968 decl
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1969 uint first
, last
, mask
;
1971 first
= decl
->Range
.First
;
1972 last
= decl
->Range
.Last
;
1973 mask
= decl
->Declaration
.UsageMask
;
1975 /* XXX we could remove this special-case code since
1976 * mach->InterpCoefs[first].a0 should already have the
1977 * front/back-face value. But we should first update the
1978 * ureg code to emit the right UsageMask value (WRITEMASK_X).
1979 * Then, we could remove the tgsi_exec_machine::Face field.
1981 if (decl
->Semantic
.Name
== TGSI_SEMANTIC_FACE
) {
1984 assert(decl
->Semantic
.Index
== 0);
1985 assert(first
== last
);
1987 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1988 mach
->Inputs
[first
].xyzw
[0].f
[i
] = mach
->Face
;
1991 eval_coef_func eval
;
1994 switch (decl
->Declaration
.Interpolate
) {
1995 case TGSI_INTERPOLATE_CONSTANT
:
1996 eval
= eval_constant_coef
;
1999 case TGSI_INTERPOLATE_LINEAR
:
2000 eval
= eval_linear_coef
;
2003 case TGSI_INTERPOLATE_PERSPECTIVE
:
2004 eval
= eval_perspective_coef
;
2012 for (j
= 0; j
< NUM_CHANNELS
; j
++) {
2013 if (mask
& (1 << j
)) {
2014 for (i
= first
; i
<= last
; i
++) {
2024 typedef void (* micro_unary_op
)(union tgsi_exec_channel
*dst
,
2025 const union tgsi_exec_channel
*src
);
2028 exec_scalar_unary(struct tgsi_exec_machine
*mach
,
2029 const struct tgsi_full_instruction
*inst
,
2031 enum tgsi_exec_datatype dst_datatype
,
2032 enum tgsi_exec_datatype src_datatype
)
2035 union tgsi_exec_channel src
;
2036 union tgsi_exec_channel dst
;
2038 fetch_source(mach
, &src
, &inst
->Src
[0], CHAN_X
, src_datatype
);
2040 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
2041 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2042 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2048 exec_vector_unary(struct tgsi_exec_machine
*mach
,
2049 const struct tgsi_full_instruction
*inst
,
2051 enum tgsi_exec_datatype dst_datatype
,
2052 enum tgsi_exec_datatype src_datatype
)
2055 struct tgsi_exec_vector dst
;
2057 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
2058 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2059 union tgsi_exec_channel src
;
2061 fetch_source(mach
, &src
, &inst
->Src
[0], chan
, src_datatype
);
2062 op(&dst
.xyzw
[chan
], &src
);
2065 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
2066 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2067 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2072 typedef void (* micro_binary_op
)(union tgsi_exec_channel
*dst
,
2073 const union tgsi_exec_channel
*src0
,
2074 const union tgsi_exec_channel
*src1
);
2077 exec_vector_binary(struct tgsi_exec_machine
*mach
,
2078 const struct tgsi_full_instruction
*inst
,
2080 enum tgsi_exec_datatype dst_datatype
,
2081 enum tgsi_exec_datatype src_datatype
)
2084 struct tgsi_exec_vector dst
;
2086 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
2087 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2088 union tgsi_exec_channel src
[2];
2090 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
2091 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
2092 op(&dst
.xyzw
[chan
], &src
[0], &src
[1]);
2095 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
2096 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2097 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2102 typedef void (* micro_trinary_op
)(union tgsi_exec_channel
*dst
,
2103 const union tgsi_exec_channel
*src0
,
2104 const union tgsi_exec_channel
*src1
,
2105 const union tgsi_exec_channel
*src2
);
2108 exec_vector_trinary(struct tgsi_exec_machine
*mach
,
2109 const struct tgsi_full_instruction
*inst
,
2110 micro_trinary_op op
,
2111 enum tgsi_exec_datatype dst_datatype
,
2112 enum tgsi_exec_datatype src_datatype
)
2115 struct tgsi_exec_vector dst
;
2117 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
2118 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2119 union tgsi_exec_channel src
[3];
2121 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
2122 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
2123 fetch_source(mach
, &src
[2], &inst
->Src
[2], chan
, src_datatype
);
2124 op(&dst
.xyzw
[chan
], &src
[0], &src
[1], &src
[2]);
2127 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
2128 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2129 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2135 exec_dp3(struct tgsi_exec_machine
*mach
,
2136 const struct tgsi_full_instruction
*inst
)
2139 union tgsi_exec_channel arg
[3];
2141 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2142 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2143 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2145 for (chan
= CHAN_Y
; chan
<= CHAN_Z
; chan
++) {
2146 fetch_source(mach
, &arg
[0], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2147 fetch_source(mach
, &arg
[1], &inst
->Src
[1], chan
, TGSI_EXEC_DATA_FLOAT
);
2148 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2151 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
2152 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2153 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2159 exec_dp4(struct tgsi_exec_machine
*mach
,
2160 const struct tgsi_full_instruction
*inst
)
2163 union tgsi_exec_channel arg
[3];
2165 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2166 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2167 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2169 for (chan
= CHAN_Y
; chan
<= CHAN_W
; chan
++) {
2170 fetch_source(mach
, &arg
[0], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2171 fetch_source(mach
, &arg
[1], &inst
->Src
[1], chan
, TGSI_EXEC_DATA_FLOAT
);
2172 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2175 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
2176 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2177 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2183 exec_dp2a(struct tgsi_exec_machine
*mach
,
2184 const struct tgsi_full_instruction
*inst
)
2187 union tgsi_exec_channel arg
[3];
2189 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2190 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2191 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2193 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2194 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2195 micro_mad(&arg
[0], &arg
[0], &arg
[1], &arg
[2]);
2197 fetch_source(mach
, &arg
[1], &inst
->Src
[2], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2198 micro_add(&arg
[0], &arg
[0], &arg
[1]);
2200 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
2201 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2202 store_dest(mach
, &arg
[0], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2208 exec_dph(struct tgsi_exec_machine
*mach
,
2209 const struct tgsi_full_instruction
*inst
)
2212 union tgsi_exec_channel arg
[3];
2214 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2215 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2216 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2218 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2219 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2220 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2222 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2223 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2224 micro_mad(&arg
[0], &arg
[0], &arg
[1], &arg
[2]);
2226 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2227 micro_add(&arg
[0], &arg
[0], &arg
[1]);
2229 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
2230 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2231 store_dest(mach
, &arg
[0], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2237 exec_dp2(struct tgsi_exec_machine
*mach
,
2238 const struct tgsi_full_instruction
*inst
)
2241 union tgsi_exec_channel arg
[3];
2243 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2244 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2245 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2247 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2248 fetch_source(mach
, &arg
[1], &inst
->Src
[1], CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2249 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2251 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
2252 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2253 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2259 exec_nrm4(struct tgsi_exec_machine
*mach
,
2260 const struct tgsi_full_instruction
*inst
)
2263 union tgsi_exec_channel arg
[4];
2264 union tgsi_exec_channel scale
;
2266 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2267 micro_mul(&scale
, &arg
[0], &arg
[0]);
2269 for (chan
= CHAN_Y
; chan
<= CHAN_W
; chan
++) {
2270 union tgsi_exec_channel product
;
2272 fetch_source(mach
, &arg
[chan
], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2273 micro_mul(&product
, &arg
[chan
], &arg
[chan
]);
2274 micro_add(&scale
, &scale
, &product
);
2277 micro_rsq(&scale
, &scale
);
2279 for (chan
= CHAN_X
; chan
<= CHAN_W
; chan
++) {
2280 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2281 micro_mul(&arg
[chan
], &arg
[chan
], &scale
);
2282 store_dest(mach
, &arg
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2288 exec_nrm3(struct tgsi_exec_machine
*mach
,
2289 const struct tgsi_full_instruction
*inst
)
2291 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XYZ
) {
2293 union tgsi_exec_channel arg
[3];
2294 union tgsi_exec_channel scale
;
2296 fetch_source(mach
, &arg
[0], &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2297 micro_mul(&scale
, &arg
[0], &arg
[0]);
2299 for (chan
= CHAN_Y
; chan
<= CHAN_Z
; chan
++) {
2300 union tgsi_exec_channel product
;
2302 fetch_source(mach
, &arg
[chan
], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2303 micro_mul(&product
, &arg
[chan
], &arg
[chan
]);
2304 micro_add(&scale
, &scale
, &product
);
2307 micro_rsq(&scale
, &scale
);
2309 for (chan
= CHAN_X
; chan
<= CHAN_Z
; chan
++) {
2310 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2311 micro_mul(&arg
[chan
], &arg
[chan
], &scale
);
2312 store_dest(mach
, &arg
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2317 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2318 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2323 exec_break(struct tgsi_exec_machine
*mach
)
2325 if (mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_LOOP
) {
2326 /* turn off loop channels for each enabled exec channel */
2327 mach
->LoopMask
&= ~mach
->ExecMask
;
2328 /* Todo: if mach->LoopMask == 0, jump to end of loop */
2329 UPDATE_EXEC_MASK(mach
);
2331 assert(mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_SWITCH
);
2333 mach
->Switch
.mask
= 0x0;
2335 UPDATE_EXEC_MASK(mach
);
2340 exec_switch(struct tgsi_exec_machine
*mach
,
2341 const struct tgsi_full_instruction
*inst
)
2343 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
2344 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
2346 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
2347 fetch_source(mach
, &mach
->Switch
.selector
, &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_UINT
);
2348 mach
->Switch
.mask
= 0x0;
2349 mach
->Switch
.defaultMask
= 0x0;
2351 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
2352 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_SWITCH
;
2354 UPDATE_EXEC_MASK(mach
);
2358 exec_case(struct tgsi_exec_machine
*mach
,
2359 const struct tgsi_full_instruction
*inst
)
2361 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
2362 union tgsi_exec_channel src
;
2365 fetch_source(mach
, &src
, &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_UINT
);
2367 if (mach
->Switch
.selector
.u
[0] == src
.u
[0]) {
2370 if (mach
->Switch
.selector
.u
[1] == src
.u
[1]) {
2373 if (mach
->Switch
.selector
.u
[2] == src
.u
[2]) {
2376 if (mach
->Switch
.selector
.u
[3] == src
.u
[3]) {
2380 mach
->Switch
.defaultMask
|= mask
;
2382 mach
->Switch
.mask
|= mask
& prevMask
;
2384 UPDATE_EXEC_MASK(mach
);
2388 exec_default(struct tgsi_exec_machine
*mach
)
2390 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
2392 mach
->Switch
.mask
|= ~mach
->Switch
.defaultMask
& prevMask
;
2394 UPDATE_EXEC_MASK(mach
);
2398 exec_endswitch(struct tgsi_exec_machine
*mach
)
2400 mach
->Switch
= mach
->SwitchStack
[--mach
->SwitchStackTop
];
2401 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
2403 UPDATE_EXEC_MASK(mach
);
2407 micro_i2f(union tgsi_exec_channel
*dst
,
2408 const union tgsi_exec_channel
*src
)
2410 dst
->f
[0] = (float)src
->i
[0];
2411 dst
->f
[1] = (float)src
->i
[1];
2412 dst
->f
[2] = (float)src
->i
[2];
2413 dst
->f
[3] = (float)src
->i
[3];
2417 micro_not(union tgsi_exec_channel
*dst
,
2418 const union tgsi_exec_channel
*src
)
2420 dst
->u
[0] = ~src
->u
[0];
2421 dst
->u
[1] = ~src
->u
[1];
2422 dst
->u
[2] = ~src
->u
[2];
2423 dst
->u
[3] = ~src
->u
[3];
2427 micro_shl(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];
2432 dst
->u
[1] = src0
->u
[1] << src1
->u
[1];
2433 dst
->u
[2] = src0
->u
[2] << src1
->u
[2];
2434 dst
->u
[3] = src0
->u
[3] << src1
->u
[3];
2438 micro_and(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];
2443 dst
->u
[1] = src0
->u
[1] & src1
->u
[1];
2444 dst
->u
[2] = src0
->u
[2] & src1
->u
[2];
2445 dst
->u
[3] = src0
->u
[3] & src1
->u
[3];
2449 micro_or(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_xor(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];
2465 dst
->u
[1] = src0
->u
[1] ^ src1
->u
[1];
2466 dst
->u
[2] = src0
->u
[2] ^ src1
->u
[2];
2467 dst
->u
[3] = src0
->u
[3] ^ src1
->u
[3];
2471 micro_f2i(union tgsi_exec_channel
*dst
,
2472 const union tgsi_exec_channel
*src
)
2474 dst
->i
[0] = (int)src
->f
[0];
2475 dst
->i
[1] = (int)src
->f
[1];
2476 dst
->i
[2] = (int)src
->f
[2];
2477 dst
->i
[3] = (int)src
->f
[3];
2481 micro_idiv(union tgsi_exec_channel
*dst
,
2482 const union tgsi_exec_channel
*src0
,
2483 const union tgsi_exec_channel
*src1
)
2485 dst
->i
[0] = src0
->i
[0] / src1
->i
[0];
2486 dst
->i
[1] = src0
->i
[1] / src1
->i
[1];
2487 dst
->i
[2] = src0
->i
[2] / src1
->i
[2];
2488 dst
->i
[3] = src0
->i
[3] / src1
->i
[3];
2492 micro_imax(union tgsi_exec_channel
*dst
,
2493 const union tgsi_exec_channel
*src0
,
2494 const union tgsi_exec_channel
*src1
)
2496 dst
->i
[0] = src0
->i
[0] > src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
2497 dst
->i
[1] = src0
->i
[1] > src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
2498 dst
->i
[2] = src0
->i
[2] > src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
2499 dst
->i
[3] = src0
->i
[3] > src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
2503 micro_imin(union tgsi_exec_channel
*dst
,
2504 const union tgsi_exec_channel
*src0
,
2505 const union tgsi_exec_channel
*src1
)
2507 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
2508 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
2509 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
2510 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
2514 micro_isge(union tgsi_exec_channel
*dst
,
2515 const union tgsi_exec_channel
*src0
,
2516 const union tgsi_exec_channel
*src1
)
2518 dst
->i
[0] = src0
->i
[0] >= src1
->i
[0] ? -1 : 0;
2519 dst
->i
[1] = src0
->i
[1] >= src1
->i
[1] ? -1 : 0;
2520 dst
->i
[2] = src0
->i
[2] >= src1
->i
[2] ? -1 : 0;
2521 dst
->i
[3] = src0
->i
[3] >= src1
->i
[3] ? -1 : 0;
2525 micro_ishr(union tgsi_exec_channel
*dst
,
2526 const union tgsi_exec_channel
*src0
,
2527 const union tgsi_exec_channel
*src1
)
2529 dst
->i
[0] = src0
->i
[0] >> src1
->i
[0];
2530 dst
->i
[1] = src0
->i
[1] >> src1
->i
[1];
2531 dst
->i
[2] = src0
->i
[2] >> src1
->i
[2];
2532 dst
->i
[3] = src0
->i
[3] >> src1
->i
[3];
2536 micro_islt(union tgsi_exec_channel
*dst
,
2537 const union tgsi_exec_channel
*src0
,
2538 const union tgsi_exec_channel
*src1
)
2540 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? -1 : 0;
2541 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? -1 : 0;
2542 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? -1 : 0;
2543 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? -1 : 0;
2547 micro_f2u(union tgsi_exec_channel
*dst
,
2548 const union tgsi_exec_channel
*src
)
2550 dst
->u
[0] = (uint
)src
->f
[0];
2551 dst
->u
[1] = (uint
)src
->f
[1];
2552 dst
->u
[2] = (uint
)src
->f
[2];
2553 dst
->u
[3] = (uint
)src
->f
[3];
2557 micro_u2f(union tgsi_exec_channel
*dst
,
2558 const union tgsi_exec_channel
*src
)
2560 dst
->f
[0] = (float)src
->u
[0];
2561 dst
->f
[1] = (float)src
->u
[1];
2562 dst
->f
[2] = (float)src
->u
[2];
2563 dst
->f
[3] = (float)src
->u
[3];
2567 micro_uadd(union tgsi_exec_channel
*dst
,
2568 const union tgsi_exec_channel
*src0
,
2569 const union tgsi_exec_channel
*src1
)
2571 dst
->u
[0] = src0
->u
[0] + src1
->u
[0];
2572 dst
->u
[1] = src0
->u
[1] + src1
->u
[1];
2573 dst
->u
[2] = src0
->u
[2] + src1
->u
[2];
2574 dst
->u
[3] = src0
->u
[3] + src1
->u
[3];
2578 micro_udiv(union tgsi_exec_channel
*dst
,
2579 const union tgsi_exec_channel
*src0
,
2580 const union tgsi_exec_channel
*src1
)
2582 dst
->u
[0] = src0
->u
[0] / src1
->u
[0];
2583 dst
->u
[1] = src0
->u
[1] / src1
->u
[1];
2584 dst
->u
[2] = src0
->u
[2] / src1
->u
[2];
2585 dst
->u
[3] = src0
->u
[3] / src1
->u
[3];
2589 micro_umad(union tgsi_exec_channel
*dst
,
2590 const union tgsi_exec_channel
*src0
,
2591 const union tgsi_exec_channel
*src1
,
2592 const union tgsi_exec_channel
*src2
)
2594 dst
->u
[0] = src0
->u
[0] * src1
->u
[0] + src2
->u
[0];
2595 dst
->u
[1] = src0
->u
[1] * src1
->u
[1] + src2
->u
[1];
2596 dst
->u
[2] = src0
->u
[2] * src1
->u
[2] + src2
->u
[2];
2597 dst
->u
[3] = src0
->u
[3] * src1
->u
[3] + src2
->u
[3];
2601 micro_umax(union tgsi_exec_channel
*dst
,
2602 const union tgsi_exec_channel
*src0
,
2603 const union tgsi_exec_channel
*src1
)
2605 dst
->u
[0] = src0
->u
[0] > src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
2606 dst
->u
[1] = src0
->u
[1] > src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
2607 dst
->u
[2] = src0
->u
[2] > src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
2608 dst
->u
[3] = src0
->u
[3] > src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
2612 micro_umin(union tgsi_exec_channel
*dst
,
2613 const union tgsi_exec_channel
*src0
,
2614 const union tgsi_exec_channel
*src1
)
2616 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
2617 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
2618 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
2619 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
2623 micro_umod(union tgsi_exec_channel
*dst
,
2624 const union tgsi_exec_channel
*src0
,
2625 const union tgsi_exec_channel
*src1
)
2627 dst
->u
[0] = src0
->u
[0] % src1
->u
[0];
2628 dst
->u
[1] = src0
->u
[1] % src1
->u
[1];
2629 dst
->u
[2] = src0
->u
[2] % src1
->u
[2];
2630 dst
->u
[3] = src0
->u
[3] % src1
->u
[3];
2634 micro_umul(union tgsi_exec_channel
*dst
,
2635 const union tgsi_exec_channel
*src0
,
2636 const union tgsi_exec_channel
*src1
)
2638 dst
->u
[0] = src0
->u
[0] * src1
->u
[0];
2639 dst
->u
[1] = src0
->u
[1] * src1
->u
[1];
2640 dst
->u
[2] = src0
->u
[2] * src1
->u
[2];
2641 dst
->u
[3] = src0
->u
[3] * src1
->u
[3];
2645 micro_useq(union tgsi_exec_channel
*dst
,
2646 const union tgsi_exec_channel
*src0
,
2647 const union tgsi_exec_channel
*src1
)
2649 dst
->u
[0] = src0
->u
[0] == src1
->u
[0] ? ~0 : 0;
2650 dst
->u
[1] = src0
->u
[1] == src1
->u
[1] ? ~0 : 0;
2651 dst
->u
[2] = src0
->u
[2] == src1
->u
[2] ? ~0 : 0;
2652 dst
->u
[3] = src0
->u
[3] == src1
->u
[3] ? ~0 : 0;
2656 micro_usge(union tgsi_exec_channel
*dst
,
2657 const union tgsi_exec_channel
*src0
,
2658 const union tgsi_exec_channel
*src1
)
2660 dst
->u
[0] = src0
->u
[0] >= src1
->u
[0] ? ~0 : 0;
2661 dst
->u
[1] = src0
->u
[1] >= src1
->u
[1] ? ~0 : 0;
2662 dst
->u
[2] = src0
->u
[2] >= src1
->u
[2] ? ~0 : 0;
2663 dst
->u
[3] = src0
->u
[3] >= src1
->u
[3] ? ~0 : 0;
2667 micro_ushr(union tgsi_exec_channel
*dst
,
2668 const union tgsi_exec_channel
*src0
,
2669 const union tgsi_exec_channel
*src1
)
2671 dst
->u
[0] = src0
->u
[0] >> src1
->u
[0];
2672 dst
->u
[1] = src0
->u
[1] >> src1
->u
[1];
2673 dst
->u
[2] = src0
->u
[2] >> src1
->u
[2];
2674 dst
->u
[3] = src0
->u
[3] >> src1
->u
[3];
2678 micro_uslt(union tgsi_exec_channel
*dst
,
2679 const union tgsi_exec_channel
*src0
,
2680 const union tgsi_exec_channel
*src1
)
2682 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? ~0 : 0;
2683 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? ~0 : 0;
2684 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? ~0 : 0;
2685 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? ~0 : 0;
2689 micro_usne(union tgsi_exec_channel
*dst
,
2690 const union tgsi_exec_channel
*src0
,
2691 const union tgsi_exec_channel
*src1
)
2693 dst
->u
[0] = src0
->u
[0] != src1
->u
[0] ? ~0 : 0;
2694 dst
->u
[1] = src0
->u
[1] != src1
->u
[1] ? ~0 : 0;
2695 dst
->u
[2] = src0
->u
[2] != src1
->u
[2] ? ~0 : 0;
2696 dst
->u
[3] = src0
->u
[3] != src1
->u
[3] ? ~0 : 0;
2701 struct tgsi_exec_machine
*mach
,
2702 const struct tgsi_full_instruction
*inst
,
2706 union tgsi_exec_channel r
[10];
2707 union tgsi_exec_channel d
[8];
2711 switch (inst
->Instruction
.Opcode
) {
2712 case TGSI_OPCODE_ARL
:
2713 exec_vector_unary(mach
, inst
, micro_arl
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
2716 case TGSI_OPCODE_MOV
:
2717 exec_vector_unary(mach
, inst
, micro_mov
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
2720 case TGSI_OPCODE_LIT
:
2721 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2722 FETCH( &r
[0], 0, CHAN_X
);
2723 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2724 micro_max(&d
[CHAN_Y
], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
2727 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2728 FETCH( &r
[1], 0, CHAN_Y
);
2729 micro_max( &r
[1], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
2731 FETCH( &r
[2], 0, CHAN_W
);
2732 micro_min( &r
[2], &r
[2], &mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
] );
2733 micro_max( &r
[2], &r
[2], &mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
] );
2734 micro_pow( &r
[1], &r
[1], &r
[2] );
2735 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
]);
2738 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2739 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2741 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2742 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2745 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2746 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2748 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2749 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2753 case TGSI_OPCODE_RCP
:
2754 exec_scalar_unary(mach
, inst
, micro_rcp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2757 case TGSI_OPCODE_RSQ
:
2758 exec_scalar_unary(mach
, inst
, micro_rsq
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2761 case TGSI_OPCODE_EXP
:
2762 FETCH( &r
[0], 0, CHAN_X
);
2763 micro_flr( &r
[1], &r
[0] ); /* r1 = floor(r0) */
2764 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2765 micro_exp2( &r
[2], &r
[1] ); /* r2 = 2 ^ r1 */
2766 STORE( &r
[2], 0, CHAN_X
); /* store r2 */
2768 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2769 micro_sub( &r
[2], &r
[0], &r
[1] ); /* r2 = r0 - r1 */
2770 STORE( &r
[2], 0, CHAN_Y
); /* store r2 */
2772 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2773 micro_exp2( &r
[2], &r
[0] ); /* r2 = 2 ^ r0 */
2774 STORE( &r
[2], 0, CHAN_Z
); /* store r2 */
2776 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2777 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2781 case TGSI_OPCODE_LOG
:
2782 FETCH( &r
[0], 0, CHAN_X
);
2783 micro_abs( &r
[2], &r
[0] ); /* r2 = abs(r0) */
2784 micro_lg2( &r
[1], &r
[2] ); /* r1 = lg2(r2) */
2785 micro_flr( &r
[0], &r
[1] ); /* r0 = floor(r1) */
2786 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2787 STORE( &r
[0], 0, CHAN_X
);
2789 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2790 micro_exp2( &r
[0], &r
[0] ); /* r0 = 2 ^ r0 */
2791 micro_div( &r
[0], &r
[2], &r
[0] ); /* r0 = r2 / r0 */
2792 STORE( &r
[0], 0, CHAN_Y
);
2794 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2795 STORE( &r
[1], 0, CHAN_Z
);
2797 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2798 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2802 case TGSI_OPCODE_MUL
:
2803 exec_vector_binary(mach
, inst
, micro_mul
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2806 case TGSI_OPCODE_ADD
:
2807 exec_vector_binary(mach
, inst
, micro_add
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2810 case TGSI_OPCODE_DP3
:
2811 exec_dp3(mach
, inst
);
2814 case TGSI_OPCODE_DP4
:
2815 exec_dp4(mach
, inst
);
2818 case TGSI_OPCODE_DST
:
2819 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2820 FETCH( &r
[0], 0, CHAN_Y
);
2821 FETCH( &r
[1], 1, CHAN_Y
);
2822 micro_mul(&d
[CHAN_Y
], &r
[0], &r
[1]);
2824 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2825 FETCH(&d
[CHAN_Z
], 0, CHAN_Z
);
2827 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2828 FETCH(&d
[CHAN_W
], 1, CHAN_W
);
2831 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2832 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2834 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2835 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2837 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2838 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2840 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2841 STORE(&d
[CHAN_W
], 0, CHAN_W
);
2845 case TGSI_OPCODE_MIN
:
2846 exec_vector_binary(mach
, inst
, micro_min
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2849 case TGSI_OPCODE_MAX
:
2850 exec_vector_binary(mach
, inst
, micro_max
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2853 case TGSI_OPCODE_SLT
:
2854 exec_vector_binary(mach
, inst
, micro_slt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2857 case TGSI_OPCODE_SGE
:
2858 exec_vector_binary(mach
, inst
, micro_sge
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2861 case TGSI_OPCODE_MAD
:
2862 exec_vector_trinary(mach
, inst
, micro_mad
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2865 case TGSI_OPCODE_SUB
:
2866 exec_vector_binary(mach
, inst
, micro_sub
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2869 case TGSI_OPCODE_LRP
:
2870 exec_vector_trinary(mach
, inst
, micro_lrp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2873 case TGSI_OPCODE_CND
:
2874 exec_vector_trinary(mach
, inst
, micro_cnd
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2877 case TGSI_OPCODE_DP2A
:
2878 exec_dp2a(mach
, inst
);
2881 case TGSI_OPCODE_FRC
:
2882 exec_vector_unary(mach
, inst
, micro_frc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2885 case TGSI_OPCODE_CLAMP
:
2886 exec_vector_trinary(mach
, inst
, micro_clamp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2889 case TGSI_OPCODE_FLR
:
2890 exec_vector_unary(mach
, inst
, micro_flr
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2893 case TGSI_OPCODE_ROUND
:
2894 exec_vector_unary(mach
, inst
, micro_rnd
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2897 case TGSI_OPCODE_EX2
:
2898 exec_scalar_unary(mach
, inst
, micro_exp2
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2901 case TGSI_OPCODE_LG2
:
2902 exec_scalar_unary(mach
, inst
, micro_lg2
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2905 case TGSI_OPCODE_POW
:
2906 FETCH(&r
[0], 0, CHAN_X
);
2907 FETCH(&r
[1], 1, CHAN_X
);
2909 micro_pow( &r
[0], &r
[0], &r
[1] );
2911 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2912 STORE( &r
[0], 0, chan_index
);
2916 case TGSI_OPCODE_XPD
:
2917 FETCH(&r
[0], 0, CHAN_Y
);
2918 FETCH(&r
[1], 1, CHAN_Z
);
2920 micro_mul( &r
[2], &r
[0], &r
[1] );
2922 FETCH(&r
[3], 0, CHAN_Z
);
2923 FETCH(&r
[4], 1, CHAN_Y
);
2925 micro_mul( &r
[5], &r
[3], &r
[4] );
2926 micro_sub(&d
[CHAN_X
], &r
[2], &r
[5]);
2928 FETCH(&r
[2], 1, CHAN_X
);
2930 micro_mul( &r
[3], &r
[3], &r
[2] );
2932 FETCH(&r
[5], 0, CHAN_X
);
2934 micro_mul( &r
[1], &r
[1], &r
[5] );
2935 micro_sub(&d
[CHAN_Y
], &r
[3], &r
[1]);
2937 micro_mul( &r
[5], &r
[5], &r
[4] );
2938 micro_mul( &r
[0], &r
[0], &r
[2] );
2939 micro_sub(&d
[CHAN_Z
], &r
[5], &r
[0]);
2941 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2942 STORE(&d
[CHAN_X
], 0, CHAN_X
);
2944 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2945 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2947 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2948 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2950 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2951 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2955 case TGSI_OPCODE_ABS
:
2956 exec_vector_unary(mach
, inst
, micro_abs
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2959 case TGSI_OPCODE_RCC
:
2960 FETCH(&r
[0], 0, CHAN_X
);
2961 micro_div(&r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0]);
2962 micro_float_clamp(&r
[0], &r
[0]);
2963 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2964 STORE(&r
[0], 0, chan_index
);
2968 case TGSI_OPCODE_DPH
:
2969 exec_dph(mach
, inst
);
2972 case TGSI_OPCODE_COS
:
2973 exec_scalar_unary(mach
, inst
, micro_cos
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2976 case TGSI_OPCODE_DDX
:
2977 exec_vector_unary(mach
, inst
, micro_ddx
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2980 case TGSI_OPCODE_DDY
:
2981 exec_vector_unary(mach
, inst
, micro_ddy
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2984 case TGSI_OPCODE_KILP
:
2985 exec_kilp (mach
, inst
);
2988 case TGSI_OPCODE_KIL
:
2989 exec_kil (mach
, inst
);
2992 case TGSI_OPCODE_PK2H
:
2996 case TGSI_OPCODE_PK2US
:
3000 case TGSI_OPCODE_PK4B
:
3004 case TGSI_OPCODE_PK4UB
:
3008 case TGSI_OPCODE_RFL
:
3009 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
3010 IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
3011 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
3012 /* r0 = dp3(src0, src0) */
3013 FETCH(&r
[2], 0, CHAN_X
);
3014 micro_mul(&r
[0], &r
[2], &r
[2]);
3015 FETCH(&r
[4], 0, CHAN_Y
);
3016 micro_mul(&r
[8], &r
[4], &r
[4]);
3017 micro_add(&r
[0], &r
[0], &r
[8]);
3018 FETCH(&r
[6], 0, CHAN_Z
);
3019 micro_mul(&r
[8], &r
[6], &r
[6]);
3020 micro_add(&r
[0], &r
[0], &r
[8]);
3022 /* r1 = dp3(src0, src1) */
3023 FETCH(&r
[3], 1, CHAN_X
);
3024 micro_mul(&r
[1], &r
[2], &r
[3]);
3025 FETCH(&r
[5], 1, CHAN_Y
);
3026 micro_mul(&r
[8], &r
[4], &r
[5]);
3027 micro_add(&r
[1], &r
[1], &r
[8]);
3028 FETCH(&r
[7], 1, CHAN_Z
);
3029 micro_mul(&r
[8], &r
[6], &r
[7]);
3030 micro_add(&r
[1], &r
[1], &r
[8]);
3032 /* r1 = 2 * r1 / r0 */
3033 micro_add(&r
[1], &r
[1], &r
[1]);
3034 micro_div(&r
[1], &r
[1], &r
[0]);
3036 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
3037 micro_mul(&r
[2], &r
[2], &r
[1]);
3038 micro_sub(&r
[2], &r
[2], &r
[3]);
3039 STORE(&r
[2], 0, CHAN_X
);
3041 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
3042 micro_mul(&r
[4], &r
[4], &r
[1]);
3043 micro_sub(&r
[4], &r
[4], &r
[5]);
3044 STORE(&r
[4], 0, CHAN_Y
);
3046 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
3047 micro_mul(&r
[6], &r
[6], &r
[1]);
3048 micro_sub(&r
[6], &r
[6], &r
[7]);
3049 STORE(&r
[6], 0, CHAN_Z
);
3052 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
3053 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
3057 case TGSI_OPCODE_SEQ
:
3058 exec_vector_binary(mach
, inst
, micro_seq
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3061 case TGSI_OPCODE_SFL
:
3062 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3063 STORE(&mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, chan_index
);
3067 case TGSI_OPCODE_SGT
:
3068 exec_vector_binary(mach
, inst
, micro_sgt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3071 case TGSI_OPCODE_SIN
:
3072 exec_scalar_unary(mach
, inst
, micro_sin
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3075 case TGSI_OPCODE_SLE
:
3076 exec_vector_binary(mach
, inst
, micro_sle
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3079 case TGSI_OPCODE_SNE
:
3080 exec_vector_binary(mach
, inst
, micro_sne
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3083 case TGSI_OPCODE_STR
:
3084 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
3085 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, chan_index
);
3089 case TGSI_OPCODE_TEX
:
3090 /* simple texture lookup */
3091 /* src[0] = texcoord */
3092 /* src[1] = sampler unit */
3093 exec_tex(mach
, inst
, TEX_MODIFIER_NONE
);
3096 case TGSI_OPCODE_TXB
:
3097 /* Texture lookup with lod bias */
3098 /* src[0] = texcoord (src[0].w = LOD bias) */
3099 /* src[1] = sampler unit */
3100 exec_tex(mach
, inst
, TEX_MODIFIER_LOD_BIAS
);
3103 case TGSI_OPCODE_TXD
:
3104 /* Texture lookup with explict partial derivatives */
3105 /* src[0] = texcoord */
3106 /* src[1] = d[strq]/dx */
3107 /* src[2] = d[strq]/dy */
3108 /* src[3] = sampler unit */
3109 exec_txd(mach
, inst
);
3112 case TGSI_OPCODE_TXL
:
3113 /* Texture lookup with explit LOD */
3114 /* src[0] = texcoord (src[0].w = LOD) */
3115 /* src[1] = sampler unit */
3116 exec_tex(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
);
3119 case TGSI_OPCODE_TXP
:
3120 /* Texture lookup with projection */
3121 /* src[0] = texcoord (src[0].w = projection) */
3122 /* src[1] = sampler unit */
3123 exec_tex(mach
, inst
, TEX_MODIFIER_PROJECTED
);
3126 case TGSI_OPCODE_UP2H
:
3130 case TGSI_OPCODE_UP2US
:
3134 case TGSI_OPCODE_UP4B
:
3138 case TGSI_OPCODE_UP4UB
:
3142 case TGSI_OPCODE_X2D
:
3143 FETCH(&r
[0], 1, CHAN_X
);
3144 FETCH(&r
[1], 1, CHAN_Y
);
3145 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
3146 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
3147 FETCH(&r
[2], 2, CHAN_X
);
3148 micro_mul(&r
[2], &r
[2], &r
[0]);
3149 FETCH(&r
[3], 2, CHAN_Y
);
3150 micro_mul(&r
[3], &r
[3], &r
[1]);
3151 micro_add(&r
[2], &r
[2], &r
[3]);
3152 FETCH(&r
[3], 0, CHAN_X
);
3153 micro_add(&d
[CHAN_X
], &r
[2], &r
[3]);
3156 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
3157 IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
3158 FETCH(&r
[2], 2, CHAN_Z
);
3159 micro_mul(&r
[2], &r
[2], &r
[0]);
3160 FETCH(&r
[3], 2, CHAN_W
);
3161 micro_mul(&r
[3], &r
[3], &r
[1]);
3162 micro_add(&r
[2], &r
[2], &r
[3]);
3163 FETCH(&r
[3], 0, CHAN_Y
);
3164 micro_add(&d
[CHAN_Y
], &r
[2], &r
[3]);
3167 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
3168 STORE(&d
[CHAN_X
], 0, CHAN_X
);
3170 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
3171 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
3173 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
3174 STORE(&d
[CHAN_X
], 0, CHAN_Z
);
3176 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
3177 STORE(&d
[CHAN_Y
], 0, CHAN_W
);
3181 case TGSI_OPCODE_ARA
:
3185 case TGSI_OPCODE_ARR
:
3186 exec_vector_unary(mach
, inst
, micro_arr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
3189 case TGSI_OPCODE_BRA
:
3193 case TGSI_OPCODE_CAL
:
3194 /* skip the call if no execution channels are enabled */
3195 if (mach
->ExecMask
) {
3198 /* First, record the depths of the execution stacks.
3199 * This is important for deeply nested/looped return statements.
3200 * We have to unwind the stacks by the correct amount. For a
3201 * real code generator, we could determine the number of entries
3202 * to pop off each stack with simple static analysis and avoid
3203 * implementing this data structure at run time.
3205 mach
->CallStack
[mach
->CallStackTop
].CondStackTop
= mach
->CondStackTop
;
3206 mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
= mach
->LoopStackTop
;
3207 mach
->CallStack
[mach
->CallStackTop
].ContStackTop
= mach
->ContStackTop
;
3208 mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
= mach
->SwitchStackTop
;
3209 mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
= mach
->BreakStackTop
;
3210 /* note that PC was already incremented above */
3211 mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
= *pc
;
3213 mach
->CallStackTop
++;
3215 /* Second, push the Cond, Loop, Cont, Func stacks */
3216 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
3217 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3218 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3219 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
3220 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
3221 assert(mach
->FuncStackTop
< TGSI_EXEC_MAX_CALL_NESTING
);
3223 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
3224 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
3225 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
3226 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
3227 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
3228 mach
->FuncStack
[mach
->FuncStackTop
++] = mach
->FuncMask
;
3230 /* Finally, jump to the subroutine */
3231 *pc
= inst
->Label
.Label
;
3235 case TGSI_OPCODE_RET
:
3236 mach
->FuncMask
&= ~mach
->ExecMask
;
3237 UPDATE_EXEC_MASK(mach
);
3239 if (mach
->FuncMask
== 0x0) {
3240 /* really return now (otherwise, keep executing */
3242 if (mach
->CallStackTop
== 0) {
3243 /* returning from main() */
3244 mach
->CondStackTop
= 0;
3245 mach
->LoopStackTop
= 0;
3250 assert(mach
->CallStackTop
> 0);
3251 mach
->CallStackTop
--;
3253 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
3254 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
3256 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
3257 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
3259 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
3260 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
3262 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
3263 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
3265 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
3266 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
3268 assert(mach
->FuncStackTop
> 0);
3269 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
3271 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
3273 UPDATE_EXEC_MASK(mach
);
3277 case TGSI_OPCODE_SSG
:
3278 exec_vector_unary(mach
, inst
, micro_sgn
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3281 case TGSI_OPCODE_CMP
:
3282 exec_vector_trinary(mach
, inst
, micro_cmp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3285 case TGSI_OPCODE_SCS
:
3286 if( IS_CHANNEL_ENABLED( *inst
, CHAN_X
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) ) {
3287 FETCH( &r
[0], 0, CHAN_X
);
3288 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
3289 micro_cos(&r
[1], &r
[0]);
3290 STORE(&r
[1], 0, CHAN_X
);
3292 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
3293 micro_sin(&r
[1], &r
[0]);
3294 STORE(&r
[1], 0, CHAN_Y
);
3297 if( IS_CHANNEL_ENABLED( *inst
, CHAN_Z
) ) {
3298 STORE( &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, CHAN_Z
);
3300 if( IS_CHANNEL_ENABLED( *inst
, CHAN_W
) ) {
3301 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
3305 case TGSI_OPCODE_NRM
:
3306 exec_nrm3(mach
, inst
);
3309 case TGSI_OPCODE_NRM4
:
3310 exec_nrm4(mach
, inst
);
3313 case TGSI_OPCODE_DIV
:
3314 exec_vector_binary(mach
, inst
, micro_div
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3317 case TGSI_OPCODE_DP2
:
3318 exec_dp2(mach
, inst
);
3321 case TGSI_OPCODE_IF
:
3323 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
3324 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
3325 FETCH( &r
[0], 0, CHAN_X
);
3326 /* update CondMask */
3328 mach
->CondMask
&= ~0x1;
3331 mach
->CondMask
&= ~0x2;
3334 mach
->CondMask
&= ~0x4;
3337 mach
->CondMask
&= ~0x8;
3339 UPDATE_EXEC_MASK(mach
);
3340 /* Todo: If CondMask==0, jump to ELSE */
3343 case TGSI_OPCODE_ELSE
:
3344 /* invert CondMask wrt previous mask */
3347 assert(mach
->CondStackTop
> 0);
3348 prevMask
= mach
->CondStack
[mach
->CondStackTop
- 1];
3349 mach
->CondMask
= ~mach
->CondMask
& prevMask
;
3350 UPDATE_EXEC_MASK(mach
);
3351 /* Todo: If CondMask==0, jump to ENDIF */
3355 case TGSI_OPCODE_ENDIF
:
3357 assert(mach
->CondStackTop
> 0);
3358 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
3359 UPDATE_EXEC_MASK(mach
);
3362 case TGSI_OPCODE_END
:
3363 /* make sure we end primitives which haven't
3364 * been explicitly emitted */
3365 conditional_emit_primitive(mach
);
3366 /* halt execution */
3370 case TGSI_OPCODE_PUSHA
:
3374 case TGSI_OPCODE_POPA
:
3378 case TGSI_OPCODE_CEIL
:
3379 exec_vector_unary(mach
, inst
, micro_ceil
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3382 case TGSI_OPCODE_I2F
:
3383 exec_vector_unary(mach
, inst
, micro_i2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_INT
);
3386 case TGSI_OPCODE_NOT
:
3387 exec_vector_unary(mach
, inst
, micro_not
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3390 case TGSI_OPCODE_TRUNC
:
3391 exec_vector_unary(mach
, inst
, micro_trunc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3394 case TGSI_OPCODE_SHL
:
3395 exec_vector_binary(mach
, inst
, micro_shl
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3398 case TGSI_OPCODE_AND
:
3399 exec_vector_binary(mach
, inst
, micro_and
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3402 case TGSI_OPCODE_OR
:
3403 exec_vector_binary(mach
, inst
, micro_or
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3406 case TGSI_OPCODE_MOD
:
3410 case TGSI_OPCODE_XOR
:
3411 exec_vector_binary(mach
, inst
, micro_xor
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3414 case TGSI_OPCODE_SAD
:
3418 case TGSI_OPCODE_TXF
:
3422 case TGSI_OPCODE_TXQ
:
3426 case TGSI_OPCODE_EMIT
:
3430 case TGSI_OPCODE_ENDPRIM
:
3431 emit_primitive(mach
);
3434 case TGSI_OPCODE_BGNLOOP
:
3435 /* push LoopMask and ContMasks */
3436 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3437 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3438 assert(mach
->LoopLabelStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3439 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
3441 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
3442 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
3443 mach
->LoopLabelStack
[mach
->LoopLabelStackTop
++] = *pc
- 1;
3444 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
3445 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_LOOP
;
3448 case TGSI_OPCODE_ENDLOOP
:
3449 /* Restore ContMask, but don't pop */
3450 assert(mach
->ContStackTop
> 0);
3451 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3452 UPDATE_EXEC_MASK(mach
);
3453 if (mach
->ExecMask
) {
3454 /* repeat loop: jump to instruction just past BGNLOOP */
3455 assert(mach
->LoopLabelStackTop
> 0);
3456 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3459 /* exit loop: pop LoopMask */
3460 assert(mach
->LoopStackTop
> 0);
3461 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3463 assert(mach
->ContStackTop
> 0);
3464 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3465 assert(mach
->LoopLabelStackTop
> 0);
3466 --mach
->LoopLabelStackTop
;
3468 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
3470 UPDATE_EXEC_MASK(mach
);
3473 case TGSI_OPCODE_BRK
:
3477 case TGSI_OPCODE_CONT
:
3478 /* turn off cont channels for each enabled exec channel */
3479 mach
->ContMask
&= ~mach
->ExecMask
;
3480 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3481 UPDATE_EXEC_MASK(mach
);
3484 case TGSI_OPCODE_BGNSUB
:
3488 case TGSI_OPCODE_ENDSUB
:
3490 * XXX: This really should be a no-op. We should never reach this opcode.
3493 assert(mach
->CallStackTop
> 0);
3494 mach
->CallStackTop
--;
3496 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
3497 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
3499 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
3500 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
3502 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
3503 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
3505 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
3506 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
3508 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
3509 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
3511 assert(mach
->FuncStackTop
> 0);
3512 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
3514 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
3516 UPDATE_EXEC_MASK(mach
);
3519 case TGSI_OPCODE_NOP
:
3522 case TGSI_OPCODE_BREAKC
:
3523 FETCH(&r
[0], 0, CHAN_X
);
3524 /* update CondMask */
3525 if (r
[0].u
[0] && (mach
->ExecMask
& 0x1)) {
3526 mach
->LoopMask
&= ~0x1;
3528 if (r
[0].u
[1] && (mach
->ExecMask
& 0x2)) {
3529 mach
->LoopMask
&= ~0x2;
3531 if (r
[0].u
[2] && (mach
->ExecMask
& 0x4)) {
3532 mach
->LoopMask
&= ~0x4;
3534 if (r
[0].u
[3] && (mach
->ExecMask
& 0x8)) {
3535 mach
->LoopMask
&= ~0x8;
3537 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3538 UPDATE_EXEC_MASK(mach
);
3541 case TGSI_OPCODE_F2I
:
3542 exec_vector_unary(mach
, inst
, micro_f2i
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
3545 case TGSI_OPCODE_IDIV
:
3546 exec_vector_binary(mach
, inst
, micro_idiv
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3549 case TGSI_OPCODE_IMAX
:
3550 exec_vector_binary(mach
, inst
, micro_imax
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3553 case TGSI_OPCODE_IMIN
:
3554 exec_vector_binary(mach
, inst
, micro_imin
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3557 case TGSI_OPCODE_INEG
:
3558 exec_vector_unary(mach
, inst
, micro_ineg
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3561 case TGSI_OPCODE_ISGE
:
3562 exec_vector_binary(mach
, inst
, micro_isge
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3565 case TGSI_OPCODE_ISHR
:
3566 exec_vector_binary(mach
, inst
, micro_ishr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3569 case TGSI_OPCODE_ISLT
:
3570 exec_vector_binary(mach
, inst
, micro_islt
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3573 case TGSI_OPCODE_F2U
:
3574 exec_vector_unary(mach
, inst
, micro_f2u
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
3577 case TGSI_OPCODE_U2F
:
3578 exec_vector_unary(mach
, inst
, micro_u2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_UINT
);
3581 case TGSI_OPCODE_UADD
:
3582 exec_vector_binary(mach
, inst
, micro_uadd
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3585 case TGSI_OPCODE_UDIV
:
3586 exec_vector_binary(mach
, inst
, micro_udiv
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3589 case TGSI_OPCODE_UMAD
:
3590 exec_vector_trinary(mach
, inst
, micro_umad
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3593 case TGSI_OPCODE_UMAX
:
3594 exec_vector_binary(mach
, inst
, micro_umax
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3597 case TGSI_OPCODE_UMIN
:
3598 exec_vector_binary(mach
, inst
, micro_umin
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3601 case TGSI_OPCODE_UMOD
:
3602 exec_vector_binary(mach
, inst
, micro_umod
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3605 case TGSI_OPCODE_UMUL
:
3606 exec_vector_binary(mach
, inst
, micro_umul
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3609 case TGSI_OPCODE_USEQ
:
3610 exec_vector_binary(mach
, inst
, micro_useq
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3613 case TGSI_OPCODE_USGE
:
3614 exec_vector_binary(mach
, inst
, micro_usge
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3617 case TGSI_OPCODE_USHR
:
3618 exec_vector_binary(mach
, inst
, micro_ushr
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3621 case TGSI_OPCODE_USLT
:
3622 exec_vector_binary(mach
, inst
, micro_uslt
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3625 case TGSI_OPCODE_USNE
:
3626 exec_vector_binary(mach
, inst
, micro_usne
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3629 case TGSI_OPCODE_SWITCH
:
3630 exec_switch(mach
, inst
);
3633 case TGSI_OPCODE_CASE
:
3634 exec_case(mach
, inst
);
3637 case TGSI_OPCODE_DEFAULT
:
3641 case TGSI_OPCODE_ENDSWITCH
:
3642 exec_endswitch(mach
);
3651 #define DEBUG_EXECUTION 0
3655 * Run TGSI interpreter.
3656 * \return bitmask of "alive" quad components
3659 tgsi_exec_machine_run( struct tgsi_exec_machine
*mach
)
3664 mach
->CondMask
= 0xf;
3665 mach
->LoopMask
= 0xf;
3666 mach
->ContMask
= 0xf;
3667 mach
->FuncMask
= 0xf;
3668 mach
->ExecMask
= 0xf;
3670 mach
->Switch
.mask
= 0xf;
3672 assert(mach
->CondStackTop
== 0);
3673 assert(mach
->LoopStackTop
== 0);
3674 assert(mach
->ContStackTop
== 0);
3675 assert(mach
->SwitchStackTop
== 0);
3676 assert(mach
->BreakStackTop
== 0);
3677 assert(mach
->CallStackTop
== 0);
3679 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] = 0;
3680 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] = 0;
3682 if( mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
3683 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0] = 0;
3684 mach
->Primitives
[0] = 0;
3687 for (i
= 0; i
< QUAD_SIZE
; i
++) {
3688 mach
->Temps
[TEMP_CC_I
].xyzw
[TEMP_CC_C
].u
[i
] =
3689 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_X_SHIFT
) |
3690 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Y_SHIFT
) |
3691 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Z_SHIFT
) |
3692 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_W_SHIFT
);
3695 /* execute declarations (interpolants) */
3696 for (i
= 0; i
< mach
->NumDeclarations
; i
++) {
3697 exec_declaration( mach
, mach
->Declarations
+i
);
3702 struct tgsi_exec_vector temps
[TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
];
3703 struct tgsi_exec_vector outputs
[PIPE_MAX_ATTRIBS
];
3706 memcpy(temps
, mach
->Temps
, sizeof(temps
));
3707 memcpy(outputs
, mach
->Outputs
, sizeof(outputs
));
3710 /* execute instructions, until pc is set to -1 */
3716 tgsi_dump_instruction(&mach
->Instructions
[pc
], inst
++);
3719 assert(pc
< (int) mach
->NumInstructions
);
3720 exec_instruction(mach
, mach
->Instructions
+ pc
, &pc
);
3723 for (i
= 0; i
< TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
; i
++) {
3724 if (memcmp(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]))) {
3727 memcpy(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]));
3728 debug_printf("TEMP[%2u] = ", i
);
3729 for (j
= 0; j
< 4; j
++) {
3733 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
3734 temps
[i
].xyzw
[0].f
[j
], temps
[i
].xyzw
[0].u
[j
],
3735 temps
[i
].xyzw
[1].f
[j
], temps
[i
].xyzw
[1].u
[j
],
3736 temps
[i
].xyzw
[2].f
[j
], temps
[i
].xyzw
[2].u
[j
],
3737 temps
[i
].xyzw
[3].f
[j
], temps
[i
].xyzw
[3].u
[j
]);
3741 for (i
= 0; i
< PIPE_MAX_ATTRIBS
; i
++) {
3742 if (memcmp(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]))) {
3745 memcpy(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]));
3746 debug_printf("OUT[%2u] = ", i
);
3747 for (j
= 0; j
< 4; j
++) {
3751 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
3752 outputs
[i
].xyzw
[0].f
[j
], outputs
[i
].xyzw
[0].u
[j
],
3753 outputs
[i
].xyzw
[1].f
[j
], outputs
[i
].xyzw
[1].u
[j
],
3754 outputs
[i
].xyzw
[2].f
[j
], outputs
[i
].xyzw
[2].u
[j
],
3755 outputs
[i
].xyzw
[3].f
[j
], outputs
[i
].xyzw
[3].u
[j
]);
3764 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
3765 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
3767 * Scale back depth component.
3769 for (i
= 0; i
< 4; i
++)
3770 mach
->Outputs
[0].xyzw
[2].f
[i
] *= ctx
->DrawBuffer
->_DepthMaxF
;
3774 /* Strictly speaking, these assertions aren't really needed but they
3775 * can potentially catch some bugs in the control flow code.
3777 assert(mach
->CondStackTop
== 0);
3778 assert(mach
->LoopStackTop
== 0);
3779 assert(mach
->ContStackTop
== 0);
3780 assert(mach
->SwitchStackTop
== 0);
3781 assert(mach
->BreakStackTop
== 0);
3782 assert(mach
->CallStackTop
== 0);
3784 return ~mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];