blob: 5975cccc353728ab2381e6cc0ba5d28a893b1a40 [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
Stephen Hines47b15302011-01-19 18:06:34 -0800100#define IN_FUNC_FN(fnc) \
Stephen Hinescb058022012-05-29 17:10:05 -0700101_RS_RUNTIME int2 __attribute__((overloadable)) fnc(float2 v); \
102_RS_RUNTIME int3 __attribute__((overloadable)) fnc(float3 v); \
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800103_RS_RUNTIME int4 __attribute__((overloadable)) fnc(float4 v);
Stephen Hines47416532011-01-11 14:38:18 -0800104
Stephen Hines47b15302011-01-19 18:06:34 -0800105#define FN_FUNC_FN_FN(fnc) \
Stephen Hinescb058022012-05-29 17:10:05 -0700106_RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, float2 v2); \
107_RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, float3 v2); \
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800108_RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, float4 v2);
Jason Sams1b937f52010-06-09 14:26:16 -0700109
Stephen Hines47b15302011-01-19 18:06:34 -0800110#define FN_FUNC_FN_F(fnc) \
Stephen Hinescb058022012-05-29 17:10:05 -0700111_RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, float v2); \
112_RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, float v2); \
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800113_RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, float v2);
Jason Sams1b937f52010-06-09 14:26:16 -0700114
Stephen Hines47b15302011-01-19 18:06:34 -0800115#define FN_FUNC_FN_IN(fnc) \
Stephen Hinescb058022012-05-29 17:10:05 -0700116_RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, int2 v2); \
117_RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, int3 v2); \
118_RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, int4 v2); \
Stephen Hines3e6482f2011-01-19 12:51:33 -0800119
Stephen Hines47b15302011-01-19 18:06:34 -0800120#define FN_FUNC_FN_I(fnc) \
Stephen Hinescb058022012-05-29 17:10:05 -0700121_RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, int v2); \
122_RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, int v2); \
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800123_RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, int v2);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800124
Stephen Hinescb058022012-05-29 17:10:05 -0700125#define FN_FUNC_FN_PFN(fnc) \
126_RS_RUNTIME float2 __attribute__((overloadable)) \
127 fnc(float2 v1, float2 *v2); \
128_RS_RUNTIME float3 __attribute__((overloadable)) \
129 fnc(float3 v1, float3 *v2); \
130_RS_RUNTIME float4 __attribute__((overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800131 fnc(float4 v1, float4 *v2);
Jason Sams1b937f52010-06-09 14:26:16 -0700132
Stephen Hines47b15302011-01-19 18:06:34 -0800133#define FN_FUNC_FN_PIN(fnc) \
Stephen Hinescb058022012-05-29 17:10:05 -0700134_RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, int2 *v2); \
135_RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, int3 *v2); \
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800136_RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, int4 *v2);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800137
Stephen Hinescb058022012-05-29 17:10:05 -0700138#define FN_FUNC_FN_FN_FN(fnc) \
139_RS_RUNTIME float2 __attribute__((overloadable)) \
140 fnc(float2 v1, float2 v2, float2 v3); \
141_RS_RUNTIME float3 __attribute__((overloadable)) \
142 fnc(float3 v1, float3 v2, float3 v3); \
143_RS_RUNTIME float4 __attribute__((overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800144 fnc(float4 v1, float4 v2, float4 v3);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800145
Stephen Hinescb058022012-05-29 17:10:05 -0700146#define FN_FUNC_FN_FN_PIN(fnc) \
147_RS_RUNTIME float2 __attribute__((overloadable)) \
148 fnc(float2 v1, float2 v2, int2 *v3); \
149_RS_RUNTIME float3 __attribute__((overloadable)) \
150 fnc(float3 v1, float3 v2, int3 *v3); \
151_RS_RUNTIME float4 __attribute__((overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800152 fnc(float4 v1, float4 v2, int4 *v3);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800153
154
Jason Samsef823642011-08-31 14:52:08 -0700155/**
156 * Return the inverse cosine.
157 *
158 * Supports float, float2, float3, float4
159 */
Jason Sams22fa3712010-05-19 17:22:57 -0700160extern float __attribute__((overloadable)) acos(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800161FN_FUNC_FN(acos)
Jason Sams22fa3712010-05-19 17:22:57 -0700162
Jason Samsef823642011-08-31 14:52:08 -0700163/**
164 * Return the inverse hyperbolic cosine.
165 *
166 * Supports float, float2, float3, float4
167 */
Jason Sams22fa3712010-05-19 17:22:57 -0700168extern float __attribute__((overloadable)) acosh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800169FN_FUNC_FN(acosh)
Jason Sams22fa3712010-05-19 17:22:57 -0700170
Jason Samsef823642011-08-31 14:52:08 -0700171/**
172 * Return the inverse cosine divided by PI.
173 *
174 * Supports float, float2, float3, float4
175 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800176_RS_RUNTIME float __attribute__((overloadable)) acospi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800177FN_FUNC_FN(acospi)
Jason Sams22fa3712010-05-19 17:22:57 -0700178
Jason Samsef823642011-08-31 14:52:08 -0700179/**
180 * Return the inverse sine.
181 *
182 * Supports float, float2, float3, float4
183 */
Jason Sams22fa3712010-05-19 17:22:57 -0700184extern float __attribute__((overloadable)) asin(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800185FN_FUNC_FN(asin)
Jason Sams22fa3712010-05-19 17:22:57 -0700186
Jason Samsef823642011-08-31 14:52:08 -0700187/**
188 * Return the inverse hyperbolic sine.
189 *
190 * Supports float, float2, float3, float4
191 */
Jason Sams22fa3712010-05-19 17:22:57 -0700192extern float __attribute__((overloadable)) asinh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800193FN_FUNC_FN(asinh)
Jason Sams22fa3712010-05-19 17:22:57 -0700194
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800195
Jason Samsef823642011-08-31 14:52:08 -0700196/**
197 * Return the inverse sine divided by PI.
198 *
199 * Supports float, float2, float3, float4
200 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800201_RS_RUNTIME float __attribute__((overloadable)) asinpi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800202FN_FUNC_FN(asinpi)
Jason Sams22fa3712010-05-19 17:22:57 -0700203
Jason Samsef823642011-08-31 14:52:08 -0700204/**
205 * Return the inverse tangent.
206 *
207 * Supports float, float2, float3, float4
208 */
Jason Sams22fa3712010-05-19 17:22:57 -0700209extern float __attribute__((overloadable)) atan(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800210FN_FUNC_FN(atan)
Jason Sams22fa3712010-05-19 17:22:57 -0700211
Jason Samsef823642011-08-31 14:52:08 -0700212/**
213 * Return the inverse tangent of y / x.
214 *
215 * Supports float, float2, float3, float4. Both arguments must be of the same
216 * type.
217 *
218 * @param y
219 * @param x
220 */
221extern float __attribute__((overloadable)) atan2(float y, float x);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800222FN_FUNC_FN_FN(atan2)
Jason Sams22fa3712010-05-19 17:22:57 -0700223
Jason Samsef823642011-08-31 14:52:08 -0700224/**
225 * Return the inverse hyperbolic tangent.
226 *
227 * Supports float, float2, float3, float4
228 */
Jason Sams22fa3712010-05-19 17:22:57 -0700229extern float __attribute__((overloadable)) atanh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800230FN_FUNC_FN(atanh)
Jason Sams22fa3712010-05-19 17:22:57 -0700231
Jason Samsef823642011-08-31 14:52:08 -0700232/**
233 * Return the inverse tangent divided by PI.
234 *
235 * Supports float, float2, float3, float4
236 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800237_RS_RUNTIME float __attribute__((overloadable)) atanpi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800238FN_FUNC_FN(atanpi)
Jason Sams22fa3712010-05-19 17:22:57 -0700239
Jason Samsef823642011-08-31 14:52:08 -0700240/**
241 * Return the inverse tangent of y / x, divided by PI.
242 *
243 * Supports float, float2, float3, float4. Both arguments must be of the same
244 * type.
245 *
246 * @param y
247 * @param x
248 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800249_RS_RUNTIME float __attribute__((overloadable)) atan2pi(float y, float x);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800250FN_FUNC_FN_FN(atan2pi)
Jason Sams22fa3712010-05-19 17:22:57 -0700251
Jason Samsef823642011-08-31 14:52:08 -0700252
253/**
254 * Return the cube root.
255 *
256 * Supports float, float2, float3, float4.
257 */
Jason Sams22fa3712010-05-19 17:22:57 -0700258extern float __attribute__((overloadable)) cbrt(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800259FN_FUNC_FN(cbrt)
Jason Sams22fa3712010-05-19 17:22:57 -0700260
Jason Samsef823642011-08-31 14:52:08 -0700261/**
262 * Return the smallest integer not less than a value.
263 *
264 * Supports float, float2, float3, float4.
265 */
Jason Sams22fa3712010-05-19 17:22:57 -0700266extern float __attribute__((overloadable)) ceil(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800267FN_FUNC_FN(ceil)
Jason Sams22fa3712010-05-19 17:22:57 -0700268
Jason Samsef823642011-08-31 14:52:08 -0700269/**
270 * Copy the sign bit from y to x.
271 *
272 * Supports float, float2, float3, float4. Both arguments must be of the same
273 * type.
274 *
275 * @param x
276 * @param y
277 */
278extern float __attribute__((overloadable)) copysign(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800279FN_FUNC_FN_FN(copysign)
Jason Sams22fa3712010-05-19 17:22:57 -0700280
Jason Samsef823642011-08-31 14:52:08 -0700281/**
282 * Return the cosine.
283 *
284 * Supports float, float2, float3, float4.
285 */
Jason Sams22fa3712010-05-19 17:22:57 -0700286extern float __attribute__((overloadable)) cos(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800287FN_FUNC_FN(cos)
Jason Sams22fa3712010-05-19 17:22:57 -0700288
Jason Samsef823642011-08-31 14:52:08 -0700289/**
290 * Return the hypebolic cosine.
291 *
292 * Supports float, float2, float3, float4.
293 */
Jason Sams22fa3712010-05-19 17:22:57 -0700294extern float __attribute__((overloadable)) cosh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800295FN_FUNC_FN(cosh)
Jason Sams22fa3712010-05-19 17:22:57 -0700296
Jason Samsef823642011-08-31 14:52:08 -0700297/**
298 * Return the cosine of the value * PI.
299 *
300 * Supports float, float2, float3, float4.
301 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800302_RS_RUNTIME float __attribute__((overloadable)) cospi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800303FN_FUNC_FN(cospi)
Jason Sams22fa3712010-05-19 17:22:57 -0700304
Jason Samsef823642011-08-31 14:52:08 -0700305/**
306 * Return the complementary error function.
307 *
308 * Supports float, float2, float3, float4.
309 */
Jason Sams22fa3712010-05-19 17:22:57 -0700310extern float __attribute__((overloadable)) erfc(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800311FN_FUNC_FN(erfc)
Jason Sams22fa3712010-05-19 17:22:57 -0700312
Jason Samsef823642011-08-31 14:52:08 -0700313/**
314 * Return the error function.
315 *
316 * Supports float, float2, float3, float4.
317 */
Jason Sams22fa3712010-05-19 17:22:57 -0700318extern float __attribute__((overloadable)) erf(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800319FN_FUNC_FN(erf)
Jason Sams22fa3712010-05-19 17:22:57 -0700320
Jason Samsef823642011-08-31 14:52:08 -0700321/**
322 * Return e ^ value.
323 *
324 * Supports float, float2, float3, float4.
325 */
Jason Sams22fa3712010-05-19 17:22:57 -0700326extern float __attribute__((overloadable)) exp(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800327FN_FUNC_FN(exp)
Jason Sams22fa3712010-05-19 17:22:57 -0700328
Jason Samsef823642011-08-31 14:52:08 -0700329/**
330 * Return 2 ^ value.
331 *
332 * Supports float, float2, float3, float4.
333 */
Jason Sams22fa3712010-05-19 17:22:57 -0700334extern float __attribute__((overloadable)) exp2(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800335FN_FUNC_FN(exp2)
Jason Sams22fa3712010-05-19 17:22:57 -0700336
Jason Samsef823642011-08-31 14:52:08 -0700337/**
338 * Return x ^ y.
339 *
340 * Supports float, float2, float3, float4. Both arguments must be of the same
341 * type.
342 */
343extern float __attribute__((overloadable)) pow(float x, float y);
344FN_FUNC_FN_FN(pow)
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800345
Jason Samsef823642011-08-31 14:52:08 -0700346/**
347 * Return 10 ^ value.
348 *
349 * Supports float, float2, float3, float4.
350 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800351_RS_RUNTIME float __attribute__((overloadable)) exp10(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800352FN_FUNC_FN(exp10)
Jason Sams22fa3712010-05-19 17:22:57 -0700353
Jason Samsef823642011-08-31 14:52:08 -0700354/**
355 * Return (e ^ value) - 1.
356 *
357 * Supports float, float2, float3, float4.
358 */
Jason Sams22fa3712010-05-19 17:22:57 -0700359extern float __attribute__((overloadable)) expm1(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800360FN_FUNC_FN(expm1)
Jason Sams22fa3712010-05-19 17:22:57 -0700361
Jason Samsef823642011-08-31 14:52:08 -0700362/**
363 * Return the absolute value of a value.
364 *
365 * Supports float, float2, float3, float4.
366 */
Jason Sams22fa3712010-05-19 17:22:57 -0700367extern float __attribute__((overloadable)) fabs(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800368FN_FUNC_FN(fabs)
Jason Sams22fa3712010-05-19 17:22:57 -0700369
Jason Samsef823642011-08-31 14:52:08 -0700370/**
371 * Return the positive difference between two values.
372 *
373 * Supports float, float2, float3, float4. Both arguments must be of the same
374 * type.
375 */
Jason Sams22fa3712010-05-19 17:22:57 -0700376extern float __attribute__((overloadable)) fdim(float, float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800377FN_FUNC_FN_FN(fdim)
Jason Sams22fa3712010-05-19 17:22:57 -0700378
Jason Samsef823642011-08-31 14:52:08 -0700379/**
380 * Return the smallest integer not greater than a value.
381 *
382 * Supports float, float2, float3, float4.
383 */
Jason Sams22fa3712010-05-19 17:22:57 -0700384extern float __attribute__((overloadable)) floor(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800385FN_FUNC_FN(floor)
Jason Sams22fa3712010-05-19 17:22:57 -0700386
Jason Samsef823642011-08-31 14:52:08 -0700387/**
388 * Return a*b + c.
389 *
390 * Supports float, float2, float3, float4.
391 */
392extern float __attribute__((overloadable)) fma(float a, float b, float c);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800393FN_FUNC_FN_FN_FN(fma)
Jason Sams22fa3712010-05-19 17:22:57 -0700394
Jason Samsef823642011-08-31 14:52:08 -0700395/**
396 * Return (x < y ? y : x)
397 *
398 * Supports float, float2, float3, float4.
399 * @param x: may be float, float2, float3, float4
400 * @param y: may be float or vector. If vector must match type of x.
401 */
402extern float __attribute__((overloadable)) fmax(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800403FN_FUNC_FN_FN(fmax);
404FN_FUNC_FN_F(fmax);
Jason Sams22fa3712010-05-19 17:22:57 -0700405
Jason Samsef823642011-08-31 14:52:08 -0700406/**
407 * Return (x > y ? y : x)
408 *
409 * @param x: may be float, float2, float3, float4
410 * @param y: may be float or vector. If vector must match type of x.
411 */
412extern float __attribute__((overloadable)) fmin(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800413FN_FUNC_FN_FN(fmin);
414FN_FUNC_FN_F(fmin);
Jason Sams22fa3712010-05-19 17:22:57 -0700415
Jason Samsef823642011-08-31 14:52:08 -0700416/**
417 * Return the remainder from x / y
418 *
419 * Supports float, float2, float3, float4.
420 */
421extern float __attribute__((overloadable)) fmod(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800422FN_FUNC_FN_FN(fmod)
Jason Sams22fa3712010-05-19 17:22:57 -0700423
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800424
Jason Samsef823642011-08-31 14:52:08 -0700425/**
426 * Return fractional part of v
427 *
428 * @param iptr iptr[0] will be set to the floor of the input value.
429 * Supports float, float2, float3, float4.
430 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800431_RS_RUNTIME float __attribute__((overloadable)) fract(float v, float *iptr);
Stephen Hines47b15302011-01-19 18:06:34 -0800432FN_FUNC_FN_PFN(fract)
Jason Sams22fa3712010-05-19 17:22:57 -0700433
Jason Samsef823642011-08-31 14:52:08 -0700434/**
435 * Return the mantissa and place the exponent into iptr[0]
436 *
437 * @param v Supports float, float2, float3, float4.
438 * @param iptr Must have the same vector size as v.
439 */
440extern float __attribute__((overloadable)) frexp(float v, int *iptr);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800441FN_FUNC_FN_PIN(frexp)
Jason Sams22fa3712010-05-19 17:22:57 -0700442
Jason Samsef823642011-08-31 14:52:08 -0700443/**
444 * Return sqrt(x*x + y*y)
445 *
446 * Supports float, float2, float3, float4.
447 */
448extern float __attribute__((overloadable)) hypot(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800449FN_FUNC_FN_FN(hypot)
Jason Sams22fa3712010-05-19 17:22:57 -0700450
Jason Samsef823642011-08-31 14:52:08 -0700451/**
452 * Return the integer exponent of a value
453 *
454 * Supports 1,2,3,4 components
455 */
Jason Sams22fa3712010-05-19 17:22:57 -0700456extern int __attribute__((overloadable)) ilogb(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800457IN_FUNC_FN(ilogb)
Jason Sams22fa3712010-05-19 17:22:57 -0700458
Jason Samsef823642011-08-31 14:52:08 -0700459/**
460 * Return (x * 2^y)
461 *
462 * @param x Supports 1,2,3,4 components
463 * @param y Supports single component or matching vector.
464 */
465extern float __attribute__((overloadable)) ldexp(float x, int y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800466FN_FUNC_FN_IN(ldexp)
467FN_FUNC_FN_I(ldexp)
Jason Sams22fa3712010-05-19 17:22:57 -0700468
Jason Samsef823642011-08-31 14:52:08 -0700469/**
470 * Return the log gamma
471 *
472 * Supports 1,2,3,4 components
473 */
Jason Sams22fa3712010-05-19 17:22:57 -0700474extern float __attribute__((overloadable)) lgamma(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800475FN_FUNC_FN(lgamma)
Jason Samsef823642011-08-31 14:52:08 -0700476
477/**
478 * Return the log gamma and sign
479 *
480 * @param x Supports 1,2,3,4 components
481 * @param y Supports matching vector.
482 */
483extern float __attribute__((overloadable)) lgamma(float x, int* y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800484FN_FUNC_FN_PIN(lgamma)
Jason Sams22fa3712010-05-19 17:22:57 -0700485
Jason Samsef823642011-08-31 14:52:08 -0700486/**
487 * Return the natural logarithm
488 *
489 * Supports 1,2,3,4 components
490 */
Jason Sams22fa3712010-05-19 17:22:57 -0700491extern float __attribute__((overloadable)) log(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800492FN_FUNC_FN(log)
Jason Sams22fa3712010-05-19 17:22:57 -0700493
Jason Samsef823642011-08-31 14:52:08 -0700494/**
495 * Return the base 10 logarithm
496 *
497 * Supports 1,2,3,4 components
498 */
Jason Sams22fa3712010-05-19 17:22:57 -0700499extern float __attribute__((overloadable)) log10(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800500FN_FUNC_FN(log10)
Jason Sams1b937f52010-06-09 14:26:16 -0700501
Jason Samsef823642011-08-31 14:52:08 -0700502/**
503 * Return the base 2 logarithm
504 *
505 * Supports 1,2,3,4 components
506 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800507_RS_RUNTIME float __attribute__((overloadable)) log2(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800508FN_FUNC_FN(log2)
Jason Sams22fa3712010-05-19 17:22:57 -0700509
Jason Samsef823642011-08-31 14:52:08 -0700510/**
511 * Return the natural logarithm of (v + 1.0f)
512 *
513 * Supports 1,2,3,4 components
514 */
515extern float __attribute__((overloadable)) log1p(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800516FN_FUNC_FN(log1p)
Jason Sams22fa3712010-05-19 17:22:57 -0700517
Jason Samsef823642011-08-31 14:52:08 -0700518/**
519 * Compute the exponent of the value.
520 *
521 * Supports 1,2,3,4 components
522 */
Jason Sams22fa3712010-05-19 17:22:57 -0700523extern float __attribute__((overloadable)) logb(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800524FN_FUNC_FN(logb)
Jason Sams22fa3712010-05-19 17:22:57 -0700525
Jason Samsef823642011-08-31 14:52:08 -0700526/**
527 * Compute (a * b) + c
528 *
529 * Supports 1,2,3,4 components
530 */
531extern float __attribute__((overloadable)) mad(float a, float b, float c);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800532FN_FUNC_FN_FN_FN(mad)
Jason Sams22fa3712010-05-19 17:22:57 -0700533
Jason Samsef823642011-08-31 14:52:08 -0700534/**
Stephen Hinescb058022012-05-29 17:10:05 -0700535 * Return the integral and fractional components of a number.
Jason Samsef823642011-08-31 14:52:08 -0700536 * Supports 1,2,3,4 components
537 *
538 * @param x Source value
539 * @param iret iret[0] will be set to the integral portion of the number.
540 * @return The floating point portion of the value.
541 */
542extern float __attribute__((overloadable)) modf(float x, float *iret);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800543FN_FUNC_FN_PFN(modf);
Jason Sams22fa3712010-05-19 17:22:57 -0700544
Jason Samsf31fa922012-03-30 18:26:31 -0700545extern float __attribute__((overloadable)) nan(uint);
Jason Sams22fa3712010-05-19 17:22:57 -0700546
Jason Samsef823642011-08-31 14:52:08 -0700547/**
548 * Return the next floating point number from x towards y.
549 *
550 * Supports 1,2,3,4 components
551 */
552extern float __attribute__((overloadable)) nextafter(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800553FN_FUNC_FN_FN(nextafter)
Jason Sams22fa3712010-05-19 17:22:57 -0700554
Jason Samsef823642011-08-31 14:52:08 -0700555/**
556 * Return (v ^ p).
557 *
558 * Supports 1,2,3,4 components
559 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800560_RS_RUNTIME float __attribute__((overloadable)) pown(float v, int p);
Jason Samsef823642011-08-31 14:52:08 -0700561FN_FUNC_FN_IN(pown)
Jason Sams22fa3712010-05-19 17:22:57 -0700562
Jason Samsef823642011-08-31 14:52:08 -0700563/**
564 * Return (v ^ p).
565 * @param v must be greater than 0.
566 *
567 * Supports 1,2,3,4 components
568 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800569_RS_RUNTIME float __attribute__((overloadable)) powr(float v, float p);
Jason Samsef823642011-08-31 14:52:08 -0700570FN_FUNC_FN_FN(powr)
Jason Sams22fa3712010-05-19 17:22:57 -0700571
Jason Samsef823642011-08-31 14:52:08 -0700572/**
573 * Return round x/y to the nearest integer then compute the remander.
574 *
575 * Supports 1,2,3,4 components
576 */
577extern float __attribute__((overloadable)) remainder(float x, float y);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800578FN_FUNC_FN_FN(remainder)
Jason Sams22fa3712010-05-19 17:22:57 -0700579
Jason Samsef823642011-08-31 14:52:08 -0700580// document once we know the precision of bionic
Stephen Hines47416532011-01-11 14:38:18 -0800581extern float __attribute__((overloadable)) remquo(float, float, int *);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800582FN_FUNC_FN_FN_PIN(remquo)
Jason Sams22fa3712010-05-19 17:22:57 -0700583
Jason Samsef823642011-08-31 14:52:08 -0700584/**
585 * Round to the nearest integral value.
586 *
587 * Supports 1,2,3,4 components
588 */
Jason Sams22fa3712010-05-19 17:22:57 -0700589extern float __attribute__((overloadable)) rint(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800590FN_FUNC_FN(rint)
Jason Sams22fa3712010-05-19 17:22:57 -0700591
Jason Samsef823642011-08-31 14:52:08 -0700592/**
593 * Compute the Nth root of a value.
594 *
595 * Supports 1,2,3,4 components
596 */
597_RS_RUNTIME float __attribute__((overloadable)) rootn(float v, int n);
598FN_FUNC_FN_IN(rootn)
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800599
Jason Samsef823642011-08-31 14:52:08 -0700600/**
601 * Round to the nearest integral value. Half values are rounded away from zero.
602 *
603 * Supports 1,2,3,4 components
604 */
Jason Sams22fa3712010-05-19 17:22:57 -0700605extern float __attribute__((overloadable)) round(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800606FN_FUNC_FN(round)
Jason Sams22fa3712010-05-19 17:22:57 -0700607
Jason Samsef823642011-08-31 14:52:08 -0700608/**
609 * Return the square root of a value.
610 *
611 * Supports 1,2,3,4 components
612 */
Jason Sams22fa3712010-05-19 17:22:57 -0700613extern float __attribute__((overloadable)) sqrt(float);
Jason Samsef823642011-08-31 14:52:08 -0700614FN_FUNC_FN(sqrt)
615
616/**
617 * Return (1 / sqrt(value)).
618 *
619 * @param v The incoming value in radians
620 * Supports 1,2,3,4 components
621 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800622_RS_RUNTIME float __attribute__((overloadable)) rsqrt(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800623FN_FUNC_FN(rsqrt)
Jason Sams1b937f52010-06-09 14:26:16 -0700624
Jason Samsef823642011-08-31 14:52:08 -0700625/**
626 * Return the sine of a value specified in radians.
627 *
628 * @param v The incoming value in radians
629 * Supports 1,2,3,4 components
630 */
631extern float __attribute__((overloadable)) sin(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800632FN_FUNC_FN(sin)
Jason Sams1b937f52010-06-09 14:26:16 -0700633
Jason Samsef823642011-08-31 14:52:08 -0700634/**
635 * Return the sine and cosine of a value.
636 *
637 * @return sine
638 * @param v The incoming value in radians
639 * @param *cosptr cosptr[0] will be set to the cosine value.
640 *
641 * Supports 1,2,3,4 components
642 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800643_RS_RUNTIME float __attribute__((overloadable)) sincos(float v, float *cosptr);
Jason Samsef823642011-08-31 14:52:08 -0700644FN_FUNC_FN_PFN(sincos);
Jason Sams1b937f52010-06-09 14:26:16 -0700645
Jason Samsef823642011-08-31 14:52:08 -0700646/**
647 * Return the hyperbolic sine of a value specified in radians.
648 *
649 * Supports 1,2,3,4 components
650 */
Jason Sams1b937f52010-06-09 14:26:16 -0700651extern float __attribute__((overloadable)) sinh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800652FN_FUNC_FN(sinh)
Jason Sams1b937f52010-06-09 14:26:16 -0700653
Jason Samsef823642011-08-31 14:52:08 -0700654/**
655 * Return the sin(v * PI).
656 *
657 * Supports 1,2,3,4 components
658 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800659_RS_RUNTIME float __attribute__((overloadable)) sinpi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800660FN_FUNC_FN(sinpi)
Jason Sams1b937f52010-06-09 14:26:16 -0700661
Jason Samsef823642011-08-31 14:52:08 -0700662/**
663 * Return the tangent of a value.
664 *
665 * Supports 1,2,3,4 components
666 * @param v The incoming value in radians
667 */
668extern float __attribute__((overloadable)) tan(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800669FN_FUNC_FN(tan)
Jason Sams22fa3712010-05-19 17:22:57 -0700670
Jason Samsef823642011-08-31 14:52:08 -0700671/**
672 * Return the hyperbolic tangent of a value.
673 *
674 * Supports 1,2,3,4 components
675 * @param v The incoming value in radians
676 */
Jason Sams22fa3712010-05-19 17:22:57 -0700677extern float __attribute__((overloadable)) tanh(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800678FN_FUNC_FN(tanh)
Jason Sams22fa3712010-05-19 17:22:57 -0700679
Jason Samsef823642011-08-31 14:52:08 -0700680/**
681 * Return tan(v * PI)
682 *
683 * Supports 1,2,3,4 components
684 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800685_RS_RUNTIME float __attribute__((overloadable)) tanpi(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800686FN_FUNC_FN(tanpi)
Jason Sams22fa3712010-05-19 17:22:57 -0700687
Jason Samsef823642011-08-31 14:52:08 -0700688/**
689 * Compute the gamma function of a value.
690 *
691 * Supports 1,2,3,4 components
692 */
Jason Sams22fa3712010-05-19 17:22:57 -0700693extern float __attribute__((overloadable)) tgamma(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800694FN_FUNC_FN(tgamma)
Jason Sams22fa3712010-05-19 17:22:57 -0700695
Jason Samsef823642011-08-31 14:52:08 -0700696/**
697 * Round to integral using truncation.
698 *
699 * Supports 1,2,3,4 components
700 */
Jason Sams22fa3712010-05-19 17:22:57 -0700701extern float __attribute__((overloadable)) trunc(float);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800702FN_FUNC_FN(trunc)
Jason Sams22fa3712010-05-19 17:22:57 -0700703
Jason Sams22fa3712010-05-19 17:22:57 -0700704
Stephen Hines47b15302011-01-19 18:06:34 -0800705#define XN_FUNC_YN(typeout, fnc, typein) \
706extern typeout __attribute__((overloadable)) fnc(typein); \
Stephen Hinescb058022012-05-29 17:10:05 -0700707_RS_RUNTIME typeout##2 __attribute__((overloadable)) fnc(typein##2 v); \
708_RS_RUNTIME typeout##3 __attribute__((overloadable)) fnc(typein##3 v); \
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800709_RS_RUNTIME typeout##4 __attribute__((overloadable)) fnc(typein##4 v);
Jason Sams22fa3712010-05-19 17:22:57 -0700710
Stephen Hines47b15302011-01-19 18:06:34 -0800711#define UIN_FUNC_IN(fnc) \
Stephen Hines3e6482f2011-01-19 12:51:33 -0800712XN_FUNC_YN(uchar, fnc, char) \
713XN_FUNC_YN(ushort, fnc, short) \
714XN_FUNC_YN(uint, fnc, int)
Jason Sams22fa3712010-05-19 17:22:57 -0700715
Stephen Hines47b15302011-01-19 18:06:34 -0800716#define IN_FUNC_IN(fnc) \
Stephen Hines3e6482f2011-01-19 12:51:33 -0800717XN_FUNC_YN(uchar, fnc, uchar) \
718XN_FUNC_YN(char, fnc, char) \
719XN_FUNC_YN(ushort, fnc, ushort) \
720XN_FUNC_YN(short, fnc, short) \
721XN_FUNC_YN(uint, fnc, uint) \
722XN_FUNC_YN(int, fnc, int)
Jason Sams22fa3712010-05-19 17:22:57 -0700723
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800724
Stephen Hines47b15302011-01-19 18:06:34 -0800725#define XN_FUNC_XN_XN_BODY(type, fnc, body) \
Stephen Hinescb058022012-05-29 17:10:05 -0700726_RS_RUNTIME type __attribute__((overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800727 fnc(type v1, type v2); \
Stephen Hinescb058022012-05-29 17:10:05 -0700728_RS_RUNTIME type##2 __attribute__((overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800729 fnc(type##2 v1, type##2 v2); \
Stephen Hinescb058022012-05-29 17:10:05 -0700730_RS_RUNTIME type##3 __attribute__((overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800731 fnc(type##3 v1, type##3 v2); \
Stephen Hinescb058022012-05-29 17:10:05 -0700732_RS_RUNTIME type##4 __attribute__((overloadable)) \
Shih-wei Liaoedf22402011-01-26 04:03:30 -0800733 fnc(type##4 v1, type##4 v2);
Jason Sams22fa3712010-05-19 17:22:57 -0700734
Stephen Hinescb058022012-05-29 17:10:05 -0700735#define IN_FUNC_IN_IN_BODY(fnc, body) \
736XN_FUNC_XN_XN_BODY(uchar, fnc, body) \
737XN_FUNC_XN_XN_BODY(char, fnc, body) \
738XN_FUNC_XN_XN_BODY(ushort, fnc, body) \
739XN_FUNC_XN_XN_BODY(short, fnc, body) \
740XN_FUNC_XN_XN_BODY(uint, fnc, body) \
741XN_FUNC_XN_XN_BODY(int, fnc, body) \
Stephen Hines3e6482f2011-01-19 12:51:33 -0800742XN_FUNC_XN_XN_BODY(float, fnc, body)
Stephen Hinesb902e4c2011-01-14 18:49:01 -0800743
Stephen Hinescb058022012-05-29 17:10:05 -0700744/**
745 * Return the absolute value of a value.
746 *
747 * Supports 1,2,3,4 components of char, short, int.
748 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800749UIN_FUNC_IN(abs)
Stephen Hinescb058022012-05-29 17:10:05 -0700750
751/**
752 * Return the number of leading 0-bits in a value.
753 *
754 * Supports 1,2,3,4 components of uchar, char, ushort, short, uint, int.
755 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800756IN_FUNC_IN(clz)
Stephen Hinesb902e4c2011-01-14 18:49:01 -0800757
Jason Samsdc2c3e62011-08-31 16:44:18 -0700758/**
759 * Return the minimum of two values.
760 *
761 * Supports 1,2,3,4 components of uchar, char, ushort, short, uint, int, float.
762 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800763IN_FUNC_IN_IN_BODY(min, (v1 < v2 ? v1 : v2))
764FN_FUNC_FN_F(min)
Stephen Hinesb902e4c2011-01-14 18:49:01 -0800765
Jason Samsdc2c3e62011-08-31 16:44:18 -0700766/**
767 * Return the maximum of two values.
768 *
769 * Supports 1,2,3,4 components of uchar, char, ushort, short, uint, int, float.
770 */
Stephen Hines3e6482f2011-01-19 12:51:33 -0800771IN_FUNC_IN_IN_BODY(max, (v1 > v2 ? v1 : v2))
772FN_FUNC_FN_F(max)
Jason Sams22fa3712010-05-19 17:22:57 -0700773
Jason Samsdc2c3e62011-08-31 16:44:18 -0700774/**
775 * Clamp a value to a specified high and low bound.
776 *
777 * @param amount value to be clamped. Supports 1,2,3,4 components
778 * @param low Lower bound, must be scalar or matching vector.
779 * @param high High bound, must match type of low
780 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800781_RS_RUNTIME float __attribute__((overloadable)) clamp(float amount, float low, float high);
782_RS_RUNTIME float2 __attribute__((overloadable)) clamp(float2 amount, float2 low, float2 high);
783_RS_RUNTIME float3 __attribute__((overloadable)) clamp(float3 amount, float3 low, float3 high);
784_RS_RUNTIME float4 __attribute__((overloadable)) clamp(float4 amount, float4 low, float4 high);
785_RS_RUNTIME float2 __attribute__((overloadable)) clamp(float2 amount, float low, float high);
786_RS_RUNTIME float3 __attribute__((overloadable)) clamp(float3 amount, float low, float high);
787_RS_RUNTIME float4 __attribute__((overloadable)) clamp(float4 amount, float low, float high);
Jason Sams22fa3712010-05-19 17:22:57 -0700788
Jason Samsdc2c3e62011-08-31 16:44:18 -0700789/**
790 * Convert from radians to degrees.
791 *
792 * Supports 1,2,3,4 components
793 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800794_RS_RUNTIME float __attribute__((overloadable)) degrees(float radians);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800795FN_FUNC_FN(degrees)
Jason Sams22fa3712010-05-19 17:22:57 -0700796
Jason Samsdc2c3e62011-08-31 16:44:18 -0700797/**
798 * return start + ((stop - start) * amount);
799 *
800 * Supports 1,2,3,4 components
801 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800802_RS_RUNTIME float __attribute__((overloadable)) mix(float start, float stop, float amount);
803_RS_RUNTIME float2 __attribute__((overloadable)) mix(float2 start, float2 stop, float2 amount);
804_RS_RUNTIME float3 __attribute__((overloadable)) mix(float3 start, float3 stop, float3 amount);
805_RS_RUNTIME float4 __attribute__((overloadable)) mix(float4 start, float4 stop, float4 amount);
806_RS_RUNTIME float2 __attribute__((overloadable)) mix(float2 start, float2 stop, float amount);
807_RS_RUNTIME float3 __attribute__((overloadable)) mix(float3 start, float3 stop, float amount);
808_RS_RUNTIME float4 __attribute__((overloadable)) mix(float4 start, float4 stop, float amount);
Jason Sams22fa3712010-05-19 17:22:57 -0700809
Jason Samsdc2c3e62011-08-31 16:44:18 -0700810/**
811 * Convert from degrees to radians.
812 *
813 * Supports 1,2,3,4 components
814 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800815_RS_RUNTIME float __attribute__((overloadable)) radians(float degrees);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800816FN_FUNC_FN(radians)
Jason Sams22fa3712010-05-19 17:22:57 -0700817
Jason Samsdc2c3e62011-08-31 16:44:18 -0700818/**
819 * if (v < edge)
820 * return 0.f;
821 * else
822 * return 1.f;
823 *
824 * Supports 1,2,3,4 components
825 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800826_RS_RUNTIME float __attribute__((overloadable)) step(float edge, float v);
827_RS_RUNTIME float2 __attribute__((overloadable)) step(float2 edge, float2 v);
828_RS_RUNTIME float3 __attribute__((overloadable)) step(float3 edge, float3 v);
829_RS_RUNTIME float4 __attribute__((overloadable)) step(float4 edge, float4 v);
830_RS_RUNTIME float2 __attribute__((overloadable)) step(float2 edge, float v);
831_RS_RUNTIME float3 __attribute__((overloadable)) step(float3 edge, float v);
832_RS_RUNTIME float4 __attribute__((overloadable)) step(float4 edge, float v);
Jason Sams22fa3712010-05-19 17:22:57 -0700833
Jason Samsdc2c3e62011-08-31 16:44:18 -0700834// not implemented
Jason Sams22fa3712010-05-19 17:22:57 -0700835extern float __attribute__((overloadable)) smoothstep(float, float, float);
836extern float2 __attribute__((overloadable)) smoothstep(float2, float2, float2);
837extern float3 __attribute__((overloadable)) smoothstep(float3, float3, float3);
838extern float4 __attribute__((overloadable)) smoothstep(float4, float4, float4);
Jason Sams22fa3712010-05-19 17:22:57 -0700839extern float2 __attribute__((overloadable)) smoothstep(float, float, float2);
840extern float3 __attribute__((overloadable)) smoothstep(float, float, float3);
841extern float4 __attribute__((overloadable)) smoothstep(float, float, float4);
Jason Sams22fa3712010-05-19 17:22:57 -0700842
Jason Samsdc2c3e62011-08-31 16:44:18 -0700843/**
Stephen Hinescb058022012-05-29 17:10:05 -0700844 * Return the sign of a value.
845 *
Jason Samsdc2c3e62011-08-31 16:44:18 -0700846 * if (v < 0) return -1.f;
847 * else if (v > 0) return 1.f;
848 * else return 0.f;
849 *
850 * Supports 1,2,3,4 components
851 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800852_RS_RUNTIME float __attribute__((overloadable)) sign(float v);
Stephen Hines3e6482f2011-01-19 12:51:33 -0800853FN_FUNC_FN(sign)
Jason Sams22fa3712010-05-19 17:22:57 -0700854
Jason Samsdc2c3e62011-08-31 16:44:18 -0700855/**
856 * Compute the cross product of two vectors.
857 *
858 * Supports 3,4 components
859 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800860_RS_RUNTIME float3 __attribute__((overloadable)) cross(float3 lhs, float3 rhs);
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800861_RS_RUNTIME float4 __attribute__((overloadable)) cross(float4 lhs, float4 rhs);
Jason Sams22fa3712010-05-19 17:22:57 -0700862
Jason Samsdc2c3e62011-08-31 16:44:18 -0700863/**
864 * Compute the dot product of two vectors.
865 *
866 * Supports 1,2,3,4 components
867 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800868_RS_RUNTIME float __attribute__((overloadable)) dot(float lhs, float rhs);
869_RS_RUNTIME float __attribute__((overloadable)) dot(float2 lhs, float2 rhs);
870_RS_RUNTIME float __attribute__((overloadable)) dot(float3 lhs, float3 rhs);
871_RS_RUNTIME float __attribute__((overloadable)) dot(float4 lhs, float4 rhs);
Jason Sams22fa3712010-05-19 17:22:57 -0700872
Jason Samsdc2c3e62011-08-31 16:44:18 -0700873/**
874 * Compute the length of a vector.
875 *
876 * Supports 1,2,3,4 components
877 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800878_RS_RUNTIME float __attribute__((overloadable)) length(float v);
879_RS_RUNTIME float __attribute__((overloadable)) length(float2 v);
880_RS_RUNTIME float __attribute__((overloadable)) length(float3 v);
881_RS_RUNTIME float __attribute__((overloadable)) length(float4 v);
Jason Sams22fa3712010-05-19 17:22:57 -0700882
Jason Samsdc2c3e62011-08-31 16:44:18 -0700883/**
884 * Compute the distance between two points.
885 *
886 * Supports 1,2,3,4 components
887 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800888_RS_RUNTIME float __attribute__((overloadable)) distance(float lhs, float rhs);
889_RS_RUNTIME float __attribute__((overloadable)) distance(float2 lhs, float2 rhs);
890_RS_RUNTIME float __attribute__((overloadable)) distance(float3 lhs, float3 rhs);
891_RS_RUNTIME float __attribute__((overloadable)) distance(float4 lhs, float4 rhs);
Jason Sams22fa3712010-05-19 17:22:57 -0700892
Jason Samsdc2c3e62011-08-31 16:44:18 -0700893/**
894 * Normalize a vector.
895 *
896 * Supports 1,2,3,4 components
897 */
Shih-wei Liaoe31775b2011-01-26 17:04:31 -0800898_RS_RUNTIME float __attribute__((overloadable)) normalize(float v);
899_RS_RUNTIME float2 __attribute__((overloadable)) normalize(float2 v);
900_RS_RUNTIME float3 __attribute__((overloadable)) normalize(float3 v);
901_RS_RUNTIME float4 __attribute__((overloadable)) normalize(float4 v);
Jason Sams1b937f52010-06-09 14:26:16 -0700902
Stephen Hines47416532011-01-11 14:38:18 -0800903#undef CVT_FUNC
904#undef CVT_FUNC_2
Stephen Hines3e6482f2011-01-19 12:51:33 -0800905#undef FN_FUNC_FN
906#undef IN_FUNC_FN
907#undef FN_FUNC_FN_FN
908#undef FN_FUNC_FN_F
909#undef FN_FUNC_FN_IN
910#undef FN_FUNC_FN_I
911#undef FN_FUNC_FN_PFN
912#undef FN_FUNC_FN_PIN
913#undef FN_FUNC_FN_FN_FN
914#undef FN_FUNC_FN_FN_PIN
915#undef XN_FUNC_YN
916#undef UIN_FUNC_IN
917#undef IN_FUNC_IN
918#undef XN_FUNC_XN_XN_BODY
919#undef IN_FUNC_IN_IN_BODY
Jason Sams1b937f52010-06-09 14:26:16 -0700920
921#endif