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_arit.h"
51 #include "lp_bld_logic.h"
52 #include "lp_bld_swizzle.h"
53 #include "lp_bld_flow.h"
54 #include "lp_bld_tgsi.h"
57 #define LP_MAX_TEMPS 256
58 #define LP_MAX_IMMEDIATES 256
61 #define FOR_EACH_CHANNEL( CHAN )\
62 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)
64 #define IS_DST0_CHANNEL_ENABLED( INST, CHAN )\
65 ((INST)->Dst[0].Register.WriteMask & (1 << (CHAN)))
67 #define IF_IS_DST0_CHANNEL_ENABLED( INST, CHAN )\
68 if (IS_DST0_CHANNEL_ENABLED( INST, CHAN ))
70 #define FOR_EACH_DST0_ENABLED_CHANNEL( INST, CHAN )\
71 FOR_EACH_CHANNEL( CHAN )\
72 IF_IS_DST0_CHANNEL_ENABLED( INST, CHAN )
79 #define QUAD_TOP_LEFT 0
80 #define QUAD_TOP_RIGHT 1
81 #define QUAD_BOTTOM_LEFT 2
82 #define QUAD_BOTTOM_RIGHT 3
85 struct lp_build_tgsi_soa_context
87 struct lp_build_context base
;
89 LLVMValueRef consts_ptr
;
90 const LLVMValueRef
*pos
;
91 const LLVMValueRef (*inputs
)[NUM_CHANNELS
];
92 LLVMValueRef (*outputs
)[NUM_CHANNELS
];
94 struct lp_build_sampler_soa
*sampler
;
96 LLVMValueRef immediates
[LP_MAX_IMMEDIATES
][NUM_CHANNELS
];
97 LLVMValueRef temps
[LP_MAX_TEMPS
][NUM_CHANNELS
];
99 struct lp_build_mask_context
*mask
;
103 static const unsigned char
105 QUAD_TOP_LEFT
, QUAD_TOP_LEFT
,
106 QUAD_BOTTOM_LEFT
, QUAD_BOTTOM_LEFT
109 static const unsigned char
111 QUAD_TOP_RIGHT
, QUAD_TOP_RIGHT
,
112 QUAD_BOTTOM_RIGHT
, QUAD_BOTTOM_RIGHT
115 static const unsigned char
117 QUAD_TOP_LEFT
, QUAD_TOP_RIGHT
,
118 QUAD_TOP_LEFT
, QUAD_TOP_RIGHT
121 static const unsigned char
122 swizzle_bottom
[4] = {
123 QUAD_BOTTOM_LEFT
, QUAD_BOTTOM_RIGHT
,
124 QUAD_BOTTOM_LEFT
, QUAD_BOTTOM_RIGHT
129 emit_ddx(struct lp_build_tgsi_soa_context
*bld
,
132 LLVMValueRef src_left
= lp_build_swizzle1_aos(&bld
->base
, src
, swizzle_left
);
133 LLVMValueRef src_right
= lp_build_swizzle1_aos(&bld
->base
, src
, swizzle_right
);
134 return lp_build_sub(&bld
->base
, src_right
, src_left
);
139 emit_ddy(struct lp_build_tgsi_soa_context
*bld
,
142 LLVMValueRef src_top
= lp_build_swizzle1_aos(&bld
->base
, src
, swizzle_top
);
143 LLVMValueRef src_bottom
= lp_build_swizzle1_aos(&bld
->base
, src
, swizzle_bottom
);
144 return lp_build_sub(&bld
->base
, src_top
, src_bottom
);
153 struct lp_build_tgsi_soa_context
*bld
,
154 const struct tgsi_full_instruction
*inst
,
156 const unsigned chan_index
)
158 const struct tgsi_full_src_register
*reg
= &inst
->Src
[index
];
159 unsigned swizzle
= tgsi_util_get_full_src_register_swizzle( reg
, chan_index
);
168 switch (reg
->Register
.File
) {
169 case TGSI_FILE_CONSTANT
: {
170 LLVMValueRef index
= LLVMConstInt(LLVMInt32Type(), reg
->Register
.Index
*4 + swizzle
, 0);
171 LLVMValueRef scalar_ptr
= LLVMBuildGEP(bld
->base
.builder
, bld
->consts_ptr
, &index
, 1, "");
172 LLVMValueRef scalar
= LLVMBuildLoad(bld
->base
.builder
, scalar_ptr
, "");
173 res
= lp_build_broadcast_scalar(&bld
->base
, scalar
);
177 case TGSI_FILE_IMMEDIATE
:
178 res
= bld
->immediates
[reg
->Register
.Index
][swizzle
];
182 case TGSI_FILE_INPUT
:
183 res
= bld
->inputs
[reg
->Register
.Index
][swizzle
];
187 case TGSI_FILE_TEMPORARY
:
188 res
= LLVMBuildLoad(bld
->base
.builder
, bld
->temps
[reg
->Register
.Index
][swizzle
], "");
190 return bld
->base
.undef
;
195 return bld
->base
.undef
;
201 return bld
->base
.undef
;
204 switch( tgsi_util_get_full_src_register_sign_mode( reg
, chan_index
) ) {
205 case TGSI_UTIL_SIGN_CLEAR
:
206 res
= lp_build_abs( &bld
->base
, res
);
209 case TGSI_UTIL_SIGN_SET
:
210 /* TODO: Use bitwese OR for floating point */
211 res
= lp_build_abs( &bld
->base
, res
);
212 res
= LLVMBuildNeg( bld
->base
.builder
, res
, "" );
215 case TGSI_UTIL_SIGN_TOGGLE
:
216 res
= LLVMBuildNeg( bld
->base
.builder
, res
, "" );
219 case TGSI_UTIL_SIGN_KEEP
:
228 * Register fetch with derivatives.
232 struct lp_build_tgsi_soa_context
*bld
,
233 const struct tgsi_full_instruction
*inst
,
235 const unsigned chan_index
,
242 src
= emit_fetch(bld
, inst
, index
, chan_index
);
247 /* TODO: use interpolation coeffs for inputs */
250 *ddx
= emit_ddx(bld
, src
);
253 *ddy
= emit_ddy(bld
, src
);
262 struct lp_build_tgsi_soa_context
*bld
,
263 const struct tgsi_full_instruction
*inst
,
268 const struct tgsi_full_dst_register
*reg
= &inst
->Dst
[index
];
270 switch( inst
->Instruction
.Saturate
) {
274 case TGSI_SAT_ZERO_ONE
:
275 value
= lp_build_max(&bld
->base
, value
, bld
->base
.zero
);
276 value
= lp_build_min(&bld
->base
, value
, bld
->base
.one
);
279 case TGSI_SAT_MINUS_PLUS_ONE
:
280 value
= lp_build_max(&bld
->base
, value
, lp_build_const_scalar(bld
->base
.type
, -1.0));
281 value
= lp_build_min(&bld
->base
, value
, bld
->base
.one
);
288 switch( reg
->Register
.File
) {
289 case TGSI_FILE_OUTPUT
:
290 LLVMBuildStore(bld
->base
.builder
, value
,
291 bld
->outputs
[reg
->Register
.Index
][chan_index
]);
294 case TGSI_FILE_TEMPORARY
:
295 LLVMBuildStore(bld
->base
.builder
, value
,
296 bld
->temps
[reg
->Register
.Index
][chan_index
]);
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
;
324 LLVMValueRef oow
= NULL
;
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
);
364 for (i
= num_coords
; i
< 3; i
++) {
365 coords
[i
] = bld
->base
.undef
;
368 bld
->sampler
->emit_fetch_texel(bld
->sampler
,
371 unit
, num_coords
, coords
, lodbias
,
378 struct lp_build_tgsi_soa_context
*bld
,
379 const struct tgsi_full_instruction
*inst
)
381 const struct tgsi_full_src_register
*reg
= &inst
->Src
[0];
382 LLVMValueRef terms
[NUM_CHANNELS
];
386 memset(&terms
, 0, sizeof terms
);
388 FOR_EACH_CHANNEL( chan_index
) {
391 /* Unswizzle channel */
392 swizzle
= tgsi_util_get_full_src_register_swizzle( reg
, chan_index
);
394 /* Check if the component has not been already tested. */
395 assert(swizzle
< NUM_CHANNELS
);
396 if( !terms
[swizzle
] )
397 /* TODO: change the comparison operator instead of setting the sign */
398 terms
[swizzle
] = emit_fetch(bld
, inst
, 0, chan_index
);
402 FOR_EACH_CHANNEL( chan_index
) {
403 if(terms
[chan_index
]) {
404 LLVMValueRef chan_mask
;
406 chan_mask
= lp_build_cmp(&bld
->base
, PIPE_FUNC_GEQUAL
, terms
[chan_index
], bld
->base
.zero
);
409 mask
= LLVMBuildAnd(bld
->base
.builder
, mask
, chan_mask
, "");
416 lp_build_mask_update(bld
->mask
, mask
);
421 * Check if inst src/dest regs use indirect addressing into temporary
425 indirect_temp_reference(const struct tgsi_full_instruction
*inst
)
428 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
429 const struct tgsi_full_src_register
*reg
= &inst
->Src
[i
];
430 if (reg
->Register
.File
== TGSI_FILE_TEMPORARY
&&
431 reg
->Register
.Indirect
)
434 for (i
= 0; i
< inst
->Instruction
.NumDstRegs
; i
++) {
435 const struct tgsi_full_dst_register
*reg
= &inst
->Dst
[i
];
436 if (reg
->Register
.File
== TGSI_FILE_TEMPORARY
&&
437 reg
->Register
.Indirect
)
445 struct lp_build_tgsi_soa_context
*bld
,
446 const struct tgsi_full_declaration
*decl
)
448 unsigned first
= decl
->Range
.First
;
449 unsigned last
= decl
->Range
.Last
;
452 for (idx
= first
; idx
<= last
; ++idx
) {
455 switch (decl
->Declaration
.File
) {
456 case TGSI_FILE_TEMPORARY
:
457 for (i
= 0; i
< NUM_CHANNELS
; i
++)
458 bld
->temps
[idx
][i
] = lp_build_alloca(&bld
->base
);
462 case TGSI_FILE_OUTPUT
:
463 for (i
= 0; i
< NUM_CHANNELS
; i
++)
464 bld
->outputs
[idx
][i
] = lp_build_alloca(&bld
->base
);
469 /* don't need to declare other vars */
482 struct lp_build_tgsi_soa_context
*bld
,
483 const struct tgsi_full_instruction
*inst
,
484 const struct tgsi_opcode_info
*info
)
487 LLVMValueRef src0
, src1
, src2
;
488 LLVMValueRef tmp0
, tmp1
, tmp2
;
489 LLVMValueRef tmp3
= NULL
;
490 LLVMValueRef tmp4
= NULL
;
491 LLVMValueRef tmp5
= NULL
;
492 LLVMValueRef tmp6
= NULL
;
493 LLVMValueRef tmp7
= NULL
;
495 LLVMValueRef dst0
[NUM_CHANNELS
];
497 /* we can't handle indirect addressing into temp register file yet */
498 if (indirect_temp_reference(inst
))
501 assert(info
->num_dst
<= 1);
503 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
504 dst0
[chan_index
] = bld
->base
.undef
;
508 switch (inst
->Instruction
.Opcode
) {
510 case TGSI_OPCODE_ARL
:
512 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
513 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
516 dst0
[chan_index
] = tmp0
;
521 case TGSI_OPCODE_MOV
:
522 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
523 dst0
[chan_index
] = emit_fetch( bld
, inst
, 0, chan_index
);
527 case TGSI_OPCODE_LIT
:
528 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ) {
529 dst0
[CHAN_X
] = bld
->base
.one
;
531 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ) {
532 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
533 dst0
[CHAN_Y
] = lp_build_max( &bld
->base
, src0
, bld
->base
.zero
);
535 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) ) {
536 /* XMM[1] = SrcReg[0].yyyy */
537 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
538 /* XMM[1] = max(XMM[1], 0) */
539 tmp1
= lp_build_max( &bld
->base
, tmp1
, bld
->base
.zero
);
540 /* XMM[2] = SrcReg[0].wwww */
541 tmp2
= emit_fetch( bld
, inst
, 0, CHAN_W
);
542 tmp1
= lp_build_pow( &bld
->base
, tmp1
, tmp2
);
543 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
544 tmp2
= lp_build_cmp(&bld
->base
, PIPE_FUNC_GREATER
, tmp0
, bld
->base
.zero
);
545 dst0
[CHAN_Z
] = lp_build_select(&bld
->base
, tmp2
, tmp1
, bld
->base
.zero
);
547 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) ) {
548 dst0
[CHAN_W
] = bld
->base
.one
;
552 case TGSI_OPCODE_RCP
:
553 /* TGSI_OPCODE_RECIP */
554 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
555 res
= lp_build_rcp(&bld
->base
, src0
);
556 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
557 dst0
[chan_index
] = res
;
561 case TGSI_OPCODE_RSQ
:
562 /* TGSI_OPCODE_RECIPSQRT */
563 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
564 src0
= lp_build_abs(&bld
->base
, src0
);
565 res
= lp_build_rsqrt(&bld
->base
, src0
);
566 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
567 dst0
[chan_index
] = res
;
571 case TGSI_OPCODE_EXP
:
572 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
573 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ||
574 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
)) {
575 LLVMValueRef
*p_exp2_int_part
= NULL
;
576 LLVMValueRef
*p_frac_part
= NULL
;
577 LLVMValueRef
*p_exp2
= NULL
;
579 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
581 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
582 p_exp2_int_part
= &tmp0
;
583 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
))
585 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
588 lp_build_exp2_approx(&bld
->base
, src0
, p_exp2_int_part
, p_frac_part
, p_exp2
);
590 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
592 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
))
594 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
598 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
)) {
599 dst0
[CHAN_W
] = bld
->base
.one
;
603 case TGSI_OPCODE_LOG
:
604 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
605 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ||
606 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
)) {
607 LLVMValueRef
*p_floor_log2
= NULL
;
608 LLVMValueRef
*p_exp
= NULL
;
609 LLVMValueRef
*p_log2
= NULL
;
611 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
612 src0
= lp_build_abs( &bld
->base
, src0
);
614 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
615 p_floor_log2
= &tmp0
;
616 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
))
618 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
621 lp_build_log2_approx(&bld
->base
, src0
, p_exp
, p_floor_log2
, p_log2
);
623 /* dst.x = floor(lg2(abs(src.x))) */
624 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
626 /* dst.y = abs(src)/ex2(floor(lg2(abs(src.x)))) */
627 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
)) {
628 dst0
[CHAN_Y
] = lp_build_div( &bld
->base
, src0
, tmp1
);
630 /* dst.z = lg2(abs(src.x)) */
631 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
635 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
)) {
636 dst0
[CHAN_W
] = bld
->base
.one
;
640 case TGSI_OPCODE_MUL
:
641 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
642 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
643 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
644 dst0
[chan_index
] = lp_build_mul(&bld
->base
, src0
, src1
);
648 case TGSI_OPCODE_ADD
:
649 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
650 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
651 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
652 dst0
[chan_index
] = lp_build_add(&bld
->base
, src0
, src1
);
656 case TGSI_OPCODE_DP3
:
657 /* TGSI_OPCODE_DOT3 */
658 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
659 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
660 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
661 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
662 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
663 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
664 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
665 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
666 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
667 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
668 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
669 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
670 dst0
[chan_index
] = tmp0
;
674 case TGSI_OPCODE_DP4
:
675 /* TGSI_OPCODE_DOT4 */
676 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
677 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
678 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
679 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
680 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
681 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
682 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
683 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
684 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
685 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
686 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
687 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_W
);
688 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_W
);
689 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
690 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
691 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
692 dst0
[chan_index
] = tmp0
;
696 case TGSI_OPCODE_DST
:
697 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) {
698 dst0
[CHAN_X
] = bld
->base
.one
;
700 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) {
701 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
702 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
703 dst0
[CHAN_Y
] = lp_build_mul( &bld
->base
, tmp0
, tmp1
);
705 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) {
706 dst0
[CHAN_Z
] = emit_fetch( bld
, inst
, 0, CHAN_Z
);
708 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) {
709 dst0
[CHAN_W
] = emit_fetch( bld
, inst
, 1, CHAN_W
);
713 case TGSI_OPCODE_MIN
:
714 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
715 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
716 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
717 dst0
[chan_index
] = lp_build_min( &bld
->base
, src0
, src1
);
721 case TGSI_OPCODE_MAX
:
722 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
723 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
724 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
725 dst0
[chan_index
] = lp_build_max( &bld
->base
, src0
, src1
);
729 case TGSI_OPCODE_SLT
:
730 /* TGSI_OPCODE_SETLT */
731 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
732 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
733 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
734 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_LESS
, src0
, src1
);
735 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
739 case TGSI_OPCODE_SGE
:
740 /* TGSI_OPCODE_SETGE */
741 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
742 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
743 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
744 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_GEQUAL
, src0
, src1
);
745 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
749 case TGSI_OPCODE_MAD
:
750 /* TGSI_OPCODE_MADD */
751 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
752 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
753 tmp1
= emit_fetch( bld
, inst
, 1, chan_index
);
754 tmp2
= emit_fetch( bld
, inst
, 2, chan_index
);
755 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
756 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp2
);
757 dst0
[chan_index
] = tmp0
;
761 case TGSI_OPCODE_SUB
:
762 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
763 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
764 tmp1
= emit_fetch( bld
, inst
, 1, chan_index
);
765 dst0
[chan_index
] = lp_build_sub( &bld
->base
, tmp0
, tmp1
);
769 case TGSI_OPCODE_LRP
:
770 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
771 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
772 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
773 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
774 tmp0
= lp_build_sub( &bld
->base
, src1
, src2
);
775 tmp0
= lp_build_mul( &bld
->base
, src0
, tmp0
);
776 dst0
[chan_index
] = lp_build_add( &bld
->base
, tmp0
, src2
);
780 case TGSI_OPCODE_CND
:
781 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
782 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
783 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
784 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
785 tmp1
= lp_build_const_scalar(bld
->base
.type
, 0.5);
786 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_GREATER
, src2
, tmp1
);
787 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, src0
, src1
);
791 case TGSI_OPCODE_DP2A
:
792 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
); /* xmm0 = src[0].x */
793 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
); /* xmm1 = src[1].x */
794 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 * xmm1 */
795 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
); /* xmm1 = src[0].y */
796 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
); /* xmm2 = src[1].y */
797 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
); /* xmm1 = xmm1 * xmm2 */
798 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 + xmm1 */
799 tmp1
= emit_fetch( bld
, inst
, 2, CHAN_X
); /* xmm1 = src[2].x */
800 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 + xmm1 */
801 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
802 dst0
[chan_index
] = tmp0
; /* dest[ch] = xmm0 */
806 case TGSI_OPCODE_FRC
:
807 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
808 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
809 tmp0
= lp_build_floor(&bld
->base
, src0
);
810 tmp0
= lp_build_sub(&bld
->base
, src0
, tmp0
);
811 dst0
[chan_index
] = tmp0
;
815 case TGSI_OPCODE_CLAMP
:
816 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
817 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
818 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
819 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
820 tmp0
= lp_build_max(&bld
->base
, tmp0
, src1
);
821 tmp0
= lp_build_min(&bld
->base
, tmp0
, src2
);
822 dst0
[chan_index
] = tmp0
;
826 case TGSI_OPCODE_FLR
:
827 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
828 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
829 dst0
[chan_index
] = lp_build_floor(&bld
->base
, tmp0
);
833 case TGSI_OPCODE_ROUND
:
834 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
835 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
836 dst0
[chan_index
] = lp_build_round(&bld
->base
, tmp0
);
840 case TGSI_OPCODE_EX2
: {
841 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
842 tmp0
= lp_build_exp2( &bld
->base
, tmp0
);
843 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
844 dst0
[chan_index
] = tmp0
;
849 case TGSI_OPCODE_LG2
:
850 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
851 tmp0
= lp_build_log2( &bld
->base
, tmp0
);
852 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
853 dst0
[chan_index
] = tmp0
;
857 case TGSI_OPCODE_POW
:
858 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
859 src1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
860 res
= lp_build_pow( &bld
->base
, src0
, src1
);
861 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
862 dst0
[chan_index
] = res
;
866 case TGSI_OPCODE_XPD
:
867 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
868 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ) {
869 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
870 tmp3
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
872 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
873 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) ) {
874 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
875 tmp4
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
877 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) {
879 tmp2
= lp_build_mul( &bld
->base
, tmp2
, tmp1
);
881 tmp5
= lp_build_mul( &bld
->base
, tmp5
, tmp4
);
882 tmp2
= lp_build_sub( &bld
->base
, tmp2
, tmp5
);
885 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ||
886 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) ) {
887 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_X
);
888 tmp5
= emit_fetch( bld
, inst
, 0, CHAN_X
);
890 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) {
891 tmp3
= lp_build_mul( &bld
->base
, tmp3
, tmp2
);
892 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp5
);
893 tmp3
= lp_build_sub( &bld
->base
, tmp3
, tmp1
);
896 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) {
897 tmp5
= lp_build_mul( &bld
->base
, tmp5
, tmp4
);
898 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp2
);
899 tmp5
= lp_build_sub( &bld
->base
, tmp5
, tmp0
);
902 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) {
903 dst0
[CHAN_W
] = bld
->base
.one
;
907 case TGSI_OPCODE_ABS
:
908 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
909 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
910 dst0
[chan_index
] = lp_build_abs( &bld
->base
, tmp0
);
914 case TGSI_OPCODE_RCC
:
919 case TGSI_OPCODE_DPH
:
920 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
921 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
922 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
923 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
924 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
925 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
926 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
927 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
928 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
929 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
930 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
931 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_W
);
932 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
933 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
934 dst0
[chan_index
] = tmp0
;
938 case TGSI_OPCODE_COS
:
939 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
940 tmp0
= lp_build_cos( &bld
->base
, tmp0
);
941 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
942 dst0
[chan_index
] = tmp0
;
946 case TGSI_OPCODE_DDX
:
947 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
948 emit_fetch_deriv( bld
, inst
, 0, chan_index
, NULL
, &dst0
[chan_index
], NULL
);
952 case TGSI_OPCODE_DDY
:
953 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
954 emit_fetch_deriv( bld
, inst
, 0, chan_index
, NULL
, NULL
, &dst0
[chan_index
]);
958 case TGSI_OPCODE_KILP
:
959 /* predicated kill */
964 case TGSI_OPCODE_KIL
:
965 /* conditional kill */
966 emit_kil( bld
, inst
);
969 case TGSI_OPCODE_PK2H
:
973 case TGSI_OPCODE_PK2US
:
977 case TGSI_OPCODE_PK4B
:
981 case TGSI_OPCODE_PK4UB
:
985 case TGSI_OPCODE_RFL
:
989 case TGSI_OPCODE_SEQ
:
990 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
991 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
992 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
993 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_EQUAL
, src0
, src1
);
994 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
998 case TGSI_OPCODE_SFL
:
999 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1000 dst0
[chan_index
] = bld
->base
.zero
;
1004 case TGSI_OPCODE_SGT
:
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_GREATER
, src0
, src1
);
1009 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
1013 case TGSI_OPCODE_SIN
:
1014 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
1015 tmp0
= lp_build_sin( &bld
->base
, tmp0
);
1016 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1017 dst0
[chan_index
] = tmp0
;
1021 case TGSI_OPCODE_SLE
:
1022 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1023 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
1024 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
1025 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_LEQUAL
, src0
, src1
);
1026 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
1030 case TGSI_OPCODE_SNE
:
1031 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1032 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
1033 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
1034 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_NOTEQUAL
, src0
, src1
);
1035 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
1039 case TGSI_OPCODE_STR
:
1040 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1041 dst0
[chan_index
] = bld
->base
.one
;
1045 case TGSI_OPCODE_TEX
:
1046 emit_tex( bld
, inst
, FALSE
, FALSE
, dst0
);
1049 case TGSI_OPCODE_TXD
:
1054 case TGSI_OPCODE_UP2H
:
1060 case TGSI_OPCODE_UP2US
:
1066 case TGSI_OPCODE_UP4B
:
1072 case TGSI_OPCODE_UP4UB
:
1078 case TGSI_OPCODE_X2D
:
1084 case TGSI_OPCODE_ARA
:
1091 case TGSI_OPCODE_ARR
:
1093 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1094 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
1095 emit_rnd( bld
, 0, 0 );
1096 emit_f2it( bld
, 0 );
1097 dst0
[chan_index
] = tmp0
;
1102 case TGSI_OPCODE_BRA
:
1108 case TGSI_OPCODE_CAL
:
1113 case TGSI_OPCODE_RET
:
1118 case TGSI_OPCODE_END
:
1121 case TGSI_OPCODE_SSG
:
1122 /* TGSI_OPCODE_SGN */
1123 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1124 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
1125 dst0
[chan_index
] = lp_build_sgn( &bld
->base
, tmp0
);
1129 case TGSI_OPCODE_CMP
:
1130 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1131 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
1132 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
1133 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
1134 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_LESS
, src0
, bld
->base
.zero
);
1135 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, src1
, src2
);
1139 case TGSI_OPCODE_SCS
:
1140 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) {
1141 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
1142 dst0
[CHAN_X
] = lp_build_cos( &bld
->base
, tmp0
);
1144 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) {
1145 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
1146 dst0
[CHAN_Y
] = lp_build_sin( &bld
->base
, tmp0
);
1148 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) {
1149 dst0
[CHAN_Z
] = bld
->base
.zero
;
1151 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) {
1152 dst0
[CHAN_W
] = bld
->base
.one
;
1156 case TGSI_OPCODE_TXB
:
1157 emit_tex( bld
, inst
, TRUE
, FALSE
, dst0
);
1160 case TGSI_OPCODE_NRM
:
1162 case TGSI_OPCODE_NRM4
:
1163 /* 3 or 4-component normalization */
1165 uint dims
= (inst
->Instruction
.Opcode
== TGSI_OPCODE_NRM
) ? 3 : 4;
1167 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
) ||
1168 IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Y
) ||
1169 IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Z
) ||
1170 (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_W
) && dims
== 4)) {
1172 /* NOTE: Cannot use xmm regs 2/3 here (see emit_rsqrt() above). */
1175 /* xmm0 = src.x * src.x */
1176 tmp0
= emit_fetch(bld
, inst
, 0, CHAN_X
);
1177 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
)) {
1180 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp0
);
1183 /* xmm0 = xmm0 + src.y * src.y */
1184 tmp1
= emit_fetch(bld
, inst
, 0, CHAN_Y
);
1185 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Y
)) {
1188 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp1
);
1189 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
1192 /* xmm0 = xmm0 + src.z * src.z */
1193 tmp1
= emit_fetch(bld
, inst
, 0, CHAN_Z
);
1194 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Z
)) {
1197 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp1
);
1198 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
1202 /* xmm0 = xmm0 + src.w * src.w */
1203 tmp1
= emit_fetch(bld
, inst
, 0, CHAN_W
);
1204 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_W
)) {
1207 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp1
);
1208 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
1211 /* xmm1 = 1 / sqrt(xmm0) */
1212 tmp1
= lp_build_rsqrt( &bld
->base
, tmp0
);
1214 /* dst.x = xmm1 * src.x */
1215 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
)) {
1216 dst0
[CHAN_X
] = lp_build_mul( &bld
->base
, tmp4
, tmp1
);
1219 /* dst.y = xmm1 * src.y */
1220 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Y
)) {
1221 dst0
[CHAN_Y
] = lp_build_mul( &bld
->base
, tmp5
, tmp1
);
1224 /* dst.z = xmm1 * src.z */
1225 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Z
)) {
1226 dst0
[CHAN_Z
] = lp_build_mul( &bld
->base
, tmp6
, tmp1
);
1229 /* dst.w = xmm1 * src.w */
1230 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
) && dims
== 4) {
1231 dst0
[CHAN_W
] = lp_build_mul( &bld
->base
, tmp7
, tmp1
);
1236 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_W
) && dims
== 3) {
1237 dst0
[CHAN_W
] = bld
->base
.one
;
1242 case TGSI_OPCODE_DIV
:
1248 case TGSI_OPCODE_DP2
:
1249 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
); /* xmm0 = src[0].x */
1250 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
); /* xmm1 = src[1].x */
1251 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 * xmm1 */
1252 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
); /* xmm1 = src[0].y */
1253 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
); /* xmm2 = src[1].y */
1254 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
); /* xmm1 = xmm1 * xmm2 */
1255 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 + xmm1 */
1256 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1257 dst0
[chan_index
] = tmp0
; /* dest[ch] = xmm0 */
1261 case TGSI_OPCODE_TXL
:
1262 emit_tex( bld
, inst
, TRUE
, FALSE
, dst0
);
1265 case TGSI_OPCODE_TXP
:
1266 emit_tex( bld
, inst
, FALSE
, TRUE
, dst0
);
1269 case TGSI_OPCODE_BRK
:
1274 case TGSI_OPCODE_IF
:
1279 case TGSI_OPCODE_BGNFOR
:
1285 case TGSI_OPCODE_REP
:
1291 case TGSI_OPCODE_ELSE
:
1296 case TGSI_OPCODE_ENDIF
:
1301 case TGSI_OPCODE_ENDFOR
:
1307 case TGSI_OPCODE_ENDREP
:
1313 case TGSI_OPCODE_PUSHA
:
1319 case TGSI_OPCODE_POPA
:
1325 case TGSI_OPCODE_CEIL
:
1326 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1327 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
1328 dst0
[chan_index
] = lp_build_ceil(&bld
->base
, tmp0
);
1332 case TGSI_OPCODE_I2F
:
1338 case TGSI_OPCODE_NOT
:
1344 case TGSI_OPCODE_TRUNC
:
1345 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1346 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
1347 dst0
[chan_index
] = lp_build_trunc(&bld
->base
, tmp0
);
1351 case TGSI_OPCODE_SHL
:
1357 case TGSI_OPCODE_ISHR
:
1363 case TGSI_OPCODE_AND
:
1369 case TGSI_OPCODE_OR
:
1375 case TGSI_OPCODE_MOD
:
1381 case TGSI_OPCODE_XOR
:
1387 case TGSI_OPCODE_SAD
:
1393 case TGSI_OPCODE_TXF
:
1399 case TGSI_OPCODE_TXQ
:
1405 case TGSI_OPCODE_CONT
:
1411 case TGSI_OPCODE_EMIT
:
1415 case TGSI_OPCODE_ENDPRIM
:
1419 case TGSI_OPCODE_NOP
:
1427 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1428 emit_store( bld
, inst
, 0, chan_index
, dst0
[chan_index
]);
1437 lp_build_tgsi_soa(LLVMBuilderRef builder
,
1438 const struct tgsi_token
*tokens
,
1439 struct lp_type type
,
1440 struct lp_build_mask_context
*mask
,
1441 LLVMValueRef consts_ptr
,
1442 const LLVMValueRef
*pos
,
1443 const LLVMValueRef (*inputs
)[NUM_CHANNELS
],
1444 LLVMValueRef (*outputs
)[NUM_CHANNELS
],
1445 struct lp_build_sampler_soa
*sampler
)
1447 struct lp_build_tgsi_soa_context bld
;
1448 struct tgsi_parse_context parse
;
1449 uint num_immediates
= 0;
1452 /* Setup build context */
1453 memset(&bld
, 0, sizeof bld
);
1454 lp_build_context_init(&bld
.base
, builder
, type
);
1457 bld
.inputs
= inputs
;
1458 bld
.outputs
= outputs
;
1459 bld
.consts_ptr
= consts_ptr
;
1460 bld
.sampler
= sampler
;
1462 tgsi_parse_init( &parse
, tokens
);
1464 while( !tgsi_parse_end_of_tokens( &parse
) ) {
1465 tgsi_parse_token( &parse
);
1467 switch( parse
.FullToken
.Token
.Type
) {
1468 case TGSI_TOKEN_TYPE_DECLARATION
:
1469 /* Inputs already interpolated */
1471 if (!emit_declaration( &bld
, &parse
.FullToken
.FullDeclaration
))
1472 _debug_printf("warning: failed to define LLVM variable\n");
1476 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1478 unsigned opcode
= parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1479 const struct tgsi_opcode_info
*info
= tgsi_get_opcode_info(opcode
);
1480 if (!emit_instruction( &bld
, &parse
.FullToken
.FullInstruction
, info
))
1481 _debug_printf("warning: failed to translate tgsi opcode %s to LLVM\n",
1482 info
? info
->mnemonic
: "<invalid>");
1487 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1488 /* simply copy the immediate values into the next immediates[] slot */
1490 const uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
1492 assert(num_immediates
< LP_MAX_IMMEDIATES
);
1493 for( i
= 0; i
< size
; ++i
)
1494 bld
.immediates
[num_immediates
][i
] =
1495 lp_build_const_scalar(type
, parse
.FullToken
.FullImmediate
.u
[i
].Float
);
1496 for( i
= size
; i
< 4; ++i
)
1497 bld
.immediates
[num_immediates
][i
] = bld
.base
.undef
;
1507 tgsi_parse_free( &parse
);