summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/gallivm/lp_bld_arit.h
blob: 9d2909340b2d7e726203e612fbd4e00d55f5b30c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/**************************************************************************
 *
 * Copyright 2009 VMware, Inc.
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 **************************************************************************/

/**
 * @file
 * Helper arithmetic functions.
 *
 * @author Jose Fonseca <jfonseca@vmware.com>
 */


#ifndef LP_BLD_ARIT_H
#define LP_BLD_ARIT_H


#include "gallivm/lp_bld.h"


struct lp_type;
struct lp_build_context;
struct gallivm_state;


/**
 * Complement, i.e., 1 - a.
 */
LLVMValueRef
lp_build_comp(struct lp_build_context *bld,
              LLVMValueRef a);

LLVMValueRef
lp_build_add(struct lp_build_context *bld,
             LLVMValueRef a,
             LLVMValueRef b);

LLVMValueRef
lp_build_horizontal_add(struct lp_build_context *bld,
                        LLVMValueRef a);

LLVMValueRef
lp_build_hadd_partial4(struct lp_build_context *bld,
                       LLVMValueRef vectors[],
                       unsigned num_vecs);

LLVMValueRef
lp_build_sub(struct lp_build_context *bld,
             LLVMValueRef a,
             LLVMValueRef b);

LLVMValueRef
lp_build_mul(struct lp_build_context *bld,
             LLVMValueRef a,
             LLVMValueRef b);

LLVMValueRef
lp_build_mul_imm(struct lp_build_context *bld,
                 LLVMValueRef a,
                 int b);

LLVMValueRef
lp_build_div(struct lp_build_context *bld,
             LLVMValueRef a,
             LLVMValueRef b);


/**
 * Set when the weights for normalized are prescaled, that is, in range
 * 0..2**n, as opposed to range 0..2**(n-1).
 */
#define LP_BLD_LERP_PRESCALED_WEIGHTS (1 << 0)

/**
 * Used internally when using wide intermediates for normalized lerps.
 *
 * Do not use.
 */
#define LP_BLD_LERP_WIDE_NORMALIZED (1 << 1)

LLVMValueRef
lp_build_lerp(struct lp_build_context *bld,
              LLVMValueRef x,
              LLVMValueRef v0,
              LLVMValueRef v1,
              unsigned flags);

LLVMValueRef
lp_build_lerp_2d(struct lp_build_context *bld,
                 LLVMValueRef x,
                 LLVMValueRef y,
                 LLVMValueRef v00,
                 LLVMValueRef v01,
                 LLVMValueRef v10,
                 LLVMValueRef v11,
                 unsigned flags);

LLVMValueRef
lp_build_lerp_3d(struct lp_build_context *bld,
                 LLVMValueRef x,
                 LLVMValueRef y,
                 LLVMValueRef z,
                 LLVMValueRef v000,
                 LLVMValueRef v001,
                 LLVMValueRef v010,
                 LLVMValueRef v011,
                 LLVMValueRef v100,
                 LLVMValueRef v101,
                 LLVMValueRef v110,
                 LLVMValueRef v111,
                 unsigned flags);

/**
 * Specifies floating point NaN behavior.
 */
enum gallivm_nan_behavior {
   /* Results are undefined with NaN. Results in fastest code */
   GALLIVM_NAN_BEHAVIOR_UNDEFINED,
   /* If input is NaN, NaN is returned */
   GALLIVM_NAN_RETURN_NAN,
   /* If one of the inputs is NaN, the other operand is returned */
   GALLIVM_NAN_RETURN_OTHER,
   /* If one of the inputs is NaN, the other operand is returned,
    * but we guarantee the second operand is not a NaN.
    * In min/max it will be as fast as undefined with sse opcodes,
    * and archs having native return_other can benefit too. */
   GALLIVM_NAN_RETURN_OTHER_SECOND_NONNAN
};

LLVMValueRef
lp_build_min(struct lp_build_context *bld,
             LLVMValueRef a,
             LLVMValueRef b);

LLVMValueRef
lp_build_min_ext(struct lp_build_context *bld,
                 LLVMValueRef a,
                 LLVMValueRef b,
                 enum gallivm_nan_behavior nan_behavior);

LLVMValueRef
lp_build_max(struct lp_build_context *bld,
             LLVMValueRef a,
             LLVMValueRef b);

LLVMValueRef
lp_build_max_ext(struct lp_build_context *bld,
                 LLVMValueRef a,
                 LLVMValueRef b,
                 enum gallivm_nan_behavior nan_behavior);

LLVMValueRef
lp_build_clamp(struct lp_build_context *bld,
               LLVMValueRef a,
               LLVMValueRef min,
               LLVMValueRef max);

LLVMValueRef
lp_build_clamp_zero_one_nanzero(struct lp_build_context *bld,
                                LLVMValueRef a);

LLVMValueRef
lp_build_abs(struct lp_build_context *bld,
             LLVMValueRef a);

LLVMValueRef
lp_build_negate(struct lp_build_context *bld,
                LLVMValueRef a);

LLVMValueRef
lp_build_sgn(struct lp_build_context *bld,
             LLVMValueRef a);

