Home | History | Annotate | Download | only in scriptc
      1 /*
      2  * Copyright (C) 2011-2012 The Android Open Source Project
      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
     18  *  \brief Basic math functions
     19  *
     20  *
     21  */
     22 
     23 #ifndef __RS_CL_RSH__
     24 #define __RS_CL_RSH__
     25 
     26 // Conversions
     27 #define CVT_FUNC_2(typeout, typein)                             \
     28 _RS_RUNTIME typeout##2 __attribute__((overloadable))            \
     29         convert_##typeout##2(typein##2 v);                      \
     30 _RS_RUNTIME typeout##3 __attribute__((overloadable))            \
     31         convert_##typeout##3(typein##3 v);                      \
     32 _RS_RUNTIME typeout##4 __attribute__((overloadable))            \
     33         convert_##typeout##4(typein##4 v);
     34 
     35 
     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)
     43 
     44 /**
     45  * Convert to char.
     46  *
     47  * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float.
     48  */
     49 CVT_FUNC(char)
     50 
     51 /**
     52  * Convert to unsigned char.
     53  *
     54  * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float.
     55  */
     56 CVT_FUNC(uchar)
     57 
     58 /**
     59  * Convert to short.
     60  *
     61  * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float.
     62  */
     63 CVT_FUNC(short)
     64 
     65 /**
     66  * Convert to unsigned short.
     67  *
     68  * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float.
     69  */
     70 CVT_FUNC(ushort)
     71 
     72 /**
     73  * Convert to int.
     74  *
     75  * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float.
     76  */
     77 CVT_FUNC(int)
     78 
     79 /**
     80  * Convert to unsigned int.
     81  *
     82  * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float.
     83  */
     84 CVT_FUNC(uint)
     85 
     86 /**
     87  * Convert to float.
     88  *
     89  * Supports 2,3,4 components of uchar, char, ushort, short, uint, int, float.
     90  */
     91 CVT_FUNC(float)
     92 
     93 // Float ops, 6.11.2
     94 
     95 #define FN_FUNC_FN(fnc)                                         \
     96 _RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v); \
     97 _RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v); \
     98 _RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v);
     99 
    100 #define F_FUNC_FN(fnc)                                          \
    101 _RS_RUNTIME float __attribute__((overloadable)) fnc(float2 v);  \
    102 _RS_RUNTIME float __attribute__((overloadable)) fnc(float3 v);  \
    103 _RS_RUNTIME float __attribute__((overloadable)) fnc(float4 v);
    104 
    105 #define IN_FUNC_FN(fnc)                                         \
    106 _RS_RUNTIME int2 __attribute__((overloadable)) fnc(float2 v);   \
    107 _RS_RUNTIME int3 __attribute__((overloadable)) fnc(float3 v);   \
    108 _RS_RUNTIME int4 __attribute__((overloadable)) fnc(float4 v);
    109 
    110 #define FN_FUNC_FN_FN(fnc)                                                  \
    111 _RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, float2 v2); \
    112 _RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, float3 v2); \
    113 _RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, float4 v2);
    114 
    115 #define F_FUNC_FN_FN(fnc)                                                   \
    116 _RS_RUNTIME float __attribute__((overloadable)) fnc(float2 v1, float2 v2);  \
    117 _RS_RUNTIME float __attribute__((overloadable)) fnc(float3 v1, float3 v2);  \
    118 _RS_RUNTIME float __attribute__((overloadable)) fnc(float4 v1, float4 v2);
    119 
    120 #define FN_FUNC_FN_F(fnc)                                                   \
    121 _RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, float v2);  \
    122 _RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, float v2);  \
    123 _RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, float v2);
    124 
    125 #define FN_FUNC_FN_IN(fnc)                                                  \
    126 _RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, int2 v2);   \
    127 _RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, int3 v2);   \
    128 _RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, int4 v2);   \
    129 
    130 #define FN_FUNC_FN_I(fnc)                                                   \
    131 _RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, int v2);    \
    132 _RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, int v2);    \
    133 _RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, int v2);
    134 
    135 #define FN_FUNC_FN_PFN(fnc)                         \
    136 _RS_RUNTIME float2 __attribute__((overloadable))    \
    137         fnc(float2 v1, float2 *v2);                 \
    138 _RS_RUNTIME float3 __attribute__((overloadable))    \
    139         fnc(float3 v1, float3 *v2);                 \
    140 _RS_RUNTIME float4 __attribute__((overloadable))    \
    141         fnc(float4 v1, float4 *v2);
    142 
    143 #define FN_FUNC_FN_PIN(fnc)                                                 \
    144 _RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, int2 *v2);  \
    145 _RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, int3 *v2);  \
    146 _RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, int4 *v2);
    147 
    148 #define FN_FUNC_FN_FN_FN(fnc)                       \
    149 _RS_RUNTIME float2 __attribute__((overloadable))    \
    150         fnc(float2 v1, float2 v2, float2 v3);       \
    151 _RS_RUNTIME float3 __attribute__((overloadable))    \
    152         fnc(float3 v1, float3 v2, float3 v3);       \
    153 _RS_RUNTIME float4 __attribute__((overloadable))    \
    154         fnc(float4 v1, float4 v2, float4 v3);
    155 
    156 #define FN_FUNC_FN_FN_F(fnc)                        \
    157 _RS_RUNTIME float2 __attribute__((overloadable))    \
    158         fnc(float2 v1, float2 v2, float v3);        \
    159 _RS_RUNTIME float3 __attribute__((overloadable))    \
    160         fnc(float3 v1, float3 v2, float v3);        \
    161 _RS_RUNTIME float4 __attribute__((overloadable))    \
    162         fnc(float4 v1, float4 v2, float v3);
    163 
    164 #define FN_FUNC_FN_F_F(fnc)                         \
    165 _RS_RUNTIME float2 __attribute__((overloadable))    \
    166         fnc(float2 v1, float v2, float v3);         \
    167 _RS_RUNTIME float3 __attribute__((overloadable))    \
    168         fnc(float3 v1, float v2, float v3);         \
    169 _RS_RUNTIME float4 __attribute__((overloadable))    \
    170         fnc(float4 v1, float v2, float v3);
    171 
    172 #define FN_FUNC_FN_FN_PIN(fnc)                      \
    173 _RS_RUNTIME float2 __attribute__((overloadable))    \
    174         fnc(float2 v1, float2 v2, int2 *v3);        \
    175 _RS_RUNTIME float3 __attribute__((overloadable))    \
    176         fnc(float3 v1, float3 v2, int3 *v3);        \
    177 _RS_RUNTIME float4 __attribute__((overloadable))    \
    178         fnc(float4 v1, float4 v2, int4 *v3);
    179 
    180 
    181 /**
    182  * Return the inverse cosine.
    183  *
    184  * Supports float, float2, float3, float4
    185  */
    186 extern float __attribute__((overloadable)) acos(float);
    187 FN_FUNC_FN(acos)
    188 
    189 /**
    190  * Return the inverse hyperbolic cosine.
    191  *
    192  * Supports float, float2, float3, float4
    193  */
    194 extern float __attribute__((overloadable)) acosh(float);
    195 FN_FUNC_FN(acosh)
    196 
    197 /**
    198  * Return the inverse cosine divided by PI.
    199  *
    200  * Supports float, float2, float3, float4
    201  */
    202 _RS_RUNTIME float __attribute__((overloadable)) acospi(float v);
    203 FN_FUNC_FN(acospi)
    204 
    205 /**
    206  * Return the inverse sine.
    207  *
    208  * Supports float, float2, float3, float4
    209  */
    210 extern float __attribute__((overloadable)) asin(float);
    211 FN_FUNC_FN(asin)
    212 
    213 /**
    214  * Return the inverse hyperbolic sine.
    215  *
    216  * Supports float, float2, float3, float4
    217  */
    218 extern float __attribute__((overloadable)) asinh(float);
    219 FN_FUNC_FN(asinh)
    220 
    221 
    222 /**
    223  * Return the inverse sine divided by PI.
    224  *
    225  * Supports float, float2, float3, float4
    226  */
    227 _RS_RUNTIME float __attribute__((overloadable)) asinpi(float v);
    228 FN_FUNC_FN(asinpi)
    229 
    230 /**
    231  * Return the inverse tangent.
    232  *
    233  * Supports float, float2, float3, float4
    234  */
    235 extern float __attribute__((overloadable)) atan(float);
    236 FN_FUNC_FN(atan)
    237 
    238 /**
    239  * Return the inverse tangent of y / x.
    240  *
    241  * Supports float, float2, float3, float4.  Both arguments must be of the same
    242  * type.
    243  *
    244  * @param y
    245  * @param x
    246  */
    247 extern float __attribute__((overloadable)) atan2(float y, float x);
    248 FN_FUNC_FN_FN(atan2)
    249 
    250 /**
    251  * Return the inverse hyperbolic tangent.
    252  *
    253  * Supports float, float2, float3, float4
    254  */
    255 extern float __attribute__((overloadable)) atanh(float);
    256 FN_FUNC_FN(atanh)
    257 
    258 /**
    259  * Return the inverse tangent divided by PI.
    260  *
    261  * Supports float, float2, float3, float4
    262  */
    263 _RS_RUNTIME float __attribute__((overloadable)) atanpi(float v);
    264 FN_FUNC_FN(atanpi)
    265 
    266 /**
    267  * Return the inverse tangent of y / x, divided by PI.
    268  *
    269  * Supports float, float2, float3, float4.  Both arguments must be of the same
    270  * type.
    271  *
    272  * @param y
    273  * @param x
    274  */
    275 _RS_RUNTIME float __attribute__((overloadable)) atan2pi(float y, float x);
    276 FN_FUNC_FN_FN(atan2pi)
    277 
    278 
    279 /**
    280  * Return the cube root.
    281  *
    282  * Supports float, float2, float3, float4.
    283  */
    284 extern float __attribute__((overloadable)) cbrt(float);
    285 FN_FUNC_FN(cbrt)
    286 
    287 /**
    288  * Return the smallest integer not less than a value.
    289  *
    290  * Supports float, float2, float3, float4.
    291  */
    292 extern float __attribute__((overloadable)) ceil(float);
    293 FN_FUNC_FN(ceil)
    294 
    295 /**
    296  * Copy the sign bit from y to x.
    297  *
    298  * Supports float, float2, float3, float4.  Both arguments must be of the same
    299  * type.
    300  *
    301  * @param x
    302  * @param y
    303  */
    304 extern float __attribute__((overloadable)) copysign(float x, float y);
    305 FN_FUNC_FN_FN(copysign)
    306 
    307 /**
    308  * Return the cosine.
    309  *
    310  * Supports float, float2, float3, float4.
    311  */
    312 extern float __attribute__((overloadable)) cos(float);
    313 FN_FUNC_FN(cos)
    314 
    315 /**
    316  * Return the hypebolic cosine.
    317  *
    318  * Supports float, float2, float3, float4.
    319  */
    320 extern float __attribute__((overloadable)) cosh(float);
    321 FN_FUNC_FN(cosh)
    322 
    323 /**
    324  * Return the cosine of the value * PI.
    325  *
    326  * Supports float, float2, float3, float4.
    327  */
    328 _RS_RUNTIME float __attribute__((overloadable)) cospi(float v);
    329 FN_FUNC_FN(cospi)
    330 
    331 /**
    332  * Return the complementary error function.
    333  *
    334  * Supports float, float2, float3, float4.
    335  */
    336 extern float __attribute__((overloadable)) erfc(float);
    337 FN_FUNC_FN(erfc)
    338 
    339 /**
    340  * Return the error function.
    341  *
    342  * Supports float, float2, float3, float4.
    343  */
    344 extern float __attribute__((overloadable)) erf(float);
    345 FN_FUNC_FN(erf)
    346 
    347 /**
    348  * Return e ^ value.
    349  *
    350  * Supports float, float2, float3, float4.
    351  */
    352 extern float __attribute__((overloadable)) exp(float);
    353 FN_FUNC_FN(exp)
    354 
    355 /**
    356  * Return 2 ^ value.
    357  *
    358  * Supports float, float2, float3, float4.
    359  */
    360 extern float __attribute__((overloadable)) exp2(float);
    361 FN_FUNC_FN(exp2)
    362 
    363 /**
    364  * Return x ^ y.
    365  *
    366  * Supports float, float2, float3, float4. Both arguments must be of the same
    367  * type.
    368  */
    369 extern float __attribute__((overloadable)) pow(float x, float y);
    370 FN_FUNC_FN_FN(pow)
    371 
    372 /**
    373  * Return 10 ^ value.
    374  *
    375  * Supports float, float2, float3, float4.
    376  */
    377 _RS_RUNTIME float __attribute__((overloadable)) exp10(float v);
    378 FN_FUNC_FN(exp10)
    379 
    380 /**
    381  * Return (e ^ value) - 1.
    382  *
    383  * Supports float, float2, float3, float4.
    384  */
    385 extern float __attribute__((overloadable)) expm1(float);
    386 FN_FUNC_FN(expm1)
    387 
    388 /**
    389  * Return the absolute value of a value.
    390  *
    391  * Supports float, float2, float3, float4.
    392  */
    393 extern float __attribute__((overloadable)) fabs(float);
    394 FN_FUNC_FN(fabs)
    395 
    396 /**
    397  * Return the positive difference between two values.
    398  *
    399  * Supports float, float2, float3, float4.  Both arguments must be of the same
    400  * type.
    401  */
    402 extern float __attribute__((overloadable)) fdim(float, float);
    403 FN_FUNC_FN_FN(fdim)
    404 
    405 /**
    406  * Return the smallest integer not greater than a value.
    407  *
    408  * Supports float, float2, float3, float4.
    409  */
    410 extern float __attribute__((overloadable)) floor(float);
    411 FN_FUNC_FN(floor)
    412 
    413 /**
    414  * Return a*b + c.
    415  *
    416  * Supports float, float2, float3, float4.
    417  */
    418 extern float __attribute__((overloadable)) fma(float a, float b, float c);
    419 FN_FUNC_FN_FN_FN(fma)
    420 
    421 /**
    422  * Return (x < y ? y : x)
    423  *
    424  * Supports float, float2, float3, float4.
    425  * @param x: may be float, float2, float3, float4
    426  * @param y: may be float or vector.  If vector must match type of x.
    427  */
    428 extern float __attribute__((overloadable)) fmax(float x, float y);
    429 FN_FUNC_FN_FN(fmax);
    430 FN_FUNC_FN_F(fmax);
    431 
    432 /**
    433  * Return (x > y ? y : x)
    434  *
    435  * @param x: may be float, float2, float3, float4
    436  * @param y: may be float or vector.  If vector must match type of x.
    437  */
    438 extern float __attribute__((overloadable)) fmin(float x, float y);
    439 FN_FUNC_FN_FN(fmin);
    440 FN_FUNC_FN_F(fmin);
    441 
    442 /**
    443  * Return the remainder from x / y
    444  *
    445  * Supports float, float2, float3, float4.
    446  */
    447 extern float __attribute__((overloadable)) fmod(float x, float y);
    448 FN_FUNC_FN_FN(fmod)
    449 
    450 
    451 /**
    452  * Return fractional part of v
    453  *
    454  * @param iptr  iptr[0] will be set to the floor of the input value.
    455  * Supports float, float2, float3, float4.
    456  */
    457 _RS_RUNTIME float __attribute__((overloadable)) fract(float v, float *iptr);
    458 FN_FUNC_FN_PFN(fract)
    459 
    460 /**
    461  * Return the mantissa and place the exponent into iptr[0]
    462  *
    463  * @param v Supports float, float2, float3, float4.
    464  * @param iptr  Must have the same vector size as v.
    465  */
    466 extern float __attribute__((overloadable)) frexp(float v, int *iptr);
    467 FN_FUNC_FN_PIN(frexp)
    468 
    469 /**
    470  * Return sqrt(x*x + y*y)
    471  *
    472  * Supports float, float2, float3, float4.
    473  */
    474 extern float __attribute__((overloadable)) hypot(float x, float y);
    475 FN_FUNC_FN_FN(hypot)
    476 
    477 /**
    478  * Return the integer exponent of a value
    479  *
    480  * Supports 1,2,3,4 components
    481  */
    482 extern int __attribute__((overloadable)) ilogb(float);
    483 IN_FUNC_FN(ilogb)
    484 
    485 /**
    486  * Return (x * 2^y)
    487  *
    488  * @param x Supports 1,2,3,4 components
    489  * @param y Supports single component or matching vector.
    490  */
    491 extern float __attribute__((overloadable)) ldexp(float x, int y);
    492 FN_FUNC_FN_IN(ldexp)
    493 FN_FUNC_FN_I(ldexp)
    494 
    495 /**
    496  * Return the log gamma
    497  *
    498  * Supports 1,2,3,4 components
    499  */
    500 extern float __attribute__((overloadable)) lgamma(float);
    501 FN_FUNC_FN(lgamma)
    502 
    503 /**
    504  * Return the log gamma and sign
    505  *
    506  * @param x Supports 1,2,3,4 components
    507  * @param y Supports matching vector.
    508  */
    509 extern float __attribute__((overloadable)) lgamma(float x, int* y);
    510 FN_FUNC_FN_PIN(lgamma)
    511 
    512 /**
    513  * Return the natural logarithm
    514  *
    515  * Supports 1,2,3,4 components
    516  */
    517 extern float __attribute__((overloadable)) log(float);
    518 FN_FUNC_FN(log)
    519 
    520 /**
    521  * Return the base 10 logarithm
    522  *
    523  * Supports 1,2,3,4 components
    524  */
    525 extern float __attribute__((overloadable)) log10(float);
    526 FN_FUNC_FN(log10)
    527 
    528 /**
    529  * Return the base 2 logarithm
    530  *
    531  * Supports 1,2,3,4 components
    532  */
    533 _RS_RUNTIME float __attribute__((overloadable)) log2(float v);
    534 FN_FUNC_FN(log2)
    535 
    536 /**
    537  * Return the natural logarithm of (v + 1.0f)
    538  *
    539  * Supports 1,2,3,4 components
    540  */
    541 extern float __attribute__((overloadable)) log1p(float v);
    542 FN_FUNC_FN(log1p)
    543 
    544 /**
    545  * Compute the exponent of the value.
    546  *
    547  * Supports 1,2,3,4 components
    548  */
    549 extern float __attribute__((overloadable)) logb(float);
    550 FN_FUNC_FN(logb)
    551 
    552 /**
    553  * Compute (a * b) + c
    554  *
    555  * Supports 1,2,3,4 components
    556  */
    557 extern float __attribute__((overloadable)) mad(float a, float b, float c);
    558 FN_FUNC_FN_FN_FN(mad)
    559 
    560 /**
    561  * Return the integral and fractional components of a number.
    562  * Supports 1,2,3,4 components
    563  *
    564  * @param x Source value
    565  * @param iret iret[0] will be set to the integral portion of the number.
    566  * @return The floating point portion of the value.
    567  */
    568 extern float __attribute__((overloadable)) modf(float x, float *iret);
    569 FN_FUNC_FN_PFN(modf);
    570 
    571 extern float __attribute__((overloadable)) nan(uint);
    572 
    573 /**
    574  * Return the next floating point number from x towards y.
    575  *
    576  * Supports 1,2,3,4 components
    577  */
    578 extern float __attribute__((overloadable)) nextafter(float x, float y);
    579 FN_FUNC_FN_FN(nextafter)
    580 
    581 /**
    582  * Return (v ^ p).
    583  *
    584  * Supports 1,2,3,4 components
    585  */
    586 _RS_RUNTIME float __attribute__((overloadable)) pown(float v, int p);
    587 FN_FUNC_FN_IN(pown)
    588 
    589 /**
    590  * Return (v ^ p).
    591  * @param v must be greater than 0.
    592  *
    593  * Supports 1,2,3,4 components
    594  */
    595 _RS_RUNTIME float __attribute__((overloadable)) powr(float v, float p);
    596 FN_FUNC_FN_FN(powr)
    597 
    598 /**
    599  * Return round x/y to the nearest integer then compute the remander.
    600  *
    601  * Supports 1,2,3,4 components
    602  */
    603 extern float __attribute__((overloadable)) remainder(float x, float y);
    604 FN_FUNC_FN_FN(remainder)
    605 
    606 // document once we know the precision of bionic
    607 extern float __attribute__((overloadable)) remquo(float, float, int *);
    608 FN_FUNC_FN_FN_PIN(remquo)
    609 
    610 /**
    611  * Round to the nearest integral value.
    612  *
    613  * Supports 1,2,3,4 components
    614  */
    615 extern float __attribute__((overloadable)) rint(float);
    616 FN_FUNC_FN(rint)
    617 
    618 /**
    619  * Compute the Nth root of a value.
    620  *
    621  * Supports 1,2,3,4 components
    622  */
    623 _RS_RUNTIME float __attribute__((overloadable)) rootn(float v, int n);
    624 FN_FUNC_FN_IN(rootn)
    625 
    626 /**
    627  * Round to the nearest integral value.  Half values are rounded away from zero.
    628  *
    629  * Supports 1,2,3,4 components
    630  */
    631 extern float __attribute__((overloadable)) round(float);
    632 FN_FUNC_FN(round)
    633 
    634 /**
    635  * Return the square root of a value.
    636  *
    637  * Supports 1,2,3,4 components
    638  */
    639 extern float __attribute__((overloadable)) sqrt(float);
    640 FN_FUNC_FN(sqrt)
    641 
    642 /**
    643  * Return (1 / sqrt(value)).
    644  *
    645  * Supports 1,2,3,4 components
    646  */
    647 _RS_RUNTIME float __attribute__((overloadable)) rsqrt(float v);
    648 FN_FUNC_FN(rsqrt)
    649 
    650 /**
    651  * Return the sine of a value specified in radians.
    652  *
    653  * @param v The incoming value in radians
    654  * Supports 1,2,3,4 components
    655  */
    656 extern float __attribute__((overloadable)) sin(float v);
    657 FN_FUNC_FN(sin)
    658 
    659 /**
    660  * Return the sine and cosine of a value.
    661  *
    662  * @return sine
    663  * @param v The incoming value in radians
    664  * @param *cosptr cosptr[0] will be set to the cosine value.
    665  *
    666  * Supports 1,2,3,4 components
    667  */
    668 _RS_RUNTIME float __attribute__((overloadable)) sincos(float v, float *cosptr);
    669 FN_FUNC_FN_PFN(sincos);
    670 
    671 /**
    672  * Return the hyperbolic sine of a value specified in radians.
    673  *
    674  * Supports 1,2,3,4 components
    675  */
    676 extern float __attribute__((overloadable)) sinh(float);
    677 FN_FUNC_FN(sinh)
    678 
    679 /**
    680  * Return the sin(v * PI).
    681  *
    682  * Supports 1,2,3,4 components
    683  */
    684 _RS_RUNTIME float __attribute__((overloadable)) sinpi(float v);
    685 FN_FUNC_FN(sinpi)
    686 
    687 /**
    688  * Return the tangent of a value.
    689  *
    690  * Supports 1,2,3,4 components
    691  * @param v The incoming value in radians
    692  */
    693 extern float __attribute__((overloadable)) tan(float v);
    694 FN_FUNC_FN(tan)
    695 
    696 /**
    697  * Return the hyperbolic tangent of a value.
    698  *
    699  * Supports 1,2,3,4 components
    700  * @param v The incoming value in radians
    701  */
    702 extern float __attribute__((overloadable)) tanh(float);
    703 FN_FUNC_FN(tanh)
    704 
    705 /**
    706  * Return tan(v * PI)
    707  *
    708  * Supports 1,2,3,4 components
    709  */
    710 _RS_RUNTIME float __attribute__((overloadable)) tanpi(float v);
    711 FN_FUNC_FN(tanpi)
    712 
    713 /**
    714  * Compute the gamma function of a value.
    715  *
    716  * Supports 1,2,3,4 components
    717  */
    718 extern float __attribute__((overloadable)) tgamma(float);
    719 FN_FUNC_FN(tgamma)
    720 
    721 /**
    722  * Round to integral using truncation.
    723  *
    724  * Supports 1,2,3,4 components
    725  */
    726 extern float __attribute__((overloadable)) trunc(float);
    727 FN_FUNC_FN(trunc)
    728 
    729 
    730 #define XN_FUNC_YN(typeout, fnc, typein)                                \
    731 extern typeout __attribute__((overloadable)) fnc(typein);               \
    732 _RS_RUNTIME typeout##2 __attribute__((overloadable)) fnc(typein##2 v);  \
    733 _RS_RUNTIME typeout##3 __attribute__((overloadable)) fnc(typein##3 v);  \
    734 _RS_RUNTIME typeout##4 __attribute__((overloadable)) fnc(typein##4 v);
    735 
    736 #define UIN_FUNC_IN(fnc)          \
    737 XN_FUNC_YN(uchar, fnc, char)      \
    738 XN_FUNC_YN(ushort, fnc, short)    \
    739 XN_FUNC_YN(uint, fnc, int)
    740 
    741 #define IN_FUNC_IN(fnc)           \
    742 XN_FUNC_YN(uchar, fnc, uchar)     \
    743 XN_FUNC_YN(char, fnc, char)       \
    744 XN_FUNC_YN(ushort, fnc, ushort)   \
    745 XN_FUNC_YN(short, fnc, short)     \
    746 XN_FUNC_YN(uint, fnc, uint)       \
    747 XN_FUNC_YN(int, fnc, int)
    748 
    749 
    750 #define XN_FUNC_XN_XN_BODY(type, fnc, body)         \
    751 _RS_RUNTIME type __attribute__((overloadable))      \
    752         fnc(type v1, type v2);                      \
    753 _RS_RUNTIME type##2 __attribute__((overloadable))   \
    754         fnc(type##2 v1, type##2 v2);                \
    755 _RS_RUNTIME type##3 __attribute__((overloadable))   \
    756         fnc(type##3 v1, type##3 v2);                \
    757 _RS_RUNTIME type##4 __attribute__((overloadable))   \
    758         fnc(type##4 v1, type##4 v2);
    759 
    760 #define IN_FUNC_IN_IN_BODY(fnc, body)   \
    761 XN_FUNC_XN_XN_BODY(uchar, fnc, body)    \
    762 XN_FUNC_XN_XN_BODY(char, fnc, body)     \
    763 XN_FUNC_XN_XN_BODY(ushort, fnc, body)   \
    764 XN_FUNC_XN_XN_BODY(short, fnc, body)    \
    765 XN_FUNC_XN_XN_BODY(uint, fnc, body)     \
    766 XN_FUNC_XN_XN_BODY(int, fnc, body)      \
    767 XN_FUNC_XN_XN_BODY(float, fnc, body)
    768 
    769 /**
    770  * Return the absolute value of a value.
    771  *
    772  * Supports 1,2,3,4 components of char, short, int.
    773  */
    774 UIN_FUNC_IN(abs)
    775 
    776 /**
    777  * Return the number of leading 0-bits in a value.
    778  *
    779  * Supports 1,2,3,4 components of uchar, char, ushort, short, uint, int.
    780  */
    781 IN_FUNC_IN(clz)
    782 
    783 /**
    784  * Return the minimum of two values.
    785  *
    786  * Supports 1,2,3,4 components of uchar, char, ushort, short, uint, int, float.
    787  */
    788 IN_FUNC_IN_IN_BODY(min, (v1 < v2 ? v1 : v2))
    789 FN_FUNC_FN_F(min)
    790 
    791 /**
    792  * Return the maximum of two values.
    793  *
    794  * Supports 1,2,3,4 components of uchar, char, ushort, short, uint, int, float.
    795  */
    796 IN_FUNC_IN_IN_BODY(max, (v1 > v2 ? v1 : v2))
    797 FN_FUNC_FN_F(max)
    798 
    799 /**
    800  *  Clamp a value to a specified high and low bound.
    801  *
    802  * @param amount value to be clamped.  Supports 1,2,3,4 components
    803  * @param low Lower bound, must be scalar or matching vector.
    804  * @param high High bound, must match type of low
    805  */
    806 _RS_RUNTIME float __attribute__((overloadable)) clamp(float amount, float low, float high);
    807 FN_FUNC_FN_FN_FN(clamp)
    808 FN_FUNC_FN_F_F(clamp)
    809 
    810 /**
    811  * Convert from radians to degrees.
    812  *
    813  * Supports 1,2,3,4 components
    814  */
    815 _RS_RUNTIME float __attribute__((overloadable)) degrees(float radians);
    816 FN_FUNC_FN(degrees)
    817 
    818 /**
    819  * return start + ((stop - start) * amount);
    820  *
    821  * Supports 1,2,3,4 components
    822  */
    823 _RS_RUNTIME float __attribute__((overloadable)) mix(float start, float stop, float amount);
    824 FN_FUNC_FN_FN_FN(mix)
    825 FN_FUNC_FN_FN_F(mix)
    826 
    827 /**
    828  * Convert from degrees to radians.
    829  *
    830  * Supports 1,2,3,4 components
    831  */
    832 _RS_RUNTIME float __attribute__((overloadable)) radians(float degrees);
    833 FN_FUNC_FN(radians)
    834 
    835 /**
    836  * if (v < edge)
    837  *     return 0.f;
    838  * else
    839  *     return 1.f;
    840  *
    841  * Supports 1,2,3,4 components
    842  */
    843 _RS_RUNTIME float __attribute__((overloadable)) step(float edge, float v);
    844 FN_FUNC_FN_FN(step)
    845 FN_FUNC_FN_F(step)
    846 
    847 // not implemented
    848 extern float __attribute__((overloadable)) smoothstep(float, float, float);
    849 extern float2 __attribute__((overloadable)) smoothstep(float2, float2, float2);
    850 extern float3 __attribute__((overloadable)) smoothstep(float3, float3, float3);
    851 extern float4 __attribute__((overloadable)) smoothstep(float4, float4, float4);
    852 extern float2 __attribute__((overloadable)) smoothstep(float, float, float2);
    853 extern float3 __attribute__((overloadable)) smoothstep(float, float, float3);
    854 extern float4 __attribute__((overloadable)) smoothstep(float, float, float4);
    855 
    856 /**
    857  * Return the sign of a value.
    858  *
    859  * if (v < 0) return -1.f;
    860  * else if (v > 0) return 1.f;
    861  * else return 0.f;
    862  *
    863  * Supports 1,2,3,4 components
    864  */
    865 _RS_RUNTIME float __attribute__((overloadable)) sign(float v);
    866 FN_FUNC_FN(sign)
    867 
    868 /**
    869  * Compute the cross product of two vectors.
    870  *
    871  * Supports 3,4 components
    872  */
    873 _RS_RUNTIME float3 __attribute__((overloadable)) cross(float3 lhs, float3 rhs);
    874 _RS_RUNTIME float4 __attribute__((overloadable)) cross(float4 lhs, float4 rhs);
    875 
    876 /**
    877  * Compute the dot product of two vectors.
    878  *
    879  * Supports 1,2,3,4 components
    880  */
    881 _RS_RUNTIME float __attribute__((overloadable)) dot(float lhs, float rhs);
    882 F_FUNC_FN_FN(dot)
    883 
    884 /**
    885  * Compute the length of a vector.
    886  *
    887  * Supports 1,2,3,4 components
    888  */
    889 _RS_RUNTIME float __attribute__((overloadable)) length(float v);
    890 F_FUNC_FN(length)
    891 
    892 /**
    893  * Compute the distance between two points.
    894  *
    895  * Supports 1,2,3,4 components
    896  */
    897 _RS_RUNTIME float __attribute__((overloadable)) distance(float lhs, float rhs);
    898 F_FUNC_FN_FN(distance)
    899 
    900 /**
    901  * Normalize a vector.
    902  *
    903  * Supports 1,2,3,4 components
    904  */
    905 _RS_RUNTIME float __attribute__((overloadable)) normalize(float v);
    906 FN_FUNC_FN(normalize)
    907 
    908 
    909 // New approx API functions
    910 #if (defined(RS_VERSION) && (RS_VERSION >= 17))
    911 
    912 /**
    913  * Return the approximate reciprocal of a value.
    914  *
    915  * Supports 1,2,3,4 components
    916  */
    917 _RS_RUNTIME float __attribute__((overloadable)) half_recip(float);
    918 FN_FUNC_FN(half_recip)
    919 
    920 /**
    921  * Return the approximate square root of a value.
    922  *
    923  * Supports 1,2,3,4 components
    924  */
    925 _RS_RUNTIME float __attribute__((overloadable)) half_sqrt(float);
    926 FN_FUNC_FN(half_sqrt)
    927 
    928 /**
    929  * Return the approximate value of (1 / sqrt(value)).
    930  *
    931  * Supports 1,2,3,4 components
    932  */
    933 _RS_RUNTIME float __attribute__((overloadable)) half_rsqrt(float v);
    934 FN_FUNC_FN(half_rsqrt)
    935 
    936 /**
    937  * Compute the approximate length of a vector.
    938  *
    939  * Supports 1,2,3,4 components
    940  */
    941 _RS_RUNTIME float __attribute__((overloadable)) fast_length(float v);
    942 F_FUNC_FN(fast_length)
    943 
    944 /**
    945  * Compute the approximate distance between two points.
    946  *
    947  * Supports 1,2,3,4 components
    948  */
    949 _RS_RUNTIME float __attribute__((overloadable)) fast_distance(float lhs, float rhs);
    950 F_FUNC_FN_FN(fast_distance)
    951 
    952 /**
    953  * Approximately normalize a vector.
    954  *
    955  * Supports 1,2,3,4 components
    956  */
    957 _RS_RUNTIME float __attribute__((overloadable)) fast_normalize(float v);
    958 F_FUNC_FN(fast_normalize)
    959 
    960 #endif  // (defined(RS_VERSION) && (RS_VERSION >= 17))
    961 
    962 
    963 #undef CVT_FUNC
    964 #undef CVT_FUNC_2
    965 #undef FN_FUNC_FN
    966 #undef F_FUNC_FN
    967 #undef IN_FUNC_FN
    968 #undef FN_FUNC_FN_FN
    969 #undef F_FUNC_FN_FN
    970 #undef FN_FUNC_FN_F
    971 #undef FN_FUNC_FN_IN
    972 #undef FN_FUNC_FN_I
    973 #undef FN_FUNC_FN_PFN
    974 #undef FN_FUNC_FN_PIN
    975 #undef FN_FUNC_FN_FN_FN
    976 #undef FN_FUNC_FN_FN_F
    977 #undef FN_FUNC_FN_F_F
    978 #undef FN_FUNC_FN_FN_PIN
    979 #undef XN_FUNC_YN
    980 #undef UIN_FUNC_IN
    981 #undef IN_FUNC_IN
    982 #undef XN_FUNC_XN_XN_BODY
    983 #undef IN_FUNC_IN_IN_BODY
    984 
    985 #endif
    986