gallium/aux/tgsi_exec.c: remove superfluous parameter from etch_source_d
[mesa.git] / src / gallium / auxiliary / tgsi / tgsi_exec.c
1 /**************************************************************************
2 *
3 * Copyright 2007-2008 VMware, Inc.
4 * All Rights Reserved.
5 * Copyright 2009-2010 VMware, Inc. All rights Reserved.
6 *
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:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
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 VMWARE 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.
26 *
27 **************************************************************************/
28
29 /**
30 * TGSI interpreter/executor.
31 *
32 * Flow control information:
33 *
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.
38 *
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.
42 * See store_dest().
43 *
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).
47 *
48 *
49 * Authors:
50 * Michal Krol
51 * Brian Paul
52 */
53
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_half.h"
62 #include "util/u_memory.h"
63 #include "util/u_math.h"
64 #include "util/rounding.h"
65
66
67 #define DEBUG_EXECUTION 0
68
69
70 #define FAST_MATH 0
71
72 #define TILE_TOP_LEFT 0
73 #define TILE_TOP_RIGHT 1
74 #define TILE_BOTTOM_LEFT 2
75 #define TILE_BOTTOM_RIGHT 3
76
77 union tgsi_double_channel {
78 double d[TGSI_QUAD_SIZE];
79 unsigned u[TGSI_QUAD_SIZE][2];
80 uint64_t u64[TGSI_QUAD_SIZE];
81 int64_t i64[TGSI_QUAD_SIZE];
82 };
83
84 struct tgsi_double_vector {
85 union tgsi_double_channel xy;
86 union tgsi_double_channel zw;
87 };
88
89 static void
90 micro_abs(union tgsi_exec_channel *dst,
91 const union tgsi_exec_channel *src)
92 {
93 dst->f[0] = fabsf(src->f[0]);
94 dst->f[1] = fabsf(src->f[1]);
95 dst->f[2] = fabsf(src->f[2]);
96 dst->f[3] = fabsf(src->f[3]);
97 }
98
99 static void
100 micro_arl(union tgsi_exec_channel *dst,
101 const union tgsi_exec_channel *src)
102 {
103 dst->i[0] = (int)floorf(src->f[0]);
104 dst->i[1] = (int)floorf(src->f[1]);
105 dst->i[2] = (int)floorf(src->f[2]);
106 dst->i[3] = (int)floorf(src->f[3]);
107 }
108
109 static void
110 micro_arr(union tgsi_exec_channel *dst,
111 const union tgsi_exec_channel *src)
112 {
113 dst->i[0] = (int)floorf(src->f[0] + 0.5f);
114 dst->i[1] = (int)floorf(src->f[1] + 0.5f);
115 dst->i[2] = (int)floorf(src->f[2] + 0.5f);
116 dst->i[3] = (int)floorf(src->f[3] + 0.5f);
117 }
118
119 static void
120 micro_ceil(union tgsi_exec_channel *dst,
121 const union tgsi_exec_channel *src)
122 {
123 dst->f[0] = ceilf(src->f[0]);
124 dst->f[1] = ceilf(src->f[1]);
125 dst->f[2] = ceilf(src->f[2]);
126 dst->f[3] = ceilf(src->f[3]);
127 }
128
129 static void
130 micro_cmp(union tgsi_exec_channel *dst,
131 const union tgsi_exec_channel *src0,
132 const union tgsi_exec_channel *src1,
133 const union tgsi_exec_channel *src2)
134 {
135 dst->f[0] = src0->f[0] < 0.0f ? src1->f[0] : src2->f[0];
136 dst->f[1] = src0->f[1] < 0.0f ? src1->f[1] : src2->f[1];
137 dst->f[2] = src0->f[2] < 0.0f ? src1->f[2] : src2->f[2];
138 dst->f[3] = src0->f[3] < 0.0f ? src1->f[3] : src2->f[3];
139 }
140
141 static void
142 micro_cos(union tgsi_exec_channel *dst,
143 const union tgsi_exec_channel *src)
144 {
145 dst->f[0] = cosf(src->f[0]);
146 dst->f[1] = cosf(src->f[1]);
147 dst->f[2] = cosf(src->f[2]);
148 dst->f[3] = cosf(src->f[3]);
149 }
150
151 static void
152 micro_d2f(union tgsi_exec_channel *dst,
153 const union tgsi_double_channel *src)
154 {
155 dst->f[0] = (float)src->d[0];
156 dst->f[1] = (float)src->d[1];
157 dst->f[2] = (float)src->d[2];
158 dst->f[3] = (float)src->d[3];
159 }
160
161 static void
162 micro_d2i(union tgsi_exec_channel *dst,
163 const union tgsi_double_channel *src)
164 {
165 dst->i[0] = (int)src->d[0];
166 dst->i[1] = (int)src->d[1];
167 dst->i[2] = (int)src->d[2];
168 dst->i[3] = (int)src->d[3];
169 }
170
171 static void
172 micro_d2u(union tgsi_exec_channel *dst,
173 const union tgsi_double_channel *src)
174 {
175 dst->u[0] = (unsigned)src->d[0];
176 dst->u[1] = (unsigned)src->d[1];
177 dst->u[2] = (unsigned)src->d[2];
178 dst->u[3] = (unsigned)src->d[3];
179 }
180 static void
181 micro_dabs(union tgsi_double_channel *dst,
182 const union tgsi_double_channel *src)
183 {
184 dst->d[0] = src->d[0] >= 0.0 ? src->d[0] : -src->d[0];
185 dst->d[1] = src->d[1] >= 0.0 ? src->d[1] : -src->d[1];
186 dst->d[2] = src->d[2] >= 0.0 ? src->d[2] : -src->d[2];
187 dst->d[3] = src->d[3] >= 0.0 ? src->d[3] : -src->d[3];
188 }
189
190 static void
191 micro_dadd(union tgsi_double_channel *dst,
192 const union tgsi_double_channel *src)
193 {
194 dst->d[0] = src[0].d[0] + src[1].d[0];
195 dst->d[1] = src[0].d[1] + src[1].d[1];
196 dst->d[2] = src[0].d[2] + src[1].d[2];
197 dst->d[3] = src[0].d[3] + src[1].d[3];
198 }
199
200 static void
201 micro_ddiv(union tgsi_double_channel *dst,
202 const union tgsi_double_channel *src)
203 {
204 dst->d[0] = src[0].d[0] / src[1].d[0];
205 dst->d[1] = src[0].d[1] / src[1].d[1];
206 dst->d[2] = src[0].d[2] / src[1].d[2];
207 dst->d[3] = src[0].d[3] / src[1].d[3];
208 }
209
210 static void
211 micro_ddx(union tgsi_exec_channel *dst,
212 const union tgsi_exec_channel *src)
213 {
214 dst->f[0] =
215 dst->f[1] =
216 dst->f[2] =
217 dst->f[3] = src->f[TILE_BOTTOM_RIGHT] - src->f[TILE_BOTTOM_LEFT];
218 }
219
220 static void
221 micro_ddy(union tgsi_exec_channel *dst,
222 const union tgsi_exec_channel *src)
223 {
224 dst->f[0] =
225 dst->f[1] =
226 dst->f[2] =
227 dst->f[3] = src->f[TILE_BOTTOM_LEFT] - src->f[TILE_TOP_LEFT];
228 }
229
230 static void
231 micro_dmul(union tgsi_double_channel *dst,
232 const union tgsi_double_channel *src)
233 {
234 dst->d[0] = src[0].d[0] * src[1].d[0];
235 dst->d[1] = src[0].d[1] * src[1].d[1];
236 dst->d[2] = src[0].d[2] * src[1].d[2];
237 dst->d[3] = src[0].d[3] * src[1].d[3];
238 }
239
240 static void
241 micro_dmax(union tgsi_double_channel *dst,
242 const union tgsi_double_channel *src)
243 {
244 dst->d[0] = src[0].d[0] > src[1].d[0] ? src[0].d[0] : src[1].d[0];
245 dst->d[1] = src[0].d[1] > src[1].d[1] ? src[0].d[1] : src[1].d[1];
246 dst->d[2] = src[0].d[2] > src[1].d[2] ? src[0].d[2] : src[1].d[2];
247 dst->d[3] = src[0].d[3] > src[1].d[3] ? src[0].d[3] : src[1].d[3];
248 }
249
250 static void
251 micro_dmin(union tgsi_double_channel *dst,
252 const union tgsi_double_channel *src)
253 {
254 dst->d[0] = src[0].d[0] < src[1].d[0] ? src[0].d[0] : src[1].d[0];
255 dst->d[1] = src[0].d[1] < src[1].d[1] ? src[0].d[1] : src[1].d[1];
256 dst->d[2] = src[0].d[2] < src[1].d[2] ? src[0].d[2] : src[1].d[2];
257 dst->d[3] = src[0].d[3] < src[1].d[3] ? src[0].d[3] : src[1].d[3];
258 }
259
260 static void
261 micro_dneg(union tgsi_double_channel *dst,
262 const union tgsi_double_channel *src)
263 {
264 dst->d[0] = -src->d[0];
265 dst->d[1] = -src->d[1];
266 dst->d[2] = -src->d[2];
267 dst->d[3] = -src->d[3];
268 }
269
270 static void
271 micro_dslt(union tgsi_double_channel *dst,
272 const union tgsi_double_channel *src)
273 {
274 dst->u[0][0] = src[0].d[0] < src[1].d[0] ? ~0U : 0U;
275 dst->u[1][0] = src[0].d[1] < src[1].d[1] ? ~0U : 0U;
276 dst->u[2][0] = src[0].d[2] < src[1].d[2] ? ~0U : 0U;
277 dst->u[3][0] = src[0].d[3] < src[1].d[3] ? ~0U : 0U;
278 }
279
280 static void
281 micro_dsne(union tgsi_double_channel *dst,
282 const union tgsi_double_channel *src)
283 {
284 dst->u[0][0] = src[0].d[0] != src[1].d[0] ? ~0U : 0U;
285 dst->u[1][0] = src[0].d[1] != src[1].d[1] ? ~0U : 0U;
286 dst->u[2][0] = src[0].d[2] != src[1].d[2] ? ~0U : 0U;
287 dst->u[3][0] = src[0].d[3] != src[1].d[3] ? ~0U : 0U;
288 }
289
290 static void
291 micro_dsge(union tgsi_double_channel *dst,
292 const union tgsi_double_channel *src)
293 {
294 dst->u[0][0] = src[0].d[0] >= src[1].d[0] ? ~0U : 0U;
295 dst->u[1][0] = src[0].d[1] >= src[1].d[1] ? ~0U : 0U;
296 dst->u[2][0] = src[0].d[2] >= src[1].d[2] ? ~0U : 0U;
297 dst->u[3][0] = src[0].d[3] >= src[1].d[3] ? ~0U : 0U;
298 }
299
300 static void
301 micro_dseq(union tgsi_double_channel *dst,
302 const union tgsi_double_channel *src)
303 {
304 dst->u[0][0] = src[0].d[0] == src[1].d[0] ? ~0U : 0U;
305 dst->u[1][0] = src[0].d[1] == src[1].d[1] ? ~0U : 0U;
306 dst->u[2][0] = src[0].d[2] == src[1].d[2] ? ~0U : 0U;
307 dst->u[3][0] = src[0].d[3] == src[1].d[3] ? ~0U : 0U;
308 }
309
310 static void
311 micro_drcp(union tgsi_double_channel *dst,
312 const union tgsi_double_channel *src)
313 {
314 dst->d[0] = 1.0 / src->d[0];
315 dst->d[1] = 1.0 / src->d[1];
316 dst->d[2] = 1.0 / src->d[2];
317 dst->d[3] = 1.0 / src->d[3];
318 }
319
320 static void
321 micro_dsqrt(union tgsi_double_channel *dst,
322 const union tgsi_double_channel *src)
323 {
324 dst->d[0] = sqrt(src->d[0]);
325 dst->d[1] = sqrt(src->d[1]);
326 dst->d[2] = sqrt(src->d[2]);
327 dst->d[3] = sqrt(src->d[3]);
328 }
329
330 static void
331 micro_drsq(union tgsi_double_channel *dst,
332 const union tgsi_double_channel *src)
333 {
334 dst->d[0] = 1.0 / sqrt(src->d[0]);
335 dst->d[1] = 1.0 / sqrt(src->d[1]);
336 dst->d[2] = 1.0 / sqrt(src->d[2]);
337 dst->d[3] = 1.0 / sqrt(src->d[3]);
338 }
339
340 static void
341 micro_dmad(union tgsi_double_channel *dst,
342 const union tgsi_double_channel *src)
343 {
344 dst->d[0] = src[0].d[0] * src[1].d[0] + src[2].d[0];
345 dst->d[1] = src[0].d[1] * src[1].d[1] + src[2].d[1];
346 dst->d[2] = src[0].d[2] * src[1].d[2] + src[2].d[2];
347 dst->d[3] = src[0].d[3] * src[1].d[3] + src[2].d[3];
348 }
349
350 static void
351 micro_dfrac(union tgsi_double_channel *dst,
352 const union tgsi_double_channel *src)
353 {
354 dst->d[0] = src->d[0] - floor(src->d[0]);
355 dst->d[1] = src->d[1] - floor(src->d[1]);
356 dst->d[2] = src->d[2] - floor(src->d[2]);
357 dst->d[3] = src->d[3] - floor(src->d[3]);
358 }
359
360 static void
361 micro_dldexp(union tgsi_double_channel *dst,
362 const union tgsi_double_channel *src0,
363 union tgsi_exec_channel *src1)
364 {
365 dst->d[0] = ldexp(src0->d[0], src1->i[0]);
366 dst->d[1] = ldexp(src0->d[1], src1->i[1]);
367 dst->d[2] = ldexp(src0->d[2], src1->i[2]);
368 dst->d[3] = ldexp(src0->d[3], src1->i[3]);
369 }
370
371 static void
372 micro_dfracexp(union tgsi_double_channel *dst,
373 union tgsi_exec_channel *dst_exp,
374 const union tgsi_double_channel *src)
375 {
376 dst->d[0] = frexp(src->d[0], &dst_exp->i[0]);
377 dst->d[1] = frexp(src->d[1], &dst_exp->i[1]);
378 dst->d[2] = frexp(src->d[2], &dst_exp->i[2]);
379 dst->d[3] = frexp(src->d[3], &dst_exp->i[3]);
380 }
381
382 static void
383 micro_exp2(union tgsi_exec_channel *dst,
384 const union tgsi_exec_channel *src)
385 {
386 #if FAST_MATH
387 dst->f[0] = util_fast_exp2(src->f[0]);
388 dst->f[1] = util_fast_exp2(src->f[1]);
389 dst->f[2] = util_fast_exp2(src->f[2]);
390 dst->f[3] = util_fast_exp2(src->f[3]);
391 #else
392 #if DEBUG
393 /* Inf is okay for this instruction, so clamp it to silence assertions. */
394 uint i;
395 union tgsi_exec_channel clamped;
396
397 for (i = 0; i < 4; i++) {
398 if (src->f[i] > 127.99999f) {
399 clamped.f[i] = 127.99999f;
400 } else if (src->f[i] < -126.99999f) {
401 clamped.f[i] = -126.99999f;
402 } else {
403 clamped.f[i] = src->f[i];
404 }
405 }
406 src = &clamped;
407 #endif /* DEBUG */
408
409 dst->f[0] = powf(2.0f, src->f[0]);
410 dst->f[1] = powf(2.0f, src->f[1]);
411 dst->f[2] = powf(2.0f, src->f[2]);
412 dst->f[3] = powf(2.0f, src->f[3]);
413 #endif /* FAST_MATH */
414 }
415
416 static void
417 micro_f2d(union tgsi_double_channel *dst,
418 const union tgsi_exec_channel *src)
419 {
420 dst->d[0] = (double)src->f[0];
421 dst->d[1] = (double)src->f[1];
422 dst->d[2] = (double)src->f[2];
423 dst->d[3] = (double)src->f[3];
424 }
425
426 static void
427 micro_flr(union tgsi_exec_channel *dst,
428 const union tgsi_exec_channel *src)
429 {
430 dst->f[0] = floorf(src->f[0]);
431 dst->f[1] = floorf(src->f[1]);
432 dst->f[2] = floorf(src->f[2]);
433 dst->f[3] = floorf(src->f[3]);
434 }
435
436 static void
437 micro_frc(union tgsi_exec_channel *dst,
438 const union tgsi_exec_channel *src)
439 {
440 dst->f[0] = src->f[0] - floorf(src->f[0]);
441 dst->f[1] = src->f[1] - floorf(src->f[1]);
442 dst->f[2] = src->f[2] - floorf(src->f[2]);
443 dst->f[3] = src->f[3] - floorf(src->f[3]);
444 }
445
446 static void
447 micro_i2d(union tgsi_double_channel *dst,
448 const union tgsi_exec_channel *src)
449 {
450 dst->d[0] = (double)src->i[0];
451 dst->d[1] = (double)src->i[1];
452 dst->d[2] = (double)src->i[2];
453 dst->d[3] = (double)src->i[3];
454 }
455
456 static void
457 micro_iabs(union tgsi_exec_channel *dst,
458 const union tgsi_exec_channel *src)
459 {
460 dst->i[0] = src->i[0] >= 0 ? src->i[0] : -src->i[0];
461 dst->i[1] = src->i[1] >= 0 ? src->i[1] : -src->i[1];
462 dst->i[2] = src->i[2] >= 0 ? src->i[2] : -src->i[2];
463 dst->i[3] = src->i[3] >= 0 ? src->i[3] : -src->i[3];
464 }
465
466 static void
467 micro_ineg(union tgsi_exec_channel *dst,
468 const union tgsi_exec_channel *src)
469 {
470 dst->i[0] = -src->i[0];
471 dst->i[1] = -src->i[1];
472 dst->i[2] = -src->i[2];
473 dst->i[3] = -src->i[3];
474 }
475
476 static void
477 micro_lg2(union tgsi_exec_channel *dst,
478 const union tgsi_exec_channel *src)
479 {
480 #if FAST_MATH
481 dst->f[0] = util_fast_log2(src->f[0]);
482 dst->f[1] = util_fast_log2(src->f[1]);
483 dst->f[2] = util_fast_log2(src->f[2]);
484 dst->f[3] = util_fast_log2(src->f[3]);
485 #else
486 dst->f[0] = logf(src->f[0]) * 1.442695f;
487 dst->f[1] = logf(src->f[1]) * 1.442695f;
488 dst->f[2] = logf(src->f[2]) * 1.442695f;
489 dst->f[3] = logf(src->f[3]) * 1.442695f;
490 #endif
491 }
492
493 static void
494 micro_lrp(union tgsi_exec_channel *dst,
495 const union tgsi_exec_channel *src0,
496 const union tgsi_exec_channel *src1,
497 const union tgsi_exec_channel *src2)
498 {
499 dst->f[0] = src0->f[0] * (src1->f[0] - src2->f[0]) + src2->f[0];
500 dst->f[1] = src0->f[1] * (src1->f[1] - src2->f[1]) + src2->f[1];
501 dst->f[2] = src0->f[2] * (src1->f[2] - src2->f[2]) + src2->f[2];
502 dst->f[3] = src0->f[3] * (src1->f[3] - src2->f[3]) + src2->f[3];
503 }
504
505 static void
506 micro_mad(union tgsi_exec_channel *dst,
507 const union tgsi_exec_channel *src0,
508 const union tgsi_exec_channel *src1,
509 const union tgsi_exec_channel *src2)
510 {
511 dst->f[0] = src0->f[0] * src1->f[0] + src2->f[0];
512 dst->f[1] = src0->f[1] * src1->f[1] + src2->f[1];
513 dst->f[2] = src0->f[2] * src1->f[2] + src2->f[2];
514 dst->f[3] = src0->f[3] * src1->f[3] + src2->f[3];
515 }
516
517 static void
518 micro_mov(union tgsi_exec_channel *dst,
519 const union tgsi_exec_channel *src)
520 {
521 dst->u[0] = src->u[0];
522 dst->u[1] = src->u[1];
523 dst->u[2] = src->u[2];
524 dst->u[3] = src->u[3];
525 }
526
527 static void
528 micro_rcp(union tgsi_exec_channel *dst,
529 const union tgsi_exec_channel *src)
530 {
531 #if 0 /* for debugging */
532 assert(src->f[0] != 0.0f);
533 assert(src->f[1] != 0.0f);
534 assert(src->f[2] != 0.0f);
535 assert(src->f[3] != 0.0f);
536 #endif
537 dst->f[0] = 1.0f / src->f[0];
538 dst->f[1] = 1.0f / src->f[1];
539 dst->f[2] = 1.0f / src->f[2];
540 dst->f[3] = 1.0f / src->f[3];
541 }
542
543 static void
544 micro_rnd(union tgsi_exec_channel *dst,
545 const union tgsi_exec_channel *src)
546 {
547 dst->f[0] = _mesa_roundevenf(src->f[0]);
548 dst->f[1] = _mesa_roundevenf(src->f[1]);
549 dst->f[2] = _mesa_roundevenf(src->f[2]);
550 dst->f[3] = _mesa_roundevenf(src->f[3]);
551 }
552
553 static void
554 micro_rsq(union tgsi_exec_channel *dst,
555 const union tgsi_exec_channel *src)
556 {
557 #if 0 /* for debugging */
558 assert(src->f[0] != 0.0f);
559 assert(src->f[1] != 0.0f);
560 assert(src->f[2] != 0.0f);
561 assert(src->f[3] != 0.0f);
562 #endif
563 dst->f[0] = 1.0f / sqrtf(src->f[0]);
564 dst->f[1] = 1.0f / sqrtf(src->f[1]);
565 dst->f[2] = 1.0f / sqrtf(src->f[2]);
566 dst->f[3] = 1.0f / sqrtf(src->f[3]);
567 }
568
569 static void
570 micro_sqrt(union tgsi_exec_channel *dst,
571 const union tgsi_exec_channel *src)
572 {
573 dst->f[0] = sqrtf(src->f[0]);
574 dst->f[1] = sqrtf(src->f[1]);
575 dst->f[2] = sqrtf(src->f[2]);
576 dst->f[3] = sqrtf(src->f[3]);
577 }
578
579 static void
580 micro_seq(union tgsi_exec_channel *dst,
581 const union tgsi_exec_channel *src0,
582 const union tgsi_exec_channel *src1)
583 {
584 dst->f[0] = src0->f[0] == src1->f[0] ? 1.0f : 0.0f;
585 dst->f[1] = src0->f[1] == src1->f[1] ? 1.0f : 0.0f;
586 dst->f[2] = src0->f[2] == src1->f[2] ? 1.0f : 0.0f;
587 dst->f[3] = src0->f[3] == src1->f[3] ? 1.0f : 0.0f;
588 }
589
590 static void
591 micro_sge(union tgsi_exec_channel *dst,
592 const union tgsi_exec_channel *src0,
593 const union tgsi_exec_channel *src1)
594 {
595 dst->f[0] = src0->f[0] >= src1->f[0] ? 1.0f : 0.0f;
596 dst->f[1] = src0->f[1] >= src1->f[1] ? 1.0f : 0.0f;
597 dst->f[2] = src0->f[2] >= src1->f[2] ? 1.0f : 0.0f;
598 dst->f[3] = src0->f[3] >= src1->f[3] ? 1.0f : 0.0f;
599 }
600
601 static void
602 micro_sgn(union tgsi_exec_channel *dst,
603 const union tgsi_exec_channel *src)
604 {
605 dst->f[0] = src->f[0] < 0.0f ? -1.0f : src->f[0] > 0.0f ? 1.0f : 0.0f;
606 dst->f[1] = src->f[1] < 0.0f ? -1.0f : src->f[1] > 0.0f ? 1.0f : 0.0f;
607 dst->f[2] = src->f[2] < 0.0f ? -1.0f : src->f[2] > 0.0f ? 1.0f : 0.0f;
608 dst->f[3] = src->f[3] < 0.0f ? -1.0f : src->f[3] > 0.0f ? 1.0f : 0.0f;
609 }
610
611 static void
612 micro_isgn(union tgsi_exec_channel *dst,
613 const union tgsi_exec_channel *src)
614 {
615 dst->i[0] = src->i[0] < 0 ? -1 : src->i[0] > 0 ? 1 : 0;
616 dst->i[1] = src->i[1] < 0 ? -1 : src->i[1] > 0 ? 1 : 0;
617 dst->i[2] = src->i[2] < 0 ? -1 : src->i[2] > 0 ? 1 : 0;
618 dst->i[3] = src->i[3] < 0 ? -1 : src->i[3] > 0 ? 1 : 0;
619 }
620
621 static void
622 micro_sgt(union tgsi_exec_channel *dst,
623 const union tgsi_exec_channel *src0,
624 const union tgsi_exec_channel *src1)
625 {
626 dst->f[0] = src0->f[0] > src1->f[0] ? 1.0f : 0.0f;
627 dst->f[1] = src0->f[1] > src1->f[1] ? 1.0f : 0.0f;
628 dst->f[2] = src0->f[2] > src1->f[2] ? 1.0f : 0.0f;
629 dst->f[3] = src0->f[3] > src1->f[3] ? 1.0f : 0.0f;
630 }
631
632 static void
633 micro_sin(union tgsi_exec_channel *dst,
634 const union tgsi_exec_channel *src)
635 {
636 dst->f[0] = sinf(src->f[0]);
637 dst->f[1] = sinf(src->f[1]);
638 dst->f[2] = sinf(src->f[2]);
639 dst->f[3] = sinf(src->f[3]);
640 }
641
642 static void
643 micro_sle(union tgsi_exec_channel *dst,
644 const union tgsi_exec_channel *src0,
645 const union tgsi_exec_channel *src1)
646 {
647 dst->f[0] = src0->f[0] <= src1->f[0] ? 1.0f : 0.0f;
648 dst->f[1] = src0->f[1] <= src1->f[1] ? 1.0f : 0.0f;
649 dst->f[2] = src0->f[2] <= src1->f[2] ? 1.0f : 0.0f;
650 dst->f[3] = src0->f[3] <= src1->f[3] ? 1.0f : 0.0f;
651 }
652
653 static void
654 micro_slt(union tgsi_exec_channel *dst,
655 const union tgsi_exec_channel *src0,
656 const union tgsi_exec_channel *src1)
657 {
658 dst->f[0] = src0->f[0] < src1->f[0] ? 1.0f : 0.0f;
659 dst->f[1] = src0->f[1] < src1->f[1] ? 1.0f : 0.0f;
660 dst->f[2] = src0->f[2] < src1->f[2] ? 1.0f : 0.0f;
661 dst->f[3] = src0->f[3] < src1->f[3] ? 1.0f : 0.0f;
662 }
663
664 static void
665 micro_sne(union tgsi_exec_channel *dst,
666 const union tgsi_exec_channel *src0,
667 const union tgsi_exec_channel *src1)
668 {
669 dst->f[0] = src0->f[0] != src1->f[0] ? 1.0f : 0.0f;
670 dst->f[1] = src0->f[1] != src1->f[1] ? 1.0f : 0.0f;
671 dst->f[2] = src0->f[2] != src1->f[2] ? 1.0f : 0.0f;
672 dst->f[3] = src0->f[3] != src1->f[3] ? 1.0f : 0.0f;
673 }
674
675 static void
676 micro_trunc(union tgsi_exec_channel *dst,
677 const union tgsi_exec_channel *src)
678 {
679 dst->f[0] = truncf(src->f[0]);
680 dst->f[1] = truncf(src->f[1]);
681 dst->f[2] = truncf(src->f[2]);
682 dst->f[3] = truncf(src->f[3]);
683 }
684
685 static void
686 micro_u2d(union tgsi_double_channel *dst,
687 const union tgsi_exec_channel *src)
688 {
689 dst->d[0] = (double)src->u[0];
690 dst->d[1] = (double)src->u[1];
691 dst->d[2] = (double)src->u[2];
692 dst->d[3] = (double)src->u[3];
693 }
694
695 static void
696 micro_i64abs(union tgsi_double_channel *dst,
697 const union tgsi_double_channel *src)
698 {
699 dst->i64[0] = src->i64[0] >= 0.0 ? src->i64[0] : -src->i64[0];
700 dst->i64[1] = src->i64[1] >= 0.0 ? src->i64[1] : -src->i64[1];
701 dst->i64[2] = src->i64[2] >= 0.0 ? src->i64[2] : -src->i64[2];
702 dst->i64[3] = src->i64[3] >= 0.0 ? src->i64[3] : -src->i64[3];
703 }
704
705 static void
706 micro_i64sgn(union tgsi_double_channel *dst,
707 const union tgsi_double_channel *src)
708 {
709 dst->i64[0] = src->i64[0] < 0 ? -1 : src->i64[0] > 0 ? 1 : 0;
710 dst->i64[1] = src->i64[1] < 0 ? -1 : src->i64[1] > 0 ? 1 : 0;
711 dst->i64[2] = src->i64[2] < 0 ? -1 : src->i64[2] > 0 ? 1 : 0;
712 dst->i64[3] = src->i64[3] < 0 ? -1 : src->i64[3] > 0 ? 1 : 0;
713 }
714
715 static void
716 micro_i64neg(union tgsi_double_channel *dst,
717 const union tgsi_double_channel *src)
718 {
719 dst->i64[0] = -src->i64[0];
720 dst->i64[1] = -src->i64[1];
721 dst->i64[2] = -src->i64[2];
722 dst->i64[3] = -src->i64[3];
723 }
724
725 static void
726 micro_u64seq(union tgsi_double_channel *dst,
727 const union tgsi_double_channel *src)
728 {
729 dst->u[0][0] = src[0].u64[0] == src[1].u64[0] ? ~0U : 0U;
730 dst->u[1][0] = src[0].u64[1] == src[1].u64[1] ? ~0U : 0U;
731 dst->u[2][0] = src[0].u64[2] == src[1].u64[2] ? ~0U : 0U;
732 dst->u[3][0] = src[0].u64[3] == src[1].u64[3] ? ~0U : 0U;
733 }
734
735 static void
736 micro_u64sne(union tgsi_double_channel *dst,
737 const union tgsi_double_channel *src)
738 {
739 dst->u[0][0] = src[0].u64[0] != src[1].u64[0] ? ~0U : 0U;
740 dst->u[1][0] = src[0].u64[1] != src[1].u64[1] ? ~0U : 0U;
741 dst->u[2][0] = src[0].u64[2] != src[1].u64[2] ? ~0U : 0U;
742 dst->u[3][0] = src[0].u64[3] != src[1].u64[3] ? ~0U : 0U;
743 }
744
745 static void
746 micro_i64slt(union tgsi_double_channel *dst,
747 const union tgsi_double_channel *src)
748 {
749 dst->u[0][0] = src[0].i64[0] < src[1].i64[0] ? ~0U : 0U;
750 dst->u[1][0] = src[0].i64[1] < src[1].i64[1] ? ~0U : 0U;
751 dst->u[2][0] = src[0].i64[2] < src[1].i64[2] ? ~0U : 0U;
752 dst->u[3][0] = src[0].i64[3] < src[1].i64[3] ? ~0U : 0U;
753 }
754
755 static void
756 micro_u64slt(union tgsi_double_channel *dst,
757 const union tgsi_double_channel *src)
758 {
759 dst->u[0][0] = src[0].u64[0] < src[1].u64[0] ? ~0U : 0U;
760 dst->u[1][0] = src[0].u64[1] < src[1].u64[1] ? ~0U : 0U;
761 dst->u[2][0] = src[0].u64[2] < src[1].u64[2] ? ~0U : 0U;
762 dst->u[3][0] = src[0].u64[3] < src[1].u64[3] ? ~0U : 0U;
763 }
764
765 static void
766 micro_i64sge(union tgsi_double_channel *dst,
767 const union tgsi_double_channel *src)
768 {
769 dst->u[0][0] = src[0].i64[0] >= src[1].i64[0] ? ~0U : 0U;
770 dst->u[1][0] = src[0].i64[1] >= src[1].i64[1] ? ~0U : 0U;
771 dst->u[2][0] = src[0].i64[2] >= src[1].i64[2] ? ~0U : 0U;
772 dst->u[3][0] = src[0].i64[3] >= src[1].i64[3] ? ~0U : 0U;
773 }
774
775 static void
776 micro_u64sge(union tgsi_double_channel *dst,
777 const union tgsi_double_channel *src)
778 {
779 dst->u[0][0] = src[0].u64[0] >= src[1].u64[0] ? ~0U : 0U;
780 dst->u[1][0] = src[0].u64[1] >= src[1].u64[1] ? ~0U : 0U;
781 dst->u[2][0] = src[0].u64[2] >= src[1].u64[2] ? ~0U : 0U;
782 dst->u[3][0] = src[0].u64[3] >= src[1].u64[3] ? ~0U : 0U;
783 }
784
785 static void
786 micro_u64max(union tgsi_double_channel *dst,
787 const union tgsi_double_channel *src)
788 {
789 dst->u64[0] = src[0].u64[0] > src[1].u64[0] ? src[0].u64[0] : src[1].u64[0];
790 dst->u64[1] = src[0].u64[1] > src[1].u64[1] ? src[0].u64[1] : src[1].u64[1];
791 dst->u64[2] = src[0].u64[2] > src[1].u64[2] ? src[0].u64[2] : src[1].u64[2];
792 dst->u64[3] = src[0].u64[3] > src[1].u64[3] ? src[0].u64[3] : src[1].u64[3];
793 }
794
795 static void
796 micro_i64max(union tgsi_double_channel *dst,
797 const union tgsi_double_channel *src)
798 {
799 dst->i64[0] = src[0].i64[0] > src[1].i64[0] ? src[0].i64[0] : src[1].i64[0];
800 dst->i64[1] = src[0].i64[1] > src[1].i64[1] ? src[0].i64[1] : src[1].i64[1];
801 dst->i64[2] = src[0].i64[2] > src[1].i64[2] ? src[0].i64[2] : src[1].i64[2];
802 dst->i64[3] = src[0].i64[3] > src[1].i64[3] ? src[0].i64[3] : src[1].i64[3];
803 }
804
805 static void
806 micro_u64min(union tgsi_double_channel *dst,
807 const union tgsi_double_channel *src)
808 {
809 dst->u64[0] = src[0].u64[0] < src[1].u64[0] ? src[0].u64[0] : src[1].u64[0];
810 dst->u64[1] = src[0].u64[1] < src[1].u64[1] ? src[0].u64[1] : src[1].u64[1];
811 dst->u64[2] = src[0].u64[2] < src[1].u64[2] ? src[0].u64[2] : src[1].u64[2];
812 dst->u64[3] = src[0].u64[3] < src[1].u64[3] ? src[0].u64[3] : src[1].u64[3];
813 }
814
815 static void
816 micro_i64min(union tgsi_double_channel *dst,
817 const union tgsi_double_channel *src)
818 {
819 dst->i64[0] = src[0].i64[0] < src[1].i64[0] ? src[0].i64[0] : src[1].i64[0];
820 dst->i64[1] = src[0].i64[1] < src[1].i64[1] ? src[0].i64[1] : src[1].i64[1];
821 dst->i64[2] = src[0].i64[2] < src[1].i64[2] ? src[0].i64[2] : src[1].i64[2];
822 dst->i64[3] = src[0].i64[3] < src[1].i64[3] ? src[0].i64[3] : src[1].i64[3];
823 }
824
825 static void
826 micro_u64add(union tgsi_double_channel *dst,
827 const union tgsi_double_channel *src)
828 {
829 dst->u64[0] = src[0].u64[0] + src[1].u64[0];
830 dst->u64[1] = src[0].u64[1] + src[1].u64[1];
831 dst->u64[2] = src[0].u64[2] + src[1].u64[2];
832 dst->u64[3] = src[0].u64[3] + src[1].u64[3];
833 }
834
835 static void
836 micro_u64mul(union tgsi_double_channel *dst,
837 const union tgsi_double_channel *src)
838 {
839 dst->u64[0] = src[0].u64[0] * src[1].u64[0];
840 dst->u64[1] = src[0].u64[1] * src[1].u64[1];
841 dst->u64[2] = src[0].u64[2] * src[1].u64[2];
842 dst->u64[3] = src[0].u64[3] * src[1].u64[3];
843 }
844
845 static void
846 micro_u64div(union tgsi_double_channel *dst,
847 const union tgsi_double_channel *src)
848 {
849 dst->u64[0] = src[1].u64[0] ? src[0].u64[0] / src[1].u64[0] : ~0ull;
850 dst->u64[1] = src[1].u64[1] ? src[0].u64[1] / src[1].u64[1] : ~0ull;
851 dst->u64[2] = src[1].u64[2] ? src[0].u64[2] / src[1].u64[2] : ~0ull;
852 dst->u64[3] = src[1].u64[3] ? src[0].u64[3] / src[1].u64[3] : ~0ull;
853 }
854
855 static void
856 micro_i64div(union tgsi_double_channel *dst,
857 const union tgsi_double_channel *src)
858 {
859 dst->i64[0] = src[1].i64[0] ? src[0].i64[0] / src[1].i64[0] : 0;
860 dst->i64[1] = src[1].i64[1] ? src[0].i64[1] / src[1].i64[1] : 0;
861 dst->i64[2] = src[1].i64[2] ? src[0].i64[2] / src[1].i64[2] : 0;
862 dst->i64[3] = src[1].i64[3] ? src[0].i64[3] / src[1].i64[3] : 0;
863 }
864
865 static void
866 micro_u64mod(union tgsi_double_channel *dst,
867 const union tgsi_double_channel *src)
868 {
869 dst->u64[0] = src[1].u64[0] ? src[0].u64[0] % src[1].u64[0] : ~0ull;
870 dst->u64[1] = src[1].u64[1] ? src[0].u64[1] % src[1].u64[1] : ~0ull;
871 dst->u64[2] = src[1].u64[2] ? src[0].u64[2] % src[1].u64[2] : ~0ull;
872 dst->u64[3] = src[1].u64[3] ? src[0].u64[3] % src[1].u64[3] : ~0ull;
873 }
874
875 static void
876 micro_i64mod(union tgsi_double_channel *dst,
877 const union tgsi_double_channel *src)
878 {
879 dst->i64[0] = src[1].i64[0] ? src[0].i64[0] % src[1].i64[0] : ~0ll;
880 dst->i64[1] = src[1].i64[1] ? src[0].i64[1] % src[1].i64[1] : ~0ll;
881 dst->i64[2] = src[1].i64[2] ? src[0].i64[2] % src[1].i64[2] : ~0ll;
882 dst->i64[3] = src[1].i64[3] ? src[0].i64[3] % src[1].i64[3] : ~0ll;
883 }
884
885 static void
886 micro_u64shl(union tgsi_double_channel *dst,
887 const union tgsi_double_channel *src0,
888 union tgsi_exec_channel *src1)
889 {
890 unsigned masked_count;
891 masked_count = src1->u[0] & 0x3f;
892 dst->u64[0] = src0->u64[0] << masked_count;
893 masked_count = src1->u[1] & 0x3f;
894 dst->u64[1] = src0->u64[1] << masked_count;
895 masked_count = src1->u[2] & 0x3f;
896 dst->u64[2] = src0->u64[2] << masked_count;
897 masked_count = src1->u[3] & 0x3f;
898 dst->u64[3] = src0->u64[3] << masked_count;
899 }
900
901 static void
902 micro_i64shr(union tgsi_double_channel *dst,
903 const union tgsi_double_channel *src0,
904 union tgsi_exec_channel *src1)
905 {
906 unsigned masked_count;
907 masked_count = src1->u[0] & 0x3f;
908 dst->i64[0] = src0->i64[0] >> masked_count;
909 masked_count = src1->u[1] & 0x3f;
910 dst->i64[1] = src0->i64[1] >> masked_count;
911 masked_count = src1->u[2] & 0x3f;
912 dst->i64[2] = src0->i64[2] >> masked_count;
913 masked_count = src1->u[3] & 0x3f;
914 dst->i64[3] = src0->i64[3] >> masked_count;
915 }
916
917 static void
918 micro_u64shr(union tgsi_double_channel *dst,
919 const union tgsi_double_channel *src0,
920 union tgsi_exec_channel *src1)
921 {
922 unsigned masked_count;
923 masked_count = src1->u[0] & 0x3f;
924 dst->u64[0] = src0->u64[0] >> masked_count;
925 masked_count = src1->u[1] & 0x3f;
926 dst->u64[1] = src0->u64[1] >> masked_count;
927 masked_count = src1->u[2] & 0x3f;
928 dst->u64[2] = src0->u64[2] >> masked_count;
929 masked_count = src1->u[3] & 0x3f;
930 dst->u64[3] = src0->u64[3] >> masked_count;
931 }
932
933 enum tgsi_exec_datatype {
934 TGSI_EXEC_DATA_FLOAT,
935 TGSI_EXEC_DATA_INT,
936 TGSI_EXEC_DATA_UINT,
937 TGSI_EXEC_DATA_DOUBLE,
938 TGSI_EXEC_DATA_INT64,
939 TGSI_EXEC_DATA_UINT64,
940 };
941
942 /*
943 * Shorthand locations of various utility registers (_I = Index, _C = Channel)
944 */
945 #define TEMP_KILMASK_I TGSI_EXEC_TEMP_KILMASK_I
946 #define TEMP_KILMASK_C TGSI_EXEC_TEMP_KILMASK_C
947 #define TEMP_OUTPUT_I TGSI_EXEC_TEMP_OUTPUT_I
948 #define TEMP_OUTPUT_C TGSI_EXEC_TEMP_OUTPUT_C
949 #define TEMP_PRIMITIVE_I TGSI_EXEC_TEMP_PRIMITIVE_I
950 #define TEMP_PRIMITIVE_C TGSI_EXEC_TEMP_PRIMITIVE_C
951
952
953 /** The execution mask depends on the conditional mask and the loop mask */
954 #define UPDATE_EXEC_MASK(MACH) \
955 MACH->ExecMask = MACH->CondMask & MACH->LoopMask & MACH->ContMask & MACH->Switch.mask & MACH->FuncMask
956
957
958 static const union tgsi_exec_channel ZeroVec =
959 { { 0.0, 0.0, 0.0, 0.0 } };
960
961 static const union tgsi_exec_channel OneVec = {
962 {1.0f, 1.0f, 1.0f, 1.0f}
963 };
964
965 static const union tgsi_exec_channel P128Vec = {
966 {128.0f, 128.0f, 128.0f, 128.0f}
967 };
968
969 static const union tgsi_exec_channel M128Vec = {
970 {-128.0f, -128.0f, -128.0f, -128.0f}
971 };
972
973
974 /**
975 * Assert that none of the float values in 'chan' are infinite or NaN.
976 * NaN and Inf may occur normally during program execution and should
977 * not lead to crashes, etc. But when debugging, it's helpful to catch
978 * them.
979 */
980 static inline void
981 check_inf_or_nan(const union tgsi_exec_channel *chan)
982 {
983 assert(!util_is_inf_or_nan((chan)->f[0]));
984 assert(!util_is_inf_or_nan((chan)->f[1]));
985 assert(!util_is_inf_or_nan((chan)->f[2]));
986 assert(!util_is_inf_or_nan((chan)->f[3]));
987 }
988
989
990 #ifdef DEBUG
991 static void
992 print_chan(const char *msg, const union tgsi_exec_channel *chan)
993 {
994 debug_printf("%s = {%f, %f, %f, %f}\n",
995 msg, chan->f[0], chan->f[1], chan->f[2], chan->f[3]);
996 }
997 #endif
998
999
1000 #ifdef DEBUG
1001 static void
1002 print_temp(const struct tgsi_exec_machine *mach, uint index)
1003 {
1004 const struct tgsi_exec_vector *tmp = &mach->Temps[index];
1005 int i;
1006 debug_printf("Temp[%u] =\n", index);
1007 for (i = 0; i < 4; i++) {
1008 debug_printf(" %c: { %f, %f, %f, %f }\n",
1009 "XYZW"[i],
1010 tmp->xyzw[i].f[0],
1011 tmp->xyzw[i].f[1],
1012 tmp->xyzw[i].f[2],
1013 tmp->xyzw[i].f[3]);
1014 }
1015 }
1016 #endif
1017
1018
1019 void
1020 tgsi_exec_set_constant_buffers(struct tgsi_exec_machine *mach,
1021 unsigned num_bufs,
1022 const void **bufs,
1023 const unsigned *buf_sizes)
1024 {
1025 unsigned i;
1026
1027 for (i = 0; i < num_bufs; i++) {
1028 mach->Consts[i] = bufs[i];
1029 mach->ConstsSize[i] = buf_sizes[i];
1030 }
1031 }
1032
1033
1034 /**
1035 * Check if there's a potential src/dst register data dependency when
1036 * using SOA execution.
1037 * Example:
1038 * MOV T, T.yxwz;
1039 * This would expand into:
1040 * MOV t0, t1;
1041 * MOV t1, t0;
1042 * MOV t2, t3;
1043 * MOV t3, t2;
1044 * The second instruction will have the wrong value for t0 if executed as-is.
1045 */
1046 boolean
1047 tgsi_check_soa_dependencies(const struct tgsi_full_instruction *inst)
1048 {
1049 uint i, chan;
1050
1051 uint writemask = inst->Dst[0].Register.WriteMask;
1052 if (writemask == TGSI_WRITEMASK_X ||
1053 writemask == TGSI_WRITEMASK_Y ||
1054 writemask == TGSI_WRITEMASK_Z ||
1055 writemask == TGSI_WRITEMASK_W ||
1056 writemask == TGSI_WRITEMASK_NONE) {
1057 /* no chance of data dependency */
1058 return FALSE;
1059 }
1060
1061 /* loop over src regs */
1062 for (i = 0; i < inst->Instruction.NumSrcRegs; i++) {
1063 if ((inst->Src[i].Register.File ==
1064 inst->Dst[0].Register.File) &&
1065 ((inst->Src[i].Register.Index ==
1066 inst->Dst[0].Register.Index) ||
1067 inst->Src[i].Register.Indirect ||
1068 inst->Dst[0].Register.Indirect)) {
1069 /* loop over dest channels */
1070 uint channelsWritten = 0x0;
1071 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
1072 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
1073 /* check if we're reading a channel that's been written */
1074 uint swizzle = tgsi_util_get_full_src_register_swizzle(&inst->Src[i], chan);
1075 if (channelsWritten & (1 << swizzle)) {
1076 return TRUE;
1077 }
1078
1079 channelsWritten |= (1 << chan);
1080 }
1081 }
1082 }
1083 }
1084 return FALSE;
1085 }
1086
1087
1088 /**
1089 * Initialize machine state by expanding tokens to full instructions,
1090 * allocating temporary storage, setting up constants, etc.
1091 * After this, we can call tgsi_exec_machine_run() many times.
1092 */
1093 void
1094 tgsi_exec_machine_bind_shader(
1095 struct tgsi_exec_machine *mach,
1096 const struct tgsi_token *tokens,
1097 struct tgsi_sampler *sampler,
1098 struct tgsi_image *image,
1099 struct tgsi_buffer *buffer)
1100 {
1101 uint k;
1102 struct tgsi_parse_context parse;
1103 struct tgsi_full_instruction *instructions;
1104 struct tgsi_full_declaration *declarations;
1105 uint maxInstructions = 10, numInstructions = 0;
1106 uint maxDeclarations = 10, numDeclarations = 0;
1107
1108 #if 0
1109 tgsi_dump(tokens, 0);
1110 #endif
1111
1112 util_init_math();
1113
1114
1115 mach->Tokens = tokens;
1116 mach->Sampler = sampler;
1117 mach->Image = image;
1118 mach->Buffer = buffer;
1119
1120 if (!tokens) {
1121 /* unbind and free all */
1122 FREE(mach->Declarations);
1123 mach->Declarations = NULL;
1124 mach->NumDeclarations = 0;
1125
1126 FREE(mach->Instructions);
1127 mach->Instructions = NULL;
1128 mach->NumInstructions = 0;
1129
1130 return;
1131 }
1132
1133 k = tgsi_parse_init (&parse, mach->Tokens);
1134 if (k != TGSI_PARSE_OK) {
1135 debug_printf( "Problem parsing!\n" );
1136 return;
1137 }
1138
1139 mach->ImmLimit = 0;
1140 mach->NumOutputs = 0;
1141
1142 for (k = 0; k < TGSI_SEMANTIC_COUNT; k++)
1143 mach->SysSemanticToIndex[k] = -1;
1144
1145 if (mach->ShaderType == PIPE_SHADER_GEOMETRY &&
1146 !mach->UsedGeometryShader) {
1147 struct tgsi_exec_vector *inputs;
1148 struct tgsi_exec_vector *outputs;
1149
1150 inputs = align_malloc(sizeof(struct tgsi_exec_vector) *
1151 TGSI_MAX_PRIM_VERTICES * PIPE_MAX_SHADER_INPUTS,
1152 16);
1153
1154 if (!inputs)
1155 return;
1156
1157 outputs = align_malloc(sizeof(struct tgsi_exec_vector) *
1158 TGSI_MAX_TOTAL_VERTICES, 16);
1159
1160 if (!outputs) {
1161 align_free(inputs);
1162 return;
1163 }
1164
1165 align_free(mach->Inputs);
1166 align_free(mach->Outputs);
1167
1168 mach->Inputs = inputs;
1169 mach->Outputs = outputs;
1170 mach->UsedGeometryShader = TRUE;
1171 }
1172
1173 declarations = (struct tgsi_full_declaration *)
1174 MALLOC( maxDeclarations * sizeof(struct tgsi_full_declaration) );
1175
1176 if (!declarations) {
1177 return;
1178 }
1179
1180 instructions = (struct tgsi_full_instruction *)
1181 MALLOC( maxInstructions * sizeof(struct tgsi_full_instruction) );
1182
1183 if (!instructions) {
1184 FREE( declarations );
1185 return;
1186 }
1187
1188 while( !tgsi_parse_end_of_tokens( &parse ) ) {
1189 uint i;
1190
1191 tgsi_parse_token( &parse );
1192 switch( parse.FullToken.Token.Type ) {
1193 case TGSI_TOKEN_TYPE_DECLARATION:
1194 /* save expanded declaration */
1195 if (numDeclarations == maxDeclarations) {
1196 declarations = REALLOC(declarations,
1197 maxDeclarations
1198 * sizeof(struct tgsi_full_declaration),
1199 (maxDeclarations + 10)
1200 * sizeof(struct tgsi_full_declaration));
1201 maxDeclarations += 10;
1202 }
1203 if (parse.FullToken.FullDeclaration.Declaration.File == TGSI_FILE_OUTPUT) {
1204 unsigned reg;
1205 for (reg = parse.FullToken.FullDeclaration.Range.First;
1206 reg <= parse.FullToken.FullDeclaration.Range.Last;
1207 ++reg) {
1208 ++mach->NumOutputs;
1209 }
1210 }
1211 else if (parse.FullToken.FullDeclaration.Declaration.File == TGSI_FILE_SYSTEM_VALUE) {
1212 const struct tgsi_full_declaration *decl = &parse.FullToken.FullDeclaration;
1213 mach->SysSemanticToIndex[decl->Semantic.Name] = decl->Range.First;
1214 }
1215
1216 memcpy(declarations + numDeclarations,
1217 &parse.FullToken.FullDeclaration,
1218 sizeof(declarations[0]));
1219 numDeclarations++;
1220 break;
1221
1222 case TGSI_TOKEN_TYPE_IMMEDIATE:
1223 {
1224 uint size = parse.FullToken.FullImmediate.Immediate.NrTokens - 1;
1225 assert( size <= 4 );
1226 assert( mach->ImmLimit + 1 <= TGSI_EXEC_NUM_IMMEDIATES );
1227
1228 for( i = 0; i < size; i++ ) {
1229 mach->Imms[mach->ImmLimit][i] =
1230 parse.FullToken.FullImmediate.u[i].Float;
1231 }
1232 mach->ImmLimit += 1;
1233 }
1234 break;
1235
1236 case TGSI_TOKEN_TYPE_INSTRUCTION:
1237
1238 /* save expanded instruction */
1239 if (numInstructions == maxInstructions) {
1240 instructions = REALLOC(instructions,
1241 maxInstructions
1242 * sizeof(struct tgsi_full_instruction),
1243 (maxInstructions + 10)
1244 * sizeof(struct tgsi_full_instruction));
1245 maxInstructions += 10;
1246 }
1247
1248 memcpy(instructions + numInstructions,
1249 &parse.FullToken.FullInstruction,
1250 sizeof(instructions[0]));
1251
1252 numInstructions++;
1253 break;
1254
1255 case TGSI_TOKEN_TYPE_PROPERTY:
1256 if (mach->ShaderType == PIPE_SHADER_GEOMETRY) {
1257 if (parse.FullToken.FullProperty.Property.PropertyName == TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES) {
1258 mach->MaxOutputVertices = parse.FullToken.FullProperty.u[0].Data;
1259 }
1260 }
1261 break;
1262
1263 default:
1264 assert( 0 );
1265 }
1266 }
1267 tgsi_parse_free (&parse);
1268
1269 FREE(mach->Declarations);
1270 mach->Declarations = declarations;
1271 mach->NumDeclarations = numDeclarations;
1272
1273 FREE(mach->Instructions);
1274 mach->Instructions = instructions;
1275 mach->NumInstructions = numInstructions;
1276 }
1277
1278
1279 struct tgsi_exec_machine *
1280 tgsi_exec_machine_create(enum pipe_shader_type shader_type)
1281 {
1282 struct tgsi_exec_machine *mach;
1283 uint i;
1284
1285 mach = align_malloc( sizeof *mach, 16 );
1286 if (!mach)
1287 goto fail;
1288
1289 memset(mach, 0, sizeof(*mach));
1290
1291 mach->ShaderType = shader_type;
1292 mach->Addrs = &mach->Temps[TGSI_EXEC_TEMP_ADDR];
1293 mach->MaxGeometryShaderOutputs = TGSI_MAX_TOTAL_VERTICES;
1294
1295 if (shader_type != PIPE_SHADER_COMPUTE) {
1296 mach->Inputs = align_malloc(sizeof(struct tgsi_exec_vector) * PIPE_MAX_SHADER_INPUTS, 16);
1297 mach->Outputs = align_malloc(sizeof(struct tgsi_exec_vector) * PIPE_MAX_SHADER_OUTPUTS, 16);
1298 if (!mach->Inputs || !mach->Outputs)
1299 goto fail;
1300 }
1301
1302 /* Setup constants needed by the SSE2 executor. */
1303 for( i = 0; i < 4; i++ ) {
1304 mach->Temps[TGSI_EXEC_TEMP_00000000_I].xyzw[TGSI_EXEC_TEMP_00000000_C].u[i] = 0x00000000;
1305 mach->Temps[TGSI_EXEC_TEMP_7FFFFFFF_I].xyzw[TGSI_EXEC_TEMP_7FFFFFFF_C].u[i] = 0x7FFFFFFF;
1306 mach->Temps[TGSI_EXEC_TEMP_80000000_I].xyzw[TGSI_EXEC_TEMP_80000000_C].u[i] = 0x80000000;
1307 mach->Temps[TGSI_EXEC_TEMP_FFFFFFFF_I].xyzw[TGSI_EXEC_TEMP_FFFFFFFF_C].u[i] = 0xFFFFFFFF; /* not used */
1308 mach->Temps[TGSI_EXEC_TEMP_ONE_I].xyzw[TGSI_EXEC_TEMP_ONE_C].f[i] = 1.0f;
1309 mach->Temps[TGSI_EXEC_TEMP_TWO_I].xyzw[TGSI_EXEC_TEMP_TWO_C].f[i] = 2.0f; /* not used */
1310 mach->Temps[TGSI_EXEC_TEMP_128_I].xyzw[TGSI_EXEC_TEMP_128_C].f[i] = 128.0f;
1311 mach->Temps[TGSI_EXEC_TEMP_MINUS_128_I].xyzw[TGSI_EXEC_TEMP_MINUS_128_C].f[i] = -128.0f;
1312 mach->Temps[TGSI_EXEC_TEMP_THREE_I].xyzw[TGSI_EXEC_TEMP_THREE_C].f[i] = 3.0f;
1313 mach->Temps[TGSI_EXEC_TEMP_HALF_I].xyzw[TGSI_EXEC_TEMP_HALF_C].f[i] = 0.5f;
1314 }
1315
1316 #ifdef DEBUG
1317 /* silence warnings */
1318 (void) print_chan;
1319 (void) print_temp;
1320 #endif
1321
1322 return mach;
1323
1324 fail:
1325 if (mach) {
1326 align_free(mach->Inputs);
1327 align_free(mach->Outputs);
1328 align_free(mach);
1329 }
1330 return NULL;
1331 }
1332
1333
1334 void
1335 tgsi_exec_machine_destroy(struct tgsi_exec_machine *mach)
1336 {
1337 if (mach) {
1338 FREE(mach->Instructions);
1339 FREE(mach->Declarations);
1340
1341 align_free(mach->Inputs);
1342 align_free(mach->Outputs);
1343
1344 align_free(mach);
1345 }
1346 }
1347
1348 static void
1349 micro_add(union tgsi_exec_channel *dst,
1350 const union tgsi_exec_channel *src0,
1351 const union tgsi_exec_channel *src1)
1352 {
1353 dst->f[0] = src0->f[0] + src1->f[0];
1354 dst->f[1] = src0->f[1] + src1->f[1];
1355 dst->f[2] = src0->f[2] + src1->f[2];
1356 dst->f[3] = src0->f[3] + src1->f[3];
1357 }
1358
1359 static void
1360 micro_div(
1361 union tgsi_exec_channel *dst,
1362 const union tgsi_exec_channel *src0,
1363 const union tgsi_exec_channel *src1 )
1364 {
1365 if (src1->f[0] != 0) {
1366 dst->f[0] = src0->f[0] / src1->f[0];
1367 }
1368 if (src1->f[1] != 0) {
1369 dst->f[1] = src0->f[1] / src1->f[1];
1370 }
1371 if (src1->f[2] != 0) {
1372 dst->f[2] = src0->f[2] / src1->f[2];
1373 }
1374 if (src1->f[3] != 0) {
1375 dst->f[3] = src0->f[3] / src1->f[3];
1376 }
1377 }
1378
1379 static void
1380 micro_lt(
1381 union tgsi_exec_channel *dst,
1382 const union tgsi_exec_channel *src0,
1383 const union tgsi_exec_channel *src1,
1384 const union tgsi_exec_channel *src2,
1385 const union tgsi_exec_channel *src3 )
1386 {
1387 dst->f[0] = src0->f[0] < src1->f[0] ? src2->f[0] : src3->f[0];
1388 dst->f[1] = src0->f[1] < src1->f[1] ? src2->f[1] : src3->f[1];
1389 dst->f[2] = src0->f[2] < src1->f[2] ? src2->f[2] : src3->f[2];
1390 dst->f[3] = src0->f[3] < src1->f[3] ? src2->f[3] : src3->f[3];
1391 }
1392
1393 static void
1394 micro_max(union tgsi_exec_channel *dst,
1395 const union tgsi_exec_channel *src0,
1396 const union tgsi_exec_channel *src1)
1397 {
1398 dst->f[0] = src0->f[0] > src1->f[0] ? src0->f[0] : src1->f[0];
1399 dst->f[1] = src0->f[1] > src1->f[1] ? src0->f[1] : src1->f[1];
1400 dst->f[2] = src0->f[2] > src1->f[2] ? src0->f[2] : src1->f[2];
1401 dst->f[3] = src0->f[3] > src1->f[3] ? src0->f[3] : src1->f[3];
1402 }
1403
1404 static void
1405 micro_min(union tgsi_exec_channel *dst,
1406 const union tgsi_exec_channel *src0,
1407 const union tgsi_exec_channel *src1)
1408 {
1409 dst->f[0] = src0->f[0] < src1->f[0] ? src0->f[0] : src1->f[0];
1410 dst->f[1] = src0->f[1] < src1->f[1] ? src0->f[1] : src1->f[1];
1411 dst->f[2] = src0->f[2] < src1->f[2] ? src0->f[2] : src1->f[2];
1412 dst->f[3] = src0->f[3] < src1->f[3] ? src0->f[3] : src1->f[3];
1413 }
1414
1415 static void
1416 micro_mul(union tgsi_exec_channel *dst,
1417 const union tgsi_exec_channel *src0,
1418 const union tgsi_exec_channel *src1)
1419 {
1420 dst->f[0] = src0->f[0] * src1->f[0];
1421 dst->f[1] = src0->f[1] * src1->f[1];
1422 dst->f[2] = src0->f[2] * src1->f[2];
1423 dst->f[3] = src0->f[3] * src1->f[3];
1424 }
1425
1426 static void
1427 micro_neg(
1428 union tgsi_exec_channel *dst,
1429 const union tgsi_exec_channel *src )
1430 {
1431 dst->f[0] = -src->f[0];
1432 dst->f[1] = -src->f[1];
1433 dst->f[2] = -src->f[2];
1434 dst->f[3] = -src->f[3];
1435 }
1436
1437 static void
1438 micro_pow(
1439 union tgsi_exec_channel *dst,
1440 const union tgsi_exec_channel *src0,
1441 const union tgsi_exec_channel *src1 )
1442 {
1443 #if FAST_MATH
1444 dst->f[0] = util_fast_pow( src0->f[0], src1->f[0] );
1445 dst->f[1] = util_fast_pow( src0->f[1], src1->f[1] );
1446 dst->f[2] = util_fast_pow( src0->f[2], src1->f[2] );
1447 dst->f[3] = util_fast_pow( src0->f[3], src1->f[3] );
1448 #else
1449 dst->f[0] = powf( src0->f[0], src1->f[0] );
1450 dst->f[1] = powf( src0->f[1], src1->f[1] );
1451 dst->f[2] = powf( src0->f[2], src1->f[2] );
1452 dst->f[3] = powf( src0->f[3], src1->f[3] );
1453 #endif
1454 }
1455
1456 static void
1457 micro_ldexp(union tgsi_exec_channel *dst,
1458 const union tgsi_exec_channel *src0,
1459 const union tgsi_exec_channel *src1)
1460 {
1461 dst->f[0] = ldexpf(src0->f[0], src1->i[0]);
1462 dst->f[1] = ldexpf(src0->f[1], src1->i[1]);
1463 dst->f[2] = ldexpf(src0->f[2], src1->i[2]);
1464 dst->f[3] = ldexpf(src0->f[3], src1->i[3]);
1465 }
1466
1467 static void
1468 micro_sub(union tgsi_exec_channel *dst,
1469 const union tgsi_exec_channel *src0,
1470 const union tgsi_exec_channel *src1)
1471 {
1472 dst->f[0] = src0->f[0] - src1->f[0];
1473 dst->f[1] = src0->f[1] - src1->f[1];
1474 dst->f[2] = src0->f[2] - src1->f[2];
1475 dst->f[3] = src0->f[3] - src1->f[3];
1476 }
1477
1478 static void
1479 fetch_src_file_channel(const struct tgsi_exec_machine *mach,
1480 const uint file,
1481 const uint swizzle,
1482 const union tgsi_exec_channel *index,
1483 const union tgsi_exec_channel *index2D,
1484 union tgsi_exec_channel *chan)
1485 {
1486 uint i;
1487
1488 assert(swizzle < 4);
1489
1490 switch (file) {
1491 case TGSI_FILE_CONSTANT:
1492 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1493 assert(index2D->i[i] >= 0 && index2D->i[i] < PIPE_MAX_CONSTANT_BUFFERS);
1494 assert(mach->Consts[index2D->i[i]]);
1495
1496 if (index->i[i] < 0) {
1497 chan->u[i] = 0;
1498 } else {
1499 /* NOTE: copying the const value as a uint instead of float */
1500 const uint constbuf = index2D->i[i];
1501 const uint *buf = (const uint *)mach->Consts[constbuf];
1502 const int pos = index->i[i] * 4 + swizzle;
1503 /* const buffer bounds check */
1504 if (pos < 0 || pos >= (int) mach->ConstsSize[constbuf]) {
1505 if (0) {
1506 /* Debug: print warning */
1507 static int count = 0;
1508 if (count++ < 100)
1509 debug_printf("TGSI Exec: const buffer index %d"
1510 " out of bounds\n", pos);
1511 }
1512 chan->u[i] = 0;
1513 }
1514 else
1515 chan->u[i] = buf[pos];
1516 }
1517 }
1518 break;
1519
1520 case TGSI_FILE_INPUT:
1521 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1522 /*
1523 if (PIPE_SHADER_GEOMETRY == mach->ShaderType) {
1524 debug_printf("Fetching Input[%d] (2d=%d, 1d=%d)\n",
1525 index2D->i[i] * TGSI_EXEC_MAX_INPUT_ATTRIBS + index->i[i],
1526 index2D->i[i], index->i[i]);
1527 }*/
1528 int pos = index2D->i[i] * TGSI_EXEC_MAX_INPUT_ATTRIBS + index->i[i];
1529 assert(pos >= 0);
1530 assert(pos < TGSI_MAX_PRIM_VERTICES * PIPE_MAX_ATTRIBS);
1531 chan->u[i] = mach->Inputs[pos].xyzw[swizzle].u[i];
1532 }
1533 break;
1534
1535 case TGSI_FILE_SYSTEM_VALUE:
1536 /* XXX no swizzling at this point. Will be needed if we put
1537 * gl_FragCoord, for example, in a sys value register.
1538 */
1539 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1540 chan->u[i] = mach->SystemValue[index->i[i]].xyzw[swizzle].u[i];
1541 }
1542 break;
1543
1544 case TGSI_FILE_TEMPORARY:
1545 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1546 assert(index->i[i] < TGSI_EXEC_NUM_TEMPS);
1547 assert(index2D->i[i] == 0);
1548
1549 chan->u[i] = mach->Temps[index->i[i]].xyzw[swizzle].u[i];
1550 }
1551 break;
1552
1553 case TGSI_FILE_IMMEDIATE:
1554 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1555 assert(index->i[i] >= 0 && index->i[i] < (int)mach->ImmLimit);
1556 assert(index2D->i[i] == 0);
1557
1558 chan->f[i] = mach->Imms[index->i[i]][swizzle];
1559 }
1560 break;
1561
1562 case TGSI_FILE_ADDRESS:
1563 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1564 assert(index->i[i] >= 0);
1565 assert(index2D->i[i] == 0);
1566
1567 chan->u[i] = mach->Addrs[index->i[i]].xyzw[swizzle].u[i];
1568 }
1569 break;
1570
1571 case TGSI_FILE_OUTPUT:
1572 /* vertex/fragment output vars can be read too */
1573 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1574 assert(index->i[i] >= 0);
1575 assert(index2D->i[i] == 0);
1576
1577 chan->u[i] = mach->Outputs[index->i[i]].xyzw[swizzle].u[i];
1578 }
1579 break;
1580
1581 default:
1582 assert(0);
1583 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1584 chan->u[i] = 0;
1585 }
1586 }
1587 }
1588
1589 static void
1590 fetch_source_d(const struct tgsi_exec_machine *mach,
1591 union tgsi_exec_channel *chan,
1592 const struct tgsi_full_src_register *reg,
1593 const uint chan_index)
1594 {
1595 union tgsi_exec_channel index;
1596 union tgsi_exec_channel index2D;
1597 uint swizzle;
1598
1599 /* We start with a direct index into a register file.
1600 *
1601 * file[1],
1602 * where:
1603 * file = Register.File
1604 * [1] = Register.Index
1605 */
1606 index.i[0] =
1607 index.i[1] =
1608 index.i[2] =
1609 index.i[3] = reg->Register.Index;
1610
1611 /* There is an extra source register that indirectly subscripts
1612 * a register file. The direct index now becomes an offset
1613 * that is being added to the indirect register.
1614 *
1615 * file[ind[2].x+1],
1616 * where:
1617 * ind = Indirect.File
1618 * [2] = Indirect.Index
1619 * .x = Indirect.SwizzleX
1620 */
1621 if (reg->Register.Indirect) {
1622 union tgsi_exec_channel index2;
1623 union tgsi_exec_channel indir_index;
1624 const uint execmask = mach->ExecMask;
1625 uint i;
1626
1627 /* which address register (always zero now) */
1628 index2.i[0] =
1629 index2.i[1] =
1630 index2.i[2] =
1631 index2.i[3] = reg->Indirect.Index;
1632 /* get current value of address register[swizzle] */
1633 swizzle = reg->Indirect.Swizzle;
1634 fetch_src_file_channel(mach,
1635 reg->Indirect.File,
1636 swizzle,
1637 &index2,
1638 &ZeroVec,
1639 &indir_index);
1640
1641 /* add value of address register to the offset */
1642 index.i[0] += indir_index.i[0];
1643 index.i[1] += indir_index.i[1];
1644 index.i[2] += indir_index.i[2];
1645 index.i[3] += indir_index.i[3];
1646
1647 /* for disabled execution channels, zero-out the index to
1648 * avoid using a potential garbage value.
1649 */
1650 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1651 if ((execmask & (1 << i)) == 0)
1652 index.i[i] = 0;
1653 }
1654 }
1655
1656 /* There is an extra source register that is a second
1657 * subscript to a register file. Effectively it means that
1658 * the register file is actually a 2D array of registers.
1659 *
1660 * file[3][1],
1661 * where:
1662 * [3] = Dimension.Index
1663 */
1664 if (reg->Register.Dimension) {
1665 index2D.i[0] =
1666 index2D.i[1] =
1667 index2D.i[2] =
1668 index2D.i[3] = reg->Dimension.Index;
1669
1670 /* Again, the second subscript index can be addressed indirectly
1671 * identically to the first one.
1672 * Nothing stops us from indirectly addressing the indirect register,
1673 * but there is no need for that, so we won't exercise it.
1674 *
1675 * file[ind[4].y+3][1],
1676 * where:
1677 * ind = DimIndirect.File
1678 * [4] = DimIndirect.Index
1679 * .y = DimIndirect.SwizzleX
1680 */
1681 if (reg->Dimension.Indirect) {
1682 union tgsi_exec_channel index2;
1683 union tgsi_exec_channel indir_index;
1684 const uint execmask = mach->ExecMask;
1685 uint i;
1686
1687 index2.i[0] =
1688 index2.i[1] =
1689 index2.i[2] =
1690 index2.i[3] = reg->DimIndirect.Index;
1691
1692 swizzle = reg->DimIndirect.Swizzle;
1693 fetch_src_file_channel(mach,
1694 reg->DimIndirect.File,
1695 swizzle,
1696 &index2,
1697 &ZeroVec,
1698 &indir_index);
1699
1700 index2D.i[0] += indir_index.i[0];
1701 index2D.i[1] += indir_index.i[1];
1702 index2D.i[2] += indir_index.i[2];
1703 index2D.i[3] += indir_index.i[3];
1704
1705 /* for disabled execution channels, zero-out the index to
1706 * avoid using a potential garbage value.
1707 */
1708 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1709 if ((execmask & (1 << i)) == 0) {
1710 index2D.i[i] = 0;
1711 }
1712 }
1713 }
1714
1715 /* If by any chance there was a need for a 3D array of register
1716 * files, we would have to check whether Dimension is followed
1717 * by a dimension register and continue the saga.
1718 */
1719 } else {
1720 index2D.i[0] =
1721 index2D.i[1] =
1722 index2D.i[2] =
1723 index2D.i[3] = 0;
1724 }
1725
1726 swizzle = tgsi_util_get_full_src_register_swizzle( reg, chan_index );
1727 fetch_src_file_channel(mach,
1728 reg->Register.File,
1729 swizzle,
1730 &index,
1731 &index2D,
1732 chan);
1733 }
1734
1735 static void
1736 fetch_source(const struct tgsi_exec_machine *mach,
1737 union tgsi_exec_channel *chan,
1738 const struct tgsi_full_src_register *reg,
1739 const uint chan_index,
1740 enum tgsi_exec_datatype src_datatype)
1741 {
1742 fetch_source_d(mach, chan, reg, chan_index);
1743
1744 if (reg->Register.Absolute) {
1745 if (src_datatype == TGSI_EXEC_DATA_FLOAT) {
1746 micro_abs(chan, chan);
1747 } else {
1748 micro_iabs(chan, chan);
1749 }
1750 }
1751
1752 if (reg->Register.Negate) {
1753 if (src_datatype == TGSI_EXEC_DATA_FLOAT) {
1754 micro_neg(chan, chan);
1755 } else {
1756 micro_ineg(chan, chan);
1757 }
1758 }
1759 }
1760
1761 static union tgsi_exec_channel *
1762 store_dest_dstret(struct tgsi_exec_machine *mach,
1763 const union tgsi_exec_channel *chan,
1764 const struct tgsi_full_dst_register *reg,
1765 uint chan_index,
1766 enum tgsi_exec_datatype dst_datatype)
1767 {
1768 static union tgsi_exec_channel null;
1769 union tgsi_exec_channel *dst;
1770 union tgsi_exec_channel index2D;
1771 int offset = 0; /* indirection offset */
1772 int index;
1773
1774 /* for debugging */
1775 if (0 && dst_datatype == TGSI_EXEC_DATA_FLOAT) {
1776 check_inf_or_nan(chan);
1777 }
1778
1779 /* There is an extra source register that indirectly subscripts
1780 * a register file. The direct index now becomes an offset
1781 * that is being added to the indirect register.
1782 *
1783 * file[ind[2].x+1],
1784 * where:
1785 * ind = Indirect.File
1786 * [2] = Indirect.Index
1787 * .x = Indirect.SwizzleX
1788 */
1789 if (reg->Register.Indirect) {
1790 union tgsi_exec_channel index;
1791 union tgsi_exec_channel indir_index;
1792 uint swizzle;
1793
1794 /* which address register (always zero for now) */
1795 index.i[0] =
1796 index.i[1] =
1797 index.i[2] =
1798 index.i[3] = reg->Indirect.Index;
1799
1800 /* get current value of address register[swizzle] */
1801 swizzle = reg->Indirect.Swizzle;
1802
1803 /* fetch values from the address/indirection register */
1804 fetch_src_file_channel(mach,
1805 reg->Indirect.File,
1806 swizzle,
1807 &index,
1808 &ZeroVec,
1809 &indir_index);
1810
1811 /* save indirection offset */
1812 offset = indir_index.i[0];
1813 }
1814
1815 /* There is an extra source register that is a second
1816 * subscript to a register file. Effectively it means that
1817 * the register file is actually a 2D array of registers.
1818 *
1819 * file[3][1],
1820 * where:
1821 * [3] = Dimension.Index
1822 */
1823 if (reg->Register.Dimension) {
1824 index2D.i[0] =
1825 index2D.i[1] =
1826 index2D.i[2] =
1827 index2D.i[3] = reg->Dimension.Index;
1828
1829 /* Again, the second subscript index can be addressed indirectly
1830 * identically to the first one.
1831 * Nothing stops us from indirectly addressing the indirect register,
1832 * but there is no need for that, so we won't exercise it.
1833 *
1834 * file[ind[4].y+3][1],
1835 * where:
1836 * ind = DimIndirect.File
1837 * [4] = DimIndirect.Index
1838 * .y = DimIndirect.SwizzleX
1839 */
1840 if (reg->Dimension.Indirect) {
1841 union tgsi_exec_channel index2;
1842 union tgsi_exec_channel indir_index;
1843 const uint execmask = mach->ExecMask;
1844 unsigned swizzle;
1845 uint i;
1846
1847 index2.i[0] =
1848 index2.i[1] =
1849 index2.i[2] =
1850 index2.i[3] = reg->DimIndirect.Index;
1851
1852 swizzle = reg->DimIndirect.Swizzle;
1853 fetch_src_file_channel(mach,
1854 reg->DimIndirect.File,
1855 swizzle,
1856 &index2,
1857 &ZeroVec,
1858 &indir_index);
1859
1860 index2D.i[0] += indir_index.i[0];
1861 index2D.i[1] += indir_index.i[1];
1862 index2D.i[2] += indir_index.i[2];
1863 index2D.i[3] += indir_index.i[3];
1864
1865 /* for disabled execution channels, zero-out the index to
1866 * avoid using a potential garbage value.
1867 */
1868 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1869 if ((execmask & (1 << i)) == 0) {
1870 index2D.i[i] = 0;
1871 }
1872 }
1873 }
1874
1875 /* If by any chance there was a need for a 3D array of register
1876 * files, we would have to check whether Dimension is followed
1877 * by a dimension register and continue the saga.
1878 */
1879 } else {
1880 index2D.i[0] =
1881 index2D.i[1] =
1882 index2D.i[2] =
1883 index2D.i[3] = 0;
1884 }
1885
1886 switch (reg->Register.File) {
1887 case TGSI_FILE_NULL:
1888 dst = &null;
1889 break;
1890
1891 case TGSI_FILE_OUTPUT:
1892 index = mach->Temps[TEMP_OUTPUT_I].xyzw[TEMP_OUTPUT_C].u[0]
1893 + reg->Register.Index;
1894 dst = &mach->Outputs[offset + index].xyzw[chan_index];
1895 #if 0
1896 debug_printf("NumOutputs = %d, TEMP_O_C/I = %d, redindex = %d\n",
1897 mach->NumOutputs, mach->Temps[TEMP_OUTPUT_I].xyzw[TEMP_OUTPUT_C].u[0],
1898 reg->Register.Index);
1899 if (PIPE_SHADER_GEOMETRY == mach->ShaderType) {
1900 debug_printf("STORING OUT[%d] mask(%d), = (", offset + index, execmask);
1901 for (i = 0; i < TGSI_QUAD_SIZE; i++)
1902 if (execmask & (1 << i))
1903 debug_printf("%f, ", chan->f[i]);
1904 debug_printf(")\n");
1905 }
1906 #endif
1907 break;
1908
1909 case TGSI_FILE_TEMPORARY:
1910 index = reg->Register.Index;
1911 assert( index < TGSI_EXEC_NUM_TEMPS );
1912 dst = &mach->Temps[offset + index].xyzw[chan_index];
1913 break;
1914
1915 case TGSI_FILE_ADDRESS:
1916 index = reg->Register.Index;
1917 dst = &mach->Addrs[index].xyzw[chan_index];
1918 break;
1919
1920 default:
1921 assert( 0 );
1922 return NULL;
1923 }
1924
1925 return dst;
1926 }
1927
1928 static void
1929 store_dest_double(struct tgsi_exec_machine *mach,
1930 const union tgsi_exec_channel *chan,
1931 const struct tgsi_full_dst_register *reg,
1932 uint chan_index,
1933 enum tgsi_exec_datatype dst_datatype)
1934 {
1935 union tgsi_exec_channel *dst;
1936 const uint execmask = mach->ExecMask;
1937 int i;
1938
1939 dst = store_dest_dstret(mach, chan, reg, chan_index, dst_datatype);
1940 if (!dst)
1941 return;
1942
1943 /* doubles path */
1944 for (i = 0; i < TGSI_QUAD_SIZE; i++)
1945 if (execmask & (1 << i))
1946 dst->i[i] = chan->i[i];
1947 }
1948
1949 static void
1950 store_dest(struct tgsi_exec_machine *mach,
1951 const union tgsi_exec_channel *chan,
1952 const struct tgsi_full_dst_register *reg,
1953 const struct tgsi_full_instruction *inst,
1954 uint chan_index,
1955 enum tgsi_exec_datatype dst_datatype)
1956 {
1957 union tgsi_exec_channel *dst;
1958 const uint execmask = mach->ExecMask;
1959 int i;
1960
1961 dst = store_dest_dstret(mach, chan, reg, chan_index, dst_datatype);
1962 if (!dst)
1963 return;
1964
1965 if (!inst->Instruction.Saturate) {
1966 for (i = 0; i < TGSI_QUAD_SIZE; i++)
1967 if (execmask & (1 << i))
1968 dst->i[i] = chan->i[i];
1969 }
1970 else {
1971 for (i = 0; i < TGSI_QUAD_SIZE; i++)
1972 if (execmask & (1 << i)) {
1973 if (chan->f[i] < 0.0f)
1974 dst->f[i] = 0.0f;
1975 else if (chan->f[i] > 1.0f)
1976 dst->f[i] = 1.0f;
1977 else
1978 dst->i[i] = chan->i[i];
1979 }
1980 }
1981 }
1982
1983 #define FETCH(VAL,INDEX,CHAN)\
1984 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_FLOAT)
1985
1986 #define IFETCH(VAL,INDEX,CHAN)\
1987 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_INT)
1988
1989
1990 /**
1991 * Execute ARB-style KIL which is predicated by a src register.
1992 * Kill fragment if any of the four values is less than zero.
1993 */
1994 static void
1995 exec_kill_if(struct tgsi_exec_machine *mach,
1996 const struct tgsi_full_instruction *inst)
1997 {
1998 uint uniquemask;
1999 uint chan_index;
2000 uint kilmask = 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
2001 union tgsi_exec_channel r[1];
2002
2003 /* This mask stores component bits that were already tested. */
2004 uniquemask = 0;
2005
2006 for (chan_index = 0; chan_index < 4; chan_index++)
2007 {
2008 uint swizzle;
2009 uint i;
2010
2011 /* unswizzle channel */
2012 swizzle = tgsi_util_get_full_src_register_swizzle (
2013 &inst->Src[0],
2014 chan_index);
2015
2016 /* check if the component has not been already tested */
2017 if (uniquemask & (1 << swizzle))
2018 continue;
2019 uniquemask |= 1 << swizzle;
2020
2021 FETCH(&r[0], 0, chan_index);
2022 for (i = 0; i < 4; i++)
2023 if (r[0].f[i] < 0.0f)
2024 kilmask |= 1 << i;
2025 }
2026
2027 /* restrict to fragments currently executing */
2028 kilmask &= mach->ExecMask;
2029
2030 mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0] |= kilmask;
2031 }
2032
2033 /**
2034 * Unconditional fragment kill/discard.
2035 */
2036 static void
2037 exec_kill(struct tgsi_exec_machine *mach)
2038 {
2039 uint kilmask; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
2040
2041 /* kill fragment for all fragments currently executing */
2042 kilmask = mach->ExecMask;
2043 mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0] |= kilmask;
2044 }
2045
2046 static void
2047 emit_vertex(struct tgsi_exec_machine *mach)
2048 {
2049 /* FIXME: check for exec mask correctly
2050 unsigned i;
2051 for (i = 0; i < TGSI_QUAD_SIZE; ++i) {
2052 if ((mach->ExecMask & (1 << i)))
2053 */
2054 if (mach->ExecMask) {
2055 if (mach->Primitives[mach->Temps[TEMP_PRIMITIVE_I].xyzw[TEMP_PRIMITIVE_C].u[0]] >= mach->MaxOutputVertices)
2056 return;
2057
2058 mach->Temps[TEMP_OUTPUT_I].xyzw[TEMP_OUTPUT_C].u[0] += mach->NumOutputs;
2059 mach->Primitives[mach->Temps[TEMP_PRIMITIVE_I].xyzw[TEMP_PRIMITIVE_C].u[0]]++;
2060 }
2061 }
2062
2063 static void
2064 emit_primitive(struct tgsi_exec_machine *mach)
2065 {
2066 unsigned *prim_count = &mach->Temps[TEMP_PRIMITIVE_I].xyzw[TEMP_PRIMITIVE_C].u[0];
2067 /* FIXME: check for exec mask correctly
2068 unsigned i;
2069 for (i = 0; i < TGSI_QUAD_SIZE; ++i) {
2070 if ((mach->ExecMask & (1 << i)))
2071 */
2072 if (mach->ExecMask) {
2073 ++(*prim_count);
2074 debug_assert((*prim_count * mach->NumOutputs) < mach->MaxGeometryShaderOutputs);
2075 mach->Primitives[*prim_count] = 0;
2076 }
2077 }
2078
2079 static void
2080 conditional_emit_primitive(struct tgsi_exec_machine *mach)
2081 {
2082 if (PIPE_SHADER_GEOMETRY == mach->ShaderType) {
2083 int emitted_verts =
2084 mach->Primitives[mach->Temps[TEMP_PRIMITIVE_I].xyzw[TEMP_PRIMITIVE_C].u[0]];
2085 if (emitted_verts) {
2086 emit_primitive(mach);
2087 }
2088 }
2089 }
2090
2091
2092 /*
2093 * Fetch four texture samples using STR texture coordinates.
2094 */
2095 static void
2096 fetch_texel( struct tgsi_sampler *sampler,
2097 const unsigned sview_idx,
2098 const unsigned sampler_idx,
2099 const union tgsi_exec_channel *s,
2100 const union tgsi_exec_channel *t,
2101 const union tgsi_exec_channel *p,
2102 const union tgsi_exec_channel *c0,
2103 const union tgsi_exec_channel *c1,
2104 float derivs[3][2][TGSI_QUAD_SIZE],
2105 const int8_t offset[3],
2106 enum tgsi_sampler_control control,
2107 union tgsi_exec_channel *r,
2108 union tgsi_exec_channel *g,
2109 union tgsi_exec_channel *b,
2110 union tgsi_exec_channel *a )
2111 {
2112 uint j;
2113 float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE];
2114
2115 /* FIXME: handle explicit derivs, offsets */
2116 sampler->get_samples(sampler, sview_idx, sampler_idx,
2117 s->f, t->f, p->f, c0->f, c1->f, derivs, offset, control, rgba);
2118
2119 for (j = 0; j < 4; j++) {
2120 r->f[j] = rgba[0][j];
2121 g->f[j] = rgba[1][j];
2122 b->f[j] = rgba[2][j];
2123 a->f[j] = rgba[3][j];
2124 }
2125 }
2126
2127
2128 #define TEX_MODIFIER_NONE 0
2129 #define TEX_MODIFIER_PROJECTED 1
2130 #define TEX_MODIFIER_LOD_BIAS 2
2131 #define TEX_MODIFIER_EXPLICIT_LOD 3
2132 #define TEX_MODIFIER_LEVEL_ZERO 4
2133 #define TEX_MODIFIER_GATHER 5
2134
2135 /*
2136 * Fetch all 3 (for s,t,r coords) texel offsets, put them into int array.
2137 */
2138 static void
2139 fetch_texel_offsets(struct tgsi_exec_machine *mach,
2140 const struct tgsi_full_instruction *inst,
2141 int8_t offsets[3])
2142 {
2143 if (inst->Texture.NumOffsets == 1) {
2144 union tgsi_exec_channel index;
2145 union tgsi_exec_channel offset[3];
2146 index.i[0] = index.i[1] = index.i[2] = index.i[3] = inst->TexOffsets[0].Index;
2147 fetch_src_file_channel(mach, inst->TexOffsets[0].File,
2148 inst->TexOffsets[0].SwizzleX, &index, &ZeroVec, &offset[0]);
2149 fetch_src_file_channel(mach, inst->TexOffsets[0].File,
2150 inst->TexOffsets[0].SwizzleY, &index, &ZeroVec, &offset[1]);
2151 fetch_src_file_channel(mach, inst->TexOffsets[0].File,
2152 inst->TexOffsets[0].SwizzleZ, &index, &ZeroVec, &offset[2]);
2153 offsets[0] = offset[0].i[0];
2154 offsets[1] = offset[1].i[0];
2155 offsets[2] = offset[2].i[0];
2156 } else {
2157 assert(inst->Texture.NumOffsets == 0);
2158 offsets[0] = offsets[1] = offsets[2] = 0;
2159 }
2160 }
2161
2162
2163 /*
2164 * Fetch dx and dy values for one channel (s, t or r).
2165 * Put dx values into one float array, dy values into another.
2166 */
2167 static void
2168 fetch_assign_deriv_channel(struct tgsi_exec_machine *mach,
2169 const struct tgsi_full_instruction *inst,
2170 unsigned regdsrcx,
2171 unsigned chan,
2172 float derivs[2][TGSI_QUAD_SIZE])
2173 {
2174 union tgsi_exec_channel d;
2175 FETCH(&d, regdsrcx, chan);
2176 derivs[0][0] = d.f[0];
2177 derivs[0][1] = d.f[1];
2178 derivs[0][2] = d.f[2];
2179 derivs[0][3] = d.f[3];
2180 FETCH(&d, regdsrcx + 1, chan);
2181 derivs[1][0] = d.f[0];
2182 derivs[1][1] = d.f[1];
2183 derivs[1][2] = d.f[2];
2184 derivs[1][3] = d.f[3];
2185 }
2186
2187 static uint
2188 fetch_sampler_unit(struct tgsi_exec_machine *mach,
2189 const struct tgsi_full_instruction *inst,
2190 uint sampler)
2191 {
2192 uint unit = 0;
2193 int i;
2194 if (inst->Src[sampler].Register.Indirect) {
2195 const struct tgsi_full_src_register *reg = &inst->Src[sampler];
2196 union tgsi_exec_channel indir_index, index2;
2197 const uint execmask = mach->ExecMask;
2198 index2.i[0] =
2199 index2.i[1] =
2200 index2.i[2] =
2201 index2.i[3] = reg->Indirect.Index;
2202
2203 fetch_src_file_channel(mach,
2204 reg->Indirect.File,
2205 reg->Indirect.Swizzle,
2206 &index2,
2207 &ZeroVec,
2208 &indir_index);
2209 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
2210 if (execmask & (1 << i)) {
2211 unit = inst->Src[sampler].Register.Index + indir_index.i[i];
2212 break;
2213 }
2214 }
2215
2216 } else {
2217 unit = inst->Src[sampler].Register.Index;
2218 }
2219 return unit;
2220 }
2221
2222 /*
2223 * execute a texture instruction.
2224 *
2225 * modifier is used to control the channel routing for the
2226 * instruction variants like proj, lod, and texture with lod bias.
2227 * sampler indicates which src register the sampler is contained in.
2228 */
2229 static void
2230 exec_tex(struct tgsi_exec_machine *mach,
2231 const struct tgsi_full_instruction *inst,
2232 uint modifier, uint sampler)
2233 {
2234 const union tgsi_exec_channel *args[5], *proj = NULL;
2235 union tgsi_exec_channel r[5];
2236 enum tgsi_sampler_control control = TGSI_SAMPLER_LOD_NONE;
2237 uint chan;
2238 uint unit;
2239 int8_t offsets[3];
2240 int dim, shadow_ref, i;
2241
2242 unit = fetch_sampler_unit(mach, inst, sampler);
2243 /* always fetch all 3 offsets, overkill but keeps code simple */
2244 fetch_texel_offsets(mach, inst, offsets);
2245
2246 assert(modifier != TEX_MODIFIER_LEVEL_ZERO);
2247 assert(inst->Texture.Texture != TGSI_TEXTURE_BUFFER);
2248
2249 dim = tgsi_util_get_texture_coord_dim(inst->Texture.Texture);
2250 shadow_ref = tgsi_util_get_shadow_ref_src_index(inst->Texture.Texture);
2251
2252 assert(dim <= 4);
2253 if (shadow_ref >= 0)
2254 assert(shadow_ref >= dim && shadow_ref < ARRAY_SIZE(args));
2255
2256 /* fetch modifier to the last argument */
2257 if (modifier != TEX_MODIFIER_NONE) {
2258 const int last = ARRAY_SIZE(args) - 1;
2259
2260 /* fetch modifier from src0.w or src1.x */
2261 if (sampler == 1) {
2262 assert(dim <= TGSI_CHAN_W && shadow_ref != TGSI_CHAN_W);
2263 FETCH(&r[last], 0, TGSI_CHAN_W);
2264 }
2265 else {
2266 assert(shadow_ref != 4);
2267 FETCH(&r[last], 1, TGSI_CHAN_X);
2268 }
2269
2270 if (modifier != TEX_MODIFIER_PROJECTED) {
2271 args[last] = &r[last];
2272 }
2273 else {
2274 proj = &r[last];
2275 args[last] = &ZeroVec;
2276 }
2277
2278 /* point unused arguments to zero vector */
2279 for (i = dim; i < last; i++)
2280 args[i] = &ZeroVec;
2281
2282 if (modifier == TEX_MODIFIER_EXPLICIT_LOD)
2283 control = TGSI_SAMPLER_LOD_EXPLICIT;
2284 else if (modifier == TEX_MODIFIER_LOD_BIAS)
2285 control = TGSI_SAMPLER_LOD_BIAS;
2286 else if (modifier == TEX_MODIFIER_GATHER)
2287 control = TGSI_SAMPLER_GATHER;
2288 }
2289 else {
2290 for (i = dim; i < ARRAY_SIZE(args); i++)
2291 args[i] = &ZeroVec;
2292 }
2293
2294 /* fetch coordinates */
2295 for (i = 0; i < dim; i++) {
2296 FETCH(&r[i], 0, TGSI_CHAN_X + i);
2297
2298 if (proj)
2299 micro_div(&r[i], &r[i], proj);
2300
2301 args[i] = &r[i];
2302 }
2303
2304 /* fetch reference value */
2305 if (shadow_ref >= 0) {
2306 FETCH(&r[shadow_ref], shadow_ref / 4, TGSI_CHAN_X + (shadow_ref % 4));
2307
2308 if (proj)
2309 micro_div(&r[shadow_ref], &r[shadow_ref], proj);
2310
2311 args[shadow_ref] = &r[shadow_ref];
2312 }
2313
2314 fetch_texel(mach->Sampler, unit, unit,
2315 args[0], args[1], args[2], args[3], args[4],
2316 NULL, offsets, control,
2317 &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */
2318
2319 #if 0
2320 debug_printf("fetch r: %g %g %g %g\n",
2321 r[0].f[0], r[0].f[1], r[0].f[2], r[0].f[3]);
2322 debug_printf("fetch g: %g %g %g %g\n",
2323 r[1].f[0], r[1].f[1], r[1].f[2], r[1].f[3]);
2324 debug_printf("fetch b: %g %g %g %g\n",
2325 r[2].f[0], r[2].f[1], r[2].f[2], r[2].f[3]);
2326 debug_printf("fetch a: %g %g %g %g\n",
2327 r[3].f[0], r[3].f[1], r[3].f[2], r[3].f[3]);
2328 #endif
2329
2330 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2331 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2332 store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
2333 }
2334 }
2335 }
2336
2337 static void
2338 exec_lodq(struct tgsi_exec_machine *mach,
2339 const struct tgsi_full_instruction *inst)
2340 {
2341 uint resource_unit, sampler_unit;
2342 int dim;
2343 int i;
2344 union tgsi_exec_channel coords[4];
2345 const union tgsi_exec_channel *args[ARRAY_SIZE(coords)];
2346 union tgsi_exec_channel r[2];
2347
2348 resource_unit = fetch_sampler_unit(mach, inst, 1);
2349 if (inst->Instruction.Opcode == TGSI_OPCODE_LOD) {
2350 uint target = mach->SamplerViews[resource_unit].Resource;
2351 dim = tgsi_util_get_texture_coord_dim(target);
2352 sampler_unit = fetch_sampler_unit(mach, inst, 2);
2353 } else {
2354 dim = tgsi_util_get_texture_coord_dim(inst->Texture.Texture);
2355 sampler_unit = resource_unit;
2356 }
2357 assert(dim <= ARRAY_SIZE(coords));
2358 /* fetch coordinates */
2359 for (i = 0; i < dim; i++) {
2360 FETCH(&coords[i], 0, TGSI_CHAN_X + i);
2361 args[i] = &coords[i];
2362 }
2363 for (i = dim; i < ARRAY_SIZE(coords); i++) {
2364 args[i] = &ZeroVec;
2365 }
2366 mach->Sampler->query_lod(mach->Sampler, resource_unit, sampler_unit,
2367 args[0]->f,
2368 args[1]->f,
2369 args[2]->f,
2370 args[3]->f,
2371 TGSI_SAMPLER_LOD_NONE,
2372 r[0].f,
2373 r[1].f);
2374
2375 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) {
2376 store_dest(mach, &r[0], &inst->Dst[0], inst, TGSI_CHAN_X,
2377 TGSI_EXEC_DATA_FLOAT);
2378 }
2379 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) {
2380 store_dest(mach, &r[1], &inst->Dst[0], inst, TGSI_CHAN_Y,
2381 TGSI_EXEC_DATA_FLOAT);
2382 }
2383 if (inst->Instruction.Opcode == TGSI_OPCODE_LOD) {
2384 unsigned char swizzles[4];
2385 unsigned chan;
2386 swizzles[0] = inst->Src[1].Register.SwizzleX;
2387 swizzles[1] = inst->Src[1].Register.SwizzleY;
2388 swizzles[2] = inst->Src[1].Register.SwizzleZ;
2389 swizzles[3] = inst->Src[1].Register.SwizzleW;
2390
2391 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2392 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2393 if (swizzles[chan] >= 2) {
2394 store_dest(mach, &ZeroVec,
2395 &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
2396 } else {
2397 store_dest(mach, &r[swizzles[chan]],
2398 &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
2399 }
2400 }
2401 }
2402 } else {
2403 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) {
2404 store_dest(mach, &r[0], &inst->Dst[0], inst, TGSI_CHAN_X,
2405 TGSI_EXEC_DATA_FLOAT);
2406 }
2407 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) {
2408 store_dest(mach, &r[1], &inst->Dst[0], inst, TGSI_CHAN_Y,
2409 TGSI_EXEC_DATA_FLOAT);
2410 }
2411 }
2412 }
2413
2414 static void
2415 exec_txd(struct tgsi_exec_machine *mach,
2416 const struct tgsi_full_instruction *inst)
2417 {
2418 union tgsi_exec_channel r[4];
2419 float derivs[3][2][TGSI_QUAD_SIZE];
2420 uint chan;
2421 uint unit;
2422 int8_t offsets[3];
2423
2424 unit = fetch_sampler_unit(mach, inst, 3);
2425 /* always fetch all 3 offsets, overkill but keeps code simple */
2426 fetch_texel_offsets(mach, inst, offsets);
2427
2428 switch (inst->Texture.Texture) {
2429 case TGSI_TEXTURE_1D:
2430 FETCH(&r[0], 0, TGSI_CHAN_X);
2431
2432 fetch_assign_deriv_channel(mach, inst, 1, TGSI_CHAN_X, derivs[0]);
2433
2434 fetch_texel(mach->Sampler, unit, unit,
2435 &r[0], &ZeroVec, &ZeroVec, &ZeroVec, &ZeroVec, /* S, T, P, C, LOD */
2436 derivs, offsets, TGSI_SAMPLER_DERIVS_EXPLICIT,
2437 &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */
2438 break;
2439
2440 case TGSI_TEXTURE_SHADOW1D:
2441 case TGSI_TEXTURE_1D_ARRAY:
2442 case TGSI_TEXTURE_SHADOW1D_ARRAY:
2443 /* SHADOW1D/1D_ARRAY would not need Y/Z respectively, but don't bother */
2444 FETCH(&r[0], 0, TGSI_CHAN_X);
2445 FETCH(&r[1], 0, TGSI_CHAN_Y);
2446 FETCH(&r[2], 0, TGSI_CHAN_Z);
2447
2448 fetch_assign_deriv_channel(mach, inst, 1, TGSI_CHAN_X, derivs[0]);
2449
2450 fetch_texel(mach->Sampler, unit, unit,
2451 &r[0], &r[1], &r[2], &ZeroVec, &ZeroVec, /* S, T, P, C, LOD */
2452 derivs, offsets, TGSI_SAMPLER_DERIVS_EXPLICIT,
2453 &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */
2454 break;
2455
2456 case TGSI_TEXTURE_2D:
2457 case TGSI_TEXTURE_RECT:
2458 FETCH(&r[0], 0, TGSI_CHAN_X);
2459 FETCH(&r[1], 0, TGSI_CHAN_Y);
2460
2461 fetch_assign_deriv_channel(mach, inst, 1, TGSI_CHAN_X, derivs[0]);
2462 fetch_assign_deriv_channel(mach, inst, 1, TGSI_CHAN_Y, derivs[1]);
2463
2464 fetch_texel(mach->Sampler, unit, unit,
2465 &r[0], &r[1], &ZeroVec, &ZeroVec, &ZeroVec, /* S, T, P, C, LOD */
2466 derivs, offsets, TGSI_SAMPLER_DERIVS_EXPLICIT,
2467 &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */
2468 break;
2469
2470
2471 case TGSI_TEXTURE_SHADOW2D:
2472 case TGSI_TEXTURE_SHADOWRECT:
2473 case TGSI_TEXTURE_2D_ARRAY:
2474 case TGSI_TEXTURE_SHADOW2D_ARRAY:
2475 /* only SHADOW2D_ARRAY actually needs W */
2476 FETCH(&r[0], 0, TGSI_CHAN_X);
2477 FETCH(&r[1], 0, TGSI_CHAN_Y);
2478 FETCH(&r[2], 0, TGSI_CHAN_Z);
2479 FETCH(&r[3], 0, TGSI_CHAN_W);
2480
2481 fetch_assign_deriv_channel(mach, inst, 1, TGSI_CHAN_X, derivs[0]);
2482 fetch_assign_deriv_channel(mach, inst, 1, TGSI_CHAN_Y, derivs[1]);
2483
2484 fetch_texel(mach->Sampler, unit, unit,
2485 &r[0], &r[1], &r[2], &r[3], &ZeroVec, /* inputs */
2486 derivs, offsets, TGSI_SAMPLER_DERIVS_EXPLICIT,
2487 &r[0], &r[1], &r[2], &r[3]); /* outputs */
2488 break;
2489
2490 case TGSI_TEXTURE_3D:
2491 case TGSI_TEXTURE_CUBE:
2492 case TGSI_TEXTURE_CUBE_ARRAY:
2493 case TGSI_TEXTURE_SHADOWCUBE:
2494 /* only TEXTURE_CUBE_ARRAY and TEXTURE_SHADOWCUBE actually need W */
2495 FETCH(&r[0], 0, TGSI_CHAN_X);
2496 FETCH(&r[1], 0, TGSI_CHAN_Y);
2497 FETCH(&r[2], 0, TGSI_CHAN_Z);
2498 FETCH(&r[3], 0, TGSI_CHAN_W);
2499
2500 fetch_assign_deriv_channel(mach, inst, 1, TGSI_CHAN_X, derivs[0]);
2501 fetch_assign_deriv_channel(mach, inst, 1, TGSI_CHAN_Y, derivs[1]);
2502 fetch_assign_deriv_channel(mach, inst, 1, TGSI_CHAN_Z, derivs[2]);
2503
2504 fetch_texel(mach->Sampler, unit, unit,
2505 &r[0], &r[1], &r[2], &r[3], &ZeroVec, /* inputs */
2506 derivs, offsets, TGSI_SAMPLER_DERIVS_EXPLICIT,
2507 &r[0], &r[1], &r[2], &r[3]); /* outputs */
2508 break;
2509
2510 default:
2511 assert(0);
2512 }
2513
2514 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2515 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2516 store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
2517 }
2518 }
2519 }
2520
2521
2522 static void
2523 exec_txf(struct tgsi_exec_machine *mach,
2524 const struct tgsi_full_instruction *inst)
2525 {
2526 union tgsi_exec_channel r[4];
2527 uint chan;
2528 uint unit;
2529 float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE];
2530 int j;
2531 int8_t offsets[3];
2532 unsigned target;
2533
2534 unit = fetch_sampler_unit(mach, inst, 1);
2535 /* always fetch all 3 offsets, overkill but keeps code simple */
2536 fetch_texel_offsets(mach, inst, offsets);
2537
2538 IFETCH(&r[3], 0, TGSI_CHAN_W);
2539
2540 if (inst->Instruction.Opcode == TGSI_OPCODE_SAMPLE_I ||
2541 inst->Instruction.Opcode == TGSI_OPCODE_SAMPLE_I_MS) {
2542 target = mach->SamplerViews[unit].Resource;
2543 }
2544 else {
2545 target = inst->Texture.Texture;
2546 }
2547 switch(target) {
2548 case TGSI_TEXTURE_3D:
2549 case TGSI_TEXTURE_2D_ARRAY:
2550 case TGSI_TEXTURE_SHADOW2D_ARRAY:
2551 case TGSI_TEXTURE_2D_ARRAY_MSAA:
2552 IFETCH(&r[2], 0, TGSI_CHAN_Z);
2553 /* fallthrough */
2554 case TGSI_TEXTURE_2D:
2555 case TGSI_TEXTURE_RECT:
2556 case TGSI_TEXTURE_SHADOW1D_ARRAY:
2557 case TGSI_TEXTURE_SHADOW2D:
2558 case TGSI_TEXTURE_SHADOWRECT:
2559 case TGSI_TEXTURE_1D_ARRAY:
2560 case TGSI_TEXTURE_2D_MSAA:
2561 IFETCH(&r[1], 0, TGSI_CHAN_Y);
2562 /* fallthrough */
2563 case TGSI_TEXTURE_BUFFER:
2564 case TGSI_TEXTURE_1D:
2565 case TGSI_TEXTURE_SHADOW1D:
2566 IFETCH(&r[0], 0, TGSI_CHAN_X);
2567 break;
2568 default:
2569 assert(0);
2570 break;
2571 }
2572
2573 mach->Sampler->get_texel(mach->Sampler, unit, r[0].i, r[1].i, r[2].i, r[3].i,
2574 offsets, rgba);
2575
2576 for (j = 0; j < TGSI_QUAD_SIZE; j++) {
2577 r[0].f[j] = rgba[0][j];
2578 r[1].f[j] = rgba[1][j];
2579 r[2].f[j] = rgba[2][j];
2580 r[3].f[j] = rgba[3][j];
2581 }
2582
2583 if (inst->Instruction.Opcode == TGSI_OPCODE_SAMPLE_I ||
2584 inst->Instruction.Opcode == TGSI_OPCODE_SAMPLE_I_MS) {
2585 unsigned char swizzles[4];
2586 swizzles[0] = inst->Src[1].Register.SwizzleX;
2587 swizzles[1] = inst->Src[1].Register.SwizzleY;
2588 swizzles[2] = inst->Src[1].Register.SwizzleZ;
2589 swizzles[3] = inst->Src[1].Register.SwizzleW;
2590
2591 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2592 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2593 store_dest(mach, &r[swizzles[chan]],
2594 &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
2595 }
2596 }
2597 }
2598 else {
2599 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2600 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2601 store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
2602 }
2603 }
2604 }
2605 }
2606
2607 static void
2608 exec_txq(struct tgsi_exec_machine *mach,
2609 const struct tgsi_full_instruction *inst)
2610 {
2611 int result[4];
2612 union tgsi_exec_channel r[4], src;
2613 uint chan;
2614 uint unit;
2615 int i,j;
2616
2617 unit = fetch_sampler_unit(mach, inst, 1);
2618
2619 fetch_source(mach, &src, &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_INT);
2620
2621 /* XXX: This interface can't return per-pixel values */
2622 mach->Sampler->get_dims(mach->Sampler, unit, src.i[0], result);
2623
2624 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
2625 for (j = 0; j < 4; j++) {
2626 r[j].i[i] = result[j];
2627 }
2628 }
2629
2630 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2631 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2632 store_dest(mach, &r[chan], &inst->Dst[0], inst, chan,
2633 TGSI_EXEC_DATA_INT);
2634 }
2635 }
2636 }
2637
2638 static void
2639 exec_sample(struct tgsi_exec_machine *mach,
2640 const struct tgsi_full_instruction *inst,
2641 uint modifier, boolean compare)
2642 {
2643 const uint resource_unit = inst->Src[1].Register.Index;
2644 const uint sampler_unit = inst->Src[2].Register.Index;
2645 union tgsi_exec_channel r[5], c1;
2646 const union tgsi_exec_channel *lod = &ZeroVec;
2647 enum tgsi_sampler_control control = TGSI_SAMPLER_LOD_NONE;
2648 uint chan;
2649 unsigned char swizzles[4];
2650 int8_t offsets[3];
2651
2652 /* always fetch all 3 offsets, overkill but keeps code simple */
2653 fetch_texel_offsets(mach, inst, offsets);
2654
2655 assert(modifier != TEX_MODIFIER_PROJECTED);
2656
2657 if (modifier != TEX_MODIFIER_NONE) {
2658 if (modifier == TEX_MODIFIER_LOD_BIAS) {
2659 FETCH(&c1, 3, TGSI_CHAN_X);
2660 lod = &c1;
2661 control = TGSI_SAMPLER_LOD_BIAS;
2662 }
2663 else if (modifier == TEX_MODIFIER_EXPLICIT_LOD) {
2664 FETCH(&c1, 3, TGSI_CHAN_X);
2665 lod = &c1;
2666 control = TGSI_SAMPLER_LOD_EXPLICIT;
2667 }
2668 else if (modifier == TEX_MODIFIER_GATHER) {
2669 control = TGSI_SAMPLER_GATHER;
2670 }
2671 else {
2672 assert(modifier == TEX_MODIFIER_LEVEL_ZERO);
2673 control = TGSI_SAMPLER_LOD_ZERO;
2674 }
2675 }
2676
2677 FETCH(&r[0], 0, TGSI_CHAN_X);
2678
2679 switch (mach->SamplerViews[resource_unit].Resource) {
2680 case TGSI_TEXTURE_1D:
2681 if (compare) {
2682 FETCH(&r[2], 3, TGSI_CHAN_X);
2683 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2684 &r[0], &ZeroVec, &r[2], &ZeroVec, lod, /* S, T, P, C, LOD */
2685 NULL, offsets, control,
2686 &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */
2687 }
2688 else {
2689 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2690 &r[0], &ZeroVec, &ZeroVec, &ZeroVec, lod, /* S, T, P, C, LOD */
2691 NULL, offsets, control,
2692 &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */
2693 }
2694 break;
2695
2696 case TGSI_TEXTURE_1D_ARRAY:
2697 case TGSI_TEXTURE_2D:
2698 case TGSI_TEXTURE_RECT:
2699 FETCH(&r[1], 0, TGSI_CHAN_Y);
2700 if (compare) {
2701 FETCH(&r[2], 3, TGSI_CHAN_X);
2702 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2703 &r[0], &r[1], &r[2], &ZeroVec, lod, /* S, T, P, C, LOD */
2704 NULL, offsets, control,
2705 &r[0], &r[1], &r[2], &r[3]); /* outputs */
2706 }
2707 else {
2708 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2709 &r[0], &r[1], &ZeroVec, &ZeroVec, lod, /* S, T, P, C, LOD */
2710 NULL, offsets, control,
2711 &r[0], &r[1], &r[2], &r[3]); /* outputs */
2712 }
2713 break;
2714
2715 case TGSI_TEXTURE_2D_ARRAY:
2716 case TGSI_TEXTURE_3D:
2717 case TGSI_TEXTURE_CUBE:
2718 FETCH(&r[1], 0, TGSI_CHAN_Y);
2719 FETCH(&r[2], 0, TGSI_CHAN_Z);
2720 if(compare) {
2721 FETCH(&r[3], 3, TGSI_CHAN_X);
2722 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2723 &r[0], &r[1], &r[2], &r[3], lod,
2724 NULL, offsets, control,
2725 &r[0], &r[1], &r[2], &r[3]);
2726 }
2727 else {
2728 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2729 &r[0], &r[1], &r[2], &ZeroVec, lod,
2730 NULL, offsets, control,
2731 &r[0], &r[1], &r[2], &r[3]);
2732 }
2733 break;
2734
2735 case TGSI_TEXTURE_CUBE_ARRAY:
2736 FETCH(&r[1], 0, TGSI_CHAN_Y);
2737 FETCH(&r[2], 0, TGSI_CHAN_Z);
2738 FETCH(&r[3], 0, TGSI_CHAN_W);
2739 if(compare) {
2740 FETCH(&r[4], 3, TGSI_CHAN_X);
2741 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2742 &r[0], &r[1], &r[2], &r[3], &r[4],
2743 NULL, offsets, control,
2744 &r[0], &r[1], &r[2], &r[3]);
2745 }
2746 else {
2747 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2748 &r[0], &r[1], &r[2], &r[3], lod,
2749 NULL, offsets, control,
2750 &r[0], &r[1], &r[2], &r[3]);
2751 }
2752 break;
2753
2754
2755 default:
2756 assert(0);
2757 }
2758
2759 swizzles[0] = inst->Src[1].Register.SwizzleX;
2760 swizzles[1] = inst->Src[1].Register.SwizzleY;
2761 swizzles[2] = inst->Src[1].Register.SwizzleZ;
2762 swizzles[3] = inst->Src[1].Register.SwizzleW;
2763
2764 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2765 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2766 store_dest(mach, &r[swizzles[chan]],
2767 &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
2768 }
2769 }
2770 }
2771
2772 static void
2773 exec_sample_d(struct tgsi_exec_machine *mach,
2774 const struct tgsi_full_instruction *inst)
2775 {
2776 const uint resource_unit = inst->Src[1].Register.Index;
2777 const uint sampler_unit = inst->Src[2].Register.Index;
2778 union tgsi_exec_channel r[4];
2779 float derivs[3][2][TGSI_QUAD_SIZE];
2780 uint chan;
2781 unsigned char swizzles[4];
2782 int8_t offsets[3];
2783
2784 /* always fetch all 3 offsets, overkill but keeps code simple */
2785 fetch_texel_offsets(mach, inst, offsets);
2786
2787 FETCH(&r[0], 0, TGSI_CHAN_X);
2788
2789 switch (mach->SamplerViews[resource_unit].Resource) {
2790 case TGSI_TEXTURE_1D:
2791 case TGSI_TEXTURE_1D_ARRAY:
2792 /* only 1D array actually needs Y */
2793 FETCH(&r[1], 0, TGSI_CHAN_Y);
2794
2795 fetch_assign_deriv_channel(mach, inst, 3, TGSI_CHAN_X, derivs[0]);
2796
2797 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2798 &r[0], &r[1], &ZeroVec, &ZeroVec, &ZeroVec, /* S, T, P, C, LOD */
2799 derivs, offsets, TGSI_SAMPLER_DERIVS_EXPLICIT,
2800 &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */
2801 break;
2802
2803 case TGSI_TEXTURE_2D:
2804 case TGSI_TEXTURE_RECT:
2805 case TGSI_TEXTURE_2D_ARRAY:
2806 /* only 2D array actually needs Z */
2807 FETCH(&r[1], 0, TGSI_CHAN_Y);
2808 FETCH(&r[2], 0, TGSI_CHAN_Z);
2809
2810 fetch_assign_deriv_channel(mach, inst, 3, TGSI_CHAN_X, derivs[0]);
2811 fetch_assign_deriv_channel(mach, inst, 3, TGSI_CHAN_Y, derivs[1]);
2812
2813 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2814 &r[0], &r[1], &r[2], &ZeroVec, &ZeroVec, /* inputs */
2815 derivs, offsets, TGSI_SAMPLER_DERIVS_EXPLICIT,
2816 &r[0], &r[1], &r[2], &r[3]); /* outputs */
2817 break;
2818
2819 case TGSI_TEXTURE_3D:
2820 case TGSI_TEXTURE_CUBE:
2821 case TGSI_TEXTURE_CUBE_ARRAY:
2822 /* only cube array actually needs W */
2823 FETCH(&r[1], 0, TGSI_CHAN_Y);
2824 FETCH(&r[2], 0, TGSI_CHAN_Z);
2825 FETCH(&r[3], 0, TGSI_CHAN_W);
2826
2827 fetch_assign_deriv_channel(mach, inst, 3, TGSI_CHAN_X, derivs[0]);
2828 fetch_assign_deriv_channel(mach, inst, 3, TGSI_CHAN_Y, derivs[1]);
2829 fetch_assign_deriv_channel(mach, inst, 3, TGSI_CHAN_Z, derivs[2]);
2830
2831 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2832 &r[0], &r[1], &r[2], &r[3], &ZeroVec,
2833 derivs, offsets, TGSI_SAMPLER_DERIVS_EXPLICIT,
2834 &r[0], &r[1], &r[2], &r[3]);
2835 break;
2836
2837 default:
2838 assert(0);
2839 }
2840
2841 swizzles[0] = inst->Src[1].Register.SwizzleX;
2842 swizzles[1] = inst->Src[1].Register.SwizzleY;
2843 swizzles[2] = inst->Src[1].Register.SwizzleZ;
2844 swizzles[3] = inst->Src[1].Register.SwizzleW;
2845
2846 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2847 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2848 store_dest(mach, &r[swizzles[chan]],
2849 &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
2850 }
2851 }
2852 }
2853
2854
2855 /**
2856 * Evaluate a constant-valued coefficient at the position of the
2857 * current quad.
2858 */
2859 static void
2860 eval_constant_coef(
2861 struct tgsi_exec_machine *mach,
2862 unsigned attrib,
2863 unsigned chan )
2864 {
2865 unsigned i;
2866
2867 for( i = 0; i < TGSI_QUAD_SIZE; i++ ) {
2868 mach->Inputs[attrib].xyzw[chan].f[i] = mach->InterpCoefs[attrib].a0[chan];
2869 }
2870 }
2871
2872 /**
2873 * Evaluate a linear-valued coefficient at the position of the
2874 * current quad.
2875 */
2876 static void
2877 eval_linear_coef(
2878 struct tgsi_exec_machine *mach,
2879 unsigned attrib,
2880 unsigned chan )
2881 {
2882 const float x = mach->QuadPos.xyzw[0].f[0];
2883 const float y = mach->QuadPos.xyzw[1].f[0];
2884 const float dadx = mach->InterpCoefs[attrib].dadx[chan];
2885 const float dady = mach->InterpCoefs[attrib].dady[chan];
2886 const float a0 = mach->InterpCoefs[attrib].a0[chan] + dadx * x + dady * y;
2887 mach->Inputs[attrib].xyzw[chan].f[0] = a0;
2888 mach->Inputs[attrib].xyzw[chan].f[1] = a0 + dadx;
2889 mach->Inputs[attrib].xyzw[chan].f[2] = a0 + dady;
2890 mach->Inputs[attrib].xyzw[chan].f[3] = a0 + dadx + dady;
2891 }
2892
2893 /**
2894 * Evaluate a perspective-valued coefficient at the position of the
2895 * current quad.
2896 */
2897 static void
2898 eval_perspective_coef(
2899 struct tgsi_exec_machine *mach,
2900 unsigned attrib,
2901 unsigned chan )
2902 {
2903 const float x = mach->QuadPos.xyzw[0].f[0];
2904 const float y = mach->QuadPos.xyzw[1].f[0];
2905 const float dadx = mach->InterpCoefs[attrib].dadx[chan];
2906 const float dady = mach->InterpCoefs[attrib].dady[chan];
2907 const float a0 = mach->InterpCoefs[attrib].a0[chan] + dadx * x + dady * y;
2908 const float *w = mach->QuadPos.xyzw[3].f;
2909 /* divide by W here */
2910 mach->Inputs[attrib].xyzw[chan].f[0] = a0 / w[0];
2911 mach->Inputs[attrib].xyzw[chan].f[1] = (a0 + dadx) / w[1];
2912 mach->Inputs[attrib].xyzw[chan].f[2] = (a0 + dady) / w[2];
2913 mach->Inputs[attrib].xyzw[chan].f[3] = (a0 + dadx + dady) / w[3];
2914 }
2915
2916
2917 typedef void (* eval_coef_func)(
2918 struct tgsi_exec_machine *mach,
2919 unsigned attrib,
2920 unsigned chan );
2921
2922 static void
2923 exec_declaration(struct tgsi_exec_machine *mach,
2924 const struct tgsi_full_declaration *decl)
2925 {
2926 if (decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) {
2927 mach->SamplerViews[decl->Range.First] = decl->SamplerView;
2928 return;
2929 }
2930
2931 if (mach->ShaderType == PIPE_SHADER_FRAGMENT) {
2932 if (decl->Declaration.File == TGSI_FILE_INPUT) {
2933 uint first, last, mask;
2934
2935 first = decl->Range.First;
2936 last = decl->Range.Last;
2937 mask = decl->Declaration.UsageMask;
2938
2939 /* XXX we could remove this special-case code since
2940 * mach->InterpCoefs[first].a0 should already have the
2941 * front/back-face value. But we should first update the
2942 * ureg code to emit the right UsageMask value (WRITEMASK_X).
2943 * Then, we could remove the tgsi_exec_machine::Face field.
2944 */
2945 /* XXX make FACE a system value */
2946 if (decl->Semantic.Name == TGSI_SEMANTIC_FACE) {
2947 uint i;
2948
2949 assert(decl->Semantic.Index == 0);
2950 assert(first == last);
2951
2952 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
2953 mach->Inputs[first].xyzw[0].f[i] = mach->Face;
2954 }
2955 } else {
2956 eval_coef_func eval;
2957 uint i, j;
2958
2959 switch (decl->Interp.Interpolate) {
2960 case TGSI_INTERPOLATE_CONSTANT:
2961 eval = eval_constant_coef;
2962 break;
2963
2964 case TGSI_INTERPOLATE_LINEAR:
2965 eval = eval_linear_coef;
2966 break;
2967
2968 case TGSI_INTERPOLATE_PERSPECTIVE:
2969 eval = eval_perspective_coef;
2970 break;
2971
2972 case TGSI_INTERPOLATE_COLOR:
2973 eval = mach->flatshade_color ? eval_constant_coef : eval_perspective_coef;
2974 break;
2975
2976 default:
2977 assert(0);
2978 return;
2979 }
2980
2981 for (j = 0; j < TGSI_NUM_CHANNELS; j++) {
2982 if (mask & (1 << j)) {
2983 for (i = first; i <= last; i++) {
2984 eval(mach, i, j);
2985 }
2986 }
2987 }
2988 }
2989
2990 if (DEBUG_EXECUTION) {
2991 uint i, j;
2992 for (i = first; i <= last; ++i) {
2993 debug_printf("IN[%2u] = ", i);
2994 for (j = 0; j < TGSI_NUM_CHANNELS; j++) {
2995 if (j > 0) {
2996 debug_printf(" ");
2997 }
2998 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
2999 mach->Inputs[i].xyzw[0].f[j], mach->Inputs[i].xyzw[0].u[j],
3000 mach->Inputs[i].xyzw[1].f[j], mach->Inputs[i].xyzw[1].u[j],
3001 mach->Inputs[i].xyzw[2].f[j], mach->Inputs[i].xyzw[2].u[j],
3002 mach->Inputs[i].xyzw[3].f[j], mach->Inputs[i].xyzw[3].u[j]);
3003 }
3004 }
3005 }
3006 }
3007 }
3008
3009 }
3010
3011 typedef void (* micro_unary_op)(union tgsi_exec_channel *dst,
3012 const union tgsi_exec_channel *src);
3013
3014 static void
3015 exec_scalar_unary(struct tgsi_exec_machine *mach,
3016 const struct tgsi_full_instruction *inst,
3017 micro_unary_op op,
3018 enum tgsi_exec_datatype dst_datatype,
3019 enum tgsi_exec_datatype src_datatype)
3020 {
3021 unsigned int chan;
3022 union tgsi_exec_channel src;
3023 union tgsi_exec_channel dst;
3024
3025 fetch_source(mach, &src, &inst->Src[0], TGSI_CHAN_X, src_datatype);
3026 op(&dst, &src);
3027 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3028 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3029 store_dest(mach, &dst, &inst->Dst[0], inst, chan, dst_datatype);
3030 }
3031 }
3032 }
3033
3034 static void
3035 exec_vector_unary(struct tgsi_exec_machine *mach,
3036 const struct tgsi_full_instruction *inst,
3037 micro_unary_op op,
3038 enum tgsi_exec_datatype dst_datatype,
3039 enum tgsi_exec_datatype src_datatype)
3040 {
3041 unsigned int chan;
3042 struct tgsi_exec_vector dst;
3043
3044 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3045 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3046 union tgsi_exec_channel src;
3047
3048 fetch_source(mach, &src, &inst->Src[0], chan, src_datatype);
3049 op(&dst.xyzw[chan], &src);
3050 }
3051 }
3052 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3053 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3054 store_dest(mach, &dst.xyzw[chan], &inst->Dst[0], inst, chan, dst_datatype);
3055 }
3056 }
3057 }
3058
3059 typedef void (* micro_binary_op)(union tgsi_exec_channel *dst,
3060 const union tgsi_exec_channel *src0,
3061 const union tgsi_exec_channel *src1);
3062
3063 static void
3064 exec_scalar_binary(struct tgsi_exec_machine *mach,
3065 const struct tgsi_full_instruction *inst,
3066 micro_binary_op op,
3067 enum tgsi_exec_datatype dst_datatype,
3068 enum tgsi_exec_datatype src_datatype)
3069 {
3070 unsigned int chan;
3071 union tgsi_exec_channel src[2];
3072 union tgsi_exec_channel dst;
3073
3074 fetch_source(mach, &src[0], &inst->Src[0], TGSI_CHAN_X, src_datatype);
3075 fetch_source(mach, &src[1], &inst->Src[1], TGSI_CHAN_X, src_datatype);
3076 op(&dst, &src[0], &src[1]);
3077 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3078 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3079 store_dest(mach, &dst, &inst->Dst[0], inst, chan, dst_datatype);
3080 }
3081 }
3082 }
3083
3084 static void
3085 exec_vector_binary(struct tgsi_exec_machine *mach,
3086 const struct tgsi_full_instruction *inst,
3087 micro_binary_op op,
3088 enum tgsi_exec_datatype dst_datatype,
3089 enum tgsi_exec_datatype src_datatype)
3090 {
3091 unsigned int chan;
3092 struct tgsi_exec_vector dst;
3093
3094 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3095 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3096 union tgsi_exec_channel src[2];
3097
3098 fetch_source(mach, &src[0], &inst->Src[0], chan, src_datatype);
3099 fetch_source(mach, &src[1], &inst->Src[1], chan, src_datatype);
3100 op(&dst.xyzw[chan], &src[0], &src[1]);
3101 }
3102 }
3103 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3104 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3105 store_dest(mach, &dst.xyzw[chan], &inst->Dst[0], inst, chan, dst_datatype);
3106 }
3107 }
3108 }
3109
3110 typedef void (* micro_trinary_op)(union tgsi_exec_channel *dst,
3111 const union tgsi_exec_channel *src0,
3112 const union tgsi_exec_channel *src1,
3113 const union tgsi_exec_channel *src2);
3114
3115 static void
3116 exec_vector_trinary(struct tgsi_exec_machine *mach,
3117 const struct tgsi_full_instruction *inst,
3118 micro_trinary_op op,
3119 enum tgsi_exec_datatype dst_datatype,
3120 enum tgsi_exec_datatype src_datatype)
3121 {
3122 unsigned int chan;
3123 struct tgsi_exec_vector dst;
3124
3125 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3126 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3127 union tgsi_exec_channel src[3];
3128
3129 fetch_source(mach, &src[0], &inst->Src[0], chan, src_datatype);
3130 fetch_source(mach, &src[1], &inst->Src[1], chan, src_datatype);
3131 fetch_source(mach, &src[2], &inst->Src[2], chan, src_datatype);
3132 op(&dst.xyzw[chan], &src[0], &src[1], &src[2]);
3133 }
3134 }
3135 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3136 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3137 store_dest(mach, &dst.xyzw[chan], &inst->Dst[0], inst, chan, dst_datatype);
3138 }
3139 }
3140 }
3141
3142 typedef void (* micro_quaternary_op)(union tgsi_exec_channel *dst,
3143 const union tgsi_exec_channel *src0,
3144 const union tgsi_exec_channel *src1,
3145 const union tgsi_exec_channel *src2,
3146 const union tgsi_exec_channel *src3);
3147
3148 static void
3149 exec_vector_quaternary(struct tgsi_exec_machine *mach,
3150 const struct tgsi_full_instruction *inst,
3151 micro_quaternary_op op,
3152 enum tgsi_exec_datatype dst_datatype,
3153 enum tgsi_exec_datatype src_datatype)
3154 {
3155 unsigned int chan;
3156 struct tgsi_exec_vector dst;
3157
3158 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3159 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3160 union tgsi_exec_channel src[4];
3161
3162 fetch_source(mach, &src[0], &inst->Src[0], chan, src_datatype);
3163 fetch_source(mach, &src[1], &inst->Src[1], chan, src_datatype);
3164 fetch_source(mach, &src[2], &inst->Src[2], chan, src_datatype);
3165 fetch_source(mach, &src[3], &inst->Src[3], chan, src_datatype);
3166 op(&dst.xyzw[chan], &src[0], &src[1], &src[2], &src[3]);
3167 }
3168 }
3169 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3170 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3171 store_dest(mach, &dst.xyzw[chan], &inst->Dst[0], inst, chan, dst_datatype);
3172 }
3173 }
3174 }
3175
3176 static void
3177 exec_dp3(struct tgsi_exec_machine *mach,
3178 const struct tgsi_full_instruction *inst)
3179 {
3180 unsigned int chan;
3181 union tgsi_exec_channel arg[3];
3182
3183 fetch_source(mach, &arg[0], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3184 fetch_source(mach, &arg[1], &inst->Src[1], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3185 micro_mul(&arg[2], &arg[0], &arg[1]);
3186
3187 for (chan = TGSI_CHAN_Y; chan <= TGSI_CHAN_Z; chan++) {
3188 fetch_source(mach, &arg[0], &inst->Src[0], chan, TGSI_EXEC_DATA_FLOAT);
3189 fetch_source(mach, &arg[1], &inst->Src[1], chan, TGSI_EXEC_DATA_FLOAT);
3190 micro_mad(&arg[2], &arg[0], &arg[1], &arg[2]);
3191 }
3192
3193 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3194 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3195 store_dest(mach, &arg[2], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
3196 }
3197 }
3198 }
3199
3200 static void
3201 exec_dp4(struct tgsi_exec_machine *mach,
3202 const struct tgsi_full_instruction *inst)
3203 {
3204 unsigned int chan;
3205 union tgsi_exec_channel arg[3];
3206
3207 fetch_source(mach, &arg[0], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3208 fetch_source(mach, &arg[1], &inst->Src[1], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3209 micro_mul(&arg[2], &arg[0], &arg[1]);
3210
3211 for (chan = TGSI_CHAN_Y; chan <= TGSI_CHAN_W; chan++) {
3212 fetch_source(mach, &arg[0], &inst->Src[0], chan, TGSI_EXEC_DATA_FLOAT);
3213 fetch_source(mach, &arg[1], &inst->Src[1], chan, TGSI_EXEC_DATA_FLOAT);
3214 micro_mad(&arg[2], &arg[0], &arg[1], &arg[2]);
3215 }
3216
3217 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3218 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3219 store_dest(mach, &arg[2], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
3220 }
3221 }
3222 }
3223
3224 static void
3225 exec_dp2(struct tgsi_exec_machine *mach,
3226 const struct tgsi_full_instruction *inst)
3227 {
3228 unsigned int chan;
3229 union tgsi_exec_channel arg[3];
3230
3231 fetch_source(mach, &arg[0], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3232 fetch_source(mach, &arg[1], &inst->Src[1], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3233 micro_mul(&arg[2], &arg[0], &arg[1]);
3234
3235 fetch_source(mach, &arg[0], &inst->Src[0], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3236 fetch_source(mach, &arg[1], &inst->Src[1], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3237 micro_mad(&arg[2], &arg[0], &arg[1], &arg[2]);
3238
3239 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3240 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3241 store_dest(mach, &arg[2], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
3242 }
3243 }
3244 }
3245
3246 static void
3247 exec_pk2h(struct tgsi_exec_machine *mach,
3248 const struct tgsi_full_instruction *inst)
3249 {
3250 unsigned chan;
3251 union tgsi_exec_channel arg[2], dst;
3252
3253 fetch_source(mach, &arg[0], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3254 fetch_source(mach, &arg[1], &inst->Src[0], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3255 for (chan = 0; chan < TGSI_QUAD_SIZE; chan++) {
3256 dst.u[chan] = util_float_to_half(arg[0].f[chan]) |
3257 (util_float_to_half(arg[1].f[chan]) << 16);
3258 }
3259 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3260 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3261 store_dest(mach, &dst, &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_UINT);
3262 }
3263 }
3264 }
3265
3266 static void
3267 exec_up2h(struct tgsi_exec_machine *mach,
3268 const struct tgsi_full_instruction *inst)
3269 {
3270 unsigned chan;
3271 union tgsi_exec_channel arg, dst[2];
3272
3273 fetch_source(mach, &arg, &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_UINT);
3274 for (chan = 0; chan < TGSI_QUAD_SIZE; chan++) {
3275 dst[0].f[chan] = util_half_to_float(arg.u[chan] & 0xffff);
3276 dst[1].f[chan] = util_half_to_float(arg.u[chan] >> 16);
3277 }
3278 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3279 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3280 store_dest(mach, &dst[chan & 1], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
3281 }
3282 }
3283 }
3284
3285 static void
3286 micro_ucmp(union tgsi_exec_channel *dst,
3287 const union tgsi_exec_channel *src0,
3288 const union tgsi_exec_channel *src1,
3289 const union tgsi_exec_channel *src2)
3290 {
3291 dst->f[0] = src0->u[0] ? src1->f[0] : src2->f[0];
3292 dst->f[1] = src0->u[1] ? src1->f[1] : src2->f[1];
3293 dst->f[2] = src0->u[2] ? src1->f[2] : src2->f[2];
3294 dst->f[3] = src0->u[3] ? src1->f[3] : src2->f[3];
3295 }
3296
3297 static void
3298 exec_ucmp(struct tgsi_exec_machine *mach,
3299 const struct tgsi_full_instruction *inst)
3300 {
3301 unsigned int chan;
3302 struct tgsi_exec_vector dst;
3303
3304 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3305 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3306 union tgsi_exec_channel src[3];
3307
3308 fetch_source(mach, &src[0], &inst->Src[0], chan,
3309 TGSI_EXEC_DATA_UINT);
3310 fetch_source(mach, &src[1], &inst->Src[1], chan,
3311 TGSI_EXEC_DATA_FLOAT);
3312 fetch_source(mach, &src[2], &inst->Src[2], chan,
3313 TGSI_EXEC_DATA_FLOAT);
3314 micro_ucmp(&dst.xyzw[chan], &src[0], &src[1], &src[2]);
3315 }
3316 }
3317 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3318 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3319 store_dest(mach, &dst.xyzw[chan], &inst->Dst[0], inst, chan,
3320 TGSI_EXEC_DATA_FLOAT);
3321 }
3322 }
3323 }
3324
3325 static void
3326 exec_dst(struct tgsi_exec_machine *mach,
3327 const struct tgsi_full_instruction *inst)
3328 {
3329 union tgsi_exec_channel r[2];
3330 union tgsi_exec_channel d[4];
3331
3332 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) {
3333 fetch_source(mach, &r[0], &inst->Src[0], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3334 fetch_source(mach, &r[1], &inst->Src[1], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3335 micro_mul(&d[TGSI_CHAN_Y], &r[0], &r[1]);
3336 }
3337 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) {
3338 fetch_source(mach, &d[TGSI_CHAN_Z], &inst->Src[0], TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
3339 }
3340 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) {
3341 fetch_source(mach, &d[TGSI_CHAN_W], &inst->Src[1], TGSI_CHAN_W, TGSI_EXEC_DATA_FLOAT);
3342 }
3343
3344 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) {
3345 store_dest(mach, &OneVec, &inst->Dst[0], inst, TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3346 }
3347 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) {
3348 store_dest(mach, &d[TGSI_CHAN_Y], &inst->Dst[0], inst, TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3349 }
3350 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) {
3351 store_dest(mach, &d[TGSI_CHAN_Z], &inst->Dst[0], inst, TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
3352 }
3353 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) {
3354 store_dest(mach, &d[TGSI_CHAN_W], &inst->Dst[0], inst, TGSI_CHAN_W, TGSI_EXEC_DATA_FLOAT);
3355 }
3356 }
3357
3358 static void
3359 exec_log(struct tgsi_exec_machine *mach,
3360 const struct tgsi_full_instruction *inst)
3361 {
3362 union tgsi_exec_channel r[3];
3363
3364 fetch_source(mach, &r[0], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3365 micro_abs(&r[2], &r[0]); /* r2 = abs(r0) */
3366 micro_lg2(&r[1], &r[2]); /* r1 = lg2(r2) */
3367 micro_flr(&r[0], &r[1]); /* r0 = floor(r1) */
3368 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) {
3369 store_dest(mach, &r[0], &inst->Dst[0], inst, TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3370 }
3371 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) {
3372 micro_exp2(&r[0], &r[0]); /* r0 = 2 ^ r0 */
3373 micro_div(&r[0], &r[2], &r[0]); /* r0 = r2 / r0 */
3374 store_dest(mach, &r[0], &inst->Dst[0], inst, TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3375 }
3376 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) {
3377 store_dest(mach, &r[1], &inst->Dst[0], inst, TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
3378 }
3379 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) {
3380 store_dest(mach, &OneVec, &inst->Dst[0], inst, TGSI_CHAN_W, TGSI_EXEC_DATA_FLOAT);
3381 }
3382 }
3383
3384 static void
3385 exec_exp(struct tgsi_exec_machine *mach,
3386 const struct tgsi_full_instruction *inst)
3387 {
3388 union tgsi_exec_channel r[3];
3389
3390 fetch_source(mach, &r[0], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3391 micro_flr(&r[1], &r[0]); /* r1 = floor(r0) */
3392 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) {
3393 micro_exp2(&r[2], &r[1]); /* r2 = 2 ^ r1 */
3394 store_dest(mach, &r[2], &inst->Dst[0], inst, TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3395 }
3396 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) {
3397 micro_sub(&r[2], &r[0], &r[1]); /* r2 = r0 - r1 */
3398 store_dest(mach, &r[2], &inst->Dst[0], inst, TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3399 }
3400 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) {
3401 micro_exp2(&r[2], &r[0]); /* r2 = 2 ^ r0 */
3402 store_dest(mach, &r[2], &inst->Dst[0], inst, TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
3403 }
3404 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) {
3405 store_dest(mach, &OneVec, &inst->Dst[0], inst, TGSI_CHAN_W, TGSI_EXEC_DATA_FLOAT);
3406 }
3407 }
3408
3409 static void
3410 exec_lit(struct tgsi_exec_machine *mach,
3411 const struct tgsi_full_instruction *inst)
3412 {
3413 union tgsi_exec_channel r[3];
3414 union tgsi_exec_channel d[3];
3415
3416 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_YZ) {
3417 fetch_source(mach, &r[0], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3418 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) {
3419 fetch_source(mach, &r[1], &inst->Src[0], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3420 micro_max(&r[1], &r[1], &ZeroVec);
3421
3422 fetch_source(mach, &r[2], &inst->Src[0], TGSI_CHAN_W, TGSI_EXEC_DATA_FLOAT);
3423 micro_min(&r[2], &r[2], &P128Vec);
3424 micro_max(&r[2], &r[2], &M128Vec);
3425 micro_pow(&r[1], &r[1], &r[2]);
3426 micro_lt(&d[TGSI_CHAN_Z], &ZeroVec, &r[0], &r[1], &ZeroVec);
3427 store_dest(mach, &d[TGSI_CHAN_Z], &inst->Dst[0], inst, TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
3428 }
3429 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) {
3430 micro_max(&d[TGSI_CHAN_Y], &r[0], &ZeroVec);
3431 store_dest(mach, &d[TGSI_CHAN_Y], &inst->Dst[0], inst, TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3432 }
3433 }
3434 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) {
3435 store_dest(mach, &OneVec, &inst->Dst[0], inst, TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3436 }
3437
3438 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) {
3439 store_dest(mach, &OneVec, &inst->Dst[0], inst, TGSI_CHAN_W, TGSI_EXEC_DATA_FLOAT);
3440 }
3441 }
3442
3443 static void
3444 exec_break(struct tgsi_exec_machine *mach)
3445 {
3446 if (mach->BreakType == TGSI_EXEC_BREAK_INSIDE_LOOP) {
3447 /* turn off loop channels for each enabled exec channel */
3448 mach->LoopMask &= ~mach->ExecMask;
3449 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3450 UPDATE_EXEC_MASK(mach);
3451 } else {
3452 assert(mach->BreakType == TGSI_EXEC_BREAK_INSIDE_SWITCH);
3453
3454 mach->Switch.mask = 0x0;
3455
3456 UPDATE_EXEC_MASK(mach);
3457 }
3458 }
3459
3460 static void
3461 exec_switch(struct tgsi_exec_machine *mach,
3462 const struct tgsi_full_instruction *inst)
3463 {
3464 assert(mach->SwitchStackTop < TGSI_EXEC_MAX_SWITCH_NESTING);
3465 assert(mach->BreakStackTop < TGSI_EXEC_MAX_BREAK_STACK);
3466
3467 mach->SwitchStack[mach->SwitchStackTop++] = mach->Switch;
3468 fetch_source(mach, &mach->Switch.selector, &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_UINT);
3469 mach->Switch.mask = 0x0;
3470 mach->Switch.defaultMask = 0x0;
3471
3472 mach->BreakStack[mach->BreakStackTop++] = mach->BreakType;
3473 mach->BreakType = TGSI_EXEC_BREAK_INSIDE_SWITCH;
3474
3475 UPDATE_EXEC_MASK(mach);
3476 }
3477
3478 static void
3479 exec_case(struct tgsi_exec_machine *mach,
3480 const struct tgsi_full_instruction *inst)
3481 {
3482 uint prevMask = mach->SwitchStack[mach->SwitchStackTop - 1].mask;
3483 union tgsi_exec_channel src;
3484 uint mask = 0;
3485
3486 fetch_source(mach, &src, &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_UINT);
3487
3488 if (mach->Switch.selector.u[0] == src.u[0]) {
3489 mask |= 0x1;
3490 }
3491 if (mach->Switch.selector.u[1] == src.u[1]) {
3492 mask |= 0x2;
3493 }
3494 if (mach->Switch.selector.u[2] == src.u[2]) {
3495 mask |= 0x4;
3496 }
3497 if (mach->Switch.selector.u[3] == src.u[3]) {
3498 mask |= 0x8;
3499 }
3500
3501 mach->Switch.defaultMask |= mask;
3502
3503 mach->Switch.mask |= mask & prevMask;
3504
3505 UPDATE_EXEC_MASK(mach);
3506 }
3507
3508 /* FIXME: this will only work if default is last */
3509 static void
3510 exec_default(struct tgsi_exec_machine *mach)
3511 {
3512 uint prevMask = mach->SwitchStack[mach->SwitchStackTop - 1].mask;
3513
3514 mach->Switch.mask |= ~mach->Switch.defaultMask & prevMask;
3515
3516 UPDATE_EXEC_MASK(mach);
3517 }
3518
3519 static void
3520 exec_endswitch(struct tgsi_exec_machine *mach)
3521 {
3522 mach->Switch = mach->SwitchStack[--mach->SwitchStackTop];
3523 mach->BreakType = mach->BreakStack[--mach->BreakStackTop];
3524
3525 UPDATE_EXEC_MASK(mach);
3526 }
3527
3528 typedef void (* micro_dop)(union tgsi_double_channel *dst,
3529 const union tgsi_double_channel *src);
3530
3531 typedef void (* micro_dop_sop)(union tgsi_double_channel *dst,
3532 const union tgsi_double_channel *src0,
3533 union tgsi_exec_channel *src1);
3534
3535 typedef void (* micro_dop_s)(union tgsi_double_channel *dst,
3536 const union tgsi_exec_channel *src);
3537
3538 typedef void (* micro_sop_d)(union tgsi_exec_channel *dst,
3539 const union tgsi_double_channel *src);
3540
3541 static void
3542 fetch_double_channel(struct tgsi_exec_machine *mach,
3543 union tgsi_double_channel *chan,
3544 const struct tgsi_full_src_register *reg,
3545 uint chan_0,
3546 uint chan_1)
3547 {
3548 union tgsi_exec_channel src[2];
3549 uint i;
3550
3551 fetch_source_d(mach, &src[0], reg, chan_0);
3552 fetch_source_d(mach, &src[1], reg, chan_1);
3553
3554 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
3555 chan->u[i][0] = src[0].u[i];
3556 chan->u[i][1] = src[1].u[i];
3557 }
3558 if (reg->Register.Absolute) {
3559 micro_dabs(chan, chan);
3560 }
3561 if (reg->Register.Negate) {
3562 micro_dneg(chan, chan);
3563 }
3564 }
3565
3566 static void
3567 store_double_channel(struct tgsi_exec_machine *mach,
3568 const union tgsi_double_channel *chan,
3569 const struct tgsi_full_dst_register *reg,
3570 const struct tgsi_full_instruction *inst,
3571 uint chan_0,
3572 uint chan_1)
3573 {
3574 union tgsi_exec_channel dst[2];
3575 uint i;
3576 union tgsi_double_channel temp;
3577 const uint execmask = mach->ExecMask;
3578
3579 if (!inst->Instruction.Saturate) {
3580 for (i = 0; i < TGSI_QUAD_SIZE; i++)
3581 if (execmask & (1 << i)) {
3582 dst[0].u[i] = chan->u[i][0];
3583 dst[1].u[i] = chan->u[i][1];
3584 }
3585 }
3586 else {
3587 for (i = 0; i < TGSI_QUAD_SIZE; i++)
3588 if (execmask & (1 << i)) {
3589 if (chan->d[i] < 0.0)
3590 temp.d[i] = 0.0;
3591 else if (chan->d[i] > 1.0)
3592 temp.d[i] = 1.0;
3593 else
3594 temp.d[i] = chan->d[i];
3595
3596 dst[0].u[i] = temp.u[i][0];
3597 dst[1].u[i] = temp.u[i][1];
3598 }
3599 }
3600
3601 store_dest_double(mach, &dst[0], reg, chan_0, TGSI_EXEC_DATA_UINT);
3602 if (chan_1 != (unsigned)-1)
3603 store_dest_double(mach, &dst[1], reg, chan_1, TGSI_EXEC_DATA_UINT);
3604 }
3605
3606 static void
3607 exec_double_unary(struct tgsi_exec_machine *mach,
3608 const struct tgsi_full_instruction *inst,
3609 micro_dop op)
3610 {
3611 union tgsi_double_channel src;
3612 union tgsi_double_channel dst;
3613
3614 if ((inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_XY) == TGSI_WRITEMASK_XY) {
3615 fetch_double_channel(mach, &src, &inst->Src[0], TGSI_CHAN_X, TGSI_CHAN_Y);
3616 op(&dst, &src);
3617 store_double_channel(mach, &dst, &inst->Dst[0], inst, TGSI_CHAN_X, TGSI_CHAN_Y);
3618 }
3619 if ((inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_ZW) == TGSI_WRITEMASK_ZW) {
3620 fetch_double_channel(mach, &src, &inst->Src[0], TGSI_CHAN_Z, TGSI_CHAN_W);
3621 op(&dst, &src);
3622 store_double_channel(mach, &dst, &inst->Dst[0], inst, TGSI_CHAN_Z, TGSI_CHAN_W);
3623 }
3624 }
3625
3626 static void
3627 exec_double_binary(struct tgsi_exec_machine *mach,
3628 const struct tgsi_full_instruction *inst,
3629 micro_dop op,
3630 enum tgsi_exec_datatype dst_datatype)
3631 {
3632 union tgsi_double_channel src[2];
3633 union tgsi_double_channel dst;
3634 int first_dest_chan, second_dest_chan;
3635 int wmask;
3636
3637 wmask = inst->Dst[0].Register.WriteMask;
3638 /* these are & because of the way DSLT etc store their destinations */
3639 if (wmask & TGSI_WRITEMASK_XY) {
3640 first_dest_chan = TGSI_CHAN_X;
3641 second_dest_chan = TGSI_CHAN_Y;
3642 if (dst_datatype == TGSI_EXEC_DATA_UINT) {
3643 first_dest_chan = (wmask & TGSI_WRITEMASK_X) ? TGSI_CHAN_X : TGSI_CHAN_Y;
3644 second_dest_chan = -1;
3645 }
3646
3647 fetch_double_channel(mach, &src[0], &inst->Src[0], TGSI_CHAN_X, TGSI_CHAN_Y);
3648 fetch_double_channel(mach, &src[1], &inst->Src[1], TGSI_CHAN_X, TGSI_CHAN_Y);
3649 op(&dst, src);
3650 store_double_channel(mach, &dst, &inst->Dst[0], inst, first_dest_chan, second_dest_chan);
3651 }
3652
3653 if (wmask & TGSI_WRITEMASK_ZW) {
3654 first_dest_chan = TGSI_CHAN_Z;
3655 second_dest_chan = TGSI_CHAN_W;
3656 if (dst_datatype == TGSI_EXEC_DATA_UINT) {
3657 first_dest_chan = (wmask & TGSI_WRITEMASK_Z) ? TGSI_CHAN_Z : TGSI_CHAN_W;
3658 second_dest_chan = -1;
3659 }
3660
3661 fetch_double_channel(mach, &src[0], &inst->Src[0], TGSI_CHAN_Z, TGSI_CHAN_W);
3662 fetch_double_channel(mach, &src[1], &inst->Src[1], TGSI_CHAN_Z, TGSI_CHAN_W);
3663 op(&dst, src);
3664 store_double_channel(mach, &dst, &inst->Dst[0], inst, first_dest_chan, second_dest_chan);
3665 }
3666 }
3667
3668 static void
3669 exec_double_trinary(struct tgsi_exec_machine *mach,
3670 const struct tgsi_full_instruction *inst,
3671 micro_dop op)
3672 {
3673 union tgsi_double_channel src[3];
3674 union tgsi_double_channel dst;
3675
3676 if ((inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_XY) == TGSI_WRITEMASK_XY) {
3677 fetch_double_channel(mach, &src[0], &inst->Src[0], TGSI_CHAN_X, TGSI_CHAN_Y);
3678 fetch_double_channel(mach, &src[1], &inst->Src[1], TGSI_CHAN_X, TGSI_CHAN_Y);
3679 fetch_double_channel(mach, &src[2], &inst->Src[2], TGSI_CHAN_X, TGSI_CHAN_Y);
3680 op(&dst, src);
3681 store_double_channel(mach, &dst, &inst->Dst[0], inst, TGSI_CHAN_X, TGSI_CHAN_Y);
3682 }
3683 if ((inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_ZW) == TGSI_WRITEMASK_ZW) {
3684 fetch_double_channel(mach, &src[0], &inst->Src[0], TGSI_CHAN_Z, TGSI_CHAN_W);
3685 fetch_double_channel(mach, &src[1], &inst->Src[1], TGSI_CHAN_Z, TGSI_CHAN_W);
3686 fetch_double_channel(mach, &src[2], &inst->Src[2], TGSI_CHAN_Z, TGSI_CHAN_W);
3687 op(&dst, src);
3688 store_double_channel(mach, &dst, &inst->Dst[0], inst, TGSI_CHAN_Z, TGSI_CHAN_W);
3689 }
3690 }
3691
3692 static void
3693 exec_dldexp(struct tgsi_exec_machine *mach,
3694 const struct tgsi_full_instruction *inst)
3695 {
3696 union tgsi_double_channel src0;
3697 union tgsi_exec_channel src1;
3698 union tgsi_double_channel dst;
3699 int wmask;
3700
3701 wmask = inst->Dst[0].Register.WriteMask;
3702 if (wmask & TGSI_WRITEMASK_XY) {
3703 fetch_double_channel(mach, &src0, &inst->Src[0], TGSI_CHAN_X, TGSI_CHAN_Y);
3704 fetch_source(mach, &src1, &inst->Src[1], TGSI_CHAN_X, TGSI_EXEC_DATA_INT);
3705 micro_dldexp(&dst, &src0, &src1);
3706 store_double_channel(mach, &dst, &inst->Dst[0], inst, TGSI_CHAN_X, TGSI_CHAN_Y);
3707 }
3708
3709 if (wmask & TGSI_WRITEMASK_ZW) {
3710 fetch_double_channel(mach, &src0, &inst->Src[0], TGSI_CHAN_Z, TGSI_CHAN_W);
3711 fetch_source(mach, &src1, &inst->Src[1], TGSI_CHAN_Z, TGSI_EXEC_DATA_INT);
3712 micro_dldexp(&dst, &src0, &src1);
3713 store_double_channel(mach, &dst, &inst->Dst[0], inst, TGSI_CHAN_Z, TGSI_CHAN_W);
3714 }
3715 }
3716
3717 static void
3718 exec_dfracexp(struct tgsi_exec_machine *mach,
3719 const struct tgsi_full_instruction *inst)
3720 {
3721 union tgsi_double_channel src;
3722 union tgsi_double_channel dst;
3723 union tgsi_exec_channel dst_exp;
3724
3725 fetch_double_channel(mach, &src, &inst->Src[0], TGSI_CHAN_X, TGSI_CHAN_Y);
3726 micro_dfracexp(&dst, &dst_exp, &src);
3727 if ((inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_XY) == TGSI_WRITEMASK_XY)
3728 store_double_channel(mach, &dst, &inst->Dst[0], inst, TGSI_CHAN_X, TGSI_CHAN_Y);
3729 if ((inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_ZW) == TGSI_WRITEMASK_ZW)
3730 store_double_channel(mach, &dst, &inst->Dst[0], inst, TGSI_CHAN_Z, TGSI_CHAN_W);
3731 for (unsigned chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3732 if (inst->Dst[1].Register.WriteMask & (1 << chan))
3733 store_dest(mach, &dst_exp, &inst->Dst[1], inst, chan, TGSI_EXEC_DATA_INT);
3734 }
3735 }
3736
3737 static void
3738 exec_arg0_64_arg1_32(struct tgsi_exec_machine *mach,
3739 const struct tgsi_full_instruction *inst,
3740 micro_dop_sop op)
3741 {
3742 union tgsi_double_channel src0;
3743 union tgsi_exec_channel src1;
3744 union tgsi_double_channel dst;
3745 int wmask;
3746
3747 wmask = inst->Dst[0].Register.WriteMask;
3748 if (wmask & TGSI_WRITEMASK_XY) {
3749 fetch_double_channel(mach, &src0, &inst->Src[0], TGSI_CHAN_X, TGSI_CHAN_Y);
3750 fetch_source(mach, &src1, &inst->Src[1], TGSI_CHAN_X, TGSI_EXEC_DATA_INT);
3751 op(&dst, &src0, &src1);
3752 store_double_channel(mach, &dst, &inst->Dst[0], inst, TGSI_CHAN_X, TGSI_CHAN_Y);
3753 }
3754
3755 if (wmask & TGSI_WRITEMASK_ZW) {
3756 fetch_double_channel(mach, &src0, &inst->Src[0], TGSI_CHAN_Z, TGSI_CHAN_W);
3757 fetch_source(mach, &src1, &inst->Src[1], TGSI_CHAN_Z, TGSI_EXEC_DATA_INT);
3758 op(&dst, &src0, &src1);
3759 store_double_channel(mach, &dst, &inst->Dst[0], inst, TGSI_CHAN_Z, TGSI_CHAN_W);
3760 }
3761 }
3762
3763 static int
3764 get_image_coord_dim(unsigned tgsi_tex)
3765 {
3766 int dim;
3767 switch (tgsi_tex) {
3768 case TGSI_TEXTURE_BUFFER:
3769 case TGSI_TEXTURE_1D:
3770 dim = 1;
3771 break;
3772 case TGSI_TEXTURE_2D:
3773 case TGSI_TEXTURE_RECT:
3774 case TGSI_TEXTURE_1D_ARRAY:
3775 case TGSI_TEXTURE_2D_MSAA:
3776 dim = 2;
3777 break;
3778 case TGSI_TEXTURE_3D:
3779 case TGSI_TEXTURE_CUBE:
3780 case TGSI_TEXTURE_2D_ARRAY:
3781 case TGSI_TEXTURE_2D_ARRAY_MSAA:
3782 case TGSI_TEXTURE_CUBE_ARRAY:
3783 dim = 3;
3784 break;
3785 default:
3786 assert(!"unknown texture target");
3787 dim = 0;
3788 break;
3789 }
3790
3791 return dim;
3792 }
3793
3794 static int
3795 get_image_coord_sample(unsigned tgsi_tex)
3796 {
3797 int sample = 0;
3798 switch (tgsi_tex) {
3799 case TGSI_TEXTURE_2D_MSAA:
3800 sample = 3;
3801 break;
3802 case TGSI_TEXTURE_2D_ARRAY_MSAA:
3803 sample = 4;
3804 break;
3805 default:
3806 break;
3807 }
3808 return sample;
3809 }
3810
3811 static void
3812 exec_load_img(struct tgsi_exec_machine *mach,
3813 const struct tgsi_full_instruction *inst)
3814 {
3815 union tgsi_exec_channel r[4], sample_r;
3816 uint unit;
3817 int sample;
3818 int i, j;
3819 int dim;
3820 uint chan;
3821 float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE];
3822 struct tgsi_image_params params;
3823 int kilmask = mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0];
3824
3825 unit = fetch_sampler_unit(mach, inst, 0);
3826 dim = get_image_coord_dim(inst->Memory.Texture);
3827 sample = get_image_coord_sample(inst->Memory.Texture);
3828 assert(dim <= 3);
3829
3830 params.execmask = mach->ExecMask & mach->NonHelperMask & ~kilmask;
3831 params.unit = unit;
3832 params.tgsi_tex_instr = inst->Memory.Texture;
3833 params.format = inst->Memory.Format;
3834
3835 for (i = 0; i < dim; i++) {
3836 IFETCH(&r[i], 1, TGSI_CHAN_X + i);
3837 }
3838
3839 if (sample)
3840 IFETCH(&sample_r, 1, TGSI_CHAN_X + sample);
3841
3842 mach->Image->load(mach->Image, &params,
3843 r[0].i, r[1].i, r[2].i, sample_r.i,
3844 rgba);
3845 for (j = 0; j < TGSI_QUAD_SIZE; j++) {
3846 r[0].f[j] = rgba[0][j];
3847 r[1].f[j] = rgba[1][j];
3848 r[2].f[j] = rgba[2][j];
3849 r[3].f[j] = rgba[3][j];
3850 }
3851 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3852 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3853 store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
3854 }
3855 }
3856 }
3857
3858 static void
3859 exec_load_buf(struct tgsi_exec_machine *mach,
3860 const struct tgsi_full_instruction *inst)
3861 {
3862 union tgsi_exec_channel r[4];
3863 uint unit;
3864 int j;
3865 uint chan;
3866 float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE];
3867 struct tgsi_buffer_params params;
3868 int kilmask = mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0];
3869
3870 unit = fetch_sampler_unit(mach, inst, 0);
3871
3872 params.execmask = mach->ExecMask & mach->NonHelperMask & ~kilmask;
3873 params.unit = unit;
3874 IFETCH(&r[0], 1, TGSI_CHAN_X);
3875
3876 mach->Buffer->load(mach->Buffer, &params,
3877 r[0].i, rgba);
3878 for (j = 0; j < TGSI_QUAD_SIZE; j++) {
3879 r[0].f[j] = rgba[0][j];
3880 r[1].f[j] = rgba[1][j];
3881 r[2].f[j] = rgba[2][j];
3882 r[3].f[j] = rgba[3][j];
3883 }
3884 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3885 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3886 store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
3887 }
3888 }
3889 }
3890
3891 static void
3892 exec_load_mem(struct tgsi_exec_machine *mach,
3893 const struct tgsi_full_instruction *inst)
3894 {
3895 union tgsi_exec_channel r[4];
3896 uint chan;
3897 char *ptr = mach->LocalMem;
3898 uint32_t offset;
3899 int j;
3900
3901 IFETCH(&r[0], 1, TGSI_CHAN_X);
3902 if (r[0].u[0] >= mach->LocalMemSize)
3903 return;
3904
3905 offset = r[0].u[0];
3906 ptr += offset;
3907
3908 for (j = 0; j < TGSI_QUAD_SIZE; j++) {
3909 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3910 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3911 memcpy(&r[chan].u[j], ptr + (4 * chan), 4);
3912 }
3913 }
3914 }
3915
3916 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
3917 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
3918 store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
3919 }
3920 }
3921 }
3922
3923 static void
3924 exec_load(struct tgsi_exec_machine *mach,
3925 const struct tgsi_full_instruction *inst)
3926 {
3927 if (inst->Src[0].Register.File == TGSI_FILE_IMAGE)
3928 exec_load_img(mach, inst);
3929 else if (inst->Src[0].Register.File == TGSI_FILE_BUFFER)
3930 exec_load_buf(mach, inst);
3931 else if (inst->Src[0].Register.File == TGSI_FILE_MEMORY)
3932 exec_load_mem(mach, inst);
3933 }
3934
3935 static void
3936 exec_store_img(struct tgsi_exec_machine *mach,
3937 const struct tgsi_full_instruction *inst)
3938 {
3939 union tgsi_exec_channel r[3], sample_r;
3940 union tgsi_exec_channel value[4];
3941 float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE];
3942 struct tgsi_image_params params;
3943 int dim;
3944 int sample;
3945 int i, j;
3946 uint unit;
3947 int kilmask = mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0];
3948 unit = inst->Dst[0].Register.Index;
3949 dim = get_image_coord_dim(inst->Memory.Texture);
3950 sample = get_image_coord_sample(inst->Memory.Texture);
3951 assert(dim <= 3);
3952
3953 params.execmask = mach->ExecMask & mach->NonHelperMask & ~kilmask;
3954 params.unit = unit;
3955 params.tgsi_tex_instr = inst->Memory.Texture;
3956 params.format = inst->Memory.Format;
3957
3958 for (i = 0; i < dim; i++) {
3959 IFETCH(&r[i], 0, TGSI_CHAN_X + i);
3960 }
3961
3962 for (i = 0; i < 4; i++) {
3963 FETCH(&value[i], 1, TGSI_CHAN_X + i);
3964 }
3965 if (sample)
3966 IFETCH(&sample_r, 0, TGSI_CHAN_X + sample);
3967
3968 for (j = 0; j < TGSI_QUAD_SIZE; j++) {
3969 rgba[0][j] = value[0].f[j];
3970 rgba[1][j] = value[1].f[j];
3971 rgba[2][j] = value[2].f[j];
3972 rgba[3][j] = value[3].f[j];
3973 }
3974
3975 mach->Image->store(mach->Image, &params,
3976 r[0].i, r[1].i, r[2].i, sample_r.i,
3977 rgba);
3978 }
3979
3980 static void
3981 exec_store_buf(struct tgsi_exec_machine *mach,
3982 const struct tgsi_full_instruction *inst)
3983 {
3984 union tgsi_exec_channel r[3];
3985 union tgsi_exec_channel value[4];
3986 float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE];
3987 struct tgsi_buffer_params params;
3988 int i, j;
3989 uint unit;
3990 int kilmask = mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0];
3991
3992 unit = inst->Dst[0].Register.Index;
3993
3994 params.execmask = mach->ExecMask & mach->NonHelperMask & ~kilmask;
3995 params.unit = unit;
3996 params.writemask = inst->Dst[0].Register.WriteMask;
3997
3998 IFETCH(&r[0], 0, TGSI_CHAN_X);
3999 for (i = 0; i < 4; i++) {
4000 FETCH(&value[i], 1, TGSI_CHAN_X + i);
4001 }
4002
4003 for (j = 0; j < TGSI_QUAD_SIZE; j++) {
4004 rgba[0][j] = value[0].f[j];
4005 rgba[1][j] = value[1].f[j];
4006 rgba[2][j] = value[2].f[j];
4007 rgba[3][j] = value[3].f[j];
4008 }
4009
4010 mach->Buffer->store(mach->Buffer, &params,
4011 r[0].i,
4012 rgba);
4013 }
4014
4015 static void
4016 exec_store_mem(struct tgsi_exec_machine *mach,
4017 const struct tgsi_full_instruction *inst)
4018 {
4019 union tgsi_exec_channel r[3];
4020 union tgsi_exec_channel value[4];
4021 uint i, chan;
4022 char *ptr = mach->LocalMem;
4023 int kilmask = mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0];
4024 int execmask = mach->ExecMask & mach->NonHelperMask & ~kilmask;
4025
4026 IFETCH(&r[0], 0, TGSI_CHAN_X);
4027
4028 for (i = 0; i < 4; i++) {
4029 FETCH(&value[i], 1, TGSI_CHAN_X + i);
4030 }
4031
4032 if (r[0].u[0] >= mach->LocalMemSize)
4033 return;
4034 ptr += r[0].u[0];
4035
4036 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
4037 if (execmask & (1 << i)) {
4038 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
4039 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
4040 memcpy(ptr + (chan * 4), &value[chan].u[0], 4);
4041 }
4042 }
4043 }
4044 }
4045 }
4046
4047 static void
4048 exec_store(struct tgsi_exec_machine *mach,
4049 const struct tgsi_full_instruction *inst)
4050 {
4051 if (inst->Dst[0].Register.File == TGSI_FILE_IMAGE)
4052 exec_store_img(mach, inst);
4053 else if (inst->Dst[0].Register.File == TGSI_FILE_BUFFER)
4054 exec_store_buf(mach, inst);
4055 else if (inst->Dst[0].Register.File == TGSI_FILE_MEMORY)
4056 exec_store_mem(mach, inst);
4057 }
4058
4059 static void
4060 exec_atomop_img(struct tgsi_exec_machine *mach,
4061 const struct tgsi_full_instruction *inst)
4062 {
4063 union tgsi_exec_channel r[4], sample_r;
4064 union tgsi_exec_channel value[4], value2[4];
4065 float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE];
4066 float rgba2[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE];
4067 struct tgsi_image_params params;
4068 int dim;
4069 int sample;
4070 int i, j;
4071 uint unit, chan;
4072 int kilmask = mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0];
4073 unit = fetch_sampler_unit(mach, inst, 0);
4074 dim = get_image_coord_dim(inst->Memory.Texture);
4075 sample = get_image_coord_sample(inst->Memory.Texture);
4076 assert(dim <= 3);
4077
4078 params.execmask = mach->ExecMask & mach->NonHelperMask & ~kilmask;
4079 params.unit = unit;
4080 params.tgsi_tex_instr = inst->Memory.Texture;
4081 params.format = inst->Memory.Format;
4082
4083 for (i = 0; i < dim; i++) {
4084 IFETCH(&r[i], 1, TGSI_CHAN_X + i);
4085 }
4086
4087 for (i = 0; i < 4; i++) {
4088 FETCH(&value[i], 2, TGSI_CHAN_X + i);
4089 if (inst->Instruction.Opcode == TGSI_OPCODE_ATOMCAS)
4090 FETCH(&value2[i], 3, TGSI_CHAN_X + i);
4091 }
4092 if (sample)
4093 IFETCH(&sample_r, 1, TGSI_CHAN_X + sample);
4094
4095 for (j = 0; j < TGSI_QUAD_SIZE; j++) {
4096 rgba[0][j] = value[0].f[j];
4097 rgba[1][j] = value[1].f[j];
4098 rgba[2][j] = value[2].f[j];
4099 rgba[3][j] = value[3].f[j];
4100 }
4101 if (inst->Instruction.Opcode == TGSI_OPCODE_ATOMCAS) {
4102 for (j = 0; j < TGSI_QUAD_SIZE; j++) {
4103 rgba2[0][j] = value2[0].f[j];
4104 rgba2[1][j] = value2[1].f[j];
4105 rgba2[2][j] = value2[2].f[j];
4106 rgba2[3][j] = value2[3].f[j];
4107 }
4108 }
4109
4110 mach->Image->op(mach->Image, &params, inst->Instruction.Opcode,
4111 r[0].i, r[1].i, r[2].i, sample_r.i,
4112 rgba, rgba2);
4113
4114 for (j = 0; j < TGSI_QUAD_SIZE; j++) {
4115 r[0].f[j] = rgba[0][j];
4116 r[1].f[j] = rgba[1][j];
4117 r[2].f[j] = rgba[2][j];
4118 r[3].f[j] = rgba[3][j];
4119 }
4120 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
4121 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
4122 store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
4123 }
4124 }
4125 }
4126
4127 static void
4128 exec_atomop_buf(struct tgsi_exec_machine *mach,
4129 const struct tgsi_full_instruction *inst)
4130 {
4131 union tgsi_exec_channel r[4];
4132 union tgsi_exec_channel value[4], value2[4];
4133 float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE];
4134 float rgba2[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE];
4135 struct tgsi_buffer_params params;
4136 int i, j;
4137 uint unit, chan;
4138 int kilmask = mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0];
4139
4140 unit = fetch_sampler_unit(mach, inst, 0);
4141
4142 params.execmask = mach->ExecMask & mach->NonHelperMask & ~kilmask;
4143 params.unit = unit;
4144 params.writemask = inst->Dst[0].Register.WriteMask;
4145
4146 IFETCH(&r[0], 1, TGSI_CHAN_X);
4147
4148 for (i = 0; i < 4; i++) {
4149 FETCH(&value[i], 2, TGSI_CHAN_X + i);
4150 if (inst->Instruction.Opcode == TGSI_OPCODE_ATOMCAS)
4151 FETCH(&value2[i], 3, TGSI_CHAN_X + i);
4152 }
4153
4154 for (j = 0; j < TGSI_QUAD_SIZE; j++) {
4155 rgba[0][j] = value[0].f[j];
4156 rgba[1][j] = value[1].f[j];
4157 rgba[2][j] = value[2].f[j];
4158 rgba[3][j] = value[3].f[j];
4159 }
4160 if (inst->Instruction.Opcode == TGSI_OPCODE_ATOMCAS) {
4161 for (j = 0; j < TGSI_QUAD_SIZE; j++) {
4162 rgba2[0][j] = value2[0].f[j];
4163 rgba2[1][j] = value2[1].f[j];
4164 rgba2[2][j] = value2[2].f[j];
4165 rgba2[3][j] = value2[3].f[j];
4166 }
4167 }
4168
4169 mach->Buffer->op(mach->Buffer, &params, inst->Instruction.Opcode,
4170 r[0].i,
4171 rgba, rgba2);
4172
4173 for (j = 0; j < TGSI_QUAD_SIZE; j++) {
4174 r[0].f[j] = rgba[0][j];
4175 r[1].f[j] = rgba[1][j];
4176 r[2].f[j] = rgba[2][j];
4177 r[3].f[j] = rgba[3][j];
4178 }
4179 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
4180 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
4181 store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
4182 }
4183 }
4184 }
4185
4186 static void
4187 exec_atomop_mem(struct tgsi_exec_machine *mach,
4188 const struct tgsi_full_instruction *inst)
4189 {
4190 union tgsi_exec_channel r[4];
4191 union tgsi_exec_channel value[4], value2[4];
4192 char *ptr = mach->LocalMem;
4193 uint32_t val;
4194 uint chan, i;
4195 uint32_t offset;
4196 int kilmask = mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0];
4197 int execmask = mach->ExecMask & mach->NonHelperMask & ~kilmask;
4198 IFETCH(&r[0], 1, TGSI_CHAN_X);
4199
4200 if (r[0].u[0] >= mach->LocalMemSize)
4201 return;
4202
4203 offset = r[0].u[0];
4204 ptr += offset;
4205 for (i = 0; i < 4; i++) {
4206 FETCH(&value[i], 2, TGSI_CHAN_X + i);
4207 if (inst->Instruction.Opcode == TGSI_OPCODE_ATOMCAS)
4208 FETCH(&value2[i], 3, TGSI_CHAN_X + i);
4209 }
4210
4211 memcpy(&r[0].u[0], ptr, 4);
4212 val = r[0].u[0];
4213 switch (inst->Instruction.Opcode) {
4214 case TGSI_OPCODE_ATOMUADD:
4215 val += value[0].u[0];
4216 break;
4217 case TGSI_OPCODE_ATOMXOR:
4218 val ^= value[0].u[0];
4219 break;
4220 case TGSI_OPCODE_ATOMOR:
4221 val |= value[0].u[0];
4222 break;
4223 case TGSI_OPCODE_ATOMAND:
4224 val &= value[0].u[0];
4225 break;
4226 case TGSI_OPCODE_ATOMUMIN:
4227 val = MIN2(val, value[0].u[0]);
4228 break;
4229 case TGSI_OPCODE_ATOMUMAX:
4230 val = MAX2(val, value[0].u[0]);
4231 break;
4232 case TGSI_OPCODE_ATOMIMIN:
4233 val = MIN2(r[0].i[0], value[0].i[0]);
4234 break;
4235 case TGSI_OPCODE_ATOMIMAX:
4236 val = MAX2(r[0].i[0], value[0].i[0]);
4237 break;
4238 case TGSI_OPCODE_ATOMXCHG:
4239 val = value[0].i[0];
4240 break;
4241 case TGSI_OPCODE_ATOMCAS:
4242 if (val == value[0].u[0])
4243 val = value2[0].u[0];
4244 break;
4245 default:
4246 break;
4247 }
4248 for (i = 0; i < TGSI_QUAD_SIZE; i++)
4249 if (execmask & (1 << i))
4250 memcpy(ptr, &val, 4);
4251
4252 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
4253 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
4254 store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
4255 }
4256 }
4257 }
4258
4259 static void
4260 exec_atomop(struct tgsi_exec_machine *mach,
4261 const struct tgsi_full_instruction *inst)
4262 {
4263 if (inst->Src[0].Register.File == TGSI_FILE_IMAGE)
4264 exec_atomop_img(mach, inst);
4265 else if (inst->Src[0].Register.File == TGSI_FILE_BUFFER)
4266 exec_atomop_buf(mach, inst);
4267 else if (inst->Src[0].Register.File == TGSI_FILE_MEMORY)
4268 exec_atomop_mem(mach, inst);
4269 }
4270
4271 static void
4272 exec_resq_img(struct tgsi_exec_machine *mach,
4273 const struct tgsi_full_instruction *inst)
4274 {
4275 int result[4];
4276 union tgsi_exec_channel r[4];
4277 uint unit;
4278 int i, chan, j;
4279 struct tgsi_image_params params;
4280 int kilmask = mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0];
4281
4282 unit = fetch_sampler_unit(mach, inst, 0);
4283
4284 params.execmask = mach->ExecMask & mach->NonHelperMask & ~kilmask;
4285 params.unit = unit;
4286 params.tgsi_tex_instr = inst->Memory.Texture;
4287 params.format = inst->Memory.Format;
4288
4289 mach->Image->get_dims(mach->Image, &params, result);
4290
4291 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
4292 for (j = 0; j < 4; j++) {
4293 r[j].i[i] = result[j];
4294 }
4295 }
4296
4297 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
4298 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
4299 store_dest(mach, &r[chan], &inst->Dst[0], inst, chan,
4300 TGSI_EXEC_DATA_INT);
4301 }
4302 }
4303 }
4304
4305 static void
4306 exec_resq_buf(struct tgsi_exec_machine *mach,
4307 const struct tgsi_full_instruction *inst)
4308 {
4309 int result;
4310 union tgsi_exec_channel r[4];
4311 uint unit;
4312 int i, chan;
4313 struct tgsi_buffer_params params;
4314 int kilmask = mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0];
4315
4316 unit = fetch_sampler_unit(mach, inst, 0);
4317
4318 params.execmask = mach->ExecMask & mach->NonHelperMask & ~kilmask;
4319 params.unit = unit;
4320
4321 mach->Buffer->get_dims(mach->Buffer, &params, &result);
4322
4323 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
4324 r[0].i[i] = result;
4325 }
4326
4327 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
4328 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
4329 store_dest(mach, &r[chan], &inst->Dst[0], inst, chan,
4330 TGSI_EXEC_DATA_INT);
4331 }
4332 }
4333 }
4334
4335 static void
4336 exec_resq(struct tgsi_exec_machine *mach,
4337 const struct tgsi_full_instruction *inst)
4338 {
4339 if (inst->Src[0].Register.File == TGSI_FILE_IMAGE)
4340 exec_resq_img(mach, inst);
4341 else
4342 exec_resq_buf(mach, inst);
4343 }
4344
4345 static void
4346 micro_f2u64(union tgsi_double_channel *dst,
4347 const union tgsi_exec_channel *src)
4348 {
4349 dst->u64[0] = (uint64_t)src->f[0];
4350 dst->u64[1] = (uint64_t)src->f[1];
4351 dst->u64[2] = (uint64_t)src->f[2];
4352 dst->u64[3] = (uint64_t)src->f[3];
4353 }
4354
4355 static void
4356 micro_f2i64(union tgsi_double_channel *dst,
4357 const union tgsi_exec_channel *src)
4358 {
4359 dst->i64[0] = (int64_t)src->f[0];
4360 dst->i64[1] = (int64_t)src->f[1];
4361 dst->i64[2] = (int64_t)src->f[2];
4362 dst->i64[3] = (int64_t)src->f[3];
4363 }
4364
4365 static void
4366 micro_u2i64(union tgsi_double_channel *dst,
4367 const union tgsi_exec_channel *src)
4368 {
4369 dst->u64[0] = (uint64_t)src->u[0];
4370 dst->u64[1] = (uint64_t)src->u[1];
4371 dst->u64[2] = (uint64_t)src->u[2];
4372 dst->u64[3] = (uint64_t)src->u[3];
4373 }
4374
4375 static void
4376 micro_i2i64(union tgsi_double_channel *dst,
4377 const union tgsi_exec_channel *src)
4378 {
4379 dst->i64[0] = (int64_t)src->i[0];
4380 dst->i64[1] = (int64_t)src->i[1];
4381 dst->i64[2] = (int64_t)src->i[2];
4382 dst->i64[3] = (int64_t)src->i[3];
4383 }
4384
4385 static void
4386 micro_d2u64(union tgsi_double_channel *dst,
4387 const union tgsi_double_channel *src)
4388 {
4389 dst->u64[0] = (uint64_t)src->d[0];
4390 dst->u64[1] = (uint64_t)src->d[1];
4391 dst->u64[2] = (uint64_t)src->d[2];
4392 dst->u64[3] = (uint64_t)src->d[3];
4393 }
4394
4395 static void
4396 micro_d2i64(union tgsi_double_channel *dst,
4397 const union tgsi_double_channel *src)
4398 {
4399 dst->i64[0] = (int64_t)src->d[0];
4400 dst->i64[1] = (int64_t)src->d[1];
4401 dst->i64[2] = (int64_t)src->d[2];
4402 dst->i64[3] = (int64_t)src->d[3];
4403 }
4404
4405 static void
4406 micro_u642d(union tgsi_double_channel *dst,
4407 const union tgsi_double_channel *src)
4408 {
4409 dst->d[0] = (double)src->u64[0];
4410 dst->d[1] = (double)src->u64[1];
4411 dst->d[2] = (double)src->u64[2];
4412 dst->d[3] = (double)src->u64[3];
4413 }
4414
4415 static void
4416 micro_i642d(union tgsi_double_channel *dst,
4417 const union tgsi_double_channel *src)
4418 {
4419 dst->d[0] = (double)src->i64[0];
4420 dst->d[1] = (double)src->i64[1];
4421 dst->d[2] = (double)src->i64[2];
4422 dst->d[3] = (double)src->i64[3];
4423 }
4424
4425 static void
4426 micro_u642f(union tgsi_exec_channel *dst,
4427 const union tgsi_double_channel *src)
4428 {
4429 dst->f[0] = (float)src->u64[0];
4430 dst->f[1] = (float)src->u64[1];
4431 dst->f[2] = (float)src->u64[2];
4432 dst->f[3] = (float)src->u64[3];
4433 }
4434
4435 static void
4436 micro_i642f(union tgsi_exec_channel *dst,
4437 const union tgsi_double_channel *src)
4438 {
4439 dst->f[0] = (float)src->i64[0];
4440 dst->f[1] = (float)src->i64[1];
4441 dst->f[2] = (float)src->i64[2];
4442 dst->f[3] = (float)src->i64[3];
4443 }
4444
4445 static void
4446 exec_t_2_64(struct tgsi_exec_machine *mach,
4447 const struct tgsi_full_instruction *inst,
4448 micro_dop_s op,
4449 enum tgsi_exec_datatype src_datatype)
4450 {
4451 union tgsi_exec_channel src;
4452 union tgsi_double_channel dst;
4453
4454 if ((inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_XY) == TGSI_WRITEMASK_XY) {
4455 fetch_source(mach, &src, &inst->Src[0], TGSI_CHAN_X, src_datatype);
4456 op(&dst, &src);
4457 store_double_channel(mach, &dst, &inst->Dst[0], inst, TGSI_CHAN_X, TGSI_CHAN_Y);
4458 }
4459 if ((inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_ZW) == TGSI_WRITEMASK_ZW) {
4460 fetch_source(mach, &src, &inst->Src[0], TGSI_CHAN_Y, src_datatype);
4461 op(&dst, &src);
4462 store_double_channel(mach, &dst, &inst->Dst[0], inst, TGSI_CHAN_Z, TGSI_CHAN_W);
4463 }
4464 }
4465
4466 static void
4467 exec_64_2_t(struct tgsi_exec_machine *mach,
4468 const struct tgsi_full_instruction *inst,
4469 micro_sop_d op,
4470 enum tgsi_exec_datatype dst_datatype)
4471 {
4472 union tgsi_double_channel src;
4473 union tgsi_exec_channel dst;
4474 int wm = inst->Dst[0].Register.WriteMask;
4475 int i;
4476 int bit;
4477 for (i = 0; i < 2; i++) {
4478 bit = ffs(wm);
4479 if (bit) {
4480 wm &= ~(1 << (bit - 1));
4481 if (i == 0)
4482 fetch_double_channel(mach, &src, &inst->Src[0], TGSI_CHAN_X, TGSI_CHAN_Y);
4483 else
4484 fetch_double_channel(mach, &src, &inst->Src[0], TGSI_CHAN_Z, TGSI_CHAN_W);
4485 op(&dst, &src);
4486 store_dest(mach, &dst, &inst->Dst[0], inst, bit - 1, dst_datatype);
4487 }
4488 }
4489 }
4490
4491 static void
4492 micro_i2f(union tgsi_exec_channel *dst,
4493 const union tgsi_exec_channel *src)
4494 {
4495 dst->f[0] = (float)src->i[0];
4496 dst->f[1] = (float)src->i[1];
4497 dst->f[2] = (float)src->i[2];
4498 dst->f[3] = (float)src->i[3];
4499 }
4500
4501 static void
4502 micro_not(union tgsi_exec_channel *dst,
4503 const union tgsi_exec_channel *src)
4504 {
4505 dst->u[0] = ~src->u[0];
4506 dst->u[1] = ~src->u[1];
4507 dst->u[2] = ~src->u[2];
4508 dst->u[3] = ~src->u[3];
4509 }
4510
4511 static void
4512 micro_shl(union tgsi_exec_channel *dst,
4513 const union tgsi_exec_channel *src0,
4514 const union tgsi_exec_channel *src1)
4515 {
4516 unsigned masked_count;
4517 masked_count = src1->u[0] & 0x1f;
4518 dst->u[0] = src0->u[0] << masked_count;
4519 masked_count = src1->u[1] & 0x1f;
4520 dst->u[1] = src0->u[1] << masked_count;
4521 masked_count = src1->u[2] & 0x1f;
4522 dst->u[2] = src0->u[2] << masked_count;
4523 masked_count = src1->u[3] & 0x1f;
4524 dst->u[3] = src0->u[3] << masked_count;
4525 }
4526
4527 static void
4528 micro_and(union tgsi_exec_channel *dst,
4529 const union tgsi_exec_channel *src0,
4530 const union tgsi_exec_channel *src1)
4531 {
4532 dst->u[0] = src0->u[0] & src1->u[0];
4533 dst->u[1] = src0->u[1] & src1->u[1];
4534 dst->u[2] = src0->u[2] & src1->u[2];
4535 dst->u[3] = src0->u[3] & src1->u[3];
4536 }
4537
4538 static void
4539 micro_or(union tgsi_exec_channel *dst,
4540 const union tgsi_exec_channel *src0,
4541 const union tgsi_exec_channel *src1)
4542 {
4543 dst->u[0] = src0->u[0] | src1->u[0];
4544 dst->u[1] = src0->u[1] | src1->u[1];
4545 dst->u[2] = src0->u[2] | src1->u[2];
4546 dst->u[3] = src0->u[3] | src1->u[3];
4547 }
4548
4549 static void
4550 micro_xor(union tgsi_exec_channel *dst,
4551 const union tgsi_exec_channel *src0,
4552 const union tgsi_exec_channel *src1)
4553 {
4554 dst->u[0] = src0->u[0] ^ src1->u[0];
4555 dst->u[1] = src0->u[1] ^ src1->u[1];
4556 dst->u[2] = src0->u[2] ^ src1->u[2];
4557 dst->u[3] = src0->u[3] ^ src1->u[3];
4558 }
4559
4560 static void
4561 micro_mod(union tgsi_exec_channel *dst,
4562 const union tgsi_exec_channel *src0,
4563 const union tgsi_exec_channel *src1)
4564 {
4565 dst->i[0] = src1->i[0] ? src0->i[0] % src1->i[0] : ~0;
4566 dst->i[1] = src1->i[1] ? src0->i[1] % src1->i[1] : ~0;
4567 dst->i[2] = src1->i[2] ? src0->i[2] % src1->i[2] : ~0;
4568 dst->i[3] = src1->i[3] ? src0->i[3] % src1->i[3] : ~0;
4569 }
4570
4571 static void
4572 micro_f2i(union tgsi_exec_channel *dst,
4573 const union tgsi_exec_channel *src)
4574 {
4575 dst->i[0] = (int)src->f[0];
4576 dst->i[1] = (int)src->f[1];
4577 dst->i[2] = (int)src->f[2];
4578 dst->i[3] = (int)src->f[3];
4579 }
4580
4581 static void
4582 micro_fseq(union tgsi_exec_channel *dst,
4583 const union tgsi_exec_channel *src0,
4584 const union tgsi_exec_channel *src1)
4585 {
4586 dst->u[0] = src0->f[0] == src1->f[0] ? ~0 : 0;
4587 dst->u[1] = src0->f[1] == src1->f[1] ? ~0 : 0;
4588 dst->u[2] = src0->f[2] == src1->f[2] ? ~0 : 0;
4589 dst->u[3] = src0->f[3] == src1->f[3] ? ~0 : 0;
4590 }
4591
4592 static void
4593 micro_fsge(union tgsi_exec_channel *dst,
4594 const union tgsi_exec_channel *src0,
4595 const union tgsi_exec_channel *src1)
4596 {
4597 dst->u[0] = src0->f[0] >= src1->f[0] ? ~0 : 0;
4598 dst->u[1] = src0->f[1] >= src1->f[1] ? ~0 : 0;
4599 dst->u[2] = src0->f[2] >= src1->f[2] ? ~0 : 0;
4600 dst->u[3] = src0->f[3] >= src1->f[3] ? ~0 : 0;
4601 }
4602
4603 static void
4604 micro_fslt(union tgsi_exec_channel *dst,
4605 const union tgsi_exec_channel *src0,
4606 const union tgsi_exec_channel *src1)
4607 {
4608 dst->u[0] = src0->f[0] < src1->f[0] ? ~0 : 0;
4609 dst->u[1] = src0->f[1] < src1->f[1] ? ~0 : 0;
4610 dst->u[2] = src0->f[2] < src1->f[2] ? ~0 : 0;
4611 dst->u[3] = src0->f[3] < src1->f[3] ? ~0 : 0;
4612 }
4613
4614 static void
4615 micro_fsne(union tgsi_exec_channel *dst,
4616 const union tgsi_exec_channel *src0,
4617 const union tgsi_exec_channel *src1)
4618 {
4619 dst->u[0] = src0->f[0] != src1->f[0] ? ~0 : 0;
4620 dst->u[1] = src0->f[1] != src1->f[1] ? ~0 : 0;
4621 dst->u[2] = src0->f[2] != src1->f[2] ? ~0 : 0;
4622 dst->u[3] = src0->f[3] != src1->f[3] ? ~0 : 0;
4623 }
4624
4625 static void
4626 micro_idiv(union tgsi_exec_channel *dst,
4627 const union tgsi_exec_channel *src0,
4628 const union tgsi_exec_channel *src1)
4629 {
4630 dst->i[0] = src1->i[0] ? src0->i[0] / src1->i[0] : 0;
4631 dst->i[1] = src1->i[1] ? src0->i[1] / src1->i[1] : 0;
4632 dst->i[2] = src1->i[2] ? src0->i[2] / src1->i[2] : 0;
4633 dst->i[3] = src1->i[3] ? src0->i[3] / src1->i[3] : 0;
4634 }
4635
4636 static void
4637 micro_imax(union tgsi_exec_channel *dst,
4638 const union tgsi_exec_channel *src0,
4639 const union tgsi_exec_channel *src1)
4640 {
4641 dst->i[0] = src0->i[0] > src1->i[0] ? src0->i[0] : src1->i[0];
4642 dst->i[1] = src0->i[1] > src1->i[1] ? src0->i[1] : src1->i[1];
4643 dst->i[2] = src0->i[2] > src1->i[2] ? src0->i[2] : src1->i[2];
4644 dst->i[3] = src0->i[3] > src1->i[3] ? src0->i[3] : src1->i[3];
4645 }
4646
4647 static void
4648 micro_imin(union tgsi_exec_channel *dst,
4649 const union tgsi_exec_channel *src0,
4650 const union tgsi_exec_channel *src1)
4651 {
4652 dst->i[0] = src0->i[0] < src1->i[0] ? src0->i[0] : src1->i[0];
4653 dst->i[1] = src0->i[1] < src1->i[1] ? src0->i[1] : src1->i[1];
4654 dst->i[2] = src0->i[2] < src1->i[2] ? src0->i[2] : src1->i[2];
4655 dst->i[3] = src0->i[3] < src1->i[3] ? src0->i[3] : src1->i[3];
4656 }
4657
4658 static void
4659 micro_isge(union tgsi_exec_channel *dst,
4660 const union tgsi_exec_channel *src0,
4661 const union tgsi_exec_channel *src1)
4662 {
4663 dst->i[0] = src0->i[0] >= src1->i[0] ? -1 : 0;
4664 dst->i[1] = src0->i[1] >= src1->i[1] ? -1 : 0;
4665 dst->i[2] = src0->i[2] >= src1->i[2] ? -1 : 0;
4666 dst->i[3] = src0->i[3] >= src1->i[3] ? -1 : 0;
4667 }
4668
4669 static void
4670 micro_ishr(union tgsi_exec_channel *dst,
4671 const union tgsi_exec_channel *src0,
4672 const union tgsi_exec_channel *src1)
4673 {
4674 unsigned masked_count;
4675 masked_count = src1->i[0] & 0x1f;
4676 dst->i[0] = src0->i[0] >> masked_count;
4677 masked_count = src1->i[1] & 0x1f;
4678 dst->i[1] = src0->i[1] >> masked_count;
4679 masked_count = src1->i[2] & 0x1f;
4680 dst->i[2] = src0->i[2] >> masked_count;
4681 masked_count = src1->i[3] & 0x1f;
4682 dst->i[3] = src0->i[3] >> masked_count;
4683 }
4684
4685 static void
4686 micro_islt(union tgsi_exec_channel *dst,
4687 const union tgsi_exec_channel *src0,
4688 const union tgsi_exec_channel *src1)
4689 {
4690 dst->i[0] = src0->i[0] < src1->i[0] ? -1 : 0;
4691 dst->i[1] = src0->i[1] < src1->i[1] ? -1 : 0;
4692 dst->i[2] = src0->i[2] < src1->i[2] ? -1 : 0;
4693 dst->i[3] = src0->i[3] < src1->i[3] ? -1 : 0;
4694 }
4695
4696 static void
4697 micro_f2u(union tgsi_exec_channel *dst,
4698 const union tgsi_exec_channel *src)
4699 {
4700 dst->u[0] = (uint)src->f[0];
4701 dst->u[1] = (uint)src->f[1];
4702 dst->u[2] = (uint)src->f[2];
4703 dst->u[3] = (uint)src->f[3];
4704 }
4705
4706 static void
4707 micro_u2f(union tgsi_exec_channel *dst,
4708 const union tgsi_exec_channel *src)
4709 {
4710 dst->f[0] = (float)src->u[0];
4711 dst->f[1] = (float)src->u[1];
4712 dst->f[2] = (float)src->u[2];
4713 dst->f[3] = (float)src->u[3];
4714 }
4715
4716 static void
4717 micro_uadd(union tgsi_exec_channel *dst,
4718 const union tgsi_exec_channel *src0,
4719 const union tgsi_exec_channel *src1)
4720 {
4721 dst->u[0] = src0->u[0] + src1->u[0];
4722 dst->u[1] = src0->u[1] + src1->u[1];
4723 dst->u[2] = src0->u[2] + src1->u[2];
4724 dst->u[3] = src0->u[3] + src1->u[3];
4725 }
4726
4727 static void
4728 micro_udiv(union tgsi_exec_channel *dst,
4729 const union tgsi_exec_channel *src0,
4730 const union tgsi_exec_channel *src1)
4731 {
4732 dst->u[0] = src1->u[0] ? src0->u[0] / src1->u[0] : ~0u;
4733 dst->u[1] = src1->u[1] ? src0->u[1] / src1->u[1] : ~0u;
4734 dst->u[2] = src1->u[2] ? src0->u[2] / src1->u[2] : ~0u;
4735 dst->u[3] = src1->u[3] ? src0->u[3] / src1->u[3] : ~0u;
4736 }
4737
4738 static void
4739 micro_umad(union tgsi_exec_channel *dst,
4740 const union tgsi_exec_channel *src0,
4741 const union tgsi_exec_channel *src1,
4742 const union tgsi_exec_channel *src2)
4743 {
4744 dst->u[0] = src0->u[0] * src1->u[0] + src2->u[0];
4745 dst->u[1] = src0->u[1] * src1->u[1] + src2->u[1];
4746 dst->u[2] = src0->u[2] * src1->u[2] + src2->u[2];
4747 dst->u[3] = src0->u[3] * src1->u[3] + src2->u[3];
4748 }
4749
4750 static void
4751 micro_umax(union tgsi_exec_channel *dst,
4752 const union tgsi_exec_channel *src0,
4753 const union tgsi_exec_channel *src1)
4754 {
4755 dst->u[0] = src0->u[0] > src1->u[0] ? src0->u[0] : src1->u[0];
4756 dst->u[1] = src0->u[1] > src1->u[1] ? src0->u[1] : src1->u[1];
4757 dst->u[2] = src0->u[2] > src1->u[2] ? src0->u[2] : src1->u[2];
4758 dst->u[3] = src0->u[3] > src1->u[3] ? src0->u[3] : src1->u[3];
4759 }
4760
4761 static void
4762 micro_umin(union tgsi_exec_channel *dst,
4763 const union tgsi_exec_channel *src0,
4764 const union tgsi_exec_channel *src1)
4765 {
4766 dst->u[0] = src0->u[0] < src1->u[0] ? src0->u[0] : src1->u[0];
4767 dst->u[1] = src0->u[1] < src1->u[1] ? src0->u[1] : src1->u[1];
4768 dst->u[2] = src0->u[2] < src1->u[2] ? src0->u[2] : src1->u[2];
4769 dst->u[3] = src0->u[3] < src1->u[3] ? src0->u[3] : src1->u[3];
4770 }
4771
4772 static void
4773 micro_umod(union tgsi_exec_channel *dst,
4774 const union tgsi_exec_channel *src0,
4775 const union tgsi_exec_channel *src1)
4776 {
4777 dst->u[0] = src1->u[0] ? src0->u[0] % src1->u[0] : ~0u;
4778 dst->u[1] = src1->u[1] ? src0->u[1] % src1->u[1] : ~0u;
4779 dst->u[2] = src1->u[2] ? src0->u[2] % src1->u[2] : ~0u;
4780 dst->u[3] = src1->u[3] ? src0->u[3] % src1->u[3] : ~0u;
4781 }
4782
4783 static void
4784 micro_umul(union tgsi_exec_channel *dst,
4785 const union tgsi_exec_channel *src0,
4786 const union tgsi_exec_channel *src1)
4787 {
4788 dst->u[0] = src0->u[0] * src1->u[0];
4789 dst->u[1] = src0->u[1] * src1->u[1];
4790 dst->u[2] = src0->u[2] * src1->u[2];
4791 dst->u[3] = src0->u[3] * src1->u[3];
4792 }
4793
4794 static void
4795 micro_imul_hi(union tgsi_exec_channel *dst,
4796 const union tgsi_exec_channel *src0,
4797 const union tgsi_exec_channel *src1)
4798 {
4799 #define I64M(x, y) ((((int64_t)x) * ((int64_t)y)) >> 32)
4800 dst->i[0] = I64M(src0->i[0], src1->i[0]);
4801 dst->i[1] = I64M(src0->i[1], src1->i[1]);
4802 dst->i[2] = I64M(src0->i[2], src1->i[2]);
4803 dst->i[3] = I64M(src0->i[3], src1->i[3]);
4804 #undef I64M
4805 }
4806
4807 static void
4808 micro_umul_hi(union tgsi_exec_channel *dst,
4809 const union tgsi_exec_channel *src0,
4810 const union tgsi_exec_channel *src1)
4811 {
4812 #define U64M(x, y) ((((uint64_t)x) * ((uint64_t)y)) >> 32)
4813 dst->u[0] = U64M(src0->u[0], src1->u[0]);
4814 dst->u[1] = U64M(src0->u[1], src1->u[1]);
4815 dst->u[2] = U64M(src0->u[2], src1->u[2]);
4816 dst->u[3] = U64M(src0->u[3], src1->u[3]);
4817 #undef U64M
4818 }
4819
4820 static void
4821 micro_useq(union tgsi_exec_channel *dst,
4822 const union tgsi_exec_channel *src0,
4823 const union tgsi_exec_channel *src1)
4824 {
4825 dst->u[0] = src0->u[0] == src1->u[0] ? ~0 : 0;
4826 dst->u[1] = src0->u[1] == src1->u[1] ? ~0 : 0;
4827 dst->u[2] = src0->u[2] == src1->u[2] ? ~0 : 0;
4828 dst->u[3] = src0->u[3] == src1->u[3] ? ~0 : 0;
4829 }
4830
4831 static void
4832 micro_usge(union tgsi_exec_channel *dst,
4833 const union tgsi_exec_channel *src0,
4834 const union tgsi_exec_channel *src1)
4835 {
4836 dst->u[0] = src0->u[0] >= src1->u[0] ? ~0 : 0;
4837 dst->u[1] = src0->u[1] >= src1->u[1] ? ~0 : 0;
4838 dst->u[2] = src0->u[2] >= src1->u[2] ? ~0 : 0;
4839 dst->u[3] = src0->u[3] >= src1->u[3] ? ~0 : 0;
4840 }
4841
4842 static void
4843 micro_ushr(union tgsi_exec_channel *dst,
4844 const union tgsi_exec_channel *src0,
4845 const union tgsi_exec_channel *src1)
4846 {
4847 unsigned masked_count;
4848 masked_count = src1->u[0] & 0x1f;
4849 dst->u[0] = src0->u[0] >> masked_count;
4850 masked_count = src1->u[1] & 0x1f;
4851 dst->u[1] = src0->u[1] >> masked_count;
4852 masked_count = src1->u[2] & 0x1f;
4853 dst->u[2] = src0->u[2] >> masked_count;
4854 masked_count = src1->u[3] & 0x1f;
4855 dst->u[3] = src0->u[3] >> masked_count;
4856 }
4857
4858 static void
4859 micro_uslt(union tgsi_exec_channel *dst,
4860 const union tgsi_exec_channel *src0,
4861 const union tgsi_exec_channel *src1)
4862 {
4863 dst->u[0] = src0->u[0] < src1->u[0] ? ~0 : 0;
4864 dst->u[1] = src0->u[1] < src1->u[1] ? ~0 : 0;
4865 dst->u[2] = src0->u[2] < src1->u[2] ? ~0 : 0;
4866 dst->u[3] = src0->u[3] < src1->u[3] ? ~0 : 0;
4867 }
4868
4869 static void
4870 micro_usne(union tgsi_exec_channel *dst,
4871 const union tgsi_exec_channel *src0,
4872 const union tgsi_exec_channel *src1)
4873 {
4874 dst->u[0] = src0->u[0] != src1->u[0] ? ~0 : 0;
4875 dst->u[1] = src0->u[1] != src1->u[1] ? ~0 : 0;
4876 dst->u[2] = src0->u[2] != src1->u[2] ? ~0 : 0;
4877 dst->u[3] = src0->u[3] != src1->u[3] ? ~0 : 0;
4878 }
4879
4880 static void
4881 micro_uarl(union tgsi_exec_channel *dst,
4882 const union tgsi_exec_channel *src)
4883 {
4884 dst->i[0] = src->u[0];
4885 dst->i[1] = src->u[1];
4886 dst->i[2] = src->u[2];
4887 dst->i[3] = src->u[3];
4888 }
4889
4890 /**
4891 * Signed bitfield extract (i.e. sign-extend the extracted bits)
4892 */
4893 static void
4894 micro_ibfe(union tgsi_exec_channel *dst,
4895 const union tgsi_exec_channel *src0,
4896 const union tgsi_exec_channel *src1,
4897 const union tgsi_exec_channel *src2)
4898 {
4899 int i;
4900 for (i = 0; i < 4; i++) {
4901 int width = src2->i[i] & 0x1f;
4902 int offset = src1->i[i] & 0x1f;
4903 if (width == 0)
4904 dst->i[i] = 0;
4905 else if (width + offset < 32)
4906 dst->i[i] = (src0->i[i] << (32 - width - offset)) >> (32 - width);
4907 else
4908 dst->i[i] = src0->i[i] >> offset;
4909 }
4910 }
4911
4912 /**
4913 * Unsigned bitfield extract
4914 */
4915 static void
4916 micro_ubfe(union tgsi_exec_channel *dst,
4917 const union tgsi_exec_channel *src0,
4918 const union tgsi_exec_channel *src1,
4919 const union tgsi_exec_channel *src2)
4920 {
4921 int i;
4922 for (i = 0; i < 4; i++) {
4923 int width = src2->u[i] & 0x1f;
4924 int offset = src1->u[i] & 0x1f;
4925 if (width == 0)
4926 dst->u[i] = 0;
4927 else if (width + offset < 32)
4928 dst->u[i] = (src0->u[i] << (32 - width - offset)) >> (32 - width);
4929 else
4930 dst->u[i] = src0->u[i] >> offset;
4931 }
4932 }
4933
4934 /**
4935 * Bitfield insert: copy low bits from src1 into a region of src0.
4936 */
4937 static void
4938 micro_bfi(union tgsi_exec_channel *dst,
4939 const union tgsi_exec_channel *src0,
4940 const union tgsi_exec_channel *src1,
4941 const union tgsi_exec_channel *src2,
4942 const union tgsi_exec_channel *src3)
4943 {
4944 int i;
4945 for (i = 0; i < 4; i++) {
4946 int width = src3->u[i] & 0x1f;
4947 int offset = src2->u[i] & 0x1f;
4948 int bitmask = ((1 << width) - 1) << offset;
4949 dst->u[i] = ((src1->u[i] << offset) & bitmask) | (src0->u[i] & ~bitmask);
4950 }
4951 }
4952
4953 static void
4954 micro_brev(union tgsi_exec_channel *dst,
4955 const union tgsi_exec_channel *src)
4956 {
4957 dst->u[0] = util_bitreverse(src->u[0]);
4958 dst->u[1] = util_bitreverse(src->u[1]);
4959 dst->u[2] = util_bitreverse(src->u[2]);
4960 dst->u[3] = util_bitreverse(src->u[3]);
4961 }
4962
4963 static void
4964 micro_popc(union tgsi_exec_channel *dst,
4965 const union tgsi_exec_channel *src)
4966 {
4967 dst->u[0] = util_bitcount(src->u[0]);
4968 dst->u[1] = util_bitcount(src->u[1]);
4969 dst->u[2] = util_bitcount(src->u[2]);
4970 dst->u[3] = util_bitcount(src->u[3]);
4971 }
4972
4973 static void
4974 micro_lsb(union tgsi_exec_channel *dst,
4975 const union tgsi_exec_channel *src)
4976 {
4977 dst->i[0] = ffs(src->u[0]) - 1;
4978 dst->i[1] = ffs(src->u[1]) - 1;
4979 dst->i[2] = ffs(src->u[2]) - 1;
4980 dst->i[3] = ffs(src->u[3]) - 1;
4981 }
4982
4983 static void
4984 micro_imsb(union tgsi_exec_channel *dst,
4985 const union tgsi_exec_channel *src)
4986 {
4987 dst->i[0] = util_last_bit_signed(src->i[0]) - 1;
4988 dst->i[1] = util_last_bit_signed(src->i[1]) - 1;
4989 dst->i[2] = util_last_bit_signed(src->i[2]) - 1;
4990 dst->i[3] = util_last_bit_signed(src->i[3]) - 1;
4991 }
4992
4993 static void
4994 micro_umsb(union tgsi_exec_channel *dst,
4995 const union tgsi_exec_channel *src)
4996 {
4997 dst->i[0] = util_last_bit(src->u[0]) - 1;
4998 dst->i[1] = util_last_bit(src->u[1]) - 1;
4999 dst->i[2] = util_last_bit(src->u[2]) - 1;
5000 dst->i[3] = util_last_bit(src->u[3]) - 1;
5001 }
5002
5003 /**
5004 * Execute a TGSI instruction.
5005 * Returns TRUE if a barrier instruction is hit,
5006 * otherwise FALSE.
5007 */
5008 static boolean
5009 exec_instruction(
5010 struct tgsi_exec_machine *mach,
5011 const struct tgsi_full_instruction *inst,
5012 int *pc )
5013 {
5014 union tgsi_exec_channel r[10];
5015
5016 (*pc)++;
5017
5018 switch (inst->Instruction.Opcode) {
5019 case TGSI_OPCODE_ARL:
5020 exec_vector_unary(mach, inst, micro_arl, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_FLOAT);
5021 break;
5022
5023 case TGSI_OPCODE_MOV:
5024 exec_vector_unary(mach, inst, micro_mov, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_FLOAT);
5025 break;
5026
5027 case TGSI_OPCODE_LIT:
5028 exec_lit(mach, inst);
5029 break;
5030
5031 case TGSI_OPCODE_RCP:
5032 exec_scalar_unary(mach, inst, micro_rcp, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5033 break;
5034
5035 case TGSI_OPCODE_RSQ:
5036 exec_scalar_unary(mach, inst, micro_rsq, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5037 break;
5038
5039 case TGSI_OPCODE_EXP:
5040 exec_exp(mach, inst);
5041 break;
5042
5043 case TGSI_OPCODE_LOG:
5044 exec_log(mach, inst);
5045 break;
5046
5047 case TGSI_OPCODE_MUL:
5048 exec_vector_binary(mach, inst, micro_mul, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5049 break;
5050
5051 case TGSI_OPCODE_ADD:
5052 exec_vector_binary(mach, inst, micro_add, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5053 break;
5054
5055 case TGSI_OPCODE_DP3:
5056 exec_dp3(mach, inst);
5057 break;
5058
5059 case TGSI_OPCODE_DP4:
5060 exec_dp4(mach, inst);
5061 break;
5062
5063 case TGSI_OPCODE_DST:
5064 exec_dst(mach, inst);
5065 break;
5066
5067 case TGSI_OPCODE_MIN:
5068 exec_vector_binary(mach, inst, micro_min, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5069 break;
5070
5071 case TGSI_OPCODE_MAX:
5072 exec_vector_binary(mach, inst, micro_max, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5073 break;
5074
5075 case TGSI_OPCODE_SLT:
5076 exec_vector_binary(mach, inst, micro_slt, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5077 break;
5078
5079 case TGSI_OPCODE_SGE:
5080 exec_vector_binary(mach, inst, micro_sge, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5081 break;
5082
5083 case TGSI_OPCODE_MAD:
5084 exec_vector_trinary(mach, inst, micro_mad, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5085 break;
5086
5087 case TGSI_OPCODE_LRP:
5088 exec_vector_trinary(mach, inst, micro_lrp, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5089 break;
5090
5091 case TGSI_OPCODE_SQRT:
5092 exec_scalar_unary(mach, inst, micro_sqrt, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5093 break;
5094
5095 case TGSI_OPCODE_FRC:
5096 exec_vector_unary(mach, inst, micro_frc, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5097 break;
5098
5099 case TGSI_OPCODE_FLR:
5100 exec_vector_unary(mach, inst, micro_flr, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5101 break;
5102
5103 case TGSI_OPCODE_ROUND:
5104 exec_vector_unary(mach, inst, micro_rnd, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5105 break;
5106
5107 case TGSI_OPCODE_EX2:
5108 exec_scalar_unary(mach, inst, micro_exp2, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5109 break;
5110
5111 case TGSI_OPCODE_LG2:
5112 exec_scalar_unary(mach, inst, micro_lg2, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5113 break;
5114
5115 case TGSI_OPCODE_POW:
5116 exec_scalar_binary(mach, inst, micro_pow, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5117 break;
5118
5119 case TGSI_OPCODE_LDEXP:
5120 exec_vector_binary(mach, inst, micro_ldexp, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5121 break;
5122
5123 case TGSI_OPCODE_COS:
5124 exec_scalar_unary(mach, inst, micro_cos, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5125 break;
5126
5127 case TGSI_OPCODE_DDX:
5128 exec_vector_unary(mach, inst, micro_ddx, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5129 break;
5130
5131 case TGSI_OPCODE_DDY:
5132 exec_vector_unary(mach, inst, micro_ddy, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5133 break;
5134
5135 case TGSI_OPCODE_KILL:
5136 exec_kill (mach);
5137 break;
5138
5139 case TGSI_OPCODE_KILL_IF:
5140 exec_kill_if (mach, inst);
5141 break;
5142
5143 case TGSI_OPCODE_PK2H:
5144 exec_pk2h(mach, inst);
5145 break;
5146
5147 case TGSI_OPCODE_PK2US:
5148 assert (0);
5149 break;
5150
5151 case TGSI_OPCODE_PK4B:
5152 assert (0);
5153 break;
5154
5155 case TGSI_OPCODE_PK4UB:
5156 assert (0);
5157 break;
5158
5159 case TGSI_OPCODE_SEQ:
5160 exec_vector_binary(mach, inst, micro_seq, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5161 break;
5162
5163 case TGSI_OPCODE_SGT:
5164 exec_vector_binary(mach, inst, micro_sgt, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5165 break;
5166
5167 case TGSI_OPCODE_SIN:
5168 exec_scalar_unary(mach, inst, micro_sin, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5169 break;
5170
5171 case TGSI_OPCODE_SLE:
5172 exec_vector_binary(mach, inst, micro_sle, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5173 break;
5174
5175 case TGSI_OPCODE_SNE:
5176 exec_vector_binary(mach, inst, micro_sne, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5177 break;
5178
5179 case TGSI_OPCODE_TEX:
5180 /* simple texture lookup */
5181 /* src[0] = texcoord */
5182 /* src[1] = sampler unit */
5183 exec_tex(mach, inst, TEX_MODIFIER_NONE, 1);
5184 break;
5185
5186 case TGSI_OPCODE_TXB:
5187 /* Texture lookup with lod bias */
5188 /* src[0] = texcoord (src[0].w = LOD bias) */
5189 /* src[1] = sampler unit */
5190 exec_tex(mach, inst, TEX_MODIFIER_LOD_BIAS, 1);
5191 break;
5192
5193 case TGSI_OPCODE_TXD:
5194 /* Texture lookup with explict partial derivatives */
5195 /* src[0] = texcoord */
5196 /* src[1] = d[strq]/dx */
5197 /* src[2] = d[strq]/dy */
5198 /* src[3] = sampler unit */
5199 exec_txd(mach, inst);
5200 break;
5201
5202 case TGSI_OPCODE_TXL:
5203 /* Texture lookup with explit LOD */
5204 /* src[0] = texcoord (src[0].w = LOD) */
5205 /* src[1] = sampler unit */
5206 exec_tex(mach, inst, TEX_MODIFIER_EXPLICIT_LOD, 1);
5207 break;
5208
5209 case TGSI_OPCODE_TXP:
5210 /* Texture lookup with projection */
5211 /* src[0] = texcoord (src[0].w = projection) */
5212 /* src[1] = sampler unit */
5213 exec_tex(mach, inst, TEX_MODIFIER_PROJECTED, 1);
5214 break;
5215
5216 case TGSI_OPCODE_TG4:
5217 /* src[0] = texcoord */
5218 /* src[1] = component */
5219 /* src[2] = sampler unit */
5220 exec_tex(mach, inst, TEX_MODIFIER_GATHER, 2);
5221 break;
5222
5223 case TGSI_OPCODE_LODQ:
5224 /* src[0] = texcoord */
5225 /* src[1] = sampler unit */
5226 exec_lodq(mach, inst);
5227 break;
5228
5229 case TGSI_OPCODE_UP2H:
5230 exec_up2h(mach, inst);
5231 break;
5232
5233 case TGSI_OPCODE_UP2US:
5234 assert (0);
5235 break;
5236
5237 case TGSI_OPCODE_UP4B:
5238 assert (0);
5239 break;
5240
5241 case TGSI_OPCODE_UP4UB:
5242 assert (0);
5243 break;
5244
5245 case TGSI_OPCODE_ARR:
5246 exec_vector_unary(mach, inst, micro_arr, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_FLOAT);
5247 break;
5248
5249 case TGSI_OPCODE_CAL:
5250 /* skip the call if no execution channels are enabled */
5251 if (mach->ExecMask) {
5252 /* do the call */
5253
5254 /* First, record the depths of the execution stacks.
5255 * This is important for deeply nested/looped return statements.
5256 * We have to unwind the stacks by the correct amount. For a
5257 * real code generator, we could determine the number of entries
5258 * to pop off each stack with simple static analysis and avoid
5259 * implementing this data structure at run time.
5260 */
5261 mach->CallStack[mach->CallStackTop].CondStackTop = mach->CondStackTop;
5262 mach->CallStack[mach->CallStackTop].LoopStackTop = mach->LoopStackTop;
5263 mach->CallStack[mach->CallStackTop].ContStackTop = mach->ContStackTop;
5264 mach->CallStack[mach->CallStackTop].SwitchStackTop = mach->SwitchStackTop;
5265 mach->CallStack[mach->CallStackTop].BreakStackTop = mach->BreakStackTop;
5266 /* note that PC was already incremented above */
5267 mach->CallStack[mach->CallStackTop].ReturnAddr = *pc;
5268
5269 mach->CallStackTop++;
5270
5271 /* Second, push the Cond, Loop, Cont, Func stacks */
5272 assert(mach->CondStackTop < TGSI_EXEC_MAX_COND_NESTING);
5273 assert(mach->LoopStackTop < TGSI_EXEC_MAX_LOOP_NESTING);
5274 assert(mach->ContStackTop < TGSI_EXEC_MAX_LOOP_NESTING);
5275 assert(mach->SwitchStackTop < TGSI_EXEC_MAX_SWITCH_NESTING);
5276 assert(mach->BreakStackTop < TGSI_EXEC_MAX_BREAK_STACK);
5277 assert(mach->FuncStackTop < TGSI_EXEC_MAX_CALL_NESTING);
5278
5279 mach->CondStack[mach->CondStackTop++] = mach->CondMask;
5280 mach->LoopStack[mach->LoopStackTop++] = mach->LoopMask;
5281 mach->ContStack[mach->ContStackTop++] = mach->ContMask;
5282 mach->SwitchStack[mach->SwitchStackTop++] = mach->Switch;
5283 mach->BreakStack[mach->BreakStackTop++] = mach->BreakType;
5284 mach->FuncStack[mach->FuncStackTop++] = mach->FuncMask;
5285
5286 /* Finally, jump to the subroutine. The label is a pointer
5287 * (an instruction number) to the BGNSUB instruction.
5288 */
5289 *pc = inst->Label.Label;
5290 assert(mach->Instructions[*pc].Instruction.Opcode
5291 == TGSI_OPCODE_BGNSUB);
5292 }
5293 break;
5294
5295 case TGSI_OPCODE_RET:
5296 mach->FuncMask &= ~mach->ExecMask;
5297 UPDATE_EXEC_MASK(mach);
5298
5299 if (mach->FuncMask == 0x0) {
5300 /* really return now (otherwise, keep executing */
5301
5302 if (mach->CallStackTop == 0) {
5303 /* returning from main() */
5304 mach->CondStackTop = 0;
5305 mach->LoopStackTop = 0;
5306 mach->ContStackTop = 0;
5307 mach->LoopLabelStackTop = 0;
5308 mach->SwitchStackTop = 0;
5309 mach->BreakStackTop = 0;
5310 *pc = -1;
5311 return FALSE;
5312 }
5313
5314 assert(mach->CallStackTop > 0);
5315 mach->CallStackTop--;
5316
5317 mach->CondStackTop = mach->CallStack[mach->CallStackTop].CondStackTop;
5318 mach->CondMask = mach->CondStack[mach->CondStackTop];
5319
5320 mach->LoopStackTop = mach->CallStack[mach->CallStackTop].LoopStackTop;
5321 mach->LoopMask = mach->LoopStack[mach->LoopStackTop];
5322
5323 mach->ContStackTop = mach->CallStack[mach->CallStackTop].ContStackTop;
5324 mach->ContMask = mach->ContStack[mach->ContStackTop];
5325
5326 mach->SwitchStackTop = mach->CallStack[mach->CallStackTop].SwitchStackTop;
5327 mach->Switch = mach->SwitchStack[mach->SwitchStackTop];
5328
5329 mach->BreakStackTop = mach->CallStack[mach->CallStackTop].BreakStackTop;
5330 mach->BreakType = mach->BreakStack[mach->BreakStackTop];
5331
5332 assert(mach->FuncStackTop > 0);
5333 mach->FuncMask = mach->FuncStack[--mach->FuncStackTop];
5334
5335 *pc = mach->CallStack[mach->CallStackTop].ReturnAddr;
5336
5337 UPDATE_EXEC_MASK(mach);
5338 }
5339 break;
5340
5341 case TGSI_OPCODE_SSG:
5342 exec_vector_unary(mach, inst, micro_sgn, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5343 break;
5344
5345 case TGSI_OPCODE_CMP:
5346 exec_vector_trinary(mach, inst, micro_cmp, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5347 break;
5348
5349 case TGSI_OPCODE_DIV:
5350 exec_vector_binary(mach, inst, micro_div, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5351 break;
5352
5353 case TGSI_OPCODE_DP2:
5354 exec_dp2(mach, inst);
5355 break;
5356
5357 case TGSI_OPCODE_IF:
5358 /* push CondMask */
5359 assert(mach->CondStackTop < TGSI_EXEC_MAX_COND_NESTING);
5360 mach->CondStack[mach->CondStackTop++] = mach->CondMask;
5361 FETCH( &r[0], 0, TGSI_CHAN_X );
5362 /* update CondMask */
5363 if( ! r[0].f[0] ) {
5364 mach->CondMask &= ~0x1;
5365 }
5366 if( ! r[0].f[1] ) {
5367 mach->CondMask &= ~0x2;
5368 }
5369 if( ! r[0].f[2] ) {
5370 mach->CondMask &= ~0x4;
5371 }
5372 if( ! r[0].f[3] ) {
5373 mach->CondMask &= ~0x8;
5374 }
5375 UPDATE_EXEC_MASK(mach);
5376 /* Todo: If CondMask==0, jump to ELSE */
5377 break;
5378
5379 case TGSI_OPCODE_UIF:
5380 /* push CondMask */
5381 assert(mach->CondStackTop < TGSI_EXEC_MAX_COND_NESTING);
5382 mach->CondStack[mach->CondStackTop++] = mach->CondMask;
5383 IFETCH( &r[0], 0, TGSI_CHAN_X );
5384 /* update CondMask */
5385 if( ! r[0].u[0] ) {
5386 mach->CondMask &= ~0x1;
5387 }
5388 if( ! r[0].u[1] ) {
5389 mach->CondMask &= ~0x2;
5390 }
5391 if( ! r[0].u[2] ) {
5392 mach->CondMask &= ~0x4;
5393 }
5394 if( ! r[0].u[3] ) {
5395 mach->CondMask &= ~0x8;
5396 }
5397 UPDATE_EXEC_MASK(mach);
5398 /* Todo: If CondMask==0, jump to ELSE */
5399 break;
5400
5401 case TGSI_OPCODE_ELSE:
5402 /* invert CondMask wrt previous mask */
5403 {
5404 uint prevMask;
5405 assert(mach->CondStackTop > 0);
5406 prevMask = mach->CondStack[mach->CondStackTop - 1];
5407 mach->CondMask = ~mach->CondMask & prevMask;
5408 UPDATE_EXEC_MASK(mach);
5409 /* Todo: If CondMask==0, jump to ENDIF */
5410 }
5411 break;
5412
5413 case TGSI_OPCODE_ENDIF:
5414 /* pop CondMask */
5415 assert(mach->CondStackTop > 0);
5416 mach->CondMask = mach->CondStack[--mach->CondStackTop];
5417 UPDATE_EXEC_MASK(mach);
5418 break;
5419
5420 case TGSI_OPCODE_END:
5421 /* make sure we end primitives which haven't
5422 * been explicitly emitted */
5423 conditional_emit_primitive(mach);
5424 /* halt execution */
5425 *pc = -1;
5426 break;
5427
5428 case TGSI_OPCODE_CEIL:
5429 exec_vector_unary(mach, inst, micro_ceil, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5430 break;
5431
5432 case TGSI_OPCODE_I2F:
5433 exec_vector_unary(mach, inst, micro_i2f, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_INT);
5434 break;
5435
5436 case TGSI_OPCODE_NOT:
5437 exec_vector_unary(mach, inst, micro_not, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5438 break;
5439
5440 case TGSI_OPCODE_TRUNC:
5441 exec_vector_unary(mach, inst, micro_trunc, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
5442 break;
5443
5444 case TGSI_OPCODE_SHL:
5445 exec_vector_binary(mach, inst, micro_shl, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5446 break;
5447
5448 case TGSI_OPCODE_AND:
5449 exec_vector_binary(mach, inst, micro_and, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5450 break;
5451
5452 case TGSI_OPCODE_OR:
5453 exec_vector_binary(mach, inst, micro_or, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5454 break;
5455
5456 case TGSI_OPCODE_MOD:
5457 exec_vector_binary(mach, inst, micro_mod, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
5458 break;
5459
5460 case TGSI_OPCODE_XOR:
5461 exec_vector_binary(mach, inst, micro_xor, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5462 break;
5463
5464 case TGSI_OPCODE_TXF:
5465 exec_txf(mach, inst);
5466 break;
5467
5468 case TGSI_OPCODE_TXQ:
5469 exec_txq(mach, inst);
5470 break;
5471
5472 case TGSI_OPCODE_EMIT:
5473 emit_vertex(mach);
5474 break;
5475
5476 case TGSI_OPCODE_ENDPRIM:
5477 emit_primitive(mach);
5478 break;
5479
5480 case TGSI_OPCODE_BGNLOOP:
5481 /* push LoopMask and ContMasks */
5482 assert(mach->LoopStackTop < TGSI_EXEC_MAX_LOOP_NESTING);
5483 assert(mach->ContStackTop < TGSI_EXEC_MAX_LOOP_NESTING);
5484 assert(mach->LoopLabelStackTop < TGSI_EXEC_MAX_LOOP_NESTING);
5485 assert(mach->BreakStackTop < TGSI_EXEC_MAX_BREAK_STACK);
5486
5487 mach->LoopStack[mach->LoopStackTop++] = mach->LoopMask;
5488 mach->ContStack[mach->ContStackTop++] = mach->ContMask;
5489 mach->LoopLabelStack[mach->LoopLabelStackTop++] = *pc - 1;
5490 mach->BreakStack[mach->BreakStackTop++] = mach->BreakType;
5491 mach->BreakType = TGSI_EXEC_BREAK_INSIDE_LOOP;
5492 break;
5493
5494 case TGSI_OPCODE_ENDLOOP:
5495 /* Restore ContMask, but don't pop */
5496 assert(mach->ContStackTop > 0);
5497 mach->ContMask = mach->ContStack[mach->ContStackTop - 1];
5498 UPDATE_EXEC_MASK(mach);
5499 if (mach->ExecMask) {
5500 /* repeat loop: jump to instruction just past BGNLOOP */
5501 assert(mach->LoopLabelStackTop > 0);
5502 *pc = mach->LoopLabelStack[mach->LoopLabelStackTop - 1] + 1;
5503 }
5504 else {
5505 /* exit loop: pop LoopMask */
5506 assert(mach->LoopStackTop > 0);
5507 mach->LoopMask = mach->LoopStack[--mach->LoopStackTop];
5508 /* pop ContMask */
5509 assert(mach->ContStackTop > 0);
5510 mach->ContMask = mach->ContStack[--mach->ContStackTop];
5511 assert(mach->LoopLabelStackTop > 0);
5512 --mach->LoopLabelStackTop;
5513
5514 mach->BreakType = mach->BreakStack[--mach->BreakStackTop];
5515 }
5516 UPDATE_EXEC_MASK(mach);
5517 break;
5518
5519 case TGSI_OPCODE_BRK:
5520 exec_break(mach);
5521 break;
5522
5523 case TGSI_OPCODE_CONT:
5524 /* turn off cont channels for each enabled exec channel */
5525 mach->ContMask &= ~mach->ExecMask;
5526 /* Todo: if mach->LoopMask == 0, jump to end of loop */
5527 UPDATE_EXEC_MASK(mach);
5528 break;
5529
5530 case TGSI_OPCODE_BGNSUB:
5531 /* no-op */
5532 break;
5533
5534 case TGSI_OPCODE_ENDSUB:
5535 /*
5536 * XXX: This really should be a no-op. We should never reach this opcode.
5537 */
5538
5539 assert(mach->CallStackTop > 0);
5540 mach->CallStackTop--;
5541
5542 mach->CondStackTop = mach->CallStack[mach->CallStackTop].CondStackTop;
5543 mach->CondMask = mach->CondStack[mach->CondStackTop];
5544
5545 mach->LoopStackTop = mach->CallStack[mach->CallStackTop].LoopStackTop;
5546 mach->LoopMask = mach->LoopStack[mach->LoopStackTop];
5547
5548 mach->ContStackTop = mach->CallStack[mach->CallStackTop].ContStackTop;
5549 mach->ContMask = mach->ContStack[mach->ContStackTop];
5550
5551 mach->SwitchStackTop = mach->CallStack[mach->CallStackTop].SwitchStackTop;
5552 mach->Switch = mach->SwitchStack[mach->SwitchStackTop];
5553
5554 mach->BreakStackTop = mach->CallStack[mach->CallStackTop].BreakStackTop;
5555 mach->BreakType = mach->BreakStack[mach->BreakStackTop];
5556
5557 assert(mach->FuncStackTop > 0);
5558 mach->FuncMask = mach->FuncStack[--mach->FuncStackTop];
5559
5560 *pc = mach->CallStack[mach->CallStackTop].ReturnAddr;
5561
5562 UPDATE_EXEC_MASK(mach);
5563 break;
5564
5565 case TGSI_OPCODE_NOP:
5566 break;
5567
5568 case TGSI_OPCODE_F2I:
5569 exec_vector_unary(mach, inst, micro_f2i, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_FLOAT);
5570 break;
5571
5572 case TGSI_OPCODE_FSEQ:
5573 exec_vector_binary(mach, inst, micro_fseq, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_FLOAT);
5574 break;
5575
5576 case TGSI_OPCODE_FSGE:
5577 exec_vector_binary(mach, inst, micro_fsge, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_FLOAT);
5578 break;
5579
5580 case TGSI_OPCODE_FSLT:
5581 exec_vector_binary(mach, inst, micro_fslt, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_FLOAT);
5582 break;
5583
5584 case TGSI_OPCODE_FSNE:
5585 exec_vector_binary(mach, inst, micro_fsne, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_FLOAT);
5586 break;
5587
5588 case TGSI_OPCODE_IDIV:
5589 exec_vector_binary(mach, inst, micro_idiv, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
5590 break;
5591
5592 case TGSI_OPCODE_IMAX:
5593 exec_vector_binary(mach, inst, micro_imax, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
5594 break;
5595
5596 case TGSI_OPCODE_IMIN:
5597 exec_vector_binary(mach, inst, micro_imin, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
5598 break;
5599
5600 case TGSI_OPCODE_INEG:
5601 exec_vector_unary(mach, inst, micro_ineg, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
5602 break;
5603
5604 case TGSI_OPCODE_ISGE:
5605 exec_vector_binary(mach, inst, micro_isge, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
5606 break;
5607
5608 case TGSI_OPCODE_ISHR:
5609 exec_vector_binary(mach, inst, micro_ishr, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
5610 break;
5611
5612 case TGSI_OPCODE_ISLT:
5613 exec_vector_binary(mach, inst, micro_islt, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
5614 break;
5615
5616 case TGSI_OPCODE_F2U:
5617 exec_vector_unary(mach, inst, micro_f2u, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_FLOAT);
5618 break;
5619
5620 case TGSI_OPCODE_U2F:
5621 exec_vector_unary(mach, inst, micro_u2f, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_UINT);
5622 break;
5623
5624 case TGSI_OPCODE_UADD:
5625 exec_vector_binary(mach, inst, micro_uadd, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
5626 break;
5627
5628 case TGSI_OPCODE_UDIV:
5629 exec_vector_binary(mach, inst, micro_udiv, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5630 break;
5631
5632 case TGSI_OPCODE_UMAD:
5633 exec_vector_trinary(mach, inst, micro_umad, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5634 break;
5635
5636 case TGSI_OPCODE_UMAX:
5637 exec_vector_binary(mach, inst, micro_umax, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5638 break;
5639
5640 case TGSI_OPCODE_UMIN:
5641 exec_vector_binary(mach, inst, micro_umin, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5642 break;
5643
5644 case TGSI_OPCODE_UMOD:
5645 exec_vector_binary(mach, inst, micro_umod, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5646 break;
5647
5648 case TGSI_OPCODE_UMUL:
5649 exec_vector_binary(mach, inst, micro_umul, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5650 break;
5651
5652 case TGSI_OPCODE_IMUL_HI:
5653 exec_vector_binary(mach, inst, micro_imul_hi, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
5654 break;
5655
5656 case TGSI_OPCODE_UMUL_HI:
5657 exec_vector_binary(mach, inst, micro_umul_hi, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5658 break;
5659
5660 case TGSI_OPCODE_USEQ:
5661 exec_vector_binary(mach, inst, micro_useq, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5662 break;
5663
5664 case TGSI_OPCODE_USGE:
5665 exec_vector_binary(mach, inst, micro_usge, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5666 break;
5667
5668 case TGSI_OPCODE_USHR:
5669 exec_vector_binary(mach, inst, micro_ushr, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5670 break;
5671
5672 case TGSI_OPCODE_USLT:
5673 exec_vector_binary(mach, inst, micro_uslt, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5674 break;
5675
5676 case TGSI_OPCODE_USNE:
5677 exec_vector_binary(mach, inst, micro_usne, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5678 break;
5679
5680 case TGSI_OPCODE_SWITCH:
5681 exec_switch(mach, inst);
5682 break;
5683
5684 case TGSI_OPCODE_CASE:
5685 exec_case(mach, inst);
5686 break;
5687
5688 case TGSI_OPCODE_DEFAULT:
5689 exec_default(mach);
5690 break;
5691
5692 case TGSI_OPCODE_ENDSWITCH:
5693 exec_endswitch(mach);
5694 break;
5695
5696 case TGSI_OPCODE_SAMPLE_I:
5697 exec_txf(mach, inst);
5698 break;
5699
5700 case TGSI_OPCODE_SAMPLE_I_MS:
5701 exec_txf(mach, inst);
5702 break;
5703
5704 case TGSI_OPCODE_SAMPLE:
5705 exec_sample(mach, inst, TEX_MODIFIER_NONE, FALSE);
5706 break;
5707
5708 case TGSI_OPCODE_SAMPLE_B:
5709 exec_sample(mach, inst, TEX_MODIFIER_LOD_BIAS, FALSE);
5710 break;
5711
5712 case TGSI_OPCODE_SAMPLE_C:
5713 exec_sample(mach, inst, TEX_MODIFIER_NONE, TRUE);
5714 break;
5715
5716 case TGSI_OPCODE_SAMPLE_C_LZ:
5717 exec_sample(mach, inst, TEX_MODIFIER_LEVEL_ZERO, TRUE);
5718 break;
5719
5720 case TGSI_OPCODE_SAMPLE_D:
5721 exec_sample_d(mach, inst);
5722 break;
5723
5724 case TGSI_OPCODE_SAMPLE_L:
5725 exec_sample(mach, inst, TEX_MODIFIER_EXPLICIT_LOD, FALSE);
5726 break;
5727
5728 case TGSI_OPCODE_GATHER4:
5729 exec_sample(mach, inst, TEX_MODIFIER_GATHER, FALSE);
5730 break;
5731
5732 case TGSI_OPCODE_SVIEWINFO:
5733 exec_txq(mach, inst);
5734 break;
5735
5736 case TGSI_OPCODE_SAMPLE_POS:
5737 assert(0);
5738 break;
5739
5740 case TGSI_OPCODE_SAMPLE_INFO:
5741 assert(0);
5742 break;
5743
5744 case TGSI_OPCODE_LOD:
5745 exec_lodq(mach, inst);
5746 break;
5747
5748 case TGSI_OPCODE_UARL:
5749 exec_vector_unary(mach, inst, micro_uarl, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_UINT);
5750 break;
5751
5752 case TGSI_OPCODE_UCMP:
5753 exec_ucmp(mach, inst);
5754 break;
5755
5756 case TGSI_OPCODE_IABS:
5757 exec_vector_unary(mach, inst, micro_iabs, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
5758 break;
5759
5760 case TGSI_OPCODE_ISSG:
5761 exec_vector_unary(mach, inst, micro_isgn, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
5762 break;
5763
5764 case TGSI_OPCODE_TEX2:
5765 /* simple texture lookup */
5766 /* src[0] = texcoord */
5767 /* src[1] = compare */
5768 /* src[2] = sampler unit */
5769 exec_tex(mach, inst, TEX_MODIFIER_NONE, 2);
5770 break;
5771 case TGSI_OPCODE_TXB2:
5772 /* simple texture lookup */
5773 /* src[0] = texcoord */
5774 /* src[1] = bias */
5775 /* src[2] = sampler unit */
5776 exec_tex(mach, inst, TEX_MODIFIER_LOD_BIAS, 2);
5777 break;
5778 case TGSI_OPCODE_TXL2:
5779 /* simple texture lookup */
5780 /* src[0] = texcoord */
5781 /* src[1] = lod */
5782 /* src[2] = sampler unit */
5783 exec_tex(mach, inst, TEX_MODIFIER_EXPLICIT_LOD, 2);
5784 break;
5785
5786 case TGSI_OPCODE_IBFE:
5787 exec_vector_trinary(mach, inst, micro_ibfe, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
5788 break;
5789 case TGSI_OPCODE_UBFE:
5790 exec_vector_trinary(mach, inst, micro_ubfe, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5791 break;
5792 case TGSI_OPCODE_BFI:
5793 exec_vector_quaternary(mach, inst, micro_bfi, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5794 break;
5795 case TGSI_OPCODE_BREV:
5796 exec_vector_unary(mach, inst, micro_brev, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5797 break;
5798 case TGSI_OPCODE_POPC:
5799 exec_vector_unary(mach, inst, micro_popc, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
5800 break;
5801 case TGSI_OPCODE_LSB:
5802 exec_vector_unary(mach, inst, micro_lsb, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_UINT);
5803 break;
5804 case TGSI_OPCODE_IMSB:
5805 exec_vector_unary(mach, inst, micro_imsb, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
5806 break;
5807 case TGSI_OPCODE_UMSB:
5808 exec_vector_unary(mach, inst, micro_umsb, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_UINT);
5809 break;
5810
5811 case TGSI_OPCODE_F2D:
5812 exec_t_2_64(mach, inst, micro_f2d, TGSI_EXEC_DATA_FLOAT);
5813 break;
5814
5815 case TGSI_OPCODE_D2F:
5816 exec_64_2_t(mach, inst, micro_d2f, TGSI_EXEC_DATA_FLOAT);
5817 break;
5818
5819 case TGSI_OPCODE_DABS:
5820 exec_double_unary(mach, inst, micro_dabs);
5821 break;
5822
5823 case TGSI_OPCODE_DNEG:
5824 exec_double_unary(mach, inst, micro_dneg);
5825 break;
5826
5827 case TGSI_OPCODE_DADD:
5828 exec_double_binary(mach, inst, micro_dadd, TGSI_EXEC_DATA_DOUBLE);
5829 break;
5830
5831 case TGSI_OPCODE_DDIV:
5832 exec_double_binary(mach, inst, micro_ddiv, TGSI_EXEC_DATA_DOUBLE);
5833 break;
5834
5835 case TGSI_OPCODE_DMUL:
5836 exec_double_binary(mach, inst, micro_dmul, TGSI_EXEC_DATA_DOUBLE);
5837 break;
5838
5839 case TGSI_OPCODE_DMAX:
5840 exec_double_binary(mach, inst, micro_dmax, TGSI_EXEC_DATA_DOUBLE);
5841 break;
5842
5843 case TGSI_OPCODE_DMIN:
5844 exec_double_binary(mach, inst, micro_dmin, TGSI_EXEC_DATA_DOUBLE);
5845 break;
5846
5847 case TGSI_OPCODE_DSLT:
5848 exec_double_binary(mach, inst, micro_dslt, TGSI_EXEC_DATA_UINT);
5849 break;
5850
5851 case TGSI_OPCODE_DSGE:
5852 exec_double_binary(mach, inst, micro_dsge, TGSI_EXEC_DATA_UINT);
5853 break;
5854
5855 case TGSI_OPCODE_DSEQ:
5856 exec_double_binary(mach, inst, micro_dseq, TGSI_EXEC_DATA_UINT);
5857 break;
5858
5859 case TGSI_OPCODE_DSNE:
5860 exec_double_binary(mach, inst, micro_dsne, TGSI_EXEC_DATA_UINT);
5861 break;
5862
5863 case TGSI_OPCODE_DRCP:
5864 exec_double_unary(mach, inst, micro_drcp);
5865 break;
5866
5867 case TGSI_OPCODE_DSQRT:
5868 exec_double_unary(mach, inst, micro_dsqrt);
5869 break;
5870
5871 case TGSI_OPCODE_DRSQ:
5872 exec_double_unary(mach, inst, micro_drsq);
5873 break;
5874
5875 case TGSI_OPCODE_DMAD:
5876 exec_double_trinary(mach, inst, micro_dmad);
5877 break;
5878
5879 case TGSI_OPCODE_DFRAC:
5880 exec_double_unary(mach, inst, micro_dfrac);
5881 break;
5882
5883 case TGSI_OPCODE_DLDEXP:
5884 exec_dldexp(mach, inst);
5885 break;
5886
5887 case TGSI_OPCODE_DFRACEXP:
5888 exec_dfracexp(mach, inst);
5889 break;
5890
5891 case TGSI_OPCODE_I2D:
5892 exec_t_2_64(mach, inst, micro_i2d, TGSI_EXEC_DATA_INT);
5893 break;
5894
5895 case TGSI_OPCODE_D2I:
5896 exec_64_2_t(mach, inst, micro_d2i, TGSI_EXEC_DATA_INT);
5897 break;
5898
5899 case TGSI_OPCODE_U2D:
5900 exec_t_2_64(mach, inst, micro_u2d, TGSI_EXEC_DATA_UINT);
5901 break;
5902
5903 case TGSI_OPCODE_D2U:
5904 exec_64_2_t(mach, inst, micro_d2u, TGSI_EXEC_DATA_INT);
5905 break;
5906
5907 case TGSI_OPCODE_LOAD:
5908 exec_load(mach, inst);
5909 break;
5910
5911 case TGSI_OPCODE_STORE:
5912 exec_store(mach, inst);
5913 break;
5914
5915 case TGSI_OPCODE_ATOMUADD:
5916 case TGSI_OPCODE_ATOMXCHG:
5917 case TGSI_OPCODE_ATOMCAS:
5918 case TGSI_OPCODE_ATOMAND:
5919 case TGSI_OPCODE_ATOMOR:
5920 case TGSI_OPCODE_ATOMXOR:
5921 case TGSI_OPCODE_ATOMUMIN:
5922 case TGSI_OPCODE_ATOMUMAX:
5923 case TGSI_OPCODE_ATOMIMIN:
5924 case TGSI_OPCODE_ATOMIMAX:
5925 exec_atomop(mach, inst);
5926 break;
5927
5928 case TGSI_OPCODE_RESQ:
5929 exec_resq(mach, inst);
5930 break;
5931 case TGSI_OPCODE_BARRIER:
5932 case TGSI_OPCODE_MEMBAR:
5933 return TRUE;
5934 break;
5935
5936 case TGSI_OPCODE_I64ABS:
5937 exec_double_unary(mach, inst, micro_i64abs);
5938 break;
5939
5940 case TGSI_OPCODE_I64SSG:
5941 exec_double_unary(mach, inst, micro_i64sgn);
5942 break;
5943
5944 case TGSI_OPCODE_I64NEG:
5945 exec_double_unary(mach, inst, micro_i64neg);
5946 break;
5947
5948 case TGSI_OPCODE_U64SEQ:
5949 exec_double_binary(mach, inst, micro_u64seq, TGSI_EXEC_DATA_UINT);
5950 break;
5951
5952 case TGSI_OPCODE_U64SNE:
5953 exec_double_binary(mach, inst, micro_u64sne, TGSI_EXEC_DATA_UINT);
5954 break;
5955
5956 case TGSI_OPCODE_I64SLT:
5957 exec_double_binary(mach, inst, micro_i64slt, TGSI_EXEC_DATA_UINT);
5958 break;
5959 case TGSI_OPCODE_U64SLT:
5960 exec_double_binary(mach, inst, micro_u64slt, TGSI_EXEC_DATA_UINT);
5961 break;
5962
5963 case TGSI_OPCODE_I64SGE:
5964 exec_double_binary(mach, inst, micro_i64sge, TGSI_EXEC_DATA_UINT);
5965 break;
5966 case TGSI_OPCODE_U64SGE:
5967 exec_double_binary(mach, inst, micro_u64sge, TGSI_EXEC_DATA_UINT);
5968 break;
5969
5970 case TGSI_OPCODE_I64MIN:
5971 exec_double_binary(mach, inst, micro_i64min, TGSI_EXEC_DATA_INT64);
5972 break;
5973 case TGSI_OPCODE_U64MIN:
5974 exec_double_binary(mach, inst, micro_u64min, TGSI_EXEC_DATA_UINT64);
5975 break;
5976 case TGSI_OPCODE_I64MAX:
5977 exec_double_binary(mach, inst, micro_i64max, TGSI_EXEC_DATA_INT64);
5978 break;
5979 case TGSI_OPCODE_U64MAX:
5980 exec_double_binary(mach, inst, micro_u64max, TGSI_EXEC_DATA_UINT64);
5981 break;
5982 case TGSI_OPCODE_U64ADD:
5983 exec_double_binary(mach, inst, micro_u64add, TGSI_EXEC_DATA_UINT64);
5984 break;
5985 case TGSI_OPCODE_U64MUL:
5986 exec_double_binary(mach, inst, micro_u64mul, TGSI_EXEC_DATA_UINT64);
5987 break;
5988 case TGSI_OPCODE_U64SHL:
5989 exec_arg0_64_arg1_32(mach, inst, micro_u64shl);
5990 break;
5991 case TGSI_OPCODE_I64SHR:
5992 exec_arg0_64_arg1_32(mach, inst, micro_i64shr);
5993 break;
5994 case TGSI_OPCODE_U64SHR:
5995 exec_arg0_64_arg1_32(mach, inst, micro_u64shr);
5996 break;
5997 case TGSI_OPCODE_U64DIV:
5998 exec_double_binary(mach, inst, micro_u64div, TGSI_EXEC_DATA_UINT64);
5999 break;
6000 case TGSI_OPCODE_I64DIV:
6001 exec_double_binary(mach, inst, micro_i64div, TGSI_EXEC_DATA_INT64);
6002 break;
6003 case TGSI_OPCODE_U64MOD:
6004 exec_double_binary(mach, inst, micro_u64mod, TGSI_EXEC_DATA_UINT64);
6005 break;
6006 case TGSI_OPCODE_I64MOD:
6007 exec_double_binary(mach, inst, micro_i64mod, TGSI_EXEC_DATA_INT64);
6008 break;
6009
6010 case TGSI_OPCODE_F2U64:
6011 exec_t_2_64(mach, inst, micro_f2u64, TGSI_EXEC_DATA_FLOAT);
6012 break;
6013
6014 case TGSI_OPCODE_F2I64:
6015 exec_t_2_64(mach, inst, micro_f2i64, TGSI_EXEC_DATA_FLOAT);
6016 break;
6017
6018 case TGSI_OPCODE_U2I64:
6019 exec_t_2_64(mach, inst, micro_u2i64, TGSI_EXEC_DATA_INT);
6020 break;
6021 case TGSI_OPCODE_I2I64:
6022 exec_t_2_64(mach, inst, micro_i2i64, TGSI_EXEC_DATA_INT);
6023 break;
6024
6025 case TGSI_OPCODE_D2U64:
6026 exec_double_unary(mach, inst, micro_d2u64);
6027 break;
6028
6029 case TGSI_OPCODE_D2I64:
6030 exec_double_unary(mach, inst, micro_d2i64);
6031 break;
6032
6033 case TGSI_OPCODE_U642F:
6034 exec_64_2_t(mach, inst, micro_u642f, TGSI_EXEC_DATA_FLOAT);
6035 break;
6036 case TGSI_OPCODE_I642F:
6037 exec_64_2_t(mach, inst, micro_i642f, TGSI_EXEC_DATA_FLOAT);
6038 break;
6039
6040 case TGSI_OPCODE_U642D:
6041 exec_double_unary(mach, inst, micro_u642d);
6042 break;
6043 case TGSI_OPCODE_I642D:
6044 exec_double_unary(mach, inst, micro_i642d);
6045 break;
6046
6047 default:
6048 assert( 0 );
6049 }
6050 return FALSE;
6051 }
6052
6053 static void
6054 tgsi_exec_machine_setup_masks(struct tgsi_exec_machine *mach)
6055 {
6056 uint default_mask = 0xf;
6057
6058 mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0] = 0;
6059 mach->Temps[TEMP_OUTPUT_I].xyzw[TEMP_OUTPUT_C].u[0] = 0;
6060
6061 if (mach->ShaderType == PIPE_SHADER_GEOMETRY) {
6062 mach->Temps[TEMP_PRIMITIVE_I].xyzw[TEMP_PRIMITIVE_C].u[0] = 0;
6063 mach->Primitives[0] = 0;
6064 /* GS runs on a single primitive for now */
6065 default_mask = 0x1;
6066 }
6067
6068 if (mach->NonHelperMask == 0)
6069 mach->NonHelperMask = default_mask;
6070 mach->CondMask = default_mask;
6071 mach->LoopMask = default_mask;
6072 mach->ContMask = default_mask;
6073 mach->FuncMask = default_mask;
6074 mach->ExecMask = default_mask;
6075
6076 mach->Switch.mask = default_mask;
6077
6078 assert(mach->CondStackTop == 0);
6079 assert(mach->LoopStackTop == 0);
6080 assert(mach->ContStackTop == 0);
6081 assert(mach->SwitchStackTop == 0);
6082 assert(mach->BreakStackTop == 0);
6083 assert(mach->CallStackTop == 0);
6084 }
6085
6086 /**
6087 * Run TGSI interpreter.
6088 * \return bitmask of "alive" quad components
6089 */
6090 uint
6091 tgsi_exec_machine_run( struct tgsi_exec_machine *mach, int start_pc )
6092 {
6093 uint i;
6094
6095 mach->pc = start_pc;
6096
6097 if (!start_pc) {
6098 tgsi_exec_machine_setup_masks(mach);
6099
6100 /* execute declarations (interpolants) */
6101 for (i = 0; i < mach->NumDeclarations; i++) {
6102 exec_declaration( mach, mach->Declarations+i );
6103 }
6104 }
6105
6106 {
6107 #if DEBUG_EXECUTION
6108 struct tgsi_exec_vector temps[TGSI_EXEC_NUM_TEMPS + TGSI_EXEC_NUM_TEMP_EXTRAS];
6109 struct tgsi_exec_vector outputs[PIPE_MAX_ATTRIBS];
6110 uint inst = 1;
6111
6112 if (!start_pc) {
6113 memset(mach->Temps, 0, sizeof(temps));
6114 if (mach->Outputs)
6115 memset(mach->Outputs, 0, sizeof(outputs));
6116 memset(temps, 0, sizeof(temps));
6117 memset(outputs, 0, sizeof(outputs));
6118 }
6119 #endif
6120
6121 /* execute instructions, until pc is set to -1 */
6122 while (mach->pc != -1) {
6123 boolean barrier_hit;
6124 #if DEBUG_EXECUTION
6125 uint i;
6126
6127 tgsi_dump_instruction(&mach->Instructions[mach->pc], inst++);
6128 #endif
6129
6130 assert(mach->pc < (int) mach->NumInstructions);
6131 barrier_hit = exec_instruction(mach, mach->Instructions + mach->pc, &mach->pc);
6132
6133 /* for compute shaders if we hit a barrier return now for later rescheduling */
6134 if (barrier_hit && mach->ShaderType == PIPE_SHADER_COMPUTE)
6135 return 0;
6136
6137 #if DEBUG_EXECUTION
6138 for (i = 0; i < TGSI_EXEC_NUM_TEMPS + TGSI_EXEC_NUM_TEMP_EXTRAS; i++) {
6139 if (memcmp(&temps[i], &mach->Temps[i], sizeof(temps[i]))) {
6140 uint j;
6141
6142 memcpy(&temps[i], &mach->Temps[i], sizeof(temps[i]));
6143 debug_printf("TEMP[%2u] = ", i);
6144 for (j = 0; j < 4; j++) {
6145 if (j > 0) {
6146 debug_printf(" ");
6147 }
6148 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
6149 temps[i].xyzw[0].f[j], temps[i].xyzw[0].u[j],
6150 temps[i].xyzw[1].f[j], temps[i].xyzw[1].u[j],
6151 temps[i].xyzw[2].f[j], temps[i].xyzw[2].u[j],
6152 temps[i].xyzw[3].f[j], temps[i].xyzw[3].u[j]);
6153 }
6154 }
6155 }
6156 if (mach->Outputs) {
6157 for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
6158 if (memcmp(&outputs[i], &mach->Outputs[i], sizeof(outputs[i]))) {
6159 uint j;
6160
6161 memcpy(&outputs[i], &mach->Outputs[i], sizeof(outputs[i]));
6162 debug_printf("OUT[%2u] = ", i);
6163 for (j = 0; j < 4; j++) {
6164 if (j > 0) {
6165 debug_printf(" ");
6166 }
6167 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
6168 outputs[i].xyzw[0].f[j], outputs[i].xyzw[0].u[j],
6169 outputs[i].xyzw[1].f[j], outputs[i].xyzw[1].u[j],
6170 outputs[i].xyzw[2].f[j], outputs[i].xyzw[2].u[j],
6171 outputs[i].xyzw[3].f[j], outputs[i].xyzw[3].u[j]);
6172 }
6173 }
6174 }
6175 }
6176 #endif
6177 }
6178 }
6179
6180 #if 0
6181 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
6182 if (mach->ShaderType == PIPE_SHADER_FRAGMENT) {
6183 /*
6184 * Scale back depth component.
6185 */
6186 for (i = 0; i < 4; i++)
6187 mach->Outputs[0].xyzw[2].f[i] *= ctx->DrawBuffer->_DepthMaxF;
6188 }
6189 #endif
6190
6191 /* Strictly speaking, these assertions aren't really needed but they
6192 * can potentially catch some bugs in the control flow code.
6193 */
6194 assert(mach->CondStackTop == 0);
6195 assert(mach->LoopStackTop == 0);
6196 assert(mach->ContStackTop == 0);
6197 assert(mach->SwitchStackTop == 0);
6198 assert(mach->BreakStackTop == 0);
6199 assert(mach->CallStackTop == 0);
6200
6201 return ~mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0];
6202 }