gallivm: Prevent disassembly debug output from being truncated.
[mesa.git] / src / gallium / auxiliary / gallivm / lp_bld_arit.h
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /**
29 * @file
30 * Helper arithmetic functions.
31 *
32 * @author Jose Fonseca <jfonseca@vmware.com>
33 */
34
35
36 #ifndef LP_BLD_ARIT_H
37 #define LP_BLD_ARIT_H
38
39
40 #include "gallivm/lp_bld.h"
41
42
43 struct lp_type;
44 struct lp_build_context;
45 struct gallivm_state;
46
47
48 /**
49 * Complement, i.e., 1 - a.
50 */
51 LLVMValueRef
52 lp_build_comp(struct lp_build_context *bld,
53 LLVMValueRef a);
54
55 LLVMValueRef
56 lp_build_add(struct lp_build_context *bld,
57 LLVMValueRef a,
58 LLVMValueRef b);
59
60 LLVMValueRef
61 lp_build_horizontal_add(struct lp_build_context *bld,
62 LLVMValueRef a);
63
64 LLVMValueRef
65 lp_build_hadd_partial4(struct lp_build_context *bld,
66 LLVMValueRef vectors[],
67 unsigned num_vecs);
68
69 LLVMValueRef
70 lp_build_sub(struct lp_build_context *bld,
71 LLVMValueRef a,
72 LLVMValueRef b);
73
74 LLVMValueRef
75 lp_build_mul(struct lp_build_context *bld,
76 LLVMValueRef a,
77 LLVMValueRef b);
78
79 LLVMValueRef
80 lp_build_mul_imm(struct lp_build_context *bld,
81 LLVMValueRef a,
82 int b);
83
84 LLVMValueRef
85 lp_build_div(struct lp_build_context *bld,
86 LLVMValueRef a,
87 LLVMValueRef b);
88
89
90 /**
91 * Set when the weights for normalized are prescaled, that is, in range
92 * 0..2**n, as opposed to range 0..2**(n-1).
93 */
94 #define LP_BLD_LERP_PRESCALED_WEIGHTS (1 << 0)
95
96 /**
97 * Used internally when using wide intermediates for normalized lerps.
98 *
99 * Do not use.
100 */
101 #define LP_BLD_LERP_WIDE_NORMALIZED (1 << 1)
102
103 LLVMValueRef
104 lp_build_lerp(struct lp_build_context *bld,
105 LLVMValueRef x,
106 LLVMValueRef v0,
107 LLVMValueRef v1,
108 unsigned flags);
109
110 LLVMValueRef
111 lp_build_lerp_2d(struct lp_build_context *bld,
112 LLVMValueRef x,
113 LLVMValueRef y,
114 LLVMValueRef v00,
115 LLVMValueRef v01,
116 LLVMValueRef v10,
117 LLVMValueRef v11,
118 unsigned flags);
119
120 LLVMValueRef
121 lp_build_lerp_3d(struct lp_build_context *bld,
122 LLVMValueRef x,
123 LLVMValueRef y,
124 LLVMValueRef z,
125 LLVMValueRef v000,
126 LLVMValueRef v001,
127 LLVMValueRef v010,
128 LLVMValueRef v011,
129 LLVMValueRef v100,
130 LLVMValueRef v101,
131 LLVMValueRef v110,
132 LLVMValueRef v111,
133 unsigned flags);
134
135 /**
136 * Specifies floating point NaN behavior.
137 */
138 enum gallivm_nan_behavior {
139 /* Results are undefined with NaN. Results in fastest code */
140 GALLIVM_NAN_BEHAVIOR_UNDEFINED,
141 /* If one of the inputs is NaN, NaN is returned */
142 GALLIVM_NAN_RETURN_NAN,
143 /* If one of the inputs is NaN, the other operand is returned */
144 GALLIVM_NAN_RETURN_OTHER,
145 /* If one of the inputs is NaN, the other operand is returned,
146 * but we guarantee the second operand is not a NaN.
147 * In min/max it will be as fast as undefined with sse opcodes,
148 * and archs having native return_other can benefit too. */
149 GALLIVM_NAN_RETURN_OTHER_SECOND_NONNAN,
150 /* If one of the inputs is NaN, NaN is returned,
151 * but we guarantee the first operand is not a NaN.
152 * In min/max it will be as fast as undefined with sse opcodes,
153 * and archs having native return_nan can benefit too. */
154 GALLIVM_NAN_RETURN_NAN_FIRST_NONNAN,
155
156 };
157
158 LLVMValueRef
159 lp_build_min(struct lp_build_context *bld,
160 LLVMValueRef a,
161 LLVMValueRef b);
162
163 LLVMValueRef
164 lp_build_min_ext(struct lp_build_context *bld,
165 LLVMValueRef a,
166 LLVMValueRef b,
167 enum gallivm_nan_behavior nan_behavior);
168
169 LLVMValueRef
170 lp_build_max(struct lp_build_context *bld,
171 LLVMValueRef a,
172 LLVMValueRef b);
173
174 LLVMValueRef
175 lp_build_max_ext(struct lp_build_context *bld,
176 LLVMValueRef a,
177 LLVMValueRef b,
178 enum gallivm_nan_behavior nan_behavior);
179
180 LLVMValueRef
181 lp_build_clamp(struct lp_build_context *bld,
182 LLVMValueRef a,
183 LLVMValueRef min,
184 LLVMValueRef max);
185
186 LLVMValueRef
187 lp_build_clamp_zero_one_nanzero(struct lp_build_context *bld,
188 LLVMValueRef a);
189
190 LLVMValueRef
191 lp_build_abs(struct lp_build_context *bld,
192 LLVMValueRef a);
193
194 LLVMValueRef
195 lp_build_negate(struct lp_build_context *bld,
196 LLVMValueRef a);
197
198 LLVMValueRef
199 lp_build_sgn(struct lp_build_context *bld,
200 LLVMValueRef a);
201
202 LLVMValueRef
203 lp_build_set_sign(struct lp_build_context *bld,
204 LLVMValueRef a, LLVMValueRef sign);
205
206 LLVMValueRef
207 lp_build_int_to_float(struct lp_build_context *bld,
208 LLVMValueRef a);
209
210 LLVMValueRef
211 lp_build_round(struct lp_build_context *bld,
212 LLVMValueRef a);
213
214 LLVMValueRef
215 lp_build_floor(struct lp_build_context *bld,
216 LLVMValueRef a);
217
218 LLVMValueRef
219 lp_build_ceil(struct lp_build_context *bld,
220 LLVMValueRef a);
221
222 LLVMValueRef
223 lp_build_trunc(struct lp_build_context *bld,
224 LLVMValueRef a);
225
226 LLVMValueRef
227 lp_build_fract(struct lp_build_context *bld,
228 LLVMValueRef a);
229
230 LLVMValueRef
231 lp_build_fract_safe(struct lp_build_context *bld,
232 LLVMValueRef a);
233
234 LLVMValueRef
235 lp_build_ifloor(struct lp_build_context *bld,
236 LLVMValueRef a);
237 LLVMValueRef
238 lp_build_iceil(struct lp_build_context *bld,
239 LLVMValueRef a);
240
241 LLVMValueRef
242 lp_build_iround(struct lp_build_context *bld,
243 LLVMValueRef a);
244
245 LLVMValueRef
246 lp_build_itrunc(struct lp_build_context *bld,
247 LLVMValueRef a);
248
249 void
250 lp_build_ifloor_fract(struct lp_build_context *bld,
251 LLVMValueRef a,
252 LLVMValueRef *out_ipart,
253 LLVMValueRef *out_fpart);
254
255 void
256 lp_build_ifloor_fract_safe(struct lp_build_context *bld,
257 LLVMValueRef a,
258 LLVMValueRef *out_ipart,
259 LLVMValueRef *out_fpart);
260
261 LLVMValueRef
262 lp_build_sqrt(struct lp_build_context *bld,
263 LLVMValueRef a);
264
265 LLVMValueRef
266 lp_build_rcp(struct lp_build_context *bld,
267 LLVMValueRef a);
268
269 LLVMValueRef
270 lp_build_rsqrt(struct lp_build_context *bld,
271 LLVMValueRef a);
272
273 boolean
274 lp_build_fast_rsqrt_available(struct lp_type type);
275
276 LLVMValueRef
277 lp_build_fast_rsqrt(struct lp_build_context *bld,
278 LLVMValueRef a);
279
280 LLVMValueRef
281 lp_build_polynomial(struct lp_build_context *bld,
282 LLVMValueRef x,
283 const double *coeffs,
284 unsigned num_coeffs);
285
286 LLVMValueRef
287 lp_build_cos(struct lp_build_context *bld,
288 LLVMValueRef a);
289
290 LLVMValueRef
291 lp_build_sin(struct lp_build_context *bld,
292 LLVMValueRef a);
293
294 LLVMValueRef
295 lp_build_pow(struct lp_build_context *bld,
296 LLVMValueRef a,
297 LLVMValueRef b);
298
299 LLVMValueRef
300 lp_build_exp(struct lp_build_context *bld,
301 LLVMValueRef a);
302
303 LLVMValueRef
304 lp_build_log(struct lp_build_context *bld,
305 LLVMValueRef a);
306
307 LLVMValueRef
308 lp_build_log_safe(struct lp_build_context *bld,
309 LLVMValueRef a);
310
311 LLVMValueRef
312 lp_build_exp2(struct lp_build_context *bld,
313 LLVMValueRef a);
314
315 LLVMValueRef
316 lp_build_extract_exponent(struct lp_build_context *bld,
317 LLVMValueRef x,
318 int bias);
319
320 LLVMValueRef
321 lp_build_extract_mantissa(struct lp_build_context *bld,
322 LLVMValueRef x);
323
324 LLVMValueRef
325 lp_build_log2(struct lp_build_context *bld,
326 LLVMValueRef a);
327
328 LLVMValueRef
329 lp_build_log2_safe(struct lp_build_context *bld,
330 LLVMValueRef a);
331
332 LLVMValueRef
333 lp_build_fast_log2(struct lp_build_context *bld,
334 LLVMValueRef a);
335
336 LLVMValueRef
337 lp_build_ilog2(struct lp_build_context *bld,
338 LLVMValueRef x);
339
340 void
341 lp_build_log2_approx(struct lp_build_context *bld,
342 LLVMValueRef x,
343 LLVMValueRef *p_exp,
344 LLVMValueRef *p_floor_log2,
345 LLVMValueRef *p_log2,
346 boolean handle_nans);
347
348 LLVMValueRef
349 lp_build_mod(struct lp_build_context *bld,
350 LLVMValueRef x,
351 LLVMValueRef y);
352
353 LLVMValueRef
354 lp_build_isnan(struct lp_build_context *bld,
355 LLVMValueRef x);
356
357 LLVMValueRef
358 lp_build_isfinite(struct lp_build_context *bld,
359 LLVMValueRef x);
360
361
362 LLVMValueRef
363 lp_build_is_inf_or_nan(struct gallivm_state *gallivm,
364 const struct lp_type type,
365 LLVMValueRef x);
366
367
368 LLVMValueRef
369 lp_build_fpstate_get(struct gallivm_state *gallivm);
370
371 void
372 lp_build_fpstate_set_denorms_zero(struct gallivm_state *gallivm,
373 boolean zero);
374 void
375 lp_build_fpstate_set(struct gallivm_state *gallivm,
376 LLVMValueRef mxcsr);
377
378 #endif /* !LP_BLD_ARIT_H */