1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
4 * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
31 * TGSI to LLVM IR translation -- SoA.
33 * @author Jose Fonseca <jfonseca@vmware.com>
35 * Based on tgsi_sse2.c code written by Michal Krol, Keith Whitwell,
36 * Brian Paul, and others.
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_info.h"
45 #include "tgsi/tgsi_parse.h"
46 #include "tgsi/tgsi_util.h"
47 #include "tgsi/tgsi_exec.h"
48 #include "lp_bld_type.h"
49 #include "lp_bld_const.h"
50 #include "lp_bld_intr.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"
59 #define LP_MAX_TEMPS 256
60 #define LP_MAX_IMMEDIATES 256
63 #define FOR_EACH_CHANNEL( CHAN )\
64 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)
66 #define IS_DST0_CHANNEL_ENABLED( INST, CHAN )\
67 ((INST)->Dst[0].Register.WriteMask & (1 << (CHAN)))
69 #define IF_IS_DST0_CHANNEL_ENABLED( INST, CHAN )\
70 if (IS_DST0_CHANNEL_ENABLED( INST, CHAN ))
72 #define FOR_EACH_DST0_ENABLED_CHANNEL( INST, CHAN )\
73 FOR_EACH_CHANNEL( CHAN )\
74 IF_IS_DST0_CHANNEL_ENABLED( INST, CHAN )
81 #define QUAD_TOP_LEFT 0
82 #define QUAD_TOP_RIGHT 1
83 #define QUAD_BOTTOM_LEFT 2
84 #define QUAD_BOTTOM_RIGHT 3
87 struct lp_build_tgsi_soa_context
89 struct lp_build_context base
;
91 LLVMValueRef consts_ptr
;
92 const LLVMValueRef
*pos
;
93 const LLVMValueRef (*inputs
)[NUM_CHANNELS
];
94 LLVMValueRef (*outputs
)[NUM_CHANNELS
];
96 struct lp_build_sampler_soa
*sampler
;
98 LLVMValueRef immediates
[LP_MAX_IMMEDIATES
][NUM_CHANNELS
];
99 LLVMValueRef temps
[LP_MAX_TEMPS
][NUM_CHANNELS
];
101 struct lp_build_mask_context
*mask
;
105 static const unsigned char
107 QUAD_TOP_LEFT
, QUAD_TOP_LEFT
,
108 QUAD_BOTTOM_LEFT
, QUAD_BOTTOM_LEFT
111 static const unsigned char
113 QUAD_TOP_RIGHT
, QUAD_TOP_RIGHT
,
114 QUAD_BOTTOM_RIGHT
, QUAD_BOTTOM_RIGHT
117 static const unsigned char
119 QUAD_TOP_LEFT
, QUAD_TOP_RIGHT
,
120 QUAD_TOP_LEFT
, QUAD_TOP_RIGHT
123 static const unsigned char
124 swizzle_bottom
[4] = {
125 QUAD_BOTTOM_LEFT
, QUAD_BOTTOM_RIGHT
,
126 QUAD_BOTTOM_LEFT
, QUAD_BOTTOM_RIGHT
131 emit_ddx(struct lp_build_tgsi_soa_context
*bld
,
134 LLVMValueRef src_left
= lp_build_swizzle1_aos(&bld
->base
, src
, swizzle_left
);
135 LLVMValueRef src_right
= lp_build_swizzle1_aos(&bld
->base
, src
, swizzle_right
);
136 return lp_build_sub(&bld
->base
, src_right
, src_left
);
141 emit_ddy(struct lp_build_tgsi_soa_context
*bld
,
144 LLVMValueRef src_top
= lp_build_swizzle1_aos(&bld
->base
, src
, swizzle_top
);
145 LLVMValueRef src_bottom
= lp_build_swizzle1_aos(&bld
->base
, src
, swizzle_bottom
);
146 return lp_build_sub(&bld
->base
, src_top
, src_bottom
);
155 struct lp_build_tgsi_soa_context
*bld
,
156 const struct tgsi_full_instruction
*inst
,
158 const unsigned chan_index
)
160 const struct tgsi_full_src_register
*reg
= &inst
->Src
[index
];
161 unsigned swizzle
= tgsi_util_get_full_src_register_swizzle( reg
, chan_index
);
170 switch (reg
->Register
.File
) {
171 case TGSI_FILE_CONSTANT
: {
172 LLVMValueRef index
= LLVMConstInt(LLVMInt32Type(), reg
->Register
.Index
*4 + swizzle
, 0);
173 LLVMValueRef scalar_ptr
= LLVMBuildGEP(bld
->base
.builder
, bld
->consts_ptr
, &index
, 1, "");
174 LLVMValueRef scalar
= LLVMBuildLoad(bld
->base
.builder
, scalar_ptr
, "");
175 res
= lp_build_broadcast_scalar(&bld
->base
, scalar
);
179 case TGSI_FILE_IMMEDIATE
:
180 res
= bld
->immediates
[reg
->Register
.Index
][swizzle
];
184 case TGSI_FILE_INPUT
:
185 res
= bld
->inputs
[reg
->Register
.Index
][swizzle
];
189 case TGSI_FILE_TEMPORARY
:
190 res
= bld
->temps
[reg
->Register
.Index
][swizzle
];
192 return bld
->base
.undef
;
197 return bld
->base
.undef
;
203 return bld
->base
.undef
;
206 switch( tgsi_util_get_full_src_register_sign_mode( reg
, chan_index
) ) {
207 case TGSI_UTIL_SIGN_CLEAR
:
208 res
= lp_build_abs( &bld
->base
, res
);
211 case TGSI_UTIL_SIGN_SET
:
212 /* TODO: Use bitwese OR for floating point */
213 res
= lp_build_abs( &bld
->base
, res
);
214 res
= LLVMBuildNeg( bld
->base
.builder
, res
, "" );
217 case TGSI_UTIL_SIGN_TOGGLE
:
218 res
= LLVMBuildNeg( bld
->base
.builder
, res
, "" );
221 case TGSI_UTIL_SIGN_KEEP
:
230 * Register fetch with derivatives.
234 struct lp_build_tgsi_soa_context
*bld
,
235 const struct tgsi_full_instruction
*inst
,
237 const unsigned chan_index
,
244 src
= emit_fetch(bld
, inst
, index
, chan_index
);
249 /* TODO: use interpolation coeffs for inputs */
252 *ddx
= emit_ddx(bld
, src
);
255 *ddy
= emit_ddy(bld
, src
);
264 struct lp_build_tgsi_soa_context
*bld
,
265 const struct tgsi_full_instruction
*inst
,
270 const struct tgsi_full_dst_register
*reg
= &inst
->Dst
[index
];
272 switch( inst
->Instruction
.Saturate
) {
276 case TGSI_SAT_ZERO_ONE
:
277 value
= lp_build_max(&bld
->base
, value
, bld
->base
.zero
);
278 value
= lp_build_min(&bld
->base
, value
, bld
->base
.one
);
281 case TGSI_SAT_MINUS_PLUS_ONE
:
282 value
= lp_build_max(&bld
->base
, value
, lp_build_const_scalar(bld
->base
.type
, -1.0));
283 value
= lp_build_min(&bld
->base
, value
, bld
->base
.one
);
290 switch( reg
->Register
.File
) {
291 case TGSI_FILE_OUTPUT
:
292 bld
->outputs
[reg
->Register
.Index
][chan_index
] = value
;
295 case TGSI_FILE_TEMPORARY
:
296 bld
->temps
[reg
->Register
.Index
][chan_index
] = value
;
299 case TGSI_FILE_ADDRESS
:
311 * High-level instruction translators.
316 emit_tex( struct lp_build_tgsi_soa_context
*bld
,
317 const struct tgsi_full_instruction
*inst
,
318 boolean apply_lodbias
,
322 const uint unit
= inst
->Src
[1].Register
.Index
;
323 LLVMValueRef lodbias
;
325 LLVMValueRef coords
[3];
329 switch (inst
->Texture
.Texture
) {
330 case TGSI_TEXTURE_1D
:
333 case TGSI_TEXTURE_2D
:
334 case TGSI_TEXTURE_RECT
:
337 case TGSI_TEXTURE_SHADOW1D
:
338 case TGSI_TEXTURE_SHADOW2D
:
339 case TGSI_TEXTURE_SHADOWRECT
:
340 case TGSI_TEXTURE_3D
:
341 case TGSI_TEXTURE_CUBE
:
350 lodbias
= emit_fetch( bld
, inst
, 0, 3 );
352 lodbias
= bld
->base
.zero
;
355 oow
= emit_fetch( bld
, inst
, 0, 3 );
356 oow
= lp_build_rcp(&bld
->base
, oow
);
359 for (i
= 0; i
< num_coords
; i
++) {
360 coords
[i
] = emit_fetch( bld
, inst
, 0, i
);
362 coords
[i
] = lp_build_mul(&bld
->base
, coords
[i
], oow
);
365 bld
->sampler
->emit_fetch_texel(bld
->sampler
,
368 unit
, num_coords
, coords
, lodbias
,
375 struct lp_build_tgsi_soa_context
*bld
,
376 const struct tgsi_full_instruction
*inst
)
378 const struct tgsi_full_src_register
*reg
= &inst
->Src
[0];
379 LLVMValueRef terms
[NUM_CHANNELS
];
383 memset(&terms
, 0, sizeof terms
);
385 FOR_EACH_CHANNEL( chan_index
) {
388 /* Unswizzle channel */
389 swizzle
= tgsi_util_get_full_src_register_swizzle( reg
, chan_index
);
391 /* Check if the component has not been already tested. */
392 assert(swizzle
< NUM_CHANNELS
);
393 if( !terms
[swizzle
] )
394 /* TODO: change the comparison operator instead of setting the sign */
395 terms
[swizzle
] = emit_fetch(bld
, inst
, 0, chan_index
);
399 FOR_EACH_CHANNEL( chan_index
) {
400 if(terms
[chan_index
]) {
401 LLVMValueRef chan_mask
;
403 chan_mask
= lp_build_cmp(&bld
->base
, PIPE_FUNC_GEQUAL
, terms
[chan_index
], bld
->base
.zero
);
406 mask
= LLVMBuildAnd(bld
->base
.builder
, mask
, chan_mask
, "");
413 lp_build_mask_update(bld
->mask
, mask
);
418 * Check if inst src/dest regs use indirect addressing into temporary
422 indirect_temp_reference(const struct tgsi_full_instruction
*inst
)
425 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
426 const struct tgsi_full_src_register
*reg
= &inst
->Src
[i
];
427 if (reg
->Register
.File
== TGSI_FILE_TEMPORARY
&&
428 reg
->Register
.Indirect
)
431 for (i
= 0; i
< inst
->Instruction
.NumDstRegs
; i
++) {
432 const struct tgsi_full_dst_register
*reg
= &inst
->Dst
[i
];
433 if (reg
->Register
.File
== TGSI_FILE_TEMPORARY
&&
434 reg
->Register
.Indirect
)
443 struct lp_build_tgsi_soa_context
*bld
,
444 const struct tgsi_full_instruction
*inst
,
445 const struct tgsi_opcode_info
*info
)
448 LLVMValueRef src0
, src1
, src2
;
449 LLVMValueRef tmp0
, tmp1
, tmp2
, tmp3
, tmp4
, tmp5
, tmp6
, tmp7
;
451 LLVMValueRef dst0
[NUM_CHANNELS
];
453 /* we can't handle indirect addressing into temp register file yet */
454 if (indirect_temp_reference(inst
))
457 assert(info
->num_dst
<= 1);
459 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
460 dst0
[chan_index
] = bld
->base
.undef
;
464 switch (inst
->Instruction
.Opcode
) {
466 case TGSI_OPCODE_ARL
:
468 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
469 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
472 dst0
[chan_index
] = tmp0
;
477 case TGSI_OPCODE_MOV
:
478 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
479 dst0
[chan_index
] = emit_fetch( bld
, inst
, 0, chan_index
);
483 case TGSI_OPCODE_LIT
:
484 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ) {
485 dst0
[CHAN_X
] = bld
->base
.one
;
487 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ) {
488 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
489 dst0
[CHAN_Y
] = lp_build_max( &bld
->base
, src0
, bld
->base
.zero
);
491 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) ) {
492 /* XMM[1] = SrcReg[0].yyyy */
493 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
494 /* XMM[1] = max(XMM[1], 0) */
495 tmp1
= lp_build_max( &bld
->base
, tmp1
, bld
->base
.zero
);
496 /* XMM[2] = SrcReg[0].wwww */
497 tmp2
= emit_fetch( bld
, inst
, 0, CHAN_W
);
498 tmp1
= lp_build_pow( &bld
->base
, tmp1
, tmp2
);
499 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
500 tmp2
= lp_build_cmp(&bld
->base
, PIPE_FUNC_GREATER
, tmp0
, bld
->base
.zero
);
501 dst0
[CHAN_Z
] = lp_build_select(&bld
->base
, tmp2
, tmp1
, bld
->base
.zero
);
503 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) ) {
504 dst0
[CHAN_W
] = bld
->base
.one
;
508 case TGSI_OPCODE_RCP
:
509 /* TGSI_OPCODE_RECIP */
510 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
511 res
= lp_build_rcp(&bld
->base
, src0
);
512 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
513 dst0
[chan_index
] = res
;
517 case TGSI_OPCODE_RSQ
:
518 /* TGSI_OPCODE_RECIPSQRT */
519 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
520 src0
= lp_build_abs(&bld
->base
, src0
);
521 res
= lp_build_rsqrt(&bld
->base
, src0
);
522 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
523 dst0
[chan_index
] = res
;
527 case TGSI_OPCODE_EXP
:
528 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
529 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ||
530 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
)) {
531 LLVMValueRef
*p_exp2_int_part
= NULL
;
532 LLVMValueRef
*p_frac_part
= NULL
;
533 LLVMValueRef
*p_exp2
= NULL
;
535 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
537 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
538 p_exp2_int_part
= &tmp0
;
539 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
))
541 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
544 lp_build_exp2_approx(&bld
->base
, src0
, p_exp2_int_part
, p_frac_part
, p_exp2
);
546 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
548 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
))
550 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
554 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
)) {
555 dst0
[CHAN_W
] = bld
->base
.one
;
559 case TGSI_OPCODE_LOG
:
560 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
561 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ||
562 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
)) {
563 LLVMValueRef
*p_floor_log2
;
565 LLVMValueRef
*p_log2
;
567 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
568 src0
= lp_build_abs( &bld
->base
, src0
);
570 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
571 p_floor_log2
= &tmp0
;
572 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
))
574 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
577 lp_build_log2_approx(&bld
->base
, src0
, p_exp
, p_floor_log2
, p_log2
);
579 /* dst.x = floor(lg2(abs(src.x))) */
580 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
582 /* dst.y = abs(src)/ex2(floor(lg2(abs(src.x)))) */
583 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
)) {
584 dst0
[CHAN_Y
] = lp_build_div( &bld
->base
, src0
, tmp1
);
586 /* dst.z = lg2(abs(src.x)) */
587 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
591 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
)) {
592 dst0
[CHAN_W
] = bld
->base
.one
;
596 case TGSI_OPCODE_MUL
:
597 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
598 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
599 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
600 dst0
[chan_index
] = lp_build_mul(&bld
->base
, src0
, src1
);
604 case TGSI_OPCODE_ADD
:
605 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
606 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
607 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
608 dst0
[chan_index
] = lp_build_add(&bld
->base
, src0
, src1
);
612 case TGSI_OPCODE_DP3
:
613 /* TGSI_OPCODE_DOT3 */
614 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
615 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
616 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
617 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
618 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
619 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
620 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
621 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
622 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
623 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
624 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
625 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
626 dst0
[chan_index
] = tmp0
;
630 case TGSI_OPCODE_DP4
:
631 /* TGSI_OPCODE_DOT4 */
632 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
633 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
634 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
635 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
636 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
637 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
638 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
639 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
640 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
641 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
642 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
643 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_W
);
644 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_W
);
645 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
646 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
647 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
648 dst0
[chan_index
] = tmp0
;
652 case TGSI_OPCODE_DST
:
653 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) {
654 dst0
[CHAN_X
] = bld
->base
.one
;
656 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) {
657 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
658 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
659 dst0
[CHAN_Y
] = lp_build_mul( &bld
->base
, tmp0
, tmp1
);
661 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) {
662 dst0
[CHAN_Z
] = emit_fetch( bld
, inst
, 0, CHAN_Z
);
664 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) {
665 dst0
[CHAN_W
] = emit_fetch( bld
, inst
, 1, CHAN_W
);
669 case TGSI_OPCODE_MIN
:
670 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
671 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
672 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
673 dst0
[chan_index
] = lp_build_min( &bld
->base
, src0
, src1
);
677 case TGSI_OPCODE_MAX
:
678 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
679 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
680 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
681 dst0
[chan_index
] = lp_build_max( &bld
->base
, src0
, src1
);
685 case TGSI_OPCODE_SLT
:
686 /* TGSI_OPCODE_SETLT */
687 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
688 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
689 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
690 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_LESS
, src0
, src1
);
691 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
695 case TGSI_OPCODE_SGE
:
696 /* TGSI_OPCODE_SETGE */
697 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
698 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
699 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
700 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_GEQUAL
, src0
, src1
);
701 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
705 case TGSI_OPCODE_MAD
:
706 /* TGSI_OPCODE_MADD */
707 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
708 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
709 tmp1
= emit_fetch( bld
, inst
, 1, chan_index
);
710 tmp2
= emit_fetch( bld
, inst
, 2, chan_index
);
711 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
712 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp2
);
713 dst0
[chan_index
] = tmp0
;
717 case TGSI_OPCODE_SUB
:
718 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
719 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
720 tmp1
= emit_fetch( bld
, inst
, 1, chan_index
);
721 dst0
[chan_index
] = lp_build_sub( &bld
->base
, tmp0
, tmp1
);
725 case TGSI_OPCODE_LRP
:
726 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
727 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
728 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
729 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
730 tmp0
= lp_build_sub( &bld
->base
, src1
, src2
);
731 tmp0
= lp_build_mul( &bld
->base
, src0
, tmp0
);
732 dst0
[chan_index
] = lp_build_add( &bld
->base
, tmp0
, src2
);
736 case TGSI_OPCODE_CND
:
737 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
738 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
739 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
740 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
741 tmp1
= lp_build_const_scalar(bld
->base
.type
, 0.5);
742 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_GREATER
, src2
, tmp1
);
743 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, src0
, src1
);
747 case TGSI_OPCODE_DP2A
:
748 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
); /* xmm0 = src[0].x */
749 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
); /* xmm1 = src[1].x */
750 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 * xmm1 */
751 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
); /* xmm1 = src[0].y */
752 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
); /* xmm2 = src[1].y */
753 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
); /* xmm1 = xmm1 * xmm2 */
754 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 + xmm1 */
755 tmp1
= emit_fetch( bld
, inst
, 2, CHAN_X
); /* xmm1 = src[2].x */
756 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 + xmm1 */
757 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
758 dst0
[chan_index
] = tmp0
; /* dest[ch] = xmm0 */
762 case TGSI_OPCODE_FRC
:
763 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
764 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
765 tmp0
= lp_build_floor(&bld
->base
, src0
);
766 tmp0
= lp_build_sub(&bld
->base
, tmp0
, src0
);
767 dst0
[chan_index
] = tmp0
;
771 case TGSI_OPCODE_CLAMP
:
772 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
773 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
774 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
775 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
776 tmp0
= lp_build_max(&bld
->base
, tmp0
, src1
);
777 tmp0
= lp_build_min(&bld
->base
, tmp0
, src2
);
778 dst0
[chan_index
] = tmp0
;
782 case TGSI_OPCODE_FLR
:
783 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
784 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
785 dst0
[chan_index
] = lp_build_floor(&bld
->base
, tmp0
);
789 case TGSI_OPCODE_ROUND
:
790 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
791 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
792 dst0
[chan_index
] = lp_build_round(&bld
->base
, tmp0
);
796 case TGSI_OPCODE_EX2
: {
797 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
798 tmp0
= lp_build_exp2( &bld
->base
, tmp0
);
799 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
800 dst0
[chan_index
] = tmp0
;
805 case TGSI_OPCODE_LG2
:
806 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
807 tmp0
= lp_build_log2( &bld
->base
, tmp0
);
808 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
809 dst0
[chan_index
] = tmp0
;
813 case TGSI_OPCODE_POW
:
814 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
815 src1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
816 res
= lp_build_pow( &bld
->base
, src0
, src1
);
817 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
818 dst0
[chan_index
] = res
;
822 case TGSI_OPCODE_XPD
:
823 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
824 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ) {
825 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
826 tmp3
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
828 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
829 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) ) {
830 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
831 tmp4
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
833 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) {
835 tmp2
= lp_build_mul( &bld
->base
, tmp2
, tmp1
);
837 tmp5
= lp_build_mul( &bld
->base
, tmp5
, tmp4
);
838 tmp2
= lp_build_sub( &bld
->base
, tmp2
, tmp5
);
841 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ||
842 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) ) {
843 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_X
);
844 tmp5
= emit_fetch( bld
, inst
, 0, CHAN_X
);
846 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) {
847 tmp3
= lp_build_mul( &bld
->base
, tmp3
, tmp2
);
848 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp5
);
849 tmp3
= lp_build_sub( &bld
->base
, tmp3
, tmp1
);
852 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) {
853 tmp5
= lp_build_mul( &bld
->base
, tmp5
, tmp4
);
854 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp2
);
855 tmp5
= lp_build_sub( &bld
->base
, tmp5
, tmp0
);
858 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) {
859 dst0
[CHAN_W
] = bld
->base
.one
;
863 case TGSI_OPCODE_ABS
:
864 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
865 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
866 dst0
[chan_index
] = lp_build_abs( &bld
->base
, tmp0
);
870 case TGSI_OPCODE_RCC
:
875 case TGSI_OPCODE_DPH
:
876 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
877 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
878 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
879 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
880 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
881 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
882 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
883 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
884 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
885 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
886 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
887 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_W
);
888 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
889 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
890 dst0
[chan_index
] = tmp0
;
894 case TGSI_OPCODE_COS
:
895 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
896 tmp0
= lp_build_cos( &bld
->base
, tmp0
);
897 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
898 dst0
[chan_index
] = tmp0
;
902 case TGSI_OPCODE_DDX
:
903 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
904 emit_fetch_deriv( bld
, inst
, 0, chan_index
, NULL
, &dst0
[chan_index
], NULL
);
908 case TGSI_OPCODE_DDY
:
909 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
910 emit_fetch_deriv( bld
, inst
, 0, chan_index
, NULL
, NULL
, &dst0
[chan_index
]);
914 case TGSI_OPCODE_KILP
:
915 /* predicated kill */
920 case TGSI_OPCODE_KIL
:
921 /* conditional kill */
922 emit_kil( bld
, inst
);
925 case TGSI_OPCODE_PK2H
:
929 case TGSI_OPCODE_PK2US
:
933 case TGSI_OPCODE_PK4B
:
937 case TGSI_OPCODE_PK4UB
:
941 case TGSI_OPCODE_RFL
:
945 case TGSI_OPCODE_SEQ
:
946 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
947 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
948 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
949 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_EQUAL
, src0
, src1
);
950 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
954 case TGSI_OPCODE_SFL
:
955 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
956 dst0
[chan_index
] = bld
->base
.zero
;
960 case TGSI_OPCODE_SGT
:
961 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
962 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
963 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
964 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_GREATER
, src0
, src1
);
965 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
969 case TGSI_OPCODE_SIN
:
970 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
971 tmp0
= lp_build_sin( &bld
->base
, tmp0
);
972 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
973 dst0
[chan_index
] = tmp0
;
977 case TGSI_OPCODE_SLE
:
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 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_LEQUAL
, src0
, src1
);
982 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
986 case TGSI_OPCODE_SNE
:
987 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
988 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
989 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
990 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_NOTEQUAL
, src0
, src1
);
991 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
995 case TGSI_OPCODE_STR
:
996 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
997 dst0
[chan_index
] = bld
->base
.one
;
1001 case TGSI_OPCODE_TEX
:
1002 emit_tex( bld
, inst
, FALSE
, FALSE
, dst0
);
1005 case TGSI_OPCODE_TXD
:
1010 case TGSI_OPCODE_UP2H
:
1016 case TGSI_OPCODE_UP2US
:
1022 case TGSI_OPCODE_UP4B
:
1028 case TGSI_OPCODE_UP4UB
:
1034 case TGSI_OPCODE_X2D
:
1040 case TGSI_OPCODE_ARA
:
1047 case TGSI_OPCODE_ARR
:
1049 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1050 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
1051 emit_rnd( bld
, 0, 0 );
1052 emit_f2it( bld
, 0 );
1053 dst0
[chan_index
] = tmp0
;
1058 case TGSI_OPCODE_BRA
:
1064 case TGSI_OPCODE_CAL
:
1069 case TGSI_OPCODE_RET
:
1074 case TGSI_OPCODE_END
:
1077 case TGSI_OPCODE_SSG
:
1078 /* TGSI_OPCODE_SGN */
1079 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1080 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
1081 dst0
[chan_index
] = lp_build_sgn( &bld
->base
, tmp0
);
1085 case TGSI_OPCODE_CMP
:
1086 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1087 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
1088 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
1089 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
1090 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_LESS
, src0
, bld
->base
.zero
);
1091 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, src1
, src2
);
1095 case TGSI_OPCODE_SCS
:
1096 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) {
1097 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
1098 dst0
[CHAN_X
] = lp_build_cos( &bld
->base
, tmp0
);
1100 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) {
1101 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
1102 dst0
[CHAN_Y
] = lp_build_sin( &bld
->base
, tmp0
);
1104 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) {
1105 dst0
[CHAN_Z
] = bld
->base
.zero
;
1107 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) {
1108 dst0
[CHAN_W
] = bld
->base
.one
;
1112 case TGSI_OPCODE_TXB
:
1113 emit_tex( bld
, inst
, TRUE
, FALSE
, dst0
);
1116 case TGSI_OPCODE_NRM
:
1118 case TGSI_OPCODE_NRM4
:
1119 /* 3 or 4-component normalization */
1121 uint dims
= (inst
->Instruction
.Opcode
== TGSI_OPCODE_NRM
) ? 3 : 4;
1123 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
) ||
1124 IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Y
) ||
1125 IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Z
) ||
1126 (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_W
) && dims
== 4)) {
1128 /* NOTE: Cannot use xmm regs 2/3 here (see emit_rsqrt() above). */
1131 /* xmm0 = src.x * src.x */
1132 tmp0
= emit_fetch(bld
, inst
, 0, CHAN_X
);
1133 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
)) {
1136 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp0
);
1139 /* xmm0 = xmm0 + src.y * src.y */
1140 tmp1
= emit_fetch(bld
, inst
, 0, CHAN_Y
);
1141 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Y
)) {
1144 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp1
);
1145 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
1148 /* xmm0 = xmm0 + src.z * src.z */
1149 tmp1
= emit_fetch(bld
, inst
, 0, CHAN_Z
);
1150 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Z
)) {
1153 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp1
);
1154 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
1158 /* xmm0 = xmm0 + src.w * src.w */
1159 tmp1
= emit_fetch(bld
, inst
, 0, CHAN_W
);
1160 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_W
)) {
1163 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp1
);
1164 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
1167 /* xmm1 = 1 / sqrt(xmm0) */
1168 tmp1
= lp_build_rsqrt( &bld
->base
, tmp0
);
1170 /* dst.x = xmm1 * src.x */
1171 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
)) {
1172 dst0
[CHAN_X
] = lp_build_mul( &bld
->base
, tmp4
, tmp1
);
1175 /* dst.y = xmm1 * src.y */
1176 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Y
)) {
1177 dst0
[CHAN_Y
] = lp_build_mul( &bld
->base
, tmp5
, tmp1
);
1180 /* dst.z = xmm1 * src.z */
1181 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Z
)) {
1182 dst0
[CHAN_Z
] = lp_build_mul( &bld
->base
, tmp6
, tmp1
);
1185 /* dst.w = xmm1 * src.w */
1186 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
) && dims
== 4) {
1187 dst0
[CHAN_W
] = lp_build_mul( &bld
->base
, tmp7
, tmp1
);
1192 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_W
) && dims
== 3) {
1193 dst0
[CHAN_W
] = bld
->base
.one
;
1198 case TGSI_OPCODE_DIV
:
1204 case TGSI_OPCODE_DP2
:
1205 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
); /* xmm0 = src[0].x */
1206 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
); /* xmm1 = src[1].x */
1207 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 * xmm1 */
1208 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
); /* xmm1 = src[0].y */
1209 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
); /* xmm2 = src[1].y */
1210 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
); /* xmm1 = xmm1 * xmm2 */
1211 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 + xmm1 */
1212 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1213 dst0
[chan_index
] = tmp0
; /* dest[ch] = xmm0 */
1217 case TGSI_OPCODE_TXL
:
1218 emit_tex( bld
, inst
, TRUE
, FALSE
, dst0
);
1221 case TGSI_OPCODE_TXP
:
1222 emit_tex( bld
, inst
, FALSE
, TRUE
, dst0
);
1225 case TGSI_OPCODE_BRK
:
1230 case TGSI_OPCODE_IF
:
1235 case TGSI_OPCODE_BGNFOR
:
1241 case TGSI_OPCODE_REP
:
1247 case TGSI_OPCODE_ELSE
:
1252 case TGSI_OPCODE_ENDIF
:
1257 case TGSI_OPCODE_ENDFOR
:
1263 case TGSI_OPCODE_ENDREP
:
1269 case TGSI_OPCODE_PUSHA
:
1275 case TGSI_OPCODE_POPA
:
1281 case TGSI_OPCODE_CEIL
:
1282 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1283 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
1284 dst0
[chan_index
] = lp_build_ceil(&bld
->base
, tmp0
);
1288 case TGSI_OPCODE_I2F
:
1294 case TGSI_OPCODE_NOT
:
1300 case TGSI_OPCODE_TRUNC
:
1301 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1302 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
1303 dst0
[chan_index
] = lp_build_trunc(&bld
->base
, tmp0
);
1307 case TGSI_OPCODE_SHL
:
1313 case TGSI_OPCODE_SHR
:
1319 case TGSI_OPCODE_AND
:
1325 case TGSI_OPCODE_OR
:
1331 case TGSI_OPCODE_MOD
:
1337 case TGSI_OPCODE_XOR
:
1343 case TGSI_OPCODE_SAD
:
1349 case TGSI_OPCODE_TXF
:
1355 case TGSI_OPCODE_TXQ
:
1361 case TGSI_OPCODE_CONT
:
1367 case TGSI_OPCODE_EMIT
:
1371 case TGSI_OPCODE_ENDPRIM
:
1375 case TGSI_OPCODE_NOP
:
1383 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1384 emit_store( bld
, inst
, 0, chan_index
, dst0
[chan_index
]);
1393 lp_build_tgsi_soa(LLVMBuilderRef builder
,
1394 const struct tgsi_token
*tokens
,
1395 struct lp_type type
,
1396 struct lp_build_mask_context
*mask
,
1397 LLVMValueRef consts_ptr
,
1398 const LLVMValueRef
*pos
,
1399 const LLVMValueRef (*inputs
)[NUM_CHANNELS
],
1400 LLVMValueRef (*outputs
)[NUM_CHANNELS
],
1401 struct lp_build_sampler_soa
*sampler
)
1403 struct lp_build_tgsi_soa_context bld
;
1404 struct tgsi_parse_context parse
;
1405 uint num_immediates
= 0;
1408 /* Setup build context */
1409 memset(&bld
, 0, sizeof bld
);
1410 lp_build_context_init(&bld
.base
, builder
, type
);
1413 bld
.inputs
= inputs
;
1414 bld
.outputs
= outputs
;
1415 bld
.consts_ptr
= consts_ptr
;
1416 bld
.sampler
= sampler
;
1418 tgsi_parse_init( &parse
, tokens
);
1420 while( !tgsi_parse_end_of_tokens( &parse
) ) {
1421 tgsi_parse_token( &parse
);
1423 switch( parse
.FullToken
.Token
.Type
) {
1424 case TGSI_TOKEN_TYPE_DECLARATION
:
1425 /* Inputs already interpolated */
1428 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1430 unsigned opcode
= parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1431 const struct tgsi_opcode_info
*info
= tgsi_get_opcode_info(opcode
);
1432 if (!emit_instruction( &bld
, &parse
.FullToken
.FullInstruction
, info
))
1433 _debug_printf("warning: failed to translate tgsi opcode %s to LLVM\n",
1434 info
? info
->mnemonic
: "<invalid>");
1439 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1440 /* simply copy the immediate values into the next immediates[] slot */
1442 const uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
1444 assert(num_immediates
< LP_MAX_IMMEDIATES
);
1445 for( i
= 0; i
< size
; ++i
)
1446 bld
.immediates
[num_immediates
][i
] =
1447 lp_build_const_scalar(type
, parse
.FullToken
.FullImmediate
.u
[i
].Float
);
1448 for( i
= size
; i
< 4; ++i
)
1449 bld
.immediates
[num_immediates
][i
] = bld
.base
.undef
;
1459 tgsi_parse_free( &parse
);