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