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