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