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 res
= lp_build_abs( &bld
->base
, res
);
171 res
= LLVMBuildNeg( bld
->base
.builder
, res
, "" );
174 case TGSI_UTIL_SIGN_TOGGLE
:
175 res
= LLVMBuildNeg( bld
->base
.builder
, res
, "" );
178 case TGSI_UTIL_SIGN_KEEP
:
191 struct lp_build_tgsi_soa_context
*bld
,
192 const struct tgsi_full_instruction
*inst
,
197 const struct tgsi_full_dst_register
*reg
= &inst
->FullDstRegisters
[index
];
199 switch( inst
->Instruction
.Saturate
) {
203 case TGSI_SAT_ZERO_ONE
:
204 value
= lp_build_max(&bld
->base
, value
, bld
->base
.zero
);
205 value
= lp_build_min(&bld
->base
, value
, bld
->base
.one
);
208 case TGSI_SAT_MINUS_PLUS_ONE
:
209 value
= lp_build_max(&bld
->base
, value
, lp_build_const_scalar(bld
->base
.type
, -1.0));
210 value
= lp_build_min(&bld
->base
, value
, bld
->base
.one
);
217 switch( reg
->DstRegister
.File
) {
218 case TGSI_FILE_OUTPUT
:
219 bld
->outputs
[reg
->DstRegister
.Index
][chan_index
] = value
;
222 case TGSI_FILE_TEMPORARY
:
223 bld
->temps
[reg
->DstRegister
.Index
][chan_index
] = value
;
226 case TGSI_FILE_ADDRESS
:
238 * High-level instruction translators.
242 emit_tex( struct lp_build_tgsi_soa_context
*bld
,
243 const struct tgsi_full_instruction
*inst
,
244 boolean apply_lodbias
,
247 const uint unit
= inst
->FullSrcRegisters
[1].SrcRegister
.Index
;
248 LLVMValueRef lodbias
;
250 LLVMValueRef coords
[3];
251 LLVMValueRef texel
[4];
255 switch (inst
->InstructionExtTexture
.Texture
) {
256 case TGSI_TEXTURE_1D
:
259 case TGSI_TEXTURE_2D
:
260 case TGSI_TEXTURE_RECT
:
263 case TGSI_TEXTURE_SHADOW1D
:
264 case TGSI_TEXTURE_SHADOW2D
:
265 case TGSI_TEXTURE_SHADOWRECT
:
266 case TGSI_TEXTURE_3D
:
267 case TGSI_TEXTURE_CUBE
:
276 lodbias
= emit_fetch( bld
, inst
, 0, 3 );
278 lodbias
= bld
->base
.zero
;
281 oow
= emit_fetch( bld
, inst
, 0, 3 );
282 oow
= lp_build_rcp(&bld
->base
, oow
);
285 for (i
= 0; i
< num_coords
; i
++) {
286 coords
[i
] = emit_fetch( bld
, inst
, 0, i
);
288 coords
[i
] = lp_build_mul(&bld
->base
, coords
[i
], oow
);
291 bld
->sampler
->emit_fetch_texel(bld
->sampler
,
294 unit
, num_coords
, coords
, lodbias
,
297 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, i
) {
298 emit_store( bld
, inst
, 0, i
, texel
[i
] );
305 struct lp_build_tgsi_soa_context
*bld
,
306 const struct tgsi_full_instruction
*inst
)
308 const struct tgsi_full_src_register
*reg
= &inst
->FullSrcRegisters
[0];
309 LLVMValueRef terms
[NUM_CHANNELS
];
313 memset(&terms
, 0, sizeof terms
);
315 FOR_EACH_CHANNEL( chan_index
) {
318 /* Unswizzle channel */
319 swizzle
= tgsi_util_get_full_src_register_extswizzle( reg
, chan_index
);
321 /* Note that we test if the value is less than zero, so 1.0 and 0.0 need
322 * not to be tested. */
323 if(swizzle
== TGSI_EXTSWIZZLE_ZERO
|| swizzle
== TGSI_EXTSWIZZLE_ONE
)
326 /* Check if the component has not been already tested. */
327 assert(swizzle
< NUM_CHANNELS
);
328 if( !terms
[swizzle
] )
329 /* TODO: change the comparison operator instead of setting the sign */
330 terms
[swizzle
] = emit_fetch(bld
, inst
, 0, chan_index
);
334 FOR_EACH_CHANNEL( chan_index
) {
335 if(terms
[chan_index
]) {
336 LLVMValueRef chan_mask
;
338 chan_mask
= lp_build_cmp(&bld
->base
, PIPE_FUNC_GEQUAL
, terms
[chan_index
], bld
->base
.zero
);
341 mask
= LLVMBuildAnd(bld
->base
.builder
, mask
, chan_mask
, "");
348 lp_build_mask_update(bld
->mask
, mask
);
354 struct lp_build_tgsi_soa_context
*bld
)
356 /* XXX todo / fix me */
361 * Check if inst src/dest regs use indirect addressing into temporary
365 indirect_temp_reference(const struct tgsi_full_instruction
*inst
)
368 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
369 const struct tgsi_full_src_register
*reg
= &inst
->FullSrcRegisters
[i
];
370 if (reg
->SrcRegister
.File
== TGSI_FILE_TEMPORARY
&&
371 reg
->SrcRegister
.Indirect
)
374 for (i
= 0; i
< inst
->Instruction
.NumDstRegs
; i
++) {
375 const struct tgsi_full_dst_register
*reg
= &inst
->FullDstRegisters
[i
];
376 if (reg
->DstRegister
.File
== TGSI_FILE_TEMPORARY
&&
377 reg
->DstRegister
.Indirect
)
386 struct lp_build_tgsi_soa_context
*bld
,
387 struct tgsi_full_instruction
*inst
)
390 LLVMValueRef src0
, src1
, src2
;
391 LLVMValueRef tmp0
, tmp1
, tmp2
, tmp3
, tmp4
, tmp5
, tmp6
, tmp7
;
394 /* we can't handle indirect addressing into temp register file yet */
395 if (indirect_temp_reference(inst
))
398 switch (inst
->Instruction
.Opcode
) {
400 case TGSI_OPCODE_ARL
:
401 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
402 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
405 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
410 case TGSI_OPCODE_MOV
:
411 case TGSI_OPCODE_SWZ
:
412 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
413 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
414 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
418 case TGSI_OPCODE_LIT
:
419 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ) {
420 emit_store( bld
, inst
, 0, CHAN_X
, bld
->base
.one
);
422 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ) {
423 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
424 dst0
= lp_build_max( &bld
->base
, src0
, bld
->base
.zero
);
425 emit_store( bld
, inst
, 0, CHAN_Y
, dst0
);
427 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) ) {
428 /* XMM[1] = SrcReg[0].yyyy */
429 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
430 /* XMM[1] = max(XMM[1], 0) */
431 tmp1
= lp_build_max( &bld
->base
, tmp1
, bld
->base
.zero
);
432 /* XMM[2] = SrcReg[0].wwww */
433 tmp2
= emit_fetch( bld
, inst
, 0, CHAN_W
);
434 tmp1
= lp_build_pow( &bld
->base
, tmp1
, tmp2
);
435 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
436 tmp2
= lp_build_cmp(&bld
->base
, PIPE_FUNC_GREATER
, tmp0
, bld
->base
.zero
);
437 dst0
= lp_build_select(&bld
->base
, tmp2
, tmp1
, bld
->base
.zero
);
438 emit_store( bld
, inst
, 0, CHAN_Z
, dst0
);
440 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) ) {
441 emit_store( bld
, inst
, 0, CHAN_W
, bld
->base
.one
);
445 case TGSI_OPCODE_RCP
:
446 /* TGSI_OPCODE_RECIP */
447 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
448 dst0
= lp_build_rcp(&bld
->base
, src0
);
449 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
450 emit_store( bld
, inst
, 0, chan_index
, dst0
);
454 case TGSI_OPCODE_RSQ
:
455 /* TGSI_OPCODE_RECIPSQRT */
456 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
457 src0
= lp_build_abs(&bld
->base
, src0
);
458 dst0
= lp_build_rsqrt(&bld
->base
, src0
);
459 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
460 emit_store( bld
, inst
, 0, chan_index
, dst0
);
464 case TGSI_OPCODE_EXP
:
465 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
466 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ||
467 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
)) {
468 LLVMValueRef
*p_exp2_int_part
= NULL
;
469 LLVMValueRef
*p_frac_part
= NULL
;
470 LLVMValueRef
*p_exp2
= NULL
;
472 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
474 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
475 p_exp2_int_part
= &tmp0
;
476 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
))
478 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
481 lp_build_exp2_approx(&bld
->base
, src0
, p_exp2_int_part
, p_frac_part
, p_exp2
);
483 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
484 emit_store( bld
, inst
, 0, CHAN_X
, tmp0
);
485 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
))
486 emit_store( bld
, inst
, 0, CHAN_Y
, tmp1
);
487 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
488 emit_store( bld
, inst
, 0, CHAN_Z
, tmp2
);
491 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
)) {
492 tmp0
= bld
->base
.one
;
493 emit_store( bld
, inst
, 0, CHAN_W
, tmp0
);
497 case TGSI_OPCODE_LOG
:
498 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
499 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ||
500 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
)) {
501 LLVMValueRef
*p_floor_log2
;
503 LLVMValueRef
*p_log2
;
505 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
506 src0
= lp_build_abs( &bld
->base
, src0
);
508 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
509 p_floor_log2
= &tmp0
;
510 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
))
512 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
515 lp_build_log2_approx(&bld
->base
, src0
, p_exp
, p_floor_log2
, p_log2
);
517 /* dst.x = floor(lg2(abs(src.x))) */
518 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
))
519 emit_store( bld
, inst
, 0, CHAN_X
, tmp0
);
520 /* dst.y = abs(src)/ex2(floor(lg2(abs(src.x)))) */
521 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
)) {
522 tmp1
= lp_build_div( &bld
->base
, src0
, tmp1
);
523 emit_store( bld
, inst
, 0, CHAN_Y
, tmp1
);
525 /* dst.z = lg2(abs(src.x)) */
526 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
))
527 emit_store( bld
, inst
, 0, CHAN_Z
, tmp2
);
530 if (IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
)) {
531 tmp0
= bld
->base
.one
;
532 emit_store( bld
, inst
, 0, CHAN_W
, tmp0
);
536 case TGSI_OPCODE_MUL
:
537 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
538 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
539 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
540 dst0
= lp_build_mul(&bld
->base
, src0
, src1
);
541 emit_store( bld
, inst
, 0, chan_index
, dst0
);
545 case TGSI_OPCODE_ADD
:
546 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
547 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
548 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
549 dst0
= lp_build_add(&bld
->base
, src0
, src1
);
550 emit_store( bld
, inst
, 0, chan_index
, dst0
);
554 case TGSI_OPCODE_DP3
:
555 /* TGSI_OPCODE_DOT3 */
556 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
557 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
558 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
559 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
560 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
561 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
562 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
563 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
564 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
565 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
566 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
567 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
568 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
572 case TGSI_OPCODE_DP4
:
573 /* TGSI_OPCODE_DOT4 */
574 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
575 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
576 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
577 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
578 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
579 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
580 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
581 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
582 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
583 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
584 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
585 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_W
);
586 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_W
);
587 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
588 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
589 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
590 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
594 case TGSI_OPCODE_DST
:
595 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) {
596 tmp0
= bld
->base
.one
;
597 emit_store( bld
, inst
, 0, CHAN_X
, tmp0
);
599 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) {
600 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
601 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
602 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
603 emit_store( bld
, inst
, 0, CHAN_Y
, tmp0
);
605 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) {
606 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
607 emit_store( bld
, inst
, 0, CHAN_Z
, tmp0
);
609 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) {
610 tmp0
= emit_fetch( bld
, inst
, 1, CHAN_W
);
611 emit_store( bld
, inst
, 0, CHAN_W
, tmp0
);
615 case TGSI_OPCODE_MIN
:
616 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
617 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
618 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
619 dst0
= lp_build_min( &bld
->base
, src0
, src1
);
620 emit_store( bld
, inst
, 0, chan_index
, dst0
);
624 case TGSI_OPCODE_MAX
:
625 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
626 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
627 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
628 dst0
= lp_build_max( &bld
->base
, src0
, src1
);
629 emit_store( bld
, inst
, 0, chan_index
, dst0
);
633 case TGSI_OPCODE_SLT
:
634 /* TGSI_OPCODE_SETLT */
635 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
636 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
637 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
638 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_LESS
, src0
, src1
);
639 dst0
= lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
640 emit_store( bld
, inst
, 0, chan_index
, dst0
);
644 case TGSI_OPCODE_SGE
:
645 /* TGSI_OPCODE_SETGE */
646 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
647 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
648 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
649 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_GEQUAL
, src0
, src1
);
650 dst0
= lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
651 emit_store( bld
, inst
, 0, chan_index
, dst0
);
655 case TGSI_OPCODE_MAD
:
656 /* TGSI_OPCODE_MADD */
657 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
658 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
659 tmp1
= emit_fetch( bld
, inst
, 1, chan_index
);
660 tmp2
= emit_fetch( bld
, inst
, 2, chan_index
);
661 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
662 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp2
);
663 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
667 case TGSI_OPCODE_SUB
:
668 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
669 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
670 tmp1
= emit_fetch( bld
, inst
, 1, chan_index
);
671 tmp0
= lp_build_sub( &bld
->base
, tmp0
, tmp1
);
672 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
676 case TGSI_OPCODE_LRP
:
677 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
678 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
679 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
680 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
681 tmp0
= lp_build_sub( &bld
->base
, src1
, src2
);
682 tmp0
= lp_build_mul( &bld
->base
, src0
, tmp0
);
683 dst0
= lp_build_add( &bld
->base
, tmp0
, src2
);
684 emit_store( bld
, inst
, 0, chan_index
, dst0
);
688 case TGSI_OPCODE_CND
:
692 case TGSI_OPCODE_DP2A
:
693 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
); /* xmm0 = src[0].x */
694 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
); /* xmm1 = src[1].x */
695 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 * xmm1 */
696 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
); /* xmm1 = src[0].y */
697 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
); /* xmm2 = src[1].y */
698 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
); /* xmm1 = xmm1 * xmm2 */
699 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 + xmm1 */
700 tmp1
= emit_fetch( bld
, inst
, 2, CHAN_X
); /* xmm1 = src[2].x */
701 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 + xmm1 */
702 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
703 emit_store( bld
, inst
, 0, chan_index
, tmp0
); /* dest[ch] = xmm0 */
708 case TGSI_OPCODE_FRC
:
709 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
710 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
711 emit_frc( bld
, 0, 0 );
712 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
716 case TGSI_OPCODE_CLAMP
:
720 case TGSI_OPCODE_FLR
:
721 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
722 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
723 emit_flr( bld
, 0, 0 );
724 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
728 case TGSI_OPCODE_ROUND
:
729 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
730 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
731 emit_rnd( bld
, 0, 0 );
732 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
737 case TGSI_OPCODE_EX2
: {
738 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
739 tmp0
= lp_build_exp2( &bld
->base
, tmp0
);
740 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
741 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
746 case TGSI_OPCODE_LG2
:
747 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
748 tmp0
= lp_build_log2( &bld
->base
, tmp0
);
749 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
750 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
754 case TGSI_OPCODE_POW
:
755 src0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
756 src1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
757 dst0
= lp_build_pow( &bld
->base
, src0
, src1
);
758 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
759 emit_store( bld
, inst
, 0, chan_index
, dst0
);
763 case TGSI_OPCODE_XPD
:
764 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
765 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ) {
766 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
767 tmp3
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
769 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) ||
770 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) ) {
771 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
772 tmp4
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
774 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) {
776 tmp2
= lp_build_mul( &bld
->base
, tmp2
, tmp1
);
778 tmp5
= lp_build_mul( &bld
->base
, tmp5
, tmp4
);
779 tmp2
= lp_build_sub( &bld
->base
, tmp2
, tmp5
);
780 emit_store( bld
, inst
, 0, CHAN_X
, tmp2
);
782 if( IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) ||
783 IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) ) {
784 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_X
);
785 tmp5
= emit_fetch( bld
, inst
, 0, CHAN_X
);
787 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) {
788 tmp3
= lp_build_mul( &bld
->base
, tmp3
, tmp2
);
789 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp5
);
790 tmp3
= lp_build_sub( &bld
->base
, tmp3
, tmp1
);
791 emit_store( bld
, inst
, 0, CHAN_Y
, tmp3
);
793 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) {
794 tmp5
= lp_build_mul( &bld
->base
, tmp5
, tmp4
);
795 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp2
);
796 tmp5
= lp_build_sub( &bld
->base
, tmp5
, tmp0
);
797 emit_store( bld
, inst
, 0, CHAN_Z
, tmp5
);
799 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) {
800 tmp0
= bld
->base
.one
;
801 emit_store( bld
, inst
, 0, CHAN_W
, tmp0
);
805 case TGSI_OPCODE_ABS
:
806 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
807 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
808 tmp0
= lp_build_abs( &bld
->base
, tmp0
) ;
809 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
813 case TGSI_OPCODE_RCC
:
817 case TGSI_OPCODE_DPH
:
818 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
819 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
);
820 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
);
821 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
);
822 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
);
823 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
824 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
825 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Z
);
826 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Z
);
827 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
);
828 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
829 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_W
);
830 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
831 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
832 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
836 case TGSI_OPCODE_COS
:
837 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
838 tmp0
= lp_build_cos( &bld
->base
, tmp0
);
839 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
840 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
844 case TGSI_OPCODE_DDX
:
848 case TGSI_OPCODE_DDY
:
853 case TGSI_OPCODE_KILP
:
854 /* predicated kill */
856 return 0; /* XXX fix me */
860 case TGSI_OPCODE_KIL
:
861 /* conditional kill */
862 emit_kil( bld
, inst
);
865 case TGSI_OPCODE_PK2H
:
869 case TGSI_OPCODE_PK2US
:
873 case TGSI_OPCODE_PK4B
:
877 case TGSI_OPCODE_PK4UB
:
881 case TGSI_OPCODE_RFL
:
885 case TGSI_OPCODE_SEQ
:
886 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
887 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
888 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
889 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_EQUAL
, src0
, src1
);
890 dst0
= lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
891 emit_store( bld
, inst
, 0, chan_index
, dst0
);
895 case TGSI_OPCODE_SFL
:
899 case TGSI_OPCODE_SGT
:
900 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
901 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
902 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
903 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_GREATER
, src0
, src1
);
904 dst0
= lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
905 emit_store( bld
, inst
, 0, chan_index
, dst0
);
909 case TGSI_OPCODE_SIN
:
910 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
911 tmp0
= lp_build_sin( &bld
->base
, tmp0
);
912 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
913 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
917 case TGSI_OPCODE_SLE
:
918 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
919 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
920 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
921 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_LEQUAL
, src0
, src1
);
922 dst0
= lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
923 emit_store( bld
, inst
, 0, chan_index
, dst0
);
927 case TGSI_OPCODE_SNE
:
928 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
929 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
930 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
931 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_NOTEQUAL
, src0
, src1
);
932 dst0
= lp_build_select( &bld
->base
, tmp0
, bld
->base
.one
, bld
->base
.zero
);
933 emit_store( bld
, inst
, 0, chan_index
, dst0
);
937 case TGSI_OPCODE_STR
:
941 case TGSI_OPCODE_TEX
:
942 emit_tex( bld
, inst
, FALSE
, FALSE
);
945 case TGSI_OPCODE_TXD
:
949 case TGSI_OPCODE_UP2H
:
953 case TGSI_OPCODE_UP2US
:
957 case TGSI_OPCODE_UP4B
:
961 case TGSI_OPCODE_UP4UB
:
965 case TGSI_OPCODE_X2D
:
969 case TGSI_OPCODE_ARA
:
974 case TGSI_OPCODE_ARR
:
975 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
976 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
977 emit_rnd( bld
, 0, 0 );
979 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
984 case TGSI_OPCODE_BRA
:
988 case TGSI_OPCODE_CAL
:
993 case TGSI_OPCODE_RET
:
998 case TGSI_OPCODE_END
:
1002 case TGSI_OPCODE_SSG
:
1003 /* TGSI_OPCODE_SGN */
1004 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1005 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
1006 emit_sgn( bld
, 0, 0 );
1007 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
1012 case TGSI_OPCODE_CMP
:
1013 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1014 src0
= emit_fetch( bld
, inst
, 0, chan_index
);
1015 src1
= emit_fetch( bld
, inst
, 1, chan_index
);
1016 src2
= emit_fetch( bld
, inst
, 2, chan_index
);
1017 tmp0
= lp_build_cmp( &bld
->base
, PIPE_FUNC_LESS
, src0
, bld
->base
.zero
);
1018 dst0
= lp_build_select( &bld
->base
, tmp0
, src1
, src2
);
1019 emit_store( bld
, inst
, 0, chan_index
, dst0
);
1023 case TGSI_OPCODE_SCS
:
1024 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_X
) {
1025 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
1026 tmp0
= lp_build_cos( &bld
->base
, tmp0
);
1027 emit_store( bld
, inst
, 0, CHAN_X
, tmp0
);
1029 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Y
) {
1030 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
);
1031 tmp0
= lp_build_sin( &bld
->base
, tmp0
);
1032 emit_store( bld
, inst
, 0, CHAN_Y
, tmp0
);
1034 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_Z
) {
1035 tmp0
= bld
->base
.zero
;
1036 emit_store( bld
, inst
, 0, CHAN_Z
, tmp0
);
1038 IF_IS_DST0_CHANNEL_ENABLED( inst
, CHAN_W
) {
1039 tmp0
= bld
->base
.one
;
1040 emit_store( bld
, inst
, 0, CHAN_W
, tmp0
);
1044 case TGSI_OPCODE_TXB
:
1045 emit_tex( bld
, inst
, TRUE
, FALSE
);
1048 case TGSI_OPCODE_NRM
:
1050 case TGSI_OPCODE_NRM4
:
1051 /* 3 or 4-component normalization */
1053 uint dims
= (inst
->Instruction
.Opcode
== TGSI_OPCODE_NRM
) ? 3 : 4;
1055 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
) ||
1056 IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Y
) ||
1057 IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Z
) ||
1058 (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_W
) && dims
== 4)) {
1060 /* NOTE: Cannot use xmm regs 2/3 here (see emit_rsqrt() above). */
1063 /* xmm0 = src.x * src.x */
1064 tmp0
= emit_fetch(bld
, inst
, 0, CHAN_X
);
1065 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
)) {
1068 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp0
);
1071 /* xmm0 = xmm0 + src.y * src.y */
1072 tmp1
= emit_fetch(bld
, inst
, 0, CHAN_Y
);
1073 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Y
)) {
1076 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp1
);
1077 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
1080 /* xmm0 = xmm0 + src.z * src.z */
1081 tmp1
= emit_fetch(bld
, inst
, 0, CHAN_Z
);
1082 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Z
)) {
1085 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp1
);
1086 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
1090 /* xmm0 = xmm0 + src.w * src.w */
1091 tmp1
= emit_fetch(bld
, inst
, 0, CHAN_W
);
1092 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_W
)) {
1095 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp1
);
1096 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
);
1099 /* xmm1 = 1 / sqrt(xmm0) */
1100 tmp1
= lp_build_rsqrt( &bld
->base
, tmp0
);
1102 /* dst.x = xmm1 * src.x */
1103 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
)) {
1104 tmp4
= lp_build_mul( &bld
->base
, tmp4
, tmp1
);
1105 emit_store(bld
, inst
, 0, CHAN_X
, tmp4
);
1108 /* dst.y = xmm1 * src.y */
1109 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Y
)) {
1110 tmp5
= lp_build_mul( &bld
->base
, tmp5
, tmp1
);
1111 emit_store(bld
, inst
, 0, CHAN_Y
, tmp5
);
1114 /* dst.z = xmm1 * src.z */
1115 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_Z
)) {
1116 tmp6
= lp_build_mul( &bld
->base
, tmp6
, tmp1
);
1117 emit_store(bld
, inst
, 0, CHAN_Z
, tmp6
);
1120 /* dst.w = xmm1 * src.w */
1121 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_X
) && dims
== 4) {
1122 tmp7
= lp_build_mul( &bld
->base
, tmp7
, tmp1
);
1123 emit_store(bld
, inst
, 0, CHAN_W
, tmp7
);
1128 if (IS_DST0_CHANNEL_ENABLED(inst
, CHAN_W
) && dims
== 3) {
1129 tmp0
= bld
->base
.one
;
1130 emit_store(bld
, inst
, 0, CHAN_W
, tmp0
);
1135 case TGSI_OPCODE_DIV
:
1139 case TGSI_OPCODE_DP2
:
1140 tmp0
= emit_fetch( bld
, inst
, 0, CHAN_X
); /* xmm0 = src[0].x */
1141 tmp1
= emit_fetch( bld
, inst
, 1, CHAN_X
); /* xmm1 = src[1].x */
1142 tmp0
= lp_build_mul( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 * xmm1 */
1143 tmp1
= emit_fetch( bld
, inst
, 0, CHAN_Y
); /* xmm1 = src[0].y */
1144 tmp2
= emit_fetch( bld
, inst
, 1, CHAN_Y
); /* xmm2 = src[1].y */
1145 tmp1
= lp_build_mul( &bld
->base
, tmp1
, tmp2
); /* xmm1 = xmm1 * xmm2 */
1146 tmp0
= lp_build_add( &bld
->base
, tmp0
, tmp1
); /* xmm0 = xmm0 + xmm1 */
1147 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1148 emit_store( bld
, inst
, 0, chan_index
, tmp0
); /* dest[ch] = xmm0 */
1152 case TGSI_OPCODE_TXL
:
1153 emit_tex( bld
, inst
, TRUE
, FALSE
);
1156 case TGSI_OPCODE_TXP
:
1157 emit_tex( bld
, inst
, FALSE
, TRUE
);
1160 case TGSI_OPCODE_BRK
:
1164 case TGSI_OPCODE_IF
:
1168 case TGSI_OPCODE_BGNFOR
:
1172 case TGSI_OPCODE_REP
:
1176 case TGSI_OPCODE_ELSE
:
1180 case TGSI_OPCODE_ENDIF
:
1184 case TGSI_OPCODE_ENDFOR
:
1188 case TGSI_OPCODE_ENDREP
:
1192 case TGSI_OPCODE_PUSHA
:
1196 case TGSI_OPCODE_POPA
:
1200 case TGSI_OPCODE_CEIL
:
1204 case TGSI_OPCODE_I2F
:
1208 case TGSI_OPCODE_NOT
:
1213 case TGSI_OPCODE_TRUNC
:
1214 FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1215 tmp0
= emit_fetch( bld
, inst
, 0, chan_index
);
1216 emit_f2it( bld
, 0 );
1218 emit_store( bld
, inst
, 0, chan_index
, tmp0
);
1223 case TGSI_OPCODE_SHL
:
1227 case TGSI_OPCODE_SHR
:
1231 case TGSI_OPCODE_AND
:
1235 case TGSI_OPCODE_OR
:
1239 case TGSI_OPCODE_MOD
:
1243 case TGSI_OPCODE_XOR
:
1247 case TGSI_OPCODE_SAD
:
1251 case TGSI_OPCODE_TXF
:
1255 case TGSI_OPCODE_TXQ
:
1259 case TGSI_OPCODE_CONT
:
1263 case TGSI_OPCODE_EMIT
:
1267 case TGSI_OPCODE_ENDPRIM
:
1280 lp_build_tgsi_soa(LLVMBuilderRef builder
,
1281 const struct tgsi_token
*tokens
,
1283 struct lp_build_mask_context
*mask
,
1284 LLVMValueRef consts_ptr
,
1285 const LLVMValueRef
*pos
,
1286 const LLVMValueRef (*inputs
)[NUM_CHANNELS
],
1287 LLVMValueRef (*outputs
)[NUM_CHANNELS
],
1288 struct lp_build_sampler_soa
*sampler
)
1290 struct lp_build_tgsi_soa_context bld
;
1291 struct tgsi_parse_context parse
;
1292 uint num_immediates
= 0;
1295 /* Setup build context */
1296 memset(&bld
, 0, sizeof bld
);
1297 lp_build_context_init(&bld
.base
, builder
, type
);
1300 bld
.inputs
= inputs
;
1301 bld
.outputs
= outputs
;
1302 bld
.consts_ptr
= consts_ptr
;
1303 bld
.sampler
= sampler
;
1305 tgsi_parse_init( &parse
, tokens
);
1307 while( !tgsi_parse_end_of_tokens( &parse
) ) {
1308 tgsi_parse_token( &parse
);
1310 switch( parse
.FullToken
.Token
.Type
) {
1311 case TGSI_TOKEN_TYPE_DECLARATION
:
1312 /* Input already interpolated */
1315 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1316 if (!emit_instruction( &bld
, &parse
.FullToken
.FullInstruction
)) {
1317 unsigned opcode
= parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1318 const struct tgsi_opcode_info
*info
= tgsi_get_opcode_info(opcode
);
1319 _debug_printf("warning: failed to translate tgsi opcode %s to LLVM\n",
1320 info
? info
->mnemonic
: "<invalid>");
1324 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1325 /* simply copy the immediate values into the next immediates[] slot */
1327 const uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
1329 assert(num_immediates
< LP_MAX_IMMEDIATES
);
1330 for( i
= 0; i
< size
; ++i
)
1331 bld
.immediates
[num_immediates
][i
] =
1332 lp_build_const_scalar(type
, parse
.FullToken
.FullImmediate
.u
[i
].Float
);
1333 for( i
= size
; i
< 4; ++i
)
1334 bld
.immediates
[num_immediates
][i
] = bld
.base
.undef
;
1344 tgsi_parse_free( &parse
);