blob: 211f53baca56fb44568f37840d7e8025097b9623 [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
Tim Murray4d3201d2013-01-03 11:58:39 -0800450/**
451 * Return fractional part of v
452 *
453 * Supports float, float2, float3, float4.
454 */
455_RS_RUNTIME float __attribute__((overloadable)) fract(float v);
456FN_FUNC_FN(fract)
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800457
Jason Samsef823642011-08-31 14:52:08 -0700458/**
459 * Return fractional part of v
460 *
461 * @param iptr iptr[0] will be set to the floor of the input value.
462 * Supports float, float2, float3, float4.
463 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800464_RS_RUNTIME float __attribute__((overloadable)) fract(float v, float *iptr);
Stephen Hines47b15302011-01-19 18:06:34 -0800465FN_FUNC_FN_PFN(fract)
Jason Sams22fa3712010-05-19 17:22:57 -0700466
Jason Samsef823642011-08-31 14:52:08 -0700467/**
468 * Return the mantissa and place the exponent into iptr[0]
469 *
470 * @param v Supports float, float2, float3, float4.
471 * @param iptr Must have the same vector size as v.
472 */
473extern float __attribute__((overloadable)) frexp(float v, int *iptr);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800474FN_FUNC_FN_PIN(frexp)
Jason Sams22fa3712010-05-19 17:22:57 -0700475
Jason Samsef823642011-08-31 14:52:08 -0700476/**
477 * Return sqrt(x*x + y*y)
478 *
479 * Supports float, float2, float3, float4.
480 */
481extern float __attribute__((overloadable)) hypot(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800482FN_FUNC_FN_FN(hypot)
Jason Sams22fa3712010-05-19 17:22:57 -0700483
Jason Samsef823642011-08-31 14:52:08 -0700484/**
485 * Return the integer exponent of a value
486 *
487 * Supports 1,2,3,4 components
488 */
Jason Sams22fa3712010-05-19 17:22:57 -0700489extern int __attribute__((overloadable)) ilogb(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800490IN_FUNC_FN(ilogb)
Jason Sams22fa3712010-05-19 17:22:57 -0700491
Jason Samsef823642011-08-31 14:52:08 -0700492/**
493 * Return (x * 2^y)
494 *
495 * @param x Supports 1,2,3,4 components
496 * @param y Supports single component or matching vector.
497 */
498extern float __attribute__((overloadable)) ldexp(float x, int y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800499FN_FUNC_FN_IN(ldexp)
500FN_FUNC_FN_I(ldexp)
Jason Sams22fa3712010-05-19 17:22:57 -0700501
Jason Samsef823642011-08-31 14:52:08 -0700502/**
503 * Return the log gamma
504 *
505 * Supports 1,2,3,4 components
506 */
Jason Sams22fa3712010-05-19 17:22:57 -0700507extern float __attribute__((overloadable)) lgamma(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800508FN_FUNC_FN(lgamma)
Jason Samsef823642011-08-31 14:52:08 -0700509
510/**
511 * Return the log gamma and sign
512 *
513 * @param x Supports 1,2,3,4 components
514 * @param y Supports matching vector.
515 */
516extern float __attribute__((overloadable)) lgamma(float x, int* y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800517FN_FUNC_FN_PIN(lgamma)
Jason Sams22fa3712010-05-19 17:22:57 -0700518
Jason Samsef823642011-08-31 14:52:08 -0700519/**
520 * Return the natural logarithm
521 *
522 * Supports 1,2,3,4 components
523 */
Jason Sams22fa3712010-05-19 17:22:57 -0700524extern float __attribute__((overloadable)) log(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800525FN_FUNC_FN(log)
Jason Sams22fa3712010-05-19 17:22:57 -0700526
Jason Samsef823642011-08-31 14:52:08 -0700527/**
528 * Return the base 10 logarithm
529 *
530 * Supports 1,2,3,4 components
531 */
Jason Sams22fa3712010-05-19 17:22:57 -0700532extern float __attribute__((overloadable)) log10(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800533FN_FUNC_FN(log10)
Jason Sams1b937f52010-06-09 14:26:16 -0700534
Jason Samsef823642011-08-31 14:52:08 -0700535/**
536 * Return the base 2 logarithm
537 *
538 * Supports 1,2,3,4 components
539 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800540_RS_RUNTIME float __attribute__((overloadable)) log2(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800541FN_FUNC_FN(log2)
Jason Sams22fa3712010-05-19 17:22:57 -0700542
Jason Samsef823642011-08-31 14:52:08 -0700543/**
544 * Return the natural logarithm of (v + 1.0f)
545 *
546 * Supports 1,2,3,4 components
547 */
548extern float __attribute__((overloadable)) log1p(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800549FN_FUNC_FN(log1p)
Jason Sams22fa3712010-05-19 17:22:57 -0700550
Jason Samsef823642011-08-31 14:52:08 -0700551/**
552 * Compute the exponent of the value.
553 *
554 * Supports 1,2,3,4 components
555 */
Jason Sams22fa3712010-05-19 17:22:57 -0700556extern float __attribute__((overloadable)) logb(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800557FN_FUNC_FN(logb)
Jason Sams22fa3712010-05-19 17:22:57 -0700558
Jason Samsef823642011-08-31 14:52:08 -0700559/**
560 * Compute (a * b) + c
561 *
562 * Supports 1,2,3,4 components
563 */
564extern float __attribute__((overloadable)) mad(float a, float b, float c);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800565FN_FUNC_FN_FN_FN(mad)
Jason Sams22fa3712010-05-19 17:22:57 -0700566
Jason Samsef823642011-08-31 14:52:08 -0700567/**
Stephen Hinescb058022012-05-29 17:10:05 -0700568 * Return the integral and fractional components of a number.
Jason Samsef823642011-08-31 14:52:08 -0700569 * Supports 1,2,3,4 components
570 *
571 * @param x Source value
572 * @param iret iret[0] will be set to the integral portion of the number.
573 * @return The floating point portion of the value.
574 */
575extern float __attribute__((overloadable)) modf(float x, float *iret);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800576FN_FUNC_FN_PFN(modf);
Jason Sams22fa3712010-05-19 17:22:57 -0700577
Jason Samsf31fa922012-03-30 18:26:31 -0700578extern float __attribute__((overloadable)) nan(uint);
Jason Sams22fa3712010-05-19 17:22:57 -0700579
Jason Samsef823642011-08-31 14:52:08 -0700580/**
581 * Return the next floating point number from x towards y.
582 *
583 * Supports 1,2,3,4 components
584 */
585extern float __attribute__((overloadable)) nextafter(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800586FN_FUNC_FN_FN(nextafter)
Jason Sams22fa3712010-05-19 17:22:57 -0700587
Jason Samsef823642011-08-31 14:52:08 -0700588/**
589 * Return (v ^ p).
590 *
591 * Supports 1,2,3,4 components
592 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800593_RS_RUNTIME float __attribute__((overloadable)) pown(float v, int p);
Jason Samsef823642011-08-31 14:52:08 -0700594FN_FUNC_FN_IN(pown)
Jason Sams22fa3712010-05-19 17:22:57 -0700595
Jason Samsef823642011-08-31 14:52:08 -0700596/**
597 * Return (v ^ p).
598 * @param v must be greater than 0.
599 *
600 * Supports 1,2,3,4 components
601 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800602_RS_RUNTIME float __attribute__((overloadable)) powr(float v, float p);
Jason Samsef823642011-08-31 14:52:08 -0700603FN_FUNC_FN_FN(powr)
Jason Sams22fa3712010-05-19 17:22:57 -0700604
Jason Samsef823642011-08-31 14:52:08 -0700605/**
606 * Return round x/y to the nearest integer then compute the remander.
607 *
608 * Supports 1,2,3,4 components
609 */
610extern float __attribute__((overloadable)) remainder(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800611FN_FUNC_FN_FN(remainder)
Jason Sams22fa3712010-05-19 17:22:57 -0700612
Jason Samsef823642011-08-31 14:52:08 -0700613// document once we know the precision of bionic
Stephen Hines47416532011-01-11 14:38:18 -0800614extern float __attribute__((overloadable)) remquo(float, float, int *);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800615FN_FUNC_FN_FN_PIN(remquo)
Jason Sams22fa3712010-05-19 17:22:57 -0700616
Jason Samsef823642011-08-31 14:52:08 -0700617/**
618 * Round to the nearest integral value.
619 *
620 * Supports 1,2,3,4 components
621 */
Jason Sams22fa3712010-05-19 17:22:57 -0700622extern float __attribute__((overloadable)) rint(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800623FN_FUNC_FN(rint)
Jason Sams22fa3712010-05-19 17:22:57 -0700624
Jason Samsef823642011-08-31 14:52:08 -0700625/**
626 * Compute the Nth root of a value.
627 *
628 * Supports 1,2,3,4 components
629 */
630_RS_RUNTIME float __attribute__((overloadable)) rootn(float v, int n);
631FN_FUNC_FN_IN(rootn)
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800632
Jason Samsef823642011-08-31 14:52:08 -0700633/**
634 * Round to the nearest integral value. Half values are rounded away from zero.
635 *
636 * Supports 1,2,3,4 components
637 */
Jason Sams22fa3712010-05-19 17:22:57 -0700638extern float __attribute__((overloadable)) round(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800639FN_FUNC_FN(round)
Jason Sams22fa3712010-05-19 17:22:57 -0700640
Jason Samsef823642011-08-31 14:52:08 -0700641/**
642 * Return the square root of a value.
643 *
644 * Supports 1,2,3,4 components
645 */
Jason Sams22fa3712010-05-19 17:22:57 -0700646extern float __attribute__((overloadable)) sqrt(float);
Jason Samsef823642011-08-31 14:52:08 -0700647FN_FUNC_FN(sqrt)
648
649/**
650 * Return (1 / sqrt(value)).
651 *
Jason Samsef823642011-08-31 14:52:08 -0700652 * Supports 1,2,3,4 components
653 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800654_RS_RUNTIME float __attribute__((overloadable)) rsqrt(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800655FN_FUNC_FN(rsqrt)
Jason Sams1b937f52010-06-09 14:26:16 -0700656
Jason Samsef823642011-08-31 14:52:08 -0700657/**
658 * Return the sine of a value specified in radians.
659 *
660 * @param v The incoming value in radians
661 * Supports 1,2,3,4 components
662 */
663extern float __attribute__((overloadable)) sin(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800664FN_FUNC_FN(sin)
Jason Sams1b937f52010-06-09 14:26:16 -0700665
Jason Samsef823642011-08-31 14:52:08 -0700666/**
667 * Return the sine and cosine of a value.
668 *
669 * @return sine
670 * @param v The incoming value in radians
671 * @param *cosptr cosptr[0] will be set to the cosine value.
672 *
673 * Supports 1,2,3,4 components
674 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800675_RS_RUNTIME float __attribute__((overloadable)) sincos(float v, float *cosptr);
Jason Samsef823642011-08-31 14:52:08 -0700676FN_FUNC_FN_PFN(sincos);
Jason Sams1b937f52010-06-09 14:26:16 -0700677
Jason Samsef823642011-08-31 14:52:08 -0700678/**
679 * Return the hyperbolic sine of a value specified in radians.
680 *
681 * Supports 1,2,3,4 components
682 */
Jason Sams1b937f52010-06-09 14:26:16 -0700683extern float __attribute__((overloadable)) sinh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800684FN_FUNC_FN(sinh)
Jason Sams1b937f52010-06-09 14:26:16 -0700685
Jason Samsef823642011-08-31 14:52:08 -0700686/**
687 * Return the sin(v * PI).
688 *
689 * Supports 1,2,3,4 components
690 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800691_RS_RUNTIME float __attribute__((overloadable)) sinpi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800692FN_FUNC_FN(sinpi)
Jason Sams1b937f52010-06-09 14:26:16 -0700693
Jason Samsef823642011-08-31 14:52:08 -0700694/**
695 * Return the tangent of a value.
696 *
697 * Supports 1,2,3,4 components
698 * @param v The incoming value in radians
699 */
700extern float __attribute__((overloadable)) tan(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800701FN_FUNC_FN(tan)
Jason Sams22fa3712010-05-19 17:22:57 -0700702
Jason Samsef823642011-08-31 14:52:08 -0700703/**
704 * Return the hyperbolic tangent of a value.
705 *
706 * Supports 1,2,3,4 components
707 * @param v The incoming value in radians
708 */
Jason Sams22fa3712010-05-19 17:22:57 -0700709extern float __attribute__((overloadable)) tanh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800710FN_FUNC_FN(tanh)
Jason Sams22fa3712010-05-19 17:22:57 -0700711
Jason Samsef823642011-08-31 14:52:08 -0700712/**
713 * Return tan(v * PI)
714 *
715 * Supports 1,2,3,4 components
716 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800717_RS_RUNTIME float __attribute__((overloadable)) tanpi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800718FN_FUNC_FN(tanpi)
Jason Sams22fa3712010-05-19 17:22:57 -0700719
Jason Samsef823642011-08-31 14:52:08 -0700720/**
721 * Compute the gamma function of a value.
722 *
723 * Supports 1,2,3,4 components
724 */
Jason Sams22fa3712010-05-19 17:22:57 -0700725extern float __attribute__((overloadable)) tgamma(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800726FN_FUNC_FN(tgamma)
Jason Sams22fa3712010-05-19 17:22:57 -0700727
Jason Samsef823642011-08-31 14:52:08 -0700728/**
729 * Round to integral using truncation.
730 *
731 * Supports 1,2,3,4 components
732 */
Jason Sams22fa3712010-05-19 17:22:57 -0700733extern float __attribute__((overloadable)) trunc(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800734FN_FUNC_FN(trunc)
Jason Sams22fa3712010-05-19 17:22:57 -0700735
Jason Sams22fa3712010-05-19 17:22:57 -0700736
Stephen Hines47b15302011-01-19 18:06:34 -0800737#define XN_FUNC_YN(typeout, fnc, typein) \
738extern typeout __attribute__((overloadable)) fnc(typein); \
Stephen Hinescb058022012-05-29 17:10:05 -0700739_RS_RUNTIME typeout##2 __attribute__((overloadable)) fnc(typein##2 v); \
740_RS_RUNTIME typeout##3 __attribute__((overloadable)) fnc(typein##3 v); \
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800741_RS_RUNTIME typeout##4 __attribute__((overloadable)) fnc(typein##4 v);
Jason Sams22fa3712010-05-19 17:22:57 -0700742
Stephen Hines47b15302011-01-19 18:06:34 -0800743#define UIN_FUNC_IN(fnc) \
Stephen Hines3e6482f2011-01-19 12:51:33 -0800744XN_FUNC_YN(uchar, fnc, char) \
745XN_FUNC_YN(ushort, fnc, short) \
746XN_FUNC_YN(uint, fnc, int)
Jason Sams22fa3712010-05-19 17:22:57 -0700747
Stephen Hines47b15302011-01-19 18:06:34 -0800748#define IN_FUNC_IN(fnc) \
Stephen Hines3e6482f2011-01-19 12:51:33 -0800749XN_FUNC_YN(uchar, fnc, uchar) \
750XN_FUNC_YN(char, fnc, char) \
751XN_FUNC_YN(ushort, fnc, ushort) \
752XN_FUNC_YN(short, fnc, short) \
753XN_FUNC_YN(uint, fnc, uint) \
754XN_FUNC_YN(int, fnc, int)
Jason Sams22fa3712010-05-19 17:22:57 -0700755
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800756
Stephen Hines47b15302011-01-19 18:06:34 -0800757#define XN_FUNC_XN_XN_BODY(type, fnc, body) \
Stephen Hinescb058022012-05-29 17:10:05 -0700758_RS_RUNTIME type __attribute__((overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800759 fnc(type v1, type v2); \
Stephen Hinescb058022012-05-29 17:10:05 -0700760_RS_RUNTIME type##2 __attribute__((overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800761 fnc(type##2 v1, type##2 v2); \
Stephen Hinescb058022012-05-29 17:10:05 -0700762_RS_RUNTIME type##3 __attribute__((overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800763 fnc(type##3 v1, type##3 v2); \
Stephen Hinescb058022012-05-29 17:10:05 -0700764_RS_RUNTIME type##4 __attribute__((overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800765 fnc(type##4 v1, type##4 v2);
Jason Sams22fa3712010-05-19 17:22:57 -0700766
Stephen Hinescb058022012-05-29 17:10:05 -0700767#define IN_FUNC_IN_IN_BODY(fnc, body) \
768XN_FUNC_XN_XN_BODY(uchar, fnc, body) \
769XN_FUNC_XN_XN_BODY(char, fnc, body) \
770XN_FUNC_XN_XN_BODY(ushort, fnc, body) \
771XN_FUNC_XN_XN_BODY(short, fnc, body) \
772XN_FUNC_XN_XN_BODY(uint, fnc, body) \
773XN_FUNC_XN_XN_BODY(int, fnc, body) \
Stephen Hines3e6482f2011-01-19 12:51:33 -0800774XN_FUNC_XN_XN_BODY(float, fnc, body)
Stephen Hinesb902e4c2011-01-14 18:49:01 -0800775
Stephen Hinescb058022012-05-29 17:10:05 -0700776/**
777 * Return the absolute value of a value.
778 *
779 * Supports 1,2,3,4 components of char, short, int.
780 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800781UIN_FUNC_IN(abs)
Stephen Hinescb058022012-05-29 17:10:05 -0700782
783/**
784 * Return the number of leading 0-bits in a value.
785 *
786 * Supports 1,2,3,4 components of uchar, char, ushort, short, uint, int.
787 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800788IN_FUNC_IN(clz)
Stephen Hinesb902e4c2011-01-14 18:49:01 -0800789
Jason Samsdc2c3e62011-08-31 16:44:18 -0700790/**
791 * Return the minimum of two values.
792 *
793 * Supports 1,2,3,4 components of uchar, char, ushort, short, uint, int, float.
794 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800795IN_FUNC_IN_IN_BODY(min, (v1 < v2 ? v1 : v2))
796FN_FUNC_FN_F(min)
Stephen Hinesb902e4c2011-01-14 18:49:01 -0800797
Jason Samsdc2c3e62011-08-31 16:44:18 -0700798/**
799 * Return the maximum of two values.
800 *
801 * Supports 1,2,3,4 components of uchar, char, ushort, short, uint, int, float.
802 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800803IN_FUNC_IN_IN_BODY(max, (v1 > v2 ? v1 : v2))
804FN_FUNC_FN_F(max)
Jason Sams22fa3712010-05-19 17:22:57 -0700805
Jason Samsdc2c3e62011-08-31 16:44:18 -0700806/**
807 * Clamp a value to a specified high and low bound.
808 *
809 * @param amount value to be clamped. Supports 1,2,3,4 components
810 * @param low Lower bound, must be scalar or matching vector.
811 * @param high High bound, must match type of low
812 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800813_RS_RUNTIME float __attribute__((overloadable)) clamp(float amount, float low, float high);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700814FN_FUNC_FN_FN_FN(clamp)
815FN_FUNC_FN_F_F(clamp)
Jason Sams22fa3712010-05-19 17:22:57 -0700816
Jason Samsdc2c3e62011-08-31 16:44:18 -0700817/**
818 * Convert from radians to degrees.
819 *
820 * Supports 1,2,3,4 components
821 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800822_RS_RUNTIME float __attribute__((overloadable)) degrees(float radians);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800823FN_FUNC_FN(degrees)
Jason Sams22fa3712010-05-19 17:22:57 -0700824
Jason Samsdc2c3e62011-08-31 16:44:18 -0700825/**
826 * return start + ((stop - start) * amount);
827 *
828 * Supports 1,2,3,4 components
829 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800830_RS_RUNTIME float __attribute__((overloadable)) mix(float start, float stop, float amount);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700831FN_FUNC_FN_FN_FN(mix)
832FN_FUNC_FN_FN_F(mix)
Jason Sams22fa3712010-05-19 17:22:57 -0700833
Jason Samsdc2c3e62011-08-31 16:44:18 -0700834/**
835 * Convert from degrees to radians.
836 *
837 * Supports 1,2,3,4 components
838 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800839_RS_RUNTIME float __attribute__((overloadable)) radians(float degrees);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800840FN_FUNC_FN(radians)
Jason Sams22fa3712010-05-19 17:22:57 -0700841
Jason Samsdc2c3e62011-08-31 16:44:18 -0700842/**
843 * if (v < edge)
844 * return 0.f;
845 * else
846 * return 1.f;
847 *
848 * Supports 1,2,3,4 components
849 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800850_RS_RUNTIME float __attribute__((overloadable)) step(float edge, float v);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700851FN_FUNC_FN_FN(step)
852FN_FUNC_FN_F(step)
Jason Sams22fa3712010-05-19 17:22:57 -0700853
Jason Samsdc2c3e62011-08-31 16:44:18 -0700854// not implemented
Jason Sams22fa3712010-05-19 17:22:57 -0700855extern float __attribute__((overloadable)) smoothstep(float, float, float);
856extern float2 __attribute__((overloadable)) smoothstep(float2, float2, float2);
857extern float3 __attribute__((overloadable)) smoothstep(float3, float3, float3);
858extern float4 __attribute__((overloadable)) smoothstep(float4, float4, float4);
Jason Sams22fa3712010-05-19 17:22:57 -0700859extern float2 __attribute__((overloadable)) smoothstep(float, float, float2);
860extern float3 __attribute__((overloadable)) smoothstep(float, float, float3);
861extern float4 __attribute__((overloadable)) smoothstep(float, float, float4);
Jason Sams22fa3712010-05-19 17:22:57 -0700862
Jason Samsdc2c3e62011-08-31 16:44:18 -0700863/**
Stephen Hinescb058022012-05-29 17:10:05 -0700864 * Return the sign of a value.
865 *
Jason Samsdc2c3e62011-08-31 16:44:18 -0700866 * if (v < 0) return -1.f;
867 * else if (v > 0) return 1.f;
868 * else return 0.f;
869 *
870 * Supports 1,2,3,4 components
871 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800872_RS_RUNTIME float __attribute__((overloadable)) sign(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800873FN_FUNC_FN(sign)
Jason Sams22fa3712010-05-19 17:22:57 -0700874
Jason Samsdc2c3e62011-08-31 16:44:18 -0700875/**
876 * Compute the cross product of two vectors.
877 *
878 * Supports 3,4 components
879 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800880_RS_RUNTIME float3 __attribute__((overloadable)) cross(float3 lhs, float3 rhs);
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800881_RS_RUNTIME float4 __attribute__((overloadable)) cross(float4 lhs, float4 rhs);
Jason Sams22fa3712010-05-19 17:22:57 -0700882
Jason Samsdc2c3e62011-08-31 16:44:18 -0700883/**
884 * Compute the dot product of two vectors.
885 *
886 * Supports 1,2,3,4 components
887 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800888_RS_RUNTIME float __attribute__((overloadable)) dot(float lhs, float rhs);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700889F_FUNC_FN_FN(dot)
Jason Sams22fa3712010-05-19 17:22:57 -0700890
Jason Samsdc2c3e62011-08-31 16:44:18 -0700891/**
892 * Compute the length of a vector.
893 *
894 * Supports 1,2,3,4 components
895 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800896_RS_RUNTIME float __attribute__((overloadable)) length(float v);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700897F_FUNC_FN(length)
Jason Sams22fa3712010-05-19 17:22:57 -0700898
Jason Samsdc2c3e62011-08-31 16:44:18 -0700899/**
900 * Compute the distance between two points.
901 *
902 * Supports 1,2,3,4 components
903 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800904_RS_RUNTIME float __attribute__((overloadable)) distance(float lhs, float rhs);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700905F_FUNC_FN_FN(distance)
Jason Sams22fa3712010-05-19 17:22:57 -0700906
Jason Samsdc2c3e62011-08-31 16:44:18 -0700907/**
908 * Normalize a vector.
909 *
910 * Supports 1,2,3,4 components
911 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800912_RS_RUNTIME float __attribute__((overloadable)) normalize(float v);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700913FN_FUNC_FN(normalize)
914
Rajeev Sharma7150c932012-08-15 21:41:39 -0700915
916// New approx API functions
917#if (defined(RS_VERSION) && (RS_VERSION >= 17))
918
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700919/**
920 * Return the approximate reciprocal of a value.
921 *
922 * Supports 1,2,3,4 components
923 */
Jason Samsab4b0ef2012-09-20 15:39:18 -0700924_RS_RUNTIME float __attribute__((overloadable)) half_recip(float);
925FN_FUNC_FN(half_recip)
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700926
927/**
928 * Return the approximate square root of a value.
929 *
930 * Supports 1,2,3,4 components
931 */
Jason Samsab4b0ef2012-09-20 15:39:18 -0700932_RS_RUNTIME float __attribute__((overloadable)) half_sqrt(float);
933FN_FUNC_FN(half_sqrt)
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700934
935/**
936 * Return the approximate value of (1 / sqrt(value)).
937 *
938 * Supports 1,2,3,4 components
939 */
Jason Samsab4b0ef2012-09-20 15:39:18 -0700940_RS_RUNTIME float __attribute__((overloadable)) half_rsqrt(float v);
941FN_FUNC_FN(half_rsqrt)
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700942
943/**
944 * Compute the approximate length of a vector.
945 *
946 * Supports 1,2,3,4 components
947 */
Jason Samsab4b0ef2012-09-20 15:39:18 -0700948_RS_RUNTIME float __attribute__((overloadable)) fast_length(float v);
949F_FUNC_FN(fast_length)
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700950
951/**
952 * Compute the approximate distance between two points.
953 *
954 * Supports 1,2,3,4 components
955 */
Jason Samsab4b0ef2012-09-20 15:39:18 -0700956_RS_RUNTIME float __attribute__((overloadable)) fast_distance(float lhs, float rhs);
957F_FUNC_FN_FN(fast_distance)
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700958
959/**
960 * Approximately normalize a vector.
961 *
962 * Supports 1,2,3,4 components
963 */
Jason Samsab4b0ef2012-09-20 15:39:18 -0700964_RS_RUNTIME float __attribute__((overloadable)) fast_normalize(float v);
965F_FUNC_FN(fast_normalize)
Rajeev Sharma7150c932012-08-15 21:41:39 -0700966
967#endif // (defined(RS_VERSION) && (RS_VERSION >= 17))
968
969
Stephen Hines47416532011-01-11 14:38:18 -0800970#undef CVT_FUNC
971#undef CVT_FUNC_2
Stephen Hines3e6482f2011-01-19 12:51:33 -0800972#undef FN_FUNC_FN
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700973#undef F_FUNC_FN
Stephen Hines3e6482f2011-01-19 12:51:33 -0800974#undef IN_FUNC_FN
975#undef FN_FUNC_FN_FN
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700976#undef F_FUNC_FN_FN
Stephen Hines3e6482f2011-01-19 12:51:33 -0800977#undef FN_FUNC_FN_F
978#undef FN_FUNC_FN_IN
979#undef FN_FUNC_FN_I
980#undef FN_FUNC_FN_PFN
981#undef FN_FUNC_FN_PIN
982#undef FN_FUNC_FN_FN_FN
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700983#undef FN_FUNC_FN_FN_F
984#undef FN_FUNC_FN_F_F
Stephen Hines3e6482f2011-01-19 12:51:33 -0800985#undef FN_FUNC_FN_FN_PIN
986#undef XN_FUNC_YN
987#undef UIN_FUNC_IN
988#undef IN_FUNC_IN
989#undef XN_FUNC_XN_XN_BODY
990#undef IN_FUNC_IN_IN_BODY
Jason Sams1b937f52010-06-09 14:26:16 -0700991
992#endif