Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4358 | Serge | 1 | /************************************************************************** |
2 | * |
||
3 | * Copyright 2011-2012 Advanced Micro Devices, Inc. |
||
4 | * Copyright 2009 VMware, Inc. |
||
5 | * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas. |
||
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 TUNGSTEN GRAPHICS 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 |
||
35 | * @author Tom Stellard |
||
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_gather.h" |
||
49 | #include "lp_bld_logic.h" |
||
50 | |||
51 | #include "tgsi/tgsi_exec.h" |
||
52 | |||
53 | /* XXX: The CPU only defaults should be repaced by generic ones. In most |
||
54 | * cases, the CPU defaults are just wrappers around a function in |
||
55 | * lp_build_arit.c and these functions should be inlined here and the CPU |
||
56 | * generic code should be removed and placed elsewhere. |
||
57 | */ |
||
58 | |||
59 | /* Default actions */ |
||
60 | |||
61 | /* Generic fetch_arg functions */ |
||
62 | |||
63 | static void scalar_unary_fetch_args( |
||
64 | struct lp_build_tgsi_context * bld_base, |
||
65 | struct lp_build_emit_data * emit_data) |
||
66 | { |
||
67 | /* src0.x */ |
||
68 | emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst, 0, 0); |
||
69 | emit_data->arg_count = 1; |
||
70 | emit_data->dst_type = LLVMTypeOf(emit_data->args[0]); |
||
71 | } |
||
72 | |||
73 | static void scalar_binary_fetch_args( |
||
74 | struct lp_build_tgsi_context * bld_base, |
||
75 | struct lp_build_emit_data * emit_data) |
||
76 | { |
||
77 | /* src0.x */ |
||
78 | emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst, |
||
79 | 0, TGSI_CHAN_X); |
||
80 | /* src1.x */ |
||
81 | emit_data->args[1] = lp_build_emit_fetch(bld_base, emit_data->inst, |
||
82 | 1, TGSI_CHAN_X); |
||
83 | emit_data->arg_count = 2; |
||
84 | emit_data->dst_type = LLVMTypeOf(emit_data->args[0]); |
||
85 | } |
||
86 | |||
87 | /* TGSI_OPCODE_ADD */ |
||
88 | static void |
||
89 | add_emit( |
||
90 | const struct lp_build_tgsi_action * action, |
||
91 | struct lp_build_tgsi_context * bld_base, |
||
92 | struct lp_build_emit_data * emit_data) |
||
93 | { |
||
94 | emit_data->output[emit_data->chan] = LLVMBuildFAdd( |
||
95 | bld_base->base.gallivm->builder, |
||
96 | emit_data->args[0], emit_data->args[1], ""); |
||
97 | } |
||
98 | |||
99 | /* TGSI_OPCODE_ARR */ |
||
100 | static void |
||
101 | arr_emit( |
||
102 | const struct lp_build_tgsi_action * action, |
||
103 | struct lp_build_tgsi_context * bld_base, |
||
104 | struct lp_build_emit_data * emit_data) |
||
105 | { |
||
106 | LLVMValueRef tmp = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_ROUND, emit_data->args[0]); |
||
107 | emit_data->output[emit_data->chan] = LLVMBuildFPToSI(bld_base->base.gallivm->builder, tmp, |
||
108 | bld_base->uint_bld.vec_type, ""); |
||
109 | } |
||
110 | |||
111 | /* TGSI_OPCODE_CLAMP */ |
||
112 | static void |
||
113 | clamp_emit( |
||
114 | const struct lp_build_tgsi_action * action, |
||
115 | struct lp_build_tgsi_context * bld_base, |
||
116 | struct lp_build_emit_data * emit_data) |
||
117 | { |
||
118 | LLVMValueRef tmp; |
||
119 | tmp = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MAX, |
||
120 | emit_data->args[0], |
||
121 | emit_data->args[1]); |
||
122 | emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base, |
||
123 | TGSI_OPCODE_MIN, tmp, emit_data->args[2]); |
||
124 | } |
||
125 | |||
126 | /* DP* Helper */ |
||
127 | |||
128 | static void |
||
129 | dp_fetch_args( |
||
130 | struct lp_build_tgsi_context * bld_base, |
||
131 | struct lp_build_emit_data * emit_data, |
||
132 | unsigned dp_components) |
||
133 | { |
||
134 | unsigned chan, src; |
||
135 | for (src = 0; src < 2; src++) { |
||
136 | for (chan = 0; chan < dp_components; chan++) { |
||
137 | emit_data->args[(src * dp_components) + chan] = |
||
138 | lp_build_emit_fetch(bld_base, emit_data->inst, src, chan); |
||
139 | } |
||
140 | } |
||
141 | emit_data->dst_type = bld_base->base.elem_type; |
||
142 | } |
||
143 | |||
144 | /* TGSI_OPCODE_DP2 */ |
||
145 | static void |
||
146 | dp2_fetch_args( |
||
147 | struct lp_build_tgsi_context * bld_base, |
||
148 | struct lp_build_emit_data * emit_data) |
||
149 | { |
||
150 | dp_fetch_args(bld_base, emit_data, 2); |
||
151 | } |
||
152 | |||
153 | static void |
||
154 | dp2_emit( |
||
155 | const struct lp_build_tgsi_action * action, |
||
156 | struct lp_build_tgsi_context * bld_base, |
||
157 | struct lp_build_emit_data * emit_data) |
||
158 | { |
||
159 | LLVMValueRef tmp0, tmp1; |
||
160 | tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, |
||
161 | emit_data->args[0] /* src0.x */, |
||
162 | emit_data->args[2] /* src1.x */); |
||
163 | tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, |
||
164 | emit_data->args[1] /* src0.y */, |
||
165 | emit_data->args[3] /* src1.y */); |
||
166 | emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base, |
||
167 | TGSI_OPCODE_ADD, tmp0, tmp1); |
||
168 | } |
||
169 | |||
170 | static struct lp_build_tgsi_action dp2_action = { |
||
171 | dp2_fetch_args, /* fetch_args */ |
||
172 | dp2_emit /* emit */ |
||
173 | }; |
||
174 | |||
175 | /* TGSI_OPCODE_DP2A */ |
||
176 | static void |
||
177 | dp2a_fetch_args( |
||
178 | struct lp_build_tgsi_context * bld_base, |
||
179 | struct lp_build_emit_data * emit_data) |
||
180 | { |
||
181 | dp_fetch_args(bld_base, emit_data, 2); |
||
182 | emit_data->args[5] = lp_build_emit_fetch(bld_base, emit_data->inst, |
||
183 | 2, TGSI_CHAN_X); |
||
184 | } |
||
185 | |||
186 | static void |
||
187 | dp2a_emit( |
||
188 | const struct lp_build_tgsi_action * action, |
||
189 | struct lp_build_tgsi_context * bld_base, |
||
190 | struct lp_build_emit_data * emit_data) |
||
191 | { |
||
192 | LLVMValueRef tmp; |
||
193 | tmp = lp_build_emit_llvm(bld_base, TGSI_OPCODE_DP2, emit_data); |
||
194 | emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_ADD, |
||
195 | emit_data->args[5], tmp); |
||
196 | } |
||
197 | |||
198 | static struct lp_build_tgsi_action dp2a_action = { |
||
199 | dp2a_fetch_args, /* fetch_args */ |
||
200 | dp2a_emit /* emit */ |
||
201 | }; |
||
202 | |||
203 | /* TGSI_OPCODE_DP3 */ |
||
204 | static void |
||
205 | dp3_fetch_args( |
||
206 | struct lp_build_tgsi_context * bld_base, |
||
207 | struct lp_build_emit_data * emit_data) |
||
208 | { |
||
209 | dp_fetch_args(bld_base, emit_data, 3); |
||
210 | } |
||
211 | |||
212 | static void |
||
213 | dp3_emit( |
||
214 | const struct lp_build_tgsi_action * action, |
||
215 | struct lp_build_tgsi_context * bld_base, |
||
216 | struct lp_build_emit_data * emit_data) |
||
217 | { |
||
218 | LLVMValueRef tmp0, tmp1; |
||
219 | tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, |
||
220 | emit_data->args[0] /* src0.x */, |
||
221 | emit_data->args[3] /* src1.x */); |
||
222 | tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, |
||
223 | emit_data->args[1] /* src0.y */, |
||
224 | emit_data->args[4] /* src1.y */); |
||
225 | tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_ADD, tmp1, tmp0); |
||
226 | tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, |
||
227 | emit_data->args[2] /* src0.z */, |
||
228 | emit_data->args[5] /* src1.z */); |
||
229 | emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base, |
||
230 | TGSI_OPCODE_ADD, tmp0, tmp1); |
||
231 | } |
||
232 | |||
233 | static struct lp_build_tgsi_action dp3_action = { |
||
234 | dp3_fetch_args, /* fetch_args */ |
||
235 | dp3_emit /* emit */ |
||
236 | }; |
||
237 | |||
238 | /* TGSI_OPCODDE_DP4 */ |
||
239 | |||
240 | static void |
||
241 | dp4_fetch_args( |
||
242 | struct lp_build_tgsi_context * bld_base, |
||
243 | struct lp_build_emit_data * emit_data) |
||
244 | { |
||
245 | dp_fetch_args(bld_base, emit_data, 4); |
||
246 | } |
||
247 | |||
248 | static void |
||
249 | dp4_emit( |
||
250 | const struct lp_build_tgsi_action * action, |
||
251 | struct lp_build_tgsi_context * bld_base, |
||
252 | struct lp_build_emit_data * emit_data) |
||
253 | { |
||
254 | LLVMValueRef tmp0, tmp1; |
||
255 | tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, |
||
256 | emit_data->args[0] /* src0.x */, |
||
257 | emit_data->args[4] /* src1.x */); |
||
258 | tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, |
||
259 | emit_data->args[1] /* src0.y */, |
||
260 | emit_data->args[5] /* src1.y */); |
||
261 | tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_ADD, tmp0, tmp1); |
||
262 | tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, |
||
263 | emit_data->args[2] /* src0.z */, |
||
264 | emit_data->args[6] /* src1.z */); |
||
265 | tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_ADD, tmp0, tmp1); |
||
266 | tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, |
||
267 | emit_data->args[3] /* src0.w */, |
||
268 | emit_data->args[7] /* src1.w */); |
||
269 | emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base, |
||
270 | TGSI_OPCODE_ADD, tmp0, tmp1); |
||
271 | } |
||
272 | |||
273 | static struct lp_build_tgsi_action dp4_action = { |
||
274 | dp4_fetch_args, /* fetch_args */ |
||
275 | dp4_emit /* emit */ |
||
276 | }; |
||
277 | |||
278 | /* TGSI_OPCODE_DPH */ |
||
279 | static void |
||
280 | dph_fetch_args( |
||
281 | struct lp_build_tgsi_context * bld_base, |
||
282 | struct lp_build_emit_data * emit_data) |
||
283 | { |
||
284 | dp_fetch_args(bld_base, emit_data, 4); |
||
285 | /* src0.w */ |
||
286 | emit_data->args[3] = bld_base->base.one; |
||
287 | } |
||
288 | |||
289 | const struct lp_build_tgsi_action dph_action = { |
||
290 | dph_fetch_args, /* fetch_args */ |
||
291 | dp4_emit /* emit */ |
||
292 | }; |
||
293 | |||
294 | /* TGSI_OPCODE_DST */ |
||
295 | static void |
||
296 | dst_fetch_args( |
||
297 | struct lp_build_tgsi_context * bld_base, |
||
298 | struct lp_build_emit_data * emit_data) |
||
299 | { |
||
300 | /* src0.y */ |
||
301 | emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst, |
||
302 | 0, TGSI_CHAN_Y); |
||
303 | /* src0.z */ |
||
304 | emit_data->args[1] = lp_build_emit_fetch(bld_base, emit_data->inst, |
||
305 | 0, TGSI_CHAN_Z); |
||
306 | /* src1.y */ |
||
307 | emit_data->args[2] = lp_build_emit_fetch(bld_base, emit_data->inst, |
||
308 | 1, TGSI_CHAN_Y); |
||
309 | /* src1.w */ |
||
310 | emit_data->args[3] = lp_build_emit_fetch(bld_base, emit_data->inst, |
||
311 | 1, TGSI_CHAN_W); |
||
312 | } |
||
313 | |||
314 | static void |
||
315 | dst_emit( |
||
316 | const struct lp_build_tgsi_action * action, |
||
317 | struct lp_build_tgsi_context * bld_base, |
||
318 | struct lp_build_emit_data * emit_data) |
||
319 | { |
||
320 | /* dst.x */ |
||
321 | emit_data->output[TGSI_CHAN_X] = bld_base->base.one; |
||
322 | |||
323 | /* dst.y */ |
||
324 | emit_data->output[TGSI_CHAN_Y] = lp_build_emit_llvm_binary(bld_base, |
||
325 | TGSI_OPCODE_MUL, |
||
326 | emit_data->args[0] /* src0.y */, |
||
327 | emit_data->args[2] /* src1.y */); |
||
328 | /* dst.z */ |
||
329 | emit_data->output[TGSI_CHAN_Z] = emit_data->args[1]; /* src0.z */ |
||
330 | |||
331 | /* dst.w */ |
||
332 | emit_data->output[TGSI_CHAN_W] = emit_data->args[3]; /* src1.w */ |
||
333 | } |
||
334 | |||
335 | static struct lp_build_tgsi_action dst_action = { |
||
336 | dst_fetch_args, /* fetch_args */ |
||
337 | dst_emit /* emit */ |
||
338 | }; |
||
339 | |||
340 | /* TGSI_OPCODE_END */ |
||
341 | static void |
||
342 | end_emit( |
||
343 | const struct lp_build_tgsi_action * action, |
||
344 | struct lp_build_tgsi_context * bld_base, |
||
345 | struct lp_build_emit_data * emit_data) |
||
346 | { |
||
347 | bld_base->pc = -1; |
||
348 | } |
||
349 | |||
350 | /* TGSI_OPCODE_EXP */ |
||
351 | |||
352 | static void |
||
353 | exp_emit( |
||
354 | const struct lp_build_tgsi_action * action, |
||
355 | struct lp_build_tgsi_context * bld_base, |
||
356 | struct lp_build_emit_data * emit_data) |
||
357 | { |
||
358 | LLVMValueRef floor_x; |
||
359 | |||
360 | /* floor( src0.x ) */ |
||
361 | floor_x = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_FLR, |
||
362 | emit_data->args[0]); |
||
363 | |||
364 | /* 2 ^ floor( src0.x ) */ |
||
365 | emit_data->output[TGSI_CHAN_X] = lp_build_emit_llvm_unary(bld_base, |
||
366 | TGSI_OPCODE_EX2, floor_x); |
||
367 | |||
368 | /* src0.x - floor( src0.x ) */ |
||
369 | emit_data->output[TGSI_CHAN_Y] = lp_build_emit_llvm_binary(bld_base, |
||
370 | TGSI_OPCODE_SUB, emit_data->args[0] /* src0.x */, floor_x); |
||
371 | |||
372 | /* 2 ^ src0.x */ |
||
373 | emit_data->output[TGSI_CHAN_Z] = lp_build_emit_llvm_unary(bld_base, |
||
374 | TGSI_OPCODE_EX2, emit_data->args[0] /* src0.x */); |
||
375 | |||
376 | emit_data->output[TGSI_CHAN_W] = bld_base->base.one; |
||
377 | } |
||
378 | |||
379 | const struct lp_build_tgsi_action exp_action = { |
||
380 | scalar_unary_fetch_args, /* fetch_args */ |
||
381 | exp_emit /* emit */ |
||
382 | }; |
||
383 | |||
384 | /* TGSI_OPCODE_FRC */ |
||
385 | |||
386 | static void |
||
387 | frc_emit( |
||
388 | const struct lp_build_tgsi_action * action, |
||
389 | struct lp_build_tgsi_context * bld_base, |
||
390 | struct lp_build_emit_data * emit_data) |
||
391 | { |
||
392 | LLVMValueRef tmp; |
||
393 | tmp = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_FLR, |
||
394 | emit_data->args[0]); |
||
395 | emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base, |
||
396 | TGSI_OPCODE_SUB, emit_data->args[0], tmp); |
||
397 | } |
||
398 | |||
399 | /* TGSI_OPCODE_KILL_IF */ |
||
400 | |||
401 | static void |
||
402 | kil_fetch_args( |
||
403 | struct lp_build_tgsi_context * bld_base, |
||
404 | struct lp_build_emit_data * emit_data) |
||
405 | { |
||
406 | /* src0.x */ |
||
407 | emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst, |
||
408 | 0, TGSI_CHAN_X); |
||
409 | /* src0.y */ |
||
410 | emit_data->args[1] = lp_build_emit_fetch(bld_base, emit_data->inst, |
||
411 | 0, TGSI_CHAN_Y); |
||
412 | /* src0.z */ |
||
413 | emit_data->args[2] = lp_build_emit_fetch(bld_base, emit_data->inst, |
||
414 | 0, TGSI_CHAN_Z); |
||
415 | /* src0.w */ |
||
416 | emit_data->args[3] = lp_build_emit_fetch(bld_base, emit_data->inst, |
||
417 | 0, TGSI_CHAN_W); |
||
418 | emit_data->arg_count = 4; |
||
419 | emit_data->dst_type = LLVMVoidTypeInContext(bld_base->base.gallivm->context); |
||
420 | } |
||
421 | |||
422 | /* TGSI_OPCODE_KILL */ |
||
423 | |||
424 | static void |
||
425 | kilp_fetch_args( |
||
426 | struct lp_build_tgsi_context * bld_base, |
||
427 | struct lp_build_emit_data * emit_data) |
||
428 | { |
||
429 | emit_data->dst_type = LLVMVoidTypeInContext(bld_base->base.gallivm->context); |
||
430 | } |
||
431 | |||
432 | /* TGSI_OPCODE_LIT */ |
||
433 | |||
434 | static void |
||
435 | lit_fetch_args( |
||
436 | struct lp_build_tgsi_context * bld_base, |
||
437 | struct lp_build_emit_data * emit_data) |
||
438 | { |
||
439 | /* src0.x */ |
||
440 | emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst, 0, TGSI_CHAN_X); |
||
441 | /* src0.y */ |
||
442 | emit_data->args[1] = lp_build_emit_fetch(bld_base, emit_data->inst, 0, TGSI_CHAN_Y); |
||
443 | /* src0.w */ |
||
444 | emit_data->args[2] = lp_build_emit_fetch(bld_base, emit_data->inst, 0, TGSI_CHAN_W); |
||
445 | emit_data->arg_count = 3; |
||
446 | } |
||
447 | |||
448 | static void |
||
449 | lit_emit( |
||
450 | const struct lp_build_tgsi_action * action, |
||
451 | struct lp_build_tgsi_context * bld_base, |
||
452 | struct lp_build_emit_data * emit_data) |
||
453 | { |
||
454 | LLVMValueRef tmp0, tmp1, tmp2; |
||
455 | |||
456 | /* dst.x */ |
||
457 | emit_data->output[TGSI_CHAN_X] = bld_base->base.one; |
||
458 | |||
459 | /* dst. y */ |
||
460 | emit_data->output[TGSI_CHAN_Y] = lp_build_emit_llvm_binary(bld_base, |
||
461 | TGSI_OPCODE_MAX, |
||
462 | emit_data->args[0] /* src0.x */, |
||
463 | bld_base->base.zero); |
||
464 | |||
465 | /* dst.z */ |
||
466 | /* XMM[1] = SrcReg[0].yyyy */ |
||
467 | tmp1 = emit_data->args[1]; |
||
468 | /* XMM[1] = max(XMM[1], 0) */ |
||
469 | tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MAX, |
||
470 | tmp1, bld_base->base.zero); |
||
471 | /* XMM[2] = SrcReg[0].wwww */ |
||
472 | tmp2 = emit_data->args[2]; |
||
473 | tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_POW, |
||
474 | tmp1, tmp2); |
||
475 | tmp0 = emit_data->args[0]; |
||
476 | emit_data->output[TGSI_CHAN_Z] = lp_build_emit_llvm_ternary(bld_base, |
||
477 | TGSI_OPCODE_CMP, |
||
478 | tmp0, bld_base->base.zero, tmp1); |
||
479 | /* dst.w */ |
||
480 | emit_data->output[TGSI_CHAN_W] = bld_base->base.one; |
||
481 | } |
||
482 | |||
483 | static struct lp_build_tgsi_action lit_action = { |
||
484 | lit_fetch_args, /* fetch_args */ |
||
485 | lit_emit /* emit */ |
||
486 | }; |
||
487 | |||
488 | /* TGSI_OPCODE_LOG */ |
||
489 | |||
490 | static void |
||
491 | log_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 | |||
497 | LLVMValueRef abs_x, log_abs_x, flr_log_abs_x, ex2_flr_log_abs_x; |
||
498 | |||
499 | /* abs( src0.x) */ |
||
500 | abs_x = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_ABS, |
||
501 | emit_data->args[0] /* src0.x */); |
||
502 | |||
503 | /* log( abs( src0.x ) ) */ |
||
504 | log_abs_x = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_LG2, |
||
505 | abs_x); |
||
506 | |||
507 | /* floor( log( abs( src0.x ) ) ) */ |
||
508 | flr_log_abs_x = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_FLR, |
||
509 | log_abs_x); |
||
510 | /* dst.x */ |
||
511 | emit_data->output[TGSI_CHAN_X] = flr_log_abs_x; |
||
512 | |||
513 | /* dst.y */ |
||
514 | ex2_flr_log_abs_x = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_EX2, |
||
515 | flr_log_abs_x); |
||
516 | |||
517 | /* abs( src0.x ) / 2^( floor( lg2( abs( src0.x ) ) ) ) */ |
||
518 | emit_data->output[TGSI_CHAN_Y] = lp_build_emit_llvm_binary(bld_base, |
||
519 | TGSI_OPCODE_DIV, abs_x, ex2_flr_log_abs_x); |
||
520 | |||
521 | /* dst.x */ |
||
522 | emit_data->output[TGSI_CHAN_Z] = log_abs_x; |
||
523 | |||
524 | /* dst.w */ |
||
525 | emit_data->output[TGSI_CHAN_W] = bld_base->base.one; |
||
526 | } |
||
527 | |||
528 | static struct lp_build_tgsi_action log_action = { |
||
529 | scalar_unary_fetch_args, /* fetch_args */ |
||
530 | log_emit /* emit */ |
||
531 | }; |
||
532 | |||
533 | /* TGSI_OPCODE_LRP */ |
||
534 | |||
535 | static void |
||
536 | lrp_emit( |
||
537 | const struct lp_build_tgsi_action * action, |
||
538 | struct lp_build_tgsi_context * bld_base, |
||
539 | struct lp_build_emit_data * emit_data) |
||
540 | { |
||
541 | LLVMValueRef tmp; |
||
542 | tmp = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_SUB, |
||
543 | emit_data->args[1], |
||
544 | emit_data->args[2]); |
||
545 | emit_data->output[emit_data->chan] = lp_build_emit_llvm_ternary(bld_base, |
||
546 | TGSI_OPCODE_MAD, emit_data->args[0], tmp, emit_data->args[2]); |
||
547 | } |
||
548 | |||
549 | /* TGSI_OPCODE_MAD */ |
||
550 | |||
551 | static void |
||
552 | mad_emit( |
||
553 | const struct lp_build_tgsi_action * action, |
||
554 | struct lp_build_tgsi_context * bld_base, |
||
555 | struct lp_build_emit_data * emit_data) |
||
556 | { |
||
557 | LLVMValueRef tmp; |
||
558 | tmp = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, |
||
559 | emit_data->args[0], |
||
560 | emit_data->args[1]); |
||
561 | emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base, |
||
562 | TGSI_OPCODE_ADD, tmp, emit_data->args[2]); |
||
563 | } |
||
564 | |||
565 | /* TGSI_OPCODE_MOV */ |
||
566 | |||
567 | static void |
||
568 | mov_emit( |
||
569 | const struct lp_build_tgsi_action * action, |
||
570 | struct lp_build_tgsi_context * bld_base, |
||
571 | struct lp_build_emit_data * emit_data) |
||
572 | { |
||
573 | emit_data->output[emit_data->chan] = emit_data->args[0]; |
||
574 | } |
||
575 | |||
576 | /* TGSI_OPCODE_MUL */ |
||
577 | static void |
||
578 | mul_emit( |
||
579 | const struct lp_build_tgsi_action * action, |
||
580 | struct lp_build_tgsi_context * bld_base, |
||
581 | struct lp_build_emit_data * emit_data) |
||
582 | { |
||
583 | emit_data->output[emit_data->chan] = LLVMBuildFMul( |
||
584 | bld_base->base.gallivm->builder, |
||
585 | emit_data->args[0], emit_data->args[1], ""); |
||
586 | } |
||
587 | |||
588 | /*.TGSI_OPCODE_DIV.*/ |
||
589 | static void fdiv_emit( |
||
590 | const struct lp_build_tgsi_action * action, |
||
591 | struct lp_build_tgsi_context * bld_base, |
||
592 | struct lp_build_emit_data * emit_data) |
||
593 | { |
||
594 | emit_data->output[emit_data->chan] = LLVMBuildFDiv( |
||
595 | bld_base->base.gallivm->builder, |
||
596 | emit_data->args[0], emit_data->args[1], ""); |
||
597 | } |
||
598 | |||
599 | /*.TGSI_OPCODE_RCP.*/ |
||
600 | static void rcp_emit( |
||
601 | const struct lp_build_tgsi_action * action, |
||
602 | struct lp_build_tgsi_context * bld_base, |
||
603 | struct lp_build_emit_data * emit_data) |
||
604 | { |
||
605 | LLVMValueRef one; |
||
606 | one = lp_build_const_float(bld_base->base.gallivm, 1.0f); |
||
607 | emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base, |
||
608 | TGSI_OPCODE_DIV, one, emit_data->args[0]); |
||
609 | } |
||
610 | |||
611 | /* TGSI_OPCODE_POW */ |
||
612 | |||
613 | static void |
||
614 | pow_emit( |
||
615 | const struct lp_build_tgsi_action * action, |
||
616 | struct lp_build_tgsi_context * bld_base, |
||
617 | struct lp_build_emit_data * emit_data) |
||
618 | { |
||
619 | emit_data->output[emit_data->chan] = lp_build_pow(&bld_base->base, |
||
620 | emit_data->args[0], emit_data->args[1]); |
||
621 | } |
||
622 | |||
623 | static struct lp_build_tgsi_action pow_action = { |
||
624 | scalar_binary_fetch_args, /* fetch_args */ |
||
625 | pow_emit /* emit */ |
||
626 | }; |
||
627 | |||
628 | /* TGSI_OPCODE_RSQ */ |
||
629 | |||
630 | static void |
||
631 | rsq_emit( |
||
632 | const struct lp_build_tgsi_action * action, |
||
633 | struct lp_build_tgsi_context * bld_base, |
||
634 | struct lp_build_emit_data * emit_data) |
||
635 | { |
||
636 | if (bld_base->rsq_action.emit) { |
||
637 | bld_base->rsq_action.emit(&bld_base->rsq_action, bld_base, emit_data); |
||
638 | } else { |
||
639 | emit_data->output[emit_data->chan] = bld_base->base.undef; |
||
640 | } |
||
641 | } |
||
642 | |||
643 | const struct lp_build_tgsi_action rsq_action = { |
||
644 | scalar_unary_fetch_args, /* fetch_args */ |
||
645 | rsq_emit /* emit */ |
||
646 | |||
647 | }; |
||
648 | |||
649 | /* TGSI_OPCODE_SQRT */ |
||
650 | |||
651 | static void |
||
652 | sqrt_emit( |
||
653 | const struct lp_build_tgsi_action * action, |
||
654 | struct lp_build_tgsi_context * bld_base, |
||
655 | struct lp_build_emit_data * emit_data) |
||
656 | { |
||
657 | if (bld_base->sqrt_action.emit) { |
||
658 | bld_base->sqrt_action.emit(&bld_base->sqrt_action, bld_base, emit_data); |
||
659 | } else { |
||
660 | emit_data->output[emit_data->chan] = bld_base->base.undef; |
||
661 | } |
||
662 | } |
||
663 | |||
664 | const struct lp_build_tgsi_action sqrt_action = { |
||
665 | scalar_unary_fetch_args, /* fetch_args */ |
||
666 | sqrt_emit /* emit */ |
||
667 | }; |
||
668 | |||
669 | /* TGSI_OPCODE_SCS */ |
||
670 | static void |
||
671 | scs_emit( |
||
672 | const struct lp_build_tgsi_action * action, |
||
673 | struct lp_build_tgsi_context * bld_base, |
||
674 | struct lp_build_emit_data * emit_data) |
||
675 | { |
||
676 | /* dst.x */ |
||
677 | emit_data->output[TGSI_CHAN_X] = lp_build_emit_llvm_unary(bld_base, |
||
678 | TGSI_OPCODE_COS, emit_data->args[0]); |
||
679 | /* dst.y */ |
||
680 | emit_data->output[TGSI_CHAN_Y] = lp_build_emit_llvm_unary(bld_base, |
||
681 | TGSI_OPCODE_SIN, emit_data->args[0]); |
||
682 | /* dst.z */ |
||
683 | emit_data->output[TGSI_CHAN_Z] = bld_base->base.zero; |
||
684 | |||
685 | /* dst.w */ |
||
686 | emit_data->output[TGSI_CHAN_W] = bld_base->base.one; |
||
687 | } |
||
688 | |||
689 | const struct lp_build_tgsi_action scs_action = { |
||
690 | scalar_unary_fetch_args, /* fetch_args */ |
||
691 | scs_emit /* emit */ |
||
692 | }; |
||
693 | |||
694 | /* TGSI_OPCODE_SFL */ |
||
695 | |||
696 | static void |
||
697 | sfl_emit( |
||
698 | const struct lp_build_tgsi_action * action, |
||
699 | struct lp_build_tgsi_context * bld_base, |
||
700 | struct lp_build_emit_data * emit_data) |
||
701 | { |
||
702 | emit_data->output[emit_data->chan] = bld_base->base.zero; |
||
703 | } |
||
704 | |||
705 | /* TGSI_OPCODE_STR */ |
||
706 | |||
707 | static void |
||
708 | str_emit( |
||
709 | const struct lp_build_tgsi_action * action, |
||
710 | struct lp_build_tgsi_context * bld_base, |
||
711 | struct lp_build_emit_data * emit_data) |
||
712 | { |
||
713 | emit_data->output[emit_data->chan] = bld_base->base.one; |
||
714 | } |
||
715 | |||
716 | /* TGSI_OPCODE_SUB */ |
||
717 | static void |
||
718 | sub_emit( |
||
719 | const struct lp_build_tgsi_action * action, |
||
720 | struct lp_build_tgsi_context * bld_base, |
||
721 | struct lp_build_emit_data * emit_data) |
||
722 | { |
||
723 | emit_data->output[emit_data->chan] = LLVMBuildFSub( |
||
724 | bld_base->base.gallivm->builder, |
||
725 | emit_data->args[0], |
||
726 | emit_data->args[1], ""); |
||
727 | } |
||
728 | |||
729 | /* TGSI_OPCODE_U2F */ |
||
730 | static void |
||
731 | u2f_emit( |
||
732 | const struct lp_build_tgsi_action * action, |
||
733 | struct lp_build_tgsi_context * bld_base, |
||
734 | struct lp_build_emit_data * emit_data) |
||
735 | { |
||
736 | emit_data->output[emit_data->chan] = LLVMBuildUIToFP(bld_base->base.gallivm->builder, |
||
737 | emit_data->args[0], |
||
738 | bld_base->base.vec_type, ""); |
||
739 | } |
||
740 | |||
741 | static void |
||
742 | umad_emit( |
||
743 | const struct lp_build_tgsi_action * action, |
||
744 | struct lp_build_tgsi_context * bld_base, |
||
745 | struct lp_build_emit_data * emit_data) |
||
746 | { |
||
747 | LLVMValueRef tmp; |
||
748 | tmp = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_UMUL, |
||
749 | emit_data->args[0], |
||
750 | emit_data->args[1]); |
||
751 | emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base, |
||
752 | TGSI_OPCODE_UADD, tmp, emit_data->args[2]); |
||
753 | } |
||
754 | |||
755 | /* TGSI_OPCODE_UMUL */ |
||
756 | static void |
||
757 | umul_emit( |
||
758 | const struct lp_build_tgsi_action * action, |
||
759 | struct lp_build_tgsi_context * bld_base, |
||
760 | struct lp_build_emit_data * emit_data) |
||
761 | { |
||
762 | emit_data->output[emit_data->chan] = lp_build_mul(&bld_base->uint_bld, |
||
763 | emit_data->args[0], emit_data->args[1]); |
||
764 | } |
||
765 | |||
766 | /* TGSI_OPCODE_MAX */ |
||
767 | static void fmax_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 | LLVMBuilderRef builder = bld_base->base.gallivm->builder; |
||
773 | emit_data->output[emit_data->chan] = LLVMBuildSelect(builder, |
||
774 | LLVMBuildFCmp(builder, LLVMRealUGE, |
||
775 | emit_data->args[0], emit_data->args[1], ""), |
||
776 | emit_data->args[0], emit_data->args[1], ""); |
||
777 | } |
||
778 | |||
779 | /* TGSI_OPCODE_MIN */ |
||
780 | static void fmin_emit( |
||
781 | const struct lp_build_tgsi_action * action, |
||
782 | struct lp_build_tgsi_context * bld_base, |
||
783 | struct lp_build_emit_data * emit_data) |
||
784 | { |
||
785 | LLVMBuilderRef builder = bld_base->base.gallivm->builder; |
||
786 | emit_data->output[emit_data->chan] = LLVMBuildSelect(builder, |
||
787 | LLVMBuildFCmp(builder, LLVMRealUGE, |
||
788 | emit_data->args[0], emit_data->args[1], ""), |
||
789 | emit_data->args[1], emit_data->args[0], ""); |
||
790 | } |
||
791 | |||
792 | /* TGSI_OPCODE_XPD */ |
||
793 | |||
794 | static void |
||
795 | xpd_fetch_args( |
||
796 | struct lp_build_tgsi_context * bld_base, |
||
797 | struct lp_build_emit_data * emit_data) |
||
798 | { |
||
799 | dp_fetch_args(bld_base, emit_data, 3); |
||
800 | } |
||
801 | |||
802 | /** |
||
803 | * (a * b) - (c * d) |
||
804 | */ |
||
805 | static LLVMValueRef |
||
806 | xpd_helper( |
||
807 | struct lp_build_tgsi_context * bld_base, |
||
808 | LLVMValueRef a, |
||
809 | LLVMValueRef b, |
||
810 | LLVMValueRef c, |
||
811 | LLVMValueRef d) |
||
812 | { |
||
813 | LLVMValueRef tmp0, tmp1; |
||
814 | |||
815 | tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, a, b); |
||
816 | tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, c, d); |
||
817 | |||
818 | return lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_SUB, tmp0, tmp1); |
||
819 | } |
||
820 | |||
821 | static void |
||
822 | xpd_emit( |
||
823 | const struct lp_build_tgsi_action * action, |
||
824 | struct lp_build_tgsi_context * bld_base, |
||
825 | struct lp_build_emit_data * emit_data) |
||
826 | { |
||
827 | emit_data->output[TGSI_CHAN_X] = xpd_helper(bld_base, |
||
828 | emit_data->args[1] /* src0.y */, emit_data->args[5] /* src1.z */, |
||
829 | emit_data->args[4] /* src1.y */, emit_data->args[2] /* src0.z */); |
||
830 | |||
831 | emit_data->output[TGSI_CHAN_Y] = xpd_helper(bld_base, |
||
832 | emit_data->args[2] /* src0.z */, emit_data->args[3] /* src1.x */, |
||
833 | emit_data->args[5] /* src1.z */, emit_data->args[0] /* src0.x */); |
||
834 | |||
835 | emit_data->output[TGSI_CHAN_Z] = xpd_helper(bld_base, |
||
836 | emit_data->args[0] /* src0.x */, emit_data->args[4] /* src1.y */, |
||
837 | emit_data->args[3] /* src1.x */, emit_data->args[1] /* src0.y */); |
||
838 | |||
839 | emit_data->output[TGSI_CHAN_W] = bld_base->base.one; |
||
840 | } |
||
841 | |||
842 | const struct lp_build_tgsi_action xpd_action = { |
||
843 | xpd_fetch_args, /* fetch_args */ |
||
844 | xpd_emit /* emit */ |
||
845 | }; |
||
846 | |||
847 | void |
||
848 | lp_set_default_actions(struct lp_build_tgsi_context * bld_base) |
||
849 | { |
||
850 | bld_base->op_actions[TGSI_OPCODE_DP2] = dp2_action; |
||
851 | bld_base->op_actions[TGSI_OPCODE_DP3] = dp3_action; |
||
852 | bld_base->op_actions[TGSI_OPCODE_DP4] = dp4_action; |
||
853 | bld_base->op_actions[TGSI_OPCODE_DP2A] = dp2a_action; |
||
854 | bld_base->op_actions[TGSI_OPCODE_DPH] = dph_action; |
||
855 | bld_base->op_actions[TGSI_OPCODE_DST] = dst_action; |
||
856 | bld_base->op_actions[TGSI_OPCODE_EXP] = exp_action; |
||
857 | bld_base->op_actions[TGSI_OPCODE_LIT] = lit_action; |
||
858 | bld_base->op_actions[TGSI_OPCODE_LOG] = log_action; |
||
859 | bld_base->op_actions[TGSI_OPCODE_RSQ] = rsq_action; |
||
860 | bld_base->op_actions[TGSI_OPCODE_SQRT] = sqrt_action; |
||
861 | bld_base->op_actions[TGSI_OPCODE_POW] = pow_action; |
||
862 | bld_base->op_actions[TGSI_OPCODE_SCS] = scs_action; |
||
863 | bld_base->op_actions[TGSI_OPCODE_XPD] = xpd_action; |
||
864 | |||
865 | bld_base->op_actions[TGSI_OPCODE_BREAKC].fetch_args = scalar_unary_fetch_args; |
||
866 | bld_base->op_actions[TGSI_OPCODE_SWITCH].fetch_args = scalar_unary_fetch_args; |
||
867 | bld_base->op_actions[TGSI_OPCODE_CASE].fetch_args = scalar_unary_fetch_args; |
||
868 | bld_base->op_actions[TGSI_OPCODE_COS].fetch_args = scalar_unary_fetch_args; |
||
869 | bld_base->op_actions[TGSI_OPCODE_EX2].fetch_args = scalar_unary_fetch_args; |
||
870 | bld_base->op_actions[TGSI_OPCODE_IF].fetch_args = scalar_unary_fetch_args; |
||
871 | bld_base->op_actions[TGSI_OPCODE_UIF].fetch_args = scalar_unary_fetch_args; |
||
872 | bld_base->op_actions[TGSI_OPCODE_KILL_IF].fetch_args = kil_fetch_args; |
||
873 | bld_base->op_actions[TGSI_OPCODE_KILL].fetch_args = kilp_fetch_args; |
||
874 | bld_base->op_actions[TGSI_OPCODE_RCP].fetch_args = scalar_unary_fetch_args; |
||
875 | bld_base->op_actions[TGSI_OPCODE_SIN].fetch_args = scalar_unary_fetch_args; |
||
876 | bld_base->op_actions[TGSI_OPCODE_LG2].fetch_args = scalar_unary_fetch_args; |
||
877 | |||
878 | bld_base->op_actions[TGSI_OPCODE_ADD].emit = add_emit; |
||
879 | bld_base->op_actions[TGSI_OPCODE_ARR].emit = arr_emit; |
||
880 | bld_base->op_actions[TGSI_OPCODE_CLAMP].emit = clamp_emit; |
||
881 | bld_base->op_actions[TGSI_OPCODE_END].emit = end_emit; |
||
882 | bld_base->op_actions[TGSI_OPCODE_FRC].emit = frc_emit; |
||
883 | bld_base->op_actions[TGSI_OPCODE_LRP].emit = lrp_emit; |
||
884 | bld_base->op_actions[TGSI_OPCODE_MAD].emit = mad_emit; |
||
885 | bld_base->op_actions[TGSI_OPCODE_MOV].emit = mov_emit; |
||
886 | bld_base->op_actions[TGSI_OPCODE_MUL].emit = mul_emit; |
||
887 | bld_base->op_actions[TGSI_OPCODE_DIV].emit = fdiv_emit; |
||
888 | bld_base->op_actions[TGSI_OPCODE_RCP].emit = rcp_emit; |
||
889 | bld_base->op_actions[TGSI_OPCODE_SFL].emit = sfl_emit; |
||
890 | bld_base->op_actions[TGSI_OPCODE_STR].emit = str_emit; |
||
891 | bld_base->op_actions[TGSI_OPCODE_SUB].emit = sub_emit; |
||
892 | |||
893 | bld_base->op_actions[TGSI_OPCODE_UARL].emit = mov_emit; |
||
894 | bld_base->op_actions[TGSI_OPCODE_U2F].emit = u2f_emit; |
||
895 | bld_base->op_actions[TGSI_OPCODE_UMAD].emit = umad_emit; |
||
896 | bld_base->op_actions[TGSI_OPCODE_UMUL].emit = umul_emit; |
||
897 | |||
898 | bld_base->op_actions[TGSI_OPCODE_MAX].emit = fmax_emit; |
||
899 | bld_base->op_actions[TGSI_OPCODE_MIN].emit = fmin_emit; |
||
900 | } |
||
901 | |||
902 | /* CPU Only default actions */ |
||
903 | |||
904 | /* These actions are CPU only, because they could potentially output SSE |
||
905 | * intrinsics. |
||
906 | */ |
||
907 | |||
908 | /* TGSI_OPCODE_ABS (CPU Only)*/ |
||
909 | |||
910 | static void |
||
911 | abs_emit_cpu( |
||
912 | const struct lp_build_tgsi_action * action, |
||
913 | struct lp_build_tgsi_context * bld_base, |
||
914 | struct lp_build_emit_data * emit_data) |
||
915 | { |
||
916 | emit_data->output[emit_data->chan] = lp_build_abs(&bld_base->base, |
||
917 | emit_data->args[0]); |
||
918 | } |
||
919 | |||
920 | /* TGSI_OPCODE_ADD (CPU Only) */ |
||
921 | static void |
||
922 | add_emit_cpu( |
||
923 | const struct lp_build_tgsi_action * action, |
||
924 | struct lp_build_tgsi_context * bld_base, |
||
925 | struct lp_build_emit_data * emit_data) |
||
926 | { |
||
927 | emit_data->output[emit_data->chan] = lp_build_add(&bld_base->base, |
||
928 | emit_data->args[0], emit_data->args[1]); |
||
929 | } |
||
930 | |||
931 | /* TGSI_OPCODE_AND (CPU Only) */ |
||
932 | static void |
||
933 | and_emit_cpu( |
||
934 | const struct lp_build_tgsi_action * action, |
||
935 | struct lp_build_tgsi_context * bld_base, |
||
936 | struct lp_build_emit_data * emit_data) |
||
937 | { |
||
938 | emit_data->output[emit_data->chan] = lp_build_and(&bld_base->uint_bld, |
||
939 | emit_data->args[0], emit_data->args[1]); |
||
940 | } |
||
941 | |||
942 | /* TGSI_OPCODE_ARL (CPU Only) */ |
||
943 | static void |
||
944 | arl_emit_cpu( |
||
945 | const struct lp_build_tgsi_action * action, |
||
946 | struct lp_build_tgsi_context * bld_base, |
||
947 | struct lp_build_emit_data * emit_data) |
||
948 | { |
||
949 | LLVMValueRef tmp; |
||
950 | tmp = lp_build_floor(&bld_base->base, |
||
951 | emit_data->args[0]); |
||
952 | emit_data->output[emit_data->chan] = LLVMBuildFPToSI(bld_base->base.gallivm->builder, tmp, |
||
953 | bld_base->uint_bld.vec_type, ""); |
||
954 | } |
||
955 | |||
956 | /* TGSI_OPCODE_ARR (CPU Only) */ |
||
957 | static void |
||
958 | arr_emit_cpu( |
||
959 | const struct lp_build_tgsi_action * action, |
||
960 | struct lp_build_tgsi_context * bld_base, |
||
961 | struct lp_build_emit_data * emit_data) |
||
962 | { |
||
963 | emit_data->output[emit_data->chan] = lp_build_iround(&bld_base->base, emit_data->args[0]); |
||
964 | } |
||
965 | |||
966 | /* TGSI_OPCODE_CEIL (CPU Only) */ |
||
967 | static void |
||
968 | ceil_emit_cpu( |
||
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 | emit_data->output[emit_data->chan] = lp_build_ceil(&bld_base->base, |
||
974 | emit_data->args[0]); |
||
975 | } |
||
976 | |||
977 | /* TGSI_OPCODE_CMP (CPU Only) */ |
||
978 | static void |
||
979 | cmp_emit_cpu( |
||
980 | const struct lp_build_tgsi_action * action, |
||
981 | struct lp_build_tgsi_context * bld_base, |
||
982 | struct lp_build_emit_data * emit_data) |
||
983 | { |
||
984 | LLVMValueRef cond = lp_build_cmp(&bld_base->base, PIPE_FUNC_LESS, |
||
985 | emit_data->args[0], bld_base->base.zero); |
||
986 | emit_data->output[emit_data->chan] = lp_build_select(&bld_base->base, |
||
987 | cond, emit_data->args[1], emit_data->args[2]); |
||
988 | } |
||
989 | |||
990 | /* TGSI_OPCODE_UCMP (CPU Only) */ |
||
991 | static void |
||
992 | ucmp_emit_cpu( |
||
993 | const struct lp_build_tgsi_action * action, |
||
994 | struct lp_build_tgsi_context * bld_base, |
||
995 | struct lp_build_emit_data * emit_data) |
||
996 | { |
||
997 | LLVMBuilderRef builder = bld_base->base.gallivm->builder; |
||
998 | struct lp_build_context *uint_bld = &bld_base->uint_bld; |
||
999 | LLVMValueRef unsigned_cond = |
||
1000 | LLVMBuildBitCast(builder, emit_data->args[0], uint_bld->vec_type, ""); |
||
1001 | LLVMValueRef cond = lp_build_cmp(uint_bld, PIPE_FUNC_NOTEQUAL, |
||
1002 | unsigned_cond, |
||
1003 | uint_bld->zero); |
||
1004 | emit_data->output[emit_data->chan] = |
||
1005 | lp_build_select(&bld_base->base, |
||
1006 | cond, emit_data->args[1], emit_data->args[2]); |
||
1007 | } |
||
1008 | |||
1009 | |||
1010 | /* TGSI_OPCODE_CND (CPU Only) */ |
||
1011 | static void |
||
1012 | cnd_emit_cpu( |
||
1013 | const struct lp_build_tgsi_action * action, |
||
1014 | struct lp_build_tgsi_context * bld_base, |
||
1015 | struct lp_build_emit_data * emit_data) |
||
1016 | { |
||
1017 | LLVMValueRef half, tmp; |
||
1018 | half = lp_build_const_vec(bld_base->base.gallivm, bld_base->base.type, 0.5); |
||
1019 | tmp = lp_build_cmp(&bld_base->base, PIPE_FUNC_GREATER, |
||
1020 | emit_data->args[2], half); |
||
1021 | emit_data->output[emit_data->chan] = lp_build_select(&bld_base->base, |
||
1022 | tmp, |
||
1023 | emit_data->args[0], |
||
1024 | emit_data->args[1]); |
||
1025 | } |
||
1026 | |||
1027 | /* TGSI_OPCODE_COS (CPU Only) */ |
||
1028 | static void |
||
1029 | cos_emit_cpu( |
||
1030 | const struct lp_build_tgsi_action * action, |
||
1031 | struct lp_build_tgsi_context * bld_base, |
||
1032 | struct lp_build_emit_data * emit_data) |
||
1033 | { |
||
1034 | emit_data->output[emit_data->chan] = lp_build_cos(&bld_base->base, |
||
1035 | emit_data->args[0]); |
||
1036 | } |
||
1037 | |||
1038 | /* TGSI_OPCODE_DIV (CPU Only) */ |
||
1039 | static void |
||
1040 | div_emit_cpu( |
||
1041 | const struct lp_build_tgsi_action * action, |
||
1042 | struct lp_build_tgsi_context * bld_base, |
||
1043 | struct lp_build_emit_data * emit_data) |
||
1044 | { |
||
1045 | emit_data->output[emit_data->chan] = lp_build_div(&bld_base->base, |
||
1046 | emit_data->args[0], emit_data->args[1]); |
||
1047 | } |
||
1048 | |||
1049 | /* TGSI_OPCODE_EX2 (CPU Only) */ |
||
1050 | static void |
||
1051 | ex2_emit_cpu( |
||
1052 | const struct lp_build_tgsi_action * action, |
||
1053 | struct lp_build_tgsi_context * bld_base, |
||
1054 | struct lp_build_emit_data * emit_data) |
||
1055 | { |
||
1056 | emit_data->output[emit_data->chan] = lp_build_exp2(&bld_base->base, |
||
1057 | emit_data->args[0]); |
||
1058 | } |
||
1059 | |||
1060 | /* TGSI_OPCODE_EXP (CPU Only) */ |
||
1061 | static void |
||
1062 | exp_emit_cpu( |
||
1063 | const struct lp_build_tgsi_action * action, |
||
1064 | struct lp_build_tgsi_context * bld_base, |
||
1065 | struct lp_build_emit_data * emit_data) |
||
1066 | { |
||
1067 | lp_build_exp2_approx(&bld_base->base, emit_data->args[0], |
||
1068 | &emit_data->output[TGSI_CHAN_X], |
||
1069 | &emit_data->output[TGSI_CHAN_Y], |
||
1070 | &emit_data->output[TGSI_CHAN_Z]); |
||
1071 | emit_data->output[TGSI_CHAN_W] = bld_base->base.one; |
||
1072 | } |
||
1073 | |||
1074 | /* TGSI_OPCODE_F2I (CPU Only) */ |
||
1075 | static void |
||
1076 | f2i_emit_cpu( |
||
1077 | const struct lp_build_tgsi_action * action, |
||
1078 | struct lp_build_tgsi_context * bld_base, |
||
1079 | struct lp_build_emit_data * emit_data) |
||
1080 | { |
||
1081 | emit_data->output[emit_data->chan] = lp_build_itrunc(&bld_base->base, |
||
1082 | emit_data->args[0]); |
||
1083 | } |
||
1084 | |||
1085 | /* TGSI_OPCODE_F2U (CPU Only) */ |
||
1086 | static void |
||
1087 | f2u_emit_cpu( |
||
1088 | const struct lp_build_tgsi_action * action, |
||
1089 | struct lp_build_tgsi_context * bld_base, |
||
1090 | struct lp_build_emit_data * emit_data) |
||
1091 | { |
||
1092 | /* FIXME: implement and use lp_build_utrunc() */ |
||
1093 | emit_data->output[emit_data->chan] = lp_build_itrunc(&bld_base->base, |
||
1094 | emit_data->args[0]); |
||
1095 | } |
||
1096 | |||
1097 | /* TGSI_OPCODE_FLR (CPU Only) */ |
||
1098 | |||
1099 | static void |
||
1100 | flr_emit_cpu( |
||
1101 | const struct lp_build_tgsi_action * action, |
||
1102 | struct lp_build_tgsi_context * bld_base, |
||
1103 | struct lp_build_emit_data * emit_data) |
||
1104 | { |
||
1105 | emit_data->output[emit_data->chan] = lp_build_floor(&bld_base->base, |
||
1106 | emit_data->args[0]); |
||
1107 | } |
||
1108 | |||
1109 | /* TGSI_OPCODE_I2F (CPU Only) */ |
||
1110 | static void |
||
1111 | i2f_emit_cpu( |
||
1112 | const struct lp_build_tgsi_action * action, |
||
1113 | struct lp_build_tgsi_context * bld_base, |
||
1114 | struct lp_build_emit_data * emit_data) |
||
1115 | { |
||
1116 | emit_data->output[emit_data->chan] = lp_build_int_to_float(&bld_base->base, |
||
1117 | emit_data->args[0]); |
||
1118 | } |
||
1119 | |||
1120 | /* TGSI_OPCODE_IABS (CPU Only) */ |
||
1121 | static void |
||
1122 | iabs_emit_cpu( |
||
1123 | const struct lp_build_tgsi_action * action, |
||
1124 | struct lp_build_tgsi_context * bld_base, |
||
1125 | struct lp_build_emit_data * emit_data) |
||
1126 | { |
||
1127 | emit_data->output[emit_data->chan] = lp_build_abs(&bld_base->int_bld, |
||
1128 | emit_data->args[0]); |
||
1129 | } |
||
1130 | |||
1131 | /* TGSI_OPCODE_IDIV (CPU Only) */ |
||
1132 | static void |
||
1133 | idiv_emit_cpu( |
||
1134 | const struct lp_build_tgsi_action * action, |
||
1135 | struct lp_build_tgsi_context * bld_base, |
||
1136 | struct lp_build_emit_data * emit_data) |
||
1137 | { |
||
1138 | emit_data->output[emit_data->chan] = lp_build_div(&bld_base->int_bld, |
||
1139 | emit_data->args[0], emit_data->args[1]); |
||
1140 | } |
||
1141 | |||
1142 | /* TGSI_OPCODE_INEG (CPU Only) */ |
||
1143 | static void |
||
1144 | ineg_emit_cpu( |
||
1145 | const struct lp_build_tgsi_action * action, |
||
1146 | struct lp_build_tgsi_context * bld_base, |
||
1147 | struct lp_build_emit_data * emit_data) |
||
1148 | { |
||
1149 | emit_data->output[emit_data->chan] = lp_build_sub(&bld_base->int_bld, |
||
1150 | bld_base->int_bld.zero, |
||
1151 | emit_data->args[0]); |
||
1152 | } |
||
1153 | |||
1154 | /* TGSI_OPCODE_ISET Helper (CPU Only) */ |
||
1155 | static void |
||
1156 | iset_emit_cpu( |
||
1157 | const struct lp_build_tgsi_action * action, |
||
1158 | struct lp_build_tgsi_context * bld_base, |
||
1159 | struct lp_build_emit_data * emit_data, |
||
1160 | unsigned pipe_func) |
||
1161 | { |
||
1162 | LLVMValueRef cond = lp_build_cmp(&bld_base->int_bld, pipe_func, |
||
1163 | emit_data->args[0], emit_data->args[1]); |
||
1164 | emit_data->output[emit_data->chan] = cond; |
||
1165 | } |
||
1166 | |||
1167 | /* TGSI_OPCODE_IMAX (CPU Only) */ |
||
1168 | static void |
||
1169 | imax_emit_cpu( |
||
1170 | const struct lp_build_tgsi_action * action, |
||
1171 | struct lp_build_tgsi_context * bld_base, |
||
1172 | struct lp_build_emit_data * emit_data) |
||
1173 | { |
||
1174 | emit_data->output[emit_data->chan] = lp_build_max(&bld_base->int_bld, |
||
1175 | emit_data->args[0], emit_data->args[1]); |
||
1176 | } |
||
1177 | |||
1178 | /* TGSI_OPCODE_IMIN (CPU Only) */ |
||
1179 | static void |
||
1180 | imin_emit_cpu( |
||
1181 | const struct lp_build_tgsi_action * action, |
||
1182 | struct lp_build_tgsi_context * bld_base, |
||
1183 | struct lp_build_emit_data * emit_data) |
||
1184 | { |
||
1185 | emit_data->output[emit_data->chan] = lp_build_min(&bld_base->int_bld, |
||
1186 | emit_data->args[0], emit_data->args[1]); |
||
1187 | } |
||
1188 | |||
1189 | /* TGSI_OPCODE_ISGE (CPU Only) */ |
||
1190 | static void |
||
1191 | isge_emit_cpu( |
||
1192 | const struct lp_build_tgsi_action * action, |
||
1193 | struct lp_build_tgsi_context * bld_base, |
||
1194 | struct lp_build_emit_data * emit_data) |
||
1195 | { |
||
1196 | iset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_GEQUAL); |
||
1197 | } |
||
1198 | |||
1199 | /* TGSI_OPCODE_ISHR (CPU Only) */ |
||
1200 | static void |
||
1201 | ishr_emit_cpu( |
||
1202 | const struct lp_build_tgsi_action * action, |
||
1203 | struct lp_build_tgsi_context * bld_base, |
||
1204 | struct lp_build_emit_data * emit_data) |
||
1205 | { |
||
1206 | emit_data->output[emit_data->chan] = lp_build_shr(&bld_base->int_bld, |
||
1207 | emit_data->args[0], emit_data->args[1]); |
||
1208 | } |
||
1209 | |||
1210 | /* TGSI_OPCODE_ISLT (CPU Only) */ |
||
1211 | static void |
||
1212 | islt_emit_cpu( |
||
1213 | const struct lp_build_tgsi_action * action, |
||
1214 | struct lp_build_tgsi_context * bld_base, |
||
1215 | struct lp_build_emit_data * emit_data) |
||
1216 | { |
||
1217 | iset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_LESS); |
||
1218 | } |
||
1219 | |||
1220 | |||
1221 | /* TGSI_OPCODE_ISSG (CPU Only) */ |
||
1222 | static void |
||
1223 | issg_emit_cpu( |
||
1224 | const struct lp_build_tgsi_action * action, |
||
1225 | struct lp_build_tgsi_context * bld_base, |
||
1226 | struct lp_build_emit_data * emit_data) |
||
1227 | { |
||
1228 | emit_data->output[emit_data->chan] = lp_build_sgn(&bld_base->int_bld, |
||
1229 | emit_data->args[0]); |
||
1230 | } |
||
1231 | |||
1232 | /* TGSI_OPCODE_LG2 (CPU Only) */ |
||
1233 | static void |
||
1234 | lg2_emit_cpu( |
||
1235 | const struct lp_build_tgsi_action * action, |
||
1236 | struct lp_build_tgsi_context * bld_base, |
||
1237 | struct lp_build_emit_data * emit_data) |
||
1238 | { |
||
1239 | emit_data->output[emit_data->chan] = lp_build_log2(&bld_base->base, |
||
1240 | emit_data->args[0]); |
||
1241 | } |
||
1242 | |||
1243 | /* TGSI_OPCODE_LOG (CPU Only) */ |
||
1244 | static void |
||
1245 | log_emit_cpu( |
||
1246 | const struct lp_build_tgsi_action * action, |
||
1247 | struct lp_build_tgsi_context * bld_base, |
||
1248 | struct lp_build_emit_data * emit_data) |
||
1249 | { |
||
1250 | LLVMValueRef p_floor_log2; |
||
1251 | LLVMValueRef p_exp; |
||
1252 | LLVMValueRef p_log2; |
||
1253 | LLVMValueRef src0 = emit_data->args[0]; |
||
1254 | |||
1255 | lp_build_log2_approx(&bld_base->base, src0, |
||
1256 | &p_exp, &p_floor_log2, &p_log2); |
||
1257 | |||
1258 | emit_data->output[TGSI_CHAN_X] = p_floor_log2; |
||
1259 | |||
1260 | emit_data->output[TGSI_CHAN_Y] = lp_build_emit_llvm_binary(bld_base, |
||
1261 | TGSI_OPCODE_DIV, |
||
1262 | src0, p_exp); |
||
1263 | emit_data->output[TGSI_CHAN_Z] = p_log2; |
||
1264 | |||
1265 | emit_data->output[TGSI_CHAN_W] = bld_base->base.one; |
||
1266 | |||
1267 | } |
||
1268 | |||
1269 | /* TGSI_OPCODE_MAX (CPU Only) */ |
||
1270 | |||
1271 | static void |
||
1272 | max_emit_cpu( |
||
1273 | const struct lp_build_tgsi_action * action, |
||
1274 | struct lp_build_tgsi_context * bld_base, |
||
1275 | struct lp_build_emit_data * emit_data) |
||
1276 | { |
||
1277 | emit_data->output[emit_data->chan] = lp_build_max(&bld_base->base, |
||
1278 | emit_data->args[0], emit_data->args[1]); |
||
1279 | } |
||
1280 | |||
1281 | /* TGSI_OPCODE_MIN (CPU Only) */ |
||
1282 | static void |
||
1283 | min_emit_cpu( |
||
1284 | const struct lp_build_tgsi_action * action, |
||
1285 | struct lp_build_tgsi_context * bld_base, |
||
1286 | struct lp_build_emit_data * emit_data) |
||
1287 | { |
||
1288 | emit_data->output[emit_data->chan] = lp_build_min(&bld_base->base, |
||
1289 | emit_data->args[0], emit_data->args[1]); |
||
1290 | } |
||
1291 | |||
1292 | /* TGSI_OPCODE_MOD (CPU Only) */ |
||
1293 | static void |
||
1294 | mod_emit_cpu( |
||
1295 | const struct lp_build_tgsi_action * action, |
||
1296 | struct lp_build_tgsi_context * bld_base, |
||
1297 | struct lp_build_emit_data * emit_data) |
||
1298 | { |
||
1299 | emit_data->output[emit_data->chan] = lp_build_mod(&bld_base->int_bld, |
||
1300 | emit_data->args[0], emit_data->args[1]); |
||
1301 | } |
||
1302 | |||
1303 | /* TGSI_OPCODE_NOT */ |
||
1304 | static void |
||
1305 | not_emit_cpu( |
||
1306 | const struct lp_build_tgsi_action * action, |
||
1307 | struct lp_build_tgsi_context * bld_base, |
||
1308 | struct lp_build_emit_data * emit_data) |
||
1309 | { |
||
1310 | emit_data->output[emit_data->chan] = lp_build_not(&bld_base->uint_bld, |
||
1311 | emit_data->args[0]); |
||
1312 | } |
||
1313 | |||
1314 | /* TGSI_OPCODE_OR (CPU Only) */ |
||
1315 | static void |
||
1316 | or_emit_cpu( |
||
1317 | const struct lp_build_tgsi_action * action, |
||
1318 | struct lp_build_tgsi_context * bld_base, |
||
1319 | struct lp_build_emit_data * emit_data) |
||
1320 | { |
||
1321 | emit_data->output[emit_data->chan] = lp_build_or(&bld_base->uint_bld, |
||
1322 | emit_data->args[0], emit_data->args[1]); |
||
1323 | } |
||
1324 | |||
1325 | /* TGSI_OPCODE_POW (CPU Only) */ |
||
1326 | static void |
||
1327 | pow_emit_cpu( |
||
1328 | const struct lp_build_tgsi_action * action, |
||
1329 | struct lp_build_tgsi_context * bld_base, |
||
1330 | struct lp_build_emit_data * emit_data) |
||
1331 | { |
||
1332 | emit_data->output[emit_data->chan] = lp_build_pow(&bld_base->base, |
||
1333 | emit_data->args[0], emit_data->args[1]); |
||
1334 | } |
||
1335 | |||
1336 | |||
1337 | /* TGSI_OPCODE_RCP (CPU Only) */ |
||
1338 | |||
1339 | static void |
||
1340 | rcp_emit_cpu( |
||
1341 | const struct lp_build_tgsi_action * action, |
||
1342 | struct lp_build_tgsi_context * bld_base, |
||
1343 | struct lp_build_emit_data * emit_data) |
||
1344 | { |
||
1345 | emit_data->output[emit_data->chan] = lp_build_rcp(&bld_base->base, |
||
1346 | emit_data->args[0]); |
||
1347 | } |
||
1348 | |||
1349 | /* Reciprical squareroot (CPU Only) */ |
||
1350 | static void |
||
1351 | recip_sqrt_emit_cpu( |
||
1352 | const struct lp_build_tgsi_action * action, |
||
1353 | struct lp_build_tgsi_context * bld_base, |
||
1354 | struct lp_build_emit_data * emit_data) |
||
1355 | { |
||
1356 | emit_data->output[emit_data->chan] = lp_build_rsqrt(&bld_base->base, |
||
1357 | emit_data->args[0]); |
||
1358 | } |
||
1359 | |||
1360 | static void |
||
1361 | sqrt_emit_cpu( |
||
1362 | const struct lp_build_tgsi_action * action, |
||
1363 | struct lp_build_tgsi_context * bld_base, |
||
1364 | struct lp_build_emit_data * emit_data) |
||
1365 | { |
||
1366 | emit_data->output[emit_data->chan] = lp_build_sqrt(&bld_base->base, |
||
1367 | emit_data->args[0]); |
||
1368 | } |
||
1369 | |||
1370 | |||
1371 | /* TGSI_OPCODE_ROUND (CPU Only) */ |
||
1372 | static void |
||
1373 | round_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_round(&bld_base->base, |
||
1379 | emit_data->args[0]); |
||
1380 | } |
||
1381 | |||
1382 | /* TGSI_OPCODE_SET Helper (CPU Only) */ |
||
1383 | |||
1384 | static void |
||
1385 | set_emit_cpu( |
||
1386 | const struct lp_build_tgsi_action * action, |
||
1387 | struct lp_build_tgsi_context * bld_base, |
||
1388 | struct lp_build_emit_data * emit_data, |
||
1389 | unsigned pipe_func) |
||
1390 | { |
||
1391 | LLVMValueRef cond = lp_build_cmp(&bld_base->base, pipe_func, |
||
1392 | emit_data->args[0], emit_data->args[1]); |
||
1393 | emit_data->output[emit_data->chan] = lp_build_select(&bld_base->base, |
||
1394 | cond, |
||
1395 | bld_base->base.one, |
||
1396 | bld_base->base.zero); |
||
1397 | } |
||
1398 | |||
1399 | /* TGSI_OPCODE_SEQ (CPU Only) */ |
||
1400 | |||
1401 | static void |
||
1402 | seq_emit_cpu( |
||
1403 | const struct lp_build_tgsi_action * action, |
||
1404 | struct lp_build_tgsi_context * bld_base, |
||
1405 | struct lp_build_emit_data * emit_data) |
||
1406 | { |
||
1407 | set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_EQUAL); |
||
1408 | } |
||
1409 | |||
1410 | /* TGSI_OPCODE_SGE (CPU Only) */ |
||
1411 | static void |
||
1412 | sge_emit_cpu( |
||
1413 | const struct lp_build_tgsi_action * action, |
||
1414 | struct lp_build_tgsi_context * bld_base, |
||
1415 | struct lp_build_emit_data * emit_data) |
||
1416 | { |
||
1417 | set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_GEQUAL); |
||
1418 | } |
||
1419 | |||
1420 | /* TGSI_OPCODE_SGT (CPU Only)*/ |
||
1421 | |||
1422 | static void |
||
1423 | sgt_emit_cpu( |
||
1424 | const struct lp_build_tgsi_action * action, |
||
1425 | struct lp_build_tgsi_context * bld_base, |
||
1426 | struct lp_build_emit_data * emit_data) |
||
1427 | { |
||
1428 | set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_GREATER); |
||
1429 | } |
||
1430 | |||
1431 | /* TGSI_OPCODE_SHL (CPU Only) */ |
||
1432 | static void |
||
1433 | shl_emit_cpu( |
||
1434 | const struct lp_build_tgsi_action * action, |
||
1435 | struct lp_build_tgsi_context * bld_base, |
||
1436 | struct lp_build_emit_data * emit_data) |
||
1437 | { |
||
1438 | emit_data->output[emit_data->chan] = lp_build_shl(&bld_base->uint_bld, |
||
1439 | emit_data->args[0], emit_data->args[1]); |
||
1440 | } |
||
1441 | |||
1442 | /* TGSI_OPCODE_SIN (CPU Only) */ |
||
1443 | static void |
||
1444 | sin_emit_cpu( |
||
1445 | const struct lp_build_tgsi_action * action, |
||
1446 | struct lp_build_tgsi_context * bld_base, |
||
1447 | struct lp_build_emit_data * emit_data) |
||
1448 | { |
||
1449 | emit_data->output[emit_data->chan] = lp_build_sin(&bld_base->base, |
||
1450 | emit_data->args[0]); |
||
1451 | } |
||
1452 | |||
1453 | /* TGSI_OPCODE_SLE (CPU Only) */ |
||
1454 | static void |
||
1455 | sle_emit_cpu( |
||
1456 | const struct lp_build_tgsi_action * action, |
||
1457 | struct lp_build_tgsi_context * bld_base, |
||
1458 | struct lp_build_emit_data * emit_data) |
||
1459 | { |
||
1460 | set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_LEQUAL); |
||
1461 | } |
||
1462 | |||
1463 | /* TGSI_OPCODE_SLT (CPU Only) */ |
||
1464 | static void |
||
1465 | slt_emit_cpu( |
||
1466 | const struct lp_build_tgsi_action * action, |
||
1467 | struct lp_build_tgsi_context * bld_base, |
||
1468 | struct lp_build_emit_data * emit_data) |
||
1469 | { |
||
1470 | set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_LESS); |
||
1471 | } |
||
1472 | |||
1473 | /* TGSI_OPCODE_SNE (CPU Only) */ |
||
1474 | |||
1475 | static void |
||
1476 | sne_emit_cpu( |
||
1477 | const struct lp_build_tgsi_action * action, |
||
1478 | struct lp_build_tgsi_context * bld_base, |
||
1479 | struct lp_build_emit_data * emit_data) |
||
1480 | { |
||
1481 | set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_NOTEQUAL); |
||
1482 | } |
||
1483 | |||
1484 | /* TGSI_OPCODE_SSG (CPU Only) */ |
||
1485 | |||
1486 | static void |
||
1487 | ssg_emit_cpu( |
||
1488 | const struct lp_build_tgsi_action * action, |
||
1489 | struct lp_build_tgsi_context * bld_base, |
||
1490 | struct lp_build_emit_data * emit_data) |
||
1491 | { |
||
1492 | emit_data->output[emit_data->chan] = lp_build_sgn(&bld_base->base, |
||
1493 | emit_data->args[0]); |
||
1494 | } |
||
1495 | |||
1496 | /* TGSI_OPCODE_SUB (CPU Only) */ |
||
1497 | |||
1498 | static void |
||
1499 | sub_emit_cpu( |
||
1500 | const struct lp_build_tgsi_action * action, |
||
1501 | struct lp_build_tgsi_context * bld_base, |
||
1502 | struct lp_build_emit_data * emit_data) |
||
1503 | { |
||
1504 | emit_data->output[emit_data->chan] = lp_build_sub(&bld_base->base, |
||
1505 | emit_data->args[0], |
||
1506 | emit_data->args[1]); |
||
1507 | } |
||
1508 | |||
1509 | /* TGSI_OPCODE_TRUNC (CPU Only) */ |
||
1510 | |||
1511 | static void |
||
1512 | trunc_emit_cpu( |
||
1513 | const struct lp_build_tgsi_action * action, |
||
1514 | struct lp_build_tgsi_context * bld_base, |
||
1515 | struct lp_build_emit_data * emit_data) |
||
1516 | { |
||
1517 | emit_data->output[emit_data->chan] = lp_build_trunc(&bld_base->base, |
||
1518 | emit_data->args[0]); |
||
1519 | } |
||
1520 | |||
1521 | /* TGSI_OPCODE_UADD (CPU Only) */ |
||
1522 | static void |
||
1523 | uadd_emit_cpu( |
||
1524 | const struct lp_build_tgsi_action * action, |
||
1525 | struct lp_build_tgsi_context * bld_base, |
||
1526 | struct lp_build_emit_data * emit_data) |
||
1527 | { |
||
1528 | emit_data->output[emit_data->chan] = lp_build_add(&bld_base->uint_bld, |
||
1529 | emit_data->args[0], emit_data->args[1]); |
||
1530 | } |
||
1531 | |||
1532 | /* TGSI_OPCODE_UDIV (CPU Only) */ |
||
1533 | static void |
||
1534 | udiv_emit_cpu( |
||
1535 | const struct lp_build_tgsi_action * action, |
||
1536 | struct lp_build_tgsi_context * bld_base, |
||
1537 | struct lp_build_emit_data * emit_data) |
||
1538 | { |
||
1539 | |||
1540 | LLVMBuilderRef builder = bld_base->base.gallivm->builder; |
||
1541 | LLVMValueRef div_mask = lp_build_cmp(&bld_base->uint_bld, |
||
1542 | PIPE_FUNC_EQUAL, emit_data->args[1], |
||
1543 | bld_base->uint_bld.zero); |
||
1544 | /* We want to make sure that we never divide/mod by zero to not |
||
1545 | * generate sigfpe. We don't want to crash just because the |
||
1546 | * shader is doing something weird. */ |
||
1547 | LLVMValueRef divisor = LLVMBuildOr(builder, |
||
1548 | div_mask, |
||
1549 | emit_data->args[1], ""); |
||
1550 | LLVMValueRef result = lp_build_div(&bld_base->uint_bld, |
||
1551 | emit_data->args[0], divisor); |
||
1552 | /* udiv by zero is guaranteed to return 0xffffffff */ |
||
1553 | emit_data->output[emit_data->chan] = LLVMBuildOr(builder, |
||
1554 | div_mask, |
||
1555 | result, ""); |
||
1556 | } |
||
1557 | |||
1558 | /* TGSI_OPCODE_UMAX (CPU Only) */ |
||
1559 | static void |
||
1560 | umax_emit_cpu( |
||
1561 | const struct lp_build_tgsi_action * action, |
||
1562 | struct lp_build_tgsi_context * bld_base, |
||
1563 | struct lp_build_emit_data * emit_data) |
||
1564 | { |
||
1565 | emit_data->output[emit_data->chan] = lp_build_max(&bld_base->uint_bld, |
||
1566 | emit_data->args[0], emit_data->args[1]); |
||
1567 | } |
||
1568 | |||
1569 | /* TGSI_OPCODE_UMIN (CPU Only) */ |
||
1570 | static void |
||
1571 | umin_emit_cpu( |
||
1572 | const struct lp_build_tgsi_action * action, |
||
1573 | struct lp_build_tgsi_context * bld_base, |
||
1574 | struct lp_build_emit_data * emit_data) |
||
1575 | { |
||
1576 | emit_data->output[emit_data->chan] = lp_build_min(&bld_base->uint_bld, |
||
1577 | emit_data->args[0], emit_data->args[1]); |
||
1578 | } |
||
1579 | |||
1580 | /* TGSI_OPCODE_UMOD (CPU Only) */ |
||
1581 | static void |
||
1582 | umod_emit_cpu( |
||
1583 | const struct lp_build_tgsi_action * action, |
||
1584 | struct lp_build_tgsi_context * bld_base, |
||
1585 | struct lp_build_emit_data * emit_data) |
||
1586 | { |
||
1587 | LLVMBuilderRef builder = bld_base->base.gallivm->builder; |
||
1588 | LLVMValueRef div_mask = lp_build_cmp(&bld_base->uint_bld, |
||
1589 | PIPE_FUNC_EQUAL, emit_data->args[1], |
||
1590 | bld_base->uint_bld.zero); |
||
1591 | /* We want to make sure that we never divide/mod by zero to not |
||
1592 | * generate sigfpe. We don't want to crash just because the |
||
1593 | * shader is doing something weird. */ |
||
1594 | LLVMValueRef divisor = LLVMBuildOr(builder, |
||
1595 | div_mask, |
||
1596 | emit_data->args[1], ""); |
||
1597 | LLVMValueRef result = lp_build_mod(&bld_base->uint_bld, |
||
1598 | emit_data->args[0], divisor); |
||
1599 | /* umod by zero is guaranteed to return 0xffffffff */ |
||
1600 | emit_data->output[emit_data->chan] = LLVMBuildOr(builder, |
||
1601 | div_mask, |
||
1602 | result, ""); |
||
1603 | } |
||
1604 | |||
1605 | /* TGSI_OPCODE_USET Helper (CPU Only) */ |
||
1606 | static void |
||
1607 | uset_emit_cpu( |
||
1608 | const struct lp_build_tgsi_action * action, |
||
1609 | struct lp_build_tgsi_context * bld_base, |
||
1610 | struct lp_build_emit_data * emit_data, |
||
1611 | unsigned pipe_func) |
||
1612 | { |
||
1613 | LLVMValueRef cond = lp_build_cmp(&bld_base->uint_bld, pipe_func, |
||
1614 | emit_data->args[0], emit_data->args[1]); |
||
1615 | emit_data->output[emit_data->chan] = cond; |
||
1616 | } |
||
1617 | |||
1618 | |||
1619 | /* TGSI_OPCODE_USEQ (CPU Only) */ |
||
1620 | static void |
||
1621 | useq_emit_cpu( |
||
1622 | const struct lp_build_tgsi_action * action, |
||
1623 | struct lp_build_tgsi_context * bld_base, |
||
1624 | struct lp_build_emit_data * emit_data) |
||
1625 | { |
||
1626 | uset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_EQUAL); |
||
1627 | } |
||
1628 | |||
1629 | /* TGSI_OPCODE_ISGE (CPU Only) */ |
||
1630 | static void |
||
1631 | usge_emit_cpu( |
||
1632 | const struct lp_build_tgsi_action * action, |
||
1633 | struct lp_build_tgsi_context * bld_base, |
||
1634 | struct lp_build_emit_data * emit_data) |
||
1635 | { |
||
1636 | uset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_GEQUAL); |
||
1637 | } |
||
1638 | |||
1639 | /* TGSI_OPCODE_USHR (CPU Only) */ |
||
1640 | static void |
||
1641 | ushr_emit_cpu( |
||
1642 | const struct lp_build_tgsi_action * action, |
||
1643 | struct lp_build_tgsi_context * bld_base, |
||
1644 | struct lp_build_emit_data * emit_data) |
||
1645 | { |
||
1646 | emit_data->output[emit_data->chan] = lp_build_shr(&bld_base->uint_bld, |
||
1647 | emit_data->args[0], emit_data->args[1]); |
||
1648 | } |
||
1649 | |||
1650 | /* TGSI_OPCODE_ISLT (CPU Only) */ |
||
1651 | static void |
||
1652 | uslt_emit_cpu( |
||
1653 | const struct lp_build_tgsi_action * action, |
||
1654 | struct lp_build_tgsi_context * bld_base, |
||
1655 | struct lp_build_emit_data * emit_data) |
||
1656 | { |
||
1657 | uset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_LESS); |
||
1658 | } |
||
1659 | |||
1660 | /* TGSI_OPCODE_USNE (CPU Only) */ |
||
1661 | |||
1662 | static void |
||
1663 | usne_emit_cpu( |
||
1664 | const struct lp_build_tgsi_action * action, |
||
1665 | struct lp_build_tgsi_context * bld_base, |
||
1666 | struct lp_build_emit_data * emit_data) |
||
1667 | { |
||
1668 | uset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_NOTEQUAL); |
||
1669 | } |
||
1670 | |||
1671 | /* TGSI_OPCODE_XOR */ |
||
1672 | static void |
||
1673 | xor_emit_cpu( |
||
1674 | const struct lp_build_tgsi_action * action, |
||
1675 | struct lp_build_tgsi_context * bld_base, |
||
1676 | struct lp_build_emit_data * emit_data) |
||
1677 | { |
||
1678 | emit_data->output[emit_data->chan] = lp_build_xor(&bld_base->uint_bld, |
||
1679 | emit_data->args[0], |
||
1680 | emit_data->args[1]); |
||
1681 | } |
||
1682 | |||
1683 | void |
||
1684 | lp_set_default_actions_cpu( |
||
1685 | struct lp_build_tgsi_context * bld_base) |
||
1686 | { |
||
1687 | lp_set_default_actions(bld_base); |
||
1688 | bld_base->op_actions[TGSI_OPCODE_ABS].emit = abs_emit_cpu; |
||
1689 | bld_base->op_actions[TGSI_OPCODE_ADD].emit = add_emit_cpu; |
||
1690 | bld_base->op_actions[TGSI_OPCODE_AND].emit = and_emit_cpu; |
||
1691 | bld_base->op_actions[TGSI_OPCODE_ARL].emit = arl_emit_cpu; |
||
1692 | bld_base->op_actions[TGSI_OPCODE_ARR].emit = arr_emit_cpu; |
||
1693 | bld_base->op_actions[TGSI_OPCODE_CEIL].emit = ceil_emit_cpu; |
||
1694 | bld_base->op_actions[TGSI_OPCODE_CND].emit = cnd_emit_cpu; |
||
1695 | bld_base->op_actions[TGSI_OPCODE_COS].emit = cos_emit_cpu; |
||
1696 | bld_base->op_actions[TGSI_OPCODE_CMP].emit = cmp_emit_cpu; |
||
1697 | bld_base->op_actions[TGSI_OPCODE_DIV].emit = div_emit_cpu; |
||
1698 | bld_base->op_actions[TGSI_OPCODE_EX2].emit = ex2_emit_cpu; |
||
1699 | bld_base->op_actions[TGSI_OPCODE_EXP].emit = exp_emit_cpu; |
||
1700 | bld_base->op_actions[TGSI_OPCODE_F2I].emit = f2i_emit_cpu; |
||
1701 | bld_base->op_actions[TGSI_OPCODE_F2U].emit = f2u_emit_cpu; |
||
1702 | bld_base->op_actions[TGSI_OPCODE_FLR].emit = flr_emit_cpu; |
||
1703 | |||
1704 | bld_base->op_actions[TGSI_OPCODE_I2F].emit = i2f_emit_cpu; |
||
1705 | bld_base->op_actions[TGSI_OPCODE_IABS].emit = iabs_emit_cpu; |
||
1706 | bld_base->op_actions[TGSI_OPCODE_IDIV].emit = idiv_emit_cpu; |
||
1707 | bld_base->op_actions[TGSI_OPCODE_INEG].emit = ineg_emit_cpu; |
||
1708 | bld_base->op_actions[TGSI_OPCODE_IMAX].emit = imax_emit_cpu; |
||
1709 | bld_base->op_actions[TGSI_OPCODE_IMIN].emit = imin_emit_cpu; |
||
1710 | bld_base->op_actions[TGSI_OPCODE_ISGE].emit = isge_emit_cpu; |
||
1711 | bld_base->op_actions[TGSI_OPCODE_ISHR].emit = ishr_emit_cpu; |
||
1712 | bld_base->op_actions[TGSI_OPCODE_ISLT].emit = islt_emit_cpu; |
||
1713 | bld_base->op_actions[TGSI_OPCODE_ISSG].emit = issg_emit_cpu; |
||
1714 | |||
1715 | bld_base->op_actions[TGSI_OPCODE_LG2].emit = lg2_emit_cpu; |
||
1716 | bld_base->op_actions[TGSI_OPCODE_LOG].emit = log_emit_cpu; |
||
1717 | bld_base->op_actions[TGSI_OPCODE_MAX].emit = max_emit_cpu; |
||
1718 | bld_base->op_actions[TGSI_OPCODE_MIN].emit = min_emit_cpu; |
||
1719 | bld_base->op_actions[TGSI_OPCODE_MOD].emit = mod_emit_cpu; |
||
1720 | bld_base->op_actions[TGSI_OPCODE_NOT].emit = not_emit_cpu; |
||
1721 | bld_base->op_actions[TGSI_OPCODE_OR].emit = or_emit_cpu; |
||
1722 | bld_base->op_actions[TGSI_OPCODE_POW].emit = pow_emit_cpu; |
||
1723 | bld_base->op_actions[TGSI_OPCODE_RCP].emit = rcp_emit_cpu; |
||
1724 | bld_base->op_actions[TGSI_OPCODE_ROUND].emit = round_emit_cpu; |
||
1725 | bld_base->op_actions[TGSI_OPCODE_SEQ].emit = seq_emit_cpu; |
||
1726 | bld_base->op_actions[TGSI_OPCODE_SGE].emit = sge_emit_cpu; |
||
1727 | bld_base->op_actions[TGSI_OPCODE_SGT].emit = sgt_emit_cpu; |
||
1728 | bld_base->op_actions[TGSI_OPCODE_SIN].emit = sin_emit_cpu; |
||
1729 | bld_base->op_actions[TGSI_OPCODE_SHL].emit = shl_emit_cpu; |
||
1730 | bld_base->op_actions[TGSI_OPCODE_SLE].emit = sle_emit_cpu; |
||
1731 | bld_base->op_actions[TGSI_OPCODE_SLT].emit = slt_emit_cpu; |
||
1732 | bld_base->op_actions[TGSI_OPCODE_SNE].emit = sne_emit_cpu; |
||
1733 | bld_base->op_actions[TGSI_OPCODE_SSG].emit = ssg_emit_cpu; |
||
1734 | bld_base->op_actions[TGSI_OPCODE_SUB].emit = sub_emit_cpu; |
||
1735 | bld_base->op_actions[TGSI_OPCODE_TRUNC].emit = trunc_emit_cpu; |
||
1736 | |||
1737 | bld_base->rsq_action.emit = recip_sqrt_emit_cpu; |
||
1738 | bld_base->sqrt_action.emit = sqrt_emit_cpu; |
||
1739 | |||
1740 | bld_base->op_actions[TGSI_OPCODE_UADD].emit = uadd_emit_cpu; |
||
1741 | bld_base->op_actions[TGSI_OPCODE_UCMP].emit = ucmp_emit_cpu; |
||
1742 | bld_base->op_actions[TGSI_OPCODE_UDIV].emit = udiv_emit_cpu; |
||
1743 | bld_base->op_actions[TGSI_OPCODE_UMAX].emit = umax_emit_cpu; |
||
1744 | bld_base->op_actions[TGSI_OPCODE_UMIN].emit = umin_emit_cpu; |
||
1745 | bld_base->op_actions[TGSI_OPCODE_UMOD].emit = umod_emit_cpu; |
||
1746 | bld_base->op_actions[TGSI_OPCODE_USEQ].emit = useq_emit_cpu; |
||
1747 | bld_base->op_actions[TGSI_OPCODE_USGE].emit = usge_emit_cpu; |
||
1748 | bld_base->op_actions[TGSI_OPCODE_USHR].emit = ushr_emit_cpu; |
||
1749 | bld_base->op_actions[TGSI_OPCODE_USLT].emit = uslt_emit_cpu; |
||
1750 | bld_base->op_actions[TGSI_OPCODE_USNE].emit = usne_emit_cpu; |
||
1751 | |||
1752 | bld_base->op_actions[TGSI_OPCODE_XOR].emit = xor_emit_cpu; |
||
1753 | |||
1754 | }>> |