blob: 74f0ad9efd91fefd38eaf2364f8464bc58ac59fa [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 Hinescb058022012-05-29 17:10:05 -070028_RS_RUNTIME typeout##2 __attribute__((overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -080029 convert_##typeout##2(typein##2 v); \
Stephen Hinescb058022012-05-29 17:10:05 -070030_RS_RUNTIME typeout##3 __attribute__((overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -080031 convert_##typeout##3(typein##3 v); \
Stephen Hinescb058022012-05-29 17:10:05 -070032_RS_RUNTIME typeout##4 __attribute__((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 Hines47b15302011-01-19 18:06:34 -080095#define FN_FUNC_FN(fnc) \
Stephen Hinescb058022012-05-29 17:10:05 -070096_RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v); \
97_RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v); \
Shih-wei Liaoe31775b2011-01-26 17:04:31 -080098_RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v);
Jason Sams1b937f52010-06-09 14:26:16 -070099
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700100#define F_FUNC_FN(fnc) \
101_RS_RUNTIME float __attribute__((overloadable)) fnc(float2 v); \
102_RS_RUNTIME float __attribute__((overloadable)) fnc(float3 v); \
103_RS_RUNTIME float __attribute__((overloadable)) fnc(float4 v);
104
Stephen Hines47b15302011-01-19 18:06:34 -0800105#define IN_FUNC_FN(fnc) \
Stephen Hinescb058022012-05-29 17:10:05 -0700106_RS_RUNTIME int2 __attribute__((overloadable)) fnc(float2 v); \
107_RS_RUNTIME int3 __attribute__((overloadable)) fnc(float3 v); \
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800108_RS_RUNTIME int4 __attribute__((overloadable)) fnc(float4 v);
Stephen Hines47416532011-01-11 14:38:18 -0800109
Stephen Hines47b15302011-01-19 18:06:34 -0800110#define FN_FUNC_FN_FN(fnc) \
Stephen Hinescb058022012-05-29 17:10:05 -0700111_RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, float2 v2); \
112_RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, float3 v2); \
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800113_RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, float4 v2);
Jason Sams1b937f52010-06-09 14:26:16 -0700114
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700115#define F_FUNC_FN_FN(fnc) \
116_RS_RUNTIME float __attribute__((overloadable)) fnc(float2 v1, float2 v2); \
117_RS_RUNTIME float __attribute__((overloadable)) fnc(float3 v1, float3 v2); \
118_RS_RUNTIME float __attribute__((overloadable)) fnc(float4 v1, float4 v2);
119
Stephen Hines47b15302011-01-19 18:06:34 -0800120#define FN_FUNC_FN_F(fnc) \
Stephen Hinescb058022012-05-29 17:10:05 -0700121_RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, float v2); \
122_RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, float v2); \
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800123_RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, float v2);
Jason Sams1b937f52010-06-09 14:26:16 -0700124
Stephen Hines47b15302011-01-19 18:06:34 -0800125#define FN_FUNC_FN_IN(fnc) \
Stephen Hinescb058022012-05-29 17:10:05 -0700126_RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, int2 v2); \
127_RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, int3 v2); \
128_RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, int4 v2); \
Stephen Hines3e6482f2011-01-19 12:51:33 -0800129
Stephen Hines47b15302011-01-19 18:06:34 -0800130#define FN_FUNC_FN_I(fnc) \
Stephen Hinescb058022012-05-29 17:10:05 -0700131_RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, int v2); \
132_RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, int v2); \
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800133_RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, int v2);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800134
Stephen Hinescb058022012-05-29 17:10:05 -0700135#define FN_FUNC_FN_PFN(fnc) \
136_RS_RUNTIME float2 __attribute__((overloadable)) \
137 fnc(float2 v1, float2 *v2); \
138_RS_RUNTIME float3 __attribute__((overloadable)) \
139 fnc(float3 v1, float3 *v2); \
140_RS_RUNTIME float4 __attribute__((overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800141 fnc(float4 v1, float4 *v2);
Jason Sams1b937f52010-06-09 14:26:16 -0700142
Stephen Hines47b15302011-01-19 18:06:34 -0800143#define FN_FUNC_FN_PIN(fnc) \
Stephen Hinescb058022012-05-29 17:10:05 -0700144_RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, int2 *v2); \
145_RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, int3 *v2); \
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800146_RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, int4 *v2);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800147
Stephen Hinescb058022012-05-29 17:10:05 -0700148#define FN_FUNC_FN_FN_FN(fnc) \
149_RS_RUNTIME float2 __attribute__((overloadable)) \
150 fnc(float2 v1, float2 v2, float2 v3); \
151_RS_RUNTIME float3 __attribute__((overloadable)) \
152 fnc(float3 v1, float3 v2, float3 v3); \
153_RS_RUNTIME float4 __attribute__((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
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700156#define FN_FUNC_FN_FN_F(fnc) \
157_RS_RUNTIME float2 __attribute__((overloadable)) \
158 fnc(float2 v1, float2 v2, float v3); \
159_RS_RUNTIME float3 __attribute__((overloadable)) \
160 fnc(float3 v1, float3 v2, float v3); \
161_RS_RUNTIME float4 __attribute__((overloadable)) \
162 fnc(float4 v1, float4 v2, float v3);
163
164#define FN_FUNC_FN_F_F(fnc) \
165_RS_RUNTIME float2 __attribute__((overloadable)) \
166 fnc(float2 v1, float v2, float v3); \
167_RS_RUNTIME float3 __attribute__((overloadable)) \
168 fnc(float3 v1, float v2, float v3); \
169_RS_RUNTIME float4 __attribute__((overloadable)) \
170 fnc(float4 v1, float v2, float v3);
171
Stephen Hinescb058022012-05-29 17:10:05 -0700172#define FN_FUNC_FN_FN_PIN(fnc) \
173_RS_RUNTIME float2 __attribute__((overloadable)) \
174 fnc(float2 v1, float2 v2, int2 *v3); \
175_RS_RUNTIME float3 __attribute__((overloadable)) \
176 fnc(float3 v1, float3 v2, int3 *v3); \
177_RS_RUNTIME float4 __attribute__((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 */
Jason Sams22fa3712010-05-19 17:22:57 -0700186extern float __attribute__((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 */
Jason Sams22fa3712010-05-19 17:22:57 -0700194extern float __attribute__((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 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800202_RS_RUNTIME float __attribute__((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 */
Jason Sams22fa3712010-05-19 17:22:57 -0700210extern float __attribute__((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 */
Jason Sams22fa3712010-05-19 17:22:57 -0700218extern float __attribute__((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 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800227_RS_RUNTIME float __attribute__((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 */
Jason Sams22fa3712010-05-19 17:22:57 -0700235extern float __attribute__((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 */
247extern float __attribute__((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 */
Jason Sams22fa3712010-05-19 17:22:57 -0700255extern float __attribute__((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 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800263_RS_RUNTIME float __attribute__((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 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800275_RS_RUNTIME float __attribute__((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 */
Jason Sams22fa3712010-05-19 17:22:57 -0700284extern float __attribute__((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 */
Jason Sams22fa3712010-05-19 17:22:57 -0700292extern float __attribute__((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 */
304extern float __attribute__((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 */
Jason Sams22fa3712010-05-19 17:22:57 -0700312extern float __attribute__((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 */
Jason Sams22fa3712010-05-19 17:22:57 -0700320extern float __attribute__((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 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800328_RS_RUNTIME float __attribute__((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 */
Jason Sams22fa3712010-05-19 17:22:57 -0700336extern float __attribute__((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 */
Jason Sams22fa3712010-05-19 17:22:57 -0700344extern float __attribute__((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 */
Jason Sams22fa3712010-05-19 17:22:57 -0700352extern float __attribute__((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 */
Jason Sams22fa3712010-05-19 17:22:57 -0700360extern float __attribute__((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 */
369extern float __attribute__((overloadable)) pow(float x, float y);
370FN_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 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800377_RS_RUNTIME float __attribute__((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 */
Jason Sams22fa3712010-05-19 17:22:57 -0700385extern float __attribute__((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 */
Jason Sams22fa3712010-05-19 17:22:57 -0700393extern float __attribute__((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 */
Jason Sams22fa3712010-05-19 17:22:57 -0700402extern float __attribute__((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 */
Jason Sams22fa3712010-05-19 17:22:57 -0700410extern float __attribute__((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 */
418extern float __attribute__((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 */
428extern float __attribute__((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 */
438extern float __attribute__((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 */
447extern float __attribute__((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
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800450
Jason Samsef823642011-08-31 14:52:08 -0700451/**
452 * Return fractional part of v
453 *
454 * @param iptr iptr[0] will be set to the floor of the input value.
455 * Supports float, float2, float3, float4.
456 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800457_RS_RUNTIME float __attribute__((overloadable)) fract(float v, float *iptr);
Stephen Hines47b15302011-01-19 18:06:34 -0800458FN_FUNC_FN_PFN(fract)
Jason Sams22fa3712010-05-19 17:22:57 -0700459
Jason Samsef823642011-08-31 14:52:08 -0700460/**
461 * Return the mantissa and place the exponent into iptr[0]
462 *
463 * @param v Supports float, float2, float3, float4.
464 * @param iptr Must have the same vector size as v.
465 */
466extern float __attribute__((overloadable)) frexp(float v, int *iptr);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800467FN_FUNC_FN_PIN(frexp)
Jason Sams22fa3712010-05-19 17:22:57 -0700468
Jason Samsef823642011-08-31 14:52:08 -0700469/**
470 * Return sqrt(x*x + y*y)
471 *
472 * Supports float, float2, float3, float4.
473 */
474extern float __attribute__((overloadable)) hypot(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800475FN_FUNC_FN_FN(hypot)
Jason Sams22fa3712010-05-19 17:22:57 -0700476
Jason Samsef823642011-08-31 14:52:08 -0700477/**
478 * Return the integer exponent of a value
479 *
480 * Supports 1,2,3,4 components
481 */
Jason Sams22fa3712010-05-19 17:22:57 -0700482extern int __attribute__((overloadable)) ilogb(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800483IN_FUNC_FN(ilogb)
Jason Sams22fa3712010-05-19 17:22:57 -0700484
Jason Samsef823642011-08-31 14:52:08 -0700485/**
486 * Return (x * 2^y)
487 *
488 * @param x Supports 1,2,3,4 components
489 * @param y Supports single component or matching vector.
490 */
491extern float __attribute__((overloadable)) ldexp(float x, int y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800492FN_FUNC_FN_IN(ldexp)
493FN_FUNC_FN_I(ldexp)
Jason Sams22fa3712010-05-19 17:22:57 -0700494
Jason Samsef823642011-08-31 14:52:08 -0700495/**
496 * Return the log gamma
497 *
498 * Supports 1,2,3,4 components
499 */
Jason Sams22fa3712010-05-19 17:22:57 -0700500extern float __attribute__((overloadable)) lgamma(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800501FN_FUNC_FN(lgamma)
Jason Samsef823642011-08-31 14:52:08 -0700502
503/**
504 * Return the log gamma and sign
505 *
506 * @param x Supports 1,2,3,4 components
507 * @param y Supports matching vector.
508 */
509extern float __attribute__((overloadable)) lgamma(float x, int* y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800510FN_FUNC_FN_PIN(lgamma)
Jason Sams22fa3712010-05-19 17:22:57 -0700511
Jason Samsef823642011-08-31 14:52:08 -0700512/**
513 * Return the natural logarithm
514 *
515 * Supports 1,2,3,4 components
516 */
Jason Sams22fa3712010-05-19 17:22:57 -0700517extern float __attribute__((overloadable)) log(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800518FN_FUNC_FN(log)
Jason Sams22fa3712010-05-19 17:22:57 -0700519
Jason Samsef823642011-08-31 14:52:08 -0700520/**
521 * Return the base 10 logarithm
522 *
523 * Supports 1,2,3,4 components
524 */
Jason Sams22fa3712010-05-19 17:22:57 -0700525extern float __attribute__((overloadable)) log10(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800526FN_FUNC_FN(log10)
Jason Sams1b937f52010-06-09 14:26:16 -0700527
Jason Samsef823642011-08-31 14:52:08 -0700528/**
529 * Return the base 2 logarithm
530 *
531 * Supports 1,2,3,4 components
532 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800533_RS_RUNTIME float __attribute__((overloadable)) log2(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800534FN_FUNC_FN(log2)
Jason Sams22fa3712010-05-19 17:22:57 -0700535
Jason Samsef823642011-08-31 14:52:08 -0700536/**
537 * Return the natural logarithm of (v + 1.0f)
538 *
539 * Supports 1,2,3,4 components
540 */
541extern float __attribute__((overloadable)) log1p(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800542FN_FUNC_FN(log1p)
Jason Sams22fa3712010-05-19 17:22:57 -0700543
Jason Samsef823642011-08-31 14:52:08 -0700544/**
545 * Compute the exponent of the value.
546 *
547 * Supports 1,2,3,4 components
548 */
Jason Sams22fa3712010-05-19 17:22:57 -0700549extern float __attribute__((overloadable)) logb(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800550FN_FUNC_FN(logb)
Jason Sams22fa3712010-05-19 17:22:57 -0700551
Jason Samsef823642011-08-31 14:52:08 -0700552/**
553 * Compute (a * b) + c
554 *
555 * Supports 1,2,3,4 components
556 */
557extern float __attribute__((overloadable)) mad(float a, float b, float c);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800558FN_FUNC_FN_FN_FN(mad)
Jason Sams22fa3712010-05-19 17:22:57 -0700559
Jason Samsef823642011-08-31 14:52:08 -0700560/**
Stephen Hinescb058022012-05-29 17:10:05 -0700561 * Return the integral and fractional components of a number.
Jason Samsef823642011-08-31 14:52:08 -0700562 * Supports 1,2,3,4 components
563 *
564 * @param x Source value
565 * @param iret iret[0] will be set to the integral portion of the number.
566 * @return The floating point portion of the value.
567 */
568extern float __attribute__((overloadable)) modf(float x, float *iret);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800569FN_FUNC_FN_PFN(modf);
Jason Sams22fa3712010-05-19 17:22:57 -0700570
Jason Samsf31fa922012-03-30 18:26:31 -0700571extern float __attribute__((overloadable)) nan(uint);
Jason Sams22fa3712010-05-19 17:22:57 -0700572
Jason Samsef823642011-08-31 14:52:08 -0700573/**
574 * Return the next floating point number from x towards y.
575 *
576 * Supports 1,2,3,4 components
577 */
578extern float __attribute__((overloadable)) nextafter(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800579FN_FUNC_FN_FN(nextafter)
Jason Sams22fa3712010-05-19 17:22:57 -0700580
Jason Samsef823642011-08-31 14:52:08 -0700581/**
582 * Return (v ^ p).
583 *
584 * Supports 1,2,3,4 components
585 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800586_RS_RUNTIME float __attribute__((overloadable)) pown(float v, int p);
Jason Samsef823642011-08-31 14:52:08 -0700587FN_FUNC_FN_IN(pown)
Jason Sams22fa3712010-05-19 17:22:57 -0700588
Jason Samsef823642011-08-31 14:52:08 -0700589/**
590 * Return (v ^ p).
591 * @param v must be greater than 0.
592 *
593 * Supports 1,2,3,4 components
594 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800595_RS_RUNTIME float __attribute__((overloadable)) powr(float v, float p);
Jason Samsef823642011-08-31 14:52:08 -0700596FN_FUNC_FN_FN(powr)
Jason Sams22fa3712010-05-19 17:22:57 -0700597
Jason Samsef823642011-08-31 14:52:08 -0700598/**
599 * Return round x/y to the nearest integer then compute the remander.
600 *
601 * Supports 1,2,3,4 components
602 */
603extern float __attribute__((overloadable)) remainder(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800604FN_FUNC_FN_FN(remainder)
Jason Sams22fa3712010-05-19 17:22:57 -0700605
Jason Samsef823642011-08-31 14:52:08 -0700606// document once we know the precision of bionic
Stephen Hines47416532011-01-11 14:38:18 -0800607extern float __attribute__((overloadable)) remquo(float, float, int *);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800608FN_FUNC_FN_FN_PIN(remquo)
Jason Sams22fa3712010-05-19 17:22:57 -0700609
Jason Samsef823642011-08-31 14:52:08 -0700610/**
611 * Round to the nearest integral value.
612 *
613 * Supports 1,2,3,4 components
614 */
Jason Sams22fa3712010-05-19 17:22:57 -0700615extern float __attribute__((overloadable)) rint(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800616FN_FUNC_FN(rint)
Jason Sams22fa3712010-05-19 17:22:57 -0700617
Jason Samsef823642011-08-31 14:52:08 -0700618/**
619 * Compute the Nth root of a value.
620 *
621 * Supports 1,2,3,4 components
622 */
623_RS_RUNTIME float __attribute__((overloadable)) rootn(float v, int n);
624FN_FUNC_FN_IN(rootn)
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800625
Jason Samsef823642011-08-31 14:52:08 -0700626/**
627 * Round to the nearest integral value. Half values are rounded away from zero.
628 *
629 * Supports 1,2,3,4 components
630 */
Jason Sams22fa3712010-05-19 17:22:57 -0700631extern float __attribute__((overloadable)) round(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800632FN_FUNC_FN(round)
Jason Sams22fa3712010-05-19 17:22:57 -0700633
Jason Samsef823642011-08-31 14:52:08 -0700634/**
635 * Return the square root of a value.
636 *
637 * Supports 1,2,3,4 components
638 */
Jason Sams22fa3712010-05-19 17:22:57 -0700639extern float __attribute__((overloadable)) sqrt(float);
Jason Samsef823642011-08-31 14:52:08 -0700640FN_FUNC_FN(sqrt)
641
642/**
643 * Return (1 / sqrt(value)).
644 *
Jason Samsef823642011-08-31 14:52:08 -0700645 * Supports 1,2,3,4 components
646 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800647_RS_RUNTIME float __attribute__((overloadable)) rsqrt(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800648FN_FUNC_FN(rsqrt)
Jason Sams1b937f52010-06-09 14:26:16 -0700649
Jason Samsef823642011-08-31 14:52:08 -0700650/**
651 * Return the sine of a value specified in radians.
652 *
653 * @param v The incoming value in radians
654 * Supports 1,2,3,4 components
655 */
656extern float __attribute__((overloadable)) sin(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800657FN_FUNC_FN(sin)
Jason Sams1b937f52010-06-09 14:26:16 -0700658
Jason Samsef823642011-08-31 14:52:08 -0700659/**
660 * Return the sine and cosine of a value.
661 *
662 * @return sine
663 * @param v The incoming value in radians
664 * @param *cosptr cosptr[0] will be set to the cosine value.
665 *
666 * Supports 1,2,3,4 components
667 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800668_RS_RUNTIME float __attribute__((overloadable)) sincos(float v, float *cosptr);
Jason Samsef823642011-08-31 14:52:08 -0700669FN_FUNC_FN_PFN(sincos);
Jason Sams1b937f52010-06-09 14:26:16 -0700670
Jason Samsef823642011-08-31 14:52:08 -0700671/**
672 * Return the hyperbolic sine of a value specified in radians.
673 *
674 * Supports 1,2,3,4 components
675 */
Jason Sams1b937f52010-06-09 14:26:16 -0700676extern float __attribute__((overloadable)) sinh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800677FN_FUNC_FN(sinh)
Jason Sams1b937f52010-06-09 14:26:16 -0700678
Jason Samsef823642011-08-31 14:52:08 -0700679/**
680 * Return the sin(v * PI).
681 *
682 * Supports 1,2,3,4 components
683 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800684_RS_RUNTIME float __attribute__((overloadable)) sinpi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800685FN_FUNC_FN(sinpi)
Jason Sams1b937f52010-06-09 14:26:16 -0700686
Jason Samsef823642011-08-31 14:52:08 -0700687/**
688 * Return the tangent of a value.
689 *
690 * Supports 1,2,3,4 components
691 * @param v The incoming value in radians
692 */
693extern float __attribute__((overloadable)) tan(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800694FN_FUNC_FN(tan)
Jason Sams22fa3712010-05-19 17:22:57 -0700695
Jason Samsef823642011-08-31 14:52:08 -0700696/**
697 * Return the hyperbolic tangent of a value.
698 *
699 * Supports 1,2,3,4 components
700 * @param v The incoming value in radians
701 */
Jason Sams22fa3712010-05-19 17:22:57 -0700702extern float __attribute__((overloadable)) tanh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800703FN_FUNC_FN(tanh)
Jason Sams22fa3712010-05-19 17:22:57 -0700704
Jason Samsef823642011-08-31 14:52:08 -0700705/**
706 * Return tan(v * PI)
707 *
708 * Supports 1,2,3,4 components
709 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800710_RS_RUNTIME float __attribute__((overloadable)) tanpi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800711FN_FUNC_FN(tanpi)
Jason Sams22fa3712010-05-19 17:22:57 -0700712
Jason Samsef823642011-08-31 14:52:08 -0700713/**
714 * Compute the gamma function of a value.
715 *
716 * Supports 1,2,3,4 components
717 */
Jason Sams22fa3712010-05-19 17:22:57 -0700718extern float __attribute__((overloadable)) tgamma(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800719FN_FUNC_FN(tgamma)
Jason Sams22fa3712010-05-19 17:22:57 -0700720
Jason Samsef823642011-08-31 14:52:08 -0700721/**
722 * Round to integral using truncation.
723 *
724 * Supports 1,2,3,4 components
725 */
Jason Sams22fa3712010-05-19 17:22:57 -0700726extern float __attribute__((overloadable)) trunc(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800727FN_FUNC_FN(trunc)
Jason Sams22fa3712010-05-19 17:22:57 -0700728
Jason Sams22fa3712010-05-19 17:22:57 -0700729
Stephen Hines47b15302011-01-19 18:06:34 -0800730#define XN_FUNC_YN(typeout, fnc, typein) \
731extern typeout __attribute__((overloadable)) fnc(typein); \
Stephen Hinescb058022012-05-29 17:10:05 -0700732_RS_RUNTIME typeout##2 __attribute__((overloadable)) fnc(typein##2 v); \
733_RS_RUNTIME typeout##3 __attribute__((overloadable)) fnc(typein##3 v); \
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800734_RS_RUNTIME typeout##4 __attribute__((overloadable)) fnc(typein##4 v);
Jason Sams22fa3712010-05-19 17:22:57 -0700735
Stephen Hines47b15302011-01-19 18:06:34 -0800736#define UIN_FUNC_IN(fnc) \
Stephen Hines3e6482f2011-01-19 12:51:33 -0800737XN_FUNC_YN(uchar, fnc, char) \
738XN_FUNC_YN(ushort, fnc, short) \
739XN_FUNC_YN(uint, fnc, int)
Jason Sams22fa3712010-05-19 17:22:57 -0700740
Stephen Hines47b15302011-01-19 18:06:34 -0800741#define IN_FUNC_IN(fnc) \
Stephen Hines3e6482f2011-01-19 12:51:33 -0800742XN_FUNC_YN(uchar, fnc, uchar) \
743XN_FUNC_YN(char, fnc, char) \
744XN_FUNC_YN(ushort, fnc, ushort) \
745XN_FUNC_YN(short, fnc, short) \
746XN_FUNC_YN(uint, fnc, uint) \
747XN_FUNC_YN(int, fnc, int)
Jason Sams22fa3712010-05-19 17:22:57 -0700748
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800749
Stephen Hines47b15302011-01-19 18:06:34 -0800750#define XN_FUNC_XN_XN_BODY(type, fnc, body) \
Stephen Hinescb058022012-05-29 17:10:05 -0700751_RS_RUNTIME type __attribute__((overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800752 fnc(type v1, type v2); \
Stephen Hinescb058022012-05-29 17:10:05 -0700753_RS_RUNTIME type##2 __attribute__((overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800754 fnc(type##2 v1, type##2 v2); \
Stephen Hinescb058022012-05-29 17:10:05 -0700755_RS_RUNTIME type##3 __attribute__((overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800756 fnc(type##3 v1, type##3 v2); \
Stephen Hinescb058022012-05-29 17:10:05 -0700757_RS_RUNTIME type##4 __attribute__((overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800758 fnc(type##4 v1, type##4 v2);
Jason Sams22fa3712010-05-19 17:22:57 -0700759
Stephen Hinescb058022012-05-29 17:10:05 -0700760#define IN_FUNC_IN_IN_BODY(fnc, body) \
761XN_FUNC_XN_XN_BODY(uchar, fnc, body) \
762XN_FUNC_XN_XN_BODY(char, fnc, body) \
763XN_FUNC_XN_XN_BODY(ushort, fnc, body) \
764XN_FUNC_XN_XN_BODY(short, fnc, body) \
765XN_FUNC_XN_XN_BODY(uint, fnc, body) \
766XN_FUNC_XN_XN_BODY(int, fnc, body) \
Stephen Hines3e6482f2011-01-19 12:51:33 -0800767XN_FUNC_XN_XN_BODY(float, fnc, body)
Stephen Hinesb902e4c2011-01-14 18:49:01 -0800768
Stephen Hinescb058022012-05-29 17:10:05 -0700769/**
770 * Return the absolute value of a value.
771 *
772 * Supports 1,2,3,4 components of char, short, int.
773 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800774UIN_FUNC_IN(abs)
Stephen Hinescb058022012-05-29 17:10:05 -0700775
776/**
777 * Return the number of leading 0-bits in a value.
778 *
779 * Supports 1,2,3,4 components of uchar, char, ushort, short, uint, int.
780 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800781IN_FUNC_IN(clz)
Stephen Hinesb902e4c2011-01-14 18:49:01 -0800782
Jason Samsdc2c3e62011-08-31 16:44:18 -0700783/**
784 * Return the minimum of two values.
785 *
786 * Supports 1,2,3,4 components of uchar, char, ushort, short, uint, int, float.
787 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800788IN_FUNC_IN_IN_BODY(min, (v1 < v2 ? v1 : v2))
789FN_FUNC_FN_F(min)
Stephen Hinesb902e4c2011-01-14 18:49:01 -0800790
Jason Samsdc2c3e62011-08-31 16:44:18 -0700791/**
792 * Return the maximum of two values.
793 *
794 * Supports 1,2,3,4 components of uchar, char, ushort, short, uint, int, float.
795 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800796IN_FUNC_IN_IN_BODY(max, (v1 > v2 ? v1 : v2))
797FN_FUNC_FN_F(max)
Jason Sams22fa3712010-05-19 17:22:57 -0700798
Jason Samsdc2c3e62011-08-31 16:44:18 -0700799/**
800 * Clamp a value to a specified high and low bound.
801 *
802 * @param amount value to be clamped. Supports 1,2,3,4 components
803 * @param low Lower bound, must be scalar or matching vector.
804 * @param high High bound, must match type of low
805 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800806_RS_RUNTIME float __attribute__((overloadable)) clamp(float amount, float low, float high);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700807FN_FUNC_FN_FN_FN(clamp)
808FN_FUNC_FN_F_F(clamp)
Jason Sams22fa3712010-05-19 17:22:57 -0700809
Jason Samsdc2c3e62011-08-31 16:44:18 -0700810/**
811 * Convert from radians to degrees.
812 *
813 * Supports 1,2,3,4 components
814 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800815_RS_RUNTIME float __attribute__((overloadable)) degrees(float radians);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800816FN_FUNC_FN(degrees)
Jason Sams22fa3712010-05-19 17:22:57 -0700817
Jason Samsdc2c3e62011-08-31 16:44:18 -0700818/**
819 * return start + ((stop - start) * amount);
820 *
821 * Supports 1,2,3,4 components
822 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800823_RS_RUNTIME float __attribute__((overloadable)) mix(float start, float stop, float amount);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700824FN_FUNC_FN_FN_FN(mix)
825FN_FUNC_FN_FN_F(mix)
Jason Sams22fa3712010-05-19 17:22:57 -0700826
Jason Samsdc2c3e62011-08-31 16:44:18 -0700827/**
828 * Convert from degrees to radians.
829 *
830 * Supports 1,2,3,4 components
831 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800832_RS_RUNTIME float __attribute__((overloadable)) radians(float degrees);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800833FN_FUNC_FN(radians)
Jason Sams22fa3712010-05-19 17:22:57 -0700834
Jason Samsdc2c3e62011-08-31 16:44:18 -0700835/**
836 * if (v < edge)
837 * return 0.f;
838 * else
839 * return 1.f;
840 *
841 * Supports 1,2,3,4 components
842 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800843_RS_RUNTIME float __attribute__((overloadable)) step(float edge, float v);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700844FN_FUNC_FN_FN(step)
845FN_FUNC_FN_F(step)
Jason Sams22fa3712010-05-19 17:22:57 -0700846
Jason Samsdc2c3e62011-08-31 16:44:18 -0700847// not implemented
Jason Sams22fa3712010-05-19 17:22:57 -0700848extern float __attribute__((overloadable)) smoothstep(float, float, float);
849extern float2 __attribute__((overloadable)) smoothstep(float2, float2, float2);
850extern float3 __attribute__((overloadable)) smoothstep(float3, float3, float3);
851extern float4 __attribute__((overloadable)) smoothstep(float4, float4, float4);
Jason Sams22fa3712010-05-19 17:22:57 -0700852extern float2 __attribute__((overloadable)) smoothstep(float, float, float2);
853extern float3 __attribute__((overloadable)) smoothstep(float, float, float3);
854extern float4 __attribute__((overloadable)) smoothstep(float, float, float4);
Jason Sams22fa3712010-05-19 17:22:57 -0700855
Jason Samsdc2c3e62011-08-31 16:44:18 -0700856/**
Stephen Hinescb058022012-05-29 17:10:05 -0700857 * Return the sign of a value.
858 *
Jason Samsdc2c3e62011-08-31 16:44:18 -0700859 * if (v < 0) return -1.f;
860 * else if (v > 0) return 1.f;
861 * else return 0.f;
862 *
863 * Supports 1,2,3,4 components
864 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800865_RS_RUNTIME float __attribute__((overloadable)) sign(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800866FN_FUNC_FN(sign)
Jason Sams22fa3712010-05-19 17:22:57 -0700867
Jason Samsdc2c3e62011-08-31 16:44:18 -0700868/**
869 * Compute the cross product of two vectors.
870 *
871 * Supports 3,4 components
872 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800873_RS_RUNTIME float3 __attribute__((overloadable)) cross(float3 lhs, float3 rhs);
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800874_RS_RUNTIME float4 __attribute__((overloadable)) cross(float4 lhs, float4 rhs);
Jason Sams22fa3712010-05-19 17:22:57 -0700875
Jason Samsdc2c3e62011-08-31 16:44:18 -0700876/**
877 * Compute the dot product of two vectors.
878 *
879 * Supports 1,2,3,4 components
880 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800881_RS_RUNTIME float __attribute__((overloadable)) dot(float lhs, float rhs);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700882F_FUNC_FN_FN(dot)
Jason Sams22fa3712010-05-19 17:22:57 -0700883
Jason Samsdc2c3e62011-08-31 16:44:18 -0700884/**
885 * Compute the length of a vector.
886 *
887 * Supports 1,2,3,4 components
888 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800889_RS_RUNTIME float __attribute__((overloadable)) length(float v);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700890F_FUNC_FN(length)
Jason Sams22fa3712010-05-19 17:22:57 -0700891
Jason Samsdc2c3e62011-08-31 16:44:18 -0700892/**
893 * Compute the distance between two points.
894 *
895 * Supports 1,2,3,4 components
896 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800897_RS_RUNTIME float __attribute__((overloadable)) distance(float lhs, float rhs);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700898F_FUNC_FN_FN(distance)
Jason Sams22fa3712010-05-19 17:22:57 -0700899
Jason Samsdc2c3e62011-08-31 16:44:18 -0700900/**
901 * Normalize a vector.
902 *
903 * Supports 1,2,3,4 components
904 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800905_RS_RUNTIME float __attribute__((overloadable)) normalize(float v);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700906FN_FUNC_FN(normalize)
907
Rajeev Sharma7150c932012-08-15 21:41:39 -0700908
909// New approx API functions
910#if (defined(RS_VERSION) && (RS_VERSION >= 17))
911
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700912/**
913 * Return the approximate reciprocal of a value.
914 *
915 * Supports 1,2,3,4 components
916 */
Jason Samsab4b0ef2012-09-20 15:39:18 -0700917_RS_RUNTIME float __attribute__((overloadable)) half_recip(float);
918FN_FUNC_FN(half_recip)
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700919
920/**
921 * Return the approximate square root of a value.
922 *
923 * Supports 1,2,3,4 components
924 */
Jason Samsab4b0ef2012-09-20 15:39:18 -0700925_RS_RUNTIME float __attribute__((overloadable)) half_sqrt(float);
926FN_FUNC_FN(half_sqrt)
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700927
928/**
929 * Return the approximate value of (1 / sqrt(value)).
930 *
931 * Supports 1,2,3,4 components
932 */
Jason Samsab4b0ef2012-09-20 15:39:18 -0700933_RS_RUNTIME float __attribute__((overloadable)) half_rsqrt(float v);
934FN_FUNC_FN(half_rsqrt)
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700935
936/**
937 * Compute the approximate length of a vector.
938 *
939 * Supports 1,2,3,4 components
940 */
Jason Samsab4b0ef2012-09-20 15:39:18 -0700941_RS_RUNTIME float __attribute__((overloadable)) fast_length(float v);
942F_FUNC_FN(fast_length)
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700943
944/**
945 * Compute the approximate distance between two points.
946 *
947 * Supports 1,2,3,4 components
948 */
Jason Samsab4b0ef2012-09-20 15:39:18 -0700949_RS_RUNTIME float __attribute__((overloadable)) fast_distance(float lhs, float rhs);
950F_FUNC_FN_FN(fast_distance)
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700951
952/**
953 * Approximately normalize a vector.
954 *
955 * Supports 1,2,3,4 components
956 */
Jason Samsab4b0ef2012-09-20 15:39:18 -0700957_RS_RUNTIME float __attribute__((overloadable)) fast_normalize(float v);
958F_FUNC_FN(fast_normalize)
Rajeev Sharma7150c932012-08-15 21:41:39 -0700959
960#endif // (defined(RS_VERSION) && (RS_VERSION >= 17))
961
962
Stephen Hines47416532011-01-11 14:38:18 -0800963#undef CVT_FUNC
964#undef CVT_FUNC_2
Stephen Hines3e6482f2011-01-19 12:51:33 -0800965#undef FN_FUNC_FN
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700966#undef F_FUNC_FN
Stephen Hines3e6482f2011-01-19 12:51:33 -0800967#undef IN_FUNC_FN
968#undef FN_FUNC_FN_FN
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700969#undef F_FUNC_FN_FN
Stephen Hines3e6482f2011-01-19 12:51:33 -0800970#undef FN_FUNC_FN_F
971#undef FN_FUNC_FN_IN
972#undef FN_FUNC_FN_I
973#undef FN_FUNC_FN_PFN
974#undef FN_FUNC_FN_PIN
975#undef FN_FUNC_FN_FN_FN
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700976#undef FN_FUNC_FN_FN_F
977#undef FN_FUNC_FN_F_F
Stephen Hines3e6482f2011-01-19 12:51:33 -0800978#undef FN_FUNC_FN_FN_PIN
979#undef XN_FUNC_YN
980#undef UIN_FUNC_IN
981#undef IN_FUNC_IN
982#undef XN_FUNC_XN_XN_BODY
983#undef IN_FUNC_IN_IN_BODY
Jason Sams1b937f52010-06-09 14:26:16 -0700984
985#endif