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 44CVT_FUNC(char) 45CVT_FUNC(uchar) 46CVT_FUNC(short) 47CVT_FUNC(ushort) 48CVT_FUNC(int) 49CVT_FUNC(uint) 50CVT_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 */ 119extern float __attribute__((overloadable)) acos(float); 120FN_FUNC_FN(acos) 121 122/** 123 * Return the inverse hyperbolic cosine. 124 * 125 * Supports float, float2, float3, float4 126 */ 127extern float __attribute__((overloadable)) acosh(float); 128FN_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); 136FN_FUNC_FN(acospi) 137 138/** 139 * Return the inverse sine. 140 * 141 * Supports float, float2, float3, float4 142 */ 143extern float __attribute__((overloadable)) asin(float); 144FN_FUNC_FN(asin) 145 146/** 147 * Return the inverse hyperbolic sine. 148 * 149 * Supports float, float2, float3, float4 150 */ 151extern float __attribute__((overloadable)) asinh(float); 152FN_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); 161FN_FUNC_FN(asinpi) 162 163/** 164 * Return the inverse tangent. 165 * 166 * Supports float, float2, float3, float4 167 */ 168extern float __attribute__((overloadable)) atan(float); 169FN_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 */ 180extern float __attribute__((overloadable)) atan2(float y, float x); 181FN_FUNC_FN_FN(atan2) 182 183/** 184 * Return the inverse hyperbolic tangent. 185 * 186 * Supports float, float2, float3, float4 187 */ 188extern float __attribute__((overloadable)) atanh(float); 189FN_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); 197FN_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); 209FN_FUNC_FN_FN(atan2pi) 210 211 212/** 213 * Return the cube root. 214 * 215 * Supports float, float2, float3, float4. 216 */ 217extern float __attribute__((overloadable)) cbrt(float); 218FN_FUNC_FN(cbrt) 219 220/** 221 * Return the smallest integer not less than a value. 222 * 223 * Supports float, float2, float3, float4. 224 */ 225extern float __attribute__((overloadable)) ceil(float); 226FN_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 */ 237extern float __attribute__((overloadable)) copysign(float x, float y); 238FN_FUNC_FN_FN(copysign) 239 240/** 241 * Return the cosine. 242 * 243 * Supports float, float2, float3, float4. 244 */ 245extern float __attribute__((overloadable)) cos(float); 246FN_FUNC_FN(cos) 247 248/** 249 * Return the hypebolic cosine. 250 * 251 * Supports float, float2, float3, float4. 252 */ 253extern float __attribute__((overloadable)) cosh(float); 254FN_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); 262FN_FUNC_FN(cospi) 263 264/** 265 * Return the complementary error function. 266 * 267 * Supports float, float2, float3, float4. 268 */ 269extern float __attribute__((overloadable)) erfc(float); 270FN_FUNC_FN(erfc) 271 272/** 273 * Return the error function. 274 * 275 * Supports float, float2, float3, float4. 276 */ 277extern float __attribute__((overloadable)) erf(float); 278FN_FUNC_FN(erf) 279 280/** 281 * Return e ^ value. 282 * 283 * Supports float, float2, float3, float4. 284 */ 285extern float __attribute__((overloadable)) exp(float); 286FN_FUNC_FN(exp) 287 288/** 289 * Return 2 ^ value. 290 * 291 * Supports float, float2, float3, float4. 292 */ 293extern float __attribute__((overloadable)) exp2(float); 294FN_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 */ 302extern float __attribute__((overloadable)) pow(float x, float y); 303FN_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); 311FN_FUNC_FN(exp10) 312 313/** 314 * Return (e ^ value) - 1. 315 * 316 * Supports float, float2, float3, float4. 317 */ 318extern float __attribute__((overloadable)) expm1(float); 319FN_FUNC_FN(expm1) 320 321/** 322 * Return the absolute value of a value. 323 * 324 * Supports float, float2, float3, float4. 325 */ 326extern float __attribute__((overloadable)) fabs(float); 327FN_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 */ 335extern float __attribute__((overloadable)) fdim(float, float); 336FN_FUNC_FN_FN(fdim) 337 338/** 339 * Return the smallest integer not greater than a value. 340 * 341 * Supports float, float2, float3, float4. 342 */ 343extern float __attribute__((overloadable)) floor(float); 344FN_FUNC_FN(floor) 345 346/** 347 * Return a*b + c. 348 * 349 * Supports float, float2, float3, float4. 350 */ 351extern float __attribute__((overloadable)) fma(float a, float b, float c); 352FN_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 */ 361extern float __attribute__((overloadable)) fmax(float x, float y); 362FN_FUNC_FN_FN(fmax); 363FN_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 */ 371extern float __attribute__((overloadable)) fmin(float x, float y); 372FN_FUNC_FN_FN(fmin); 373FN_FUNC_FN_F(fmin); 374 375/** 376 * Return the remainder from x / y 377 * 378 * Supports float, float2, float3, float4. 379 */ 380extern float __attribute__((overloadable)) fmod(float x, float y); 381FN_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); 391FN_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 */ 399extern float __attribute__((overloadable)) frexp(float v, int *iptr); 400FN_FUNC_FN_PIN(frexp) 401 402/** 403 * Return sqrt(x*x + y*y) 404 * 405 * Supports float, float2, float3, float4. 406 */ 407extern float __attribute__((overloadable)) hypot(float x, float y); 408FN_FUNC_FN_FN(hypot) 409 410/** 411 * Return the integer exponent of a value 412 * 413 * Supports 1,2,3,4 components 414 */ 415extern int __attribute__((overloadable)) ilogb(float); 416IN_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 */ 424extern float __attribute__((overloadable)) ldexp(float x, int y); 425FN_FUNC_FN_IN(ldexp) 426FN_FUNC_FN_I(ldexp) 427 428/** 429 * Return the log gamma 430 * 431 * Supports 1,2,3,4 components 432 */ 433extern float __attribute__((overloadable)) lgamma(float); 434FN_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 */ 442extern float __attribute__((overloadable)) lgamma(float x, int* y); 443FN_FUNC_FN_PIN(lgamma) 444 445/** 446 * Return the natural logarithm 447 * 448 * Supports 1,2,3,4 components 449 */ 450extern float __attribute__((overloadable)) log(float); 451FN_FUNC_FN(log) 452 453/** 454 * Return the base 10 logarithm 455 * 456 * Supports 1,2,3,4 components 457 */ 458extern float __attribute__((overloadable)) log10(float); 459FN_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); 467FN_FUNC_FN(log2) 468 469/** 470 * Return the natural logarithm of (v + 1.0f) 471 * 472 * Supports 1,2,3,4 components 473 */ 474extern float __attribute__((overloadable)) log1p(float v); 475FN_FUNC_FN(log1p) 476 477/** 478 * Compute the exponent of the value. 479 * 480 * Supports 1,2,3,4 components 481 */ 482extern float __attribute__((overloadable)) logb(float); 483FN_FUNC_FN(logb) 484 485/** 486 * Compute (a * b) + c 487 * 488 * Supports 1,2,3,4 components 489 */ 490extern float __attribute__((overloadable)) mad(float a, float b, float c); 491FN_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 */ 501extern float __attribute__((overloadable)) modf(float x, float *iret); 502FN_FUNC_FN_PFN(modf); 503 504extern 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 */ 511extern float __attribute__((overloadable)) nextafter(float x, float y); 512FN_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); 520FN_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); 529FN_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 */ 536extern float __attribute__((overloadable)) remainder(float x, float y); 537FN_FUNC_FN_FN(remainder) 538 539// document once we know the precision of bionic 540extern float __attribute__((overloadable)) remquo(float, float, int *); 541FN_FUNC_FN_FN_PIN(remquo) 542 543/** 544 * Round to the nearest integral value. 545 * 546 * Supports 1,2,3,4 components 547 */ 548extern float __attribute__((overloadable)) rint(float); 549FN_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); 557FN_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 */ 564extern float __attribute__((overloadable)) round(float); 565FN_FUNC_FN(round) 566 567/** 568 * Return the square root of a value. 569 * 570 * Supports 1,2,3,4 components 571 */ 572extern float __attribute__((overloadable)) sqrt(float); 573FN_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); 582FN_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 */ 590extern float __attribute__((overloadable)) sin(float v); 591FN_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); 603FN_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 */ 610extern float __attribute__((overloadable)) sinh(float); 611FN_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); 619FN_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 */ 627extern float __attribute__((overloadable)) tan(float v); 628FN_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 */ 636extern float __attribute__((overloadable)) tanh(float); 637FN_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); 645FN_FUNC_FN(tanpi) 646 647/** 648 * Compute the gamma function of a value. 649 * 650 * Supports 1,2,3,4 components 651 */ 652extern float __attribute__((overloadable)) tgamma(float); 653FN_FUNC_FN(tgamma) 654 655/** 656 * Round to integral using truncation. 657 * 658 * Supports 1,2,3,4 components 659 */ 660extern float __attribute__((overloadable)) trunc(float); 661FN_FUNC_FN(trunc) 662 663 664#define XN_FUNC_YN(typeout, fnc, typein) \ 665extern 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) \ 671XN_FUNC_YN(uchar, fnc, char) \ 672XN_FUNC_YN(ushort, fnc, short) \ 673XN_FUNC_YN(uint, fnc, int) 674 675#define IN_FUNC_IN(fnc) \ 676XN_FUNC_YN(uchar, fnc, uchar) \ 677XN_FUNC_YN(char, fnc, char) \ 678XN_FUNC_YN(ushort, fnc, ushort) \ 679XN_FUNC_YN(short, fnc, short) \ 680XN_FUNC_YN(uint, fnc, uint) \ 681XN_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) \ 695XN_FUNC_XN_XN_BODY(uchar, fnc, body) \ 696XN_FUNC_XN_XN_BODY(char, fnc, body) \ 697XN_FUNC_XN_XN_BODY(ushort, fnc, body) \ 698XN_FUNC_XN_XN_BODY(short, fnc, body) \ 699XN_FUNC_XN_XN_BODY(uint, fnc, body) \ 700XN_FUNC_XN_XN_BODY(int, fnc, body) \ 701XN_FUNC_XN_XN_BODY(float, fnc, body) 702 703UIN_FUNC_IN(abs) 704IN_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 */ 711IN_FUNC_IN_IN_BODY(min, (v1 < v2 ? v1 : v2)) 712FN_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 */ 719IN_FUNC_IN_IN_BODY(max, (v1 > v2 ? v1 : v2)) 720FN_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); 743FN_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); 764FN_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 783extern float __attribute__((overloadable)) smoothstep(float, float, float); 784extern float2 __attribute__((overloadable)) smoothstep(float2, float2, float2); 785extern float3 __attribute__((overloadable)) smoothstep(float3, float3, float3); 786extern float4 __attribute__((overloadable)) smoothstep(float4, float4, float4); 787extern float2 __attribute__((overloadable)) smoothstep(float, float, float2); 788extern float3 __attribute__((overloadable)) smoothstep(float, float, float3); 789extern 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); 799FN_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