blob: 6dc971cff1fd13495e6fe8b2e71725e3408989dd [file] [log] [blame]
Jason Sams044e2ee2011-08-08 16:52:30 -07001/*
Stephen Hinescb058022012-05-29 17:10:05 -07002 * Copyright (C) 2011-2012 The Android Open Source Project
Jason Sams044e2ee2011-08-08 16:52:30 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/** @file rs_cl.rsh
Jason Samsef823642011-08-31 14:52:08 -070018 * \brief Basic math functions
Jason Sams044e2ee2011-08-08 16:52:30 -070019 *
20 *
21 */
22
Jason Sams1b937f52010-06-09 14:26:16 -070023#ifndef __RS_CL_RSH__
24#define __RS_CL_RSH__
25
Jason Sams1b937f52010-06-09 14:26:16 -070026// Conversions
Stephen Hines47b15302011-01-19 18:06:34 -080027#define CVT_FUNC_2(typeout, typein) \
Stephen Hines52132472013-04-30 15:45:22 -070028_RS_RUNTIME typeout##2 __attribute__((const, overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -080029 convert_##typeout##2(typein##2 v); \
Stephen Hines52132472013-04-30 15:45:22 -070030_RS_RUNTIME typeout##3 __attribute__((const, overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -080031 convert_##typeout##3(typein##3 v); \
Stephen Hines52132472013-04-30 15:45:22 -070032_RS_RUNTIME typeout##4 __attribute__((const, overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -080033 convert_##typeout##4(typein##4 v);
34
Jason Sams1b937f52010-06-09 14:26:16 -070035
Stephen Hines47b15302011-01-19 18:06:34 -080036#define CVT_FUNC(type) CVT_FUNC_2(type, uchar) \
37 CVT_FUNC_2(type, char) \
38 CVT_FUNC_2(type, ushort) \
39 CVT_FUNC_2(type, short) \
40 CVT_FUNC_2(type, uint) \
41 CVT_FUNC_2(type, int) \
42 CVT_FUNC_2(type, float)
Jason Sams1b937f52010-06-09 14:26:16 -070043
Stephen Hinescb058022012-05-29 17:10:05 -070044/**
45 * Convert to char.
46 *
47 * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float.
48 */
Jason Sams1b937f52010-06-09 14:26:16 -070049CVT_FUNC(char)
Stephen Hinescb058022012-05-29 17:10:05 -070050
51/**
52 * Convert to unsigned char.
53 *
54 * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float.
55 */
Jason Sams1b937f52010-06-09 14:26:16 -070056CVT_FUNC(uchar)
Stephen Hinescb058022012-05-29 17:10:05 -070057
58/**
59 * Convert to short.
60 *
61 * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float.
62 */
Jason Sams1b937f52010-06-09 14:26:16 -070063CVT_FUNC(short)
Stephen Hinescb058022012-05-29 17:10:05 -070064
65/**
66 * Convert to unsigned short.
67 *
68 * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float.
69 */
Jason Sams1b937f52010-06-09 14:26:16 -070070CVT_FUNC(ushort)
Stephen Hinescb058022012-05-29 17:10:05 -070071
72/**
73 * Convert to int.
74 *
75 * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float.
76 */
Jason Sams1b937f52010-06-09 14:26:16 -070077CVT_FUNC(int)
Stephen Hinescb058022012-05-29 17:10:05 -070078
79/**
80 * Convert to unsigned int.
81 *
82 * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float.
83 */
Jason Sams1b937f52010-06-09 14:26:16 -070084CVT_FUNC(uint)
Stephen Hinescb058022012-05-29 17:10:05 -070085
86/**
87 * Convert to float.
88 *
89 * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float.
90 */
Jason Sams1b937f52010-06-09 14:26:16 -070091CVT_FUNC(float)
92
Jason Sams22fa3712010-05-19 17:22:57 -070093// Float ops, 6.11.2
94
Stephen Hines52132472013-04-30 15:45:22 -070095#define FN_FUNC_FN(fnc) \
96_RS_RUNTIME float2 __attribute__((const, overloadable)) fnc(float2 v); \
97_RS_RUNTIME float3 __attribute__((const, overloadable)) fnc(float3 v); \
98_RS_RUNTIME float4 __attribute__((const, overloadable)) fnc(float4 v);
Jason Sams1b937f52010-06-09 14:26:16 -070099
Stephen Hines52132472013-04-30 15:45:22 -0700100#define F_FUNC_FN(fnc) \
101_RS_RUNTIME float __attribute__((const, overloadable)) fnc(float2 v); \
102_RS_RUNTIME float __attribute__((const, overloadable)) fnc(float3 v); \
103_RS_RUNTIME float __attribute__((const, overloadable)) fnc(float4 v);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700104
Stephen Hines52132472013-04-30 15:45:22 -0700105#define IN_FUNC_FN(fnc) \
106_RS_RUNTIME int2 __attribute__((const, overloadable)) fnc(float2 v); \
107_RS_RUNTIME int3 __attribute__((const, overloadable)) fnc(float3 v); \
108_RS_RUNTIME int4 __attribute__((const, overloadable)) fnc(float4 v);
Stephen Hines47416532011-01-11 14:38:18 -0800109
Stephen Hines52132472013-04-30 15:45:22 -0700110#define FN_FUNC_FN_FN(fnc) \
111_RS_RUNTIME float2 __attribute__((const, overloadable)) fnc(float2 v1, float2 v2); \
112_RS_RUNTIME float3 __attribute__((const, overloadable)) fnc(float3 v1, float3 v2); \
113_RS_RUNTIME float4 __attribute__((const, overloadable)) fnc(float4 v1, float4 v2);
Jason Sams1b937f52010-06-09 14:26:16 -0700114
Stephen Hines52132472013-04-30 15:45:22 -0700115#define F_FUNC_FN_FN(fnc) \
116_RS_RUNTIME float __attribute__((const, overloadable)) fnc(float2 v1, float2 v2); \
117_RS_RUNTIME float __attribute__((const, overloadable)) fnc(float3 v1, float3 v2); \
118_RS_RUNTIME float __attribute__((const, overloadable)) fnc(float4 v1, float4 v2);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700119
Stephen Hines52132472013-04-30 15:45:22 -0700120#define FN_FUNC_FN_F(fnc) \
121_RS_RUNTIME float2 __attribute__((const, overloadable)) fnc(float2 v1, float v2); \
122_RS_RUNTIME float3 __attribute__((const, overloadable)) fnc(float3 v1, float v2); \
123_RS_RUNTIME float4 __attribute__((const, overloadable)) fnc(float4 v1, float v2);
Jason Sams1b937f52010-06-09 14:26:16 -0700124
Stephen Hines52132472013-04-30 15:45:22 -0700125#define FN_FUNC_FN_IN(fnc) \
126_RS_RUNTIME float2 __attribute__((const, overloadable)) fnc(float2 v1, int2 v2); \
127_RS_RUNTIME float3 __attribute__((const, overloadable)) fnc(float3 v1, int3 v2); \
128_RS_RUNTIME float4 __attribute__((const, overloadable)) fnc(float4 v1, int4 v2);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800129
Stephen Hines52132472013-04-30 15:45:22 -0700130#define FN_FUNC_FN_I(fnc) \
131_RS_RUNTIME float2 __attribute__((const, overloadable)) fnc(float2 v1, int v2); \
132_RS_RUNTIME float3 __attribute__((const, overloadable)) fnc(float3 v1, int v2); \
133_RS_RUNTIME float4 __attribute__((const, overloadable)) fnc(float4 v1, int v2);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800134
Stephen Hines52132472013-04-30 15:45:22 -0700135#define FN_FUNC_FN_PFN(fnc) \
136_RS_RUNTIME float2 __attribute__((pure, overloadable)) \
137 fnc(float2 v1, float2 *v2); \
138_RS_RUNTIME float3 __attribute__((pure, overloadable)) \
139 fnc(float3 v1, float3 *v2); \
140_RS_RUNTIME float4 __attribute__((pure, overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800141 fnc(float4 v1, float4 *v2);
Jason Sams1b937f52010-06-09 14:26:16 -0700142
Stephen Hines52132472013-04-30 15:45:22 -0700143#define FN_FUNC_FN_PIN(fnc) \
144_RS_RUNTIME float2 __attribute__((pure, overloadable)) fnc(float2 v1, int2 *v2); \
145_RS_RUNTIME float3 __attribute__((pure, overloadable)) fnc(float3 v1, int3 *v2); \
146_RS_RUNTIME float4 __attribute__((pure, overloadable)) fnc(float4 v1, int4 *v2);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800147
Stephen Hines52132472013-04-30 15:45:22 -0700148#define FN_FUNC_FN_FN_FN(fnc) \
149_RS_RUNTIME float2 __attribute__((const, overloadable)) \
150 fnc(float2 v1, float2 v2, float2 v3); \
151_RS_RUNTIME float3 __attribute__((const, overloadable)) \
152 fnc(float3 v1, float3 v2, float3 v3); \
153_RS_RUNTIME float4 __attribute__((const, overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800154 fnc(float4 v1, float4 v2, float4 v3);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800155
Stephen Hines52132472013-04-30 15:45:22 -0700156#define FN_FUNC_FN_FN_F(fnc) \
157_RS_RUNTIME float2 __attribute__((const, overloadable)) \
158 fnc(float2 v1, float2 v2, float v3); \
159_RS_RUNTIME float3 __attribute__((const, overloadable)) \
160 fnc(float3 v1, float3 v2, float v3); \
161_RS_RUNTIME float4 __attribute__((const, overloadable)) \
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700162 fnc(float4 v1, float4 v2, float v3);
163
Stephen Hines52132472013-04-30 15:45:22 -0700164#define FN_FUNC_FN_F_F(fnc) \
165_RS_RUNTIME float2 __attribute__((const, overloadable)) \
166 fnc(float2 v1, float v2, float v3); \
167_RS_RUNTIME float3 __attribute__((const, overloadable)) \
168 fnc(float3 v1, float v2, float v3); \
169_RS_RUNTIME float4 __attribute__((const, overloadable)) \
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700170 fnc(float4 v1, float v2, float v3);
171
Stephen Hines52132472013-04-30 15:45:22 -0700172#define FN_FUNC_FN_FN_PIN(fnc) \
173_RS_RUNTIME float2 __attribute__((pure, overloadable)) \
174 fnc(float2 v1, float2 v2, int2 *v3); \
175_RS_RUNTIME float3 __attribute__((pure, overloadable)) \
176 fnc(float3 v1, float3 v2, int3 *v3); \
177_RS_RUNTIME float4 __attribute__((pure, overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800178 fnc(float4 v1, float4 v2, int4 *v3);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800179
180
Jason Samsef823642011-08-31 14:52:08 -0700181/**
182 * Return the inverse cosine.
183 *
184 * Supports float, float2, float3, float4
185 */
Stephen Hines52132472013-04-30 15:45:22 -0700186extern float __attribute__((const, overloadable)) acos(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800187FN_FUNC_FN(acos)
Jason Sams22fa3712010-05-19 17:22:57 -0700188
Jason Samsef823642011-08-31 14:52:08 -0700189/**
190 * Return the inverse hyperbolic cosine.
191 *
192 * Supports float, float2, float3, float4
193 */
Stephen Hines52132472013-04-30 15:45:22 -0700194extern float __attribute__((const, overloadable)) acosh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800195FN_FUNC_FN(acosh)
Jason Sams22fa3712010-05-19 17:22:57 -0700196
Jason Samsef823642011-08-31 14:52:08 -0700197/**
198 * Return the inverse cosine divided by PI.
199 *
200 * Supports float, float2, float3, float4
201 */
Stephen Hines52132472013-04-30 15:45:22 -0700202_RS_RUNTIME float __attribute__((const, overloadable)) acospi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800203FN_FUNC_FN(acospi)
Jason Sams22fa3712010-05-19 17:22:57 -0700204
Jason Samsef823642011-08-31 14:52:08 -0700205/**
206 * Return the inverse sine.
207 *
208 * Supports float, float2, float3, float4
209 */
Stephen Hines52132472013-04-30 15:45:22 -0700210extern float __attribute__((const, overloadable)) asin(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800211FN_FUNC_FN(asin)
Jason Sams22fa3712010-05-19 17:22:57 -0700212
Jason Samsef823642011-08-31 14:52:08 -0700213/**
214 * Return the inverse hyperbolic sine.
215 *
216 * Supports float, float2, float3, float4
217 */
Stephen Hines52132472013-04-30 15:45:22 -0700218extern float __attribute__((const, overloadable)) asinh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800219FN_FUNC_FN(asinh)
Jason Sams22fa3712010-05-19 17:22:57 -0700220
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800221
Jason Samsef823642011-08-31 14:52:08 -0700222/**
223 * Return the inverse sine divided by PI.
224 *
225 * Supports float, float2, float3, float4
226 */
Stephen Hines52132472013-04-30 15:45:22 -0700227_RS_RUNTIME float __attribute__((const, overloadable)) asinpi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800228FN_FUNC_FN(asinpi)
Jason Sams22fa3712010-05-19 17:22:57 -0700229
Jason Samsef823642011-08-31 14:52:08 -0700230/**
231 * Return the inverse tangent.
232 *
233 * Supports float, float2, float3, float4
234 */
Stephen Hines52132472013-04-30 15:45:22 -0700235extern float __attribute__((const, overloadable)) atan(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800236FN_FUNC_FN(atan)
Jason Sams22fa3712010-05-19 17:22:57 -0700237
Jason Samsef823642011-08-31 14:52:08 -0700238/**
239 * Return the inverse tangent of y / x.
240 *
241 * Supports float, float2, float3, float4. Both arguments must be of the same
242 * type.
243 *
244 * @param y
245 * @param x
246 */
Stephen Hines52132472013-04-30 15:45:22 -0700247extern float __attribute__((const, overloadable)) atan2(float y, float x);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800248FN_FUNC_FN_FN(atan2)
Jason Sams22fa3712010-05-19 17:22:57 -0700249
Jason Samsef823642011-08-31 14:52:08 -0700250/**
251 * Return the inverse hyperbolic tangent.
252 *
253 * Supports float, float2, float3, float4
254 */
Stephen Hines52132472013-04-30 15:45:22 -0700255extern float __attribute__((const, overloadable)) atanh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800256FN_FUNC_FN(atanh)
Jason Sams22fa3712010-05-19 17:22:57 -0700257
Jason Samsef823642011-08-31 14:52:08 -0700258/**
259 * Return the inverse tangent divided by PI.
260 *
261 * Supports float, float2, float3, float4
262 */
Stephen Hines52132472013-04-30 15:45:22 -0700263_RS_RUNTIME float __attribute__((const, overloadable)) atanpi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800264FN_FUNC_FN(atanpi)
Jason Sams22fa3712010-05-19 17:22:57 -0700265
Jason Samsef823642011-08-31 14:52:08 -0700266/**
267 * Return the inverse tangent of y / x, divided by PI.
268 *
269 * Supports float, float2, float3, float4. Both arguments must be of the same
270 * type.
271 *
272 * @param y
273 * @param x
274 */
Stephen Hines52132472013-04-30 15:45:22 -0700275_RS_RUNTIME float __attribute__((const, overloadable)) atan2pi(float y, float x);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800276FN_FUNC_FN_FN(atan2pi)
Jason Sams22fa3712010-05-19 17:22:57 -0700277
Jason Samsef823642011-08-31 14:52:08 -0700278
279/**
280 * Return the cube root.
281 *
282 * Supports float, float2, float3, float4.
283 */
Stephen Hines52132472013-04-30 15:45:22 -0700284extern float __attribute__((const, overloadable)) cbrt(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800285FN_FUNC_FN(cbrt)
Jason Sams22fa3712010-05-19 17:22:57 -0700286
Jason Samsef823642011-08-31 14:52:08 -0700287/**
288 * Return the smallest integer not less than a value.
289 *
290 * Supports float, float2, float3, float4.
291 */
Stephen Hines52132472013-04-30 15:45:22 -0700292extern float __attribute__((const, overloadable)) ceil(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800293FN_FUNC_FN(ceil)
Jason Sams22fa3712010-05-19 17:22:57 -0700294
Jason Samsef823642011-08-31 14:52:08 -0700295/**
296 * Copy the sign bit from y to x.
297 *
298 * Supports float, float2, float3, float4. Both arguments must be of the same
299 * type.
300 *
301 * @param x
302 * @param y
303 */
Stephen Hines52132472013-04-30 15:45:22 -0700304extern float __attribute__((const, overloadable)) copysign(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800305FN_FUNC_FN_FN(copysign)
Jason Sams22fa3712010-05-19 17:22:57 -0700306
Jason Samsef823642011-08-31 14:52:08 -0700307/**
308 * Return the cosine.
309 *
310 * Supports float, float2, float3, float4.
311 */
Stephen Hines52132472013-04-30 15:45:22 -0700312extern float __attribute__((const, overloadable)) cos(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800313FN_FUNC_FN(cos)
Jason Sams22fa3712010-05-19 17:22:57 -0700314
Jason Samsef823642011-08-31 14:52:08 -0700315/**
316 * Return the hypebolic cosine.
317 *
318 * Supports float, float2, float3, float4.
319 */
Stephen Hines52132472013-04-30 15:45:22 -0700320extern float __attribute__((const, overloadable)) cosh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800321FN_FUNC_FN(cosh)
Jason Sams22fa3712010-05-19 17:22:57 -0700322
Jason Samsef823642011-08-31 14:52:08 -0700323/**
324 * Return the cosine of the value * PI.
325 *
326 * Supports float, float2, float3, float4.
327 */
Stephen Hines52132472013-04-30 15:45:22 -0700328_RS_RUNTIME float __attribute__((const, overloadable)) cospi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800329FN_FUNC_FN(cospi)
Jason Sams22fa3712010-05-19 17:22:57 -0700330
Jason Samsef823642011-08-31 14:52:08 -0700331/**
332 * Return the complementary error function.
333 *
334 * Supports float, float2, float3, float4.
335 */
Stephen Hines52132472013-04-30 15:45:22 -0700336extern float __attribute__((const, overloadable)) erfc(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800337FN_FUNC_FN(erfc)
Jason Sams22fa3712010-05-19 17:22:57 -0700338
Jason Samsef823642011-08-31 14:52:08 -0700339/**
340 * Return the error function.
341 *
342 * Supports float, float2, float3, float4.
343 */
Stephen Hines52132472013-04-30 15:45:22 -0700344extern float __attribute__((const, overloadable)) erf(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800345FN_FUNC_FN(erf)
Jason Sams22fa3712010-05-19 17:22:57 -0700346
Jason Samsef823642011-08-31 14:52:08 -0700347/**
348 * Return e ^ value.
349 *
350 * Supports float, float2, float3, float4.
351 */
Stephen Hines52132472013-04-30 15:45:22 -0700352extern float __attribute__((const, overloadable)) exp(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800353FN_FUNC_FN(exp)
Jason Sams22fa3712010-05-19 17:22:57 -0700354
Jason Samsef823642011-08-31 14:52:08 -0700355/**
356 * Return 2 ^ value.
357 *
358 * Supports float, float2, float3, float4.
359 */
Stephen Hines52132472013-04-30 15:45:22 -0700360extern float __attribute__((const, overloadable)) exp2(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800361FN_FUNC_FN(exp2)
Jason Sams22fa3712010-05-19 17:22:57 -0700362
Jason Samsef823642011-08-31 14:52:08 -0700363/**
364 * Return x ^ y.
365 *
366 * Supports float, float2, float3, float4. Both arguments must be of the same
367 * type.
368 */
Stephen Hines52132472013-04-30 15:45:22 -0700369extern float __attribute__((const, overloadable)) pow(float x, float y);
Jason Samsef823642011-08-31 14:52:08 -0700370FN_FUNC_FN_FN(pow)
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800371
Jason Samsef823642011-08-31 14:52:08 -0700372/**
373 * Return 10 ^ value.
374 *
375 * Supports float, float2, float3, float4.
376 */
Stephen Hines52132472013-04-30 15:45:22 -0700377_RS_RUNTIME float __attribute__((const, overloadable)) exp10(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800378FN_FUNC_FN(exp10)
Jason Sams22fa3712010-05-19 17:22:57 -0700379
Jason Samsef823642011-08-31 14:52:08 -0700380/**
381 * Return (e ^ value) - 1.
382 *
383 * Supports float, float2, float3, float4.
384 */
Stephen Hines52132472013-04-30 15:45:22 -0700385extern float __attribute__((const, overloadable)) expm1(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800386FN_FUNC_FN(expm1)
Jason Sams22fa3712010-05-19 17:22:57 -0700387
Jason Samsef823642011-08-31 14:52:08 -0700388/**
389 * Return the absolute value of a value.
390 *
391 * Supports float, float2, float3, float4.
392 */
Stephen Hines52132472013-04-30 15:45:22 -0700393extern float __attribute__((const, overloadable)) fabs(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800394FN_FUNC_FN(fabs)
Jason Sams22fa3712010-05-19 17:22:57 -0700395
Jason Samsef823642011-08-31 14:52:08 -0700396/**
397 * Return the positive difference between two values.
398 *
399 * Supports float, float2, float3, float4. Both arguments must be of the same
400 * type.
401 */
Stephen Hines52132472013-04-30 15:45:22 -0700402extern float __attribute__((const, overloadable)) fdim(float, float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800403FN_FUNC_FN_FN(fdim)
Jason Sams22fa3712010-05-19 17:22:57 -0700404
Jason Samsef823642011-08-31 14:52:08 -0700405/**
406 * Return the smallest integer not greater than a value.
407 *
408 * Supports float, float2, float3, float4.
409 */
Stephen Hines52132472013-04-30 15:45:22 -0700410extern float __attribute__((const, overloadable)) floor(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800411FN_FUNC_FN(floor)
Jason Sams22fa3712010-05-19 17:22:57 -0700412
Jason Samsef823642011-08-31 14:52:08 -0700413/**
414 * Return a*b + c.
415 *
416 * Supports float, float2, float3, float4.
417 */
Stephen Hines52132472013-04-30 15:45:22 -0700418extern float __attribute__((const, overloadable)) fma(float a, float b, float c);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800419FN_FUNC_FN_FN_FN(fma)
Jason Sams22fa3712010-05-19 17:22:57 -0700420
Jason Samsef823642011-08-31 14:52:08 -0700421/**
422 * Return (x < y ? y : x)
423 *
424 * Supports float, float2, float3, float4.
425 * @param x: may be float, float2, float3, float4
426 * @param y: may be float or vector. If vector must match type of x.
427 */
Stephen Hines52132472013-04-30 15:45:22 -0700428extern float __attribute__((const, overloadable)) fmax(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800429FN_FUNC_FN_FN(fmax);
430FN_FUNC_FN_F(fmax);
Jason Sams22fa3712010-05-19 17:22:57 -0700431
Jason Samsef823642011-08-31 14:52:08 -0700432/**
433 * Return (x > y ? y : x)
434 *
435 * @param x: may be float, float2, float3, float4
436 * @param y: may be float or vector. If vector must match type of x.
437 */
Stephen Hines52132472013-04-30 15:45:22 -0700438extern float __attribute__((const, overloadable)) fmin(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800439FN_FUNC_FN_FN(fmin);
440FN_FUNC_FN_F(fmin);
Jason Sams22fa3712010-05-19 17:22:57 -0700441
Jason Samsef823642011-08-31 14:52:08 -0700442/**
443 * Return the remainder from x / y
444 *
445 * Supports float, float2, float3, float4.
446 */
Stephen Hines52132472013-04-30 15:45:22 -0700447extern float __attribute__((const, overloadable)) fmod(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800448FN_FUNC_FN_FN(fmod)
Jason Sams22fa3712010-05-19 17:22:57 -0700449
Tim Murray4d3201d2013-01-03 11:58:39 -0800450/**
451 * Return fractional part of v
452 *
Jason Samsef823642011-08-31 14:52:08 -0700453 * @param iptr iptr[0] will be set to the floor of the input value.
454 * Supports float, float2, float3, float4.
455 */
Stephen Hines52132472013-04-30 15:45:22 -0700456_RS_RUNTIME float __attribute__((pure, overloadable)) fract(float v, float *iptr);
Stephen Hines47b15302011-01-19 18:06:34 -0800457FN_FUNC_FN_PFN(fract)
Jason Sams22fa3712010-05-19 17:22:57 -0700458
Jason Samsef823642011-08-31 14:52:08 -0700459/**
Stephen Hines891bcfe2013-01-16 18:46:43 -0800460 * Return fractional part of v
461 *
462 * Supports float, float2, float3, float4.
463 */
Stephen Hines52132472013-04-30 15:45:22 -0700464static inline float __attribute__((const, overloadable)) fract(float v) {
Stephen Hines891bcfe2013-01-16 18:46:43 -0800465 float unused;
466 return fract(v, &unused);
467}
468
Stephen Hines52132472013-04-30 15:45:22 -0700469static inline float2 __attribute__((const, overloadable)) fract(float2 v) {
Stephen Hines891bcfe2013-01-16 18:46:43 -0800470 float2 unused;
471 return fract(v, &unused);
472}
473
Stephen Hines52132472013-04-30 15:45:22 -0700474static inline float3 __attribute__((const, overloadable)) fract(float3 v) {
Stephen Hines891bcfe2013-01-16 18:46:43 -0800475 float3 unused;
476 return fract(v, &unused);
477}
478
Stephen Hines52132472013-04-30 15:45:22 -0700479static inline float4 __attribute__((const, overloadable)) fract(float4 v) {
Stephen Hines891bcfe2013-01-16 18:46:43 -0800480 float4 unused;
481 return fract(v, &unused);
482}
483
484/**
Jason Samsef823642011-08-31 14:52:08 -0700485 * Return the mantissa and place the exponent into iptr[0]
486 *
487 * @param v Supports float, float2, float3, float4.
488 * @param iptr Must have the same vector size as v.
489 */
Stephen Hines52132472013-04-30 15:45:22 -0700490extern float __attribute__((pure, overloadable)) frexp(float v, int *iptr);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800491FN_FUNC_FN_PIN(frexp)
Jason Sams22fa3712010-05-19 17:22:57 -0700492
Jason Samsef823642011-08-31 14:52:08 -0700493/**
494 * Return sqrt(x*x + y*y)
495 *
496 * Supports float, float2, float3, float4.
497 */
Stephen Hines52132472013-04-30 15:45:22 -0700498extern float __attribute__((const, overloadable)) hypot(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800499FN_FUNC_FN_FN(hypot)
Jason Sams22fa3712010-05-19 17:22:57 -0700500
Jason Samsef823642011-08-31 14:52:08 -0700501/**
502 * Return the integer exponent of a value
503 *
504 * Supports 1,2,3,4 components
505 */
Stephen Hines52132472013-04-30 15:45:22 -0700506extern int __attribute__((const, overloadable)) ilogb(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800507IN_FUNC_FN(ilogb)
Jason Sams22fa3712010-05-19 17:22:57 -0700508
Jason Samsef823642011-08-31 14:52:08 -0700509/**
510 * Return (x * 2^y)
511 *
512 * @param x Supports 1,2,3,4 components
513 * @param y Supports single component or matching vector.
514 */
Stephen Hines52132472013-04-30 15:45:22 -0700515extern float __attribute__((const, overloadable)) ldexp(float x, int y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800516FN_FUNC_FN_IN(ldexp)
517FN_FUNC_FN_I(ldexp)
Jason Sams22fa3712010-05-19 17:22:57 -0700518
Jason Samsef823642011-08-31 14:52:08 -0700519/**
520 * Return the log gamma
521 *
522 * Supports 1,2,3,4 components
523 */
Stephen Hines52132472013-04-30 15:45:22 -0700524extern float __attribute__((const, overloadable)) lgamma(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800525FN_FUNC_FN(lgamma)
Jason Samsef823642011-08-31 14:52:08 -0700526
527/**
528 * Return the log gamma and sign
529 *
530 * @param x Supports 1,2,3,4 components
531 * @param y Supports matching vector.
532 */
Stephen Hines52132472013-04-30 15:45:22 -0700533extern float __attribute__((pure, overloadable)) lgamma(float x, int* y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800534FN_FUNC_FN_PIN(lgamma)
Jason Sams22fa3712010-05-19 17:22:57 -0700535
Jason Samsef823642011-08-31 14:52:08 -0700536/**
537 * Return the natural logarithm
538 *
539 * Supports 1,2,3,4 components
540 */
Stephen Hines52132472013-04-30 15:45:22 -0700541extern float __attribute__((const, overloadable)) log(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800542FN_FUNC_FN(log)
Jason Sams22fa3712010-05-19 17:22:57 -0700543
Jason Samsef823642011-08-31 14:52:08 -0700544/**
545 * Return the base 10 logarithm
546 *
547 * Supports 1,2,3,4 components
548 */
Stephen Hines52132472013-04-30 15:45:22 -0700549extern float __attribute__((const, overloadable)) log10(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800550FN_FUNC_FN(log10)
Jason Sams1b937f52010-06-09 14:26:16 -0700551
Jason Samsef823642011-08-31 14:52:08 -0700552/**
553 * Return the base 2 logarithm
554 *
555 * Supports 1,2,3,4 components
556 */
Stephen Hines52132472013-04-30 15:45:22 -0700557_RS_RUNTIME float __attribute__((const, overloadable)) log2(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800558FN_FUNC_FN(log2)
Jason Sams22fa3712010-05-19 17:22:57 -0700559
Jason Samsef823642011-08-31 14:52:08 -0700560/**
561 * Return the natural logarithm of (v + 1.0f)
562 *
563 * Supports 1,2,3,4 components
564 */
Stephen Hines52132472013-04-30 15:45:22 -0700565extern float __attribute__((const, overloadable)) log1p(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800566FN_FUNC_FN(log1p)
Jason Sams22fa3712010-05-19 17:22:57 -0700567
Jason Samsef823642011-08-31 14:52:08 -0700568/**
569 * Compute the exponent of the value.
570 *
571 * Supports 1,2,3,4 components
572 */
Stephen Hines52132472013-04-30 15:45:22 -0700573extern float __attribute__((const, overloadable)) logb(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800574FN_FUNC_FN(logb)
Jason Sams22fa3712010-05-19 17:22:57 -0700575
Jason Samsef823642011-08-31 14:52:08 -0700576/**
577 * Compute (a * b) + c
578 *
579 * Supports 1,2,3,4 components
580 */
Stephen Hines52132472013-04-30 15:45:22 -0700581extern float __attribute__((const, overloadable)) mad(float a, float b, float c);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800582FN_FUNC_FN_FN_FN(mad)
Jason Sams22fa3712010-05-19 17:22:57 -0700583
Jason Samsef823642011-08-31 14:52:08 -0700584/**
Stephen Hinescb058022012-05-29 17:10:05 -0700585 * Return the integral and fractional components of a number.
Jason Samsef823642011-08-31 14:52:08 -0700586 * Supports 1,2,3,4 components
587 *
588 * @param x Source value
589 * @param iret iret[0] will be set to the integral portion of the number.
590 * @return The floating point portion of the value.
591 */
Stephen Hines52132472013-04-30 15:45:22 -0700592extern float __attribute__((pure, overloadable)) modf(float x, float *iret);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800593FN_FUNC_FN_PFN(modf);
Jason Sams22fa3712010-05-19 17:22:57 -0700594
Stephen Hines52132472013-04-30 15:45:22 -0700595extern float __attribute__((const, overloadable)) nan(uint);
Jason Sams22fa3712010-05-19 17:22:57 -0700596
Jason Samsef823642011-08-31 14:52:08 -0700597/**
598 * Return the next floating point number from x towards y.
599 *
600 * Supports 1,2,3,4 components
601 */
Stephen Hines52132472013-04-30 15:45:22 -0700602extern float __attribute__((const, overloadable)) nextafter(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800603FN_FUNC_FN_FN(nextafter)
Jason Sams22fa3712010-05-19 17:22:57 -0700604
Jason Samsef823642011-08-31 14:52:08 -0700605/**
606 * Return (v ^ p).
607 *
608 * Supports 1,2,3,4 components
609 */
Stephen Hines52132472013-04-30 15:45:22 -0700610_RS_RUNTIME float __attribute__((const, overloadable)) pown(float v, int p);
Jason Samsef823642011-08-31 14:52:08 -0700611FN_FUNC_FN_IN(pown)
Jason Sams22fa3712010-05-19 17:22:57 -0700612
Jason Samsef823642011-08-31 14:52:08 -0700613/**
614 * Return (v ^ p).
615 * @param v must be greater than 0.
616 *
617 * Supports 1,2,3,4 components
618 */
Stephen Hines52132472013-04-30 15:45:22 -0700619_RS_RUNTIME float __attribute__((const, overloadable)) powr(float v, float p);
Jason Samsef823642011-08-31 14:52:08 -0700620FN_FUNC_FN_FN(powr)
Jason Sams22fa3712010-05-19 17:22:57 -0700621
Jason Samsef823642011-08-31 14:52:08 -0700622/**
623 * Return round x/y to the nearest integer then compute the remander.
624 *
625 * Supports 1,2,3,4 components
626 */
Stephen Hines52132472013-04-30 15:45:22 -0700627extern float __attribute__((const, overloadable)) remainder(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800628FN_FUNC_FN_FN(remainder)
Jason Sams22fa3712010-05-19 17:22:57 -0700629
Jason Samsef823642011-08-31 14:52:08 -0700630// document once we know the precision of bionic
Stephen Hines52132472013-04-30 15:45:22 -0700631extern float __attribute__((pure, overloadable)) remquo(float, float, int *);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800632FN_FUNC_FN_FN_PIN(remquo)
Jason Sams22fa3712010-05-19 17:22:57 -0700633
Jason Samsef823642011-08-31 14:52:08 -0700634/**
635 * Round to the nearest integral value.
636 *
637 * Supports 1,2,3,4 components
638 */
Stephen Hines52132472013-04-30 15:45:22 -0700639extern float __attribute__((const, overloadable)) rint(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800640FN_FUNC_FN(rint)
Jason Sams22fa3712010-05-19 17:22:57 -0700641
Jason Samsef823642011-08-31 14:52:08 -0700642/**
643 * Compute the Nth root of a value.
644 *
645 * Supports 1,2,3,4 components
646 */
Stephen Hines52132472013-04-30 15:45:22 -0700647_RS_RUNTIME float __attribute__((const, overloadable)) rootn(float v, int n);
Jason Samsef823642011-08-31 14:52:08 -0700648FN_FUNC_FN_IN(rootn)
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800649
Jason Samsef823642011-08-31 14:52:08 -0700650/**
651 * Round to the nearest integral value. Half values are rounded away from zero.
652 *
653 * Supports 1,2,3,4 components
654 */
Stephen Hines52132472013-04-30 15:45:22 -0700655extern float __attribute__((const, overloadable)) round(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800656FN_FUNC_FN(round)
Jason Sams22fa3712010-05-19 17:22:57 -0700657
Jason Samsef823642011-08-31 14:52:08 -0700658/**
659 * Return the square root of a value.
660 *
661 * Supports 1,2,3,4 components
662 */
Stephen Hines52132472013-04-30 15:45:22 -0700663extern float __attribute__((const, overloadable)) sqrt(float);
Jason Samsef823642011-08-31 14:52:08 -0700664FN_FUNC_FN(sqrt)
665
666/**
667 * Return (1 / sqrt(value)).
668 *
Jason Samsef823642011-08-31 14:52:08 -0700669 * Supports 1,2,3,4 components
670 */
Stephen Hines52132472013-04-30 15:45:22 -0700671_RS_RUNTIME float __attribute__((const, overloadable)) rsqrt(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800672FN_FUNC_FN(rsqrt)
Jason Sams1b937f52010-06-09 14:26:16 -0700673
Jason Samsef823642011-08-31 14:52:08 -0700674/**
675 * Return the sine of a value specified in radians.
676 *
677 * @param v The incoming value in radians
678 * Supports 1,2,3,4 components
679 */
Stephen Hines52132472013-04-30 15:45:22 -0700680extern float __attribute__((const, overloadable)) sin(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800681FN_FUNC_FN(sin)
Jason Sams1b937f52010-06-09 14:26:16 -0700682
Jason Samsef823642011-08-31 14:52:08 -0700683/**
684 * Return the sine and cosine of a value.
685 *
686 * @return sine
687 * @param v The incoming value in radians
688 * @param *cosptr cosptr[0] will be set to the cosine value.
689 *
690 * Supports 1,2,3,4 components
691 */
Stephen Hines52132472013-04-30 15:45:22 -0700692_RS_RUNTIME float __attribute__((pure, overloadable)) sincos(float v, float *cosptr);
Jason Samsef823642011-08-31 14:52:08 -0700693FN_FUNC_FN_PFN(sincos);
Jason Sams1b937f52010-06-09 14:26:16 -0700694
Jason Samsef823642011-08-31 14:52:08 -0700695/**
696 * Return the hyperbolic sine of a value specified in radians.
697 *
698 * Supports 1,2,3,4 components
699 */
Stephen Hines52132472013-04-30 15:45:22 -0700700extern float __attribute__((const, overloadable)) sinh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800701FN_FUNC_FN(sinh)
Jason Sams1b937f52010-06-09 14:26:16 -0700702
Jason Samsef823642011-08-31 14:52:08 -0700703/**
704 * Return the sin(v * PI).
705 *
706 * Supports 1,2,3,4 components
707 */
Stephen Hines52132472013-04-30 15:45:22 -0700708_RS_RUNTIME float __attribute__((const, overloadable)) sinpi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800709FN_FUNC_FN(sinpi)
Jason Sams1b937f52010-06-09 14:26:16 -0700710
Jason Samsef823642011-08-31 14:52:08 -0700711/**
712 * Return the tangent of a value.
713 *
714 * Supports 1,2,3,4 components
715 * @param v The incoming value in radians
716 */
Stephen Hines52132472013-04-30 15:45:22 -0700717extern float __attribute__((const, overloadable)) tan(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800718FN_FUNC_FN(tan)
Jason Sams22fa3712010-05-19 17:22:57 -0700719
Jason Samsef823642011-08-31 14:52:08 -0700720/**
721 * Return the hyperbolic tangent of a value.
722 *
723 * Supports 1,2,3,4 components
724 * @param v The incoming value in radians
725 */
Stephen Hines52132472013-04-30 15:45:22 -0700726extern float __attribute__((const, overloadable)) tanh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800727FN_FUNC_FN(tanh)
Jason Sams22fa3712010-05-19 17:22:57 -0700728
Jason Samsef823642011-08-31 14:52:08 -0700729/**
730 * Return tan(v * PI)
731 *
732 * Supports 1,2,3,4 components
733 */
Stephen Hines52132472013-04-30 15:45:22 -0700734_RS_RUNTIME float __attribute__((const, overloadable)) tanpi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800735FN_FUNC_FN(tanpi)
Jason Sams22fa3712010-05-19 17:22:57 -0700736
Jason Samsef823642011-08-31 14:52:08 -0700737/**
738 * Compute the gamma function of a value.
739 *
740 * Supports 1,2,3,4 components
741 */
Stephen Hines52132472013-04-30 15:45:22 -0700742extern float __attribute__((const, overloadable)) tgamma(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800743FN_FUNC_FN(tgamma)
Jason Sams22fa3712010-05-19 17:22:57 -0700744
Jason Samsef823642011-08-31 14:52:08 -0700745/**
746 * Round to integral using truncation.
747 *
748 * Supports 1,2,3,4 components
749 */
Stephen Hines52132472013-04-30 15:45:22 -0700750extern float __attribute__((const, overloadable)) trunc(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800751FN_FUNC_FN(trunc)
Jason Sams22fa3712010-05-19 17:22:57 -0700752
Jason Sams22fa3712010-05-19 17:22:57 -0700753
Stephen Hines52132472013-04-30 15:45:22 -0700754#define XN_FUNC_YN(typeout, fnc, typein) \
755extern typeout __attribute__((const, overloadable)) fnc(typein); \
756_RS_RUNTIME typeout##2 __attribute__((const, overloadable)) fnc(typein##2 v); \
757_RS_RUNTIME typeout##3 __attribute__((const, overloadable)) fnc(typein##3 v); \
758_RS_RUNTIME typeout##4 __attribute__((const, overloadable)) fnc(typein##4 v);
Jason Sams22fa3712010-05-19 17:22:57 -0700759
Stephen Hines47b15302011-01-19 18:06:34 -0800760#define UIN_FUNC_IN(fnc) \
Stephen Hines3e6482f2011-01-19 12:51:33 -0800761XN_FUNC_YN(uchar, fnc, char) \
762XN_FUNC_YN(ushort, fnc, short) \
763XN_FUNC_YN(uint, fnc, int)
Jason Sams22fa3712010-05-19 17:22:57 -0700764
Stephen Hines47b15302011-01-19 18:06:34 -0800765#define IN_FUNC_IN(fnc) \
Stephen Hines3e6482f2011-01-19 12:51:33 -0800766XN_FUNC_YN(uchar, fnc, uchar) \
767XN_FUNC_YN(char, fnc, char) \
768XN_FUNC_YN(ushort, fnc, ushort) \
769XN_FUNC_YN(short, fnc, short) \
770XN_FUNC_YN(uint, fnc, uint) \
771XN_FUNC_YN(int, fnc, int)
Jason Sams22fa3712010-05-19 17:22:57 -0700772
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800773
Stephen Hines52132472013-04-30 15:45:22 -0700774#define XN_FUNC_XN_XN_BODY(type, fnc, body) \
775_RS_RUNTIME type __attribute__((const, overloadable)) \
776 fnc(type v1, type v2); \
777_RS_RUNTIME type##2 __attribute__((const, overloadable)) \
778 fnc(type##2 v1, type##2 v2); \
779_RS_RUNTIME type##3 __attribute__((const, overloadable)) \
780 fnc(type##3 v1, type##3 v2); \
781_RS_RUNTIME type##4 __attribute__((const, overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800782 fnc(type##4 v1, type##4 v2);
Jason Sams22fa3712010-05-19 17:22:57 -0700783
Stephen Hinescb058022012-05-29 17:10:05 -0700784#define IN_FUNC_IN_IN_BODY(fnc, body) \
785XN_FUNC_XN_XN_BODY(uchar, fnc, body) \
786XN_FUNC_XN_XN_BODY(char, fnc, body) \
787XN_FUNC_XN_XN_BODY(ushort, fnc, body) \
788XN_FUNC_XN_XN_BODY(short, fnc, body) \
789XN_FUNC_XN_XN_BODY(uint, fnc, body) \
790XN_FUNC_XN_XN_BODY(int, fnc, body) \
Stephen Hines3e6482f2011-01-19 12:51:33 -0800791XN_FUNC_XN_XN_BODY(float, fnc, body)
Stephen Hinesb902e4c2011-01-14 18:49:01 -0800792
Stephen Hinescb058022012-05-29 17:10:05 -0700793/**
794 * Return the absolute value of a value.
795 *
796 * Supports 1,2,3,4 components of char, short, int.
797 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800798UIN_FUNC_IN(abs)
Stephen Hinescb058022012-05-29 17:10:05 -0700799
800/**
801 * Return the number of leading 0-bits in a value.
802 *
803 * Supports 1,2,3,4 components of uchar, char, ushort, short, uint, int.
804 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800805IN_FUNC_IN(clz)
Stephen Hinesb902e4c2011-01-14 18:49:01 -0800806
Jason Samsdc2c3e62011-08-31 16:44:18 -0700807/**
808 * Return the minimum of two values.
809 *
810 * Supports 1,2,3,4 components of uchar, char, ushort, short, uint, int, float.
811 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800812IN_FUNC_IN_IN_BODY(min, (v1 < v2 ? v1 : v2))
813FN_FUNC_FN_F(min)
Stephen Hinesb902e4c2011-01-14 18:49:01 -0800814
Jason Samsdc2c3e62011-08-31 16:44:18 -0700815/**
816 * Return the maximum of two values.
817 *
818 * Supports 1,2,3,4 components of uchar, char, ushort, short, uint, int, float.
819 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800820IN_FUNC_IN_IN_BODY(max, (v1 > v2 ? v1 : v2))
821FN_FUNC_FN_F(max)
Jason Sams22fa3712010-05-19 17:22:57 -0700822
Jason Samsdc2c3e62011-08-31 16:44:18 -0700823/**
824 * Clamp a value to a specified high and low bound.
825 *
826 * @param amount value to be clamped. Supports 1,2,3,4 components
827 * @param low Lower bound, must be scalar or matching vector.
828 * @param high High bound, must match type of low
829 */
Jason Samsc6261352013-05-24 14:51:52 -0700830
831#if !defined(RS_VERSION) || (RS_VERSION < 19)
Stephen Hines52132472013-04-30 15:45:22 -0700832_RS_RUNTIME float __attribute__((const, overloadable)) clamp(float amount, float low, float high);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700833FN_FUNC_FN_FN_FN(clamp)
834FN_FUNC_FN_F_F(clamp)
Jason Samsc6261352013-05-24 14:51:52 -0700835#else
836#define _CLAMP(T) \
837extern T __attribute__((overloadable)) clamp(T amount, T low, T high); \
838extern T##2 __attribute__((overloadable)) clamp(T##2 amount, T##2 low, T##2 high); \
839extern T##3 __attribute__((overloadable)) clamp(T##3 amount, T##3 low, T##3 high); \
840extern T##4 __attribute__((overloadable)) clamp(T##4 amount, T##4 low, T##4 high); \
841extern T##2 __attribute__((overloadable)) clamp(T##2 amount, T low, T high); \
842extern T##3 __attribute__((overloadable)) clamp(T##3 amount, T low, T high); \
843extern T##4 __attribute__((overloadable)) clamp(T##4 amount, T low, T high)
844
845_CLAMP(float);
846_CLAMP(double);
847_CLAMP(char);
848_CLAMP(uchar);
849_CLAMP(short);
850_CLAMP(ushort);
851_CLAMP(int);
852_CLAMP(uint);
853_CLAMP(long);
854_CLAMP(ulong);
855
856#undef _CLAMP
857#endif
Jason Sams22fa3712010-05-19 17:22:57 -0700858
Jason Samsdc2c3e62011-08-31 16:44:18 -0700859/**
860 * Convert from radians to degrees.
861 *
862 * Supports 1,2,3,4 components
863 */
Stephen Hines52132472013-04-30 15:45:22 -0700864_RS_RUNTIME float __attribute__((const, overloadable)) degrees(float radians);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800865FN_FUNC_FN(degrees)
Jason Sams22fa3712010-05-19 17:22:57 -0700866
Jason Samsdc2c3e62011-08-31 16:44:18 -0700867/**
868 * return start + ((stop - start) * amount);
869 *
870 * Supports 1,2,3,4 components
871 */
Stephen Hines52132472013-04-30 15:45:22 -0700872_RS_RUNTIME float __attribute__((const, overloadable)) mix(float start, float stop, float amount);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700873FN_FUNC_FN_FN_FN(mix)
874FN_FUNC_FN_FN_F(mix)
Jason Sams22fa3712010-05-19 17:22:57 -0700875
Jason Samsdc2c3e62011-08-31 16:44:18 -0700876/**
877 * Convert from degrees to radians.
878 *
879 * Supports 1,2,3,4 components
880 */
Stephen Hines52132472013-04-30 15:45:22 -0700881_RS_RUNTIME float __attribute__((const, overloadable)) radians(float degrees);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800882FN_FUNC_FN(radians)
Jason Sams22fa3712010-05-19 17:22:57 -0700883
Jason Samsdc2c3e62011-08-31 16:44:18 -0700884/**
885 * if (v < edge)
886 * return 0.f;
887 * else
888 * return 1.f;
889 *
890 * Supports 1,2,3,4 components
891 */
Stephen Hines52132472013-04-30 15:45:22 -0700892_RS_RUNTIME float __attribute__((const, overloadable)) step(float edge, float v);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700893FN_FUNC_FN_FN(step)
894FN_FUNC_FN_F(step)
Jason Sams22fa3712010-05-19 17:22:57 -0700895
Jason Samsdc2c3e62011-08-31 16:44:18 -0700896// not implemented
Stephen Hines52132472013-04-30 15:45:22 -0700897extern float __attribute__((const, overloadable)) smoothstep(float, float, float);
898extern float2 __attribute__((const, overloadable)) smoothstep(float2, float2, float2);
899extern float3 __attribute__((const, overloadable)) smoothstep(float3, float3, float3);
900extern float4 __attribute__((const, overloadable)) smoothstep(float4, float4, float4);
901extern float2 __attribute__((const, overloadable)) smoothstep(float, float, float2);
902extern float3 __attribute__((const, overloadable)) smoothstep(float, float, float3);
903extern float4 __attribute__((const, overloadable)) smoothstep(float, float, float4);
Jason Sams22fa3712010-05-19 17:22:57 -0700904
Jason Samsdc2c3e62011-08-31 16:44:18 -0700905/**
Stephen Hinescb058022012-05-29 17:10:05 -0700906 * Return the sign of a value.
907 *
Jason Samsdc2c3e62011-08-31 16:44:18 -0700908 * if (v < 0) return -1.f;
909 * else if (v > 0) return 1.f;
910 * else return 0.f;
911 *
912 * Supports 1,2,3,4 components
913 */
Stephen Hines52132472013-04-30 15:45:22 -0700914_RS_RUNTIME float __attribute__((const, overloadable)) sign(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800915FN_FUNC_FN(sign)
Jason Sams22fa3712010-05-19 17:22:57 -0700916
Jason Samsdc2c3e62011-08-31 16:44:18 -0700917/**
918 * Compute the cross product of two vectors.
919 *
920 * Supports 3,4 components
921 */
Stephen Hines52132472013-04-30 15:45:22 -0700922_RS_RUNTIME float3 __attribute__((const, overloadable)) cross(float3 lhs, float3 rhs);
923_RS_RUNTIME float4 __attribute__((const, overloadable)) cross(float4 lhs, float4 rhs);
Jason Sams22fa3712010-05-19 17:22:57 -0700924
Jason Samsdc2c3e62011-08-31 16:44:18 -0700925/**
926 * Compute the dot product of two vectors.
927 *
928 * Supports 1,2,3,4 components
929 */
Stephen Hines52132472013-04-30 15:45:22 -0700930_RS_RUNTIME float __attribute__((const, overloadable)) dot(float lhs, float rhs);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700931F_FUNC_FN_FN(dot)
Jason Sams22fa3712010-05-19 17:22:57 -0700932
Jason Samsdc2c3e62011-08-31 16:44:18 -0700933/**
934 * Compute the length of a vector.
935 *
936 * Supports 1,2,3,4 components
937 */
Stephen Hines52132472013-04-30 15:45:22 -0700938_RS_RUNTIME float __attribute__((const, overloadable)) length(float v);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700939F_FUNC_FN(length)
Jason Sams22fa3712010-05-19 17:22:57 -0700940
Jason Samsdc2c3e62011-08-31 16:44:18 -0700941/**
942 * Compute the distance between two points.
943 *
944 * Supports 1,2,3,4 components
945 */
Stephen Hines52132472013-04-30 15:45:22 -0700946_RS_RUNTIME float __attribute__((const, overloadable)) distance(float lhs, float rhs);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700947F_FUNC_FN_FN(distance)
Jason Sams22fa3712010-05-19 17:22:57 -0700948
Jason Samsdc2c3e62011-08-31 16:44:18 -0700949/**
950 * Normalize a vector.
951 *
952 * Supports 1,2,3,4 components
953 */
Stephen Hines52132472013-04-30 15:45:22 -0700954_RS_RUNTIME float __attribute__((const, overloadable)) normalize(float v);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700955FN_FUNC_FN(normalize)
956
Rajeev Sharma7150c932012-08-15 21:41:39 -0700957
958// New approx API functions
959#if (defined(RS_VERSION) && (RS_VERSION >= 17))
960
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700961/**
962 * Return the approximate reciprocal of a value.
963 *
964 * Supports 1,2,3,4 components
965 */
Stephen Hines52132472013-04-30 15:45:22 -0700966_RS_RUNTIME float __attribute__((const, overloadable)) half_recip(float);
Jason Samsab4b0ef2012-09-20 15:39:18 -0700967FN_FUNC_FN(half_recip)
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700968
969/**
970 * Return the approximate square root of a value.
971 *
972 * Supports 1,2,3,4 components
973 */
Stephen Hines52132472013-04-30 15:45:22 -0700974_RS_RUNTIME float __attribute__((const, overloadable)) half_sqrt(float);
Jason Samsab4b0ef2012-09-20 15:39:18 -0700975FN_FUNC_FN(half_sqrt)
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700976
977/**
978 * Return the approximate value of (1 / sqrt(value)).
979 *
980 * Supports 1,2,3,4 components
981 */
Stephen Hines52132472013-04-30 15:45:22 -0700982_RS_RUNTIME float __attribute__((const, overloadable)) half_rsqrt(float v);
Jason Samsab4b0ef2012-09-20 15:39:18 -0700983FN_FUNC_FN(half_rsqrt)
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700984
985/**
986 * Compute the approximate length of a vector.
987 *
988 * Supports 1,2,3,4 components
989 */
Stephen Hines52132472013-04-30 15:45:22 -0700990_RS_RUNTIME float __attribute__((const, overloadable)) fast_length(float v);
Jason Samsab4b0ef2012-09-20 15:39:18 -0700991F_FUNC_FN(fast_length)
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700992
993/**
994 * Compute the approximate distance between two points.
995 *
996 * Supports 1,2,3,4 components
997 */
Stephen Hines52132472013-04-30 15:45:22 -0700998_RS_RUNTIME float __attribute__((const, overloadable)) fast_distance(float lhs, float rhs);
Jason Samsab4b0ef2012-09-20 15:39:18 -0700999F_FUNC_FN_FN(fast_distance)
Rajeev Sharma65723fe2012-08-03 15:11:04 -07001000
1001/**
1002 * Approximately normalize a vector.
1003 *
1004 * Supports 1,2,3,4 components
1005 */
Stephen Hines52132472013-04-30 15:45:22 -07001006_RS_RUNTIME float __attribute__((const, overloadable)) fast_normalize(float v);
Jason Samsab4b0ef2012-09-20 15:39:18 -07001007F_FUNC_FN(fast_normalize)
Rajeev Sharma7150c932012-08-15 21:41:39 -07001008
1009#endif // (defined(RS_VERSION) && (RS_VERSION >= 17))
1010
1011
Jason Sams59531f72013-01-18 14:10:32 -08001012
1013#if (defined(RS_VERSION) && (RS_VERSION >= 18))
1014// Fast native math functions.
1015
1016
1017/**
1018 * Fast approximate exp2
1019 * valid for inputs -125.f to 125.f
1020 * Max 8192 ulps of error
1021 *
1022 * Supports 1,2,3,4 components
1023 */
Stephen Hines52132472013-04-30 15:45:22 -07001024_RS_RUNTIME float __attribute__((const, overloadable)) native_exp2(float v);
Jason Sams59531f72013-01-18 14:10:32 -08001025FN_FUNC_FN(native_exp2)
1026
1027/**
1028 * Fast approximate exp
1029 * valid for inputs -86.f to 86.f
1030 * Max 8192 ulps of error
1031 *
1032 * Supports 1,2,3,4 components
1033 */
Stephen Hines52132472013-04-30 15:45:22 -07001034_RS_RUNTIME float __attribute__((const, overloadable)) native_exp(float v);
Jason Sams59531f72013-01-18 14:10:32 -08001035FN_FUNC_FN(native_exp)
1036
1037/**
1038 * Fast approximate exp10
1039 * valid for inputs -37.f to 37.f
1040 * Max 8192 ulps of error
1041 *
1042 * Supports 1,2,3,4 components
1043 */
Stephen Hines52132472013-04-30 15:45:22 -07001044_RS_RUNTIME float __attribute__((const, overloadable)) native_exp10(float v);
Jason Sams59531f72013-01-18 14:10:32 -08001045FN_FUNC_FN(native_exp10)
1046
1047
Stephen Hines52132472013-04-30 15:45:22 -07001048_RS_RUNTIME float __attribute__((const, overloadable)) native_log2(float v);
Jason Samsaa493952013-01-25 13:21:17 -08001049FN_FUNC_FN(native_log2)
1050
Stephen Hines52132472013-04-30 15:45:22 -07001051_RS_RUNTIME float __attribute__((const, overloadable)) native_log(float v);
Jason Samsaa493952013-01-25 13:21:17 -08001052FN_FUNC_FN(native_log)
1053
Stephen Hines52132472013-04-30 15:45:22 -07001054_RS_RUNTIME float __attribute__((const, overloadable)) native_log10(float v);
Jason Samsaa493952013-01-25 13:21:17 -08001055FN_FUNC_FN(native_log10)
1056
1057
Stephen Hines52132472013-04-30 15:45:22 -07001058_RS_RUNTIME float __attribute__((const, overloadable)) native_powr(float v, float y);
Jason Samsaa493952013-01-25 13:21:17 -08001059FN_FUNC_FN_FN(native_powr)
1060
1061
Jason Sams59531f72013-01-18 14:10:32 -08001062#endif // (defined(RS_VERSION) && (RS_VERSION >= 18))
1063
1064
Stephen Hines47416532011-01-11 14:38:18 -08001065#undef CVT_FUNC
1066#undef CVT_FUNC_2
Stephen Hines3e6482f2011-01-19 12:51:33 -08001067#undef FN_FUNC_FN
Rajeev Sharma65723fe2012-08-03 15:11:04 -07001068#undef F_FUNC_FN
Stephen Hines3e6482f2011-01-19 12:51:33 -08001069#undef IN_FUNC_FN
1070#undef FN_FUNC_FN_FN
Rajeev Sharma65723fe2012-08-03 15:11:04 -07001071#undef F_FUNC_FN_FN
Stephen Hines3e6482f2011-01-19 12:51:33 -08001072#undef FN_FUNC_FN_F
1073#undef FN_FUNC_FN_IN
1074#undef FN_FUNC_FN_I
1075#undef FN_FUNC_FN_PFN
1076#undef FN_FUNC_FN_PIN
1077#undef FN_FUNC_FN_FN_FN
Rajeev Sharma65723fe2012-08-03 15:11:04 -07001078#undef FN_FUNC_FN_FN_F
1079#undef FN_FUNC_FN_F_F
Stephen Hines3e6482f2011-01-19 12:51:33 -08001080#undef FN_FUNC_FN_FN_PIN
1081#undef XN_FUNC_YN
1082#undef UIN_FUNC_IN
1083#undef IN_FUNC_IN
1084#undef XN_FUNC_XN_XN_BODY
1085#undef IN_FUNC_IN_IN_BODY
Jason Sams1b937f52010-06-09 14:26:16 -07001086
1087#endif