LLVMValueRef
lp_build_set_sign(struct lp_build_context *bld,
                  LLVMValueRef a, LLVMValueRef sign);

LLVMValueRef
lp_build_int_to_float(struct lp_build_context *bld,
                      LLVMValueRef a);

LLVMValueRef
lp_build_round(struct lp_build_context *bld,
               LLVMValueRef a);

LLVMValueRef
lp_build_floor(struct lp_build_context *bld,
               LLVMValueRef a);

LLVMValueRef
lp_build_ceil(struct lp_build_context *bld,
              LLVMValueRef a);

LLVMValueRef
lp_build_trunc(struct lp_build_context *bld,
               LLVMValueRef a);

LLVMValueRef
lp_build_fract(struct lp_build_context *bld,
               LLVMValueRef a);

LLVMValueRef
lp_build_fract_safe(struct lp_build_context *bld,
                    LLVMValueRef a);

LLVMValueRef
lp_build_ifloor(struct lp_build_context *bld,
                LLVMValueRef a);
LLVMValueRef
lp_build_iceil(struct lp_build_context *bld,
               LLVMValueRef a);

LLVMValueRef
lp_build_iround(struct lp_build_context *bld,
                LLVMValueRef a);

LLVMValueRef
lp_build_itrunc(struct lp_build_context *bld,
                LLVMValueRef a);

void
lp_build_ifloor_fract(struct lp_build_context *bld,
                      LLVMValueRef a,
                      LLVMValueRef *out_ipart,
                      LLVMValueRef *out_fpart);

void
lp_build_ifloor_fract_safe(struct lp_build_context *bld,
                           LLVMValueRef a,
                           LLVMValueRef *out_ipart,
                           LLVMValueRef *out_fpart);

LLVMValueRef
lp_build_sqrt(struct lp_build_context *bld,
              LLVMValueRef a);

LLVMValueRef
lp_build_rcp(struct lp_build_context *bld,
             LLVMValueRef a);

LLVMValueRef
lp_build_rsqrt(struct lp_build_context *bld,
               LLVMValueRef a);

boolean
lp_build_fast_rsqrt_available(struct lp_type type);

LLVMValueRef
lp_build_fast_rsqrt(struct lp_build_context *bld,
                    LLVMValueRef a);

LLVMValueRef
lp_build_polynomial(struct lp_build_context *bld,
                    LLVMValueRef x,
                    const double *coeffs,
                    unsigned num_coeffs);

LLVMValueRef
lp_build_cos(struct lp_build_context *bld,
             LLVMValueRef a);

LLVMValueRef
lp_build_sin(struct lp_build_context *bld,
             LLVMValueRef a);

LLVMValueRef
lp_build_pow(struct lp_build_context *bld,
             LLVMValueRef a,
             LLVMValueRef b);

LLVMValueRef
lp_build_exp(struct lp_build_context *bld,
             LLVMValueRef a);

LLVMValueRef
lp_build_log(struct lp_build_context *bld,
             LLVMValueRef a);

LLVMValueRef
lp_build_log_safe(struct lp_build_context *bld,
                  LLVMValueRef a);

LLVMValueRef
lp_build_exp2(struct lp_build_context *bld,
              LLVMValueRef a);

LLVMValueRef
lp_build_extract_exponent(struct lp_build_context *bld,
                          LLVMValueRef x,
                          int bias);

LLVMValueRef
lp_build_extract_mantissa(struct lp_build_context *bld,
                          LLVMValueRef x);

LLVMValueRef
lp_build_log2(struct lp_build_context *bld,
              LLVMValueRef a);

LLVMValueRef
lp_build_log2_safe(struct lp_build_context *bld,
                   LLVMValueRef a);

LLVMValueRef
lp_build_fast_log2(struct lp_build_context *bld,
                   LLVMValueRef a);

LLVMValueRef
lp_build_ilog2(struct lp_build_context *bld,
               LLVMValueRef x);

void
lp_build_log2_approx(struct lp_build_context *bld,
                     LLVMValueRef x,
                     LLVMValueRef *p_exp,
                     LLVMValueRef *p_floor_log2,
                     LLVMValueRef *p_log2,
                     boolean handle_nans);

LLVMValueRef
lp_build_mod(struct lp_build_context *bld,
             LLVMValueRef x,
             LLVMValueRef y);

LLVMValueRef
lp_build_isnan(struct lp_build_context *bld,
               LLVMValueRef x);

LLVMValueRef
lp_build_isfinite(struct lp_build_context *bld,
                  LLVMValueRef x);


LLVMValueRef
lp_build_is_inf_or_nan(struct gallivm_state *gallivm,
                       const struct lp_type type,
                       LLVMValueRef x);


LLVMValueRef
lp_build_fpstate_get(struct gallivm_state *gallivm);

void
lp_build_fpstate_set_denorms_zero(struct gallivm_state *gallivm,
                                  boolean zero);
void
lp_build_fpstate_set(struct gallivm_state *gallivm,
                     LLVMValueRef mxcsr);

#endif /* !LP_BLD_ARIT_H */