gallium: remove TGSI opcode BREAKC
[mesa.git] / src / gallium / auxiliary / gallivm / lp_bld_tgsi_action.c
1 /**************************************************************************
2 *
3 * Copyright 2011-2012 Advanced Micro Devices, Inc.
4 * Copyright 2009 VMware, Inc.
5 * Copyright 2007-2008 VMware, Inc.
6 * All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
24 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
28 **************************************************************************/
29
30 /**
31 * @file
32 * TGSI to LLVM IR translation.
33 *
34 * @author Jose Fonseca <jfonseca@vmware.com>
35 * @author Tom Stellard <thomas.stellard@amd.com>
36 *
37 * Based on tgsi_sse2.c code written by Michal Krol, Keith Whitwell,
38 * Brian Paul, and others.
39 */
40
41
42 #include "lp_bld_tgsi_action.h"
43
44 #include "lp_bld_tgsi.h"
45 #include "lp_bld_arit.h"
46 #include "lp_bld_bitarit.h"
47 #include "lp_bld_const.h"
48 #include "lp_bld_conv.h"
49 #include "lp_bld_gather.h"
50 #include "lp_bld_logic.h"
51 #include "lp_bld_pack.h"
52
53 #include "tgsi/tgsi_exec.h"
54
55 /* XXX: The CPU only defaults should be repaced by generic ones. In most
56 * cases, the CPU defaults are just wrappers around a function in
57 * lp_build_arit.c and these functions should be inlined here and the CPU
58 * generic code should be removed and placed elsewhere.
59 */
60
61 /* Default actions */
62
63 /* Generic fetch_arg functions */
64
65 static void scalar_unary_fetch_args(
66 struct lp_build_tgsi_context * bld_base,
67 struct lp_build_emit_data * emit_data)
68 {
69 /* src0.x */
70 emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst, 0, 0);
71 emit_data->arg_count = 1;
72 emit_data->dst_type = LLVMTypeOf(emit_data->args[0]);
73 }
74
75 static void scalar_binary_fetch_args(
76 struct lp_build_tgsi_context * bld_base,
77 struct lp_build_emit_data * emit_data)
78 {
79 /* src0.x */
80 emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst,
81 0, TGSI_CHAN_X);
82 /* src1.x */
83 emit_data->args[1] = lp_build_emit_fetch(bld_base, emit_data->inst,
84 1, TGSI_CHAN_X);
85 emit_data->arg_count = 2;
86 emit_data->dst_type = LLVMTypeOf(emit_data->args[0]);
87 }
88
89 /* TGSI_OPCODE_ADD */
90 static void
91 add_emit(
92 const struct lp_build_tgsi_action * action,
93 struct lp_build_tgsi_context * bld_base,
94 struct lp_build_emit_data * emit_data)
95 {
96 emit_data->output[emit_data->chan] = LLVMBuildFAdd(
97 bld_base->base.gallivm->builder,
98 emit_data->args[0], emit_data->args[1], "");
99 }
100
101 /* TGSI_OPCODE_ARR */
102 static void
103 arr_emit(
104 const struct lp_build_tgsi_action * action,
105 struct lp_build_tgsi_context * bld_base,
106 struct lp_build_emit_data * emit_data)
107 {
108 LLVMValueRef tmp = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_ROUND, emit_data->args[0]);
109 emit_data->output[emit_data->chan] = LLVMBuildFPToSI(bld_base->base.gallivm->builder, tmp,
110 bld_base->uint_bld.vec_type, "");
111 }
112
113 /* DP* Helper */
114
115 static void
116 dp_fetch_args(
117 struct lp_build_tgsi_context * bld_base,
118 struct lp_build_emit_data * emit_data,
119 unsigned dp_components)
120 {
121 unsigned chan, src;
122 for (src = 0; src < 2; src++) {
123 for (chan = 0; chan < dp_components; chan++) {
124 emit_data->args[(src * dp_components) + chan] =
125 lp_build_emit_fetch(bld_base, emit_data->inst, src, chan);
126 }
127 }
128 emit_data->dst_type = bld_base->base.elem_type;
129 }
130
131 /* TGSI_OPCODE_DP2 */
132 static void
133 dp2_fetch_args(
134 struct lp_build_tgsi_context * bld_base,
135 struct lp_build_emit_data * emit_data)
136 {
137 dp_fetch_args(bld_base, emit_data, 2);
138 }
139
140 static void
141 dp2_emit(
142 const struct lp_build_tgsi_action * action,
143 struct lp_build_tgsi_context * bld_base,
144 struct lp_build_emit_data * emit_data)
145 {
146 LLVMValueRef tmp0, tmp1;
147 tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL,
148 emit_data->args[0] /* src0.x */,
149 emit_data->args[2] /* src1.x */);
150 tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL,
151 emit_data->args[1] /* src0.y */,
152 emit_data->args[3] /* src1.y */);
153 emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base,
154 TGSI_OPCODE_ADD, tmp0, tmp1);
155 }
156
157 static struct lp_build_tgsi_action dp2_action = {
158 dp2_fetch_args, /* fetch_args */
159 dp2_emit /* emit */
160 };
161
162 /* TGSI_OPCODE_DP3 */
163 static void
164 dp3_fetch_args(
165 struct lp_build_tgsi_context * bld_base,
166 struct lp_build_emit_data * emit_data)
167 {
168 dp_fetch_args(bld_base, emit_data, 3);
169 }
170
171 static void
172 dp3_emit(
173 const struct lp_build_tgsi_action * action,
174 struct lp_build_tgsi_context * bld_base,
175 struct lp_build_emit_data * emit_data)
176 {
177 LLVMValueRef tmp0, tmp1;
178 tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL,
179 emit_data->args[0] /* src0.x */,
180 emit_data->args[3] /* src1.x */);
181 tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL,
182 emit_data->args[1] /* src0.y */,
183 emit_data->args[4] /* src1.y */);
184 tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_ADD, tmp1, tmp0);
185 tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL,
186 emit_data->args[2] /* src0.z */,
187 emit_data->args[5] /* src1.z */);
188 emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base,
189 TGSI_OPCODE_ADD, tmp0, tmp1);
190 }
191
192 static struct lp_build_tgsi_action dp3_action = {
193 dp3_fetch_args, /* fetch_args */
194 dp3_emit /* emit */
195 };
196
197 /* TGSI_OPCODDE_DP4 */
198
199 static void
200 dp4_fetch_args(
201 struct lp_build_tgsi_context * bld_base,
202 struct lp_build_emit_data * emit_data)
203 {
204 dp_fetch_args(bld_base, emit_data, 4);
205 }
206
207 static void
208 dp4_emit(
209 const struct lp_build_tgsi_action * action,
210 struct lp_build_tgsi_context * bld_base,
211 struct lp_build_emit_data * emit_data)
212 {
213 LLVMValueRef tmp0, tmp1;
214 tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL,
215 emit_data->args[0] /* src0.x */,
216 emit_data->args[4] /* src1.x */);
217 tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL,
218 emit_data->args[1] /* src0.y */,
219 emit_data->args[5] /* src1.y */);
220 tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_ADD, tmp0, tmp1);
221 tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL,
222 emit_data->args[2] /* src0.z */,
223 emit_data->args[6] /* src1.z */);
224 tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_ADD, tmp0, tmp1);
225 tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL,
226 emit_data->args[3] /* src0.w */,
227 emit_data->args[7] /* src1.w */);
228 emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base,
229 TGSI_OPCODE_ADD, tmp0, tmp1);
230 }
231
232 static struct lp_build_tgsi_action dp4_action = {
233 dp4_fetch_args, /* fetch_args */
234 dp4_emit /* emit */
235 };
236
237 /* TGSI_OPCODE_DST */
238 static void
239 dst_fetch_args(
240 struct lp_build_tgsi_context * bld_base,
241 struct lp_build_emit_data * emit_data)
242 {
243 /* src0.y */
244 emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst,
245 0, TGSI_CHAN_Y);
246 /* src0.z */
247 emit_data->args[1] = lp_build_emit_fetch(bld_base, emit_data->inst,
248 0, TGSI_CHAN_Z);
249 /* src1.y */
250 emit_data->args[2] = lp_build_emit_fetch(bld_base, emit_data->inst,
251 1, TGSI_CHAN_Y);
252 /* src1.w */
253 emit_data->args[3] = lp_build_emit_fetch(bld_base, emit_data->inst,
254 1, TGSI_CHAN_W);
255 }
256
257 static void
258 dst_emit(
259 const struct lp_build_tgsi_action * action,
260 struct lp_build_tgsi_context * bld_base,
261 struct lp_build_emit_data * emit_data)
262 {
263 /* dst.x */
264 emit_data->output[TGSI_CHAN_X] = bld_base->base.one;
265
266 /* dst.y */
267 emit_data->output[TGSI_CHAN_Y] = lp_build_emit_llvm_binary(bld_base,
268 TGSI_OPCODE_MUL,
269 emit_data->args[0] /* src0.y */,
270 emit_data->args[2] /* src1.y */);
271 /* dst.z */
272 emit_data->output[TGSI_CHAN_Z] = emit_data->args[1]; /* src0.z */
273
274 /* dst.w */
275 emit_data->output[TGSI_CHAN_W] = emit_data->args[3]; /* src1.w */
276 }
277
278 static struct lp_build_tgsi_action dst_action = {
279 dst_fetch_args, /* fetch_args */
280 dst_emit /* emit */
281 };
282
283 /* TGSI_OPCODE_END */
284 static void
285 end_emit(
286 const struct lp_build_tgsi_action * action,
287 struct lp_build_tgsi_context * bld_base,
288 struct lp_build_emit_data * emit_data)
289 {
290 bld_base->pc = -1;
291 }
292
293 /* TGSI_OPCODE_EXP */
294
295 static void
296 exp_emit(
297 const struct lp_build_tgsi_action * action,
298 struct lp_build_tgsi_context * bld_base,
299 struct lp_build_emit_data * emit_data)
300 {
301 LLVMValueRef floor_x;
302
303 /* floor( src0.x ) */
304 floor_x = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_FLR,
305 emit_data->args[0]);
306
307 /* 2 ^ floor( src0.x ) */
308 emit_data->output[TGSI_CHAN_X] = lp_build_emit_llvm_unary(bld_base,
309 TGSI_OPCODE_EX2, floor_x);
310
311 /* src0.x - floor( src0.x ) */
312 emit_data->output[TGSI_CHAN_Y] =
313 lp_build_sub(&bld_base->base, emit_data->args[0] /* src0.x */, floor_x);
314
315 /* 2 ^ src0.x */
316 emit_data->output[TGSI_CHAN_Z] = lp_build_emit_llvm_unary(bld_base,
317 TGSI_OPCODE_EX2, emit_data->args[0] /* src0.x */);
318
319 emit_data->output[TGSI_CHAN_W] = bld_base->base.one;
320 }
321
322 const struct lp_build_tgsi_action exp_action = {
323 scalar_unary_fetch_args, /* fetch_args */
324 exp_emit /* emit */
325 };
326
327 /* TGSI_OPCODE_FRC */
328
329 static void
330 frc_emit(
331 const struct lp_build_tgsi_action * action,
332 struct lp_build_tgsi_context * bld_base,
333 struct lp_build_emit_data * emit_data)
334 {
335 LLVMValueRef tmp;
336 tmp = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_FLR,
337 emit_data->args[0]);
338 emit_data->output[emit_data->chan] =
339 lp_build_sub(&bld_base->base, emit_data->args[0], tmp);
340 }
341
342 /* TGSI_OPCODE_KILL_IF */
343
344 static void
345 kil_fetch_args(
346 struct lp_build_tgsi_context * bld_base,
347 struct lp_build_emit_data * emit_data)
348 {
349 /* src0.x */
350 emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst,
351 0, TGSI_CHAN_X);
352 /* src0.y */
353 emit_data->args[1] = lp_build_emit_fetch(bld_base, emit_data->inst,
354 0, TGSI_CHAN_Y);
355 /* src0.z */
356 emit_data->args[2] = lp_build_emit_fetch(bld_base, emit_data->inst,
357 0, TGSI_CHAN_Z);
358 /* src0.w */
359 emit_data->args[3] = lp_build_emit_fetch(bld_base, emit_data->inst,
360 0, TGSI_CHAN_W);
361 emit_data->arg_count = 4;
362 emit_data->dst_type = LLVMVoidTypeInContext(bld_base->base.gallivm->context);
363 }
364
365 /* TGSI_OPCODE_KILL */
366
367 static void
368 kilp_fetch_args(
369 struct lp_build_tgsi_context * bld_base,
370 struct lp_build_emit_data * emit_data)
371 {
372 emit_data->dst_type = LLVMVoidTypeInContext(bld_base->base.gallivm->context);
373 }
374
375 /* TGSI_OPCODE_LIT */
376
377 static void
378 lit_fetch_args(
379 struct lp_build_tgsi_context * bld_base,
380 struct lp_build_emit_data * emit_data)
381 {
382 /* src0.x */
383 emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst, 0, TGSI_CHAN_X);
384 /* src0.y */
385 emit_data->args[1] = lp_build_emit_fetch(bld_base, emit_data->inst, 0, TGSI_CHAN_Y);
386 /* src0.w */
387 emit_data->args[2] = lp_build_emit_fetch(bld_base, emit_data->inst, 0, TGSI_CHAN_W);
388 emit_data->arg_count = 3;
389 }
390
391 static void
392 lit_emit(
393 const struct lp_build_tgsi_action * action,
394 struct lp_build_tgsi_context * bld_base,
395 struct lp_build_emit_data * emit_data)
396 {
397 LLVMValueRef tmp0, tmp1, tmp2;
398
399 /* dst.x */
400 emit_data->output[TGSI_CHAN_X] = bld_base->base.one;
401
402 /* dst. y */
403 emit_data->output[TGSI_CHAN_Y] = lp_build_emit_llvm_binary(bld_base,
404 TGSI_OPCODE_MAX,
405 emit_data->args[0] /* src0.x */,
406 bld_base->base.zero);
407
408 /* dst.z */
409 /* XMM[1] = SrcReg[0].yyyy */
410 tmp1 = emit_data->args[1];
411 /* XMM[1] = max(XMM[1], 0) */
412 tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MAX,
413 tmp1, bld_base->base.zero);
414 /* XMM[2] = SrcReg[0].wwww */
415 tmp2 = emit_data->args[2];
416 tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_POW,
417 tmp1, tmp2);
418 tmp0 = emit_data->args[0];
419 emit_data->output[TGSI_CHAN_Z] = lp_build_emit_llvm_ternary(bld_base,
420 TGSI_OPCODE_CMP,
421 tmp0, bld_base->base.zero, tmp1);
422 /* dst.w */
423 emit_data->output[TGSI_CHAN_W] = bld_base->base.one;
424 }
425
426 static struct lp_build_tgsi_action lit_action = {
427 lit_fetch_args, /* fetch_args */
428 lit_emit /* emit */
429 };
430
431 /* TGSI_OPCODE_LOG */
432
433 static void
434 log_emit(
435 const struct lp_build_tgsi_action * action,
436 struct lp_build_tgsi_context * bld_base,
437 struct lp_build_emit_data * emit_data)
438 {
439
440 LLVMValueRef abs_x, log_abs_x, flr_log_abs_x, ex2_flr_log_abs_x;
441
442 /* abs( src0.x) */
443 abs_x = lp_build_abs(&bld_base->base, emit_data->args[0] /* src0.x */);
444
445 /* log( abs( src0.x ) ) */
446 log_abs_x = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_LG2,
447 abs_x);
448
449 /* floor( log( abs( src0.x ) ) ) */
450 flr_log_abs_x = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_FLR,
451 log_abs_x);
452 /* dst.x */
453 emit_data->output[TGSI_CHAN_X] = flr_log_abs_x;
454
455 /* dst.y */
456 ex2_flr_log_abs_x = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_EX2,
457 flr_log_abs_x);
458
459 /* abs( src0.x ) / 2^( floor( lg2( abs( src0.x ) ) ) ) */
460 emit_data->output[TGSI_CHAN_Y] = lp_build_emit_llvm_binary(bld_base,
461 TGSI_OPCODE_DIV, abs_x, ex2_flr_log_abs_x);
462
463 /* dst.x */
464 emit_data->output[TGSI_CHAN_Z] = log_abs_x;
465
466 /* dst.w */
467 emit_data->output[TGSI_CHAN_W] = bld_base->base.one;
468 }
469
470 static struct lp_build_tgsi_action log_action = {
471 scalar_unary_fetch_args, /* fetch_args */
472 log_emit /* emit */
473 };
474
475 /* TGSI_OPCODE_PK2H */
476
477 static void
478 pk2h_fetch_args(
479 struct lp_build_tgsi_context * bld_base,
480 struct lp_build_emit_data * emit_data)
481 {
482 /* src0.x */
483 emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst,
484 0, TGSI_CHAN_X);
485 /* src0.y */
486 emit_data->args[1] = lp_build_emit_fetch(bld_base, emit_data->inst,
487 0, TGSI_CHAN_Y);
488 }
489
490 static void
491 pk2h_emit(
492 const struct lp_build_tgsi_action *action,
493 struct lp_build_tgsi_context *bld_base,
494 struct lp_build_emit_data *emit_data)
495 {
496 struct gallivm_state *gallivm = bld_base->base.gallivm;
497 struct lp_type f16i_t;
498 LLVMValueRef lo, hi, res;
499
500 f16i_t = lp_type_uint_vec(16, bld_base->base.type.length * 32);
501 lo = lp_build_float_to_half(gallivm, emit_data->args[0]);
502 hi = lp_build_float_to_half(gallivm, emit_data->args[1]);
503 /* maybe some interleave doubling vector width would be useful... */
504 lo = lp_build_pad_vector(gallivm, lo, bld_base->base.type.length * 2);
505 hi = lp_build_pad_vector(gallivm, hi, bld_base->base.type.length * 2);
506 res = lp_build_interleave2(gallivm, f16i_t, lo, hi, 0);
507
508 emit_data->output[emit_data->chan] = res;
509 }
510
511 static struct lp_build_tgsi_action pk2h_action = {
512 pk2h_fetch_args, /* fetch_args */
513 pk2h_emit /* emit */
514 };
515
516 /* TGSI_OPCODE_UP2H */
517
518 static void
519 up2h_emit(
520 const struct lp_build_tgsi_action *action,
521 struct lp_build_tgsi_context *bld_base,
522 struct lp_build_emit_data *emit_data)
523 {
524 struct gallivm_state *gallivm = bld_base->base.gallivm;
525 LLVMBuilderRef builder = gallivm->builder;
526 LLVMContextRef context = gallivm->context;
527 LLVMValueRef lo, hi, res[2], arg;
528 unsigned nr = bld_base->base.type.length;
529 LLVMTypeRef i16t = LLVMVectorType(LLVMInt16TypeInContext(context), nr * 2);
530
531 arg = LLVMBuildBitCast(builder, emit_data->args[0], i16t, "");
532 lo = lp_build_uninterleave1(gallivm, nr * 2, arg, 0);
533 hi = lp_build_uninterleave1(gallivm, nr * 2, arg, 1);
534 res[0] = lp_build_half_to_float(gallivm, lo);
535 res[1] = lp_build_half_to_float(gallivm, hi);
536
537 emit_data->output[0] = emit_data->output[2] = res[0];
538 emit_data->output[1] = emit_data->output[3] = res[1];
539 }
540
541 static struct lp_build_tgsi_action up2h_action = {
542 scalar_unary_fetch_args, /* fetch_args */
543 up2h_emit /* emit */
544 };
545
546 /* TGSI_OPCODE_LRP */
547
548 static void
549 lrp_emit(
550 const struct lp_build_tgsi_action * action,
551 struct lp_build_tgsi_context * bld_base,
552 struct lp_build_emit_data * emit_data)
553 {
554 struct lp_build_context *bld = &bld_base->base;
555 LLVMValueRef inv, a, b;
556
557 /* This uses the correct version: (1 - t)*a + t*b
558 *
559 * An alternative version is "a + t*(b-a)". The problem is this version
560 * doesn't return "b" for t = 1, because "a + (b-a)" isn't equal to "b"
561 * because of the floating-point rounding.
562 */
563 inv = lp_build_sub(bld, bld_base->base.one, emit_data->args[0]);
564 a = lp_build_mul(bld, emit_data->args[1], emit_data->args[0]);
565 b = lp_build_mul(bld, emit_data->args[2], inv);
566 emit_data->output[emit_data->chan] = lp_build_add(bld, a, b);
567 }
568
569 /* TGSI_OPCODE_MAD */
570
571 static void
572 mad_emit(
573 const struct lp_build_tgsi_action * action,
574 struct lp_build_tgsi_context * bld_base,
575 struct lp_build_emit_data * emit_data)
576 {
577 LLVMValueRef tmp;
578 tmp = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL,
579 emit_data->args[0],
580 emit_data->args[1]);
581 emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base,
582 TGSI_OPCODE_ADD, tmp, emit_data->args[2]);
583 }
584
585 /* TGSI_OPCODE_MOV */
586
587 static void
588 mov_emit(
589 const struct lp_build_tgsi_action * action,
590 struct lp_build_tgsi_context * bld_base,
591 struct lp_build_emit_data * emit_data)
592 {
593 emit_data->output[emit_data->chan] = emit_data->args[0];
594 }
595
596 /* TGSI_OPCODE_MUL */
597 static void
598 mul_emit(
599 const struct lp_build_tgsi_action * action,
600 struct lp_build_tgsi_context * bld_base,
601 struct lp_build_emit_data * emit_data)
602 {
603 emit_data->output[emit_data->chan] = LLVMBuildFMul(
604 bld_base->base.gallivm->builder,
605 emit_data->args[0], emit_data->args[1], "");
606 }
607
608 /*.TGSI_OPCODE_DIV.*/
609 static void fdiv_emit(
610 const struct lp_build_tgsi_action * action,
611 struct lp_build_tgsi_context * bld_base,
612 struct lp_build_emit_data * emit_data)
613 {
614 emit_data->output[emit_data->chan] = LLVMBuildFDiv(
615 bld_base->base.gallivm->builder,
616 emit_data->args[0], emit_data->args[1], "");
617 }
618
619 /*.TGSI_OPCODE_RCP.*/
620 static void rcp_emit(
621 const struct lp_build_tgsi_action * action,
622 struct lp_build_tgsi_context * bld_base,
623 struct lp_build_emit_data * emit_data)
624 {
625 LLVMValueRef one;
626 one = lp_build_const_float(bld_base->base.gallivm, 1.0f);
627 emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base,
628 TGSI_OPCODE_DIV, one, emit_data->args[0]);
629 }
630
631 /* TGSI_OPCODE_POW */
632
633 static void
634 pow_emit(
635 const struct lp_build_tgsi_action * action,
636 struct lp_build_tgsi_context * bld_base,
637 struct lp_build_emit_data * emit_data)
638 {
639 emit_data->output[emit_data->chan] = lp_build_pow(&bld_base->base,
640 emit_data->args[0], emit_data->args[1]);
641 }
642
643 static struct lp_build_tgsi_action pow_action = {
644 scalar_binary_fetch_args, /* fetch_args */
645 pow_emit /* emit */
646 };
647
648 /* TGSI_OPCODE_RSQ */
649
650 static void
651 rsq_emit(
652 const struct lp_build_tgsi_action * action,
653 struct lp_build_tgsi_context * bld_base,
654 struct lp_build_emit_data * emit_data)
655 {
656 if (bld_base->rsq_action.emit) {
657 bld_base->rsq_action.emit(&bld_base->rsq_action, bld_base, emit_data);
658 } else {
659 emit_data->output[emit_data->chan] = bld_base->base.undef;
660 }
661 }
662
663 const struct lp_build_tgsi_action rsq_action = {
664 scalar_unary_fetch_args, /* fetch_args */
665 rsq_emit /* emit */
666
667 };
668
669 /* TGSI_OPCODE_SQRT */
670
671 static void
672 sqrt_emit(
673 const struct lp_build_tgsi_action * action,
674 struct lp_build_tgsi_context * bld_base,
675 struct lp_build_emit_data * emit_data)
676 {
677 if (bld_base->sqrt_action.emit) {
678 bld_base->sqrt_action.emit(&bld_base->sqrt_action, bld_base, emit_data);
679 } else {
680 emit_data->output[emit_data->chan] = bld_base->base.undef;
681 }
682 }
683
684 const struct lp_build_tgsi_action sqrt_action = {
685 scalar_unary_fetch_args, /* fetch_args */
686 sqrt_emit /* emit */
687 };
688
689 /* TGSI_OPCODE_SCS */
690 static void
691 scs_emit(
692 const struct lp_build_tgsi_action * action,
693 struct lp_build_tgsi_context * bld_base,
694 struct lp_build_emit_data * emit_data)
695 {
696 /* dst.x */
697 emit_data->output[TGSI_CHAN_X] = lp_build_emit_llvm_unary(bld_base,
698 TGSI_OPCODE_COS, emit_data->args[0]);
699 /* dst.y */
700 emit_data->output[TGSI_CHAN_Y] = lp_build_emit_llvm_unary(bld_base,
701 TGSI_OPCODE_SIN, emit_data->args[0]);
702 /* dst.z */
703 emit_data->output[TGSI_CHAN_Z] = bld_base->base.zero;
704
705 /* dst.w */
706 emit_data->output[TGSI_CHAN_W] = bld_base->base.one;
707 }
708
709 const struct lp_build_tgsi_action scs_action = {
710 scalar_unary_fetch_args, /* fetch_args */
711 scs_emit /* emit */
712 };
713
714 /* TGSI_OPCODE_F2U */
715 static void
716 f2u_emit(
717 const struct lp_build_tgsi_action * action,
718 struct lp_build_tgsi_context * bld_base,
719 struct lp_build_emit_data * emit_data)
720 {
721 emit_data->output[emit_data->chan] =
722 LLVMBuildFPToUI(bld_base->base.gallivm->builder,
723 emit_data->args[0],
724 bld_base->base.int_vec_type, "");
725 }
726
727 /* TGSI_OPCODE_U2F */
728 static void
729 u2f_emit(
730 const struct lp_build_tgsi_action * action,
731 struct lp_build_tgsi_context * bld_base,
732 struct lp_build_emit_data * emit_data)
733 {
734 emit_data->output[emit_data->chan] =
735 LLVMBuildUIToFP(bld_base->base.gallivm->builder,
736 emit_data->args[0],
737 bld_base->base.vec_type, "");
738 }
739
740 static void
741 umad_emit(
742 const struct lp_build_tgsi_action * action,
743 struct lp_build_tgsi_context * bld_base,
744 struct lp_build_emit_data * emit_data)
745 {
746 LLVMValueRef tmp;
747 tmp = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_UMUL,
748 emit_data->args[0],
749 emit_data->args[1]);
750 emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base,
751 TGSI_OPCODE_UADD, tmp, emit_data->args[2]);
752 }
753
754 /* TGSI_OPCODE_UMUL */
755 static void
756 umul_emit(
757 const struct lp_build_tgsi_action * action,
758 struct lp_build_tgsi_context * bld_base,
759 struct lp_build_emit_data * emit_data)
760 {
761 emit_data->output[emit_data->chan] = lp_build_mul(&bld_base->uint_bld,
762 emit_data->args[0], emit_data->args[1]);
763 }
764
765 /* TGSI_OPCODE_IMUL_HI */
766 static void
767 imul_hi_emit(
768 const struct lp_build_tgsi_action * action,
769 struct lp_build_tgsi_context * bld_base,
770 struct lp_build_emit_data * emit_data)
771 {
772 struct lp_build_context *int_bld = &bld_base->int_bld;
773 LLVMValueRef hi_bits;
774
775 assert(int_bld->type.width == 32);
776
777 /* low result bits are tossed away */
778 lp_build_mul_32_lohi(int_bld, emit_data->args[0],
779 emit_data->args[1], &hi_bits);
780 emit_data->output[emit_data->chan] = hi_bits;
781 }
782
783 static void
784 imul_hi_emit_cpu(
785 const struct lp_build_tgsi_action * action,
786 struct lp_build_tgsi_context * bld_base,
787 struct lp_build_emit_data * emit_data)
788 {
789 struct lp_build_context *int_bld = &bld_base->int_bld;
790 LLVMValueRef hi_bits;
791
792 assert(int_bld->type.width == 32);
793
794 /* low result bits are tossed away */
795 lp_build_mul_32_lohi_cpu(int_bld, emit_data->args[0],
796 emit_data->args[1], &hi_bits);
797 emit_data->output[emit_data->chan] = hi_bits;
798 }
799
800 /* TGSI_OPCODE_UMUL_HI */
801 static void
802 umul_hi_emit(
803 const struct lp_build_tgsi_action * action,
804 struct lp_build_tgsi_context * bld_base,
805 struct lp_build_emit_data * emit_data)
806 {
807 struct lp_build_context *uint_bld = &bld_base->uint_bld;
808 LLVMValueRef hi_bits;
809
810 assert(uint_bld->type.width == 32);
811
812 /* low result bits are tossed away */
813 lp_build_mul_32_lohi(uint_bld, emit_data->args[0],
814 emit_data->args[1], &hi_bits);
815 emit_data->output[emit_data->chan] = hi_bits;
816 }
817
818 static void
819 umul_hi_emit_cpu(
820 const struct lp_build_tgsi_action * action,
821 struct lp_build_tgsi_context * bld_base,
822 struct lp_build_emit_data * emit_data)
823 {
824 struct lp_build_context *uint_bld = &bld_base->uint_bld;
825 LLVMValueRef hi_bits;
826
827 assert(uint_bld->type.width == 32);
828
829 /* low result bits are tossed away */
830 lp_build_mul_32_lohi_cpu(uint_bld, emit_data->args[0],
831 emit_data->args[1], &hi_bits);
832 emit_data->output[emit_data->chan] = hi_bits;
833 }
834
835 /* TGSI_OPCODE_MAX */
836 static void fmax_emit(
837 const struct lp_build_tgsi_action * action,
838 struct lp_build_tgsi_context * bld_base,
839 struct lp_build_emit_data * emit_data)
840 {
841 LLVMBuilderRef builder = bld_base->base.gallivm->builder;
842 emit_data->output[emit_data->chan] = LLVMBuildSelect(builder,
843 LLVMBuildFCmp(builder, LLVMRealUGE,
844 emit_data->args[0], emit_data->args[1], ""),
845 emit_data->args[0], emit_data->args[1], "");
846 }
847
848 /* TGSI_OPCODE_MIN */
849 static void fmin_emit(
850 const struct lp_build_tgsi_action * action,
851 struct lp_build_tgsi_context * bld_base,
852 struct lp_build_emit_data * emit_data)
853 {
854 LLVMBuilderRef builder = bld_base->base.gallivm->builder;
855 emit_data->output[emit_data->chan] = LLVMBuildSelect(builder,
856 LLVMBuildFCmp(builder, LLVMRealUGE,
857 emit_data->args[0], emit_data->args[1], ""),
858 emit_data->args[1], emit_data->args[0], "");
859 }
860
861 /* TGSI_OPCODE_D2F */
862 static void
863 d2f_emit(
864 const struct lp_build_tgsi_action * action,
865 struct lp_build_tgsi_context * bld_base,
866 struct lp_build_emit_data * emit_data)
867 {
868 emit_data->output[emit_data->chan] =
869 LLVMBuildFPTrunc(bld_base->base.gallivm->builder,
870 emit_data->args[0],
871 bld_base->base.vec_type, "");
872 }
873
874 /* TGSI_OPCODE_D2I */
875 static void
876 d2i_emit(
877 const struct lp_build_tgsi_action * action,
878 struct lp_build_tgsi_context * bld_base,
879 struct lp_build_emit_data * emit_data)
880 {
881 emit_data->output[emit_data->chan] =
882 LLVMBuildFPToSI(bld_base->base.gallivm->builder,
883 emit_data->args[0],
884 bld_base->base.int_vec_type, "");
885 }
886
887 /* TGSI_OPCODE_D2U */
888 static void
889 d2u_emit(
890 const struct lp_build_tgsi_action * action,
891 struct lp_build_tgsi_context * bld_base,
892 struct lp_build_emit_data * emit_data)
893 {
894 emit_data->output[emit_data->chan] =
895 LLVMBuildFPToUI(bld_base->base.gallivm->builder,
896 emit_data->args[0],
897 bld_base->base.int_vec_type, "");
898 }
899
900 /* TGSI_OPCODE_F2D */
901 static void
902 f2d_emit(
903 const struct lp_build_tgsi_action * action,
904 struct lp_build_tgsi_context * bld_base,
905 struct lp_build_emit_data * emit_data)
906 {
907 emit_data->output[emit_data->chan] =
908 LLVMBuildFPExt(bld_base->base.gallivm->builder,
909 emit_data->args[0],
910 bld_base->dbl_bld.vec_type, "");
911 }
912
913 /* TGSI_OPCODE_U2D */
914 static void
915 u2d_emit(
916 const struct lp_build_tgsi_action * action,
917 struct lp_build_tgsi_context * bld_base,
918 struct lp_build_emit_data * emit_data)
919 {
920 emit_data->output[emit_data->chan] =
921 LLVMBuildUIToFP(bld_base->base.gallivm->builder,
922 emit_data->args[0],
923 bld_base->dbl_bld.vec_type, "");
924 }
925
926 /* TGSI_OPCODE_I2D */
927 static void
928 i2d_emit(
929 const struct lp_build_tgsi_action * action,
930 struct lp_build_tgsi_context * bld_base,
931 struct lp_build_emit_data * emit_data)
932 {
933 emit_data->output[emit_data->chan] =
934 LLVMBuildSIToFP(bld_base->base.gallivm->builder,
935 emit_data->args[0],
936 bld_base->dbl_bld.vec_type, "");
937 }
938
939 /* TGSI_OPCODE_DMAD */
940 static void
941 dmad_emit(
942 const struct lp_build_tgsi_action * action,
943 struct lp_build_tgsi_context * bld_base,
944 struct lp_build_emit_data * emit_data)
945 {
946 LLVMValueRef tmp;
947 tmp = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_DMUL,
948 emit_data->args[0],
949 emit_data->args[1]);
950 emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base,
951 TGSI_OPCODE_DADD, tmp, emit_data->args[2]);
952 }
953
954 /*.TGSI_OPCODE_DRCP.*/
955 static void drcp_emit(
956 const struct lp_build_tgsi_action * action,
957 struct lp_build_tgsi_context * bld_base,
958 struct lp_build_emit_data * emit_data)
959 {
960 LLVMValueRef one;
961 one = lp_build_const_vec(bld_base->dbl_bld.gallivm, bld_base->dbl_bld.type, 1.0f);
962 emit_data->output[emit_data->chan] = LLVMBuildFDiv(
963 bld_base->base.gallivm->builder,
964 one, emit_data->args[0], "");
965 }
966
967 /* TGSI_OPCODE_DFRAC */
968 static void dfrac_emit(
969 const struct lp_build_tgsi_action * action,
970 struct lp_build_tgsi_context * bld_base,
971 struct lp_build_emit_data * emit_data)
972 {
973 LLVMValueRef tmp;
974 tmp = lp_build_floor(&bld_base->dbl_bld,
975 emit_data->args[0]);
976 emit_data->output[emit_data->chan] = LLVMBuildFSub(bld_base->base.gallivm->builder,
977 emit_data->args[0], tmp, "");
978 }
979
980 static void
981 u64mul_emit(
982 const struct lp_build_tgsi_action * action,
983 struct lp_build_tgsi_context * bld_base,
984 struct lp_build_emit_data * emit_data)
985 {
986 emit_data->output[emit_data->chan] = lp_build_mul(&bld_base->uint64_bld,
987 emit_data->args[0], emit_data->args[1]);
988 }
989
990 static void
991 u64mod_emit_cpu(
992 const struct lp_build_tgsi_action * action,
993 struct lp_build_tgsi_context * bld_base,
994 struct lp_build_emit_data * emit_data)
995 {
996 LLVMBuilderRef builder = bld_base->base.gallivm->builder;
997 LLVMValueRef div_mask = lp_build_cmp(&bld_base->uint64_bld,
998 PIPE_FUNC_EQUAL, emit_data->args[1],
999 bld_base->uint64_bld.zero);
1000 /* We want to make sure that we never divide/mod by zero to not
1001 * generate sigfpe. We don't want to crash just because the
1002 * shader is doing something weird. */
1003 LLVMValueRef divisor = LLVMBuildOr(builder,
1004 div_mask,
1005 emit_data->args[1], "");
1006 LLVMValueRef result = lp_build_mod(&bld_base->uint64_bld,
1007 emit_data->args[0], divisor);
1008 /* umod by zero doesn't have a guaranteed return value chose -1 for now. */
1009 emit_data->output[emit_data->chan] = LLVMBuildOr(builder,
1010 div_mask,
1011 result, "");
1012 }
1013
1014 static void
1015 i64mod_emit_cpu(
1016 const struct lp_build_tgsi_action * action,
1017 struct lp_build_tgsi_context * bld_base,
1018 struct lp_build_emit_data * emit_data)
1019 {
1020 LLVMBuilderRef builder = bld_base->base.gallivm->builder;
1021 LLVMValueRef div_mask = lp_build_cmp(&bld_base->uint64_bld,
1022 PIPE_FUNC_EQUAL, emit_data->args[1],
1023 bld_base->uint64_bld.zero);
1024 /* We want to make sure that we never divide/mod by zero to not
1025 * generate sigfpe. We don't want to crash just because the
1026 * shader is doing something weird. */
1027 LLVMValueRef divisor = LLVMBuildOr(builder,
1028 div_mask,
1029 emit_data->args[1], "");
1030 LLVMValueRef result = lp_build_mod(&bld_base->int64_bld,
1031 emit_data->args[0], divisor);
1032 /* umod by zero doesn't have a guaranteed return value chose -1 for now. */
1033 emit_data->output[emit_data->chan] = LLVMBuildOr(builder,
1034 div_mask,
1035 result, "");
1036 }
1037
1038 static void
1039 u64div_emit_cpu(
1040 const struct lp_build_tgsi_action * action,
1041 struct lp_build_tgsi_context * bld_base,
1042 struct lp_build_emit_data * emit_data)
1043 {
1044
1045 LLVMBuilderRef builder = bld_base->base.gallivm->builder;
1046 LLVMValueRef div_mask = lp_build_cmp(&bld_base->uint64_bld,
1047 PIPE_FUNC_EQUAL, emit_data->args[1],
1048 bld_base->uint64_bld.zero);
1049 /* We want to make sure that we never divide/mod by zero to not
1050 * generate sigfpe. We don't want to crash just because the
1051 * shader is doing something weird. */
1052 LLVMValueRef divisor = LLVMBuildOr(builder,
1053 div_mask,
1054 emit_data->args[1], "");
1055 LLVMValueRef result = LLVMBuildUDiv(builder,
1056 emit_data->args[0], divisor, "");
1057 /* udiv by zero is guaranteed to return 0xffffffff at least with d3d10 */
1058 emit_data->output[emit_data->chan] = LLVMBuildOr(builder,
1059 div_mask,
1060 result, "");
1061 }
1062
1063 static void
1064 i64div_emit_cpu(
1065 const struct lp_build_tgsi_action * action,
1066 struct lp_build_tgsi_context * bld_base,
1067 struct lp_build_emit_data * emit_data)
1068 {
1069
1070 LLVMBuilderRef builder = bld_base->base.gallivm->builder;
1071 LLVMValueRef div_mask = lp_build_cmp(&bld_base->int64_bld,
1072 PIPE_FUNC_EQUAL, emit_data->args[1],
1073 bld_base->int64_bld.zero);
1074 /* We want to make sure that we never divide/mod by zero to not
1075 * generate sigfpe. We don't want to crash just because the
1076 * shader is doing something weird. */
1077 LLVMValueRef divisor = LLVMBuildOr(builder,
1078 div_mask,
1079 emit_data->args[1], "");
1080 LLVMValueRef result = LLVMBuildSDiv(builder,
1081 emit_data->args[0], divisor, "");
1082 /* udiv by zero is guaranteed to return 0xffffffff at least with d3d10 */
1083 emit_data->output[emit_data->chan] = LLVMBuildOr(builder,
1084 div_mask,
1085 result, "");
1086 }
1087
1088 static void
1089 f2u64_emit(
1090 const struct lp_build_tgsi_action * action,
1091 struct lp_build_tgsi_context * bld_base,
1092 struct lp_build_emit_data * emit_data)
1093 {
1094 emit_data->output[emit_data->chan] =
1095 LLVMBuildFPToUI(bld_base->base.gallivm->builder,
1096 emit_data->args[0],
1097 bld_base->uint64_bld.vec_type, "");
1098 }
1099
1100 static void
1101 f2i64_emit(
1102 const struct lp_build_tgsi_action * action,
1103 struct lp_build_tgsi_context * bld_base,
1104 struct lp_build_emit_data * emit_data)
1105 {
1106 emit_data->output[emit_data->chan] =
1107 LLVMBuildFPToSI(bld_base->base.gallivm->builder,
1108 emit_data->args[0],
1109 bld_base->int64_bld.vec_type, "");
1110 }
1111
1112 static void
1113 u2i64_emit(
1114 const struct lp_build_tgsi_action * action,
1115 struct lp_build_tgsi_context * bld_base,
1116 struct lp_build_emit_data * emit_data)
1117 {
1118 emit_data->output[emit_data->chan] =
1119 LLVMBuildZExt(bld_base->base.gallivm->builder,
1120 emit_data->args[0],
1121 bld_base->uint64_bld.vec_type, "");
1122 }
1123
1124 static void
1125 i2i64_emit(
1126 const struct lp_build_tgsi_action * action,
1127 struct lp_build_tgsi_context * bld_base,
1128 struct lp_build_emit_data * emit_data)
1129 {
1130 emit_data->output[emit_data->chan] =
1131 LLVMBuildSExt(bld_base->base.gallivm->builder,
1132 emit_data->args[0],
1133 bld_base->int64_bld.vec_type, "");
1134 }
1135
1136 static void
1137 i642f_emit(
1138 const struct lp_build_tgsi_action * action,
1139 struct lp_build_tgsi_context * bld_base,
1140 struct lp_build_emit_data * emit_data)
1141 {
1142 emit_data->output[emit_data->chan] =
1143 LLVMBuildSIToFP(bld_base->base.gallivm->builder,
1144 emit_data->args[0],
1145 bld_base->base.vec_type, "");
1146 }
1147
1148 static void
1149 u642f_emit(
1150 const struct lp_build_tgsi_action * action,
1151 struct lp_build_tgsi_context * bld_base,
1152 struct lp_build_emit_data * emit_data)
1153 {
1154 emit_data->output[emit_data->chan] =
1155 LLVMBuildUIToFP(bld_base->base.gallivm->builder,
1156 emit_data->args[0],
1157 bld_base->base.vec_type, "");
1158 }
1159
1160 static void
1161 i642d_emit(
1162 const struct lp_build_tgsi_action * action,
1163 struct lp_build_tgsi_context * bld_base,
1164 struct lp_build_emit_data * emit_data)
1165 {
1166 emit_data->output[emit_data->chan] =
1167 LLVMBuildSIToFP(bld_base->base.gallivm->builder,
1168 emit_data->args[0],
1169 bld_base->dbl_bld.vec_type, "");
1170 }
1171
1172 static void
1173 u642d_emit(
1174 const struct lp_build_tgsi_action * action,
1175 struct lp_build_tgsi_context * bld_base,
1176 struct lp_build_emit_data * emit_data)
1177 {
1178 emit_data->output[emit_data->chan] =
1179 LLVMBuildUIToFP(bld_base->base.gallivm->builder,
1180 emit_data->args[0],
1181 bld_base->dbl_bld.vec_type, "");
1182 }
1183
1184 void
1185 lp_set_default_actions(struct lp_build_tgsi_context * bld_base)
1186 {
1187 bld_base->op_actions[TGSI_OPCODE_DP2] = dp2_action;
1188 bld_base->op_actions[TGSI_OPCODE_DP3] = dp3_action;
1189 bld_base->op_actions[TGSI_OPCODE_DP4] = dp4_action;
1190 bld_base->op_actions[TGSI_OPCODE_DST] = dst_action;
1191 bld_base->op_actions[TGSI_OPCODE_EXP] = exp_action;
1192 bld_base->op_actions[TGSI_OPCODE_LIT] = lit_action;
1193 bld_base->op_actions[TGSI_OPCODE_LOG] = log_action;
1194 bld_base->op_actions[TGSI_OPCODE_PK2H] = pk2h_action;
1195 bld_base->op_actions[TGSI_OPCODE_RSQ] = rsq_action;
1196 bld_base->op_actions[TGSI_OPCODE_SQRT] = sqrt_action;
1197 bld_base->op_actions[TGSI_OPCODE_POW] = pow_action;
1198 bld_base->op_actions[TGSI_OPCODE_SCS] = scs_action;
1199 bld_base->op_actions[TGSI_OPCODE_UP2H] = up2h_action;
1200
1201 bld_base->op_actions[TGSI_OPCODE_SWITCH].fetch_args = scalar_unary_fetch_args;
1202 bld_base->op_actions[TGSI_OPCODE_CASE].fetch_args = scalar_unary_fetch_args;
1203 bld_base->op_actions[TGSI_OPCODE_COS].fetch_args = scalar_unary_fetch_args;
1204 bld_base->op_actions[TGSI_OPCODE_EX2].fetch_args = scalar_unary_fetch_args;
1205 bld_base->op_actions[TGSI_OPCODE_IF].fetch_args = scalar_unary_fetch_args;
1206 bld_base->op_actions[TGSI_OPCODE_UIF].fetch_args = scalar_unary_fetch_args;
1207 bld_base->op_actions[TGSI_OPCODE_KILL_IF].fetch_args = kil_fetch_args;
1208 bld_base->op_actions[TGSI_OPCODE_KILL].fetch_args = kilp_fetch_args;
1209 bld_base->op_actions[TGSI_OPCODE_RCP].fetch_args = scalar_unary_fetch_args;
1210 bld_base->op_actions[TGSI_OPCODE_SIN].fetch_args = scalar_unary_fetch_args;
1211 bld_base->op_actions[TGSI_OPCODE_LG2].fetch_args = scalar_unary_fetch_args;
1212
1213 bld_base->op_actions[TGSI_OPCODE_ADD].emit = add_emit;
1214 bld_base->op_actions[TGSI_OPCODE_ARR].emit = arr_emit;
1215 bld_base->op_actions[TGSI_OPCODE_END].emit = end_emit;
1216 bld_base->op_actions[TGSI_OPCODE_FRC].emit = frc_emit;
1217 bld_base->op_actions[TGSI_OPCODE_LRP].emit = lrp_emit;
1218 bld_base->op_actions[TGSI_OPCODE_MAD].emit = mad_emit;
1219 bld_base->op_actions[TGSI_OPCODE_MOV].emit = mov_emit;
1220 bld_base->op_actions[TGSI_OPCODE_MUL].emit = mul_emit;
1221 bld_base->op_actions[TGSI_OPCODE_DIV].emit = fdiv_emit;
1222 bld_base->op_actions[TGSI_OPCODE_RCP].emit = rcp_emit;
1223
1224 bld_base->op_actions[TGSI_OPCODE_UARL].emit = mov_emit;
1225 bld_base->op_actions[TGSI_OPCODE_F2U].emit = f2u_emit;
1226 bld_base->op_actions[TGSI_OPCODE_U2F].emit = u2f_emit;
1227 bld_base->op_actions[TGSI_OPCODE_UMAD].emit = umad_emit;
1228 bld_base->op_actions[TGSI_OPCODE_UMUL].emit = umul_emit;
1229 bld_base->op_actions[TGSI_OPCODE_IMUL_HI].emit = imul_hi_emit;
1230 bld_base->op_actions[TGSI_OPCODE_UMUL_HI].emit = umul_hi_emit;
1231
1232 bld_base->op_actions[TGSI_OPCODE_MAX].emit = fmax_emit;
1233 bld_base->op_actions[TGSI_OPCODE_MIN].emit = fmin_emit;
1234
1235 bld_base->op_actions[TGSI_OPCODE_DADD].emit = add_emit;
1236 bld_base->op_actions[TGSI_OPCODE_DMAX].emit = fmax_emit;
1237 bld_base->op_actions[TGSI_OPCODE_DMIN].emit = fmin_emit;
1238 bld_base->op_actions[TGSI_OPCODE_DMUL].emit = mul_emit;
1239 bld_base->op_actions[TGSI_OPCODE_DDIV].emit = fdiv_emit;
1240
1241 bld_base->op_actions[TGSI_OPCODE_D2F].emit = d2f_emit;
1242 bld_base->op_actions[TGSI_OPCODE_D2I].emit = d2i_emit;
1243 bld_base->op_actions[TGSI_OPCODE_D2U].emit = d2u_emit;
1244
1245 bld_base->op_actions[TGSI_OPCODE_F2D].emit = f2d_emit;
1246 bld_base->op_actions[TGSI_OPCODE_I2D].emit = i2d_emit;
1247 bld_base->op_actions[TGSI_OPCODE_U2D].emit = u2d_emit;
1248
1249 bld_base->op_actions[TGSI_OPCODE_DMAD].emit = dmad_emit;
1250
1251 bld_base->op_actions[TGSI_OPCODE_DRCP].emit = drcp_emit;
1252 bld_base->op_actions[TGSI_OPCODE_DFRAC].emit = dfrac_emit;
1253
1254 bld_base->op_actions[TGSI_OPCODE_U64MUL].emit = u64mul_emit;
1255
1256 bld_base->op_actions[TGSI_OPCODE_F2I64].emit = f2i64_emit;
1257 bld_base->op_actions[TGSI_OPCODE_F2U64].emit = f2u64_emit;
1258
1259 bld_base->op_actions[TGSI_OPCODE_D2I64].emit = f2i64_emit;
1260 bld_base->op_actions[TGSI_OPCODE_D2U64].emit = f2u64_emit;
1261
1262 bld_base->op_actions[TGSI_OPCODE_I2I64].emit = i2i64_emit;
1263 bld_base->op_actions[TGSI_OPCODE_U2I64].emit = u2i64_emit;
1264
1265 bld_base->op_actions[TGSI_OPCODE_I642F].emit = i642f_emit;
1266 bld_base->op_actions[TGSI_OPCODE_U642F].emit = u642f_emit;
1267
1268 bld_base->op_actions[TGSI_OPCODE_I642F].emit = i642f_emit;
1269 bld_base->op_actions[TGSI_OPCODE_U642F].emit = u642f_emit;
1270
1271 bld_base->op_actions[TGSI_OPCODE_I642D].emit = i642d_emit;
1272 bld_base->op_actions[TGSI_OPCODE_U642D].emit = u642d_emit;
1273
1274 }
1275
1276 /* CPU Only default actions */
1277
1278 /* These actions are CPU only, because they could potentially output SSE
1279 * intrinsics.
1280 */
1281
1282 /* TGSI_OPCODE_ADD (CPU Only) */
1283 static void
1284 add_emit_cpu(
1285 const struct lp_build_tgsi_action * action,
1286 struct lp_build_tgsi_context * bld_base,
1287 struct lp_build_emit_data * emit_data)
1288 {
1289 emit_data->output[emit_data->chan] = lp_build_add(&bld_base->base,
1290 emit_data->args[0], emit_data->args[1]);
1291 }
1292
1293 /* TGSI_OPCODE_AND (CPU Only) */
1294 static void
1295 and_emit_cpu(
1296 const struct lp_build_tgsi_action * action,
1297 struct lp_build_tgsi_context * bld_base,
1298 struct lp_build_emit_data * emit_data)
1299 {
1300 emit_data->output[emit_data->chan] = lp_build_and(&bld_base->uint_bld,
1301 emit_data->args[0], emit_data->args[1]);
1302 }
1303
1304 /* TGSI_OPCODE_ARL (CPU Only) */
1305 static void
1306 arl_emit_cpu(
1307 const struct lp_build_tgsi_action * action,
1308 struct lp_build_tgsi_context * bld_base,
1309 struct lp_build_emit_data * emit_data)
1310 {
1311 LLVMValueRef tmp;
1312 tmp = lp_build_floor(&bld_base->base,
1313 emit_data->args[0]);
1314 emit_data->output[emit_data->chan] = LLVMBuildFPToSI(bld_base->base.gallivm->builder, tmp,
1315 bld_base->uint_bld.vec_type, "");
1316 }
1317
1318 /* TGSI_OPCODE_ARR (CPU Only) */
1319 static void
1320 arr_emit_cpu(
1321 const struct lp_build_tgsi_action * action,
1322 struct lp_build_tgsi_context * bld_base,
1323 struct lp_build_emit_data * emit_data)
1324 {
1325 emit_data->output[emit_data->chan] = lp_build_iround(&bld_base->base, emit_data->args[0]);
1326 }
1327
1328 /* TGSI_OPCODE_CEIL (CPU Only) */
1329 static void
1330 ceil_emit_cpu(
1331 const struct lp_build_tgsi_action * action,
1332 struct lp_build_tgsi_context * bld_base,
1333 struct lp_build_emit_data * emit_data)
1334 {
1335 emit_data->output[emit_data->chan] = lp_build_ceil(&bld_base->base,
1336 emit_data->args[0]);
1337 }
1338
1339 /* TGSI_OPCODE_CMP (CPU Only) */
1340 static void
1341 cmp_emit_cpu(
1342 const struct lp_build_tgsi_action * action,
1343 struct lp_build_tgsi_context * bld_base,
1344 struct lp_build_emit_data * emit_data)
1345 {
1346 LLVMValueRef cond = lp_build_cmp(&bld_base->base, PIPE_FUNC_LESS,
1347 emit_data->args[0], bld_base->base.zero);
1348 emit_data->output[emit_data->chan] = lp_build_select(&bld_base->base,
1349 cond, emit_data->args[1], emit_data->args[2]);
1350 }
1351
1352 /* TGSI_OPCODE_UCMP (CPU Only) */
1353 static void
1354 ucmp_emit_cpu(
1355 const struct lp_build_tgsi_action * action,
1356 struct lp_build_tgsi_context * bld_base,
1357 struct lp_build_emit_data * emit_data)
1358 {
1359 LLVMBuilderRef builder = bld_base->base.gallivm->builder;
1360 struct lp_build_context *uint_bld = &bld_base->uint_bld;
1361 LLVMValueRef unsigned_cond =
1362 LLVMBuildBitCast(builder, emit_data->args[0], uint_bld->vec_type, "");
1363 LLVMValueRef cond = lp_build_cmp(uint_bld, PIPE_FUNC_NOTEQUAL,
1364 unsigned_cond,
1365 uint_bld->zero);
1366 emit_data->output[emit_data->chan] =
1367 lp_build_select(&bld_base->base,
1368 cond, emit_data->args[1], emit_data->args[2]);
1369 }
1370
1371 /* TGSI_OPCODE_COS (CPU Only) */
1372 static void
1373 cos_emit_cpu(
1374 const struct lp_build_tgsi_action * action,
1375 struct lp_build_tgsi_context * bld_base,
1376 struct lp_build_emit_data * emit_data)
1377 {
1378 emit_data->output[emit_data->chan] = lp_build_cos(&bld_base->base,
1379 emit_data->args[0]);
1380 }
1381
1382 /* TGSI_OPCODE_DIV (CPU Only) */
1383 static void
1384 div_emit_cpu(
1385 const struct lp_build_tgsi_action * action,
1386 struct lp_build_tgsi_context * bld_base,
1387 struct lp_build_emit_data * emit_data)
1388 {
1389 emit_data->output[emit_data->chan] = lp_build_div(&bld_base->base,
1390 emit_data->args[0], emit_data->args[1]);
1391 }
1392
1393 /* TGSI_OPCODE_EX2 (CPU Only) */
1394 static void
1395 ex2_emit_cpu(
1396 const struct lp_build_tgsi_action * action,
1397 struct lp_build_tgsi_context * bld_base,
1398 struct lp_build_emit_data * emit_data)
1399 {
1400 emit_data->output[emit_data->chan] = lp_build_exp2(&bld_base->base,
1401 emit_data->args[0]);
1402 }
1403
1404 /* TGSI_OPCODE_F2I (CPU Only) */
1405 static void
1406 f2i_emit_cpu(
1407 const struct lp_build_tgsi_action * action,
1408 struct lp_build_tgsi_context * bld_base,
1409 struct lp_build_emit_data * emit_data)
1410 {
1411 emit_data->output[emit_data->chan] = lp_build_itrunc(&bld_base->base,
1412 emit_data->args[0]);
1413 }
1414
1415 /* TGSI_OPCODE_FSET Helper (CPU Only) */
1416 static void
1417 fset_emit_cpu(
1418 const struct lp_build_tgsi_action * action,
1419 struct lp_build_tgsi_context * bld_base,
1420 struct lp_build_emit_data * emit_data,
1421 unsigned pipe_func)
1422 {
1423 LLVMValueRef cond;
1424
1425 if (pipe_func != PIPE_FUNC_NOTEQUAL) {
1426 cond = lp_build_cmp_ordered(&bld_base->base, pipe_func,
1427 emit_data->args[0], emit_data->args[1]);
1428 }
1429 else {
1430 cond = lp_build_cmp(&bld_base->base, pipe_func,
1431 emit_data->args[0], emit_data->args[1]);
1432
1433 }
1434 emit_data->output[emit_data->chan] = cond;
1435 }
1436
1437
1438 /* TGSI_OPCODE_FSEQ (CPU Only) */
1439 static void
1440 fseq_emit_cpu(
1441 const struct lp_build_tgsi_action * action,
1442 struct lp_build_tgsi_context * bld_base,
1443 struct lp_build_emit_data * emit_data)
1444 {
1445 fset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_EQUAL);
1446 }
1447
1448 /* TGSI_OPCODE_ISGE (CPU Only) */
1449 static void
1450 fsge_emit_cpu(
1451 const struct lp_build_tgsi_action * action,
1452 struct lp_build_tgsi_context * bld_base,
1453 struct lp_build_emit_data * emit_data)
1454 {
1455 fset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_GEQUAL);
1456 }
1457
1458 /* TGSI_OPCODE_ISLT (CPU Only) */
1459 static void
1460 fslt_emit_cpu(
1461 const struct lp_build_tgsi_action * action,
1462 struct lp_build_tgsi_context * bld_base,
1463 struct lp_build_emit_data * emit_data)
1464 {
1465 fset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_LESS);
1466 }
1467
1468 /* TGSI_OPCODE_USNE (CPU Only) */
1469
1470 static void
1471 fsne_emit_cpu(
1472 const struct lp_build_tgsi_action * action,
1473 struct lp_build_tgsi_context * bld_base,
1474 struct lp_build_emit_data * emit_data)
1475 {
1476 fset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_NOTEQUAL);
1477 }
1478
1479 /* TGSI_OPCODE_FLR (CPU Only) */
1480
1481 static void
1482 flr_emit_cpu(
1483 const struct lp_build_tgsi_action * action,
1484 struct lp_build_tgsi_context * bld_base,
1485 struct lp_build_emit_data * emit_data)
1486 {
1487 emit_data->output[emit_data->chan] = lp_build_floor(&bld_base->base,
1488 emit_data->args[0]);
1489 }
1490
1491 /* TGSI_OPCODE_I2F (CPU Only) */
1492 static void
1493 i2f_emit_cpu(
1494 const struct lp_build_tgsi_action * action,
1495 struct lp_build_tgsi_context * bld_base,
1496 struct lp_build_emit_data * emit_data)
1497 {
1498 emit_data->output[emit_data->chan] = lp_build_int_to_float(&bld_base->base,
1499 emit_data->args[0]);
1500 }
1501
1502 /* TGSI_OPCODE_IABS (CPU Only) */
1503 static void
1504 iabs_emit_cpu(
1505 const struct lp_build_tgsi_action * action,
1506 struct lp_build_tgsi_context * bld_base,
1507 struct lp_build_emit_data * emit_data)
1508 {
1509 emit_data->output[emit_data->chan] = lp_build_abs(&bld_base->int_bld,
1510 emit_data->args[0]);
1511 }
1512
1513 /* TGSI_OPCODE_IDIV (CPU Only) */
1514 static void
1515 idiv_emit_cpu(
1516 const struct lp_build_tgsi_action * action,
1517 struct lp_build_tgsi_context * bld_base,
1518 struct lp_build_emit_data * emit_data)
1519 {
1520 LLVMBuilderRef builder = bld_base->base.gallivm->builder;
1521 LLVMValueRef div_mask = lp_build_cmp(&bld_base->uint_bld,
1522 PIPE_FUNC_EQUAL, emit_data->args[1],
1523 bld_base->uint_bld.zero);
1524 /* We want to make sure that we never divide/mod by zero to not
1525 * generate sigfpe. We don't want to crash just because the
1526 * shader is doing something weird. */
1527 LLVMValueRef divisor = LLVMBuildOr(builder,
1528 div_mask,
1529 emit_data->args[1], "");
1530 LLVMValueRef result = lp_build_div(&bld_base->int_bld,
1531 emit_data->args[0], divisor);
1532 LLVMValueRef not_div_mask = LLVMBuildNot(builder,
1533 div_mask,"");
1534 /* idiv by zero doesn't have a guaranteed return value chose 0 for now. */
1535 emit_data->output[emit_data->chan] = LLVMBuildAnd(builder,
1536 not_div_mask,
1537 result, "");
1538 }
1539
1540 /* TGSI_OPCODE_INEG (CPU Only) */
1541 static void
1542 ineg_emit_cpu(
1543 const struct lp_build_tgsi_action * action,
1544 struct lp_build_tgsi_context * bld_base,
1545 struct lp_build_emit_data * emit_data)
1546 {
1547 emit_data->output[emit_data->chan] = lp_build_sub(&bld_base->int_bld,
1548 bld_base->int_bld.zero,
1549 emit_data->args[0]);
1550 }
1551
1552 /* TGSI_OPCODE_ISET Helper (CPU Only) */
1553 static void
1554 iset_emit_cpu(
1555 const struct lp_build_tgsi_action * action,
1556 struct lp_build_tgsi_context * bld_base,
1557 struct lp_build_emit_data * emit_data,
1558 unsigned pipe_func)
1559 {
1560 LLVMValueRef cond = lp_build_cmp(&bld_base->int_bld, pipe_func,
1561 emit_data->args[0], emit_data->args[1]);
1562 emit_data->output[emit_data->chan] = cond;
1563 }
1564
1565 /* TGSI_OPCODE_IMAX (CPU Only) */
1566 static void
1567 imax_emit_cpu(
1568 const struct lp_build_tgsi_action * action,
1569 struct lp_build_tgsi_context * bld_base,
1570 struct lp_build_emit_data * emit_data)
1571 {
1572 emit_data->output[emit_data->chan] = lp_build_max(&bld_base->int_bld,
1573 emit_data->args[0], emit_data->args[1]);
1574 }
1575
1576 /* TGSI_OPCODE_IMIN (CPU Only) */
1577 static void
1578 imin_emit_cpu(
1579 const struct lp_build_tgsi_action * action,
1580 struct lp_build_tgsi_context * bld_base,
1581 struct lp_build_emit_data * emit_data)
1582 {
1583 emit_data->output[emit_data->chan] = lp_build_min(&bld_base->int_bld,
1584 emit_data->args[0], emit_data->args[1]);
1585 }
1586
1587 /* TGSI_OPCODE_ISGE (CPU Only) */
1588 static void
1589 isge_emit_cpu(
1590 const struct lp_build_tgsi_action * action,
1591 struct lp_build_tgsi_context * bld_base,
1592 struct lp_build_emit_data * emit_data)
1593 {
1594 iset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_GEQUAL);
1595 }
1596
1597 /* TGSI_OPCODE_ISHR (CPU Only) */
1598 static void
1599 ishr_emit_cpu(
1600 const struct lp_build_tgsi_action * action,
1601 struct lp_build_tgsi_context * bld_base,
1602 struct lp_build_emit_data * emit_data)
1603 {
1604 struct lp_build_context *int_bld = &bld_base->int_bld;
1605 LLVMValueRef mask = lp_build_const_vec(int_bld->gallivm, int_bld->type,
1606 int_bld->type.width - 1);
1607 LLVMValueRef masked_count = lp_build_and(int_bld, emit_data->args[1], mask);
1608 emit_data->output[emit_data->chan] = lp_build_shr(int_bld, emit_data->args[0],
1609 masked_count);
1610 }
1611
1612 /* TGSI_OPCODE_ISLT (CPU Only) */
1613 static void
1614 islt_emit_cpu(
1615 const struct lp_build_tgsi_action * action,
1616 struct lp_build_tgsi_context * bld_base,
1617 struct lp_build_emit_data * emit_data)
1618 {
1619 iset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_LESS);
1620 }
1621
1622
1623 /* TGSI_OPCODE_ISSG (CPU Only) */
1624 static void
1625 issg_emit_cpu(
1626 const struct lp_build_tgsi_action * action,
1627 struct lp_build_tgsi_context * bld_base,
1628 struct lp_build_emit_data * emit_data)
1629 {
1630 emit_data->output[emit_data->chan] = lp_build_sgn(&bld_base->int_bld,
1631 emit_data->args[0]);
1632 }
1633
1634 /* TGSI_OPCODE_LG2 (CPU Only) */
1635 static void
1636 lg2_emit_cpu(
1637 const struct lp_build_tgsi_action * action,
1638 struct lp_build_tgsi_context * bld_base,
1639 struct lp_build_emit_data * emit_data)
1640 {
1641 emit_data->output[emit_data->chan] = lp_build_log2_safe(&bld_base->base,
1642 emit_data->args[0]);
1643 }
1644
1645 /* TGSI_OPCODE_LOG (CPU Only) */
1646 static void
1647 log_emit_cpu(
1648 const struct lp_build_tgsi_action * action,
1649 struct lp_build_tgsi_context * bld_base,
1650 struct lp_build_emit_data * emit_data)
1651 {
1652 LLVMValueRef p_floor_log2;
1653 LLVMValueRef p_exp;
1654 LLVMValueRef p_log2;
1655 LLVMValueRef src0 = emit_data->args[0];
1656
1657 lp_build_log2_approx(&bld_base->base, src0,
1658 &p_exp, &p_floor_log2, &p_log2, FALSE);
1659
1660 emit_data->output[TGSI_CHAN_X] = p_floor_log2;
1661
1662 emit_data->output[TGSI_CHAN_Y] = lp_build_emit_llvm_binary(bld_base,
1663 TGSI_OPCODE_DIV,
1664 src0, p_exp);
1665 emit_data->output[TGSI_CHAN_Z] = p_log2;
1666
1667 emit_data->output[TGSI_CHAN_W] = bld_base->base.one;
1668
1669 }
1670
1671 /* TGSI_OPCODE_MAD (CPU Only) */
1672
1673 static void
1674 mad_emit_cpu(
1675 const struct lp_build_tgsi_action * action,
1676 struct lp_build_tgsi_context * bld_base,
1677 struct lp_build_emit_data * emit_data)
1678 {
1679 emit_data->output[emit_data->chan] =
1680 lp_build_mad(&bld_base->base,
1681 emit_data->args[0], emit_data->args[1], emit_data->args[2]);
1682 }
1683
1684 /* TGSI_OPCODE_MAX (CPU Only) */
1685
1686 static void
1687 max_emit_cpu(
1688 const struct lp_build_tgsi_action * action,
1689 struct lp_build_tgsi_context * bld_base,
1690 struct lp_build_emit_data * emit_data)
1691 {
1692 emit_data->output[emit_data->chan] =
1693 lp_build_max_ext(&bld_base->base,
1694 emit_data->args[0], emit_data->args[1],
1695 GALLIVM_NAN_RETURN_OTHER);
1696 }
1697
1698 /* TGSI_OPCODE_MIN (CPU Only) */
1699 static void
1700 min_emit_cpu(
1701 const struct lp_build_tgsi_action * action,
1702 struct lp_build_tgsi_context * bld_base,
1703 struct lp_build_emit_data * emit_data)
1704 {
1705 emit_data->output[emit_data->chan] =
1706 lp_build_min_ext(&bld_base->base,
1707 emit_data->args[0], emit_data->args[1],
1708 GALLIVM_NAN_RETURN_OTHER);
1709 }
1710
1711 /* TGSI_OPCODE_MOD (CPU Only) */
1712 static void
1713 mod_emit_cpu(
1714 const struct lp_build_tgsi_action * action,
1715 struct lp_build_tgsi_context * bld_base,
1716 struct lp_build_emit_data * emit_data)
1717 {
1718 LLVMBuilderRef builder = bld_base->base.gallivm->builder;
1719 LLVMValueRef div_mask = lp_build_cmp(&bld_base->uint_bld,
1720 PIPE_FUNC_EQUAL, emit_data->args[1],
1721 bld_base->uint_bld.zero);
1722 /* We want to make sure that we never divide/mod by zero to not
1723 * generate sigfpe. We don't want to crash just because the
1724 * shader is doing something weird. */
1725 LLVMValueRef divisor = LLVMBuildOr(builder,
1726 div_mask,
1727 emit_data->args[1], "");
1728 LLVMValueRef result = lp_build_mod(&bld_base->int_bld,
1729 emit_data->args[0], divisor);
1730 /* umod by zero doesn't have a guaranteed return value chose -1 for now. */
1731 emit_data->output[emit_data->chan] = LLVMBuildOr(builder,
1732 div_mask,
1733 result, "");
1734 }
1735
1736 /* TGSI_OPCODE_NOT */
1737 static void
1738 not_emit_cpu(
1739 const struct lp_build_tgsi_action * action,
1740 struct lp_build_tgsi_context * bld_base,
1741 struct lp_build_emit_data * emit_data)
1742 {
1743 emit_data->output[emit_data->chan] = lp_build_not(&bld_base->uint_bld,
1744 emit_data->args[0]);
1745 }
1746
1747 /* TGSI_OPCODE_OR (CPU Only) */
1748 static void
1749 or_emit_cpu(
1750 const struct lp_build_tgsi_action * action,
1751 struct lp_build_tgsi_context * bld_base,
1752 struct lp_build_emit_data * emit_data)
1753 {
1754 emit_data->output[emit_data->chan] = lp_build_or(&bld_base->uint_bld,
1755 emit_data->args[0], emit_data->args[1]);
1756 }
1757
1758 /* TGSI_OPCODE_POW (CPU Only) */
1759 static void
1760 pow_emit_cpu(
1761 const struct lp_build_tgsi_action * action,
1762 struct lp_build_tgsi_context * bld_base,
1763 struct lp_build_emit_data * emit_data)
1764 {
1765 emit_data->output[emit_data->chan] = lp_build_pow(&bld_base->base,
1766 emit_data->args[0], emit_data->args[1]);
1767 }
1768
1769
1770 /* TGSI_OPCODE_RCP (CPU Only) */
1771
1772 static void
1773 rcp_emit_cpu(
1774 const struct lp_build_tgsi_action * action,
1775 struct lp_build_tgsi_context * bld_base,
1776 struct lp_build_emit_data * emit_data)
1777 {
1778 emit_data->output[emit_data->chan] = lp_build_rcp(&bld_base->base,
1779 emit_data->args[0]);
1780 }
1781
1782 /* Reciprical squareroot (CPU Only) */
1783 static void
1784 recip_sqrt_emit_cpu(
1785 const struct lp_build_tgsi_action * action,
1786 struct lp_build_tgsi_context * bld_base,
1787 struct lp_build_emit_data * emit_data)
1788 {
1789 emit_data->output[emit_data->chan] = lp_build_rsqrt(&bld_base->base,
1790 emit_data->args[0]);
1791 }
1792
1793 static void
1794 sqrt_emit_cpu(
1795 const struct lp_build_tgsi_action * action,
1796 struct lp_build_tgsi_context * bld_base,
1797 struct lp_build_emit_data * emit_data)
1798 {
1799 emit_data->output[emit_data->chan] = lp_build_sqrt(&bld_base->base,
1800 emit_data->args[0]);
1801 }
1802
1803
1804 /* TGSI_OPCODE_ROUND (CPU Only) */
1805 static void
1806 round_emit_cpu(
1807 const struct lp_build_tgsi_action * action,
1808 struct lp_build_tgsi_context * bld_base,
1809 struct lp_build_emit_data * emit_data)
1810 {
1811 emit_data->output[emit_data->chan] = lp_build_round(&bld_base->base,
1812 emit_data->args[0]);
1813 }
1814
1815 /* TGSI_OPCODE_SET Helper (CPU Only) */
1816
1817 static void
1818 set_emit_cpu(
1819 const struct lp_build_tgsi_action * action,
1820 struct lp_build_tgsi_context * bld_base,
1821 struct lp_build_emit_data * emit_data,
1822 unsigned pipe_func)
1823 {
1824 LLVMValueRef cond;
1825
1826 if (pipe_func != PIPE_FUNC_NOTEQUAL) {
1827 cond = lp_build_cmp_ordered(&bld_base->base, pipe_func,
1828 emit_data->args[0], emit_data->args[1]);
1829 }
1830 else {
1831 cond = lp_build_cmp(&bld_base->base, pipe_func,
1832 emit_data->args[0], emit_data->args[1]);
1833
1834 }
1835 emit_data->output[emit_data->chan] = lp_build_select(&bld_base->base,
1836 cond,
1837 bld_base->base.one,
1838 bld_base->base.zero);
1839 }
1840
1841 /* TGSI_OPCODE_SEQ (CPU Only) */
1842
1843 static void
1844 seq_emit_cpu(
1845 const struct lp_build_tgsi_action * action,
1846 struct lp_build_tgsi_context * bld_base,
1847 struct lp_build_emit_data * emit_data)
1848 {
1849 set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_EQUAL);
1850 }
1851
1852 /* TGSI_OPCODE_SGE (CPU Only) */
1853 static void
1854 sge_emit_cpu(
1855 const struct lp_build_tgsi_action * action,
1856 struct lp_build_tgsi_context * bld_base,
1857 struct lp_build_emit_data * emit_data)
1858 {
1859 set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_GEQUAL);
1860 }
1861
1862 /* TGSI_OPCODE_SGT (CPU Only)*/
1863
1864 static void
1865 sgt_emit_cpu(
1866 const struct lp_build_tgsi_action * action,
1867 struct lp_build_tgsi_context * bld_base,
1868 struct lp_build_emit_data * emit_data)
1869 {
1870 set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_GREATER);
1871 }
1872
1873 /* TGSI_OPCODE_SHL (CPU Only) */
1874 static void
1875 shl_emit_cpu(
1876 const struct lp_build_tgsi_action * action,
1877 struct lp_build_tgsi_context * bld_base,
1878 struct lp_build_emit_data * emit_data)
1879 {
1880 struct lp_build_context *uint_bld = &bld_base->uint_bld;
1881 LLVMValueRef mask = lp_build_const_vec(uint_bld->gallivm, uint_bld->type,
1882 uint_bld->type.width - 1);
1883 LLVMValueRef masked_count = lp_build_and(uint_bld, emit_data->args[1], mask);
1884 emit_data->output[emit_data->chan] = lp_build_shl(uint_bld, emit_data->args[0],
1885 masked_count);
1886 }
1887
1888 /* TGSI_OPCODE_SIN (CPU Only) */
1889 static void
1890 sin_emit_cpu(
1891 const struct lp_build_tgsi_action * action,
1892 struct lp_build_tgsi_context * bld_base,
1893 struct lp_build_emit_data * emit_data)
1894 {
1895 emit_data->output[emit_data->chan] = lp_build_sin(&bld_base->base,
1896 emit_data->args[0]);
1897 }
1898
1899 /* TGSI_OPCODE_SLE (CPU Only) */
1900 static void
1901 sle_emit_cpu(
1902 const struct lp_build_tgsi_action * action,
1903 struct lp_build_tgsi_context * bld_base,
1904 struct lp_build_emit_data * emit_data)
1905 {
1906 set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_LEQUAL);
1907 }
1908
1909 /* TGSI_OPCODE_SLT (CPU Only) */
1910 static void
1911 slt_emit_cpu(
1912 const struct lp_build_tgsi_action * action,
1913 struct lp_build_tgsi_context * bld_base,
1914 struct lp_build_emit_data * emit_data)
1915 {
1916 set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_LESS);
1917 }
1918
1919 /* TGSI_OPCODE_SNE (CPU Only) */
1920
1921 static void
1922 sne_emit_cpu(
1923 const struct lp_build_tgsi_action * action,
1924 struct lp_build_tgsi_context * bld_base,
1925 struct lp_build_emit_data * emit_data)
1926 {
1927 set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_NOTEQUAL);
1928 }
1929
1930 /* TGSI_OPCODE_SSG (CPU Only) */
1931
1932 static void
1933 ssg_emit_cpu(
1934 const struct lp_build_tgsi_action * action,
1935 struct lp_build_tgsi_context * bld_base,
1936 struct lp_build_emit_data * emit_data)
1937 {
1938 emit_data->output[emit_data->chan] = lp_build_sgn(&bld_base->base,
1939 emit_data->args[0]);
1940 }
1941
1942 /* TGSI_OPCODE_TRUNC (CPU Only) */
1943
1944 static void
1945 trunc_emit_cpu(
1946 const struct lp_build_tgsi_action * action,
1947 struct lp_build_tgsi_context * bld_base,
1948 struct lp_build_emit_data * emit_data)
1949 {
1950 emit_data->output[emit_data->chan] = lp_build_trunc(&bld_base->base,
1951 emit_data->args[0]);
1952 }
1953
1954 /* TGSI_OPCODE_UADD (CPU Only) */
1955 static void
1956 uadd_emit_cpu(
1957 const struct lp_build_tgsi_action * action,
1958 struct lp_build_tgsi_context * bld_base,
1959 struct lp_build_emit_data * emit_data)
1960 {
1961 emit_data->output[emit_data->chan] = lp_build_add(&bld_base->uint_bld,
1962 emit_data->args[0], emit_data->args[1]);
1963 }
1964
1965 /* TGSI_OPCODE_UDIV (CPU Only) */
1966 static void
1967 udiv_emit_cpu(
1968 const struct lp_build_tgsi_action * action,
1969 struct lp_build_tgsi_context * bld_base,
1970 struct lp_build_emit_data * emit_data)
1971 {
1972
1973 LLVMBuilderRef builder = bld_base->base.gallivm->builder;
1974 LLVMValueRef div_mask = lp_build_cmp(&bld_base->uint_bld,
1975 PIPE_FUNC_EQUAL, emit_data->args[1],
1976 bld_base->uint_bld.zero);
1977 /* We want to make sure that we never divide/mod by zero to not
1978 * generate sigfpe. We don't want to crash just because the
1979 * shader is doing something weird. */
1980 LLVMValueRef divisor = LLVMBuildOr(builder,
1981 div_mask,
1982 emit_data->args[1], "");
1983 LLVMValueRef result = lp_build_div(&bld_base->uint_bld,
1984 emit_data->args[0], divisor);
1985 /* udiv by zero is guaranteed to return 0xffffffff at least with d3d10 */
1986 emit_data->output[emit_data->chan] = LLVMBuildOr(builder,
1987 div_mask,
1988 result, "");
1989 }
1990
1991 /* TGSI_OPCODE_UMAX (CPU Only) */
1992 static void
1993 umax_emit_cpu(
1994 const struct lp_build_tgsi_action * action,
1995 struct lp_build_tgsi_context * bld_base,
1996 struct lp_build_emit_data * emit_data)
1997 {
1998 emit_data->output[emit_data->chan] = lp_build_max(&bld_base->uint_bld,
1999 emit_data->args[0], emit_data->args[1]);
2000 }
2001
2002 /* TGSI_OPCODE_UMIN (CPU Only) */
2003 static void
2004 umin_emit_cpu(
2005 const struct lp_build_tgsi_action * action,
2006 struct lp_build_tgsi_context * bld_base,
2007 struct lp_build_emit_data * emit_data)
2008 {
2009 emit_data->output[emit_data->chan] = lp_build_min(&bld_base->uint_bld,
2010 emit_data->args[0], emit_data->args[1]);
2011 }
2012
2013 /* TGSI_OPCODE_UMOD (CPU Only) */
2014 static void
2015 umod_emit_cpu(
2016 const struct lp_build_tgsi_action * action,
2017 struct lp_build_tgsi_context * bld_base,
2018 struct lp_build_emit_data * emit_data)
2019 {
2020 LLVMBuilderRef builder = bld_base->base.gallivm->builder;
2021 LLVMValueRef div_mask = lp_build_cmp(&bld_base->uint_bld,
2022 PIPE_FUNC_EQUAL, emit_data->args[1],
2023 bld_base->uint_bld.zero);
2024 /* We want to make sure that we never divide/mod by zero to not
2025 * generate sigfpe. We don't want to crash just because the
2026 * shader is doing something weird. */
2027 LLVMValueRef divisor = LLVMBuildOr(builder,
2028 div_mask,
2029 emit_data->args[1], "");
2030 LLVMValueRef result = lp_build_mod(&bld_base->uint_bld,
2031 emit_data->args[0], divisor);
2032 /* umod by zero is guaranteed to return 0xffffffff */
2033 emit_data->output[emit_data->chan] = LLVMBuildOr(builder,
2034 div_mask,
2035 result, "");
2036 }
2037
2038 /* TGSI_OPCODE_USET Helper (CPU Only) */
2039 static void
2040 uset_emit_cpu(
2041 const struct lp_build_tgsi_action * action,
2042 struct lp_build_tgsi_context * bld_base,
2043 struct lp_build_emit_data * emit_data,
2044 unsigned pipe_func)
2045 {
2046 LLVMValueRef cond = lp_build_cmp(&bld_base->uint_bld, pipe_func,
2047 emit_data->args[0], emit_data->args[1]);
2048 emit_data->output[emit_data->chan] = cond;
2049 }
2050
2051
2052 /* TGSI_OPCODE_USEQ (CPU Only) */
2053 static void
2054 useq_emit_cpu(
2055 const struct lp_build_tgsi_action * action,
2056 struct lp_build_tgsi_context * bld_base,
2057 struct lp_build_emit_data * emit_data)
2058 {
2059 uset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_EQUAL);
2060 }
2061
2062 /* TGSI_OPCODE_ISGE (CPU Only) */
2063 static void
2064 usge_emit_cpu(
2065 const struct lp_build_tgsi_action * action,
2066 struct lp_build_tgsi_context * bld_base,
2067 struct lp_build_emit_data * emit_data)
2068 {
2069 uset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_GEQUAL);
2070 }
2071
2072 /* TGSI_OPCODE_USHR (CPU Only) */
2073 static void
2074 ushr_emit_cpu(
2075 const struct lp_build_tgsi_action * action,
2076 struct lp_build_tgsi_context * bld_base,
2077 struct lp_build_emit_data * emit_data)
2078 {
2079 struct lp_build_context *uint_bld = &bld_base->uint_bld;
2080 LLVMValueRef mask = lp_build_const_vec(uint_bld->gallivm, uint_bld->type,
2081 uint_bld->type.width - 1);
2082 LLVMValueRef masked_count = lp_build_and(uint_bld, emit_data->args[1], mask);
2083 emit_data->output[emit_data->chan] = lp_build_shr(uint_bld, emit_data->args[0],
2084 masked_count);
2085 }
2086
2087 /* TGSI_OPCODE_ISLT (CPU Only) */
2088 static void
2089 uslt_emit_cpu(
2090 const struct lp_build_tgsi_action * action,
2091 struct lp_build_tgsi_context * bld_base,
2092 struct lp_build_emit_data * emit_data)
2093 {
2094 uset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_LESS);
2095 }
2096
2097 /* TGSI_OPCODE_USNE (CPU Only) */
2098
2099 static void
2100 usne_emit_cpu(
2101 const struct lp_build_tgsi_action * action,
2102 struct lp_build_tgsi_context * bld_base,
2103 struct lp_build_emit_data * emit_data)
2104 {
2105 uset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_NOTEQUAL);
2106 }
2107
2108 /* TGSI_OPCODE_XOR */
2109 static void
2110 xor_emit_cpu(
2111 const struct lp_build_tgsi_action * action,
2112 struct lp_build_tgsi_context * bld_base,
2113 struct lp_build_emit_data * emit_data)
2114 {
2115 emit_data->output[emit_data->chan] = lp_build_xor(&bld_base->uint_bld,
2116 emit_data->args[0],
2117 emit_data->args[1]);
2118 }
2119
2120 /* TGSI_OPCODE_DABS (CPU Only) */
2121 static void
2122 dabs_emit_cpu(
2123 const struct lp_build_tgsi_action * action,
2124 struct lp_build_tgsi_context * bld_base,
2125 struct lp_build_emit_data * emit_data)
2126 {
2127 emit_data->output[emit_data->chan] = lp_build_abs(&bld_base->dbl_bld,
2128 emit_data->args[0]);
2129 }
2130
2131 /* TGSI_OPCODE_DNEG (CPU Only) */
2132 static void
2133 dneg_emit_cpu(
2134 const struct lp_build_tgsi_action * action,
2135 struct lp_build_tgsi_context * bld_base,
2136 struct lp_build_emit_data * emit_data)
2137 {
2138 emit_data->output[emit_data->chan] = lp_build_sub(&bld_base->dbl_bld,
2139 bld_base->dbl_bld.zero,
2140 emit_data->args[0]);
2141 }
2142
2143 /* TGSI_OPCODE_DSET Helper (CPU Only) */
2144 static void
2145 dset_emit_cpu(
2146 const struct lp_build_tgsi_action * action,
2147 struct lp_build_tgsi_context * bld_base,
2148 struct lp_build_emit_data * emit_data,
2149 unsigned pipe_func)
2150 {
2151 LLVMBuilderRef builder = bld_base->base.gallivm->builder;
2152 LLVMValueRef cond = lp_build_cmp(&bld_base->dbl_bld, pipe_func,
2153 emit_data->args[0], emit_data->args[1]);
2154 /* arguments were 64 bit but store as 32 bit */
2155 cond = LLVMBuildTrunc(builder, cond, bld_base->int_bld.int_vec_type, "");
2156 emit_data->output[emit_data->chan] = cond;
2157 }
2158
2159 /* TGSI_OPCODE_DSEQ (CPU Only) */
2160 static void
2161 dseq_emit_cpu(
2162 const struct lp_build_tgsi_action * action,
2163 struct lp_build_tgsi_context * bld_base,
2164 struct lp_build_emit_data * emit_data)
2165 {
2166 dset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_EQUAL);
2167 }
2168
2169 /* TGSI_OPCODE_DSGE (CPU Only) */
2170 static void
2171 dsge_emit_cpu(
2172 const struct lp_build_tgsi_action * action,
2173 struct lp_build_tgsi_context * bld_base,
2174 struct lp_build_emit_data * emit_data)
2175 {
2176 dset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_GEQUAL);
2177 }
2178
2179 /* TGSI_OPCODE_DSLT (CPU Only) */
2180 static void
2181 dslt_emit_cpu(
2182 const struct lp_build_tgsi_action * action,
2183 struct lp_build_tgsi_context * bld_base,
2184 struct lp_build_emit_data * emit_data)
2185 {
2186 dset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_LESS);
2187 }
2188
2189 /* TGSI_OPCODE_DSNE (CPU Only) */
2190 static void
2191 dsne_emit_cpu(
2192 const struct lp_build_tgsi_action * action,
2193 struct lp_build_tgsi_context * bld_base,
2194 struct lp_build_emit_data * emit_data)
2195 {
2196 dset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_NOTEQUAL);
2197 }
2198
2199 /* Double Reciprocal squareroot (CPU Only) */
2200 static void
2201 drecip_sqrt_emit_cpu(
2202 const struct lp_build_tgsi_action * action,
2203 struct lp_build_tgsi_context * bld_base,
2204 struct lp_build_emit_data * emit_data)
2205 {
2206 emit_data->output[emit_data->chan] = lp_build_rsqrt(&bld_base->dbl_bld,
2207 emit_data->args[0]);
2208 }
2209
2210 /* Double Squareroot (CPU Only) */
2211 static void
2212 dsqrt_emit_cpu(
2213 const struct lp_build_tgsi_action * action,
2214 struct lp_build_tgsi_context * bld_base,
2215 struct lp_build_emit_data * emit_data)
2216 {
2217 emit_data->output[emit_data->chan] = lp_build_sqrt(&bld_base->dbl_bld,
2218 emit_data->args[0]);
2219 }
2220
2221 static void
2222 i64abs_emit_cpu(
2223 const struct lp_build_tgsi_action * action,
2224 struct lp_build_tgsi_context * bld_base,
2225 struct lp_build_emit_data * emit_data)
2226 {
2227 emit_data->output[emit_data->chan] = lp_build_abs(&bld_base->int64_bld,
2228 emit_data->args[0]);
2229 }
2230
2231 static void
2232 i64ssg_emit_cpu(
2233 const struct lp_build_tgsi_action * action,
2234 struct lp_build_tgsi_context * bld_base,
2235 struct lp_build_emit_data * emit_data)
2236 {
2237 emit_data->output[emit_data->chan] = lp_build_sgn(&bld_base->int64_bld,
2238 emit_data->args[0]);
2239 }
2240
2241 static void
2242 i64neg_emit_cpu(
2243 const struct lp_build_tgsi_action * action,
2244 struct lp_build_tgsi_context * bld_base,
2245 struct lp_build_emit_data * emit_data)
2246 {
2247 emit_data->output[emit_data->chan] = lp_build_sub(&bld_base->int64_bld,
2248 bld_base->int64_bld.zero,
2249 emit_data->args[0]);
2250 }
2251
2252 static void
2253 u64set_emit_cpu(
2254 const struct lp_build_tgsi_action * action,
2255 struct lp_build_tgsi_context * bld_base,
2256 struct lp_build_emit_data * emit_data,
2257 unsigned pipe_func)
2258 {
2259 LLVMBuilderRef builder = bld_base->base.gallivm->builder;
2260 LLVMValueRef cond = lp_build_cmp(&bld_base->uint64_bld, pipe_func,
2261 emit_data->args[0], emit_data->args[1]);
2262 /* arguments were 64 bit but store as 32 bit */
2263 cond = LLVMBuildTrunc(builder, cond, bld_base->int_bld.int_vec_type, "");
2264 emit_data->output[emit_data->chan] = cond;
2265 }
2266
2267 static void
2268 u64seq_emit_cpu(
2269 const struct lp_build_tgsi_action * action,
2270 struct lp_build_tgsi_context * bld_base,
2271 struct lp_build_emit_data * emit_data)
2272 {
2273 u64set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_EQUAL);
2274 }
2275
2276 static void
2277 u64sne_emit_cpu(
2278 const struct lp_build_tgsi_action * action,
2279 struct lp_build_tgsi_context * bld_base,
2280 struct lp_build_emit_data * emit_data)
2281 {
2282 u64set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_NOTEQUAL);
2283 }
2284
2285 static void
2286 u64slt_emit_cpu(
2287 const struct lp_build_tgsi_action * action,
2288 struct lp_build_tgsi_context * bld_base,
2289 struct lp_build_emit_data * emit_data)
2290 {
2291 u64set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_LESS);
2292 }
2293
2294 static void
2295 u64sge_emit_cpu(
2296 const struct lp_build_tgsi_action * action,
2297 struct lp_build_tgsi_context * bld_base,
2298 struct lp_build_emit_data * emit_data)
2299 {
2300 u64set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_GEQUAL);
2301 }
2302
2303 static void
2304 i64set_emit_cpu(
2305 const struct lp_build_tgsi_action * action,
2306 struct lp_build_tgsi_context * bld_base,
2307 struct lp_build_emit_data * emit_data,
2308 unsigned pipe_func)
2309 {
2310 LLVMBuilderRef builder = bld_base->base.gallivm->builder;
2311 LLVMValueRef cond = lp_build_cmp(&bld_base->int64_bld, pipe_func,
2312 emit_data->args[0], emit_data->args[1]);
2313 /* arguments were 64 bit but store as 32 bit */
2314 cond = LLVMBuildTrunc(builder, cond, bld_base->int_bld.int_vec_type, "");
2315 emit_data->output[emit_data->chan] = cond;
2316 }
2317
2318 static void
2319 i64slt_emit_cpu(
2320 const struct lp_build_tgsi_action * action,
2321 struct lp_build_tgsi_context * bld_base,
2322 struct lp_build_emit_data * emit_data)
2323 {
2324 i64set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_LESS);
2325 }
2326
2327 static void
2328 i64sge_emit_cpu(
2329 const struct lp_build_tgsi_action * action,
2330 struct lp_build_tgsi_context * bld_base,
2331 struct lp_build_emit_data * emit_data)
2332 {
2333 i64set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_GEQUAL);
2334 }
2335
2336 static void
2337 u64max_emit_cpu(
2338 const struct lp_build_tgsi_action * action,
2339 struct lp_build_tgsi_context * bld_base,
2340 struct lp_build_emit_data * emit_data)
2341 {
2342 emit_data->output[emit_data->chan] = lp_build_max(&bld_base->uint64_bld,
2343 emit_data->args[0], emit_data->args[1]);
2344 }
2345
2346 static void
2347 u64min_emit_cpu(
2348 const struct lp_build_tgsi_action * action,
2349 struct lp_build_tgsi_context * bld_base,
2350 struct lp_build_emit_data * emit_data)
2351 {
2352 emit_data->output[emit_data->chan] = lp_build_min(&bld_base->uint64_bld,
2353 emit_data->args[0], emit_data->args[1]);
2354 }
2355
2356 static void
2357 i64max_emit_cpu(
2358 const struct lp_build_tgsi_action * action,
2359 struct lp_build_tgsi_context * bld_base,
2360 struct lp_build_emit_data * emit_data)
2361 {
2362 emit_data->output[emit_data->chan] = lp_build_max(&bld_base->int64_bld,
2363 emit_data->args[0], emit_data->args[1]);
2364 }
2365
2366 static void
2367 i64min_emit_cpu(
2368 const struct lp_build_tgsi_action * action,
2369 struct lp_build_tgsi_context * bld_base,
2370 struct lp_build_emit_data * emit_data)
2371 {
2372 emit_data->output[emit_data->chan] = lp_build_min(&bld_base->int64_bld,
2373 emit_data->args[0], emit_data->args[1]);
2374 }
2375
2376 static void
2377 u64add_emit_cpu(
2378 const struct lp_build_tgsi_action * action,
2379 struct lp_build_tgsi_context * bld_base,
2380 struct lp_build_emit_data * emit_data)
2381 {
2382 emit_data->output[emit_data->chan] = lp_build_add(&bld_base->uint64_bld,
2383 emit_data->args[0], emit_data->args[1]);
2384 }
2385
2386 static void
2387 u64shl_emit_cpu(
2388 const struct lp_build_tgsi_action * action,
2389 struct lp_build_tgsi_context * bld_base,
2390 struct lp_build_emit_data * emit_data)
2391 {
2392 struct lp_build_context *uint_bld = &bld_base->uint64_bld;
2393 LLVMValueRef mask = lp_build_const_vec(uint_bld->gallivm, uint_bld->type,
2394 uint_bld->type.width - 1);
2395 LLVMValueRef masked_count = lp_build_and(uint_bld, emit_data->args[1], mask);
2396 emit_data->output[emit_data->chan] = lp_build_shl(uint_bld, emit_data->args[0],
2397 masked_count);
2398 }
2399
2400 static void
2401 i64shr_emit_cpu(
2402 const struct lp_build_tgsi_action * action,
2403 struct lp_build_tgsi_context * bld_base,
2404 struct lp_build_emit_data * emit_data)
2405 {
2406 struct lp_build_context *int_bld = &bld_base->int64_bld;
2407 LLVMValueRef mask = lp_build_const_vec(int_bld->gallivm, int_bld->type,
2408 int_bld->type.width - 1);
2409 LLVMValueRef masked_count = lp_build_and(int_bld, emit_data->args[1], mask);
2410 emit_data->output[emit_data->chan] = lp_build_shr(int_bld, emit_data->args[0],
2411 masked_count);
2412 }
2413
2414 static void
2415 u64shr_emit_cpu(
2416 const struct lp_build_tgsi_action * action,
2417 struct lp_build_tgsi_context * bld_base,
2418 struct lp_build_emit_data * emit_data)
2419 {
2420 struct lp_build_context *uint_bld = &bld_base->uint64_bld;
2421 LLVMValueRef mask = lp_build_const_vec(uint_bld->gallivm, uint_bld->type,
2422 uint_bld->type.width - 1);
2423 LLVMValueRef masked_count = lp_build_and(uint_bld, emit_data->args[1], mask);
2424 emit_data->output[emit_data->chan] = lp_build_shr(uint_bld, emit_data->args[0],
2425 masked_count);
2426 }
2427
2428 void
2429 lp_set_default_actions_cpu(
2430 struct lp_build_tgsi_context * bld_base)
2431 {
2432 lp_set_default_actions(bld_base);
2433 bld_base->op_actions[TGSI_OPCODE_ADD].emit = add_emit_cpu;
2434 bld_base->op_actions[TGSI_OPCODE_AND].emit = and_emit_cpu;
2435 bld_base->op_actions[TGSI_OPCODE_ARL].emit = arl_emit_cpu;
2436 bld_base->op_actions[TGSI_OPCODE_ARR].emit = arr_emit_cpu;
2437 bld_base->op_actions[TGSI_OPCODE_CEIL].emit = ceil_emit_cpu;
2438 bld_base->op_actions[TGSI_OPCODE_COS].emit = cos_emit_cpu;
2439 bld_base->op_actions[TGSI_OPCODE_CMP].emit = cmp_emit_cpu;
2440 bld_base->op_actions[TGSI_OPCODE_DIV].emit = div_emit_cpu;
2441 bld_base->op_actions[TGSI_OPCODE_EX2].emit = ex2_emit_cpu;
2442 bld_base->op_actions[TGSI_OPCODE_F2I].emit = f2i_emit_cpu;
2443 bld_base->op_actions[TGSI_OPCODE_FLR].emit = flr_emit_cpu;
2444 bld_base->op_actions[TGSI_OPCODE_FSEQ].emit = fseq_emit_cpu;
2445 bld_base->op_actions[TGSI_OPCODE_FSGE].emit = fsge_emit_cpu;
2446 bld_base->op_actions[TGSI_OPCODE_FSLT].emit = fslt_emit_cpu;
2447 bld_base->op_actions[TGSI_OPCODE_FSNE].emit = fsne_emit_cpu;
2448
2449 bld_base->op_actions[TGSI_OPCODE_I2F].emit = i2f_emit_cpu;
2450 bld_base->op_actions[TGSI_OPCODE_IABS].emit = iabs_emit_cpu;
2451 bld_base->op_actions[TGSI_OPCODE_IDIV].emit = idiv_emit_cpu;
2452 bld_base->op_actions[TGSI_OPCODE_INEG].emit = ineg_emit_cpu;
2453 bld_base->op_actions[TGSI_OPCODE_IMAX].emit = imax_emit_cpu;
2454 bld_base->op_actions[TGSI_OPCODE_IMIN].emit = imin_emit_cpu;
2455 bld_base->op_actions[TGSI_OPCODE_ISGE].emit = isge_emit_cpu;
2456 bld_base->op_actions[TGSI_OPCODE_ISHR].emit = ishr_emit_cpu;
2457 bld_base->op_actions[TGSI_OPCODE_ISLT].emit = islt_emit_cpu;
2458 bld_base->op_actions[TGSI_OPCODE_ISSG].emit = issg_emit_cpu;
2459 bld_base->op_actions[TGSI_OPCODE_IMUL_HI].emit = imul_hi_emit_cpu;
2460 bld_base->op_actions[TGSI_OPCODE_UMUL_HI].emit = umul_hi_emit_cpu;
2461
2462 bld_base->op_actions[TGSI_OPCODE_LG2].emit = lg2_emit_cpu;
2463 bld_base->op_actions[TGSI_OPCODE_LOG].emit = log_emit_cpu;
2464 bld_base->op_actions[TGSI_OPCODE_MAD].emit = mad_emit_cpu;
2465 bld_base->op_actions[TGSI_OPCODE_MAX].emit = max_emit_cpu;
2466 bld_base->op_actions[TGSI_OPCODE_MIN].emit = min_emit_cpu;
2467 bld_base->op_actions[TGSI_OPCODE_MOD].emit = mod_emit_cpu;
2468 bld_base->op_actions[TGSI_OPCODE_NOT].emit = not_emit_cpu;
2469 bld_base->op_actions[TGSI_OPCODE_OR].emit = or_emit_cpu;
2470 bld_base->op_actions[TGSI_OPCODE_POW].emit = pow_emit_cpu;
2471 bld_base->op_actions[TGSI_OPCODE_RCP].emit = rcp_emit_cpu;
2472 bld_base->op_actions[TGSI_OPCODE_ROUND].emit = round_emit_cpu;
2473 bld_base->op_actions[TGSI_OPCODE_SEQ].emit = seq_emit_cpu;
2474 bld_base->op_actions[TGSI_OPCODE_SGE].emit = sge_emit_cpu;
2475 bld_base->op_actions[TGSI_OPCODE_SGT].emit = sgt_emit_cpu;
2476 bld_base->op_actions[TGSI_OPCODE_SIN].emit = sin_emit_cpu;
2477 bld_base->op_actions[TGSI_OPCODE_SHL].emit = shl_emit_cpu;
2478 bld_base->op_actions[TGSI_OPCODE_SLE].emit = sle_emit_cpu;
2479 bld_base->op_actions[TGSI_OPCODE_SLT].emit = slt_emit_cpu;
2480 bld_base->op_actions[TGSI_OPCODE_SNE].emit = sne_emit_cpu;
2481 bld_base->op_actions[TGSI_OPCODE_SSG].emit = ssg_emit_cpu;
2482 bld_base->op_actions[TGSI_OPCODE_TRUNC].emit = trunc_emit_cpu;
2483
2484 bld_base->rsq_action.emit = recip_sqrt_emit_cpu;
2485 bld_base->sqrt_action.emit = sqrt_emit_cpu;
2486
2487 bld_base->op_actions[TGSI_OPCODE_UADD].emit = uadd_emit_cpu;
2488 bld_base->op_actions[TGSI_OPCODE_UCMP].emit = ucmp_emit_cpu;
2489 bld_base->op_actions[TGSI_OPCODE_UDIV].emit = udiv_emit_cpu;
2490 bld_base->op_actions[TGSI_OPCODE_UMAX].emit = umax_emit_cpu;
2491 bld_base->op_actions[TGSI_OPCODE_UMIN].emit = umin_emit_cpu;
2492 bld_base->op_actions[TGSI_OPCODE_UMOD].emit = umod_emit_cpu;
2493 bld_base->op_actions[TGSI_OPCODE_USEQ].emit = useq_emit_cpu;
2494 bld_base->op_actions[TGSI_OPCODE_USGE].emit = usge_emit_cpu;
2495 bld_base->op_actions[TGSI_OPCODE_USHR].emit = ushr_emit_cpu;
2496 bld_base->op_actions[TGSI_OPCODE_USLT].emit = uslt_emit_cpu;
2497 bld_base->op_actions[TGSI_OPCODE_USNE].emit = usne_emit_cpu;
2498
2499 bld_base->op_actions[TGSI_OPCODE_XOR].emit = xor_emit_cpu;
2500
2501 bld_base->op_actions[TGSI_OPCODE_DABS].emit = dabs_emit_cpu;
2502 bld_base->op_actions[TGSI_OPCODE_DNEG].emit = dneg_emit_cpu;
2503 bld_base->op_actions[TGSI_OPCODE_DSEQ].emit = dseq_emit_cpu;
2504 bld_base->op_actions[TGSI_OPCODE_DSGE].emit = dsge_emit_cpu;
2505 bld_base->op_actions[TGSI_OPCODE_DSLT].emit = dslt_emit_cpu;
2506 bld_base->op_actions[TGSI_OPCODE_DSNE].emit = dsne_emit_cpu;
2507
2508 bld_base->op_actions[TGSI_OPCODE_DRSQ].emit = drecip_sqrt_emit_cpu;
2509 bld_base->op_actions[TGSI_OPCODE_DSQRT].emit = dsqrt_emit_cpu;
2510
2511 bld_base->op_actions[TGSI_OPCODE_I64ABS].emit = i64abs_emit_cpu;
2512 bld_base->op_actions[TGSI_OPCODE_I64SSG].emit = i64ssg_emit_cpu;
2513 bld_base->op_actions[TGSI_OPCODE_I64NEG].emit = i64neg_emit_cpu;
2514
2515 bld_base->op_actions[TGSI_OPCODE_U64SEQ].emit = u64seq_emit_cpu;
2516 bld_base->op_actions[TGSI_OPCODE_U64SNE].emit = u64sne_emit_cpu;
2517 bld_base->op_actions[TGSI_OPCODE_U64SLT].emit = u64slt_emit_cpu;
2518 bld_base->op_actions[TGSI_OPCODE_U64SGE].emit = u64sge_emit_cpu;
2519 bld_base->op_actions[TGSI_OPCODE_I64SLT].emit = i64slt_emit_cpu;
2520 bld_base->op_actions[TGSI_OPCODE_I64SGE].emit = i64sge_emit_cpu;
2521
2522 bld_base->op_actions[TGSI_OPCODE_U64MIN].emit = u64min_emit_cpu;
2523 bld_base->op_actions[TGSI_OPCODE_U64MAX].emit = u64max_emit_cpu;
2524 bld_base->op_actions[TGSI_OPCODE_I64MIN].emit = i64min_emit_cpu;
2525 bld_base->op_actions[TGSI_OPCODE_I64MAX].emit = i64max_emit_cpu;
2526
2527 bld_base->op_actions[TGSI_OPCODE_U64ADD].emit = u64add_emit_cpu;
2528 bld_base->op_actions[TGSI_OPCODE_U64MOD].emit = u64mod_emit_cpu;
2529 bld_base->op_actions[TGSI_OPCODE_I64MOD].emit = i64mod_emit_cpu;
2530 bld_base->op_actions[TGSI_OPCODE_U64DIV].emit = u64div_emit_cpu;
2531 bld_base->op_actions[TGSI_OPCODE_I64DIV].emit = i64div_emit_cpu;
2532
2533 bld_base->op_actions[TGSI_OPCODE_U64SHL].emit = u64shl_emit_cpu;
2534 bld_base->op_actions[TGSI_OPCODE_I64SHR].emit = i64shr_emit_cpu;
2535 bld_base->op_actions[TGSI_OPCODE_U64SHR].emit = u64shr_emit_cpu;
2536 }