gallivm: fix nested break and continue statements
[mesa.git] / src / gallium / auxiliary / gallivm / lp_bld_tgsi_soa.c
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
4 * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * 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 TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29 /**
30 * @file
31 * TGSI to LLVM IR translation -- SoA.
32 *
33 * @author Jose Fonseca <jfonseca@vmware.com>
34 *
35 * Based on tgsi_sse2.c code written by Michal Krol, Keith Whitwell,
36 * Brian Paul, and others.
37 */
38
39 #include "pipe/p_config.h"
40 #include "pipe/p_shader_tokens.h"
41 #include "util/u_debug.h"
42 #include "util/u_math.h"
43 #include "util/u_memory.h"
44 #include "tgsi/tgsi_dump.h"
45 #include "tgsi/tgsi_info.h"
46 #include "tgsi/tgsi_parse.h"
47 #include "tgsi/tgsi_util.h"
48 #include "tgsi/tgsi_exec.h"
49 #include "tgsi/tgsi_scan.h"
50 #include "lp_bld_type.h"
51 #include "lp_bld_const.h"
52 #include "lp_bld_arit.h"
53 #include "lp_bld_logic.h"
54 #include "lp_bld_swizzle.h"
55 #include "lp_bld_flow.h"
56 #include "lp_bld_tgsi.h"
57 #include "lp_bld_debug.h"
58
59
60 #define LP_MAX_TEMPS 256
61 #define LP_MAX_IMMEDIATES 256
62
63
64 #define FOR_EACH_CHANNEL( CHAN )\
65 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)
66
67 #define IS_DST0_CHANNEL_ENABLED( INST, CHAN )\
68 ((INST)->Dst[0].Register.WriteMask & (1 << (CHAN)))
69
70 #define IF_IS_DST0_CHANNEL_ENABLED( INST, CHAN )\
71 if (IS_DST0_CHANNEL_ENABLED( INST, CHAN ))
72
73 #define FOR_EACH_DST0_ENABLED_CHANNEL( INST, CHAN )\
74 FOR_EACH_CHANNEL( CHAN )\
75 IF_IS_DST0_CHANNEL_ENABLED( INST, CHAN )
76
77 #define CHAN_X 0
78 #define CHAN_Y 1
79 #define CHAN_Z 2
80 #define CHAN_W 3
81
82 #define QUAD_TOP_LEFT 0
83 #define QUAD_TOP_RIGHT 1
84 #define QUAD_BOTTOM_LEFT 2
85 #define QUAD_BOTTOM_RIGHT 3
86
87 #define LP_TGSI_MAX_NESTING 16
88
89 struct lp_exec_mask {
90 struct lp_build_context *bld;
91
92 boolean has_mask;
93
94 LLVMTypeRef int_vec_type;
95
96 LLVMValueRef cond_stack[LP_TGSI_MAX_NESTING];
97 int cond_stack_size;
98 LLVMValueRef cond_mask;
99
100 LLVMValueRef break_stack[LP_TGSI_MAX_NESTING];
101 int break_stack_size;
102 LLVMValueRef break_mask;
103
104 LLVMValueRef cont_stack[LP_TGSI_MAX_NESTING];
105 int cont_stack_size;
106 LLVMValueRef cont_mask;
107
108 LLVMBasicBlockRef loop_stack[LP_TGSI_MAX_NESTING];
109 int loop_stack_size;
110 LLVMBasicBlockRef loop_block;
111
112
113 LLVMValueRef exec_mask;
114 };
115
116 struct lp_build_tgsi_soa_context
117 {
118 struct lp_build_context base;
119
120 LLVMValueRef consts_ptr;
121 const LLVMValueRef *pos;
122 const LLVMValueRef (*inputs)[NUM_CHANNELS];
123 LLVMValueRef (*outputs)[NUM_CHANNELS];
124
125 struct lp_build_sampler_soa *sampler;
126
127 LLVMValueRef immediates[LP_MAX_IMMEDIATES][NUM_CHANNELS];
128 LLVMValueRef temps[LP_MAX_TEMPS][NUM_CHANNELS];
129 LLVMValueRef addr[LP_MAX_TEMPS][NUM_CHANNELS];
130
131 /* we allocate an array of temps if we have indirect
132 * addressing and then the temps above is unused */
133 LLVMValueRef temps_array;
134 boolean has_indirect_addressing;
135
136 struct lp_build_mask_context *mask;
137 struct lp_exec_mask exec_mask;
138 };
139
140 static const unsigned char
141 swizzle_left[4] = {
142 QUAD_TOP_LEFT, QUAD_TOP_LEFT,
143 QUAD_BOTTOM_LEFT, QUAD_BOTTOM_LEFT
144 };
145
146 static const unsigned char
147 swizzle_right[4] = {
148 QUAD_TOP_RIGHT, QUAD_TOP_RIGHT,
149 QUAD_BOTTOM_RIGHT, QUAD_BOTTOM_RIGHT
150 };
151
152 static const unsigned char
153 swizzle_top[4] = {
154 QUAD_TOP_LEFT, QUAD_TOP_RIGHT,
155 QUAD_TOP_LEFT, QUAD_TOP_RIGHT
156 };
157
158 static const unsigned char
159 swizzle_bottom[4] = {
160 QUAD_BOTTOM_LEFT, QUAD_BOTTOM_RIGHT,
161 QUAD_BOTTOM_LEFT, QUAD_BOTTOM_RIGHT
162 };
163
164 static void lp_exec_mask_init(struct lp_exec_mask *mask, struct lp_build_context *bld)
165 {
166 mask->bld = bld;
167 mask->has_mask = FALSE;
168 mask->cond_stack_size = 0;
169 mask->loop_stack_size = 0;
170 mask->break_stack_size = 0;
171 mask->cont_stack_size = 0;
172
173 mask->int_vec_type = lp_build_int_vec_type(mask->bld->type);
174 }
175
176 static void lp_exec_mask_update(struct lp_exec_mask *mask)
177 {
178 if (mask->loop_stack_size) {
179 /*for loops we need to update the entire mask at runtime */
180 LLVMValueRef tmp;
181 assert(mask->break_mask);
182 tmp = LLVMBuildAnd(mask->bld->builder,
183 mask->cont_mask,
184 mask->break_mask,
185 "maskcb");
186 mask->exec_mask = LLVMBuildAnd(mask->bld->builder,
187 mask->cond_mask,
188 tmp,
189 "maskfull");
190 } else
191 mask->exec_mask = mask->cond_mask;
192
193
194 mask->has_mask = (mask->cond_stack_size > 0 ||
195 mask->loop_stack_size > 0);
196 }
197
198 static void lp_exec_mask_cond_push(struct lp_exec_mask *mask,
199 LLVMValueRef val)
200 {
201 mask->cond_stack[mask->cond_stack_size++] = mask->cond_mask;
202 mask->cond_mask = LLVMBuildBitCast(mask->bld->builder, val,
203 mask->int_vec_type, "");
204
205 lp_exec_mask_update(mask);
206 }
207
208 static void lp_exec_mask_cond_invert(struct lp_exec_mask *mask)
209 {
210 LLVMValueRef prev_mask = mask->cond_stack[mask->cond_stack_size - 1];
211 LLVMValueRef inv_mask = LLVMBuildNot(mask->bld->builder,
212 mask->cond_mask, "");
213
214 /* means that we didn't have any mask before and that
215 * we were fully enabled */
216 if (mask->cond_stack_size <= 1) {
217 prev_mask = LLVMConstAllOnes(mask->int_vec_type);
218 }
219
220 mask->cond_mask = LLVMBuildAnd(mask->bld->builder,
221 inv_mask,
222 prev_mask, "");
223 lp_exec_mask_update(mask);
224 }
225
226 static void lp_exec_mask_cond_pop(struct lp_exec_mask *mask)
227 {
228 mask->cond_mask = mask->cond_stack[--mask->cond_stack_size];
229 lp_exec_mask_update(mask);
230 }
231
232 static void lp_exec_bgnloop(struct lp_exec_mask *mask)
233 {
234
235 if (mask->cont_stack_size == 0)
236 mask->cont_mask = LLVMConstAllOnes(mask->int_vec_type);
237 if (mask->break_stack_size == 0)
238 mask->break_mask = LLVMConstAllOnes(mask->int_vec_type);
239 if (mask->cond_stack_size == 0)
240 mask->cond_mask = LLVMConstAllOnes(mask->int_vec_type);
241
242 mask->break_stack[mask->break_stack_size++] = mask->break_mask;
243 mask->cont_stack[mask->cont_stack_size++] = mask->cont_mask;
244 mask->loop_stack[mask->loop_stack_size++] = mask->loop_block;
245 mask->loop_block = lp_build_insert_new_block(mask->bld->builder, "bgnloop");
246 LLVMBuildBr(mask->bld->builder, mask->loop_block);
247 LLVMPositionBuilderAtEnd(mask->bld->builder, mask->loop_block);
248
249 lp_exec_mask_update(mask);
250 }
251
252 static void lp_exec_break(struct lp_exec_mask *mask)
253 {
254 LLVMValueRef exec_mask = LLVMBuildNot(mask->bld->builder,
255 mask->exec_mask,
256 "break");
257
258 mask->break_mask = LLVMBuildAnd(mask->bld->builder,
259 mask->break_mask,
260 exec_mask, "break_full");
261
262 lp_exec_mask_update(mask);
263 }
264
265 static void lp_exec_continue(struct lp_exec_mask *mask)
266 {
267 LLVMValueRef exec_mask = LLVMBuildNot(mask->bld->builder,
268 mask->exec_mask,
269 "");
270
271 mask->cont_mask = LLVMBuildAnd(mask->bld->builder,
272 mask->cont_mask,
273 exec_mask, "");
274
275 lp_exec_mask_update(mask);
276 }
277
278
279 static void lp_exec_endloop(struct lp_exec_mask *mask)
280 {
281 LLVMBasicBlockRef endloop;
282 LLVMTypeRef reg_type = LLVMIntType(mask->bld->type.width*
283 mask->bld->type.length);
284 LLVMValueRef i1cond;
285
286 assert(mask->break_mask);
287
288 /* i1cond = (mask == 0) */
289 i1cond = LLVMBuildICmp(
290 mask->bld->builder,
291 LLVMIntNE,
292 LLVMBuildBitCast(mask->bld->builder, mask->break_mask, reg_type, ""),
293 LLVMConstNull(reg_type), "");
294
295 endloop = lp_build_insert_new_block(mask->bld->builder, "endloop");
296
297 LLVMBuildCondBr(mask->bld->builder,
298 i1cond, mask->loop_block, endloop);
299
300 LLVMPositionBuilderAtEnd(mask->bld->builder, endloop);
301
302 mask->loop_block = mask->loop_stack[--mask->loop_stack_size];
303 /* pop the cont mask */
304 if (mask->cont_stack_size) {
305 mask->cont_mask = mask->cont_stack[--mask->cont_stack_size];
306 }
307 /* pop the break mask */
308 if (mask->break_stack_size) {
309 mask->break_mask = mask->break_stack[--mask->break_stack_size];
310 }
311
312 lp_exec_mask_update(mask);
313 }
314
315 /* stores val into an address pointed to by dst.
316 * mask->exec_mask is used to figure out which bits of val
317 * should be stored into the address
318 * (0 means don't store this bit, 1 means do store).
319 */
320 static void lp_exec_mask_store(struct lp_exec_mask *mask,
321 LLVMValueRef val,
322 LLVMValueRef dst)
323 {
324 if (mask->has_mask) {
325 LLVMValueRef real_val, dst_val;
326
327 dst_val = LLVMBuildLoad(mask->bld->builder, dst, "");
328 real_val = lp_build_select(mask->bld,
329 mask->exec_mask,
330 val, dst_val);
331
332 LLVMBuildStore(mask->bld->builder, real_val, dst);
333 } else
334 LLVMBuildStore(mask->bld->builder, val, dst);
335 }
336
337
338 static LLVMValueRef
339 emit_ddx(struct lp_build_tgsi_soa_context *bld,
340 LLVMValueRef src)
341 {
342 LLVMValueRef src_left = lp_build_swizzle1_aos(&bld->base, src, swizzle_left);
343 LLVMValueRef src_right = lp_build_swizzle1_aos(&bld->base, src, swizzle_right);
344 return lp_build_sub(&bld->base, src_right, src_left);
345 }
346
347
348 static LLVMValueRef
349 emit_ddy(struct lp_build_tgsi_soa_context *bld,
350 LLVMValueRef src)
351 {
352 LLVMValueRef src_top = lp_build_swizzle1_aos(&bld->base, src, swizzle_top);
353 LLVMValueRef src_bottom = lp_build_swizzle1_aos(&bld->base, src, swizzle_bottom);
354 return lp_build_sub(&bld->base, src_top, src_bottom);
355 }
356
357 static LLVMValueRef
358 get_temp_ptr(struct lp_build_tgsi_soa_context *bld,
359 unsigned index,
360 unsigned swizzle,
361 boolean is_indirect,
362 LLVMValueRef addr)
363 {
364 if (!bld->has_indirect_addressing) {
365 return bld->temps[index][swizzle];
366 } else {
367 LLVMValueRef lindex =
368 LLVMConstInt(LLVMInt32Type(), index*4 + swizzle, 0);
369 if (is_indirect)
370 lindex = lp_build_add(&bld->base, lindex, addr);
371 return LLVMBuildGEP(bld->base.builder, bld->temps_array, &lindex, 1, "");
372 }
373 }
374
375 /**
376 * Register fetch.
377 */
378 static LLVMValueRef
379 emit_fetch(
380 struct lp_build_tgsi_soa_context *bld,
381 const struct tgsi_full_instruction *inst,
382 unsigned index,
383 const unsigned chan_index )
384 {
385 const struct tgsi_full_src_register *reg = &inst->Src[index];
386 unsigned swizzle = tgsi_util_get_full_src_register_swizzle( reg, chan_index );
387 LLVMValueRef res;
388 LLVMValueRef addr;
389
390 switch (swizzle) {
391 case TGSI_SWIZZLE_X:
392 case TGSI_SWIZZLE_Y:
393 case TGSI_SWIZZLE_Z:
394 case TGSI_SWIZZLE_W:
395
396 if (reg->Register.Indirect) {
397 LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->base.type);
398 unsigned swizzle = tgsi_util_get_src_register_swizzle( &reg->Indirect, chan_index );
399 addr = LLVMBuildLoad(bld->base.builder,
400 bld->addr[reg->Indirect.Index][swizzle],
401 "");
402 /* for indexing we want integers */
403 addr = LLVMBuildFPToSI(bld->base.builder, addr,
404 int_vec_type, "");
405 addr = LLVMBuildExtractElement(bld->base.builder,
406 addr, LLVMConstInt(LLVMInt32Type(), 0, 0),
407 "");
408 addr = lp_build_mul(&bld->base, addr, LLVMConstInt(LLVMInt32Type(), 4, 0));
409 }
410
411 switch (reg->Register.File) {
412 case TGSI_FILE_CONSTANT: {
413 LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), reg->Register.Index*4 + swizzle, 0);
414 LLVMValueRef scalar, scalar_ptr;
415
416 if (reg->Register.Indirect) {
417 /*lp_build_printf(bld->base.builder,
418 "\taddr = %d\n", addr);*/
419 index = lp_build_add(&bld->base, index, addr);
420 }
421 scalar_ptr = LLVMBuildGEP(bld->base.builder, bld->consts_ptr, &index, 1, "");
422 scalar = LLVMBuildLoad(bld->base.builder, scalar_ptr, "");
423
424 res = lp_build_broadcast_scalar(&bld->base, scalar);
425 break;
426 }
427
428 case TGSI_FILE_IMMEDIATE:
429 res = bld->immediates[reg->Register.Index][swizzle];
430 assert(res);
431 break;
432
433 case TGSI_FILE_INPUT:
434 res = bld->inputs[reg->Register.Index][swizzle];
435 assert(res);
436 break;
437
438 case TGSI_FILE_TEMPORARY: {
439 LLVMValueRef temp_ptr = get_temp_ptr(bld, reg->Register.Index,
440 swizzle,
441 reg->Register.Indirect,
442 addr);
443 res = LLVMBuildLoad(bld->base.builder, temp_ptr, "");
444 if(!res)
445 return bld->base.undef;
446 break;
447 }
448
449 default:
450 assert( 0 );
451 return bld->base.undef;
452 }
453 break;
454
455 default:
456 assert( 0 );
457 return bld->base.undef;
458 }
459
460 switch( tgsi_util_get_full_src_register_sign_mode( reg, chan_index ) ) {
461 case TGSI_UTIL_SIGN_CLEAR:
462 res = lp_build_abs( &bld->base, res );
463 break;
464
465 case TGSI_UTIL_SIGN_SET:
466 /* TODO: Use bitwese OR for floating point */
467 res = lp_build_abs( &bld->base, res );
468 res = LLVMBuildNeg( bld->base.builder, res, "" );
469 break;
470
471 case TGSI_UTIL_SIGN_TOGGLE:
472 res = LLVMBuildNeg( bld->base.builder, res, "" );
473 break;
474
475 case TGSI_UTIL_SIGN_KEEP:
476 break;
477 }
478
479 return res;
480 }
481
482
483 /**
484 * Register fetch with derivatives.
485 */
486 static void
487 emit_fetch_deriv(
488 struct lp_build_tgsi_soa_context *bld,
489 const struct tgsi_full_instruction *inst,
490 unsigned index,
491 const unsigned chan_index,
492 LLVMValueRef *res,
493 LLVMValueRef *ddx,
494 LLVMValueRef *ddy)
495 {
496 LLVMValueRef src;
497
498 src = emit_fetch(bld, inst, index, chan_index);
499
500 if(res)
501 *res = src;
502
503 /* TODO: use interpolation coeffs for inputs */
504
505 if(ddx)
506 *ddx = emit_ddx(bld, src);
507
508 if(ddy)
509 *ddy = emit_ddy(bld, src);
510 }
511
512
513 /**
514 * Register store.
515 */
516 static void
517 emit_store(
518 struct lp_build_tgsi_soa_context *bld,
519 const struct tgsi_full_instruction *inst,
520 unsigned index,
521 unsigned chan_index,
522 LLVMValueRef value)
523 {
524 const struct tgsi_full_dst_register *reg = &inst->Dst[index];
525 LLVMValueRef addr;
526
527 switch( inst->Instruction.Saturate ) {
528 case TGSI_SAT_NONE:
529 break;
530
531 case TGSI_SAT_ZERO_ONE:
532 value = lp_build_max(&bld->base, value, bld->base.zero);
533 value = lp_build_min(&bld->base, value, bld->base.one);
534 break;
535
536 case TGSI_SAT_MINUS_PLUS_ONE:
537 value = lp_build_max(&bld->base, value, lp_build_const_vec(bld->base.type, -1.0));
538 value = lp_build_min(&bld->base, value, bld->base.one);
539 break;
540
541 default:
542 assert(0);
543 }
544
545 if (reg->Register.Indirect) {
546 LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->base.type);
547 unsigned swizzle = tgsi_util_get_src_register_swizzle( &reg->Indirect, chan_index );
548 addr = LLVMBuildLoad(bld->base.builder,
549 bld->addr[reg->Indirect.Index][swizzle],
550 "");
551 /* for indexing we want integers */
552 addr = LLVMBuildFPToSI(bld->base.builder, addr,
553 int_vec_type, "");
554 addr = LLVMBuildExtractElement(bld->base.builder,
555 addr, LLVMConstInt(LLVMInt32Type(), 0, 0),
556 "");
557 addr = lp_build_mul(&bld->base, addr, LLVMConstInt(LLVMInt32Type(), 4, 0));
558 }
559
560 switch( reg->Register.File ) {
561 case TGSI_FILE_OUTPUT:
562 lp_exec_mask_store(&bld->exec_mask, value,
563 bld->outputs[reg->Register.Index][chan_index]);
564 break;
565
566 case TGSI_FILE_TEMPORARY: {
567 LLVMValueRef temp_ptr = get_temp_ptr(bld, reg->Register.Index,
568 chan_index,
569 reg->Register.Indirect,
570 addr);
571 lp_exec_mask_store(&bld->exec_mask, value, temp_ptr);
572 break;
573 }
574
575 case TGSI_FILE_ADDRESS:
576 lp_exec_mask_store(&bld->exec_mask, value,
577 bld->addr[reg->Indirect.Index][chan_index]);
578 break;
579
580 case TGSI_FILE_PREDICATE:
581 /* FIXME */
582 assert(0);
583 break;
584
585 default:
586 assert( 0 );
587 }
588 }
589
590
591 /**
592 * High-level instruction translators.
593 */
594
595
596 static void
597 emit_tex( struct lp_build_tgsi_soa_context *bld,
598 const struct tgsi_full_instruction *inst,
599 boolean apply_lodbias,
600 boolean projected,
601 LLVMValueRef *texel)
602 {
603 const uint unit = inst->Src[1].Register.Index;
604 LLVMValueRef lodbias;
605 LLVMValueRef oow = NULL;
606 LLVMValueRef coords[3];
607 unsigned num_coords;
608 unsigned i;
609
610 switch (inst->Texture.Texture) {
611 case TGSI_TEXTURE_1D:
612 num_coords = 1;
613 break;
614 case TGSI_TEXTURE_2D:
615 case TGSI_TEXTURE_RECT:
616 num_coords = 2;
617 break;
618 case TGSI_TEXTURE_SHADOW1D:
619 case TGSI_TEXTURE_SHADOW2D:
620 case TGSI_TEXTURE_SHADOWRECT:
621 case TGSI_TEXTURE_3D:
622 case TGSI_TEXTURE_CUBE:
623 num_coords = 3;
624 break;
625 default:
626 assert(0);
627 return;
628 }
629
630 if(apply_lodbias)
631 lodbias = emit_fetch( bld, inst, 0, 3 );
632 else
633 lodbias = bld->base.zero;
634
635 if (projected) {
636 oow = emit_fetch( bld, inst, 0, 3 );
637 oow = lp_build_rcp(&bld->base, oow);
638 }
639
640 for (i = 0; i < num_coords; i++) {
641 coords[i] = emit_fetch( bld, inst, 0, i );
642 if (projected)
643 coords[i] = lp_build_mul(&bld->base, coords[i], oow);
644 }
645 for (i = num_coords; i < 3; i++) {
646 coords[i] = bld->base.undef;
647 }
648
649 bld->sampler->emit_fetch_texel(bld->sampler,
650 bld->base.builder,
651 bld->base.type,
652 unit, num_coords, coords, lodbias,
653 texel);
654 }
655
656
657 /**
658 * Kill fragment if any of the src register values are negative.
659 */
660 static void
661 emit_kil(
662 struct lp_build_tgsi_soa_context *bld,
663 const struct tgsi_full_instruction *inst )
664 {
665 const struct tgsi_full_src_register *reg = &inst->Src[0];
666 LLVMValueRef terms[NUM_CHANNELS];
667 LLVMValueRef mask;
668 unsigned chan_index;
669
670 memset(&terms, 0, sizeof terms);
671
672 FOR_EACH_CHANNEL( chan_index ) {
673 unsigned swizzle;
674
675 /* Unswizzle channel */
676 swizzle = tgsi_util_get_full_src_register_swizzle( reg, chan_index );
677
678 /* Check if the component has not been already tested. */
679 assert(swizzle < NUM_CHANNELS);
680 if( !terms[swizzle] )
681 /* TODO: change the comparison operator instead of setting the sign */
682 terms[swizzle] = emit_fetch(bld, inst, 0, chan_index );
683 }
684
685 mask = NULL;
686 FOR_EACH_CHANNEL( chan_index ) {
687 if(terms[chan_index]) {
688 LLVMValueRef chan_mask;
689
690 /*
691 * If term < 0 then mask = 0 else mask = ~0.
692 */
693 chan_mask = lp_build_cmp(&bld->base, PIPE_FUNC_GEQUAL, terms[chan_index], bld->base.zero);
694
695 if(mask)
696 mask = LLVMBuildAnd(bld->base.builder, mask, chan_mask, "");
697 else
698 mask = chan_mask;
699 }
700 }
701
702 if(mask)
703 lp_build_mask_update(bld->mask, mask);
704 }
705
706
707 /**
708 * Predicated fragment kill.
709 * XXX Actually, we do an unconditional kill (as in tgsi_exec.c).
710 * The only predication is the execution mask which will apply if
711 * we're inside a loop or conditional.
712 */
713 static void
714 emit_kilp(struct lp_build_tgsi_soa_context *bld,
715 const struct tgsi_full_instruction *inst)
716 {
717 LLVMValueRef mask;
718
719 /* For those channels which are "alive", disable fragment shader
720 * execution.
721 */
722 if (bld->exec_mask.has_mask) {
723 mask = LLVMBuildNot(bld->base.builder, bld->exec_mask.exec_mask, "kilp");
724 }
725 else {
726 mask = bld->base.zero;
727 }
728
729 lp_build_mask_update(bld->mask, mask);
730 }
731
732 static int
733 emit_declaration(
734 struct lp_build_tgsi_soa_context *bld,
735 const struct tgsi_full_declaration *decl)
736 {
737 LLVMTypeRef vec_type = lp_build_vec_type(bld->base.type);
738
739 unsigned first = decl->Range.First;
740 unsigned last = decl->Range.Last;
741 unsigned idx, i;
742
743 for (idx = first; idx <= last; ++idx) {
744 switch (decl->Declaration.File) {
745 case TGSI_FILE_TEMPORARY:
746 if (bld->has_indirect_addressing) {
747 LLVMValueRef val = LLVMConstInt(LLVMInt32Type(),
748 last*4 + 4, 0);
749 bld->temps_array = lp_build_array_alloca(bld->base.builder,
750 vec_type, val, "");
751 } else {
752 for (i = 0; i < NUM_CHANNELS; i++)
753 bld->temps[idx][i] = lp_build_alloca(bld->base.builder,
754 vec_type, "");
755 }
756 break;
757
758 case TGSI_FILE_OUTPUT:
759 for (i = 0; i < NUM_CHANNELS; i++)
760 bld->outputs[idx][i] = lp_build_alloca(bld->base.builder,
761 vec_type, "");
762 break;
763
764 case TGSI_FILE_ADDRESS:
765 for (i = 0; i < NUM_CHANNELS; i++)
766 bld->addr[idx][i] = lp_build_alloca(bld->base.builder,
767 vec_type, "");
768 break;
769
770 default:
771 /* don't need to declare other vars */
772 break;
773 }
774 }
775
776 return TRUE;
777 }
778
779
780 /**
781 * Emit LLVM for one TGSI instruction.
782 * \param return TRUE for success, FALSE otherwise
783 */
784 static boolean
785 emit_instruction(
786 struct lp_build_tgsi_soa_context *bld,
787 const struct tgsi_full_instruction *inst,
788 const struct tgsi_opcode_info *info)
789 {
790 unsigned chan_index;
791 LLVMValueRef src0, src1, src2;
792 LLVMValueRef tmp0, tmp1, tmp2;
793 LLVMValueRef tmp3 = NULL;
794 LLVMValueRef tmp4 = NULL;
795 LLVMValueRef tmp5 = NULL;
796 LLVMValueRef tmp6 = NULL;
797 LLVMValueRef tmp7 = NULL;
798 LLVMValueRef res;
799 LLVMValueRef dst0[NUM_CHANNELS];
800
801 /*
802 * Stores and write masks are handled in a general fashion after the long
803 * instruction opcode switch statement.
804 *
805 * Although not stricitly necessary, we avoid generating instructions for
806 * channels which won't be stored, in cases where's that easy. For some
807 * complex instructions, like texture sampling, it is more convenient to
808 * assume a full writemask and then let LLVM optimization passes eliminate
809 * redundant code.
810 */
811
812 assert(info->num_dst <= 1);
813 if(info->num_dst) {
814 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
815 dst0[chan_index] = bld->base.undef;
816 }
817 }
818
819 switch (inst->Instruction.Opcode) {
820 case TGSI_OPCODE_ARL:
821 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
822 tmp0 = emit_fetch( bld, inst, 0, chan_index );
823 tmp0 = lp_build_floor(&bld->base, tmp0);
824 dst0[chan_index] = tmp0;
825 }
826 break;
827
828 case TGSI_OPCODE_MOV:
829 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
830 dst0[chan_index] = emit_fetch( bld, inst, 0, chan_index );
831 }
832 break;
833
834 case TGSI_OPCODE_LIT:
835 if( IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ) ) {
836 dst0[CHAN_X] = bld->base.one;
837 }
838 if( IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y ) ) {
839 src0 = emit_fetch( bld, inst, 0, CHAN_X );
840 dst0[CHAN_Y] = lp_build_max( &bld->base, src0, bld->base.zero);
841 }
842 if( IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z ) ) {
843 /* XMM[1] = SrcReg[0].yyyy */
844 tmp1 = emit_fetch( bld, inst, 0, CHAN_Y );
845 /* XMM[1] = max(XMM[1], 0) */
846 tmp1 = lp_build_max( &bld->base, tmp1, bld->base.zero);
847 /* XMM[2] = SrcReg[0].wwww */
848 tmp2 = emit_fetch( bld, inst, 0, CHAN_W );
849 tmp1 = lp_build_pow( &bld->base, tmp1, tmp2);
850 tmp0 = emit_fetch( bld, inst, 0, CHAN_X );
851 tmp2 = lp_build_cmp(&bld->base, PIPE_FUNC_GREATER, tmp0, bld->base.zero);
852 dst0[CHAN_Z] = lp_build_select(&bld->base, tmp2, tmp1, bld->base.zero);
853 }
854 if( IS_DST0_CHANNEL_ENABLED( inst, CHAN_W ) ) {
855 dst0[CHAN_W] = bld->base.one;
856 }
857 break;
858
859 case TGSI_OPCODE_RCP:
860 /* TGSI_OPCODE_RECIP */
861 src0 = emit_fetch( bld, inst, 0, CHAN_X );
862 res = lp_build_rcp(&bld->base, src0);
863 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
864 dst0[chan_index] = res;
865 }
866 break;
867
868 case TGSI_OPCODE_RSQ:
869 /* TGSI_OPCODE_RECIPSQRT */
870 src0 = emit_fetch( bld, inst, 0, CHAN_X );
871 src0 = lp_build_abs(&bld->base, src0);
872 res = lp_build_rsqrt(&bld->base, src0);
873 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
874 dst0[chan_index] = res;
875 }
876 break;
877
878 case TGSI_OPCODE_EXP:
879 if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ) ||
880 IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y ) ||
881 IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z )) {
882 LLVMValueRef *p_exp2_int_part = NULL;
883 LLVMValueRef *p_frac_part = NULL;
884 LLVMValueRef *p_exp2 = NULL;
885
886 src0 = emit_fetch( bld, inst, 0, CHAN_X );
887
888 if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ))
889 p_exp2_int_part = &tmp0;
890 if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y ))
891 p_frac_part = &tmp1;
892 if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z ))
893 p_exp2 = &tmp2;
894
895 lp_build_exp2_approx(&bld->base, src0, p_exp2_int_part, p_frac_part, p_exp2);
896
897 if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ))
898 dst0[CHAN_X] = tmp0;
899 if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y ))
900 dst0[CHAN_Y] = tmp1;
901 if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z ))
902 dst0[CHAN_Z] = tmp2;
903 }
904 /* dst.w = 1.0 */
905 if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_W )) {
906 dst0[CHAN_W] = bld->base.one;
907 }
908 break;
909
910 case TGSI_OPCODE_LOG:
911 if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ) ||
912 IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y ) ||
913 IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z )) {
914 LLVMValueRef *p_floor_log2 = NULL;
915 LLVMValueRef *p_exp = NULL;
916 LLVMValueRef *p_log2 = NULL;
917
918 src0 = emit_fetch( bld, inst, 0, CHAN_X );
919 src0 = lp_build_abs( &bld->base, src0 );
920
921 if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ))
922 p_floor_log2 = &tmp0;
923 if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y ))
924 p_exp = &tmp1;
925 if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z ))
926 p_log2 = &tmp2;
927
928 lp_build_log2_approx(&bld->base, src0, p_exp, p_floor_log2, p_log2);
929
930 /* dst.x = floor(lg2(abs(src.x))) */
931 if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ))
932 dst0[CHAN_X] = tmp0;
933 /* dst.y = abs(src)/ex2(floor(lg2(abs(src.x)))) */
934 if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y )) {
935 dst0[CHAN_Y] = lp_build_div( &bld->base, src0, tmp1);
936 }
937 /* dst.z = lg2(abs(src.x)) */
938 if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z ))
939 dst0[CHAN_Z] = tmp2;
940 }
941 /* dst.w = 1.0 */
942 if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_W )) {
943 dst0[CHAN_W] = bld->base.one;
944 }
945 break;
946
947 case TGSI_OPCODE_MUL:
948 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
949 src0 = emit_fetch( bld, inst, 0, chan_index );
950 src1 = emit_fetch( bld, inst, 1, chan_index );
951 dst0[chan_index] = lp_build_mul(&bld->base, src0, src1);
952 }
953 break;
954
955 case TGSI_OPCODE_ADD:
956 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
957 src0 = emit_fetch( bld, inst, 0, chan_index );
958 src1 = emit_fetch( bld, inst, 1, chan_index );
959 dst0[chan_index] = lp_build_add(&bld->base, src0, src1);
960 }
961 break;
962
963 case TGSI_OPCODE_DP3:
964 /* TGSI_OPCODE_DOT3 */
965 tmp0 = emit_fetch( bld, inst, 0, CHAN_X );
966 tmp1 = emit_fetch( bld, inst, 1, CHAN_X );
967 tmp0 = lp_build_mul( &bld->base, tmp0, tmp1);
968 tmp1 = emit_fetch( bld, inst, 0, CHAN_Y );
969 tmp2 = emit_fetch( bld, inst, 1, CHAN_Y );
970 tmp1 = lp_build_mul( &bld->base, tmp1, tmp2);
971 tmp0 = lp_build_add( &bld->base, tmp0, tmp1);
972 tmp1 = emit_fetch( bld, inst, 0, CHAN_Z );
973 tmp2 = emit_fetch( bld, inst, 1, CHAN_Z );
974 tmp1 = lp_build_mul( &bld->base, tmp1, tmp2);
975 tmp0 = lp_build_add( &bld->base, tmp0, tmp1);
976 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
977 dst0[chan_index] = tmp0;
978 }
979 break;
980
981 case TGSI_OPCODE_DP4:
982 /* TGSI_OPCODE_DOT4 */
983 tmp0 = emit_fetch( bld, inst, 0, CHAN_X );
984 tmp1 = emit_fetch( bld, inst, 1, CHAN_X );
985 tmp0 = lp_build_mul( &bld->base, tmp0, tmp1);
986 tmp1 = emit_fetch( bld, inst, 0, CHAN_Y );
987 tmp2 = emit_fetch( bld, inst, 1, CHAN_Y );
988 tmp1 = lp_build_mul( &bld->base, tmp1, tmp2);
989 tmp0 = lp_build_add( &bld->base, tmp0, tmp1);
990 tmp1 = emit_fetch( bld, inst, 0, CHAN_Z );
991 tmp2 = emit_fetch( bld, inst, 1, CHAN_Z );
992 tmp1 = lp_build_mul( &bld->base, tmp1, tmp2);
993 tmp0 = lp_build_add( &bld->base, tmp0, tmp1);
994 tmp1 = emit_fetch( bld, inst, 0, CHAN_W );
995 tmp2 = emit_fetch( bld, inst, 1, CHAN_W );
996 tmp1 = lp_build_mul( &bld->base, tmp1, tmp2);
997 tmp0 = lp_build_add( &bld->base, tmp0, tmp1);
998 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
999 dst0[chan_index] = tmp0;
1000 }
1001 break;
1002
1003 case TGSI_OPCODE_DST:
1004 IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ) {
1005 dst0[CHAN_X] = bld->base.one;
1006 }
1007 IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y ) {
1008 tmp0 = emit_fetch( bld, inst, 0, CHAN_Y );
1009 tmp1 = emit_fetch( bld, inst, 1, CHAN_Y );
1010 dst0[CHAN_Y] = lp_build_mul( &bld->base, tmp0, tmp1);
1011 }
1012 IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z ) {
1013 dst0[CHAN_Z] = emit_fetch( bld, inst, 0, CHAN_Z );
1014 }
1015 IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_W ) {
1016 dst0[CHAN_W] = emit_fetch( bld, inst, 1, CHAN_W );
1017 }
1018 break;
1019
1020 case TGSI_OPCODE_MIN:
1021 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1022 src0 = emit_fetch( bld, inst, 0, chan_index );
1023 src1 = emit_fetch( bld, inst, 1, chan_index );
1024 dst0[chan_index] = lp_build_min( &bld->base, src0, src1 );
1025 }
1026 break;
1027
1028 case TGSI_OPCODE_MAX:
1029 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1030 src0 = emit_fetch( bld, inst, 0, chan_index );
1031 src1 = emit_fetch( bld, inst, 1, chan_index );
1032 dst0[chan_index] = lp_build_max( &bld->base, src0, src1 );
1033 }
1034 break;
1035
1036 case TGSI_OPCODE_SLT:
1037 /* TGSI_OPCODE_SETLT */
1038 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1039 src0 = emit_fetch( bld, inst, 0, chan_index );
1040 src1 = emit_fetch( bld, inst, 1, chan_index );
1041 tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_LESS, src0, src1 );
1042 dst0[chan_index] = lp_build_select( &bld->base, tmp0, bld->base.one, bld->base.zero );
1043 }
1044 break;
1045
1046 case TGSI_OPCODE_SGE:
1047 /* TGSI_OPCODE_SETGE */
1048 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1049 src0 = emit_fetch( bld, inst, 0, chan_index );
1050 src1 = emit_fetch( bld, inst, 1, chan_index );
1051 tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_GEQUAL, src0, src1 );
1052 dst0[chan_index] = lp_build_select( &bld->base, tmp0, bld->base.one, bld->base.zero );
1053 }
1054 break;
1055
1056 case TGSI_OPCODE_MAD:
1057 /* TGSI_OPCODE_MADD */
1058 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1059 tmp0 = emit_fetch( bld, inst, 0, chan_index );
1060 tmp1 = emit_fetch( bld, inst, 1, chan_index );
1061 tmp2 = emit_fetch( bld, inst, 2, chan_index );
1062 tmp0 = lp_build_mul( &bld->base, tmp0, tmp1);
1063 tmp0 = lp_build_add( &bld->base, tmp0, tmp2);
1064 dst0[chan_index] = tmp0;
1065 }
1066 break;
1067
1068 case TGSI_OPCODE_SUB:
1069 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1070 tmp0 = emit_fetch( bld, inst, 0, chan_index );
1071 tmp1 = emit_fetch( bld, inst, 1, chan_index );
1072 dst0[chan_index] = lp_build_sub( &bld->base, tmp0, tmp1);
1073 }
1074 break;
1075
1076 case TGSI_OPCODE_LRP:
1077 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1078 src0 = emit_fetch( bld, inst, 0, chan_index );
1079 src1 = emit_fetch( bld, inst, 1, chan_index );
1080 src2 = emit_fetch( bld, inst, 2, chan_index );
1081 tmp0 = lp_build_sub( &bld->base, src1, src2 );
1082 tmp0 = lp_build_mul( &bld->base, src0, tmp0 );
1083 dst0[chan_index] = lp_build_add( &bld->base, tmp0, src2 );
1084 }
1085 break;
1086
1087 case TGSI_OPCODE_CND:
1088 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1089 src0 = emit_fetch( bld, inst, 0, chan_index );
1090 src1 = emit_fetch( bld, inst, 1, chan_index );
1091 src2 = emit_fetch( bld, inst, 2, chan_index );
1092 tmp1 = lp_build_const_vec(bld->base.type, 0.5);
1093 tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_GREATER, src2, tmp1);
1094 dst0[chan_index] = lp_build_select( &bld->base, tmp0, src0, src1 );
1095 }
1096 break;
1097
1098 case TGSI_OPCODE_DP2A:
1099 tmp0 = emit_fetch( bld, inst, 0, CHAN_X ); /* xmm0 = src[0].x */
1100 tmp1 = emit_fetch( bld, inst, 1, CHAN_X ); /* xmm1 = src[1].x */
1101 tmp0 = lp_build_mul( &bld->base, tmp0, tmp1); /* xmm0 = xmm0 * xmm1 */
1102 tmp1 = emit_fetch( bld, inst, 0, CHAN_Y ); /* xmm1 = src[0].y */
1103 tmp2 = emit_fetch( bld, inst, 1, CHAN_Y ); /* xmm2 = src[1].y */
1104 tmp1 = lp_build_mul( &bld->base, tmp1, tmp2); /* xmm1 = xmm1 * xmm2 */
1105 tmp0 = lp_build_add( &bld->base, tmp0, tmp1); /* xmm0 = xmm0 + xmm1 */
1106 tmp1 = emit_fetch( bld, inst, 2, CHAN_X ); /* xmm1 = src[2].x */
1107 tmp0 = lp_build_add( &bld->base, tmp0, tmp1); /* xmm0 = xmm0 + xmm1 */
1108 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1109 dst0[chan_index] = tmp0; /* dest[ch] = xmm0 */
1110 }
1111 break;
1112
1113 case TGSI_OPCODE_FRC:
1114 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1115 src0 = emit_fetch( bld, inst, 0, chan_index );
1116 tmp0 = lp_build_floor(&bld->base, src0);
1117 tmp0 = lp_build_sub(&bld->base, src0, tmp0);
1118 dst0[chan_index] = tmp0;
1119 }
1120 break;
1121
1122 case TGSI_OPCODE_CLAMP:
1123 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1124 tmp0 = emit_fetch( bld, inst, 0, chan_index );
1125 src1 = emit_fetch( bld, inst, 1, chan_index );
1126 src2 = emit_fetch( bld, inst, 2, chan_index );
1127 tmp0 = lp_build_max(&bld->base, tmp0, src1);
1128 tmp0 = lp_build_min(&bld->base, tmp0, src2);
1129 dst0[chan_index] = tmp0;
1130 }
1131 break;
1132
1133 case TGSI_OPCODE_FLR:
1134 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1135 tmp0 = emit_fetch( bld, inst, 0, chan_index );
1136 dst0[chan_index] = lp_build_floor(&bld->base, tmp0);
1137 }
1138 break;
1139
1140 case TGSI_OPCODE_ROUND:
1141 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1142 tmp0 = emit_fetch( bld, inst, 0, chan_index );
1143 dst0[chan_index] = lp_build_round(&bld->base, tmp0);
1144 }
1145 break;
1146
1147 case TGSI_OPCODE_EX2: {
1148 tmp0 = emit_fetch( bld, inst, 0, CHAN_X );
1149 tmp0 = lp_build_exp2( &bld->base, tmp0);
1150 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1151 dst0[chan_index] = tmp0;
1152 }
1153 break;
1154 }
1155
1156 case TGSI_OPCODE_LG2:
1157 tmp0 = emit_fetch( bld, inst, 0, CHAN_X );
1158 tmp0 = lp_build_log2( &bld->base, tmp0);
1159 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1160 dst0[chan_index] = tmp0;
1161 }
1162 break;
1163
1164 case TGSI_OPCODE_POW:
1165 src0 = emit_fetch( bld, inst, 0, CHAN_X );
1166 src1 = emit_fetch( bld, inst, 1, CHAN_X );
1167 res = lp_build_pow( &bld->base, src0, src1 );
1168 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1169 dst0[chan_index] = res;
1170 }
1171 break;
1172
1173 case TGSI_OPCODE_XPD:
1174 if( IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ) ||
1175 IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y ) ) {
1176 tmp1 = emit_fetch( bld, inst, 1, CHAN_Z );
1177 tmp3 = emit_fetch( bld, inst, 0, CHAN_Z );
1178 }
1179 if( IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ) ||
1180 IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z ) ) {
1181 tmp0 = emit_fetch( bld, inst, 0, CHAN_Y );
1182 tmp4 = emit_fetch( bld, inst, 1, CHAN_Y );
1183 }
1184 IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ) {
1185 tmp2 = tmp0;
1186 tmp2 = lp_build_mul( &bld->base, tmp2, tmp1);
1187 tmp5 = tmp3;
1188 tmp5 = lp_build_mul( &bld->base, tmp5, tmp4);
1189 tmp2 = lp_build_sub( &bld->base, tmp2, tmp5);
1190 dst0[CHAN_X] = tmp2;
1191 }
1192 if( IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y ) ||
1193 IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z ) ) {
1194 tmp2 = emit_fetch( bld, inst, 1, CHAN_X );
1195 tmp5 = emit_fetch( bld, inst, 0, CHAN_X );
1196 }
1197 IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y ) {
1198 tmp3 = lp_build_mul( &bld->base, tmp3, tmp2);
1199 tmp1 = lp_build_mul( &bld->base, tmp1, tmp5);
1200 tmp3 = lp_build_sub( &bld->base, tmp3, tmp1);
1201 dst0[CHAN_Y] = tmp3;
1202 }
1203 IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z ) {
1204 tmp5 = lp_build_mul( &bld->base, tmp5, tmp4);
1205 tmp0 = lp_build_mul( &bld->base, tmp0, tmp2);
1206 tmp5 = lp_build_sub( &bld->base, tmp5, tmp0);
1207 dst0[CHAN_Z] = tmp5;
1208 }
1209 IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_W ) {
1210 dst0[CHAN_W] = bld->base.one;
1211 }
1212 break;
1213
1214 case TGSI_OPCODE_ABS:
1215 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1216 tmp0 = emit_fetch( bld, inst, 0, chan_index );
1217 dst0[chan_index] = lp_build_abs( &bld->base, tmp0 );
1218 }
1219 break;
1220
1221 case TGSI_OPCODE_RCC:
1222 /* deprecated? */
1223 assert(0);
1224 return FALSE;
1225
1226 case TGSI_OPCODE_DPH:
1227 tmp0 = emit_fetch( bld, inst, 0, CHAN_X );
1228 tmp1 = emit_fetch( bld, inst, 1, CHAN_X );
1229 tmp0 = lp_build_mul( &bld->base, tmp0, tmp1);
1230 tmp1 = emit_fetch( bld, inst, 0, CHAN_Y );
1231 tmp2 = emit_fetch( bld, inst, 1, CHAN_Y );
1232 tmp1 = lp_build_mul( &bld->base, tmp1, tmp2);
1233 tmp0 = lp_build_add( &bld->base, tmp0, tmp1);
1234 tmp1 = emit_fetch( bld, inst, 0, CHAN_Z );
1235 tmp2 = emit_fetch( bld, inst, 1, CHAN_Z );
1236 tmp1 = lp_build_mul( &bld->base, tmp1, tmp2);
1237 tmp0 = lp_build_add( &bld->base, tmp0, tmp1);
1238 tmp1 = emit_fetch( bld, inst, 1, CHAN_W );
1239 tmp0 = lp_build_add( &bld->base, tmp0, tmp1);
1240 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1241 dst0[chan_index] = tmp0;
1242 }
1243 break;
1244
1245 case TGSI_OPCODE_COS:
1246 tmp0 = emit_fetch( bld, inst, 0, CHAN_X );
1247 tmp0 = lp_build_cos( &bld->base, tmp0 );
1248 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1249 dst0[chan_index] = tmp0;
1250 }
1251 break;
1252
1253 case TGSI_OPCODE_DDX:
1254 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1255 emit_fetch_deriv( bld, inst, 0, chan_index, NULL, &dst0[chan_index], NULL);
1256 }
1257 break;
1258
1259 case TGSI_OPCODE_DDY:
1260 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1261 emit_fetch_deriv( bld, inst, 0, chan_index, NULL, NULL, &dst0[chan_index]);
1262 }
1263 break;
1264
1265 case TGSI_OPCODE_KILP:
1266 /* predicated kill */
1267 emit_kilp( bld, inst );
1268 break;
1269
1270 case TGSI_OPCODE_KIL:
1271 /* conditional kill */
1272 emit_kil( bld, inst );
1273 break;
1274
1275 case TGSI_OPCODE_PK2H:
1276 return FALSE;
1277 break;
1278
1279 case TGSI_OPCODE_PK2US:
1280 return FALSE;
1281 break;
1282
1283 case TGSI_OPCODE_PK4B:
1284 return FALSE;
1285 break;
1286
1287 case TGSI_OPCODE_PK4UB:
1288 return FALSE;
1289 break;
1290
1291 case TGSI_OPCODE_RFL:
1292 return FALSE;
1293 break;
1294
1295 case TGSI_OPCODE_SEQ:
1296 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1297 src0 = emit_fetch( bld, inst, 0, chan_index );
1298 src1 = emit_fetch( bld, inst, 1, chan_index );
1299 tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_EQUAL, src0, src1 );
1300 dst0[chan_index] = lp_build_select( &bld->base, tmp0, bld->base.one, bld->base.zero );
1301 }
1302 break;
1303
1304 case TGSI_OPCODE_SFL:
1305 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1306 dst0[chan_index] = bld->base.zero;
1307 }
1308 break;
1309
1310 case TGSI_OPCODE_SGT:
1311 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1312 src0 = emit_fetch( bld, inst, 0, chan_index );
1313 src1 = emit_fetch( bld, inst, 1, chan_index );
1314 tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_GREATER, src0, src1 );
1315 dst0[chan_index] = lp_build_select( &bld->base, tmp0, bld->base.one, bld->base.zero );
1316 }
1317 break;
1318
1319 case TGSI_OPCODE_SIN:
1320 tmp0 = emit_fetch( bld, inst, 0, CHAN_X );
1321 tmp0 = lp_build_sin( &bld->base, tmp0 );
1322 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1323 dst0[chan_index] = tmp0;
1324 }
1325 break;
1326
1327 case TGSI_OPCODE_SLE:
1328 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1329 src0 = emit_fetch( bld, inst, 0, chan_index );
1330 src1 = emit_fetch( bld, inst, 1, chan_index );
1331 tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_LEQUAL, src0, src1 );
1332 dst0[chan_index] = lp_build_select( &bld->base, tmp0, bld->base.one, bld->base.zero );
1333 }
1334 break;
1335
1336 case TGSI_OPCODE_SNE:
1337 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1338 src0 = emit_fetch( bld, inst, 0, chan_index );
1339 src1 = emit_fetch( bld, inst, 1, chan_index );
1340 tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_NOTEQUAL, src0, src1 );
1341 dst0[chan_index] = lp_build_select( &bld->base, tmp0, bld->base.one, bld->base.zero );
1342 }
1343 break;
1344
1345 case TGSI_OPCODE_STR:
1346 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1347 dst0[chan_index] = bld->base.one;
1348 }
1349 break;
1350
1351 case TGSI_OPCODE_TEX:
1352 emit_tex( bld, inst, FALSE, FALSE, dst0 );
1353 break;
1354
1355 case TGSI_OPCODE_TXD:
1356 /* FIXME */
1357 return FALSE;
1358 break;
1359
1360 case TGSI_OPCODE_UP2H:
1361 /* deprecated */
1362 assert (0);
1363 return FALSE;
1364 break;
1365
1366 case TGSI_OPCODE_UP2US:
1367 /* deprecated */
1368 assert(0);
1369 return FALSE;
1370 break;
1371
1372 case TGSI_OPCODE_UP4B:
1373 /* deprecated */
1374 assert(0);
1375 return FALSE;
1376 break;
1377
1378 case TGSI_OPCODE_UP4UB:
1379 /* deprecated */
1380 assert(0);
1381 return FALSE;
1382 break;
1383
1384 case TGSI_OPCODE_X2D:
1385 /* deprecated? */
1386 assert(0);
1387 return FALSE;
1388 break;
1389
1390 case TGSI_OPCODE_ARA:
1391 /* deprecated */
1392 assert(0);
1393 return FALSE;
1394 break;
1395
1396 case TGSI_OPCODE_ARR:
1397 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1398 tmp0 = emit_fetch( bld, inst, 0, chan_index );
1399 tmp0 = lp_build_round(&bld->base, tmp0);
1400 dst0[chan_index] = tmp0;
1401 }
1402 break;
1403
1404 case TGSI_OPCODE_BRA:
1405 /* deprecated */
1406 assert(0);
1407 return FALSE;
1408 break;
1409
1410 case TGSI_OPCODE_CAL:
1411 /* FIXME */
1412 return FALSE;
1413 break;
1414
1415 case TGSI_OPCODE_RET:
1416 /* FIXME */
1417 return FALSE;
1418 break;
1419
1420 case TGSI_OPCODE_END:
1421 break;
1422
1423 case TGSI_OPCODE_SSG:
1424 /* TGSI_OPCODE_SGN */
1425 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1426 tmp0 = emit_fetch( bld, inst, 0, chan_index );
1427 dst0[chan_index] = lp_build_sgn( &bld->base, tmp0 );
1428 }
1429 break;
1430
1431 case TGSI_OPCODE_CMP:
1432 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1433 src0 = emit_fetch( bld, inst, 0, chan_index );
1434 src1 = emit_fetch( bld, inst, 1, chan_index );
1435 src2 = emit_fetch( bld, inst, 2, chan_index );
1436 tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_LESS, src0, bld->base.zero );
1437 dst0[chan_index] = lp_build_select( &bld->base, tmp0, src1, src2);
1438 }
1439 break;
1440
1441 case TGSI_OPCODE_SCS:
1442 IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ) {
1443 tmp0 = emit_fetch( bld, inst, 0, CHAN_X );
1444 dst0[CHAN_X] = lp_build_cos( &bld->base, tmp0 );
1445 }
1446 IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y ) {
1447 tmp0 = emit_fetch( bld, inst, 0, CHAN_X );
1448 dst0[CHAN_Y] = lp_build_sin( &bld->base, tmp0 );
1449 }
1450 IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z ) {
1451 dst0[CHAN_Z] = bld->base.zero;
1452 }
1453 IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_W ) {
1454 dst0[CHAN_W] = bld->base.one;
1455 }
1456 break;
1457
1458 case TGSI_OPCODE_TXB:
1459 emit_tex( bld, inst, TRUE, FALSE, dst0 );
1460 break;
1461
1462 case TGSI_OPCODE_NRM:
1463 /* fall-through */
1464 case TGSI_OPCODE_NRM4:
1465 /* 3 or 4-component normalization */
1466 {
1467 uint dims = (inst->Instruction.Opcode == TGSI_OPCODE_NRM) ? 3 : 4;
1468
1469 if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_X) ||
1470 IS_DST0_CHANNEL_ENABLED(inst, CHAN_Y) ||
1471 IS_DST0_CHANNEL_ENABLED(inst, CHAN_Z) ||
1472 (IS_DST0_CHANNEL_ENABLED(inst, CHAN_W) && dims == 4)) {
1473
1474 /* NOTE: Cannot use xmm regs 2/3 here (see emit_rsqrt() above). */
1475
1476 /* xmm4 = src.x */
1477 /* xmm0 = src.x * src.x */
1478 tmp0 = emit_fetch(bld, inst, 0, CHAN_X);
1479 if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_X)) {
1480 tmp4 = tmp0;
1481 }
1482 tmp0 = lp_build_mul( &bld->base, tmp0, tmp0);
1483
1484 /* xmm5 = src.y */
1485 /* xmm0 = xmm0 + src.y * src.y */
1486 tmp1 = emit_fetch(bld, inst, 0, CHAN_Y);
1487 if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_Y)) {
1488 tmp5 = tmp1;
1489 }
1490 tmp1 = lp_build_mul( &bld->base, tmp1, tmp1);
1491 tmp0 = lp_build_add( &bld->base, tmp0, tmp1);
1492
1493 /* xmm6 = src.z */
1494 /* xmm0 = xmm0 + src.z * src.z */
1495 tmp1 = emit_fetch(bld, inst, 0, CHAN_Z);
1496 if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_Z)) {
1497 tmp6 = tmp1;
1498 }
1499 tmp1 = lp_build_mul( &bld->base, tmp1, tmp1);
1500 tmp0 = lp_build_add( &bld->base, tmp0, tmp1);
1501
1502 if (dims == 4) {
1503 /* xmm7 = src.w */
1504 /* xmm0 = xmm0 + src.w * src.w */
1505 tmp1 = emit_fetch(bld, inst, 0, CHAN_W);
1506 if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_W)) {
1507 tmp7 = tmp1;
1508 }
1509 tmp1 = lp_build_mul( &bld->base, tmp1, tmp1);
1510 tmp0 = lp_build_add( &bld->base, tmp0, tmp1);
1511 }
1512
1513 /* xmm1 = 1 / sqrt(xmm0) */
1514 tmp1 = lp_build_rsqrt( &bld->base, tmp0);
1515
1516 /* dst.x = xmm1 * src.x */
1517 if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_X)) {
1518 dst0[CHAN_X] = lp_build_mul( &bld->base, tmp4, tmp1);
1519 }
1520
1521 /* dst.y = xmm1 * src.y */
1522 if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_Y)) {
1523 dst0[CHAN_Y] = lp_build_mul( &bld->base, tmp5, tmp1);
1524 }
1525
1526 /* dst.z = xmm1 * src.z */
1527 if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_Z)) {
1528 dst0[CHAN_Z] = lp_build_mul( &bld->base, tmp6, tmp1);
1529 }
1530
1531 /* dst.w = xmm1 * src.w */
1532 if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_X) && dims == 4) {
1533 dst0[CHAN_W] = lp_build_mul( &bld->base, tmp7, tmp1);
1534 }
1535 }
1536
1537 /* dst.w = 1.0 */
1538 if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_W) && dims == 3) {
1539 dst0[CHAN_W] = bld->base.one;
1540 }
1541 }
1542 break;
1543
1544 case TGSI_OPCODE_DIV:
1545 /* deprecated */
1546 assert( 0 );
1547 return FALSE;
1548 break;
1549
1550 case TGSI_OPCODE_DP2:
1551 tmp0 = emit_fetch( bld, inst, 0, CHAN_X ); /* xmm0 = src[0].x */
1552 tmp1 = emit_fetch( bld, inst, 1, CHAN_X ); /* xmm1 = src[1].x */
1553 tmp0 = lp_build_mul( &bld->base, tmp0, tmp1); /* xmm0 = xmm0 * xmm1 */
1554 tmp1 = emit_fetch( bld, inst, 0, CHAN_Y ); /* xmm1 = src[0].y */
1555 tmp2 = emit_fetch( bld, inst, 1, CHAN_Y ); /* xmm2 = src[1].y */
1556 tmp1 = lp_build_mul( &bld->base, tmp1, tmp2); /* xmm1 = xmm1 * xmm2 */
1557 tmp0 = lp_build_add( &bld->base, tmp0, tmp1); /* xmm0 = xmm0 + xmm1 */
1558 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1559 dst0[chan_index] = tmp0; /* dest[ch] = xmm0 */
1560 }
1561 break;
1562
1563 case TGSI_OPCODE_TXL:
1564 emit_tex( bld, inst, TRUE, FALSE, dst0 );
1565 break;
1566
1567 case TGSI_OPCODE_TXP:
1568 emit_tex( bld, inst, FALSE, TRUE, dst0 );
1569 break;
1570
1571 case TGSI_OPCODE_BRK:
1572 lp_exec_break(&bld->exec_mask);
1573 break;
1574
1575 case TGSI_OPCODE_IF:
1576 tmp0 = emit_fetch(bld, inst, 0, CHAN_X);
1577 tmp0 = lp_build_cmp(&bld->base, PIPE_FUNC_NOTEQUAL,
1578 tmp0, bld->base.zero);
1579 lp_exec_mask_cond_push(&bld->exec_mask, tmp0);
1580 break;
1581
1582 case TGSI_OPCODE_BGNLOOP:
1583 lp_exec_bgnloop(&bld->exec_mask);
1584 break;
1585
1586 case TGSI_OPCODE_ELSE:
1587 lp_exec_mask_cond_invert(&bld->exec_mask);
1588 break;
1589
1590 case TGSI_OPCODE_ENDIF:
1591 lp_exec_mask_cond_pop(&bld->exec_mask);
1592 break;
1593
1594 case TGSI_OPCODE_ENDLOOP:
1595 lp_exec_endloop(&bld->exec_mask);
1596 break;
1597
1598 case TGSI_OPCODE_PUSHA:
1599 /* deprecated? */
1600 assert(0);
1601 return FALSE;
1602 break;
1603
1604 case TGSI_OPCODE_POPA:
1605 /* deprecated? */
1606 assert(0);
1607 return FALSE;
1608 break;
1609
1610 case TGSI_OPCODE_CEIL:
1611 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1612 tmp0 = emit_fetch( bld, inst, 0, chan_index );
1613 dst0[chan_index] = lp_build_ceil(&bld->base, tmp0);
1614 }
1615 break;
1616
1617 case TGSI_OPCODE_I2F:
1618 /* deprecated? */
1619 assert(0);
1620 return FALSE;
1621 break;
1622
1623 case TGSI_OPCODE_NOT:
1624 /* deprecated? */
1625 assert(0);
1626 return FALSE;
1627 break;
1628
1629 case TGSI_OPCODE_TRUNC:
1630 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1631 tmp0 = emit_fetch( bld, inst, 0, chan_index );
1632 dst0[chan_index] = lp_build_trunc(&bld->base, tmp0);
1633 }
1634 break;
1635
1636 case TGSI_OPCODE_SHL:
1637 /* deprecated? */
1638 assert(0);
1639 return FALSE;
1640 break;
1641
1642 case TGSI_OPCODE_ISHR:
1643 /* deprecated? */
1644 assert(0);
1645 return FALSE;
1646 break;
1647
1648 case TGSI_OPCODE_AND:
1649 /* deprecated? */
1650 assert(0);
1651 return FALSE;
1652 break;
1653
1654 case TGSI_OPCODE_OR:
1655 /* deprecated? */
1656 assert(0);
1657 return FALSE;
1658 break;
1659
1660 case TGSI_OPCODE_MOD:
1661 /* deprecated? */
1662 assert(0);
1663 return FALSE;
1664 break;
1665
1666 case TGSI_OPCODE_XOR:
1667 /* deprecated? */
1668 assert(0);
1669 return FALSE;
1670 break;
1671
1672 case TGSI_OPCODE_SAD:
1673 /* deprecated? */
1674 assert(0);
1675 return FALSE;
1676 break;
1677
1678 case TGSI_OPCODE_TXF:
1679 /* deprecated? */
1680 assert(0);
1681 return FALSE;
1682 break;
1683
1684 case TGSI_OPCODE_TXQ:
1685 /* deprecated? */
1686 assert(0);
1687 return FALSE;
1688 break;
1689
1690 case TGSI_OPCODE_CONT:
1691 lp_exec_continue(&bld->exec_mask);
1692 break;
1693
1694 case TGSI_OPCODE_EMIT:
1695 return FALSE;
1696 break;
1697
1698 case TGSI_OPCODE_ENDPRIM:
1699 return FALSE;
1700 break;
1701
1702 case TGSI_OPCODE_NOP:
1703 break;
1704
1705 default:
1706 return FALSE;
1707 }
1708
1709 if(info->num_dst) {
1710 FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) {
1711 emit_store( bld, inst, 0, chan_index, dst0[chan_index]);
1712 }
1713 }
1714
1715 return TRUE;
1716 }
1717
1718
1719 void
1720 lp_build_tgsi_soa(LLVMBuilderRef builder,
1721 const struct tgsi_token *tokens,
1722 struct lp_type type,
1723 struct lp_build_mask_context *mask,
1724 LLVMValueRef consts_ptr,
1725 const LLVMValueRef *pos,
1726 const LLVMValueRef (*inputs)[NUM_CHANNELS],
1727 LLVMValueRef (*outputs)[NUM_CHANNELS],
1728 struct lp_build_sampler_soa *sampler,
1729 struct tgsi_shader_info *info)
1730 {
1731 struct lp_build_tgsi_soa_context bld;
1732 struct tgsi_parse_context parse;
1733 uint num_immediates = 0;
1734 unsigned i;
1735
1736 /* Setup build context */
1737 memset(&bld, 0, sizeof bld);
1738 lp_build_context_init(&bld.base, builder, type);
1739 bld.mask = mask;
1740 bld.pos = pos;
1741 bld.inputs = inputs;
1742 bld.outputs = outputs;
1743 bld.consts_ptr = consts_ptr;
1744 bld.sampler = sampler;
1745 bld.has_indirect_addressing = info->opcode_count[TGSI_OPCODE_ARR] > 0 ||
1746 info->opcode_count[TGSI_OPCODE_ARL] > 0;
1747
1748 lp_exec_mask_init(&bld.exec_mask, &bld.base);
1749
1750 tgsi_parse_init( &parse, tokens );
1751
1752 while( !tgsi_parse_end_of_tokens( &parse ) ) {
1753 tgsi_parse_token( &parse );
1754
1755 switch( parse.FullToken.Token.Type ) {
1756 case TGSI_TOKEN_TYPE_DECLARATION:
1757 /* Inputs already interpolated */
1758 {
1759 if (!emit_declaration( &bld, &parse.FullToken.FullDeclaration ))
1760 _debug_printf("warning: failed to define LLVM variable\n");
1761 }
1762 break;
1763
1764 case TGSI_TOKEN_TYPE_INSTRUCTION:
1765 {
1766 unsigned opcode = parse.FullToken.FullInstruction.Instruction.Opcode;
1767 const struct tgsi_opcode_info *opcode_info = tgsi_get_opcode_info(opcode);
1768 if (!emit_instruction( &bld, &parse.FullToken.FullInstruction, opcode_info ))
1769 _debug_printf("warning: failed to translate tgsi opcode %s to LLVM\n",
1770 opcode_info->mnemonic);
1771 }
1772
1773 break;
1774
1775 case TGSI_TOKEN_TYPE_IMMEDIATE:
1776 /* simply copy the immediate values into the next immediates[] slot */
1777 {
1778 const uint size = parse.FullToken.FullImmediate.Immediate.NrTokens - 1;
1779 assert(size <= 4);
1780 assert(num_immediates < LP_MAX_IMMEDIATES);
1781 for( i = 0; i < size; ++i )
1782 bld.immediates[num_immediates][i] =
1783 lp_build_const_vec(type, parse.FullToken.FullImmediate.u[i].Float);
1784 for( i = size; i < 4; ++i )
1785 bld.immediates[num_immediates][i] = bld.base.undef;
1786 num_immediates++;
1787 }
1788 break;
1789
1790 case TGSI_TOKEN_TYPE_PROPERTY:
1791 break;
1792
1793 default:
1794 assert( 0 );
1795 }
1796 }
1797 if (0) {
1798 LLVMBasicBlockRef block = LLVMGetInsertBlock(builder);
1799 LLVMValueRef function = LLVMGetBasicBlockParent(block);
1800 debug_printf("11111111111111111111111111111 \n");
1801 tgsi_dump(tokens, 0);
1802 LLVMDumpValue(function);
1803 debug_printf("2222222222222222222222222222 \n");
1804 }
1805 tgsi_parse_free( &parse );
1806 }
1807