blob: 2ff5d8b7bd5c846b65c01ad1762b53e526596ff5 [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 Hinese7812282013-06-19 00:07:04 -070095#ifdef DOXYGEN
96
97#define FN_FUNC_FN(fnc)
98#define F_FUNC_FN(fnc)
99#define IN_FUNC_FN(fnc)
100#define FN_FUNC_FN_FN(fnc)
101#define F_FUNC_FN_FN(fnc)
102#define FN_FUNC_FN_F(fnc)
103#define FN_FUNC_FN_IN(fnc)
104#define FN_FUNC_FN_I(fnc)
105#define FN_FUNC_FN_PFN(fnc)
106#define FN_FUNC_FN_PIN(fnc)
107#define FN_FUNC_FN_FN_FN(fnc)
108#define FN_FUNC_FN_FN_F(fnc)
109#define FN_FUNC_FN_F_F(fnc)
110#define FN_FUNC_FN_FN_PIN(fnc)
111
112#else
113
Stephen Hines52132472013-04-30 15:45:22 -0700114#define FN_FUNC_FN(fnc) \
115_RS_RUNTIME float2 __attribute__((const, overloadable)) fnc(float2 v); \
116_RS_RUNTIME float3 __attribute__((const, overloadable)) fnc(float3 v); \
117_RS_RUNTIME float4 __attribute__((const, overloadable)) fnc(float4 v);
Jason Sams1b937f52010-06-09 14:26:16 -0700118
Stephen Hines52132472013-04-30 15:45:22 -0700119#define F_FUNC_FN(fnc) \
120_RS_RUNTIME float __attribute__((const, overloadable)) fnc(float2 v); \
121_RS_RUNTIME float __attribute__((const, overloadable)) fnc(float3 v); \
122_RS_RUNTIME float __attribute__((const, overloadable)) fnc(float4 v);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700123
Stephen Hines52132472013-04-30 15:45:22 -0700124#define IN_FUNC_FN(fnc) \
125_RS_RUNTIME int2 __attribute__((const, overloadable)) fnc(float2 v); \
126_RS_RUNTIME int3 __attribute__((const, overloadable)) fnc(float3 v); \
127_RS_RUNTIME int4 __attribute__((const, overloadable)) fnc(float4 v);
Stephen Hines47416532011-01-11 14:38:18 -0800128
Stephen Hines52132472013-04-30 15:45:22 -0700129#define FN_FUNC_FN_FN(fnc) \
130_RS_RUNTIME float2 __attribute__((const, overloadable)) fnc(float2 v1, float2 v2); \
131_RS_RUNTIME float3 __attribute__((const, overloadable)) fnc(float3 v1, float3 v2); \
132_RS_RUNTIME float4 __attribute__((const, overloadable)) fnc(float4 v1, float4 v2);
Jason Sams1b937f52010-06-09 14:26:16 -0700133
Stephen Hines52132472013-04-30 15:45:22 -0700134#define F_FUNC_FN_FN(fnc) \
135_RS_RUNTIME float __attribute__((const, overloadable)) fnc(float2 v1, float2 v2); \
136_RS_RUNTIME float __attribute__((const, overloadable)) fnc(float3 v1, float3 v2); \
137_RS_RUNTIME float __attribute__((const, overloadable)) fnc(float4 v1, float4 v2);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700138
Stephen Hines52132472013-04-30 15:45:22 -0700139#define FN_FUNC_FN_F(fnc) \
140_RS_RUNTIME float2 __attribute__((const, overloadable)) fnc(float2 v1, float v2); \
141_RS_RUNTIME float3 __attribute__((const, overloadable)) fnc(float3 v1, float v2); \
142_RS_RUNTIME float4 __attribute__((const, overloadable)) fnc(float4 v1, float v2);
Jason Sams1b937f52010-06-09 14:26:16 -0700143
Stephen Hines52132472013-04-30 15:45:22 -0700144#define FN_FUNC_FN_IN(fnc) \
145_RS_RUNTIME float2 __attribute__((const, overloadable)) fnc(float2 v1, int2 v2); \
146_RS_RUNTIME float3 __attribute__((const, overloadable)) fnc(float3 v1, int3 v2); \
147_RS_RUNTIME float4 __attribute__((const, overloadable)) fnc(float4 v1, int4 v2);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800148
Stephen Hines52132472013-04-30 15:45:22 -0700149#define FN_FUNC_FN_I(fnc) \
150_RS_RUNTIME float2 __attribute__((const, overloadable)) fnc(float2 v1, int v2); \
151_RS_RUNTIME float3 __attribute__((const, overloadable)) fnc(float3 v1, int v2); \
152_RS_RUNTIME float4 __attribute__((const, overloadable)) fnc(float4 v1, int v2);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800153
Stephen Hines52132472013-04-30 15:45:22 -0700154#define FN_FUNC_FN_PFN(fnc) \
155_RS_RUNTIME float2 __attribute__((pure, overloadable)) \
156 fnc(float2 v1, float2 *v2); \
157_RS_RUNTIME float3 __attribute__((pure, overloadable)) \
158 fnc(float3 v1, float3 *v2); \
159_RS_RUNTIME float4 __attribute__((pure, overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800160 fnc(float4 v1, float4 *v2);
Jason Sams1b937f52010-06-09 14:26:16 -0700161
Stephen Hines52132472013-04-30 15:45:22 -0700162#define FN_FUNC_FN_PIN(fnc) \
163_RS_RUNTIME float2 __attribute__((pure, overloadable)) fnc(float2 v1, int2 *v2); \
164_RS_RUNTIME float3 __attribute__((pure, overloadable)) fnc(float3 v1, int3 *v2); \
165_RS_RUNTIME float4 __attribute__((pure, overloadable)) fnc(float4 v1, int4 *v2);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800166
Stephen Hines52132472013-04-30 15:45:22 -0700167#define FN_FUNC_FN_FN_FN(fnc) \
168_RS_RUNTIME float2 __attribute__((const, overloadable)) \
169 fnc(float2 v1, float2 v2, float2 v3); \
170_RS_RUNTIME float3 __attribute__((const, overloadable)) \
171 fnc(float3 v1, float3 v2, float3 v3); \
172_RS_RUNTIME float4 __attribute__((const, overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800173 fnc(float4 v1, float4 v2, float4 v3);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800174
Stephen Hines52132472013-04-30 15:45:22 -0700175#define FN_FUNC_FN_FN_F(fnc) \
176_RS_RUNTIME float2 __attribute__((const, overloadable)) \
177 fnc(float2 v1, float2 v2, float v3); \
178_RS_RUNTIME float3 __attribute__((const, overloadable)) \
179 fnc(float3 v1, float3 v2, float v3); \
180_RS_RUNTIME float4 __attribute__((const, overloadable)) \
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700181 fnc(float4 v1, float4 v2, float v3);
182
Stephen Hines52132472013-04-30 15:45:22 -0700183#define FN_FUNC_FN_F_F(fnc) \
184_RS_RUNTIME float2 __attribute__((const, overloadable)) \
185 fnc(float2 v1, float v2, float v3); \
186_RS_RUNTIME float3 __attribute__((const, overloadable)) \
187 fnc(float3 v1, float v2, float v3); \
188_RS_RUNTIME float4 __attribute__((const, overloadable)) \
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700189 fnc(float4 v1, float v2, float v3);
190
Stephen Hines52132472013-04-30 15:45:22 -0700191#define FN_FUNC_FN_FN_PIN(fnc) \
192_RS_RUNTIME float2 __attribute__((pure, overloadable)) \
193 fnc(float2 v1, float2 v2, int2 *v3); \
194_RS_RUNTIME float3 __attribute__((pure, overloadable)) \
195 fnc(float3 v1, float3 v2, int3 *v3); \
196_RS_RUNTIME float4 __attribute__((pure, overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800197 fnc(float4 v1, float4 v2, int4 *v3);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800198
Stephen Hinese7812282013-06-19 00:07:04 -0700199#endif // DOXYGEN
200
Stephen Hines3e6482f2011-01-19 12:51:33 -0800201
Jason Samsef823642011-08-31 14:52:08 -0700202/**
203 * Return the inverse cosine.
204 *
205 * Supports float, float2, float3, float4
206 */
Stephen Hines52132472013-04-30 15:45:22 -0700207extern float __attribute__((const, overloadable)) acos(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800208FN_FUNC_FN(acos)
Jason Sams22fa3712010-05-19 17:22:57 -0700209
Jason Samsef823642011-08-31 14:52:08 -0700210/**
211 * Return the inverse hyperbolic cosine.
212 *
213 * Supports float, float2, float3, float4
214 */
Stephen Hines52132472013-04-30 15:45:22 -0700215extern float __attribute__((const, overloadable)) acosh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800216FN_FUNC_FN(acosh)
Jason Sams22fa3712010-05-19 17:22:57 -0700217
Jason Samsef823642011-08-31 14:52:08 -0700218/**
219 * Return the inverse cosine divided by PI.
220 *
221 * Supports float, float2, float3, float4
222 */
Stephen Hines52132472013-04-30 15:45:22 -0700223_RS_RUNTIME float __attribute__((const, overloadable)) acospi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800224FN_FUNC_FN(acospi)
Jason Sams22fa3712010-05-19 17:22:57 -0700225
Jason Samsef823642011-08-31 14:52:08 -0700226/**
227 * Return the inverse sine.
228 *
229 * Supports float, float2, float3, float4
230 */
Stephen Hines52132472013-04-30 15:45:22 -0700231extern float __attribute__((const, overloadable)) asin(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800232FN_FUNC_FN(asin)
Jason Sams22fa3712010-05-19 17:22:57 -0700233
Jason Samsef823642011-08-31 14:52:08 -0700234/**
235 * Return the inverse hyperbolic sine.
236 *
237 * Supports float, float2, float3, float4
238 */
Stephen Hines52132472013-04-30 15:45:22 -0700239extern float __attribute__((const, overloadable)) asinh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800240FN_FUNC_FN(asinh)
Jason Sams22fa3712010-05-19 17:22:57 -0700241
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800242
Jason Samsef823642011-08-31 14:52:08 -0700243/**
244 * Return the inverse sine divided by PI.
245 *
246 * Supports float, float2, float3, float4
247 */
Stephen Hines52132472013-04-30 15:45:22 -0700248_RS_RUNTIME float __attribute__((const, overloadable)) asinpi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800249FN_FUNC_FN(asinpi)
Jason Sams22fa3712010-05-19 17:22:57 -0700250
Jason Samsef823642011-08-31 14:52:08 -0700251/**
252 * Return the inverse tangent.
253 *
254 * Supports float, float2, float3, float4
255 */
Stephen Hines52132472013-04-30 15:45:22 -0700256extern float __attribute__((const, overloadable)) atan(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800257FN_FUNC_FN(atan)
Jason Sams22fa3712010-05-19 17:22:57 -0700258
Jason Samsef823642011-08-31 14:52:08 -0700259/**
260 * Return the inverse tangent of y / x.
261 *
262 * Supports float, float2, float3, float4. Both arguments must be of the same
263 * type.
264 *
265 * @param y
266 * @param x
267 */
Stephen Hines52132472013-04-30 15:45:22 -0700268extern float __attribute__((const, overloadable)) atan2(float y, float x);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800269FN_FUNC_FN_FN(atan2)
Jason Sams22fa3712010-05-19 17:22:57 -0700270
Jason Samsef823642011-08-31 14:52:08 -0700271/**
272 * Return the inverse hyperbolic tangent.
273 *
274 * Supports float, float2, float3, float4
275 */
Stephen Hines52132472013-04-30 15:45:22 -0700276extern float __attribute__((const, overloadable)) atanh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800277FN_FUNC_FN(atanh)
Jason Sams22fa3712010-05-19 17:22:57 -0700278
Jason Samsef823642011-08-31 14:52:08 -0700279/**
280 * Return the inverse tangent divided by PI.
281 *
282 * Supports float, float2, float3, float4
283 */
Stephen Hines52132472013-04-30 15:45:22 -0700284_RS_RUNTIME float __attribute__((const, overloadable)) atanpi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800285FN_FUNC_FN(atanpi)
Jason Sams22fa3712010-05-19 17:22:57 -0700286
Jason Samsef823642011-08-31 14:52:08 -0700287/**
288 * Return the inverse tangent of y / x, divided by PI.
289 *
290 * Supports float, float2, float3, float4. Both arguments must be of the same
291 * type.
292 *
293 * @param y
294 * @param x
295 */
Stephen Hines52132472013-04-30 15:45:22 -0700296_RS_RUNTIME float __attribute__((const, overloadable)) atan2pi(float y, float x);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800297FN_FUNC_FN_FN(atan2pi)
Jason Sams22fa3712010-05-19 17:22:57 -0700298
Jason Samsef823642011-08-31 14:52:08 -0700299
300/**
301 * Return the cube root.
302 *
303 * Supports float, float2, float3, float4.
304 */
Stephen Hines52132472013-04-30 15:45:22 -0700305extern float __attribute__((const, overloadable)) cbrt(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800306FN_FUNC_FN(cbrt)
Jason Sams22fa3712010-05-19 17:22:57 -0700307
Jason Samsef823642011-08-31 14:52:08 -0700308/**
309 * Return the smallest integer not less than a value.
310 *
311 * Supports float, float2, float3, float4.
312 */
Stephen Hines52132472013-04-30 15:45:22 -0700313extern float __attribute__((const, overloadable)) ceil(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800314FN_FUNC_FN(ceil)
Jason Sams22fa3712010-05-19 17:22:57 -0700315
Jason Samsef823642011-08-31 14:52:08 -0700316/**
317 * Copy the sign bit from y to x.
318 *
319 * Supports float, float2, float3, float4. Both arguments must be of the same
320 * type.
321 *
322 * @param x
323 * @param y
324 */
Stephen Hines52132472013-04-30 15:45:22 -0700325extern float __attribute__((const, overloadable)) copysign(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800326FN_FUNC_FN_FN(copysign)
Jason Sams22fa3712010-05-19 17:22:57 -0700327
Jason Samsef823642011-08-31 14:52:08 -0700328/**
329 * Return the cosine.
330 *
331 * Supports float, float2, float3, float4.
332 */
Stephen Hines52132472013-04-30 15:45:22 -0700333extern float __attribute__((const, overloadable)) cos(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800334FN_FUNC_FN(cos)
Jason Sams22fa3712010-05-19 17:22:57 -0700335
Jason Samsef823642011-08-31 14:52:08 -0700336/**
337 * Return the hypebolic cosine.
338 *
339 * Supports float, float2, float3, float4.
340 */
Stephen Hines52132472013-04-30 15:45:22 -0700341extern float __attribute__((const, overloadable)) cosh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800342FN_FUNC_FN(cosh)
Jason Sams22fa3712010-05-19 17:22:57 -0700343
Jason Samsef823642011-08-31 14:52:08 -0700344/**
345 * Return the cosine of the value * PI.
346 *
347 * Supports float, float2, float3, float4.
348 */
Stephen Hines52132472013-04-30 15:45:22 -0700349_RS_RUNTIME float __attribute__((const, overloadable)) cospi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800350FN_FUNC_FN(cospi)
Jason Sams22fa3712010-05-19 17:22:57 -0700351
Jason Samsef823642011-08-31 14:52:08 -0700352/**
353 * Return the complementary error function.
354 *
355 * Supports float, float2, float3, float4.
356 */
Stephen Hines52132472013-04-30 15:45:22 -0700357extern float __attribute__((const, overloadable)) erfc(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800358FN_FUNC_FN(erfc)
Jason Sams22fa3712010-05-19 17:22:57 -0700359
Jason Samsef823642011-08-31 14:52:08 -0700360/**
361 * Return the error function.
362 *
363 * Supports float, float2, float3, float4.
364 */
Stephen Hines52132472013-04-30 15:45:22 -0700365extern float __attribute__((const, overloadable)) erf(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800366FN_FUNC_FN(erf)
Jason Sams22fa3712010-05-19 17:22:57 -0700367
Jason Samsef823642011-08-31 14:52:08 -0700368/**
369 * Return e ^ value.
370 *
371 * Supports float, float2, float3, float4.
372 */
Stephen Hines52132472013-04-30 15:45:22 -0700373extern float __attribute__((const, overloadable)) exp(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800374FN_FUNC_FN(exp)
Jason Sams22fa3712010-05-19 17:22:57 -0700375
Jason Samsef823642011-08-31 14:52:08 -0700376/**
377 * Return 2 ^ value.
378 *
379 * Supports float, float2, float3, float4.
380 */
Stephen Hines52132472013-04-30 15:45:22 -0700381extern float __attribute__((const, overloadable)) exp2(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800382FN_FUNC_FN(exp2)
Jason Sams22fa3712010-05-19 17:22:57 -0700383
Jason Samsef823642011-08-31 14:52:08 -0700384/**
385 * Return x ^ y.
386 *
387 * Supports float, float2, float3, float4. Both arguments must be of the same
388 * type.
389 */
Stephen Hines52132472013-04-30 15:45:22 -0700390extern float __attribute__((const, overloadable)) pow(float x, float y);
Jason Samsef823642011-08-31 14:52:08 -0700391FN_FUNC_FN_FN(pow)
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800392
Jason Samsef823642011-08-31 14:52:08 -0700393/**
394 * Return 10 ^ value.
395 *
396 * Supports float, float2, float3, float4.
397 */
Stephen Hines52132472013-04-30 15:45:22 -0700398_RS_RUNTIME float __attribute__((const, overloadable)) exp10(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800399FN_FUNC_FN(exp10)
Jason Sams22fa3712010-05-19 17:22:57 -0700400
Jason Samsef823642011-08-31 14:52:08 -0700401/**
402 * Return (e ^ value) - 1.
403 *
404 * Supports float, float2, float3, float4.
405 */
Stephen Hines52132472013-04-30 15:45:22 -0700406extern float __attribute__((const, overloadable)) expm1(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800407FN_FUNC_FN(expm1)
Jason Sams22fa3712010-05-19 17:22:57 -0700408
Jason Samsef823642011-08-31 14:52:08 -0700409/**
410 * Return the absolute value of a value.
411 *
412 * Supports float, float2, float3, float4.
413 */
Stephen Hines52132472013-04-30 15:45:22 -0700414extern float __attribute__((const, overloadable)) fabs(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800415FN_FUNC_FN(fabs)
Jason Sams22fa3712010-05-19 17:22:57 -0700416
Jason Samsef823642011-08-31 14:52:08 -0700417/**
418 * Return the positive difference between two values.
419 *
420 * Supports float, float2, float3, float4. Both arguments must be of the same
421 * type.
422 */
Stephen Hines52132472013-04-30 15:45:22 -0700423extern float __attribute__((const, overloadable)) fdim(float, float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800424FN_FUNC_FN_FN(fdim)
Jason Sams22fa3712010-05-19 17:22:57 -0700425
Jason Samsef823642011-08-31 14:52:08 -0700426/**
427 * Return the smallest integer not greater than a value.
428 *
429 * Supports float, float2, float3, float4.
430 */
Stephen Hines52132472013-04-30 15:45:22 -0700431extern float __attribute__((const, overloadable)) floor(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800432FN_FUNC_FN(floor)
Jason Sams22fa3712010-05-19 17:22:57 -0700433
Jason Samsef823642011-08-31 14:52:08 -0700434/**
435 * Return a*b + c.
436 *
437 * Supports float, float2, float3, float4.
438 */
Stephen Hines52132472013-04-30 15:45:22 -0700439extern float __attribute__((const, overloadable)) fma(float a, float b, float c);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800440FN_FUNC_FN_FN_FN(fma)
Jason Sams22fa3712010-05-19 17:22:57 -0700441
Jason Samsef823642011-08-31 14:52:08 -0700442/**
443 * Return (x < y ? y : x)
444 *
445 * Supports float, float2, float3, float4.
446 * @param x: may be float, float2, float3, float4
447 * @param y: may be float or vector. If vector must match type of x.
448 */
Stephen Hines52132472013-04-30 15:45:22 -0700449extern float __attribute__((const, overloadable)) fmax(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800450FN_FUNC_FN_FN(fmax);
451FN_FUNC_FN_F(fmax);
Jason Sams22fa3712010-05-19 17:22:57 -0700452
Jason Samsef823642011-08-31 14:52:08 -0700453/**
454 * Return (x > y ? y : x)
455 *
456 * @param x: may be float, float2, float3, float4
457 * @param y: may be float or vector. If vector must match type of x.
458 */
Stephen Hines52132472013-04-30 15:45:22 -0700459extern float __attribute__((const, overloadable)) fmin(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800460FN_FUNC_FN_FN(fmin);
461FN_FUNC_FN_F(fmin);
Jason Sams22fa3712010-05-19 17:22:57 -0700462
Jason Samsef823642011-08-31 14:52:08 -0700463/**
464 * Return the remainder from x / y
465 *
466 * Supports float, float2, float3, float4.
467 */
Stephen Hines52132472013-04-30 15:45:22 -0700468extern float __attribute__((const, overloadable)) fmod(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800469FN_FUNC_FN_FN(fmod)
Jason Sams22fa3712010-05-19 17:22:57 -0700470
Tim Murray4d3201d2013-01-03 11:58:39 -0800471/**
472 * Return fractional part of v
473 *
Jason Samsef823642011-08-31 14:52:08 -0700474 * @param iptr iptr[0] will be set to the floor of the input value.
475 * Supports float, float2, float3, float4.
476 */
Stephen Hines52132472013-04-30 15:45:22 -0700477_RS_RUNTIME float __attribute__((pure, overloadable)) fract(float v, float *iptr);
Stephen Hines47b15302011-01-19 18:06:34 -0800478FN_FUNC_FN_PFN(fract)
Jason Sams22fa3712010-05-19 17:22:57 -0700479
Jason Samsef823642011-08-31 14:52:08 -0700480/**
Stephen Hines891bcfe2013-01-16 18:46:43 -0800481 * Return fractional part of v
482 *
483 * Supports float, float2, float3, float4.
484 */
Stephen Hines52132472013-04-30 15:45:22 -0700485static inline float __attribute__((const, overloadable)) fract(float v) {
Stephen Hines891bcfe2013-01-16 18:46:43 -0800486 float unused;
487 return fract(v, &unused);
488}
489
Stephen Hines52132472013-04-30 15:45:22 -0700490static inline float2 __attribute__((const, overloadable)) fract(float2 v) {
Stephen Hines891bcfe2013-01-16 18:46:43 -0800491 float2 unused;
492 return fract(v, &unused);
493}
494
Stephen Hines52132472013-04-30 15:45:22 -0700495static inline float3 __attribute__((const, overloadable)) fract(float3 v) {
Stephen Hines891bcfe2013-01-16 18:46:43 -0800496 float3 unused;
497 return fract(v, &unused);
498}
499
Stephen Hines52132472013-04-30 15:45:22 -0700500static inline float4 __attribute__((const, overloadable)) fract(float4 v) {
Stephen Hines891bcfe2013-01-16 18:46:43 -0800501 float4 unused;
502 return fract(v, &unused);
503}
504
505/**
Jason Samsef823642011-08-31 14:52:08 -0700506 * Return the mantissa and place the exponent into iptr[0]
507 *
508 * @param v Supports float, float2, float3, float4.
509 * @param iptr Must have the same vector size as v.
510 */
Stephen Hines52132472013-04-30 15:45:22 -0700511extern float __attribute__((pure, overloadable)) frexp(float v, int *iptr);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800512FN_FUNC_FN_PIN(frexp)
Jason Sams22fa3712010-05-19 17:22:57 -0700513
Jason Samsef823642011-08-31 14:52:08 -0700514/**
515 * Return sqrt(x*x + y*y)
516 *
517 * Supports float, float2, float3, float4.
518 */
Stephen Hines52132472013-04-30 15:45:22 -0700519extern float __attribute__((const, overloadable)) hypot(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800520FN_FUNC_FN_FN(hypot)
Jason Sams22fa3712010-05-19 17:22:57 -0700521
Jason Samsef823642011-08-31 14:52:08 -0700522/**
523 * Return the integer exponent of a value
524 *
525 * Supports 1,2,3,4 components
526 */
Stephen Hines52132472013-04-30 15:45:22 -0700527extern int __attribute__((const, overloadable)) ilogb(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800528IN_FUNC_FN(ilogb)
Jason Sams22fa3712010-05-19 17:22:57 -0700529
Jason Samsef823642011-08-31 14:52:08 -0700530/**
531 * Return (x * 2^y)
532 *
533 * @param x Supports 1,2,3,4 components
534 * @param y Supports single component or matching vector.
535 */
Stephen Hines52132472013-04-30 15:45:22 -0700536extern float __attribute__((const, overloadable)) ldexp(float x, int y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800537FN_FUNC_FN_IN(ldexp)
538FN_FUNC_FN_I(ldexp)
Jason Sams22fa3712010-05-19 17:22:57 -0700539
Jason Samsef823642011-08-31 14:52:08 -0700540/**
541 * Return the log gamma
542 *
543 * Supports 1,2,3,4 components
544 */
Stephen Hines52132472013-04-30 15:45:22 -0700545extern float __attribute__((const, overloadable)) lgamma(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800546FN_FUNC_FN(lgamma)
Jason Samsef823642011-08-31 14:52:08 -0700547
548/**
549 * Return the log gamma and sign
550 *
551 * @param x Supports 1,2,3,4 components
552 * @param y Supports matching vector.
553 */
Stephen Hines52132472013-04-30 15:45:22 -0700554extern float __attribute__((pure, overloadable)) lgamma(float x, int* y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800555FN_FUNC_FN_PIN(lgamma)
Jason Sams22fa3712010-05-19 17:22:57 -0700556
Jason Samsef823642011-08-31 14:52:08 -0700557/**
558 * Return the natural logarithm
559 *
560 * Supports 1,2,3,4 components
561 */
Stephen Hines52132472013-04-30 15:45:22 -0700562extern float __attribute__((const, overloadable)) log(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800563FN_FUNC_FN(log)
Jason Sams22fa3712010-05-19 17:22:57 -0700564
Jason Samsef823642011-08-31 14:52:08 -0700565/**
566 * Return the base 10 logarithm
567 *
568 * Supports 1,2,3,4 components
569 */
Stephen Hines52132472013-04-30 15:45:22 -0700570extern float __attribute__((const, overloadable)) log10(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800571FN_FUNC_FN(log10)
Jason Sams1b937f52010-06-09 14:26:16 -0700572
Jason Samsef823642011-08-31 14:52:08 -0700573/**
574 * Return the base 2 logarithm
575 *
576 * Supports 1,2,3,4 components
577 */
Stephen Hines52132472013-04-30 15:45:22 -0700578_RS_RUNTIME float __attribute__((const, overloadable)) log2(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800579FN_FUNC_FN(log2)
Jason Sams22fa3712010-05-19 17:22:57 -0700580
Jason Samsef823642011-08-31 14:52:08 -0700581/**
582 * Return the natural logarithm of (v + 1.0f)
583 *
584 * Supports 1,2,3,4 components
585 */
Stephen Hines52132472013-04-30 15:45:22 -0700586extern float __attribute__((const, overloadable)) log1p(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800587FN_FUNC_FN(log1p)
Jason Sams22fa3712010-05-19 17:22:57 -0700588
Jason Samsef823642011-08-31 14:52:08 -0700589/**
590 * Compute the exponent of the value.
591 *
592 * Supports 1,2,3,4 components
593 */
Stephen Hines52132472013-04-30 15:45:22 -0700594extern float __attribute__((const, overloadable)) logb(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800595FN_FUNC_FN(logb)
Jason Sams22fa3712010-05-19 17:22:57 -0700596
Jason Samsef823642011-08-31 14:52:08 -0700597/**
598 * Compute (a * b) + c
599 *
600 * Supports 1,2,3,4 components
601 */
Stephen Hines52132472013-04-30 15:45:22 -0700602extern float __attribute__((const, overloadable)) mad(float a, float b, float c);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800603FN_FUNC_FN_FN_FN(mad)
Jason Sams22fa3712010-05-19 17:22:57 -0700604
Jason Samsef823642011-08-31 14:52:08 -0700605/**
Stephen Hinescb058022012-05-29 17:10:05 -0700606 * Return the integral and fractional components of a number.
Jason Samsef823642011-08-31 14:52:08 -0700607 * Supports 1,2,3,4 components
608 *
609 * @param x Source value
610 * @param iret iret[0] will be set to the integral portion of the number.
611 * @return The floating point portion of the value.
612 */
Stephen Hines52132472013-04-30 15:45:22 -0700613extern float __attribute__((pure, overloadable)) modf(float x, float *iret);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800614FN_FUNC_FN_PFN(modf);
Jason Sams22fa3712010-05-19 17:22:57 -0700615
Stephen Hines52132472013-04-30 15:45:22 -0700616extern float __attribute__((const, overloadable)) nan(uint);
Jason Sams22fa3712010-05-19 17:22:57 -0700617
Jason Samsef823642011-08-31 14:52:08 -0700618/**
619 * Return the next floating point number from x towards y.
620 *
621 * Supports 1,2,3,4 components
622 */
Stephen Hines52132472013-04-30 15:45:22 -0700623extern float __attribute__((const, overloadable)) nextafter(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800624FN_FUNC_FN_FN(nextafter)
Jason Sams22fa3712010-05-19 17:22:57 -0700625
Jason Samsef823642011-08-31 14:52:08 -0700626/**
627 * Return (v ^ p).
628 *
629 * Supports 1,2,3,4 components
630 */
Stephen Hines52132472013-04-30 15:45:22 -0700631_RS_RUNTIME float __attribute__((const, overloadable)) pown(float v, int p);
Jason Samsef823642011-08-31 14:52:08 -0700632FN_FUNC_FN_IN(pown)
Jason Sams22fa3712010-05-19 17:22:57 -0700633
Jason Samsef823642011-08-31 14:52:08 -0700634/**
635 * Return (v ^ p).
636 * @param v must be greater than 0.
637 *
638 * Supports 1,2,3,4 components
639 */
Stephen Hines52132472013-04-30 15:45:22 -0700640_RS_RUNTIME float __attribute__((const, overloadable)) powr(float v, float p);
Jason Samsef823642011-08-31 14:52:08 -0700641FN_FUNC_FN_FN(powr)
Jason Sams22fa3712010-05-19 17:22:57 -0700642
Jason Samsef823642011-08-31 14:52:08 -0700643/**
644 * Return round x/y to the nearest integer then compute the remander.
645 *
646 * Supports 1,2,3,4 components
647 */
Stephen Hines52132472013-04-30 15:45:22 -0700648extern float __attribute__((const, overloadable)) remainder(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800649FN_FUNC_FN_FN(remainder)
Jason Sams22fa3712010-05-19 17:22:57 -0700650
Jason Samsef823642011-08-31 14:52:08 -0700651// document once we know the precision of bionic
Stephen Hines52132472013-04-30 15:45:22 -0700652extern float __attribute__((pure, overloadable)) remquo(float, float, int *);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800653FN_FUNC_FN_FN_PIN(remquo)
Jason Sams22fa3712010-05-19 17:22:57 -0700654
Jason Samsef823642011-08-31 14:52:08 -0700655/**
656 * Round to the nearest integral value.
657 *
658 * Supports 1,2,3,4 components
659 */
Stephen Hines52132472013-04-30 15:45:22 -0700660extern float __attribute__((const, overloadable)) rint(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800661FN_FUNC_FN(rint)
Jason Sams22fa3712010-05-19 17:22:57 -0700662
Jason Samsef823642011-08-31 14:52:08 -0700663/**
664 * Compute the Nth root of a value.
665 *
666 * Supports 1,2,3,4 components
667 */
Stephen Hines52132472013-04-30 15:45:22 -0700668_RS_RUNTIME float __attribute__((const, overloadable)) rootn(float v, int n);
Jason Samsef823642011-08-31 14:52:08 -0700669FN_FUNC_FN_IN(rootn)
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800670
Jason Samsef823642011-08-31 14:52:08 -0700671/**
672 * Round to the nearest integral value. Half values are rounded away from zero.
673 *
674 * Supports 1,2,3,4 components
675 */
Stephen Hines52132472013-04-30 15:45:22 -0700676extern float __attribute__((const, overloadable)) round(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800677FN_FUNC_FN(round)
Jason Sams22fa3712010-05-19 17:22:57 -0700678
Jason Samsef823642011-08-31 14:52:08 -0700679/**
680 * Return the square root of a value.
681 *
682 * Supports 1,2,3,4 components
683 */
Stephen Hines52132472013-04-30 15:45:22 -0700684extern float __attribute__((const, overloadable)) sqrt(float);
Jason Samsef823642011-08-31 14:52:08 -0700685FN_FUNC_FN(sqrt)
686
687/**
688 * Return (1 / sqrt(value)).
689 *
Jason Samsef823642011-08-31 14:52:08 -0700690 * Supports 1,2,3,4 components
691 */
Stephen Hines52132472013-04-30 15:45:22 -0700692_RS_RUNTIME float __attribute__((const, overloadable)) rsqrt(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800693FN_FUNC_FN(rsqrt)
Jason Sams1b937f52010-06-09 14:26:16 -0700694
Jason Samsef823642011-08-31 14:52:08 -0700695/**
696 * Return the sine of a value specified in radians.
697 *
698 * @param v The incoming value in radians
699 * Supports 1,2,3,4 components
700 */
Stephen Hines52132472013-04-30 15:45:22 -0700701extern float __attribute__((const, overloadable)) sin(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800702FN_FUNC_FN(sin)
Jason Sams1b937f52010-06-09 14:26:16 -0700703
Jason Samsef823642011-08-31 14:52:08 -0700704/**
705 * Return the sine and cosine of a value.
706 *
707 * @return sine
708 * @param v The incoming value in radians
709 * @param *cosptr cosptr[0] will be set to the cosine value.
710 *
711 * Supports 1,2,3,4 components
712 */
Stephen Hines52132472013-04-30 15:45:22 -0700713_RS_RUNTIME float __attribute__((pure, overloadable)) sincos(float v, float *cosptr);
Jason Samsef823642011-08-31 14:52:08 -0700714FN_FUNC_FN_PFN(sincos);
Jason Sams1b937f52010-06-09 14:26:16 -0700715
Jason Samsef823642011-08-31 14:52:08 -0700716/**
717 * Return the hyperbolic sine of a value specified in radians.
718 *
719 * Supports 1,2,3,4 components
720 */
Stephen Hines52132472013-04-30 15:45:22 -0700721extern float __attribute__((const, overloadable)) sinh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800722FN_FUNC_FN(sinh)
Jason Sams1b937f52010-06-09 14:26:16 -0700723
Jason Samsef823642011-08-31 14:52:08 -0700724/**
725 * Return the sin(v * PI).
726 *
727 * Supports 1,2,3,4 components
728 */
Stephen Hines52132472013-04-30 15:45:22 -0700729_RS_RUNTIME float __attribute__((const, overloadable)) sinpi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800730FN_FUNC_FN(sinpi)
Jason Sams1b937f52010-06-09 14:26:16 -0700731
Jason Samsef823642011-08-31 14:52:08 -0700732/**
733 * Return the tangent of a value.
734 *
735 * Supports 1,2,3,4 components
736 * @param v The incoming value in radians
737 */
Stephen Hines52132472013-04-30 15:45:22 -0700738extern float __attribute__((const, overloadable)) tan(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800739FN_FUNC_FN(tan)
Jason Sams22fa3712010-05-19 17:22:57 -0700740
Jason Samsef823642011-08-31 14:52:08 -0700741/**
742 * Return the hyperbolic tangent of a value.
743 *
744 * Supports 1,2,3,4 components
745 * @param v The incoming value in radians
746 */
Stephen Hines52132472013-04-30 15:45:22 -0700747extern float __attribute__((const, overloadable)) tanh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800748FN_FUNC_FN(tanh)
Jason Sams22fa3712010-05-19 17:22:57 -0700749
Jason Samsef823642011-08-31 14:52:08 -0700750/**
751 * Return tan(v * PI)
752 *
753 * Supports 1,2,3,4 components
754 */
Stephen Hines52132472013-04-30 15:45:22 -0700755_RS_RUNTIME float __attribute__((const, overloadable)) tanpi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800756FN_FUNC_FN(tanpi)
Jason Sams22fa3712010-05-19 17:22:57 -0700757
Jason Samsef823642011-08-31 14:52:08 -0700758/**
759 * Compute the gamma function of a value.
760 *
761 * Supports 1,2,3,4 components
762 */
Stephen Hines52132472013-04-30 15:45:22 -0700763extern float __attribute__((const, overloadable)) tgamma(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800764FN_FUNC_FN(tgamma)
Jason Sams22fa3712010-05-19 17:22:57 -0700765
Jason Samsef823642011-08-31 14:52:08 -0700766/**
767 * Round to integral using truncation.
768 *
769 * Supports 1,2,3,4 components
770 */
Stephen Hines52132472013-04-30 15:45:22 -0700771extern float __attribute__((const, overloadable)) trunc(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800772FN_FUNC_FN(trunc)
Jason Sams22fa3712010-05-19 17:22:57 -0700773
Stephen Hinese7812282013-06-19 00:07:04 -0700774#ifdef DOXYGEN
775
776#define XN_FUNC_YN(typeout, fnc, typein) \
777extern typeout __attribute__((overloadable)) fnc(typein v);
778
779#define XN_FUNC_XN_XN_BODY(type, fnc, body) \
780_RS_RUNTIME type __attribute__((overloadable)) \
781 fnc(type v1, type v2);
782
783#else
Jason Sams22fa3712010-05-19 17:22:57 -0700784
Stephen Hines52132472013-04-30 15:45:22 -0700785#define XN_FUNC_YN(typeout, fnc, typein) \
Stephen Hinese7812282013-06-19 00:07:04 -0700786extern typeout __attribute__((const, overloadable)) fnc(typein v); \
Stephen Hines52132472013-04-30 15:45:22 -0700787_RS_RUNTIME typeout##2 __attribute__((const, overloadable)) fnc(typein##2 v); \
788_RS_RUNTIME typeout##3 __attribute__((const, overloadable)) fnc(typein##3 v); \
789_RS_RUNTIME typeout##4 __attribute__((const, overloadable)) fnc(typein##4 v);
Jason Sams22fa3712010-05-19 17:22:57 -0700790
Stephen Hinese7812282013-06-19 00:07:04 -0700791#define XN_FUNC_XN_XN_BODY(type, fnc, body) \
792_RS_RUNTIME type __attribute__((const, overloadable)) \
793 fnc(type v1, type v2); \
794_RS_RUNTIME type##2 __attribute__((const, overloadable)) \
795 fnc(type##2 v1, type##2 v2); \
796_RS_RUNTIME type##3 __attribute__((const, overloadable)) \
797 fnc(type##3 v1, type##3 v2); \
798_RS_RUNTIME type##4 __attribute__((const, overloadable)) \
799 fnc(type##4 v1, type##4 v2);
800
801#endif // DOXYGEN
802
Stephen Hines47b15302011-01-19 18:06:34 -0800803#define UIN_FUNC_IN(fnc) \
Stephen Hines3e6482f2011-01-19 12:51:33 -0800804XN_FUNC_YN(uchar, fnc, char) \
805XN_FUNC_YN(ushort, fnc, short) \
806XN_FUNC_YN(uint, fnc, int)
Jason Sams22fa3712010-05-19 17:22:57 -0700807
Stephen Hines47b15302011-01-19 18:06:34 -0800808#define IN_FUNC_IN(fnc) \
Stephen Hines3e6482f2011-01-19 12:51:33 -0800809XN_FUNC_YN(uchar, fnc, uchar) \
810XN_FUNC_YN(char, fnc, char) \
811XN_FUNC_YN(ushort, fnc, ushort) \
812XN_FUNC_YN(short, fnc, short) \
813XN_FUNC_YN(uint, fnc, uint) \
814XN_FUNC_YN(int, fnc, int)
Jason Sams22fa3712010-05-19 17:22:57 -0700815
Stephen Hinescb058022012-05-29 17:10:05 -0700816#define IN_FUNC_IN_IN_BODY(fnc, body) \
817XN_FUNC_XN_XN_BODY(uchar, fnc, body) \
818XN_FUNC_XN_XN_BODY(char, fnc, body) \
819XN_FUNC_XN_XN_BODY(ushort, fnc, body) \
820XN_FUNC_XN_XN_BODY(short, fnc, body) \
821XN_FUNC_XN_XN_BODY(uint, fnc, body) \
822XN_FUNC_XN_XN_BODY(int, fnc, body) \
Stephen Hines3e6482f2011-01-19 12:51:33 -0800823XN_FUNC_XN_XN_BODY(float, fnc, body)
Stephen Hinesb902e4c2011-01-14 18:49:01 -0800824
Stephen Hinescb058022012-05-29 17:10:05 -0700825/**
Stephen Hinese7812282013-06-19 00:07:04 -0700826 * \fn uchar abs(char)
Stephen Hinescb058022012-05-29 17:10:05 -0700827 * Return the absolute value of a value.
828 *
829 * Supports 1,2,3,4 components of char, short, int.
830 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800831UIN_FUNC_IN(abs)
Stephen Hinescb058022012-05-29 17:10:05 -0700832
833/**
834 * Return the number of leading 0-bits in a value.
835 *
836 * Supports 1,2,3,4 components of uchar, char, ushort, short, uint, int.
837 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800838IN_FUNC_IN(clz)
Stephen Hinesb902e4c2011-01-14 18:49:01 -0800839
Jason Samsdc2c3e62011-08-31 16:44:18 -0700840/**
841 * Return the minimum of two values.
842 *
843 * Supports 1,2,3,4 components of uchar, char, ushort, short, uint, int, float.
844 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800845IN_FUNC_IN_IN_BODY(min, (v1 < v2 ? v1 : v2))
846FN_FUNC_FN_F(min)
Stephen Hinesb902e4c2011-01-14 18:49:01 -0800847
Jason Samsdc2c3e62011-08-31 16:44:18 -0700848/**
849 * Return the maximum of two values.
850 *
851 * Supports 1,2,3,4 components of uchar, char, ushort, short, uint, int, float.
852 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800853IN_FUNC_IN_IN_BODY(max, (v1 > v2 ? v1 : v2))
854FN_FUNC_FN_F(max)
Jason Sams22fa3712010-05-19 17:22:57 -0700855
Jason Samsdc2c3e62011-08-31 16:44:18 -0700856/**
857 * Clamp a value to a specified high and low bound.
858 *
859 * @param amount value to be clamped. Supports 1,2,3,4 components
860 * @param low Lower bound, must be scalar or matching vector.
861 * @param high High bound, must match type of low
862 */
Jason Samsc6261352013-05-24 14:51:52 -0700863
864#if !defined(RS_VERSION) || (RS_VERSION < 19)
Stephen Hines52132472013-04-30 15:45:22 -0700865_RS_RUNTIME float __attribute__((const, overloadable)) clamp(float amount, float low, float high);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700866FN_FUNC_FN_FN_FN(clamp)
867FN_FUNC_FN_F_F(clamp)
Jason Samsc6261352013-05-24 14:51:52 -0700868#else
869#define _CLAMP(T) \
870extern T __attribute__((overloadable)) clamp(T amount, T low, T high); \
871extern T##2 __attribute__((overloadable)) clamp(T##2 amount, T##2 low, T##2 high); \
872extern T##3 __attribute__((overloadable)) clamp(T##3 amount, T##3 low, T##3 high); \
873extern T##4 __attribute__((overloadable)) clamp(T##4 amount, T##4 low, T##4 high); \
874extern T##2 __attribute__((overloadable)) clamp(T##2 amount, T low, T high); \
875extern T##3 __attribute__((overloadable)) clamp(T##3 amount, T low, T high); \
876extern T##4 __attribute__((overloadable)) clamp(T##4 amount, T low, T high)
877
878_CLAMP(float);
879_CLAMP(double);
880_CLAMP(char);
881_CLAMP(uchar);
882_CLAMP(short);
883_CLAMP(ushort);
884_CLAMP(int);
885_CLAMP(uint);
886_CLAMP(long);
887_CLAMP(ulong);
888
889#undef _CLAMP
890#endif
Jason Sams22fa3712010-05-19 17:22:57 -0700891
Jason Samsdc2c3e62011-08-31 16:44:18 -0700892/**
893 * Convert from radians to degrees.
894 *
895 * Supports 1,2,3,4 components
896 */
Stephen Hines52132472013-04-30 15:45:22 -0700897_RS_RUNTIME float __attribute__((const, overloadable)) degrees(float radians);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800898FN_FUNC_FN(degrees)
Jason Sams22fa3712010-05-19 17:22:57 -0700899
Jason Samsdc2c3e62011-08-31 16:44:18 -0700900/**
901 * return start + ((stop - start) * amount);
902 *
903 * Supports 1,2,3,4 components
904 */
Stephen Hines52132472013-04-30 15:45:22 -0700905_RS_RUNTIME float __attribute__((const, overloadable)) mix(float start, float stop, float amount);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700906FN_FUNC_FN_FN_FN(mix)
907FN_FUNC_FN_FN_F(mix)
Jason Sams22fa3712010-05-19 17:22:57 -0700908
Jason Samsdc2c3e62011-08-31 16:44:18 -0700909/**
910 * Convert from degrees to radians.
911 *
912 * Supports 1,2,3,4 components
913 */
Stephen Hines52132472013-04-30 15:45:22 -0700914_RS_RUNTIME float __attribute__((const, overloadable)) radians(float degrees);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800915FN_FUNC_FN(radians)
Jason Sams22fa3712010-05-19 17:22:57 -0700916
Jason Samsdc2c3e62011-08-31 16:44:18 -0700917/**
918 * if (v < edge)
919 * return 0.f;
920 * else
921 * return 1.f;
922 *
923 * Supports 1,2,3,4 components
924 */
Stephen Hines52132472013-04-30 15:45:22 -0700925_RS_RUNTIME float __attribute__((const, overloadable)) step(float edge, float v);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700926FN_FUNC_FN_FN(step)
927FN_FUNC_FN_F(step)
Jason Sams22fa3712010-05-19 17:22:57 -0700928
Jason Samsdc2c3e62011-08-31 16:44:18 -0700929// not implemented
Stephen Hines52132472013-04-30 15:45:22 -0700930extern float __attribute__((const, overloadable)) smoothstep(float, float, float);
931extern float2 __attribute__((const, overloadable)) smoothstep(float2, float2, float2);
932extern float3 __attribute__((const, overloadable)) smoothstep(float3, float3, float3);
933extern float4 __attribute__((const, overloadable)) smoothstep(float4, float4, float4);
934extern float2 __attribute__((const, overloadable)) smoothstep(float, float, float2);
935extern float3 __attribute__((const, overloadable)) smoothstep(float, float, float3);
936extern float4 __attribute__((const, overloadable)) smoothstep(float, float, float4);
Jason Sams22fa3712010-05-19 17:22:57 -0700937
Jason Samsdc2c3e62011-08-31 16:44:18 -0700938/**
Stephen Hinescb058022012-05-29 17:10:05 -0700939 * Return the sign of a value.
940 *
Jason Samsdc2c3e62011-08-31 16:44:18 -0700941 * if (v < 0) return -1.f;
942 * else if (v > 0) return 1.f;
943 * else return 0.f;
944 *
945 * Supports 1,2,3,4 components
946 */
Stephen Hines52132472013-04-30 15:45:22 -0700947_RS_RUNTIME float __attribute__((const, overloadable)) sign(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800948FN_FUNC_FN(sign)
Jason Sams22fa3712010-05-19 17:22:57 -0700949
Jason Samsdc2c3e62011-08-31 16:44:18 -0700950/**
951 * Compute the cross product of two vectors.
952 *
953 * Supports 3,4 components
954 */
Stephen Hines52132472013-04-30 15:45:22 -0700955_RS_RUNTIME float3 __attribute__((const, overloadable)) cross(float3 lhs, float3 rhs);
956_RS_RUNTIME float4 __attribute__((const, overloadable)) cross(float4 lhs, float4 rhs);
Jason Sams22fa3712010-05-19 17:22:57 -0700957
Jason Samsdc2c3e62011-08-31 16:44:18 -0700958/**
959 * Compute the dot product of two vectors.
960 *
961 * Supports 1,2,3,4 components
962 */
Stephen Hines52132472013-04-30 15:45:22 -0700963_RS_RUNTIME float __attribute__((const, overloadable)) dot(float lhs, float rhs);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700964F_FUNC_FN_FN(dot)
Jason Sams22fa3712010-05-19 17:22:57 -0700965
Jason Samsdc2c3e62011-08-31 16:44:18 -0700966/**
967 * Compute the length of a vector.
968 *
969 * Supports 1,2,3,4 components
970 */
Stephen Hines52132472013-04-30 15:45:22 -0700971_RS_RUNTIME float __attribute__((const, overloadable)) length(float v);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700972F_FUNC_FN(length)
Jason Sams22fa3712010-05-19 17:22:57 -0700973
Jason Samsdc2c3e62011-08-31 16:44:18 -0700974/**
975 * Compute the distance between two points.
976 *
977 * Supports 1,2,3,4 components
978 */
Stephen Hines52132472013-04-30 15:45:22 -0700979_RS_RUNTIME float __attribute__((const, overloadable)) distance(float lhs, float rhs);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700980F_FUNC_FN_FN(distance)
Jason Sams22fa3712010-05-19 17:22:57 -0700981
Jason Samsdc2c3e62011-08-31 16:44:18 -0700982/**
983 * Normalize a vector.
984 *
985 * Supports 1,2,3,4 components
986 */
Stephen Hines52132472013-04-30 15:45:22 -0700987_RS_RUNTIME float __attribute__((const, overloadable)) normalize(float v);
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700988FN_FUNC_FN(normalize)
989
Rajeev Sharma7150c932012-08-15 21:41:39 -0700990
991// New approx API functions
992#if (defined(RS_VERSION) && (RS_VERSION >= 17))
993
Rajeev Sharma65723fe2012-08-03 15:11:04 -0700994/**
995 * Return the approximate reciprocal of a value.
996 *
997 * Supports 1,2,3,4 components
998 */
Stephen Hines52132472013-04-30 15:45:22 -0700999_RS_RUNTIME float __attribute__((const, overloadable)) half_recip(float);
Jason Samsab4b0ef2012-09-20 15:39:18 -07001000FN_FUNC_FN(half_recip)
Rajeev Sharma65723fe2012-08-03 15:11:04 -07001001
1002/**
1003 * Return the approximate square root of a value.
1004 *
1005 * Supports 1,2,3,4 components
1006 */
Stephen Hines52132472013-04-30 15:45:22 -07001007_RS_RUNTIME float __attribute__((const, overloadable)) half_sqrt(float);
Jason Samsab4b0ef2012-09-20 15:39:18 -07001008FN_FUNC_FN(half_sqrt)
Rajeev Sharma65723fe2012-08-03 15:11:04 -07001009
1010/**
1011 * Return the approximate value of (1 / sqrt(value)).
1012 *
1013 * Supports 1,2,3,4 components
1014 */
Stephen Hines52132472013-04-30 15:45:22 -07001015_RS_RUNTIME float __attribute__((const, overloadable)) half_rsqrt(float v);
Jason Samsab4b0ef2012-09-20 15:39:18 -07001016FN_FUNC_FN(half_rsqrt)
Rajeev Sharma65723fe2012-08-03 15:11:04 -07001017
1018/**
1019 * Compute the approximate length of a vector.
1020 *
1021 * Supports 1,2,3,4 components
1022 */
Stephen Hines52132472013-04-30 15:45:22 -07001023_RS_RUNTIME float __attribute__((const, overloadable)) fast_length(float v);
Jason Samsab4b0ef2012-09-20 15:39:18 -07001024F_FUNC_FN(fast_length)
Rajeev Sharma65723fe2012-08-03 15:11:04 -07001025
1026/**
1027 * Compute the approximate distance between two points.
1028 *
1029 * Supports 1,2,3,4 components
1030 */
Stephen Hines52132472013-04-30 15:45:22 -07001031_RS_RUNTIME float __attribute__((const, overloadable)) fast_distance(float lhs, float rhs);
Jason Samsab4b0ef2012-09-20 15:39:18 -07001032F_FUNC_FN_FN(fast_distance)
Rajeev Sharma65723fe2012-08-03 15:11:04 -07001033
1034/**
1035 * Approximately normalize a vector.
1036 *
1037 * Supports 1,2,3,4 components
1038 */
Stephen Hines52132472013-04-30 15:45:22 -07001039_RS_RUNTIME float __attribute__((const, overloadable)) fast_normalize(float v);
Jason Samsab4b0ef2012-09-20 15:39:18 -07001040F_FUNC_FN(fast_normalize)
Rajeev Sharma7150c932012-08-15 21:41:39 -07001041
1042#endif // (defined(RS_VERSION) && (RS_VERSION >= 17))
1043
1044
Jason Sams59531f72013-01-18 14:10:32 -08001045
1046#if (defined(RS_VERSION) && (RS_VERSION >= 18))
1047// Fast native math functions.
1048
1049
1050/**
1051 * Fast approximate exp2
1052 * valid for inputs -125.f to 125.f
1053 * Max 8192 ulps of error
1054 *
1055 * Supports 1,2,3,4 components
1056 */
Stephen Hines52132472013-04-30 15:45:22 -07001057_RS_RUNTIME float __attribute__((const, overloadable)) native_exp2(float v);
Jason Sams59531f72013-01-18 14:10:32 -08001058FN_FUNC_FN(native_exp2)
1059
1060/**
1061 * Fast approximate exp
1062 * valid for inputs -86.f to 86.f
1063 * Max 8192 ulps of error
1064 *
1065 * Supports 1,2,3,4 components
1066 */
Stephen Hines52132472013-04-30 15:45:22 -07001067_RS_RUNTIME float __attribute__((const, overloadable)) native_exp(float v);
Jason Sams59531f72013-01-18 14:10:32 -08001068FN_FUNC_FN(native_exp)
1069
1070/**
1071 * Fast approximate exp10
1072 * valid for inputs -37.f to 37.f
1073 * Max 8192 ulps of error
1074 *
1075 * Supports 1,2,3,4 components
1076 */
Stephen Hines52132472013-04-30 15:45:22 -07001077_RS_RUNTIME float __attribute__((const, overloadable)) native_exp10(float v);
Jason Sams59531f72013-01-18 14:10:32 -08001078FN_FUNC_FN(native_exp10)
1079
1080
Stephen Hines52132472013-04-30 15:45:22 -07001081_RS_RUNTIME float __attribute__((const, overloadable)) native_log2(float v);
Jason Samsaa493952013-01-25 13:21:17 -08001082FN_FUNC_FN(native_log2)
1083
Stephen Hines52132472013-04-30 15:45:22 -07001084_RS_RUNTIME float __attribute__((const, overloadable)) native_log(float v);
Jason Samsaa493952013-01-25 13:21:17 -08001085FN_FUNC_FN(native_log)
1086
Stephen Hines52132472013-04-30 15:45:22 -07001087_RS_RUNTIME float __attribute__((const, overloadable)) native_log10(float v);
Jason Samsaa493952013-01-25 13:21:17 -08001088FN_FUNC_FN(native_log10)
1089
1090
Stephen Hines52132472013-04-30 15:45:22 -07001091_RS_RUNTIME float __attribute__((const, overloadable)) native_powr(float v, float y);
Jason Samsaa493952013-01-25 13:21:17 -08001092FN_FUNC_FN_FN(native_powr)
1093
1094
Jason Sams59531f72013-01-18 14:10:32 -08001095#endif // (defined(RS_VERSION) && (RS_VERSION >= 18))
1096
1097
Stephen Hines47416532011-01-11 14:38:18 -08001098#undef CVT_FUNC
1099#undef CVT_FUNC_2
Stephen Hines3e6482f2011-01-19 12:51:33 -08001100#undef FN_FUNC_FN
Rajeev Sharma65723fe2012-08-03 15:11:04 -07001101#undef F_FUNC_FN
Stephen Hines3e6482f2011-01-19 12:51:33 -08001102#undef IN_FUNC_FN
1103#undef FN_FUNC_FN_FN
Rajeev Sharma65723fe2012-08-03 15:11:04 -07001104#undef F_FUNC_FN_FN
Stephen Hines3e6482f2011-01-19 12:51:33 -08001105#undef FN_FUNC_FN_F
1106#undef FN_FUNC_FN_IN
1107#undef FN_FUNC_FN_I
1108#undef FN_FUNC_FN_PFN
1109#undef FN_FUNC_FN_PIN
1110#undef FN_FUNC_FN_FN_FN
Rajeev Sharma65723fe2012-08-03 15:11:04 -07001111#undef FN_FUNC_FN_FN_F
1112#undef FN_FUNC_FN_F_F
Stephen Hines3e6482f2011-01-19 12:51:33 -08001113#undef FN_FUNC_FN_FN_PIN
1114#undef XN_FUNC_YN
1115#undef UIN_FUNC_IN
1116#undef IN_FUNC_IN
1117#undef XN_FUNC_XN_XN_BODY
1118#undef IN_FUNC_IN_IN_BODY
Jason Sams1b937f52010-06-09 14:26:16 -07001119
1120#endif