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