1 #ifndef __RS_CL_RSH__ 2 #define __RS_CL_RSH__ 3 4 #define _RS_RUNTIME extern 5 6 // Conversions 7 #define CVT_FUNC_2(typeout, typein) \ 8 _RS_RUNTIME typeout##2 __attribute__((overloadable)) \ 9 convert_##typeout##2(typein##2 v); \ 10 _RS_RUNTIME typeout##3 __attribute__((overloadable)) \ 11 convert_##typeout##3(typein##3 v); \ 12 _RS_RUNTIME typeout##4 __attribute__((overloadable)) \ 13 convert_##typeout##4(typein##4 v); 14 15 16 #define CVT_FUNC(type) CVT_FUNC_2(type, uchar) \ 17 CVT_FUNC_2(type, char) \ 18 CVT_FUNC_2(type, ushort) \ 19 CVT_FUNC_2(type, short) \ 20 CVT_FUNC_2(type, uint) \ 21 CVT_FUNC_2(type, int) \ 22 CVT_FUNC_2(type, float) 23 24 CVT_FUNC(char) 25 CVT_FUNC(uchar) 26 CVT_FUNC(short) 27 CVT_FUNC(ushort) 28 CVT_FUNC(int) 29 CVT_FUNC(uint) 30 CVT_FUNC(float) 31 32 // Float ops, 6.11.2 33 34 #define FN_FUNC_FN(fnc) \ 35 _RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v); \ 36 _RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v); \ 37 _RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v); 38 39 #define IN_FUNC_FN(fnc) \ 40 _RS_RUNTIME int2 __attribute__((overloadable)) fnc(float2 v); \ 41 _RS_RUNTIME int3 __attribute__((overloadable)) fnc(float3 v); \ 42 _RS_RUNTIME int4 __attribute__((overloadable)) fnc(float4 v); 43 44 #define FN_FUNC_FN_FN(fnc) \ 45 _RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, float2 v2); \ 46 _RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, float3 v2); \ 47 _RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, float4 v2); 48 49 #define FN_FUNC_FN_F(fnc) \ 50 _RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, float v2); \ 51 _RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, float v2); \ 52 _RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, float v2); 53 54 #define FN_FUNC_FN_IN(fnc) \ 55 _RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, int2 v2); \ 56 _RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, int3 v2); \ 57 _RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, int4 v2); \ 58 59 #define FN_FUNC_FN_I(fnc) \ 60 _RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, int v2); \ 61 _RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, int v2); \ 62 _RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, int v2); 63 64 #define FN_FUNC_FN_PFN(fnc) \ 65 _RS_RUNTIME float2 __attribute__((overloadable)) \ 66 fnc(float2 v1, float2 *v2); \ 67 _RS_RUNTIME float3 __attribute__((overloadable)) \ 68 fnc(float3 v1, float3 *v2); \ 69 _RS_RUNTIME float4 __attribute__((overloadable)) \ 70 fnc(float4 v1, float4 *v2); 71 72 #define FN_FUNC_FN_PIN(fnc) \ 73 _RS_RUNTIME float2 __attribute__((overloadable)) fnc(float2 v1, int2 *v2); \ 74 _RS_RUNTIME float3 __attribute__((overloadable)) fnc(float3 v1, int3 *v2); \ 75 _RS_RUNTIME float4 __attribute__((overloadable)) fnc(float4 v1, int4 *v2); 76 77 #define FN_FUNC_FN_FN_FN(fnc) \ 78 _RS_RUNTIME float2 __attribute__((overloadable)) \ 79 fnc(float2 v1, float2 v2, float2 v3); \ 80 _RS_RUNTIME float3 __attribute__((overloadable)) \ 81 fnc(float3 v1, float3 v2, float3 v3); \ 82 _RS_RUNTIME float4 __attribute__((overloadable)) \ 83 fnc(float4 v1, float4 v2, float4 v3); 84 85 #define FN_FUNC_FN_FN_PIN(fnc) \ 86 _RS_RUNTIME float2 __attribute__((overloadable)) \ 87 fnc(float2 v1, float2 v2, int2 *v3); \ 88 _RS_RUNTIME float3 __attribute__((overloadable)) \ 89 fnc(float3 v1, float3 v2, int3 *v3); \ 90 _RS_RUNTIME float4 __attribute__((overloadable)) \ 91 fnc(float4 v1, float4 v2, int4 *v3); 92 93 94 extern float __attribute__((overloadable)) acos(float); 95 FN_FUNC_FN(acos) 96 97 extern float __attribute__((overloadable)) acosh(float); 98 FN_FUNC_FN(acosh) 99 100 _RS_RUNTIME float __attribute__((overloadable)) acospi(float v); 101 102 103 FN_FUNC_FN(acospi) 104 105 extern float __attribute__((overloadable)) asin(float); 106 FN_FUNC_FN(asin) 107 108 extern float __attribute__((overloadable)) asinh(float); 109 FN_FUNC_FN(asinh) 110 111 112 _RS_RUNTIME float __attribute__((overloadable)) asinpi(float v); 113 FN_FUNC_FN(asinpi) 114 115 extern float __attribute__((overloadable)) atan(float); 116 FN_FUNC_FN(atan) 117 118 extern float __attribute__((overloadable)) atan2(float, float); 119 FN_FUNC_FN_FN(atan2) 120 121 extern float __attribute__((overloadable)) atanh(float); 122 FN_FUNC_FN(atanh) 123 124 125 _RS_RUNTIME float __attribute__((overloadable)) atanpi(float v); 126 FN_FUNC_FN(atanpi) 127 128 129 _RS_RUNTIME float __attribute__((overloadable)) atan2pi(float y, float x); 130 FN_FUNC_FN_FN(atan2pi) 131 132 extern float __attribute__((overloadable)) cbrt(float); 133 FN_FUNC_FN(cbrt) 134 135 extern float __attribute__((overloadable)) ceil(float); 136 FN_FUNC_FN(ceil) 137 138 extern float __attribute__((overloadable)) copysign(float, float); 139 FN_FUNC_FN_FN(copysign) 140 141 extern float __attribute__((overloadable)) cos(float); 142 FN_FUNC_FN(cos) 143 144 extern float __attribute__((overloadable)) cosh(float); 145 FN_FUNC_FN(cosh) 146 147 148 _RS_RUNTIME float __attribute__((overloadable)) cospi(float v); 149 FN_FUNC_FN(cospi) 150 151 extern float __attribute__((overloadable)) erfc(float); 152 FN_FUNC_FN(erfc) 153 154 extern float __attribute__((overloadable)) erf(float); 155 FN_FUNC_FN(erf) 156 157 extern float __attribute__((overloadable)) exp(float); 158 FN_FUNC_FN(exp) 159 160 extern float __attribute__((overloadable)) exp2(float); 161 FN_FUNC_FN(exp2) 162 163 extern float __attribute__((overloadable)) pow(float, float); 164 165 _RS_RUNTIME float __attribute__((overloadable)) exp10(float v); 166 FN_FUNC_FN(exp10) 167 168 extern float __attribute__((overloadable)) expm1(float); 169 FN_FUNC_FN(expm1) 170 171 extern float __attribute__((overloadable)) fabs(float); 172 FN_FUNC_FN(fabs) 173 174 extern float __attribute__((overloadable)) fdim(float, float); 175 FN_FUNC_FN_FN(fdim) 176 177 extern float __attribute__((overloadable)) floor(float); 178 FN_FUNC_FN(floor) 179 180 extern float __attribute__((overloadable)) fma(float, float, float); 181 FN_FUNC_FN_FN_FN(fma) 182 183 extern float __attribute__((overloadable)) fmax(float, float); 184 FN_FUNC_FN_FN(fmax); 185 FN_FUNC_FN_F(fmax); 186 187 extern float __attribute__((overloadable)) fmin(float, float); 188 FN_FUNC_FN_FN(fmin); 189 FN_FUNC_FN_F(fmin); 190 191 extern float __attribute__((overloadable)) fmod(float, float); 192 FN_FUNC_FN_FN(fmod) 193 194 195 _RS_RUNTIME float __attribute__((overloadable)) fract(float v, float *iptr); 196 FN_FUNC_FN_PFN(fract) 197 198 extern float __attribute__((overloadable)) frexp(float, int *); 199 FN_FUNC_FN_PIN(frexp) 200 201 extern float __attribute__((overloadable)) hypot(float, float); 202 FN_FUNC_FN_FN(hypot) 203 204 extern int __attribute__((overloadable)) ilogb(float); 205 IN_FUNC_FN(ilogb) 206 207 extern float __attribute__((overloadable)) ldexp(float, int); 208 FN_FUNC_FN_IN(ldexp) 209 FN_FUNC_FN_I(ldexp) 210 211 extern float __attribute__((overloadable)) lgamma(float); 212 FN_FUNC_FN(lgamma) 213 extern float __attribute__((overloadable)) lgamma(float, int*); 214 FN_FUNC_FN_PIN(lgamma) 215 216 extern float __attribute__((overloadable)) log(float); 217 FN_FUNC_FN(log) 218 219 220 extern float __attribute__((overloadable)) log10(float); 221 FN_FUNC_FN(log10) 222 223 224 _RS_RUNTIME float __attribute__((overloadable)) log2(float v); 225 FN_FUNC_FN(log2) 226 227 extern float __attribute__((overloadable)) log1p(float); 228 FN_FUNC_FN(log1p) 229 230 extern float __attribute__((overloadable)) logb(float); 231 FN_FUNC_FN(logb) 232 233 extern float __attribute__((overloadable)) mad(float, float, float); 234 FN_FUNC_FN_FN_FN(mad) 235 236 extern float __attribute__((overloadable)) modf(float, float *); 237 FN_FUNC_FN_PFN(modf); 238 239 //extern float __attribute__((overloadable)) nan(uint); 240 241 extern float __attribute__((overloadable)) nextafter(float, float); 242 FN_FUNC_FN_FN(nextafter) 243 244 FN_FUNC_FN_FN(pow) 245 246 _RS_RUNTIME float __attribute__((overloadable)) pown(float v, int p); 247 _RS_RUNTIME float2 __attribute__((overloadable)) pown(float2 v, int2 p); 248 _RS_RUNTIME float3 __attribute__((overloadable)) pown(float3 v, int3 p); 249 _RS_RUNTIME float4 __attribute__((overloadable)) pown(float4 v, int4 p); 250 251 _RS_RUNTIME float __attribute__((overloadable)) powr(float v, float p); 252 _RS_RUNTIME float2 __attribute__((overloadable)) powr(float2 v, float2 p); 253 _RS_RUNTIME float3 __attribute__((overloadable)) powr(float3 v, float3 p); 254 _RS_RUNTIME float4 __attribute__((overloadable)) powr(float4 v, float4 p); 255 256 extern float __attribute__((overloadable)) remainder(float, float); 257 FN_FUNC_FN_FN(remainder) 258 259 extern float __attribute__((overloadable)) remquo(float, float, int *); 260 FN_FUNC_FN_FN_PIN(remquo) 261 262 extern float __attribute__((overloadable)) rint(float); 263 FN_FUNC_FN(rint) 264 265 266 _RS_RUNTIME float __attribute__((overloadable)) rootn(float v, int r); 267 _RS_RUNTIME float2 __attribute__((overloadable)) rootn(float2 v, int2 r); 268 _RS_RUNTIME float3 __attribute__((overloadable)) rootn(float3 v, int3 r); 269 _RS_RUNTIME float4 __attribute__((overloadable)) rootn(float4 v, int4 r); 270 271 272 extern float __attribute__((overloadable)) round(float); 273 FN_FUNC_FN(round) 274 275 276 extern float __attribute__((overloadable)) sqrt(float); 277 _RS_RUNTIME float __attribute__((overloadable)) rsqrt(float v); 278 FN_FUNC_FN(rsqrt) 279 280 extern float __attribute__((overloadable)) sin(float); 281 FN_FUNC_FN(sin) 282 283 _RS_RUNTIME float __attribute__((overloadable)) sincos(float v, float *cosptr); 284 _RS_RUNTIME float2 __attribute__((overloadable)) sincos(float2 v, float2 *cosptr); 285 _RS_RUNTIME float3 __attribute__((overloadable)) sincos(float3 v, float3 *cosptr); 286 _RS_RUNTIME float4 __attribute__((overloadable)) sincos(float4 v, float4 *cosptr); 287 288 extern float __attribute__((overloadable)) sinh(float); 289 FN_FUNC_FN(sinh) 290 291 _RS_RUNTIME float __attribute__((overloadable)) sinpi(float v); 292 FN_FUNC_FN(sinpi) 293 294 FN_FUNC_FN(sqrt) 295 296 extern float __attribute__((overloadable)) tan(float); 297 FN_FUNC_FN(tan) 298 299 extern float __attribute__((overloadable)) tanh(float); 300 FN_FUNC_FN(tanh) 301 302 _RS_RUNTIME float __attribute__((overloadable)) tanpi(float v); 303 FN_FUNC_FN(tanpi) 304 305 306 extern float __attribute__((overloadable)) tgamma(float); 307 FN_FUNC_FN(tgamma) 308 309 extern float __attribute__((overloadable)) trunc(float); 310 FN_FUNC_FN(trunc) 311 312 // Int ops (partial), 6.11.3 313 314 #define XN_FUNC_YN(typeout, fnc, typein) \ 315 extern typeout __attribute__((overloadable)) fnc(typein); \ 316 _RS_RUNTIME typeout##2 __attribute__((overloadable)) fnc(typein##2 v); \ 317 _RS_RUNTIME typeout##3 __attribute__((overloadable)) fnc(typein##3 v); \ 318 _RS_RUNTIME typeout##4 __attribute__((overloadable)) fnc(typein##4 v); 319 320 #define UIN_FUNC_IN(fnc) \ 321 XN_FUNC_YN(uchar, fnc, char) \ 322 XN_FUNC_YN(ushort, fnc, short) \ 323 XN_FUNC_YN(uint, fnc, int) 324 325 #define IN_FUNC_IN(fnc) \ 326 XN_FUNC_YN(uchar, fnc, uchar) \ 327 XN_FUNC_YN(char, fnc, char) \ 328 XN_FUNC_YN(ushort, fnc, ushort) \ 329 XN_FUNC_YN(short, fnc, short) \ 330 XN_FUNC_YN(uint, fnc, uint) \ 331 XN_FUNC_YN(int, fnc, int) 332 333 334 #define XN_FUNC_XN_XN_BODY(type, fnc, body) \ 335 _RS_RUNTIME type __attribute__((overloadable)) \ 336 fnc(type v1, type v2); \ 337 _RS_RUNTIME type##2 __attribute__((overloadable)) \ 338 fnc(type##2 v1, type##2 v2); \ 339 _RS_RUNTIME type##3 __attribute__((overloadable)) \ 340 fnc(type##3 v1, type##3 v2); \ 341 _RS_RUNTIME type##4 __attribute__((overloadable)) \ 342 fnc(type##4 v1, type##4 v2); 343 344 #define IN_FUNC_IN_IN_BODY(fnc, body) \ 345 XN_FUNC_XN_XN_BODY(uchar, fnc, body) \ 346 XN_FUNC_XN_XN_BODY(char, fnc, body) \ 347 XN_FUNC_XN_XN_BODY(ushort, fnc, body) \ 348 XN_FUNC_XN_XN_BODY(short, fnc, body) \ 349 XN_FUNC_XN_XN_BODY(uint, fnc, body) \ 350 XN_FUNC_XN_XN_BODY(int, fnc, body) \ 351 XN_FUNC_XN_XN_BODY(float, fnc, body) 352 353 UIN_FUNC_IN(abs) 354 IN_FUNC_IN(clz) 355 356 IN_FUNC_IN_IN_BODY(min, (v1 < v2 ? v1 : v2)) 357 FN_FUNC_FN_F(min) 358 359 IN_FUNC_IN_IN_BODY(max, (v1 > v2 ? v1 : v2)) 360 FN_FUNC_FN_F(max) 361 362 // 6.11.4 363 364 _RS_RUNTIME float __attribute__((overloadable)) clamp(float amount, float low, float high); 365 _RS_RUNTIME float2 __attribute__((overloadable)) clamp(float2 amount, float2 low, float2 high); 366 _RS_RUNTIME float3 __attribute__((overloadable)) clamp(float3 amount, float3 low, float3 high); 367 _RS_RUNTIME float4 __attribute__((overloadable)) clamp(float4 amount, float4 low, float4 high); 368 _RS_RUNTIME float2 __attribute__((overloadable)) clamp(float2 amount, float low, float high); 369 _RS_RUNTIME float3 __attribute__((overloadable)) clamp(float3 amount, float low, float high); 370 _RS_RUNTIME float4 __attribute__((overloadable)) clamp(float4 amount, float low, float high); 371 372 _RS_RUNTIME float __attribute__((overloadable)) degrees(float radians); 373 FN_FUNC_FN(degrees) 374 375 _RS_RUNTIME float __attribute__((overloadable)) mix(float start, float stop, float amount); 376 _RS_RUNTIME float2 __attribute__((overloadable)) mix(float2 start, float2 stop, float2 amount); 377 _RS_RUNTIME float3 __attribute__((overloadable)) mix(float3 start, float3 stop, float3 amount); 378 _RS_RUNTIME float4 __attribute__((overloadable)) mix(float4 start, float4 stop, float4 amount); 379 _RS_RUNTIME float2 __attribute__((overloadable)) mix(float2 start, float2 stop, float amount); 380 _RS_RUNTIME float3 __attribute__((overloadable)) mix(float3 start, float3 stop, float amount); 381 _RS_RUNTIME float4 __attribute__((overloadable)) mix(float4 start, float4 stop, float amount); 382 383 _RS_RUNTIME float __attribute__((overloadable)) radians(float degrees); 384 FN_FUNC_FN(radians) 385 386 _RS_RUNTIME float __attribute__((overloadable)) step(float edge, float v); 387 _RS_RUNTIME float2 __attribute__((overloadable)) step(float2 edge, float2 v); 388 _RS_RUNTIME float3 __attribute__((overloadable)) step(float3 edge, float3 v); 389 _RS_RUNTIME float4 __attribute__((overloadable)) step(float4 edge, float4 v); 390 _RS_RUNTIME float2 __attribute__((overloadable)) step(float2 edge, float v); 391 _RS_RUNTIME float3 __attribute__((overloadable)) step(float3 edge, float v); 392 _RS_RUNTIME float4 __attribute__((overloadable)) step(float4 edge, float v); 393 394 extern float __attribute__((overloadable)) smoothstep(float, float, float); 395 extern float2 __attribute__((overloadable)) smoothstep(float2, float2, float2); 396 extern float3 __attribute__((overloadable)) smoothstep(float3, float3, float3); 397 extern float4 __attribute__((overloadable)) smoothstep(float4, float4, float4); 398 extern float2 __attribute__((overloadable)) smoothstep(float, float, float2); 399 extern float3 __attribute__((overloadable)) smoothstep(float, float, float3); 400 extern float4 __attribute__((overloadable)) smoothstep(float, float, float4); 401 402 _RS_RUNTIME float __attribute__((overloadable)) sign(float v); 403 FN_FUNC_FN(sign) 404 405 // 6.11.5 406 _RS_RUNTIME float3 __attribute__((overloadable)) cross(float3 lhs, float3 rhs); 407 408 _RS_RUNTIME float4 __attribute__((overloadable)) cross(float4 lhs, float4 rhs); 409 410 _RS_RUNTIME float __attribute__((overloadable)) dot(float lhs, float rhs); 411 _RS_RUNTIME float __attribute__((overloadable)) dot(float2 lhs, float2 rhs); 412 _RS_RUNTIME float __attribute__((overloadable)) dot(float3 lhs, float3 rhs); 413 _RS_RUNTIME float __attribute__((overloadable)) dot(float4 lhs, float4 rhs); 414 415 _RS_RUNTIME float __attribute__((overloadable)) length(float v); 416 _RS_RUNTIME float __attribute__((overloadable)) length(float2 v); 417 _RS_RUNTIME float __attribute__((overloadable)) length(float3 v); 418 _RS_RUNTIME float __attribute__((overloadable)) length(float4 v); 419 420 _RS_RUNTIME float __attribute__((overloadable)) distance(float lhs, float rhs); 421 _RS_RUNTIME float __attribute__((overloadable)) distance(float2 lhs, float2 rhs); 422 _RS_RUNTIME float __attribute__((overloadable)) distance(float3 lhs, float3 rhs); 423 _RS_RUNTIME float __attribute__((overloadable)) distance(float4 lhs, float4 rhs); 424 425 _RS_RUNTIME float __attribute__((overloadable)) normalize(float v); 426 _RS_RUNTIME float2 __attribute__((overloadable)) normalize(float2 v); 427 _RS_RUNTIME float3 __attribute__((overloadable)) normalize(float3 v); 428 _RS_RUNTIME float4 __attribute__((overloadable)) normalize(float4 v); 429 430 #undef CVT_FUNC 431 #undef CVT_FUNC_2 432 #undef FN_FUNC_FN 433 #undef IN_FUNC_FN 434 #undef FN_FUNC_FN_FN 435 #undef FN_FUNC_FN_F 436 #undef FN_FUNC_FN_IN 437 #undef FN_FUNC_FN_I 438 #undef FN_FUNC_FN_PFN 439 #undef FN_FUNC_FN_PIN 440 #undef FN_FUNC_FN_FN_FN 441 #undef FN_FUNC_FN_FN_PIN 442 #undef XN_FUNC_YN 443 #undef UIN_FUNC_IN 444 #undef IN_FUNC_IN 445 #undef XN_FUNC_XN_XN_BODY 446 #undef IN_FUNC_IN_IN_BODY 447 #undef _RS_RUNTIME 448 449 #endif 450