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 )
82 struct lp_build_tgsi_soa_context
84 struct lp_build_context base
;
86 LLVMValueRef consts_ptr
;
87 const LLVMValueRef
*pos
;
88 const LLVMValueRef (*inputs
)[NUM_CHANNELS
];
89 LLVMValueRef (*outputs
)[NUM_CHANNELS
];
91 struct lp_build_sampler_soa
*sampler
;
93 LLVMValueRef immediates
[LP_MAX_IMMEDIATES
][NUM_CHANNELS
];
94 LLVMValueRef temps
[LP_MAX_TEMPS
][NUM_CHANNELS
];
96 struct lp_build_mask_context
*mask
;
105 struct lp_build_tgsi_soa_context
*bld
,
106 const struct tgsi_full_instruction
*inst
,
108 const unsigned chan_index
)
110 const struct tgsi_full_src_register
*reg
= &inst
->FullSrcRegisters
[index
];
111 unsigned swizzle
= tgsi_util_get_full_src_register_extswizzle( reg
, chan_index
);
115 case TGSI_EXTSWIZZLE_X
:
116 case TGSI_EXTSWIZZLE_Y
:
117 case TGSI_EXTSWIZZLE_Z
:
118 case TGSI_EXTSWIZZLE_W
:
120 switch (reg
->SrcRegister
.File
) {
121 case TGSI_FILE_CONSTANT
: {
122 LLVMValueRef index
= LLVMConstInt(LLVMInt32Type(), reg
->SrcRegister
.Index
*4 + swizzle
, 0);
123 LLVMValueRef scalar_ptr
= LLVMBuildGEP(bld
->base
.builder
, bld
->consts_ptr
, &index
, 1, "");
124 LLVMValueRef scalar
= LLVMBuildLoad(bld
->base
.builder
, scalar_ptr
, "");
125 res
= lp_build_broadcast_scalar(&bld
->base
, scalar
);
129 case TGSI_FILE_IMMEDIATE
:
130 res
= bld
->immediates
[reg
->SrcRegister
.Index
][swizzle
];
134 case TGSI_FILE_INPUT
:
135 res
= bld
->inputs
[reg
->SrcRegister
.Index
][swizzle
];
139 case TGSI_FILE_TEMPORARY
:
140 res
= bld
->temps
[reg
->SrcRegister
.Index
][swizzle
];
142 return bld
->base
.undef
;
147 return bld
->base
.undef
;
151 case TGSI_EXTSWIZZLE_ZERO
:
152 res
= bld
->base
.zero
;
155 case TGSI_EXTSWIZZLE_ONE
:
161 return bld
->base
.undef
;
164 switch( tgsi_util_get_full_src_register_sign_mode( reg
, chan_index
) ) {
165 case TGSI_UTIL_SIGN_CLEAR
:
166 res
= lp_build_abs( &bld
->base
, res
);
169 case TGSI_UTIL_SIGN_SET
:
170 /* TODO: Use bitwese OR for floating point */
171 res
= lp_build_abs( &bld
->base
, res
);
172 res
= LLVMBuildNeg( bld
->base
.builder
, res
, "" );
175 case TGSI_UTIL_SIGN_TOGGLE
:
176 res
= LLVMBuildNeg( bld
->base
.builder
, res
, "" );
179 case TGSI_UTIL_SIGN_KEEP
:
192 struct lp_build_tgsi_soa_context
*bld
,
193 const struct tgsi_full_instruction
*inst
,
198 const struct tgsi_full_dst_register
*reg
= &inst
->FullDstRegisters
[index
];
200 switch( inst
->Instruction
.Saturate
) {
204 case TGSI_SAT_ZERO_ONE
:
205 value
= lp_build_max(&bld
->base
, value
, bld
->base
.zero
);
206 value
= lp_build_min(&bld
->base
, value
, bld
->base
.one
);
209 case TGSI_SAT_MINUS_PLUS_ONE
:
210 value
= lp_build_max(&bld
->base
, value
, lp_build_const_scalar(bld
->base
.type
, -1.0));
211 value
= lp_build_min(&bld
->base
, value
, bld
->base
.one
);
218 switch( reg
->DstRegister
.File
) {
219 case TGSI_FILE_OUTPUT
:
220 bld
->outputs
[reg
->DstRegister
.Index
][chan_index
] = value
;
223 case TGSI_FILE_TEMPORARY
:
224 bld
->temps
[reg
->DstRegister
.Index
][chan_index
] = value
;
227 case TGSI_FILE_ADDRESS
:
239 * High-level instruction translators.
243 emit_tex( struct lp_build_tgsi_soa_context
*bld
,
244 const struct tgsi_full_instruction
*inst
,
245 boolean apply_lodbias
,
248 const uint unit
= inst
->FullSrcRegisters
[1].SrcRegister
.Index
;
249 LLVMValueRef lodbias
;
251 LLVMValueRef coords
[3];
252 LLVMValueRef texel
[4];
256 switch (inst
->InstructionExtTexture
.Texture
) {
257 case TGSI_TEXTURE_1D
:
260 case TGSI_TEXTURE_2D
:
261 case TGSI_TEXTURE_RECT
:
264 case TGSI_TEXTURE_SHADOW1D
:
265 case TGSI_TEXTURE_SHADOW2D
:
266 case TGSI_TEXTURE_SHADOWRECT
:
267 case TGSI_TEXTURE_3D
:
268 case TGSI_TEXTURE_CUBE
:
277 lodbias
= emit_fetch( bld
, inst
, 0, 3 );
279 lodbias
= bld
->base
.zero
;
282 oow
= emit_fetch( bld
, inst
, 0, 3 );
283 oow
= lp_build_rcp(&bld
->base
, oow
);
286 for (i
= 0; i
< num_coords
; i
++) {
287 coords
[i
] = emit_fetch( bld
, inst
, 0, i
);
289 coords
[i
] = lp_build_mul(&bld
->base
, coords
[i
], oow
);
292 bld
->sampler
->emit_fetch_texel(bld
->sampler
,
295 unit
, num_coords
, coords
, lodbias
,
298 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, i
) {
299 emit_store( bld
, inst
, 0, i
, texel
[i
] );
306 struct lp_build_tgsi_soa_context
*bld
,
307 const struct tgsi_full_instruction
*inst
)
309 const struct tgsi_full_src_register
*reg
= &inst
->FullSrcRegisters
[0];
310 LLVMValueRef terms
[NUM_CHANNELS
];
314 memset(&terms
, 0, sizeof terms
);
316 FOR_EACH_CHANNEL( chan_index
) {
319 /* Unswizzle channel */
320 swizzle
= tgsi_util_get_full_src_register_extswizzle( reg
, chan_index
);
322 /* Note that we test if the value is less than zero, so 1.0 and 0.0 need
323 * not to be tested. */
324 if(swizzle
== TGSI_EXTSWIZZLE_ZERO
|| swizzle
== TGSI_EXTSWIZZLE_ONE
)
327 /* Check if the component has not been already tested. */
328 assert(swizzle
< NUM_CHANNELS
);
329 if( !terms
[swizzle
] )
330 /* TODO: change the comparison operator instead of setting the sign */
331 terms
[swizzle
] = emit_fetch(bld
, inst
, 0, chan_index
);
335 FOR_EACH_CHANNEL( chan_index
) {
336 if(terms
[chan_index
]) {
337 LLVMValueRef chan_mask
;
339 chan_mask
= lp_build_cmp(&bld
->base
, PIPE_FUNC_GEQUAL
, terms
[chan_index
], bld
->base
.zero
);
342 mask
= LLVMBuildAnd(bld
->base
.builder
, mask
, chan_mask
, "");
349 lp_build_mask_update(bld
->mask
, mask
);
354 * Check if inst src/dest regs use indirect addressing into temporary
358 indirect_temp_reference(const struct tgsi_full_instruction
*inst
)
361 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
362 const struct tgsi_full_src_register
*reg
= &inst
->FullSrcRegisters
[i
];
363 if (reg
->SrcRegister
.File
== TGSI_FILE_TEMPORARY
&&
364 reg
->SrcRegister
.Indirect
)
367 for (i
= 0; i
< inst
->Instruction
.NumDstRegs
; i
++) {
368 const struct tgsi_full_dst_register
*reg
= &inst
->FullDstRegisters
[i
];
369 if (reg
->DstRegister
.File
== TGSI_FILE_TEMPORARY
&&
370 reg
->DstRegister
.Indirect
)
379 struct lp_build_tgsi_soa_context
*bld
,
380 struct tgsi_full_instruction
*inst
)
383 LLVMValueRef src0
, src1
, src2
;
384 LLVMValueRef tmp0
, tmp1
, tmp2
, tmp3
, tmp4
, tmp5
, tmp6
, tmp7
;
387 /* we can't handle indirect addressing into temp register file yet */
388 if (indirect_temp_reference(inst
))
391 switch (inst
->Instruction
.Opcode
) {
393 case TGSI_OPCODE_ARL
:
395 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
396 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
399 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
404 case TGSI_OPCODE_MOV
:
405 case TGSI_OPCODE_SWZ
:
406 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
407 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
408 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
412 case TGSI_OPCODE_LIT
:
413 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ) {
414 emit_store( bld
, inst
, 0, CHAN_X
, bld
->base
.one
);
416 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ) {
417 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
418 dst0
= lp_build_max( &bld
->base
, src0
, bld
->base
.zero
);
419 emit_store( bld
, inst
, 0, CHAN_Y
, dst0
);
421 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) ) {
422 /* XMM[1] = SrcReg[0].yyyy */
423 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
424 /* XMM[1] = max(XMM[1], 0) */
425 tmp1
= lp_build_max( &bld
->base
, tmp1
, bld
->base
.zero
);
426 /* XMM[2] = SrcReg[0].wwww */
427 tmp2
= emit_fetch( bld
, inst
, 0, CHAN_W
);
428 tmp1
= lp_build_pow( &bld
->base
, tmp1
, tmp2
);
429 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
430 tmp2
= lp_build_cmp(&bld
->base
, PIPE_FUNC_GREATER
, tmp0
, bld
->base
.zero
);
431 dst0
= lp_build_select(&bld
->base
, tmp2
, tmp1
, bld
->base
.zero
);
432 emit_store( bld
, inst
, 0, CHAN_Z
, dst0
);
434 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) ) {
435 emit_store( bld
, inst
, 0, CHAN_W
, bld
->base
.one
);
439 case TGSI_OPCODE_RCP
:
440 /* TGSI_OPCODE_RECIP */
441 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
442 dst0
= lp_build_rcp(&bld
->base
, src0
);
443 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
444 emit_store( bld
, inst
, 0, chan_index
, dst0
);
448 case TGSI_OPCODE_RSQ
:
449 /* TGSI_OPCODE_RECIPSQRT */
450 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
451 src0
= lp_build_abs(&bld
->base
, src0
);
452 dst0
= lp_build_rsqrt(&bld
->base
, src0
);
453 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
454 emit_store( bld
, inst
, 0, chan_index
, dst0
);
458 case TGSI_OPCODE_EXP
:
459 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
460 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ||
461 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
)) {
462 LLVMValueRef
*p_exp2_int_part
= NULL
;
463 LLVMValueRef
*p_frac_part
= NULL
;
464 LLVMValueRef
*p_exp2
= NULL
;
466 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
468 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
469 p_exp2_int_part
= &tmp0
;
470 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
))
472 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
475 lp_build_exp2_approx(&bld
->base
, src0
, p_exp2_int_part
, p_frac_part
, p_exp2
);
477 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
478 emit_store( bld
, inst
, 0, CHAN_X
, tmp0
);
479 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
))
480 emit_store( bld
, inst
, 0, CHAN_Y
, tmp1
);
481 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
482 emit_store( bld
, inst
, 0, CHAN_Z
, tmp2
);
485 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
)) {
486 tmp0
= bld
->base
.one
;
487 emit_store( bld
, inst
, 0, CHAN_W
, tmp0
);
491 case TGSI_OPCODE_LOG
:
492 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
493 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ||
494 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
)) {
495 LLVMValueRef
*p_floor_log2
;
497 LLVMValueRef
*p_log2
;
499 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
500 src0
= lp_build_abs( &bld
->base
, src0
);
502 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
503 p_floor_log2
= &tmp0
;
504 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
))
506 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
509 lp_build_log2_approx(&bld
->base
, src0
, p_exp
, p_floor_log2
, p_log2
);
511 /* dst.x = floor(lg2(abs(src.x))) */
512 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
513 emit_store( bld
, inst
, 0, CHAN_X
, tmp0
);
514 /* dst.y = abs(src)/ex2(floor(lg2(abs(src.x)))) */
515 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
)) {
516 tmp1
= lp_build_div( &bld
->base
, src0
, tmp1
);
517 emit_store( bld
, inst
, 0, CHAN_Y
, tmp1
);
519 /* dst.z = lg2(abs(src.x)) */
520 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
521 emit_store( bld
, inst
, 0, CHAN_Z
, tmp2
);
524 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
)) {
525 tmp0
= bld
->base
.one
;
526 emit_store( bld
, inst
, 0, CHAN_W
, tmp0
);
530 case TGSI_OPCODE_MUL
:
531 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
532 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
533 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
534 dst0
= lp_build_mul(&bld
->base
, src0
, src1
);
535 emit_store( bld
, inst
, 0, chan_index
, dst0
);
539 case TGSI_OPCODE_ADD
:
540 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
541 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
542 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
543 dst0
= lp_build_add(&bld
->base
, src0
, src1
);
544 emit_store( bld
, inst
, 0, chan_index
, dst0
);
548 case TGSI_OPCODE_DP3
:
549 /* TGSI_OPCODE_DOT3 */
550 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
551 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
552 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
553 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
554 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
555 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
556 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
557 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
558 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
559 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
560 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
561 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
562 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
566 case TGSI_OPCODE_DP4
:
567 /* TGSI_OPCODE_DOT4 */
568 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
569 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
570 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
571 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
572 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
573 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
574 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
575 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
576 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
577 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
578 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
579 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_W
);
580 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_W
);
581 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
582 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
583 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
584 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
588 case TGSI_OPCODE_DST
:
589 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) {
590 tmp0
= bld
->base
.one
;
591 emit_store( bld
, inst
, 0, CHAN_X
, tmp0
);
593 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) {
594 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
595 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
596 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
597 emit_store( bld
, inst
, 0, CHAN_Y
, tmp0
);
599 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) {
600 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
601 emit_store( bld
, inst
, 0, CHAN_Z
, tmp0
);
603 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) {
604 tmp0
= emit_fetch( bld
, inst
, 1, CHAN_W
);
605 emit_store( bld
, inst
, 0, CHAN_W
, tmp0
);
609 case TGSI_OPCODE_MIN
:
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
= lp_build_min( &bld
->base
, src0
, src1
);
614 emit_store( bld
, inst
, 0, chan_index
, dst0
);
618 case TGSI_OPCODE_MAX
:
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
= lp_build_max( &bld
->base
, src0
, src1
);
623 emit_store( bld
, inst
, 0, chan_index
, dst0
);
627 case TGSI_OPCODE_SLT
:
628 /* TGSI_OPCODE_SETLT */
629 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
630 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
631 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
632 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_LESS
, src0
, src1
);
633 dst0
= lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
634 emit_store( bld
, inst
, 0, chan_index
, dst0
);
638 case TGSI_OPCODE_SGE
:
639 /* TGSI_OPCODE_SETGE */
640 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
641 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
642 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
643 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_GEQUAL
, src0
, src1
);
644 dst0
= lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
645 emit_store( bld
, inst
, 0, chan_index
, dst0
);
649 case TGSI_OPCODE_MAD
:
650 /* TGSI_OPCODE_MADD */
651 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
652 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
653 tmp1
= emit_fetch( bld
, inst
, 1, chan_index
);
654 tmp2
= emit_fetch( bld
, inst
, 2, chan_index
);
655 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
656 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp2
);
657 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
661 case TGSI_OPCODE_SUB
:
662 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
663 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
664 tmp1
= emit_fetch( bld
, inst
, 1, chan_index
);
665 tmp0
= lp_build_sub( &bld
->base
, tmp0
, tmp1
);
666 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
670 case TGSI_OPCODE_LRP
:
671 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
672 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
673 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
674 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
675 tmp0
= lp_build_sub( &bld
->base
, src1
, src2
);
676 tmp0
= lp_build_mul( &bld
->base
, src0
, tmp0
);
677 dst0
= lp_build_add( &bld
->base
, tmp0
, src2
);
678 emit_store( bld
, inst
, 0, chan_index
, dst0
);
682 case TGSI_OPCODE_CND
:
687 case TGSI_OPCODE_DP2A
:
688 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
); /* xmm0 = src[0].x */
689 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
); /* xmm1 = src[1].x */
690 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 * xmm1 */
691 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
); /* xmm1 = src[0].y */
692 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
); /* xmm2 = src[1].y */
693 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
); /* xmm1 = xmm1 * xmm2 */
694 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 + xmm1 */
695 tmp1
= emit_fetch( bld
, inst
, 2, CHAN_X
); /* xmm1 = src[2].x */
696 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 + xmm1 */
697 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
698 emit_store( bld
, inst
, 0, chan_index
, tmp0
); /* dest[ch] = xmm0 */
703 case TGSI_OPCODE_FRC
:
704 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
705 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
706 emit_frc( bld
, 0, 0 );
707 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
711 case TGSI_OPCODE_CLAMP
:
715 case TGSI_OPCODE_FLR
:
716 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
717 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
718 emit_flr( bld
, 0, 0 );
719 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
723 case TGSI_OPCODE_ROUND
:
724 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
725 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
726 emit_rnd( bld
, 0, 0 );
727 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
732 case TGSI_OPCODE_EX2
: {
733 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
734 tmp0
= lp_build_exp2( &bld
->base
, tmp0
);
735 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
736 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
741 case TGSI_OPCODE_LG2
:
742 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
743 tmp0
= lp_build_log2( &bld
->base
, tmp0
);
744 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
745 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
749 case TGSI_OPCODE_POW
:
750 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
751 src1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
752 dst0
= lp_build_pow( &bld
->base
, src0
, src1
);
753 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
754 emit_store( bld
, inst
, 0, chan_index
, dst0
);
758 case TGSI_OPCODE_XPD
:
759 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
760 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ) {
761 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
762 tmp3
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
764 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
765 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) ) {
766 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
767 tmp4
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
769 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) {
771 tmp2
= lp_build_mul( &bld
->base
, tmp2
, tmp1
);
773 tmp5
= lp_build_mul( &bld
->base
, tmp5
, tmp4
);
774 tmp2
= lp_build_sub( &bld
->base
, tmp2
, tmp5
);
775 emit_store( bld
, inst
, 0, CHAN_X
, tmp2
);
777 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ||
778 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) ) {
779 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_X
);
780 tmp5
= emit_fetch( bld
, inst
, 0, CHAN_X
);
782 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) {
783 tmp3
= lp_build_mul( &bld
->base
, tmp3
, tmp2
);
784 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp5
);
785 tmp3
= lp_build_sub( &bld
->base
, tmp3
, tmp1
);
786 emit_store( bld
, inst
, 0, CHAN_Y
, tmp3
);
788 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) {
789 tmp5
= lp_build_mul( &bld
->base
, tmp5
, tmp4
);
790 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp2
);
791 tmp5
= lp_build_sub( &bld
->base
, tmp5
, tmp0
);
792 emit_store( bld
, inst
, 0, CHAN_Z
, tmp5
);
794 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) {
795 tmp0
= bld
->base
.one
;
796 emit_store( bld
, inst
, 0, CHAN_W
, tmp0
);
800 case TGSI_OPCODE_ABS
:
801 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
802 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
803 tmp0
= lp_build_abs( &bld
->base
, tmp0
) ;
804 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
808 case TGSI_OPCODE_RCC
:
812 case TGSI_OPCODE_DPH
:
813 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
814 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
815 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
816 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
817 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
818 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
819 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
820 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
821 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
822 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
823 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
824 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_W
);
825 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
826 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
827 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
831 case TGSI_OPCODE_COS
:
832 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
833 tmp0
= lp_build_cos( &bld
->base
, tmp0
);
834 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
835 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
839 case TGSI_OPCODE_DDX
:
843 case TGSI_OPCODE_DDY
:
847 case TGSI_OPCODE_KILP
:
848 /* predicated kill */
853 case TGSI_OPCODE_KIL
:
854 /* conditional kill */
855 emit_kil( bld
, inst
);
858 case TGSI_OPCODE_PK2H
:
862 case TGSI_OPCODE_PK2US
:
866 case TGSI_OPCODE_PK4B
:
870 case TGSI_OPCODE_PK4UB
:
874 case TGSI_OPCODE_RFL
:
878 case TGSI_OPCODE_SEQ
:
879 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
880 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
881 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
882 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_EQUAL
, src0
, src1
);
883 dst0
= lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
884 emit_store( bld
, inst
, 0, chan_index
, dst0
);
888 case TGSI_OPCODE_SFL
:
892 case TGSI_OPCODE_SGT
:
893 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
894 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
895 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
896 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_GREATER
, src0
, src1
);
897 dst0
= lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
898 emit_store( bld
, inst
, 0, chan_index
, dst0
);
902 case TGSI_OPCODE_SIN
:
903 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
904 tmp0
= lp_build_sin( &bld
->base
, tmp0
);
905 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
906 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
910 case TGSI_OPCODE_SLE
:
911 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
912 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
913 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
914 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_LEQUAL
, src0
, src1
);
915 dst0
= lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
916 emit_store( bld
, inst
, 0, chan_index
, dst0
);
920 case TGSI_OPCODE_SNE
:
921 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
922 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
923 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
924 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_NOTEQUAL
, src0
, src1
);
925 dst0
= lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
926 emit_store( bld
, inst
, 0, chan_index
, dst0
);
930 case TGSI_OPCODE_STR
:
934 case TGSI_OPCODE_TEX
:
935 emit_tex( bld
, inst
, FALSE
, FALSE
);
938 case TGSI_OPCODE_TXD
:
942 case TGSI_OPCODE_UP2H
:
946 case TGSI_OPCODE_UP2US
:
950 case TGSI_OPCODE_UP4B
:
954 case TGSI_OPCODE_UP4UB
:
958 case TGSI_OPCODE_X2D
:
962 case TGSI_OPCODE_ARA
:
967 case TGSI_OPCODE_ARR
:
968 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
969 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
970 emit_rnd( bld
, 0, 0 );
972 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
977 case TGSI_OPCODE_BRA
:
981 case TGSI_OPCODE_CAL
:
986 case TGSI_OPCODE_RET
:
991 case TGSI_OPCODE_END
:
995 case TGSI_OPCODE_SSG
:
996 /* TGSI_OPCODE_SGN */
997 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
998 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
999 emit_sgn( bld
, 0, 0 );
1000 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
1005 case TGSI_OPCODE_CMP
:
1006 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1007 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
1008 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
1009 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
1010 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_LESS
, src0
, bld
->base
.zero
);
1011 dst0
= lp_build_select( &bld
->base
, tmp0
, src1
, src2
);
1012 emit_store( bld
, inst
, 0, chan_index
, dst0
);
1016 case TGSI_OPCODE_SCS
:
1017 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) {
1018 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
1019 tmp0
= lp_build_cos( &bld
->base
, tmp0
);
1020 emit_store( bld
, inst
, 0, CHAN_X
, tmp0
);
1022 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) {
1023 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
1024 tmp0
= lp_build_sin( &bld
->base
, tmp0
);
1025 emit_store( bld
, inst
, 0, CHAN_Y
, tmp0
);
1027 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) {
1028 tmp0
= bld
->base
.zero
;
1029 emit_store( bld
, inst
, 0, CHAN_Z
, tmp0
);
1031 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) {
1032 tmp0
= bld
->base
.one
;
1033 emit_store( bld
, inst
, 0, CHAN_W
, tmp0
);
1037 case TGSI_OPCODE_TXB
:
1038 emit_tex( bld
, inst
, TRUE
, FALSE
);
1041 case TGSI_OPCODE_NRM
:
1043 case TGSI_OPCODE_NRM4
:
1044 /* 3 or 4-component normalization */
1046 uint dims
= (inst
->Instruction
.Opcode
== TGSI_OPCODE_NRM
) ? 3 : 4;
1048 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
) ||
1049 IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Y
) ||
1050 IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Z
) ||
1051 (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_W
) && dims
== 4)) {
1053 /* NOTE: Cannot use xmm regs 2/3 here (see emit_rsqrt() above). */
1056 /* xmm0 = src.x * src.x */
1057 tmp0
= emit_fetch(bld
, inst
, 0, CHAN_X
);
1058 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
)) {
1061 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp0
);
1064 /* xmm0 = xmm0 + src.y * src.y */
1065 tmp1
= emit_fetch(bld
, inst
, 0, CHAN_Y
);
1066 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Y
)) {
1069 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp1
);
1070 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
1073 /* xmm0 = xmm0 + src.z * src.z */
1074 tmp1
= emit_fetch(bld
, inst
, 0, CHAN_Z
);
1075 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Z
)) {
1078 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp1
);
1079 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
1083 /* xmm0 = xmm0 + src.w * src.w */
1084 tmp1
= emit_fetch(bld
, inst
, 0, CHAN_W
);
1085 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_W
)) {
1088 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp1
);
1089 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
1092 /* xmm1 = 1 / sqrt(xmm0) */
1093 tmp1
= lp_build_rsqrt( &bld
->base
, tmp0
);
1095 /* dst.x = xmm1 * src.x */
1096 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
)) {
1097 tmp4
= lp_build_mul( &bld
->base
, tmp4
, tmp1
);
1098 emit_store(bld
, inst
, 0, CHAN_X
, tmp4
);
1101 /* dst.y = xmm1 * src.y */
1102 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Y
)) {
1103 tmp5
= lp_build_mul( &bld
->base
, tmp5
, tmp1
);
1104 emit_store(bld
, inst
, 0, CHAN_Y
, tmp5
);
1107 /* dst.z = xmm1 * src.z */
1108 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Z
)) {
1109 tmp6
= lp_build_mul( &bld
->base
, tmp6
, tmp1
);
1110 emit_store(bld
, inst
, 0, CHAN_Z
, tmp6
);
1113 /* dst.w = xmm1 * src.w */
1114 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
) && dims
== 4) {
1115 tmp7
= lp_build_mul( &bld
->base
, tmp7
, tmp1
);
1116 emit_store(bld
, inst
, 0, CHAN_W
, tmp7
);
1121 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_W
) && dims
== 3) {
1122 tmp0
= bld
->base
.one
;
1123 emit_store(bld
, inst
, 0, CHAN_W
, tmp0
);
1128 case TGSI_OPCODE_DIV
:
1132 case TGSI_OPCODE_DP2
:
1133 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
); /* xmm0 = src[0].x */
1134 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
); /* xmm1 = src[1].x */
1135 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 * xmm1 */
1136 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
); /* xmm1 = src[0].y */
1137 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
); /* xmm2 = src[1].y */
1138 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
); /* xmm1 = xmm1 * xmm2 */
1139 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 + xmm1 */
1140 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1141 emit_store( bld
, inst
, 0, chan_index
, tmp0
); /* dest[ch] = xmm0 */
1145 case TGSI_OPCODE_TXL
:
1146 emit_tex( bld
, inst
, TRUE
, FALSE
);
1149 case TGSI_OPCODE_TXP
:
1150 emit_tex( bld
, inst
, FALSE
, TRUE
);
1153 case TGSI_OPCODE_BRK
:
1157 case TGSI_OPCODE_IF
:
1161 case TGSI_OPCODE_BGNFOR
:
1165 case TGSI_OPCODE_REP
:
1169 case TGSI_OPCODE_ELSE
:
1173 case TGSI_OPCODE_ENDIF
:
1177 case TGSI_OPCODE_ENDFOR
:
1181 case TGSI_OPCODE_ENDREP
:
1185 case TGSI_OPCODE_PUSHA
:
1189 case TGSI_OPCODE_POPA
:
1193 case TGSI_OPCODE_CEIL
:
1197 case TGSI_OPCODE_I2F
:
1201 case TGSI_OPCODE_NOT
:
1206 case TGSI_OPCODE_TRUNC
:
1207 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1208 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
1209 emit_f2it( bld
, 0 );
1211 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
1216 case TGSI_OPCODE_SHL
:
1220 case TGSI_OPCODE_SHR
:
1224 case TGSI_OPCODE_AND
:
1228 case TGSI_OPCODE_OR
:
1232 case TGSI_OPCODE_MOD
:
1236 case TGSI_OPCODE_XOR
:
1240 case TGSI_OPCODE_SAD
:
1244 case TGSI_OPCODE_TXF
:
1248 case TGSI_OPCODE_TXQ
:
1252 case TGSI_OPCODE_CONT
:
1256 case TGSI_OPCODE_EMIT
:
1260 case TGSI_OPCODE_ENDPRIM
:
1273 lp_build_tgsi_soa(LLVMBuilderRef builder
,
1274 const struct tgsi_token
*tokens
,
1276 struct lp_build_mask_context
*mask
,
1277 LLVMValueRef consts_ptr
,
1278 const LLVMValueRef
*pos
,
1279 const LLVMValueRef (*inputs
)[NUM_CHANNELS
],
1280 LLVMValueRef (*outputs
)[NUM_CHANNELS
],
1281 struct lp_build_sampler_soa
*sampler
)
1283 struct lp_build_tgsi_soa_context bld
;
1284 struct tgsi_parse_context parse
;
1285 uint num_immediates
= 0;
1288 /* Setup build context */
1289 memset(&bld
, 0, sizeof bld
);
1290 lp_build_context_init(&bld
.base
, builder
, type
);
1293 bld
.inputs
= inputs
;
1294 bld
.outputs
= outputs
;
1295 bld
.consts_ptr
= consts_ptr
;
1296 bld
.sampler
= sampler
;
1298 tgsi_parse_init( &parse
, tokens
);
1300 while( !tgsi_parse_end_of_tokens( &parse
) ) {
1301 tgsi_parse_token( &parse
);
1303 switch( parse
.FullToken
.Token
.Type
) {
1304 case TGSI_TOKEN_TYPE_DECLARATION
:
1305 /* Inputs already interpolated */
1308 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1309 if (!emit_instruction( &bld
, &parse
.FullToken
.FullInstruction
)) {
1310 unsigned opcode
= parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1311 const struct tgsi_opcode_info
*info
= tgsi_get_opcode_info(opcode
);
1312 _debug_printf("warning: failed to translate tgsi opcode %s to LLVM\n",
1313 info
? info
->mnemonic
: "<invalid>");
1317 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1318 /* simply copy the immediate values into the next immediates[] slot */
1320 const uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
1322 assert(num_immediates
< LP_MAX_IMMEDIATES
);
1323 for( i
= 0; i
< size
; ++i
)
1324 bld
.immediates
[num_immediates
][i
] =
1325 lp_build_const_scalar(type
, parse
.FullToken
.FullImmediate
.u
[i
].Float
);
1326 for( i
= size
; i
< 4; ++i
)
1327 bld
.immediates
[num_immediates
][i
] = bld
.base
.undef
;
1337 tgsi_parse_free( &parse
);