Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 1 | /* |
Stephen Hines | cb05802 | 2012-05-29 17:10:05 -0700 | [diff] [blame] | 2 | * Copyright (C) 2011-2012 The Android Open Source Project |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 3 | * |
| 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 Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 18 | * \brief Basic math functions |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
Jason Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 23 | #ifndef __RS_CL_RSH__ |
| 24 | #define __RS_CL_RSH__ |
| 25 | |
Jason Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 26 | // Conversions |
Stephen Hines | 47b1530 | 2011-01-19 18:06:34 -0800 | [diff] [blame] | 27 | #define CVT_FUNC_2(typeout, typein) \ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 28 | _RS_RUNTIME typeout##2 __attribute__((const, overloadable)) \ |
Shih-wei Liao | edf2240 | 2011-01-26 04:03:30 -0800 | [diff] [blame] | 29 | convert_##typeout##2(typein##2 v); \ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 30 | _RS_RUNTIME typeout##3 __attribute__((const, overloadable)) \ |
Shih-wei Liao | edf2240 | 2011-01-26 04:03:30 -0800 | [diff] [blame] | 31 | convert_##typeout##3(typein##3 v); \ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 32 | _RS_RUNTIME typeout##4 __attribute__((const, overloadable)) \ |
Shih-wei Liao | edf2240 | 2011-01-26 04:03:30 -0800 | [diff] [blame] | 33 | convert_##typeout##4(typein##4 v); |
| 34 | |
Jason Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 35 | |
Stephen Hines | 47b1530 | 2011-01-19 18:06:34 -0800 | [diff] [blame] | 36 | #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 Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 43 | |
Stephen Hines | cb05802 | 2012-05-29 17:10:05 -0700 | [diff] [blame] | 44 | /** |
| 45 | * Convert to char. |
| 46 | * |
| 47 | * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float. |
| 48 | */ |
Jason Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 49 | CVT_FUNC(char) |
Stephen Hines | cb05802 | 2012-05-29 17:10:05 -0700 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * Convert to unsigned char. |
| 53 | * |
| 54 | * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float. |
| 55 | */ |
Jason Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 56 | CVT_FUNC(uchar) |
Stephen Hines | cb05802 | 2012-05-29 17:10:05 -0700 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * Convert to short. |
| 60 | * |
| 61 | * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float. |
| 62 | */ |
Jason Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 63 | CVT_FUNC(short) |
Stephen Hines | cb05802 | 2012-05-29 17:10:05 -0700 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * Convert to unsigned short. |
| 67 | * |
| 68 | * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float. |
| 69 | */ |
Jason Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 70 | CVT_FUNC(ushort) |
Stephen Hines | cb05802 | 2012-05-29 17:10:05 -0700 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * Convert to int. |
| 74 | * |
| 75 | * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float. |
| 76 | */ |
Jason Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 77 | CVT_FUNC(int) |
Stephen Hines | cb05802 | 2012-05-29 17:10:05 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * Convert to unsigned int. |
| 81 | * |
| 82 | * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float. |
| 83 | */ |
Jason Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 84 | CVT_FUNC(uint) |
Stephen Hines | cb05802 | 2012-05-29 17:10:05 -0700 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * Convert to float. |
| 88 | * |
| 89 | * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float. |
| 90 | */ |
Jason Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 91 | CVT_FUNC(float) |
| 92 | |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 93 | // Float ops, 6.11.2 |
| 94 | |
Stephen Hines | e781228 | 2013-06-19 00:07:04 -0700 | [diff] [blame^] | 95 | #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 Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 114 | #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 Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 118 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 119 | #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 Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 123 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 124 | #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 Hines | 4741653 | 2011-01-11 14:38:18 -0800 | [diff] [blame] | 128 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 129 | #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 Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 133 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 134 | #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 Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 138 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 139 | #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 Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 143 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 144 | #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 Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 148 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 149 | #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 Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 153 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 154 | #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 Liao | edf2240 | 2011-01-26 04:03:30 -0800 | [diff] [blame] | 160 | fnc(float4 v1, float4 *v2); |
Jason Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 161 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 162 | #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 Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 166 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 167 | #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 Liao | edf2240 | 2011-01-26 04:03:30 -0800 | [diff] [blame] | 173 | fnc(float4 v1, float4 v2, float4 v3); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 174 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 175 | #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 Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 181 | fnc(float4 v1, float4 v2, float v3); |
| 182 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 183 | #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 Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 189 | fnc(float4 v1, float v2, float v3); |
| 190 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 191 | #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 Liao | edf2240 | 2011-01-26 04:03:30 -0800 | [diff] [blame] | 197 | fnc(float4 v1, float4 v2, int4 *v3); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 198 | |
Stephen Hines | e781228 | 2013-06-19 00:07:04 -0700 | [diff] [blame^] | 199 | #endif // DOXYGEN |
| 200 | |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 201 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 202 | /** |
| 203 | * Return the inverse cosine. |
| 204 | * |
| 205 | * Supports float, float2, float3, float4 |
| 206 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 207 | extern float __attribute__((const, overloadable)) acos(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 208 | FN_FUNC_FN(acos) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 209 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 210 | /** |
| 211 | * Return the inverse hyperbolic cosine. |
| 212 | * |
| 213 | * Supports float, float2, float3, float4 |
| 214 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 215 | extern float __attribute__((const, overloadable)) acosh(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 216 | FN_FUNC_FN(acosh) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 217 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 218 | /** |
| 219 | * Return the inverse cosine divided by PI. |
| 220 | * |
| 221 | * Supports float, float2, float3, float4 |
| 222 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 223 | _RS_RUNTIME float __attribute__((const, overloadable)) acospi(float v); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 224 | FN_FUNC_FN(acospi) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 225 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 226 | /** |
| 227 | * Return the inverse sine. |
| 228 | * |
| 229 | * Supports float, float2, float3, float4 |
| 230 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 231 | extern float __attribute__((const, overloadable)) asin(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 232 | FN_FUNC_FN(asin) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 233 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 234 | /** |
| 235 | * Return the inverse hyperbolic sine. |
| 236 | * |
| 237 | * Supports float, float2, float3, float4 |
| 238 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 239 | extern float __attribute__((const, overloadable)) asinh(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 240 | FN_FUNC_FN(asinh) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 241 | |
Shih-wei Liao | edf2240 | 2011-01-26 04:03:30 -0800 | [diff] [blame] | 242 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 243 | /** |
| 244 | * Return the inverse sine divided by PI. |
| 245 | * |
| 246 | * Supports float, float2, float3, float4 |
| 247 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 248 | _RS_RUNTIME float __attribute__((const, overloadable)) asinpi(float v); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 249 | FN_FUNC_FN(asinpi) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 250 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 251 | /** |
| 252 | * Return the inverse tangent. |
| 253 | * |
| 254 | * Supports float, float2, float3, float4 |
| 255 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 256 | extern float __attribute__((const, overloadable)) atan(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 257 | FN_FUNC_FN(atan) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 258 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 259 | /** |
| 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 Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 268 | extern float __attribute__((const, overloadable)) atan2(float y, float x); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 269 | FN_FUNC_FN_FN(atan2) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 270 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 271 | /** |
| 272 | * Return the inverse hyperbolic tangent. |
| 273 | * |
| 274 | * Supports float, float2, float3, float4 |
| 275 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 276 | extern float __attribute__((const, overloadable)) atanh(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 277 | FN_FUNC_FN(atanh) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 278 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 279 | /** |
| 280 | * Return the inverse tangent divided by PI. |
| 281 | * |
| 282 | * Supports float, float2, float3, float4 |
| 283 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 284 | _RS_RUNTIME float __attribute__((const, overloadable)) atanpi(float v); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 285 | FN_FUNC_FN(atanpi) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 286 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 287 | /** |
| 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 Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 296 | _RS_RUNTIME float __attribute__((const, overloadable)) atan2pi(float y, float x); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 297 | FN_FUNC_FN_FN(atan2pi) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 298 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 299 | |
| 300 | /** |
| 301 | * Return the cube root. |
| 302 | * |
| 303 | * Supports float, float2, float3, float4. |
| 304 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 305 | extern float __attribute__((const, overloadable)) cbrt(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 306 | FN_FUNC_FN(cbrt) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 307 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 308 | /** |
| 309 | * Return the smallest integer not less than a value. |
| 310 | * |
| 311 | * Supports float, float2, float3, float4. |
| 312 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 313 | extern float __attribute__((const, overloadable)) ceil(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 314 | FN_FUNC_FN(ceil) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 315 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 316 | /** |
| 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 Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 325 | extern float __attribute__((const, overloadable)) copysign(float x, float y); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 326 | FN_FUNC_FN_FN(copysign) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 327 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 328 | /** |
| 329 | * Return the cosine. |
| 330 | * |
| 331 | * Supports float, float2, float3, float4. |
| 332 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 333 | extern float __attribute__((const, overloadable)) cos(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 334 | FN_FUNC_FN(cos) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 335 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 336 | /** |
| 337 | * Return the hypebolic cosine. |
| 338 | * |
| 339 | * Supports float, float2, float3, float4. |
| 340 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 341 | extern float __attribute__((const, overloadable)) cosh(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 342 | FN_FUNC_FN(cosh) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 343 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 344 | /** |
| 345 | * Return the cosine of the value * PI. |
| 346 | * |
| 347 | * Supports float, float2, float3, float4. |
| 348 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 349 | _RS_RUNTIME float __attribute__((const, overloadable)) cospi(float v); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 350 | FN_FUNC_FN(cospi) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 351 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 352 | /** |
| 353 | * Return the complementary error function. |
| 354 | * |
| 355 | * Supports float, float2, float3, float4. |
| 356 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 357 | extern float __attribute__((const, overloadable)) erfc(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 358 | FN_FUNC_FN(erfc) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 359 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 360 | /** |
| 361 | * Return the error function. |
| 362 | * |
| 363 | * Supports float, float2, float3, float4. |
| 364 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 365 | extern float __attribute__((const, overloadable)) erf(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 366 | FN_FUNC_FN(erf) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 367 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 368 | /** |
| 369 | * Return e ^ value. |
| 370 | * |
| 371 | * Supports float, float2, float3, float4. |
| 372 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 373 | extern float __attribute__((const, overloadable)) exp(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 374 | FN_FUNC_FN(exp) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 375 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 376 | /** |
| 377 | * Return 2 ^ value. |
| 378 | * |
| 379 | * Supports float, float2, float3, float4. |
| 380 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 381 | extern float __attribute__((const, overloadable)) exp2(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 382 | FN_FUNC_FN(exp2) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 383 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 384 | /** |
| 385 | * Return x ^ y. |
| 386 | * |
| 387 | * Supports float, float2, float3, float4. Both arguments must be of the same |
| 388 | * type. |
| 389 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 390 | extern float __attribute__((const, overloadable)) pow(float x, float y); |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 391 | FN_FUNC_FN_FN(pow) |
Shih-wei Liao | edf2240 | 2011-01-26 04:03:30 -0800 | [diff] [blame] | 392 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 393 | /** |
| 394 | * Return 10 ^ value. |
| 395 | * |
| 396 | * Supports float, float2, float3, float4. |
| 397 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 398 | _RS_RUNTIME float __attribute__((const, overloadable)) exp10(float v); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 399 | FN_FUNC_FN(exp10) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 400 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 401 | /** |
| 402 | * Return (e ^ value) - 1. |
| 403 | * |
| 404 | * Supports float, float2, float3, float4. |
| 405 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 406 | extern float __attribute__((const, overloadable)) expm1(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 407 | FN_FUNC_FN(expm1) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 408 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 409 | /** |
| 410 | * Return the absolute value of a value. |
| 411 | * |
| 412 | * Supports float, float2, float3, float4. |
| 413 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 414 | extern float __attribute__((const, overloadable)) fabs(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 415 | FN_FUNC_FN(fabs) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 416 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 417 | /** |
| 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 Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 423 | extern float __attribute__((const, overloadable)) fdim(float, float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 424 | FN_FUNC_FN_FN(fdim) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 425 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 426 | /** |
| 427 | * Return the smallest integer not greater than a value. |
| 428 | * |
| 429 | * Supports float, float2, float3, float4. |
| 430 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 431 | extern float __attribute__((const, overloadable)) floor(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 432 | FN_FUNC_FN(floor) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 433 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 434 | /** |
| 435 | * Return a*b + c. |
| 436 | * |
| 437 | * Supports float, float2, float3, float4. |
| 438 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 439 | extern float __attribute__((const, overloadable)) fma(float a, float b, float c); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 440 | FN_FUNC_FN_FN_FN(fma) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 441 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 442 | /** |
| 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 Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 449 | extern float __attribute__((const, overloadable)) fmax(float x, float y); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 450 | FN_FUNC_FN_FN(fmax); |
| 451 | FN_FUNC_FN_F(fmax); |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 452 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 453 | /** |
| 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 Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 459 | extern float __attribute__((const, overloadable)) fmin(float x, float y); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 460 | FN_FUNC_FN_FN(fmin); |
| 461 | FN_FUNC_FN_F(fmin); |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 462 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 463 | /** |
| 464 | * Return the remainder from x / y |
| 465 | * |
| 466 | * Supports float, float2, float3, float4. |
| 467 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 468 | extern float __attribute__((const, overloadable)) fmod(float x, float y); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 469 | FN_FUNC_FN_FN(fmod) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 470 | |
Tim Murray | 4d3201d | 2013-01-03 11:58:39 -0800 | [diff] [blame] | 471 | /** |
| 472 | * Return fractional part of v |
| 473 | * |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 474 | * @param iptr iptr[0] will be set to the floor of the input value. |
| 475 | * Supports float, float2, float3, float4. |
| 476 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 477 | _RS_RUNTIME float __attribute__((pure, overloadable)) fract(float v, float *iptr); |
Stephen Hines | 47b1530 | 2011-01-19 18:06:34 -0800 | [diff] [blame] | 478 | FN_FUNC_FN_PFN(fract) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 479 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 480 | /** |
Stephen Hines | 891bcfe | 2013-01-16 18:46:43 -0800 | [diff] [blame] | 481 | * Return fractional part of v |
| 482 | * |
| 483 | * Supports float, float2, float3, float4. |
| 484 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 485 | static inline float __attribute__((const, overloadable)) fract(float v) { |
Stephen Hines | 891bcfe | 2013-01-16 18:46:43 -0800 | [diff] [blame] | 486 | float unused; |
| 487 | return fract(v, &unused); |
| 488 | } |
| 489 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 490 | static inline float2 __attribute__((const, overloadable)) fract(float2 v) { |
Stephen Hines | 891bcfe | 2013-01-16 18:46:43 -0800 | [diff] [blame] | 491 | float2 unused; |
| 492 | return fract(v, &unused); |
| 493 | } |
| 494 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 495 | static inline float3 __attribute__((const, overloadable)) fract(float3 v) { |
Stephen Hines | 891bcfe | 2013-01-16 18:46:43 -0800 | [diff] [blame] | 496 | float3 unused; |
| 497 | return fract(v, &unused); |
| 498 | } |
| 499 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 500 | static inline float4 __attribute__((const, overloadable)) fract(float4 v) { |
Stephen Hines | 891bcfe | 2013-01-16 18:46:43 -0800 | [diff] [blame] | 501 | float4 unused; |
| 502 | return fract(v, &unused); |
| 503 | } |
| 504 | |
| 505 | /** |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 506 | * 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 Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 511 | extern float __attribute__((pure, overloadable)) frexp(float v, int *iptr); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 512 | FN_FUNC_FN_PIN(frexp) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 513 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 514 | /** |
| 515 | * Return sqrt(x*x + y*y) |
| 516 | * |
| 517 | * Supports float, float2, float3, float4. |
| 518 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 519 | extern float __attribute__((const, overloadable)) hypot(float x, float y); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 520 | FN_FUNC_FN_FN(hypot) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 521 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 522 | /** |
| 523 | * Return the integer exponent of a value |
| 524 | * |
| 525 | * Supports 1,2,3,4 components |
| 526 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 527 | extern int __attribute__((const, overloadable)) ilogb(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 528 | IN_FUNC_FN(ilogb) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 529 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 530 | /** |
| 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 Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 536 | extern float __attribute__((const, overloadable)) ldexp(float x, int y); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 537 | FN_FUNC_FN_IN(ldexp) |
| 538 | FN_FUNC_FN_I(ldexp) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 539 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 540 | /** |
| 541 | * Return the log gamma |
| 542 | * |
| 543 | * Supports 1,2,3,4 components |
| 544 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 545 | extern float __attribute__((const, overloadable)) lgamma(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 546 | FN_FUNC_FN(lgamma) |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 547 | |
| 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 Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 554 | extern float __attribute__((pure, overloadable)) lgamma(float x, int* y); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 555 | FN_FUNC_FN_PIN(lgamma) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 556 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 557 | /** |
| 558 | * Return the natural logarithm |
| 559 | * |
| 560 | * Supports 1,2,3,4 components |
| 561 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 562 | extern float __attribute__((const, overloadable)) log(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 563 | FN_FUNC_FN(log) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 564 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 565 | /** |
| 566 | * Return the base 10 logarithm |
| 567 | * |
| 568 | * Supports 1,2,3,4 components |
| 569 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 570 | extern float __attribute__((const, overloadable)) log10(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 571 | FN_FUNC_FN(log10) |
Jason Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 572 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 573 | /** |
| 574 | * Return the base 2 logarithm |
| 575 | * |
| 576 | * Supports 1,2,3,4 components |
| 577 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 578 | _RS_RUNTIME float __attribute__((const, overloadable)) log2(float v); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 579 | FN_FUNC_FN(log2) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 580 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 581 | /** |
| 582 | * Return the natural logarithm of (v + 1.0f) |
| 583 | * |
| 584 | * Supports 1,2,3,4 components |
| 585 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 586 | extern float __attribute__((const, overloadable)) log1p(float v); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 587 | FN_FUNC_FN(log1p) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 588 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 589 | /** |
| 590 | * Compute the exponent of the value. |
| 591 | * |
| 592 | * Supports 1,2,3,4 components |
| 593 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 594 | extern float __attribute__((const, overloadable)) logb(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 595 | FN_FUNC_FN(logb) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 596 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 597 | /** |
| 598 | * Compute (a * b) + c |
| 599 | * |
| 600 | * Supports 1,2,3,4 components |
| 601 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 602 | extern float __attribute__((const, overloadable)) mad(float a, float b, float c); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 603 | FN_FUNC_FN_FN_FN(mad) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 604 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 605 | /** |
Stephen Hines | cb05802 | 2012-05-29 17:10:05 -0700 | [diff] [blame] | 606 | * Return the integral and fractional components of a number. |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 607 | * 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 Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 613 | extern float __attribute__((pure, overloadable)) modf(float x, float *iret); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 614 | FN_FUNC_FN_PFN(modf); |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 615 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 616 | extern float __attribute__((const, overloadable)) nan(uint); |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 617 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 618 | /** |
| 619 | * Return the next floating point number from x towards y. |
| 620 | * |
| 621 | * Supports 1,2,3,4 components |
| 622 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 623 | extern float __attribute__((const, overloadable)) nextafter(float x, float y); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 624 | FN_FUNC_FN_FN(nextafter) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 625 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 626 | /** |
| 627 | * Return (v ^ p). |
| 628 | * |
| 629 | * Supports 1,2,3,4 components |
| 630 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 631 | _RS_RUNTIME float __attribute__((const, overloadable)) pown(float v, int p); |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 632 | FN_FUNC_FN_IN(pown) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 633 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 634 | /** |
| 635 | * Return (v ^ p). |
| 636 | * @param v must be greater than 0. |
| 637 | * |
| 638 | * Supports 1,2,3,4 components |
| 639 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 640 | _RS_RUNTIME float __attribute__((const, overloadable)) powr(float v, float p); |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 641 | FN_FUNC_FN_FN(powr) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 642 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 643 | /** |
| 644 | * Return round x/y to the nearest integer then compute the remander. |
| 645 | * |
| 646 | * Supports 1,2,3,4 components |
| 647 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 648 | extern float __attribute__((const, overloadable)) remainder(float x, float y); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 649 | FN_FUNC_FN_FN(remainder) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 650 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 651 | // document once we know the precision of bionic |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 652 | extern float __attribute__((pure, overloadable)) remquo(float, float, int *); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 653 | FN_FUNC_FN_FN_PIN(remquo) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 654 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 655 | /** |
| 656 | * Round to the nearest integral value. |
| 657 | * |
| 658 | * Supports 1,2,3,4 components |
| 659 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 660 | extern float __attribute__((const, overloadable)) rint(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 661 | FN_FUNC_FN(rint) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 662 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 663 | /** |
| 664 | * Compute the Nth root of a value. |
| 665 | * |
| 666 | * Supports 1,2,3,4 components |
| 667 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 668 | _RS_RUNTIME float __attribute__((const, overloadable)) rootn(float v, int n); |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 669 | FN_FUNC_FN_IN(rootn) |
Shih-wei Liao | edf2240 | 2011-01-26 04:03:30 -0800 | [diff] [blame] | 670 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 671 | /** |
| 672 | * Round to the nearest integral value. Half values are rounded away from zero. |
| 673 | * |
| 674 | * Supports 1,2,3,4 components |
| 675 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 676 | extern float __attribute__((const, overloadable)) round(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 677 | FN_FUNC_FN(round) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 678 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 679 | /** |
| 680 | * Return the square root of a value. |
| 681 | * |
| 682 | * Supports 1,2,3,4 components |
| 683 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 684 | extern float __attribute__((const, overloadable)) sqrt(float); |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 685 | FN_FUNC_FN(sqrt) |
| 686 | |
| 687 | /** |
| 688 | * Return (1 / sqrt(value)). |
| 689 | * |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 690 | * Supports 1,2,3,4 components |
| 691 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 692 | _RS_RUNTIME float __attribute__((const, overloadable)) rsqrt(float v); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 693 | FN_FUNC_FN(rsqrt) |
Jason Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 694 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 695 | /** |
| 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 Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 701 | extern float __attribute__((const, overloadable)) sin(float v); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 702 | FN_FUNC_FN(sin) |
Jason Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 703 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 704 | /** |
| 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 Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 713 | _RS_RUNTIME float __attribute__((pure, overloadable)) sincos(float v, float *cosptr); |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 714 | FN_FUNC_FN_PFN(sincos); |
Jason Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 715 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 716 | /** |
| 717 | * Return the hyperbolic sine of a value specified in radians. |
| 718 | * |
| 719 | * Supports 1,2,3,4 components |
| 720 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 721 | extern float __attribute__((const, overloadable)) sinh(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 722 | FN_FUNC_FN(sinh) |
Jason Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 723 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 724 | /** |
| 725 | * Return the sin(v * PI). |
| 726 | * |
| 727 | * Supports 1,2,3,4 components |
| 728 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 729 | _RS_RUNTIME float __attribute__((const, overloadable)) sinpi(float v); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 730 | FN_FUNC_FN(sinpi) |
Jason Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 731 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 732 | /** |
| 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 Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 738 | extern float __attribute__((const, overloadable)) tan(float v); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 739 | FN_FUNC_FN(tan) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 740 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 741 | /** |
| 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 Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 747 | extern float __attribute__((const, overloadable)) tanh(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 748 | FN_FUNC_FN(tanh) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 749 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 750 | /** |
| 751 | * Return tan(v * PI) |
| 752 | * |
| 753 | * Supports 1,2,3,4 components |
| 754 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 755 | _RS_RUNTIME float __attribute__((const, overloadable)) tanpi(float v); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 756 | FN_FUNC_FN(tanpi) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 757 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 758 | /** |
| 759 | * Compute the gamma function of a value. |
| 760 | * |
| 761 | * Supports 1,2,3,4 components |
| 762 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 763 | extern float __attribute__((const, overloadable)) tgamma(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 764 | FN_FUNC_FN(tgamma) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 765 | |
Jason Sams | ef82364 | 2011-08-31 14:52:08 -0700 | [diff] [blame] | 766 | /** |
| 767 | * Round to integral using truncation. |
| 768 | * |
| 769 | * Supports 1,2,3,4 components |
| 770 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 771 | extern float __attribute__((const, overloadable)) trunc(float); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 772 | FN_FUNC_FN(trunc) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 773 | |
Stephen Hines | e781228 | 2013-06-19 00:07:04 -0700 | [diff] [blame^] | 774 | #ifdef DOXYGEN |
| 775 | |
| 776 | #define XN_FUNC_YN(typeout, fnc, typein) \ |
| 777 | extern 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 Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 784 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 785 | #define XN_FUNC_YN(typeout, fnc, typein) \ |
Stephen Hines | e781228 | 2013-06-19 00:07:04 -0700 | [diff] [blame^] | 786 | extern typeout __attribute__((const, overloadable)) fnc(typein v); \ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 787 | _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 Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 790 | |
Stephen Hines | e781228 | 2013-06-19 00:07:04 -0700 | [diff] [blame^] | 791 | #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 Hines | 47b1530 | 2011-01-19 18:06:34 -0800 | [diff] [blame] | 803 | #define UIN_FUNC_IN(fnc) \ |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 804 | XN_FUNC_YN(uchar, fnc, char) \ |
| 805 | XN_FUNC_YN(ushort, fnc, short) \ |
| 806 | XN_FUNC_YN(uint, fnc, int) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 807 | |
Stephen Hines | 47b1530 | 2011-01-19 18:06:34 -0800 | [diff] [blame] | 808 | #define IN_FUNC_IN(fnc) \ |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 809 | XN_FUNC_YN(uchar, fnc, uchar) \ |
| 810 | XN_FUNC_YN(char, fnc, char) \ |
| 811 | XN_FUNC_YN(ushort, fnc, ushort) \ |
| 812 | XN_FUNC_YN(short, fnc, short) \ |
| 813 | XN_FUNC_YN(uint, fnc, uint) \ |
| 814 | XN_FUNC_YN(int, fnc, int) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 815 | |
Stephen Hines | cb05802 | 2012-05-29 17:10:05 -0700 | [diff] [blame] | 816 | #define IN_FUNC_IN_IN_BODY(fnc, body) \ |
| 817 | XN_FUNC_XN_XN_BODY(uchar, fnc, body) \ |
| 818 | XN_FUNC_XN_XN_BODY(char, fnc, body) \ |
| 819 | XN_FUNC_XN_XN_BODY(ushort, fnc, body) \ |
| 820 | XN_FUNC_XN_XN_BODY(short, fnc, body) \ |
| 821 | XN_FUNC_XN_XN_BODY(uint, fnc, body) \ |
| 822 | XN_FUNC_XN_XN_BODY(int, fnc, body) \ |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 823 | XN_FUNC_XN_XN_BODY(float, fnc, body) |
Stephen Hines | b902e4c | 2011-01-14 18:49:01 -0800 | [diff] [blame] | 824 | |
Stephen Hines | cb05802 | 2012-05-29 17:10:05 -0700 | [diff] [blame] | 825 | /** |
Stephen Hines | e781228 | 2013-06-19 00:07:04 -0700 | [diff] [blame^] | 826 | * \fn uchar abs(char) |
Stephen Hines | cb05802 | 2012-05-29 17:10:05 -0700 | [diff] [blame] | 827 | * Return the absolute value of a value. |
| 828 | * |
| 829 | * Supports 1,2,3,4 components of char, short, int. |
| 830 | */ |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 831 | UIN_FUNC_IN(abs) |
Stephen Hines | cb05802 | 2012-05-29 17:10:05 -0700 | [diff] [blame] | 832 | |
| 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 Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 838 | IN_FUNC_IN(clz) |
Stephen Hines | b902e4c | 2011-01-14 18:49:01 -0800 | [diff] [blame] | 839 | |
Jason Sams | dc2c3e6 | 2011-08-31 16:44:18 -0700 | [diff] [blame] | 840 | /** |
| 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 Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 845 | IN_FUNC_IN_IN_BODY(min, (v1 < v2 ? v1 : v2)) |
| 846 | FN_FUNC_FN_F(min) |
Stephen Hines | b902e4c | 2011-01-14 18:49:01 -0800 | [diff] [blame] | 847 | |
Jason Sams | dc2c3e6 | 2011-08-31 16:44:18 -0700 | [diff] [blame] | 848 | /** |
| 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 Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 853 | IN_FUNC_IN_IN_BODY(max, (v1 > v2 ? v1 : v2)) |
| 854 | FN_FUNC_FN_F(max) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 855 | |
Jason Sams | dc2c3e6 | 2011-08-31 16:44:18 -0700 | [diff] [blame] | 856 | /** |
| 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 Sams | c626135 | 2013-05-24 14:51:52 -0700 | [diff] [blame] | 863 | |
| 864 | #if !defined(RS_VERSION) || (RS_VERSION < 19) |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 865 | _RS_RUNTIME float __attribute__((const, overloadable)) clamp(float amount, float low, float high); |
Rajeev Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 866 | FN_FUNC_FN_FN_FN(clamp) |
| 867 | FN_FUNC_FN_F_F(clamp) |
Jason Sams | c626135 | 2013-05-24 14:51:52 -0700 | [diff] [blame] | 868 | #else |
| 869 | #define _CLAMP(T) \ |
| 870 | extern T __attribute__((overloadable)) clamp(T amount, T low, T high); \ |
| 871 | extern T##2 __attribute__((overloadable)) clamp(T##2 amount, T##2 low, T##2 high); \ |
| 872 | extern T##3 __attribute__((overloadable)) clamp(T##3 amount, T##3 low, T##3 high); \ |
| 873 | extern T##4 __attribute__((overloadable)) clamp(T##4 amount, T##4 low, T##4 high); \ |
| 874 | extern T##2 __attribute__((overloadable)) clamp(T##2 amount, T low, T high); \ |
| 875 | extern T##3 __attribute__((overloadable)) clamp(T##3 amount, T low, T high); \ |
| 876 | extern 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 Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 891 | |
Jason Sams | dc2c3e6 | 2011-08-31 16:44:18 -0700 | [diff] [blame] | 892 | /** |
| 893 | * Convert from radians to degrees. |
| 894 | * |
| 895 | * Supports 1,2,3,4 components |
| 896 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 897 | _RS_RUNTIME float __attribute__((const, overloadable)) degrees(float radians); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 898 | FN_FUNC_FN(degrees) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 899 | |
Jason Sams | dc2c3e6 | 2011-08-31 16:44:18 -0700 | [diff] [blame] | 900 | /** |
| 901 | * return start + ((stop - start) * amount); |
| 902 | * |
| 903 | * Supports 1,2,3,4 components |
| 904 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 905 | _RS_RUNTIME float __attribute__((const, overloadable)) mix(float start, float stop, float amount); |
Rajeev Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 906 | FN_FUNC_FN_FN_FN(mix) |
| 907 | FN_FUNC_FN_FN_F(mix) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 908 | |
Jason Sams | dc2c3e6 | 2011-08-31 16:44:18 -0700 | [diff] [blame] | 909 | /** |
| 910 | * Convert from degrees to radians. |
| 911 | * |
| 912 | * Supports 1,2,3,4 components |
| 913 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 914 | _RS_RUNTIME float __attribute__((const, overloadable)) radians(float degrees); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 915 | FN_FUNC_FN(radians) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 916 | |
Jason Sams | dc2c3e6 | 2011-08-31 16:44:18 -0700 | [diff] [blame] | 917 | /** |
| 918 | * if (v < edge) |
| 919 | * return 0.f; |
| 920 | * else |
| 921 | * return 1.f; |
| 922 | * |
| 923 | * Supports 1,2,3,4 components |
| 924 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 925 | _RS_RUNTIME float __attribute__((const, overloadable)) step(float edge, float v); |
Rajeev Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 926 | FN_FUNC_FN_FN(step) |
| 927 | FN_FUNC_FN_F(step) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 928 | |
Jason Sams | dc2c3e6 | 2011-08-31 16:44:18 -0700 | [diff] [blame] | 929 | // not implemented |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 930 | extern float __attribute__((const, overloadable)) smoothstep(float, float, float); |
| 931 | extern float2 __attribute__((const, overloadable)) smoothstep(float2, float2, float2); |
| 932 | extern float3 __attribute__((const, overloadable)) smoothstep(float3, float3, float3); |
| 933 | extern float4 __attribute__((const, overloadable)) smoothstep(float4, float4, float4); |
| 934 | extern float2 __attribute__((const, overloadable)) smoothstep(float, float, float2); |
| 935 | extern float3 __attribute__((const, overloadable)) smoothstep(float, float, float3); |
| 936 | extern float4 __attribute__((const, overloadable)) smoothstep(float, float, float4); |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 937 | |
Jason Sams | dc2c3e6 | 2011-08-31 16:44:18 -0700 | [diff] [blame] | 938 | /** |
Stephen Hines | cb05802 | 2012-05-29 17:10:05 -0700 | [diff] [blame] | 939 | * Return the sign of a value. |
| 940 | * |
Jason Sams | dc2c3e6 | 2011-08-31 16:44:18 -0700 | [diff] [blame] | 941 | * 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 Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 947 | _RS_RUNTIME float __attribute__((const, overloadable)) sign(float v); |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 948 | FN_FUNC_FN(sign) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 949 | |
Jason Sams | dc2c3e6 | 2011-08-31 16:44:18 -0700 | [diff] [blame] | 950 | /** |
| 951 | * Compute the cross product of two vectors. |
| 952 | * |
| 953 | * Supports 3,4 components |
| 954 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 955 | _RS_RUNTIME float3 __attribute__((const, overloadable)) cross(float3 lhs, float3 rhs); |
| 956 | _RS_RUNTIME float4 __attribute__((const, overloadable)) cross(float4 lhs, float4 rhs); |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 957 | |
Jason Sams | dc2c3e6 | 2011-08-31 16:44:18 -0700 | [diff] [blame] | 958 | /** |
| 959 | * Compute the dot product of two vectors. |
| 960 | * |
| 961 | * Supports 1,2,3,4 components |
| 962 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 963 | _RS_RUNTIME float __attribute__((const, overloadable)) dot(float lhs, float rhs); |
Rajeev Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 964 | F_FUNC_FN_FN(dot) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 965 | |
Jason Sams | dc2c3e6 | 2011-08-31 16:44:18 -0700 | [diff] [blame] | 966 | /** |
| 967 | * Compute the length of a vector. |
| 968 | * |
| 969 | * Supports 1,2,3,4 components |
| 970 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 971 | _RS_RUNTIME float __attribute__((const, overloadable)) length(float v); |
Rajeev Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 972 | F_FUNC_FN(length) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 973 | |
Jason Sams | dc2c3e6 | 2011-08-31 16:44:18 -0700 | [diff] [blame] | 974 | /** |
| 975 | * Compute the distance between two points. |
| 976 | * |
| 977 | * Supports 1,2,3,4 components |
| 978 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 979 | _RS_RUNTIME float __attribute__((const, overloadable)) distance(float lhs, float rhs); |
Rajeev Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 980 | F_FUNC_FN_FN(distance) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 981 | |
Jason Sams | dc2c3e6 | 2011-08-31 16:44:18 -0700 | [diff] [blame] | 982 | /** |
| 983 | * Normalize a vector. |
| 984 | * |
| 985 | * Supports 1,2,3,4 components |
| 986 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 987 | _RS_RUNTIME float __attribute__((const, overloadable)) normalize(float v); |
Rajeev Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 988 | FN_FUNC_FN(normalize) |
| 989 | |
Rajeev Sharma | 7150c93 | 2012-08-15 21:41:39 -0700 | [diff] [blame] | 990 | |
| 991 | // New approx API functions |
| 992 | #if (defined(RS_VERSION) && (RS_VERSION >= 17)) |
| 993 | |
Rajeev Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 994 | /** |
| 995 | * Return the approximate reciprocal of a value. |
| 996 | * |
| 997 | * Supports 1,2,3,4 components |
| 998 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 999 | _RS_RUNTIME float __attribute__((const, overloadable)) half_recip(float); |
Jason Sams | ab4b0ef | 2012-09-20 15:39:18 -0700 | [diff] [blame] | 1000 | FN_FUNC_FN(half_recip) |
Rajeev Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 1001 | |
| 1002 | /** |
| 1003 | * Return the approximate square root of a value. |
| 1004 | * |
| 1005 | * Supports 1,2,3,4 components |
| 1006 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 1007 | _RS_RUNTIME float __attribute__((const, overloadable)) half_sqrt(float); |
Jason Sams | ab4b0ef | 2012-09-20 15:39:18 -0700 | [diff] [blame] | 1008 | FN_FUNC_FN(half_sqrt) |
Rajeev Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 1009 | |
| 1010 | /** |
| 1011 | * Return the approximate value of (1 / sqrt(value)). |
| 1012 | * |
| 1013 | * Supports 1,2,3,4 components |
| 1014 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 1015 | _RS_RUNTIME float __attribute__((const, overloadable)) half_rsqrt(float v); |
Jason Sams | ab4b0ef | 2012-09-20 15:39:18 -0700 | [diff] [blame] | 1016 | FN_FUNC_FN(half_rsqrt) |
Rajeev Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 1017 | |
| 1018 | /** |
| 1019 | * Compute the approximate length of a vector. |
| 1020 | * |
| 1021 | * Supports 1,2,3,4 components |
| 1022 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 1023 | _RS_RUNTIME float __attribute__((const, overloadable)) fast_length(float v); |
Jason Sams | ab4b0ef | 2012-09-20 15:39:18 -0700 | [diff] [blame] | 1024 | F_FUNC_FN(fast_length) |
Rajeev Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 1025 | |
| 1026 | /** |
| 1027 | * Compute the approximate distance between two points. |
| 1028 | * |
| 1029 | * Supports 1,2,3,4 components |
| 1030 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 1031 | _RS_RUNTIME float __attribute__((const, overloadable)) fast_distance(float lhs, float rhs); |
Jason Sams | ab4b0ef | 2012-09-20 15:39:18 -0700 | [diff] [blame] | 1032 | F_FUNC_FN_FN(fast_distance) |
Rajeev Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 1033 | |
| 1034 | /** |
| 1035 | * Approximately normalize a vector. |
| 1036 | * |
| 1037 | * Supports 1,2,3,4 components |
| 1038 | */ |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 1039 | _RS_RUNTIME float __attribute__((const, overloadable)) fast_normalize(float v); |
Jason Sams | ab4b0ef | 2012-09-20 15:39:18 -0700 | [diff] [blame] | 1040 | F_FUNC_FN(fast_normalize) |
Rajeev Sharma | 7150c93 | 2012-08-15 21:41:39 -0700 | [diff] [blame] | 1041 | |
| 1042 | #endif // (defined(RS_VERSION) && (RS_VERSION >= 17)) |
| 1043 | |
| 1044 | |
Jason Sams | 59531f7 | 2013-01-18 14:10:32 -0800 | [diff] [blame] | 1045 | |
| 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 Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 1057 | _RS_RUNTIME float __attribute__((const, overloadable)) native_exp2(float v); |
Jason Sams | 59531f7 | 2013-01-18 14:10:32 -0800 | [diff] [blame] | 1058 | FN_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 Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 1067 | _RS_RUNTIME float __attribute__((const, overloadable)) native_exp(float v); |
Jason Sams | 59531f7 | 2013-01-18 14:10:32 -0800 | [diff] [blame] | 1068 | FN_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 Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 1077 | _RS_RUNTIME float __attribute__((const, overloadable)) native_exp10(float v); |
Jason Sams | 59531f7 | 2013-01-18 14:10:32 -0800 | [diff] [blame] | 1078 | FN_FUNC_FN(native_exp10) |
| 1079 | |
| 1080 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 1081 | _RS_RUNTIME float __attribute__((const, overloadable)) native_log2(float v); |
Jason Sams | aa49395 | 2013-01-25 13:21:17 -0800 | [diff] [blame] | 1082 | FN_FUNC_FN(native_log2) |
| 1083 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 1084 | _RS_RUNTIME float __attribute__((const, overloadable)) native_log(float v); |
Jason Sams | aa49395 | 2013-01-25 13:21:17 -0800 | [diff] [blame] | 1085 | FN_FUNC_FN(native_log) |
| 1086 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 1087 | _RS_RUNTIME float __attribute__((const, overloadable)) native_log10(float v); |
Jason Sams | aa49395 | 2013-01-25 13:21:17 -0800 | [diff] [blame] | 1088 | FN_FUNC_FN(native_log10) |
| 1089 | |
| 1090 | |
Stephen Hines | 5213247 | 2013-04-30 15:45:22 -0700 | [diff] [blame] | 1091 | _RS_RUNTIME float __attribute__((const, overloadable)) native_powr(float v, float y); |
Jason Sams | aa49395 | 2013-01-25 13:21:17 -0800 | [diff] [blame] | 1092 | FN_FUNC_FN_FN(native_powr) |
| 1093 | |
| 1094 | |
Jason Sams | 59531f7 | 2013-01-18 14:10:32 -0800 | [diff] [blame] | 1095 | #endif // (defined(RS_VERSION) && (RS_VERSION >= 18)) |
| 1096 | |
| 1097 | |
Stephen Hines | 4741653 | 2011-01-11 14:38:18 -0800 | [diff] [blame] | 1098 | #undef CVT_FUNC |
| 1099 | #undef CVT_FUNC_2 |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 1100 | #undef FN_FUNC_FN |
Rajeev Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 1101 | #undef F_FUNC_FN |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 1102 | #undef IN_FUNC_FN |
| 1103 | #undef FN_FUNC_FN_FN |
Rajeev Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 1104 | #undef F_FUNC_FN_FN |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 1105 | #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 Sharma | 65723fe | 2012-08-03 15:11:04 -0700 | [diff] [blame] | 1111 | #undef FN_FUNC_FN_FN_F |
| 1112 | #undef FN_FUNC_FN_F_F |
Stephen Hines | 3e6482f | 2011-01-19 12:51:33 -0800 | [diff] [blame] | 1113 | #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 Sams | 1b937f5 | 2010-06-09 14:26:16 -0700 | [diff] [blame] | 1119 | |
| 1120 | #endif |