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)->FullDstRegisters[0].DstRegister.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
->FullSrcRegisters
[index
];
161 unsigned swizzle
= tgsi_util_get_full_src_register_extswizzle( reg
, chan_index
);
165 case TGSI_EXTSWIZZLE_X
:
166 case TGSI_EXTSWIZZLE_Y
:
167 case TGSI_EXTSWIZZLE_Z
:
168 case TGSI_EXTSWIZZLE_W
:
170 switch (reg
->SrcRegister
.File
) {
171 case TGSI_FILE_CONSTANT
: {
172 LLVMValueRef index
= LLVMConstInt(LLVMInt32Type(), reg
->SrcRegister
.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
->SrcRegister
.Index
][swizzle
];
184 case TGSI_FILE_INPUT
:
185 res
= bld
->inputs
[reg
->SrcRegister
.Index
][swizzle
];
189 case TGSI_FILE_TEMPORARY
:
190 res
= bld
->temps
[reg
->SrcRegister
.Index
][swizzle
];
192 return bld
->base
.undef
;
197 return bld
->base
.undef
;
201 case TGSI_EXTSWIZZLE_ZERO
:
202 res
= bld
->base
.zero
;
205 case TGSI_EXTSWIZZLE_ONE
:
211 return bld
->base
.undef
;
214 switch( tgsi_util_get_full_src_register_sign_mode( reg
, chan_index
) ) {
215 case TGSI_UTIL_SIGN_CLEAR
:
216 res
= lp_build_abs( &bld
->base
, res
);
219 case TGSI_UTIL_SIGN_SET
:
220 /* TODO: Use bitwese OR for floating point */
221 res
= lp_build_abs( &bld
->base
, res
);
222 res
= LLVMBuildNeg( bld
->base
.builder
, res
, "" );
225 case TGSI_UTIL_SIGN_TOGGLE
:
226 res
= LLVMBuildNeg( bld
->base
.builder
, res
, "" );
229 case TGSI_UTIL_SIGN_KEEP
:
238 * Register fetch with derivatives.
242 struct lp_build_tgsi_soa_context
*bld
,
243 const struct tgsi_full_instruction
*inst
,
245 const unsigned chan_index
,
252 src
= emit_fetch(bld
, inst
, index
, chan_index
);
257 /* TODO: use interpolation coeffs for inputs */
260 *ddx
= emit_ddx(bld
, src
);
263 *ddy
= emit_ddy(bld
, src
);
272 struct lp_build_tgsi_soa_context
*bld
,
273 const struct tgsi_full_instruction
*inst
,
278 const struct tgsi_full_dst_register
*reg
= &inst
->FullDstRegisters
[index
];
280 switch( inst
->Instruction
.Saturate
) {
284 case TGSI_SAT_ZERO_ONE
:
285 value
= lp_build_max(&bld
->base
, value
, bld
->base
.zero
);
286 value
= lp_build_min(&bld
->base
, value
, bld
->base
.one
);
289 case TGSI_SAT_MINUS_PLUS_ONE
:
290 value
= lp_build_max(&bld
->base
, value
, lp_build_const_scalar(bld
->base
.type
, -1.0));
291 value
= lp_build_min(&bld
->base
, value
, bld
->base
.one
);
298 switch( reg
->DstRegister
.File
) {
299 case TGSI_FILE_OUTPUT
:
300 bld
->outputs
[reg
->DstRegister
.Index
][chan_index
] = value
;
303 case TGSI_FILE_TEMPORARY
:
304 bld
->temps
[reg
->DstRegister
.Index
][chan_index
] = value
;
307 case TGSI_FILE_ADDRESS
:
319 * High-level instruction translators.
324 emit_tex( struct lp_build_tgsi_soa_context
*bld
,
325 const struct tgsi_full_instruction
*inst
,
326 boolean apply_lodbias
,
330 const uint unit
= inst
->FullSrcRegisters
[1].SrcRegister
.Index
;
331 LLVMValueRef lodbias
;
333 LLVMValueRef coords
[3];
337 switch (inst
->InstructionExtTexture
.Texture
) {
338 case TGSI_TEXTURE_1D
:
341 case TGSI_TEXTURE_2D
:
342 case TGSI_TEXTURE_RECT
:
345 case TGSI_TEXTURE_SHADOW1D
:
346 case TGSI_TEXTURE_SHADOW2D
:
347 case TGSI_TEXTURE_SHADOWRECT
:
348 case TGSI_TEXTURE_3D
:
349 case TGSI_TEXTURE_CUBE
:
358 lodbias
= emit_fetch( bld
, inst
, 0, 3 );
360 lodbias
= bld
->base
.zero
;
363 oow
= emit_fetch( bld
, inst
, 0, 3 );
364 oow
= lp_build_rcp(&bld
->base
, oow
);
367 for (i
= 0; i
< num_coords
; i
++) {
368 coords
[i
] = emit_fetch( bld
, inst
, 0, i
);
370 coords
[i
] = lp_build_mul(&bld
->base
, coords
[i
], oow
);
373 bld
->sampler
->emit_fetch_texel(bld
->sampler
,
376 unit
, num_coords
, coords
, lodbias
,
383 struct lp_build_tgsi_soa_context
*bld
,
384 const struct tgsi_full_instruction
*inst
)
386 const struct tgsi_full_src_register
*reg
= &inst
->FullSrcRegisters
[0];
387 LLVMValueRef terms
[NUM_CHANNELS
];
391 memset(&terms
, 0, sizeof terms
);
393 FOR_EACH_CHANNEL( chan_index
) {
396 /* Unswizzle channel */
397 swizzle
= tgsi_util_get_full_src_register_extswizzle( reg
, chan_index
);
399 /* Note that we test if the value is less than zero, so 1.0 and 0.0 need
400 * not to be tested. */
401 if(swizzle
== TGSI_EXTSWIZZLE_ZERO
|| swizzle
== TGSI_EXTSWIZZLE_ONE
)
404 /* Check if the component has not been already tested. */
405 assert(swizzle
< NUM_CHANNELS
);
406 if( !terms
[swizzle
] )
407 /* TODO: change the comparison operator instead of setting the sign */
408 terms
[swizzle
] = emit_fetch(bld
, inst
, 0, chan_index
);
412 FOR_EACH_CHANNEL( chan_index
) {
413 if(terms
[chan_index
]) {
414 LLVMValueRef chan_mask
;
416 chan_mask
= lp_build_cmp(&bld
->base
, PIPE_FUNC_GEQUAL
, terms
[chan_index
], bld
->base
.zero
);
419 mask
= LLVMBuildAnd(bld
->base
.builder
, mask
, chan_mask
, "");
426 lp_build_mask_update(bld
->mask
, mask
);
431 * Check if inst src/dest regs use indirect addressing into temporary
435 indirect_temp_reference(const struct tgsi_full_instruction
*inst
)
438 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
439 const struct tgsi_full_src_register
*reg
= &inst
->FullSrcRegisters
[i
];
440 if (reg
->SrcRegister
.File
== TGSI_FILE_TEMPORARY
&&
441 reg
->SrcRegister
.Indirect
)
444 for (i
= 0; i
< inst
->Instruction
.NumDstRegs
; i
++) {
445 const struct tgsi_full_dst_register
*reg
= &inst
->FullDstRegisters
[i
];
446 if (reg
->DstRegister
.File
== TGSI_FILE_TEMPORARY
&&
447 reg
->DstRegister
.Indirect
)
456 struct lp_build_tgsi_soa_context
*bld
,
457 const struct tgsi_full_instruction
*inst
,
458 const struct tgsi_opcode_info
*info
)
461 LLVMValueRef src0
, src1
, src2
;
462 LLVMValueRef tmp0
, tmp1
, tmp2
, tmp3
, tmp4
, tmp5
, tmp6
, tmp7
;
464 LLVMValueRef dst0
[NUM_CHANNELS
];
466 /* we can't handle indirect addressing into temp register file yet */
467 if (indirect_temp_reference(inst
))
470 assert(info
->num_dst
<= 1);
472 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
473 dst0
[chan_index
] = bld
->base
.undef
;
477 switch (inst
->Instruction
.Opcode
) {
479 case TGSI_OPCODE_ARL
:
481 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
482 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
485 dst0
[chan_index
] = tmp0
;
490 case TGSI_OPCODE_MOV
:
491 case TGSI_OPCODE_SWZ
:
492 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
493 dst0
[chan_index
] = emit_fetch( bld
, inst
, 0, chan_index
);
497 case TGSI_OPCODE_LIT
:
498 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ) {
499 dst0
[CHAN_X
] = bld
->base
.one
;
501 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ) {
502 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
503 dst0
[CHAN_Y
] = lp_build_max( &bld
->base
, src0
, bld
->base
.zero
);
505 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) ) {
506 /* XMM[1] = SrcReg[0].yyyy */
507 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
508 /* XMM[1] = max(XMM[1], 0) */
509 tmp1
= lp_build_max( &bld
->base
, tmp1
, bld
->base
.zero
);
510 /* XMM[2] = SrcReg[0].wwww */
511 tmp2
= emit_fetch( bld
, inst
, 0, CHAN_W
);
512 tmp1
= lp_build_pow( &bld
->base
, tmp1
, tmp2
);
513 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
514 tmp2
= lp_build_cmp(&bld
->base
, PIPE_FUNC_GREATER
, tmp0
, bld
->base
.zero
);
515 dst0
[CHAN_Z
] = lp_build_select(&bld
->base
, tmp2
, tmp1
, bld
->base
.zero
);
517 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) ) {
518 dst0
[CHAN_W
] = bld
->base
.one
;
522 case TGSI_OPCODE_RCP
:
523 /* TGSI_OPCODE_RECIP */
524 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
525 res
= lp_build_rcp(&bld
->base
, src0
);
526 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
527 dst0
[chan_index
] = res
;
531 case TGSI_OPCODE_RSQ
:
532 /* TGSI_OPCODE_RECIPSQRT */
533 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
534 src0
= lp_build_abs(&bld
->base
, src0
);
535 res
= lp_build_rsqrt(&bld
->base
, src0
);
536 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
537 dst0
[chan_index
] = res
;
541 case TGSI_OPCODE_EXP
:
542 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
543 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ||
544 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
)) {
545 LLVMValueRef
*p_exp2_int_part
= NULL
;
546 LLVMValueRef
*p_frac_part
= NULL
;
547 LLVMValueRef
*p_exp2
= NULL
;
549 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
551 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
552 p_exp2_int_part
= &tmp0
;
553 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
))
555 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
558 lp_build_exp2_approx(&bld
->base
, src0
, p_exp2_int_part
, p_frac_part
, p_exp2
);
560 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
562 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
))
564 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
568 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
)) {
569 dst0
[CHAN_W
] = bld
->base
.one
;
573 case TGSI_OPCODE_LOG
:
574 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
575 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ||
576 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
)) {
577 LLVMValueRef
*p_floor_log2
;
579 LLVMValueRef
*p_log2
;
581 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
582 src0
= lp_build_abs( &bld
->base
, src0
);
584 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
585 p_floor_log2
= &tmp0
;
586 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
))
588 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
591 lp_build_log2_approx(&bld
->base
, src0
, p_exp
, p_floor_log2
, p_log2
);
593 /* dst.x = floor(lg2(abs(src.x))) */
594 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
596 /* dst.y = abs(src)/ex2(floor(lg2(abs(src.x)))) */
597 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
)) {
598 dst0
[CHAN_Y
] = lp_build_div( &bld
->base
, src0
, tmp1
);
600 /* dst.z = lg2(abs(src.x)) */
601 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
605 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
)) {
606 dst0
[CHAN_W
] = bld
->base
.one
;
610 case TGSI_OPCODE_MUL
:
611 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
612 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
613 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
614 dst0
[chan_index
] = lp_build_mul(&bld
->base
, src0
, src1
);
618 case TGSI_OPCODE_ADD
:
619 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
620 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
621 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
622 dst0
[chan_index
] = lp_build_add(&bld
->base
, src0
, src1
);
626 case TGSI_OPCODE_DP3
:
627 /* TGSI_OPCODE_DOT3 */
628 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
629 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
630 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
631 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
632 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
633 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
634 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
635 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
636 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
637 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
638 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
639 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
640 dst0
[chan_index
] = tmp0
;
644 case TGSI_OPCODE_DP4
:
645 /* TGSI_OPCODE_DOT4 */
646 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
647 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
648 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
649 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
650 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
651 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
652 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
653 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
654 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
655 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
656 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
657 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_W
);
658 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_W
);
659 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
660 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
661 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
662 dst0
[chan_index
] = tmp0
;
666 case TGSI_OPCODE_DST
:
667 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) {
668 dst0
[CHAN_X
] = bld
->base
.one
;
670 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) {
671 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
672 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
673 dst0
[CHAN_Y
] = lp_build_mul( &bld
->base
, tmp0
, tmp1
);
675 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) {
676 dst0
[CHAN_Z
] = emit_fetch( bld
, inst
, 0, CHAN_Z
);
678 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) {
679 dst0
[CHAN_W
] = emit_fetch( bld
, inst
, 1, CHAN_W
);
683 case TGSI_OPCODE_MIN
:
684 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
685 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
686 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
687 dst0
[chan_index
] = lp_build_min( &bld
->base
, src0
, src1
);
691 case TGSI_OPCODE_MAX
:
692 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
693 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
694 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
695 dst0
[chan_index
] = lp_build_max( &bld
->base
, src0
, src1
);
699 case TGSI_OPCODE_SLT
:
700 /* TGSI_OPCODE_SETLT */
701 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
702 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
703 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
704 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_LESS
, src0
, src1
);
705 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
709 case TGSI_OPCODE_SGE
:
710 /* TGSI_OPCODE_SETGE */
711 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
712 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
713 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
714 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_GEQUAL
, src0
, src1
);
715 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
719 case TGSI_OPCODE_MAD
:
720 /* TGSI_OPCODE_MADD */
721 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
722 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
723 tmp1
= emit_fetch( bld
, inst
, 1, chan_index
);
724 tmp2
= emit_fetch( bld
, inst
, 2, chan_index
);
725 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
726 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp2
);
727 dst0
[chan_index
] = tmp0
;
731 case TGSI_OPCODE_SUB
:
732 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
733 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
734 tmp1
= emit_fetch( bld
, inst
, 1, chan_index
);
735 dst0
[chan_index
] = lp_build_sub( &bld
->base
, tmp0
, tmp1
);
739 case TGSI_OPCODE_LRP
:
740 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
741 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
742 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
743 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
744 tmp0
= lp_build_sub( &bld
->base
, src1
, src2
);
745 tmp0
= lp_build_mul( &bld
->base
, src0
, tmp0
);
746 dst0
[chan_index
] = lp_build_add( &bld
->base
, tmp0
, src2
);
750 case TGSI_OPCODE_CND
:
751 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
752 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
753 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
754 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
755 tmp1
= lp_build_const_scalar(bld
->base
.type
, 0.5);
756 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_GREATER
, src2
, tmp1
);
757 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, src0
, src1
);
761 case TGSI_OPCODE_DP2A
:
762 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
); /* xmm0 = src[0].x */
763 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
); /* xmm1 = src[1].x */
764 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 * xmm1 */
765 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
); /* xmm1 = src[0].y */
766 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
); /* xmm2 = src[1].y */
767 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
); /* xmm1 = xmm1 * xmm2 */
768 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 + xmm1 */
769 tmp1
= emit_fetch( bld
, inst
, 2, CHAN_X
); /* xmm1 = src[2].x */
770 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 + xmm1 */
771 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
772 dst0
[chan_index
] = tmp0
; /* dest[ch] = xmm0 */
776 case TGSI_OPCODE_FRC
:
777 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
778 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
779 tmp0
= lp_build_floor(&bld
->base
, src0
);
780 tmp0
= lp_build_sub(&bld
->base
, tmp0
, src0
);
781 dst0
[chan_index
] = tmp0
;
785 case TGSI_OPCODE_CLAMP
:
786 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
787 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
788 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
789 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
790 tmp0
= lp_build_max(&bld
->base
, tmp0
, src1
);
791 tmp0
= lp_build_min(&bld
->base
, tmp0
, src2
);
792 dst0
[chan_index
] = tmp0
;
796 case TGSI_OPCODE_FLR
:
797 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
798 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
799 dst0
[chan_index
] = lp_build_floor(&bld
->base
, tmp0
);
803 case TGSI_OPCODE_ROUND
:
804 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
805 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
806 dst0
[chan_index
] = lp_build_round(&bld
->base
, tmp0
);
810 case TGSI_OPCODE_EX2
: {
811 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
812 tmp0
= lp_build_exp2( &bld
->base
, tmp0
);
813 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
814 dst0
[chan_index
] = tmp0
;
819 case TGSI_OPCODE_LG2
:
820 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
821 tmp0
= lp_build_log2( &bld
->base
, tmp0
);
822 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
823 dst0
[chan_index
] = tmp0
;
827 case TGSI_OPCODE_POW
:
828 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
829 src1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
830 res
= lp_build_pow( &bld
->base
, src0
, src1
);
831 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
832 dst0
[chan_index
] = res
;
836 case TGSI_OPCODE_XPD
:
837 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
838 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ) {
839 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
840 tmp3
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
842 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
843 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) ) {
844 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
845 tmp4
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
847 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) {
849 tmp2
= lp_build_mul( &bld
->base
, tmp2
, tmp1
);
851 tmp5
= lp_build_mul( &bld
->base
, tmp5
, tmp4
);
852 tmp2
= lp_build_sub( &bld
->base
, tmp2
, tmp5
);
855 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ||
856 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) ) {
857 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_X
);
858 tmp5
= emit_fetch( bld
, inst
, 0, CHAN_X
);
860 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) {
861 tmp3
= lp_build_mul( &bld
->base
, tmp3
, tmp2
);
862 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp5
);
863 tmp3
= lp_build_sub( &bld
->base
, tmp3
, tmp1
);
866 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) {
867 tmp5
= lp_build_mul( &bld
->base
, tmp5
, tmp4
);
868 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp2
);
869 tmp5
= lp_build_sub( &bld
->base
, tmp5
, tmp0
);
872 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) {
873 dst0
[CHAN_W
] = bld
->base
.one
;
877 case TGSI_OPCODE_ABS
:
878 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
879 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
880 dst0
[chan_index
] = lp_build_abs( &bld
->base
, tmp0
);
884 case TGSI_OPCODE_RCC
:
889 case TGSI_OPCODE_DPH
:
890 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
891 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
892 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
893 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
894 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
895 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
896 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
897 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
898 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
899 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
900 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
901 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_W
);
902 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
903 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
904 dst0
[chan_index
] = tmp0
;
908 case TGSI_OPCODE_COS
:
909 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
910 tmp0
= lp_build_cos( &bld
->base
, tmp0
);
911 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
912 dst0
[chan_index
] = tmp0
;
916 case TGSI_OPCODE_DDX
:
917 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
918 emit_fetch_deriv( bld
, inst
, 0, chan_index
, NULL
, &dst0
[chan_index
], NULL
);
922 case TGSI_OPCODE_DDY
:
923 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
924 emit_fetch_deriv( bld
, inst
, 0, chan_index
, NULL
, NULL
, &dst0
[chan_index
]);
928 case TGSI_OPCODE_KILP
:
929 /* predicated kill */
934 case TGSI_OPCODE_KIL
:
935 /* conditional kill */
936 emit_kil( bld
, inst
);
939 case TGSI_OPCODE_PK2H
:
943 case TGSI_OPCODE_PK2US
:
947 case TGSI_OPCODE_PK4B
:
951 case TGSI_OPCODE_PK4UB
:
955 case TGSI_OPCODE_RFL
:
959 case TGSI_OPCODE_SEQ
:
960 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
961 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
962 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
963 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_EQUAL
, src0
, src1
);
964 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
968 case TGSI_OPCODE_SFL
:
969 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
970 dst0
[chan_index
] = bld
->base
.zero
;
974 case TGSI_OPCODE_SGT
:
975 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
976 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
977 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
978 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_GREATER
, src0
, src1
);
979 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
983 case TGSI_OPCODE_SIN
:
984 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
985 tmp0
= lp_build_sin( &bld
->base
, tmp0
);
986 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
987 dst0
[chan_index
] = tmp0
;
991 case TGSI_OPCODE_SLE
:
992 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
993 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
994 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
995 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_LEQUAL
, src0
, src1
);
996 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
1000 case TGSI_OPCODE_SNE
:
1001 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1002 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
1003 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
1004 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_NOTEQUAL
, src0
, src1
);
1005 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
1009 case TGSI_OPCODE_STR
:
1010 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1011 dst0
[chan_index
] = bld
->base
.one
;
1015 case TGSI_OPCODE_TEX
:
1016 emit_tex( bld
, inst
, FALSE
, FALSE
, dst0
);
1019 case TGSI_OPCODE_TXD
:
1024 case TGSI_OPCODE_UP2H
:
1030 case TGSI_OPCODE_UP2US
:
1036 case TGSI_OPCODE_UP4B
:
1042 case TGSI_OPCODE_UP4UB
:
1048 case TGSI_OPCODE_X2D
:
1054 case TGSI_OPCODE_ARA
:
1061 case TGSI_OPCODE_ARR
:
1063 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1064 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
1065 emit_rnd( bld
, 0, 0 );
1066 emit_f2it( bld
, 0 );
1067 dst0
[chan_index
] = tmp0
;
1072 case TGSI_OPCODE_BRA
:
1078 case TGSI_OPCODE_CAL
:
1083 case TGSI_OPCODE_RET
:
1088 case TGSI_OPCODE_END
:
1091 case TGSI_OPCODE_SSG
:
1092 /* TGSI_OPCODE_SGN */
1093 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1094 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
1095 dst0
[chan_index
] = lp_build_sgn( &bld
->base
, tmp0
);
1099 case TGSI_OPCODE_CMP
:
1100 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1101 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
1102 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
1103 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
1104 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_LESS
, src0
, bld
->base
.zero
);
1105 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, src1
, src2
);
1109 case TGSI_OPCODE_SCS
:
1110 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) {
1111 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
1112 dst0
[CHAN_X
] = lp_build_cos( &bld
->base
, tmp0
);
1114 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) {
1115 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
1116 dst0
[CHAN_Y
] = lp_build_sin( &bld
->base
, tmp0
);
1118 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) {
1119 dst0
[CHAN_Z
] = bld
->base
.zero
;
1121 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) {
1122 dst0
[CHAN_W
] = bld
->base
.one
;
1126 case TGSI_OPCODE_TXB
:
1127 emit_tex( bld
, inst
, TRUE
, FALSE
, dst0
);
1130 case TGSI_OPCODE_NRM
:
1132 case TGSI_OPCODE_NRM4
:
1133 /* 3 or 4-component normalization */
1135 uint dims
= (inst
->Instruction
.Opcode
== TGSI_OPCODE_NRM
) ? 3 : 4;
1137 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
) ||
1138 IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Y
) ||
1139 IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Z
) ||
1140 (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_W
) && dims
== 4)) {
1142 /* NOTE: Cannot use xmm regs 2/3 here (see emit_rsqrt() above). */
1145 /* xmm0 = src.x * src.x */
1146 tmp0
= emit_fetch(bld
, inst
, 0, CHAN_X
);
1147 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
)) {
1150 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp0
);
1153 /* xmm0 = xmm0 + src.y * src.y */
1154 tmp1
= emit_fetch(bld
, inst
, 0, CHAN_Y
);
1155 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Y
)) {
1158 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp1
);
1159 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
1162 /* xmm0 = xmm0 + src.z * src.z */
1163 tmp1
= emit_fetch(bld
, inst
, 0, CHAN_Z
);
1164 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Z
)) {
1167 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp1
);
1168 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
1172 /* xmm0 = xmm0 + src.w * src.w */
1173 tmp1
= emit_fetch(bld
, inst
, 0, CHAN_W
);
1174 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_W
)) {
1177 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp1
);
1178 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
1181 /* xmm1 = 1 / sqrt(xmm0) */
1182 tmp1
= lp_build_rsqrt( &bld
->base
, tmp0
);
1184 /* dst.x = xmm1 * src.x */
1185 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
)) {
1186 dst0
[CHAN_X
] = lp_build_mul( &bld
->base
, tmp4
, tmp1
);
1189 /* dst.y = xmm1 * src.y */
1190 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Y
)) {
1191 dst0
[CHAN_Y
] = lp_build_mul( &bld
->base
, tmp5
, tmp1
);
1194 /* dst.z = xmm1 * src.z */
1195 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Z
)) {
1196 dst0
[CHAN_Z
] = lp_build_mul( &bld
->base
, tmp6
, tmp1
);
1199 /* dst.w = xmm1 * src.w */
1200 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
) && dims
== 4) {
1201 dst0
[CHAN_W
] = lp_build_mul( &bld
->base
, tmp7
, tmp1
);
1206 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_W
) && dims
== 3) {
1207 dst0
[CHAN_W
] = bld
->base
.one
;
1212 case TGSI_OPCODE_DIV
:
1218 case TGSI_OPCODE_DP2
:
1219 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
); /* xmm0 = src[0].x */
1220 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
); /* xmm1 = src[1].x */
1221 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 * xmm1 */
1222 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
); /* xmm1 = src[0].y */
1223 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
); /* xmm2 = src[1].y */
1224 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
); /* xmm1 = xmm1 * xmm2 */
1225 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 + xmm1 */
1226 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1227 dst0
[chan_index
] = tmp0
; /* dest[ch] = xmm0 */
1231 case TGSI_OPCODE_TXL
:
1232 emit_tex( bld
, inst
, TRUE
, FALSE
, dst0
);
1235 case TGSI_OPCODE_TXP
:
1236 emit_tex( bld
, inst
, FALSE
, TRUE
, dst0
);
1239 case TGSI_OPCODE_BRK
:
1244 case TGSI_OPCODE_IF
:
1249 case TGSI_OPCODE_BGNFOR
:
1255 case TGSI_OPCODE_REP
:
1261 case TGSI_OPCODE_ELSE
:
1266 case TGSI_OPCODE_ENDIF
:
1271 case TGSI_OPCODE_ENDFOR
:
1277 case TGSI_OPCODE_ENDREP
:
1283 case TGSI_OPCODE_PUSHA
:
1289 case TGSI_OPCODE_POPA
:
1295 case TGSI_OPCODE_CEIL
:
1296 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1297 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
1298 dst0
[chan_index
] = lp_build_ceil(&bld
->base
, tmp0
);
1302 case TGSI_OPCODE_I2F
:
1308 case TGSI_OPCODE_NOT
:
1314 case TGSI_OPCODE_TRUNC
:
1315 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1316 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
1317 dst0
[chan_index
] = lp_build_trunc(&bld
->base
, tmp0
);
1321 case TGSI_OPCODE_SHL
:
1327 case TGSI_OPCODE_SHR
:
1333 case TGSI_OPCODE_AND
:
1339 case TGSI_OPCODE_OR
:
1345 case TGSI_OPCODE_MOD
:
1351 case TGSI_OPCODE_XOR
:
1357 case TGSI_OPCODE_SAD
:
1363 case TGSI_OPCODE_TXF
:
1369 case TGSI_OPCODE_TXQ
:
1375 case TGSI_OPCODE_CONT
:
1381 case TGSI_OPCODE_EMIT
:
1385 case TGSI_OPCODE_ENDPRIM
:
1389 case TGSI_OPCODE_NOISE1
:
1390 case TGSI_OPCODE_NOISE2
:
1391 case TGSI_OPCODE_NOISE3
:
1392 case TGSI_OPCODE_NOISE4
:
1393 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1394 dst0
[chan_index
] = bld
->base
.zero
;
1398 case TGSI_OPCODE_NOP
:
1406 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1407 emit_store( bld
, inst
, 0, chan_index
, dst0
[chan_index
]);
1416 lp_build_tgsi_soa(LLVMBuilderRef builder
,
1417 const struct tgsi_token
*tokens
,
1418 struct lp_type type
,
1419 struct lp_build_mask_context
*mask
,
1420 LLVMValueRef consts_ptr
,
1421 const LLVMValueRef
*pos
,
1422 const LLVMValueRef (*inputs
)[NUM_CHANNELS
],
1423 LLVMValueRef (*outputs
)[NUM_CHANNELS
],
1424 struct lp_build_sampler_soa
*sampler
)
1426 struct lp_build_tgsi_soa_context bld
;
1427 struct tgsi_parse_context parse
;
1428 uint num_immediates
= 0;
1431 /* Setup build context */
1432 memset(&bld
, 0, sizeof bld
);
1433 lp_build_context_init(&bld
.base
, builder
, type
);
1436 bld
.inputs
= inputs
;
1437 bld
.outputs
= outputs
;
1438 bld
.consts_ptr
= consts_ptr
;
1439 bld
.sampler
= sampler
;
1441 tgsi_parse_init( &parse
, tokens
);
1443 while( !tgsi_parse_end_of_tokens( &parse
) ) {
1444 tgsi_parse_token( &parse
);
1446 switch( parse
.FullToken
.Token
.Type
) {
1447 case TGSI_TOKEN_TYPE_DECLARATION
:
1448 /* Inputs already interpolated */
1451 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1453 unsigned opcode
= parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1454 const struct tgsi_opcode_info
*info
= tgsi_get_opcode_info(opcode
);
1455 if (!emit_instruction( &bld
, &parse
.FullToken
.FullInstruction
, info
))
1456 _debug_printf("warning: failed to translate tgsi opcode %s to LLVM\n",
1457 info
? info
->mnemonic
: "<invalid>");
1462 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1463 /* simply copy the immediate values into the next immediates[] slot */
1465 const uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
1467 assert(num_immediates
< LP_MAX_IMMEDIATES
);
1468 for( i
= 0; i
< size
; ++i
)
1469 bld
.immediates
[num_immediates
][i
] =
1470 lp_build_const_scalar(type
, parse
.FullToken
.FullImmediate
.u
[i
].Float
);
1471 for( i
= size
; i
< 4; ++i
)
1472 bld
.immediates
[num_immediates
][i
] = bld
.base
.undef
;
1482 tgsi_parse_free( &parse
);