c78b61decf08bb9ba491b5a4b6b8da2bb0d1d003
[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
46
47 /**
48 * Complement, i.e., 1 - a.
49 */
50 LLVMValueRef
51 lp_build_comp(struct lp_build_context *bld,
52 LLVMValueRef a);
53
54 LLVMValueRef
55 lp_build_add(struct lp_build_context *bld,
56 LLVMValueRef a,
57 LLVMValueRef b);
58
59 LLVMValueRef
60 lp_build_sum_vector(struct lp_build_context *bld,
61 LLVMValueRef a);
62
63 LLVMValueRef
64 lp_build_sub(struct lp_build_context *bld,
65 LLVMValueRef a,
66 LLVMValueRef b);
67
68 LLVMValueRef
69 lp_build_mul(struct lp_build_context *bld,
70 LLVMValueRef a,
71 LLVMValueRef b);
72
73 LLVMValueRef
74 lp_build_mul_imm(struct lp_build_context *bld,
75 LLVMValueRef a,
76 int b);
77
78 LLVMValueRef
79 lp_build_div(struct lp_build_context *bld,
80 LLVMValueRef a,
81 LLVMValueRef b);
82
83 LLVMValueRef
84 lp_build_lerp(struct lp_build_context *bld,
85 LLVMValueRef x,
86 LLVMValueRef v0,
87 LLVMValueRef v1);
88
89 /**
90 * Bilinear interpolation.
91 *
92 * Values indices are in v_{yx}.
93 */
94 LLVMValueRef
95 lp_build_lerp_2d(struct lp_build_context *bld,
96 LLVMValueRef x,
97 LLVMValueRef y,
98 LLVMValueRef v00,
99 LLVMValueRef v01,
100 LLVMValueRef v10,
101 LLVMValueRef v11);
102
103 LLVMValueRef
104 lp_build_min(struct lp_build_context *bld,
105 LLVMValueRef a,
106 LLVMValueRef b);
107
108 LLVMValueRef
109 lp_build_max(struct lp_build_context *bld,
110 LLVMValueRef a,
111 LLVMValueRef b);
112
113 LLVMValueRef
114 lp_build_clamp(struct lp_build_context *bld,
115 LLVMValueRef a,
116 LLVMValueRef min,
117 LLVMValueRef max);
118
119 LLVMValueRef
120 lp_build_abs(struct lp_build_context *bld,
121 LLVMValueRef a);
122
123 LLVMValueRef
124 lp_build_negate(struct lp_build_context *bld,
125 LLVMValueRef a);
126
127 LLVMValueRef
128 lp_build_sgn(struct lp_build_context *bld,
129 LLVMValueRef a);
130
131 LLVMValueRef
132 lp_build_set_sign(struct lp_build_context *bld,
133 LLVMValueRef a, LLVMValueRef sign);
134
135 LLVMValueRef
136 lp_build_int_to_float(struct lp_build_context *bld,
137 LLVMValueRef a);
138
139 LLVMValueRef
140 lp_build_round(struct lp_build_context *bld,
141 LLVMValueRef a);
142
143 LLVMValueRef
144 lp_build_floor(struct lp_build_context *bld,
145 LLVMValueRef a);
146
147 LLVMValueRef
148 lp_build_ceil(struct lp_build_context *bld,
149 LLVMValueRef a);
150
151 LLVMValueRef
152 lp_build_trunc(struct lp_build_context *bld,
153 LLVMValueRef a);
154
155 LLVMValueRef
156 lp_build_fract(struct lp_build_context *bld,
157 LLVMValueRef a);
158
159 LLVMValueRef
160 lp_build_ifloor(struct lp_build_context *bld,
161 LLVMValueRef a);
162 LLVMValueRef
163 lp_build_iceil(struct lp_build_context *bld,
164 LLVMValueRef a);
165
166 LLVMValueRef
167 lp_build_iround(struct lp_build_context *bld,
168 LLVMValueRef a);
169
170 LLVMValueRef
171 lp_build_itrunc(struct lp_build_context *bld,
172 LLVMValueRef a);
173
174 void
175 lp_build_ifloor_fract(struct lp_build_context *bld,
176 LLVMValueRef a,
177 LLVMValueRef *out_ipart,
178 LLVMValueRef *out_fpart);
179
180 LLVMValueRef
181 lp_build_sqrt(struct lp_build_context *bld,
182 LLVMValueRef a);
183
184 LLVMValueRef
185 lp_build_rcp(struct lp_build_context *bld,
186 LLVMValueRef a);
187
188 LLVMValueRef
189 lp_build_rsqrt(struct lp_build_context *bld,
190 LLVMValueRef a);
191
192 LLVMValueRef
193 lp_build_cos(struct lp_build_context *bld,
194 LLVMValueRef a);
195
196 LLVMValueRef
197 lp_build_sin(struct lp_build_context *bld,
198 LLVMValueRef a);
199
200 LLVMValueRef
201 lp_build_pow(struct lp_build_context *bld,
202 LLVMValueRef a,
203 LLVMValueRef b);
204
205 LLVMValueRef
206 lp_build_exp(struct lp_build_context *bld,
207 LLVMValueRef a);
208
209 LLVMValueRef
210 lp_build_log(struct lp_build_context *bld,
211 LLVMValueRef a);
212
213 LLVMValueRef
214 lp_build_exp2(struct lp_build_context *bld,
215 LLVMValueRef a);
216
217 LLVMValueRef
218 lp_build_extract_exponent(struct lp_build_context *bld,
219 LLVMValueRef x,
220 int bias);
221
222 LLVMValueRef
223 lp_build_extract_mantissa(struct lp_build_context *bld,
224 LLVMValueRef x);
225
226 LLVMValueRef
227 lp_build_log2(struct lp_build_context *bld,
228 LLVMValueRef a);
229
230 LLVMValueRef
231 lp_build_fast_log2(struct lp_build_context *bld,
232 LLVMValueRef a);
233
234 LLVMValueRef
235 lp_build_ilog2(struct lp_build_context *bld,
236 LLVMValueRef x);
237
238 void
239 lp_build_exp2_approx(struct lp_build_context *bld,
240 LLVMValueRef x,
241 LLVMValueRef *p_exp2_int_part,
242 LLVMValueRef *p_frac_part,
243 LLVMValueRef *p_exp2);
244
245 void
246 lp_build_log2_approx(struct lp_build_context *bld,
247 LLVMValueRef x,
248 LLVMValueRef *p_exp,
249 LLVMValueRef *p_floor_log2,
250 LLVMValueRef *p_log2);
251
252 #endif /* !LP_BLD_ARIT_H */