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
;
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
);
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
;
450 LLVMValueRef tmp3
= NULL
;
451 LLVMValueRef tmp4
= NULL
;
452 LLVMValueRef tmp5
= NULL
;
453 LLVMValueRef tmp6
= NULL
;
454 LLVMValueRef tmp7
= NULL
;
456 LLVMValueRef dst0
[NUM_CHANNELS
];
458 /* we can't handle indirect addressing into temp register file yet */
459 if (indirect_temp_reference(inst
))
462 assert(info
->num_dst
<= 1);
464 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
465 dst0
[chan_index
] = bld
->base
.undef
;
469 switch (inst
->Instruction
.Opcode
) {
471 case TGSI_OPCODE_ARL
:
473 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
474 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
477 dst0
[chan_index
] = tmp0
;
482 case TGSI_OPCODE_MOV
:
483 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
484 dst0
[chan_index
] = emit_fetch( bld
, inst
, 0, chan_index
);
488 case TGSI_OPCODE_LIT
:
489 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ) {
490 dst0
[CHAN_X
] = bld
->base
.one
;
492 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ) {
493 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
494 dst0
[CHAN_Y
] = lp_build_max( &bld
->base
, src0
, bld
->base
.zero
);
496 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) ) {
497 /* XMM[1] = SrcReg[0].yyyy */
498 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
499 /* XMM[1] = max(XMM[1], 0) */
500 tmp1
= lp_build_max( &bld
->base
, tmp1
, bld
->base
.zero
);
501 /* XMM[2] = SrcReg[0].wwww */
502 tmp2
= emit_fetch( bld
, inst
, 0, CHAN_W
);
503 tmp1
= lp_build_pow( &bld
->base
, tmp1
, tmp2
);
504 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
505 tmp2
= lp_build_cmp(&bld
->base
, PIPE_FUNC_GREATER
, tmp0
, bld
->base
.zero
);
506 dst0
[CHAN_Z
] = lp_build_select(&bld
->base
, tmp2
, tmp1
, bld
->base
.zero
);
508 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) ) {
509 dst0
[CHAN_W
] = bld
->base
.one
;
513 case TGSI_OPCODE_RCP
:
514 /* TGSI_OPCODE_RECIP */
515 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
516 res
= lp_build_rcp(&bld
->base
, src0
);
517 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
518 dst0
[chan_index
] = res
;
522 case TGSI_OPCODE_RSQ
:
523 /* TGSI_OPCODE_RECIPSQRT */
524 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
525 src0
= lp_build_abs(&bld
->base
, src0
);
526 res
= lp_build_rsqrt(&bld
->base
, src0
);
527 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
528 dst0
[chan_index
] = res
;
532 case TGSI_OPCODE_EXP
:
533 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
534 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ||
535 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
)) {
536 LLVMValueRef
*p_exp2_int_part
= NULL
;
537 LLVMValueRef
*p_frac_part
= NULL
;
538 LLVMValueRef
*p_exp2
= NULL
;
540 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
542 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
543 p_exp2_int_part
= &tmp0
;
544 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
))
546 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
549 lp_build_exp2_approx(&bld
->base
, src0
, p_exp2_int_part
, p_frac_part
, p_exp2
);
551 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
553 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
))
555 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
559 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
)) {
560 dst0
[CHAN_W
] = bld
->base
.one
;
564 case TGSI_OPCODE_LOG
:
565 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
566 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ||
567 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
)) {
568 LLVMValueRef
*p_floor_log2
= NULL
;
569 LLVMValueRef
*p_exp
= NULL
;
570 LLVMValueRef
*p_log2
= NULL
;
572 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
573 src0
= lp_build_abs( &bld
->base
, src0
);
575 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
576 p_floor_log2
= &tmp0
;
577 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
))
579 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
582 lp_build_log2_approx(&bld
->base
, src0
, p_exp
, p_floor_log2
, p_log2
);
584 /* dst.x = floor(lg2(abs(src.x))) */
585 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
587 /* dst.y = abs(src)/ex2(floor(lg2(abs(src.x)))) */
588 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
)) {
589 dst0
[CHAN_Y
] = lp_build_div( &bld
->base
, src0
, tmp1
);
591 /* dst.z = lg2(abs(src.x)) */
592 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
596 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
)) {
597 dst0
[CHAN_W
] = bld
->base
.one
;
601 case TGSI_OPCODE_MUL
:
602 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
603 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
604 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
605 dst0
[chan_index
] = lp_build_mul(&bld
->base
, src0
, src1
);
609 case TGSI_OPCODE_ADD
:
610 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
611 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
612 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
613 dst0
[chan_index
] = lp_build_add(&bld
->base
, src0
, src1
);
617 case TGSI_OPCODE_DP3
:
618 /* TGSI_OPCODE_DOT3 */
619 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
620 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
621 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
622 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
623 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
624 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
625 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
626 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
627 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
628 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
629 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
630 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
631 dst0
[chan_index
] = tmp0
;
635 case TGSI_OPCODE_DP4
:
636 /* TGSI_OPCODE_DOT4 */
637 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
638 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
639 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
640 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
641 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
642 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
643 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
644 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
645 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
646 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
647 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
648 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_W
);
649 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_W
);
650 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
651 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
652 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
653 dst0
[chan_index
] = tmp0
;
657 case TGSI_OPCODE_DST
:
658 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) {
659 dst0
[CHAN_X
] = bld
->base
.one
;
661 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) {
662 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
663 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
664 dst0
[CHAN_Y
] = lp_build_mul( &bld
->base
, tmp0
, tmp1
);
666 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) {
667 dst0
[CHAN_Z
] = emit_fetch( bld
, inst
, 0, CHAN_Z
);
669 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) {
670 dst0
[CHAN_W
] = emit_fetch( bld
, inst
, 1, CHAN_W
);
674 case TGSI_OPCODE_MIN
:
675 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
676 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
677 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
678 dst0
[chan_index
] = lp_build_min( &bld
->base
, src0
, src1
);
682 case TGSI_OPCODE_MAX
:
683 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
684 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
685 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
686 dst0
[chan_index
] = lp_build_max( &bld
->base
, src0
, src1
);
690 case TGSI_OPCODE_SLT
:
691 /* TGSI_OPCODE_SETLT */
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 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_LESS
, src0
, src1
);
696 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
700 case TGSI_OPCODE_SGE
:
701 /* TGSI_OPCODE_SETGE */
702 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
703 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
704 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
705 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_GEQUAL
, src0
, src1
);
706 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
710 case TGSI_OPCODE_MAD
:
711 /* TGSI_OPCODE_MADD */
712 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
713 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
714 tmp1
= emit_fetch( bld
, inst
, 1, chan_index
);
715 tmp2
= emit_fetch( bld
, inst
, 2, chan_index
);
716 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
717 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp2
);
718 dst0
[chan_index
] = tmp0
;
722 case TGSI_OPCODE_SUB
:
723 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
724 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
725 tmp1
= emit_fetch( bld
, inst
, 1, chan_index
);
726 dst0
[chan_index
] = lp_build_sub( &bld
->base
, tmp0
, tmp1
);
730 case TGSI_OPCODE_LRP
:
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 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
735 tmp0
= lp_build_sub( &bld
->base
, src1
, src2
);
736 tmp0
= lp_build_mul( &bld
->base
, src0
, tmp0
);
737 dst0
[chan_index
] = lp_build_add( &bld
->base
, tmp0
, src2
);
741 case TGSI_OPCODE_CND
:
742 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
743 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
744 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
745 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
746 tmp1
= lp_build_const_scalar(bld
->base
.type
, 0.5);
747 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_GREATER
, src2
, tmp1
);
748 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, src0
, src1
);
752 case TGSI_OPCODE_DP2A
:
753 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
); /* xmm0 = src[0].x */
754 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
); /* xmm1 = src[1].x */
755 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 * xmm1 */
756 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
); /* xmm1 = src[0].y */
757 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
); /* xmm2 = src[1].y */
758 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
); /* xmm1 = xmm1 * xmm2 */
759 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 + xmm1 */
760 tmp1
= emit_fetch( bld
, inst
, 2, CHAN_X
); /* xmm1 = src[2].x */
761 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 + xmm1 */
762 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
763 dst0
[chan_index
] = tmp0
; /* dest[ch] = xmm0 */
767 case TGSI_OPCODE_FRC
:
768 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
769 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
770 tmp0
= lp_build_floor(&bld
->base
, src0
);
771 tmp0
= lp_build_sub(&bld
->base
, src0
, tmp0
);
772 dst0
[chan_index
] = tmp0
;
776 case TGSI_OPCODE_CLAMP
:
777 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
778 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
779 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
780 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
781 tmp0
= lp_build_max(&bld
->base
, tmp0
, src1
);
782 tmp0
= lp_build_min(&bld
->base
, tmp0
, src2
);
783 dst0
[chan_index
] = tmp0
;
787 case TGSI_OPCODE_FLR
:
788 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
789 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
790 dst0
[chan_index
] = lp_build_floor(&bld
->base
, tmp0
);
794 case TGSI_OPCODE_ROUND
:
795 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
796 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
797 dst0
[chan_index
] = lp_build_round(&bld
->base
, tmp0
);
801 case TGSI_OPCODE_EX2
: {
802 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
803 tmp0
= lp_build_exp2( &bld
->base
, tmp0
);
804 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
805 dst0
[chan_index
] = tmp0
;
810 case TGSI_OPCODE_LG2
:
811 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
812 tmp0
= lp_build_log2( &bld
->base
, tmp0
);
813 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
814 dst0
[chan_index
] = tmp0
;
818 case TGSI_OPCODE_POW
:
819 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
820 src1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
821 res
= lp_build_pow( &bld
->base
, src0
, src1
);
822 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
823 dst0
[chan_index
] = res
;
827 case TGSI_OPCODE_XPD
:
828 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
829 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ) {
830 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
831 tmp3
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
833 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
834 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) ) {
835 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
836 tmp4
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
838 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) {
840 tmp2
= lp_build_mul( &bld
->base
, tmp2
, tmp1
);
842 tmp5
= lp_build_mul( &bld
->base
, tmp5
, tmp4
);
843 tmp2
= lp_build_sub( &bld
->base
, tmp2
, tmp5
);
846 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ||
847 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) ) {
848 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_X
);
849 tmp5
= emit_fetch( bld
, inst
, 0, CHAN_X
);
851 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) {
852 tmp3
= lp_build_mul( &bld
->base
, tmp3
, tmp2
);
853 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp5
);
854 tmp3
= lp_build_sub( &bld
->base
, tmp3
, tmp1
);
857 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) {
858 tmp5
= lp_build_mul( &bld
->base
, tmp5
, tmp4
);
859 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp2
);
860 tmp5
= lp_build_sub( &bld
->base
, tmp5
, tmp0
);
863 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) {
864 dst0
[CHAN_W
] = bld
->base
.one
;
868 case TGSI_OPCODE_ABS
:
869 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
870 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
871 dst0
[chan_index
] = lp_build_abs( &bld
->base
, tmp0
);
875 case TGSI_OPCODE_RCC
:
880 case TGSI_OPCODE_DPH
:
881 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
882 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
883 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
884 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
885 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
886 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
887 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
888 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
889 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
890 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
891 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
892 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_W
);
893 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
894 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
895 dst0
[chan_index
] = tmp0
;
899 case TGSI_OPCODE_COS
:
900 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
901 tmp0
= lp_build_cos( &bld
->base
, tmp0
);
902 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
903 dst0
[chan_index
] = tmp0
;
907 case TGSI_OPCODE_DDX
:
908 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
909 emit_fetch_deriv( bld
, inst
, 0, chan_index
, NULL
, &dst0
[chan_index
], NULL
);
913 case TGSI_OPCODE_DDY
:
914 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
915 emit_fetch_deriv( bld
, inst
, 0, chan_index
, NULL
, NULL
, &dst0
[chan_index
]);
919 case TGSI_OPCODE_KILP
:
920 /* predicated kill */
925 case TGSI_OPCODE_KIL
:
926 /* conditional kill */
927 emit_kil( bld
, inst
);
930 case TGSI_OPCODE_PK2H
:
934 case TGSI_OPCODE_PK2US
:
938 case TGSI_OPCODE_PK4B
:
942 case TGSI_OPCODE_PK4UB
:
946 case TGSI_OPCODE_RFL
:
950 case TGSI_OPCODE_SEQ
:
951 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
952 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
953 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
954 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_EQUAL
, src0
, src1
);
955 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
959 case TGSI_OPCODE_SFL
:
960 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
961 dst0
[chan_index
] = bld
->base
.zero
;
965 case TGSI_OPCODE_SGT
:
966 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
967 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
968 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
969 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_GREATER
, src0
, src1
);
970 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
974 case TGSI_OPCODE_SIN
:
975 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
976 tmp0
= lp_build_sin( &bld
->base
, tmp0
);
977 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
978 dst0
[chan_index
] = tmp0
;
982 case TGSI_OPCODE_SLE
:
983 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
984 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
985 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
986 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_LEQUAL
, src0
, src1
);
987 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
991 case TGSI_OPCODE_SNE
:
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_NOTEQUAL
, src0
, src1
);
996 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
1000 case TGSI_OPCODE_STR
:
1001 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1002 dst0
[chan_index
] = bld
->base
.one
;
1006 case TGSI_OPCODE_TEX
:
1007 emit_tex( bld
, inst
, FALSE
, FALSE
, dst0
);
1010 case TGSI_OPCODE_TXD
:
1015 case TGSI_OPCODE_UP2H
:
1021 case TGSI_OPCODE_UP2US
:
1027 case TGSI_OPCODE_UP4B
:
1033 case TGSI_OPCODE_UP4UB
:
1039 case TGSI_OPCODE_X2D
:
1045 case TGSI_OPCODE_ARA
:
1052 case TGSI_OPCODE_ARR
:
1054 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1055 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
1056 emit_rnd( bld
, 0, 0 );
1057 emit_f2it( bld
, 0 );
1058 dst0
[chan_index
] = tmp0
;
1063 case TGSI_OPCODE_BRA
:
1069 case TGSI_OPCODE_CAL
:
1074 case TGSI_OPCODE_RET
:
1079 case TGSI_OPCODE_END
:
1082 case TGSI_OPCODE_SSG
:
1083 /* TGSI_OPCODE_SGN */
1084 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1085 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
1086 dst0
[chan_index
] = lp_build_sgn( &bld
->base
, tmp0
);
1090 case TGSI_OPCODE_CMP
:
1091 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1092 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
1093 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
1094 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
1095 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_LESS
, src0
, bld
->base
.zero
);
1096 dst0
[chan_index
] = lp_build_select( &bld
->base
, tmp0
, src1
, src2
);
1100 case TGSI_OPCODE_SCS
:
1101 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) {
1102 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
1103 dst0
[CHAN_X
] = lp_build_cos( &bld
->base
, tmp0
);
1105 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) {
1106 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
1107 dst0
[CHAN_Y
] = lp_build_sin( &bld
->base
, tmp0
);
1109 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) {
1110 dst0
[CHAN_Z
] = bld
->base
.zero
;
1112 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) {
1113 dst0
[CHAN_W
] = bld
->base
.one
;
1117 case TGSI_OPCODE_TXB
:
1118 emit_tex( bld
, inst
, TRUE
, FALSE
, dst0
);
1121 case TGSI_OPCODE_NRM
:
1123 case TGSI_OPCODE_NRM4
:
1124 /* 3 or 4-component normalization */
1126 uint dims
= (inst
->Instruction
.Opcode
== TGSI_OPCODE_NRM
) ? 3 : 4;
1128 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
) ||
1129 IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Y
) ||
1130 IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Z
) ||
1131 (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_W
) && dims
== 4)) {
1133 /* NOTE: Cannot use xmm regs 2/3 here (see emit_rsqrt() above). */
1136 /* xmm0 = src.x * src.x */
1137 tmp0
= emit_fetch(bld
, inst
, 0, CHAN_X
);
1138 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
)) {
1141 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp0
);
1144 /* xmm0 = xmm0 + src.y * src.y */
1145 tmp1
= emit_fetch(bld
, inst
, 0, CHAN_Y
);
1146 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Y
)) {
1149 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp1
);
1150 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
1153 /* xmm0 = xmm0 + src.z * src.z */
1154 tmp1
= emit_fetch(bld
, inst
, 0, CHAN_Z
);
1155 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Z
)) {
1158 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp1
);
1159 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
1163 /* xmm0 = xmm0 + src.w * src.w */
1164 tmp1
= emit_fetch(bld
, inst
, 0, CHAN_W
);
1165 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_W
)) {
1168 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp1
);
1169 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
1172 /* xmm1 = 1 / sqrt(xmm0) */
1173 tmp1
= lp_build_rsqrt( &bld
->base
, tmp0
);
1175 /* dst.x = xmm1 * src.x */
1176 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
)) {
1177 dst0
[CHAN_X
] = lp_build_mul( &bld
->base
, tmp4
, tmp1
);
1180 /* dst.y = xmm1 * src.y */
1181 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Y
)) {
1182 dst0
[CHAN_Y
] = lp_build_mul( &bld
->base
, tmp5
, tmp1
);
1185 /* dst.z = xmm1 * src.z */
1186 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Z
)) {
1187 dst0
[CHAN_Z
] = lp_build_mul( &bld
->base
, tmp6
, tmp1
);
1190 /* dst.w = xmm1 * src.w */
1191 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
) && dims
== 4) {
1192 dst0
[CHAN_W
] = lp_build_mul( &bld
->base
, tmp7
, tmp1
);
1197 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_W
) && dims
== 3) {
1198 dst0
[CHAN_W
] = bld
->base
.one
;
1203 case TGSI_OPCODE_DIV
:
1209 case TGSI_OPCODE_DP2
:
1210 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
); /* xmm0 = src[0].x */
1211 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
); /* xmm1 = src[1].x */
1212 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 * xmm1 */
1213 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
); /* xmm1 = src[0].y */
1214 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
); /* xmm2 = src[1].y */
1215 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
); /* xmm1 = xmm1 * xmm2 */
1216 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 + xmm1 */
1217 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1218 dst0
[chan_index
] = tmp0
; /* dest[ch] = xmm0 */
1222 case TGSI_OPCODE_TXL
:
1223 emit_tex( bld
, inst
, TRUE
, FALSE
, dst0
);
1226 case TGSI_OPCODE_TXP
:
1227 emit_tex( bld
, inst
, FALSE
, TRUE
, dst0
);
1230 case TGSI_OPCODE_BRK
:
1235 case TGSI_OPCODE_IF
:
1240 case TGSI_OPCODE_BGNFOR
:
1246 case TGSI_OPCODE_REP
:
1252 case TGSI_OPCODE_ELSE
:
1257 case TGSI_OPCODE_ENDIF
:
1262 case TGSI_OPCODE_ENDFOR
:
1268 case TGSI_OPCODE_ENDREP
:
1274 case TGSI_OPCODE_PUSHA
:
1280 case TGSI_OPCODE_POPA
:
1286 case TGSI_OPCODE_CEIL
:
1287 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1288 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
1289 dst0
[chan_index
] = lp_build_ceil(&bld
->base
, tmp0
);
1293 case TGSI_OPCODE_I2F
:
1299 case TGSI_OPCODE_NOT
:
1305 case TGSI_OPCODE_TRUNC
:
1306 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1307 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
1308 dst0
[chan_index
] = lp_build_trunc(&bld
->base
, tmp0
);
1312 case TGSI_OPCODE_SHL
:
1318 case TGSI_OPCODE_SHR
:
1324 case TGSI_OPCODE_AND
:
1330 case TGSI_OPCODE_OR
:
1336 case TGSI_OPCODE_MOD
:
1342 case TGSI_OPCODE_XOR
:
1348 case TGSI_OPCODE_SAD
:
1354 case TGSI_OPCODE_TXF
:
1360 case TGSI_OPCODE_TXQ
:
1366 case TGSI_OPCODE_CONT
:
1372 case TGSI_OPCODE_EMIT
:
1376 case TGSI_OPCODE_ENDPRIM
:
1380 case TGSI_OPCODE_NOP
:
1388 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1389 emit_store( bld
, inst
, 0, chan_index
, dst0
[chan_index
]);
1398 lp_build_tgsi_soa(LLVMBuilderRef builder
,
1399 const struct tgsi_token
*tokens
,
1400 struct lp_type type
,
1401 struct lp_build_mask_context
*mask
,
1402 LLVMValueRef consts_ptr
,
1403 const LLVMValueRef
*pos
,
1404 const LLVMValueRef (*inputs
)[NUM_CHANNELS
],
1405 LLVMValueRef (*outputs
)[NUM_CHANNELS
],
1406 struct lp_build_sampler_soa
*sampler
)
1408 struct lp_build_tgsi_soa_context bld
;
1409 struct tgsi_parse_context parse
;
1410 uint num_immediates
= 0;
1413 /* Setup build context */
1414 memset(&bld
, 0, sizeof bld
);
1415 lp_build_context_init(&bld
.base
, builder
, type
);
1418 bld
.inputs
= inputs
;
1419 bld
.outputs
= outputs
;
1420 bld
.consts_ptr
= consts_ptr
;
1421 bld
.sampler
= sampler
;
1423 tgsi_parse_init( &parse
, tokens
);
1425 while( !tgsi_parse_end_of_tokens( &parse
) ) {
1426 tgsi_parse_token( &parse
);
1428 switch( parse
.FullToken
.Token
.Type
) {
1429 case TGSI_TOKEN_TYPE_DECLARATION
:
1430 /* Inputs already interpolated */
1433 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1435 unsigned opcode
= parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1436 const struct tgsi_opcode_info
*info
= tgsi_get_opcode_info(opcode
);
1437 if (!emit_instruction( &bld
, &parse
.FullToken
.FullInstruction
, info
))
1438 _debug_printf("warning: failed to translate tgsi opcode %s to LLVM\n",
1439 info
? info
->mnemonic
: "<invalid>");
1444 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1445 /* simply copy the immediate values into the next immediates[] slot */
1447 const uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
1449 assert(num_immediates
< LP_MAX_IMMEDIATES
);
1450 for( i
= 0; i
< size
; ++i
)
1451 bld
.immediates
[num_immediates
][i
] =
1452 lp_build_const_scalar(type
, parse
.FullToken
.FullImmediate
.u
[i
].Float
);
1453 for( i
= size
; i
< 4; ++i
)
1454 bld
.immediates
[num_immediates
][i
] = bld
.base
.undef
;
1464 tgsi_parse_free( &parse
);