rs_cl.c revision f72e74660567181b79673f2a476a6957db2507e5
1be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet#include "rs_core.rsh" 2f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar#include "rs_f16_util.h" 35a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 45a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) convert_float2(int2 c); 55a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) convert_float3(int3 c); 65a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) convert_float4(int4 c); 75a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 85a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int2 __attribute__((overloadable)) convert_int2(float2 c); 95a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int3 __attribute__((overloadable)) convert_int3(float3 c); 105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int4 __attribute__((overloadable)) convert_int4(float4 c); 115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fmin(float v, float v2); 145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fmin(float2 v, float v2); 155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fmin(float3 v, float v2); 165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fmin(float4 v, float v2); 175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fmax(float v, float v2); 195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fmax(float2 v, float v2); 205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fmax(float3 v, float v2); 215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fmax(float4 v, float v2); 225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// Float ops, 6.11.2 245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN(fnc) \ 265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fnc(float2 v) { \ 275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; \ 285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fnc(float3 v) { \ 335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; \ 345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v.z); \ 375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fnc(float4 v) { \ 405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; \ 415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v.z); \ 445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v.w); \ 455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define IN_FUNC_FN(fnc) \ 495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int2 __attribute__((overloadable)) fnc(float2 v) { \ 505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int2 r; \ 515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int3 __attribute__((overloadable)) fnc(float3 v) { \ 565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int3 r; \ 575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v.z); \ 605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int4 __attribute__((overloadable)) fnc(float4 v) { \ 635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int4 r; \ 645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v.z); \ 675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v.w); \ 685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_FN(fnc) \ 725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fnc(float2 v1, float2 v2) { \ 735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; \ 745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fnc(float3 v1, float3 v2) { \ 795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; \ 805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z); \ 835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fnc(float4 v1, float4 v2) { \ 865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; \ 875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z); \ 905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, v2.w); \ 915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_F(fnc) \ 955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fnc(float2 v1, float v2) { \ 965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; \ 975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2); \ 985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2); \ 995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 1015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fnc(float3 v1, float v2) { \ 1025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; \ 1035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2); \ 1045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2); \ 1055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2); \ 1065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 1085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fnc(float4 v1, float v2) { \ 1095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; \ 1105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2); \ 1115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2); \ 1125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2); \ 1135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, v2); \ 1145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 1165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_IN(fnc) \ 1185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fnc(float2 v1, int2 v2) { \ 1195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; \ 1205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 1215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 1225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 1245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fnc(float3 v1, int3 v2) { \ 1255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; \ 1265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 1275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 1285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z); \ 1295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 1315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fnc(float4 v1, int4 v2) { \ 1325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; \ 1335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 1345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 1355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z); \ 1365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, v2.w); \ 1375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 1395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_I(fnc) \ 1415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fnc(float2 v1, int v2) { \ 1425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; \ 1435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2); \ 1445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2); \ 1455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 1475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fnc(float3 v1, int v2) { \ 1485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; \ 1495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2); \ 1505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2); \ 1515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2); \ 1525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 1545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fnc(float4 v1, int v2) { \ 1555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; \ 1565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2); \ 1575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2); \ 1585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2); \ 1595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, v2); \ 1605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 1625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_PFN(fnc) \ 1645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) \ 1655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(float2 v1, float2 *v2) { \ 1665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; \ 1675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float t[2]; \ 1685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, &t[0]); \ 1695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, &t[1]); \ 1705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->x = t[0]; \ 1715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->y = t[1]; \ 1725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 1745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) \ 1755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(float3 v1, float3 *v2) { \ 1765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; \ 1775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float t[3]; \ 1785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, &t[0]); \ 1795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, &t[1]); \ 1805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, &t[2]); \ 1815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->x = t[0]; \ 1825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->y = t[1]; \ 1835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->z = t[2]; \ 1845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 1865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) \ 1875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(float4 v1, float4 *v2) { \ 1885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; \ 1895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float t[4]; \ 1905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, &t[0]); \ 1915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, &t[1]); \ 1925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, &t[2]); \ 1935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, &t[3]); \ 1945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->x = t[0]; \ 1955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->y = t[1]; \ 1965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->z = t[2]; \ 1975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->w = t[3]; \ 1985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_PIN(fnc) \ 2025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fnc(float2 v1, int2 *v2) { \ 2035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; \ 2045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int t[2]; \ 2055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, &t[0]); \ 2065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, &t[1]); \ 2075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->x = t[0]; \ 2085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->y = t[1]; \ 2095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 2105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 2115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fnc(float3 v1, int3 *v2) { \ 2125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; \ 2135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int t[3]; \ 2145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, &t[0]); \ 2155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, &t[1]); \ 2165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, &t[2]); \ 2175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->x = t[0]; \ 2185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->y = t[1]; \ 2195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->z = t[2]; \ 2205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 2215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 2225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fnc(float4 v1, int4 *v2) { \ 2235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; \ 2245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int t[4]; \ 2255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, &t[0]); \ 2265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, &t[1]); \ 2275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, &t[2]); \ 2285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, &t[3]); \ 2295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->x = t[0]; \ 2305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->y = t[1]; \ 2315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->z = t[2]; \ 2325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->w = t[3]; \ 2335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 2345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_FN_FN(fnc) \ 2375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) \ 2385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(float2 v1, float2 v2, float2 v3) { \ 2395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; \ 2405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x, v3.x); \ 2415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y, v3.y); \ 2425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 2435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 2445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) \ 2455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(float3 v1, float3 v2, float3 v3) { \ 2465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; \ 2475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x, v3.x); \ 2485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y, v3.y); \ 2495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z, v3.z); \ 2505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 2515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 2525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) \ 2535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(float4 v1, float4 v2, float4 v3) { \ 2545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; \ 2555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x, v3.x); \ 2565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y, v3.y); \ 2575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z, v3.z); \ 2585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, v2.w, v3.w); \ 2595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 2605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_FN_PIN(fnc) \ 2635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) \ 2645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(float2 v1, float2 v2, int2 *v3) { \ 2655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; \ 2665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int t[2]; \ 2675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x, &t[0]); \ 2685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y, &t[1]); \ 2695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v3->x = t[0]; \ 2705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v3->y = t[1]; \ 2715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 2725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 2735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) \ 2745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(float3 v1, float3 v2, int3 *v3) { \ 2755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; \ 2765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int t[3]; \ 2775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x, &t[0]); \ 2785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y, &t[1]); \ 2795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z, &t[2]); \ 2805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v3->x = t[0]; \ 2815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v3->y = t[1]; \ 2825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v3->z = t[2]; \ 2835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 2845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 2855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) \ 2865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(float4 v1, float4 v2, int4 *v3) { \ 2875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; \ 2885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int t[4]; \ 2895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x, &t[0]); \ 2905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y, &t[1]); \ 2915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z, &t[2]); \ 2925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, v2.w, &t[3]); \ 2935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v3->x = t[0]; \ 2945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v3->y = t[1]; \ 2955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v3->z = t[2]; \ 2965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v3->w = t[3]; \ 2975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 2985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic const int iposinf = 0x7f800000; 3015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic const int ineginf = 0xff800000; 3025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic const float posinf() { 3045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float f = *((float*)&iposinf); 3055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return f; 3065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic const float neginf() { 3095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float f = *((float*)&ineginf); 3105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return f; 3115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic bool isinf(float f) { 3145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int i = *((int*)(void*)&f); 3155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (i == iposinf) || (i == ineginf); 3165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic bool isnan(float f) { 3195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int i = *((int*)(void*)&f); 3205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (((i & 0x7f800000) == 0x7f800000) && (i & 0x007fffff)); 3215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic bool isposzero(float f) { 3245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int i = *((int*)(void*)&f); 3255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (i == 0x00000000); 3265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic bool isnegzero(float f) { 3295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int i = *((int*)(void*)&f); 3305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (i == 0x80000000); 3315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic bool iszero(float f) { 3345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return isposzero(f) || isnegzero(f); 3355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 338e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_acosf(float); 339e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) acos(float v) { 340e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_acosf(v); 341e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 3425a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(acos) 3435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 344e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_acoshf(float); 345e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) acosh(float v) { 346e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_acoshf(v); 347e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 3485a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(acosh) 3495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) acospi(float v) { 3525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return acos(v) / M_PI; 3535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3545a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(acospi) 3555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 356e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_asinf(float); 357e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) asin(float v) { 358e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_asinf(v); 359e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 3605a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(asin) 3615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 362e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_asinhf(float); 363e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) asinh(float v) { 364e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_asinhf(v); 365e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 3665a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(asinh) 3675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) asinpi(float v) { 3695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return asin(v) / M_PI; 3705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3715a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(asinpi) 3725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 373e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_atanf(float); 374e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) atan(float v) { 375e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_atanf(v); 376e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 3775a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(atan) 3785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 379e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_atan2f(float, float); 380e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) atan2(float v1, float v2) { 381e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_atan2f(v1, v2); 382e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 3835a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(atan2) 3845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 385e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_atanhf(float); 386e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) atanh(float v) { 387e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_atanhf(v); 388e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 3895a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(atanh) 3905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) atanpi(float v) { 3925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return atan(v) / M_PI; 3935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3945a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(atanpi) 3955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) atan2pi(float y, float x) { 3985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return atan2(y, x) / M_PI; 3995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 4005a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(atan2pi) 4015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 402e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_cbrtf(float); 403e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) cbrt(float v) { 404e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_cbrtf(v); 405e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 4065a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(cbrt) 4075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 408e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_ceilf(float); 409e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) ceil(float v) { 410e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_ceilf(v); 411e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 4125a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(ceil) 4135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 414e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_copysignf(float, float); 415e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) copysign(float v1, float v2) { 416e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_copysignf(v1, v2); 417e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 4185a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(copysign) 4195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 420e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_cosf(float); 421e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) cos(float v) { 422e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_cosf(v); 423e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 4245a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(cos) 4255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 426e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_coshf(float); 427e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) cosh(float v) { 428e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_coshf(v); 429e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 4305a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(cosh) 4315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) cospi(float v) { 4335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return cos(v * M_PI); 4345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 4355a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(cospi) 4365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 437e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_erfcf(float); 438e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) erfc(float v) { 439e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_erfcf(v); 440e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 4415a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(erfc) 4425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 443e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_erff(float); 444e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) erf(float v) { 445e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_erff(v); 446e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 4475a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(erf) 4485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 449e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_expf(float); 450e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) exp(float v) { 451e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_expf(v); 452e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 4535a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(exp) 4545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 455e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_exp2f(float); 456e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) exp2(float v) { 457e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_exp2f(v); 458e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 4595a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(exp2) 4605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) pow(float, float); 4625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) exp10(float v) { 4645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return exp2(v * 3.321928095f); 4655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 4665a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(exp10) 4675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 468e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_expm1f(float); 469e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) expm1(float v) { 470e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_expm1f(v); 471e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 4725a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(expm1) 4735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fabs(float v) { 4755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int i = *((int*)(void*)&v) & 0x7fffffff; 4765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return *((float*)(void*)&i); 4775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 4785a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(fabs) 4795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 480e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_fdimf(float, float); 481e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) fdim(float v1, float v2) { 482e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_fdimf(v1, v2); 483e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 4845a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(fdim) 4855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 486e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_floorf(float); 487e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) floor(float v) { 488e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_floorf(v); 489e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 4905a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(floor) 4915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 492e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_fmaf(float, float, float); 493e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) fma(float v1, float v2, float v3) { 494e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_fmaf(v1, v2, v3); 495e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 4965a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN_FN(fma) 4975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 498e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_fminf(float, float); 4995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 500e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_fmodf(float, float); 501e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) fmod(float v1, float v2) { 502e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_fmodf(v1, v2); 503e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 5045a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(fmod) 5055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fract(float v, float *iptr) { 5075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int i = (int)floor(v); 5085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (iptr) { 5095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines iptr[0] = i; 5105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fmin(v - i, 0x1.fffffep-1f); 5125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5135a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_PFN(fract) 5145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5159cbc99ba45126a6a30ba13fc6d4e75e51ca14ea7Verena Beckhamextern float __attribute__((const, overloadable)) fract(float v) { 5169cbc99ba45126a6a30ba13fc6d4e75e51ca14ea7Verena Beckham float unused; 5179cbc99ba45126a6a30ba13fc6d4e75e51ca14ea7Verena Beckham return fract(v, &unused); 5189cbc99ba45126a6a30ba13fc6d4e75e51ca14ea7Verena Beckham} 5199cbc99ba45126a6a30ba13fc6d4e75e51ca14ea7Verena BeckhamFN_FUNC_FN(fract) 5209cbc99ba45126a6a30ba13fc6d4e75e51ca14ea7Verena Beckham 521e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_frexpf(float, int *); 522e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) frexp(float v1, int* v2) { 523e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_frexpf(v1, v2); 524e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 5255a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_PIN(frexp) 5265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 527e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_hypotf(float, float); 528e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) hypot(float v1, float v2) { 529e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_hypotf(v1, v2); 530e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 5315a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(hypot) 5325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 533e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern int __attribute__((overloadable)) SC_ilogbf(float); 534e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamint __attribute__((overloadable)) ilogb(float v) { 535e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_ilogbf(v); 536e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 5375a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesIN_FUNC_FN(ilogb) 5385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 539e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_ldexpf(float, int); 540e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) ldexp(float v1, int v2) { 541e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_ldexpf(v1, v2); 542e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 5435a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_IN(ldexp) 5445a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_I(ldexp) 5455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 546e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_lgammaf(float); 547e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) lgamma(float v) { 548e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_lgammaf(v); 549e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 5505a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(lgamma) 551e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_lgammaf_r(float, int*); 552e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) lgamma(float v, int* ptr) { 553e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_lgammaf_r(v, ptr); 554e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 5555a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_PIN(lgamma) 5565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 557e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_logf(float); 558e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) log(float v) { 559e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_logf(v); 560e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 5615a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(log) 5625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 563e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_log10f(float); 564e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) log10(float v) { 565e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_log10f(v); 566e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 5675a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(log10) 5685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) log2(float v) { 5715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return log10(v) * 3.321928095f; 5725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5735a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(log2) 5745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 575e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_log1pf(float); 576e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) log1p(float v) { 577e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_log1pf(v); 578e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 5795a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(log1p) 5805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 581e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_logbf(float); 582e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) logb(float v) { 583e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_logbf(v); 584e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 5855a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(logb) 5865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) mad(float a, float b, float c) { 5885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return a * b + c; 5895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) mad(float2 a, float2 b, float2 c) { 5915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return a * b + c; 5925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) mad(float3 a, float3 b, float3 c) { 5945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return a * b + c; 5955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) mad(float4 a, float4 b, float4 c) { 5975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return a * b + c; 5985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 600e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_modff(float, float *); 601e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) modf(float v1, float *v2) { 602e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_modff(v1, v2); 603e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 6045a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_PFN(modf); 6055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) nan(uint v) { 6075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float f[1]; 6085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines uint32_t *ip = (uint32_t *)f; 6095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *ip = v | 0x7fc00000; 6105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return f[0]; 6115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 613e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_nextafterf(float, float); 614e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) nextafter(float v1, float v2) { 615e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_nextafterf(v1, v2); 616e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 6175a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(nextafter) 6185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 619fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// This function must be defined here if we're compiling with debug info 620fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// (libclcore_g.bc), because we need a C source to get debug information. 621fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// Otherwise the implementation can be found in IR. 622fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#if defined(RS_G_RUNTIME) 623fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckhamextern float __attribute__((overloadable)) SC_powf(float, float); 624fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckhamfloat __attribute__((overloadable)) pow(float v1, float v2) { 625fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham return SC_powf(v1, v2); 626fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham} 627f72e74660567181b79673f2a476a6957db2507e5Stephen Hines#endif // defined(RS_G_RUNTIME) 6285a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(pow) 6295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) pown(float v, int p) { 6310b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet /* The mantissa of a float has fewer bits than an int (24 effective vs. 31). 6320b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet * For very large ints, we'll lose whether the exponent is even or odd, making 633bcd5b9af756d10317faf54fa3742f89dfacef152Jean-Luc Brouillet * the selection of a correct sign incorrect. We correct this. Use copysign 634bcd5b9af756d10317faf54fa3742f89dfacef152Jean-Luc Brouillet * to handle the negative zero case. 6350b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet */ 636bcd5b9af756d10317faf54fa3742f89dfacef152Jean-Luc Brouillet float sign = (p & 0x1) ? copysign(1.f, v) : 1.f; 6370b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet float f = pow(v, (float)p); 6380b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet return copysign(f, sign); 6390b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet} 6400b0bcff691d047da1d658889866c6a0347850f1cJean-Luc BrouilletFN_FUNC_FN_IN(pown) 6415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) powr(float v, float p) { 6435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, p); 6445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) powr(float2 v, float2 p) { 6465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, p); 6475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) powr(float3 v, float3 p) { 6495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, p); 6505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) powr(float4 v, float4 p) { 6525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, p); 6535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 655e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_remainderf(float, float); 656e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) remainder(float v1, float v2) { 657e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_remainderf(v1, v2); 658e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 6595a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(remainder) 6605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 661e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_remquof(float, float, int *); 662e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) remquo(float v1, float v2, int *v3) { 663e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_remquof(v1, v2, v3); 664e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 6655a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN_PIN(remquo) 6665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 667e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_rintf(float); 668e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) rint(float v) { 669e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_rintf(v); 670e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 6715a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(rint) 6725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) rootn(float v, int r) { 6745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r == 0) { 6753a3dfe7ecba55a3a832b44e4337276c09a6a25e9Dan Albert return posinf(); 6765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 6775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (iszero(v)) { 6795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r < 0) { 6805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r & 1) { 6815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return copysign(posinf(), v); 6825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } else { 6835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return posinf(); 6845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 6855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } else { 6865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r & 1) { 6875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return copysign(0.f, v); 6885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } else { 6895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return 0.f; 6905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 6915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 6925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 6935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (!isinf(v) && !isnan(v) && (v < 0.f)) { 6955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r & 1) { 6965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (-1.f * pow(-1.f * v, 1.f / r)); 6975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } else { 6985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return nan(0); 6995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 7005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 7015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, 1.f / r); 7035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7045a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_IN(rootn); 7055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 706e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_roundf(float); 707e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) round(float v) { 708e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_roundf(v); 709e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 7105a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(round) 7115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 712e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_randf2(float, float); 713e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) rsRand(float min, float max) { 714e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_randf2(min, max); 715e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 716e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham 7175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) rsqrt(float v) { 7195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return 1.f / sqrt(v); 7205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 721146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 722fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#if !defined(ARCH_X86_HAVE_SSSE3) || defined(RS_DEBUG_RUNTIME) || defined(RS_G_RUNTIME) 723a673fb0db28eac2300fcfa04549138c1c9202014Stephen Hines// These functions must be defined here if we are not using the SSE 724a673fb0db28eac2300fcfa04549138c1c9202014Stephen Hines// implementation, which includes when we are built as part of the 725fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// debug runtime (libclcore_debug.bc) or compiling with debug info. 726fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#if defined(RS_G_RUNTIME) 727fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckhamextern float __attribute__((overloadable)) SC_sqrtf(float); 728fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckhamfloat __attribute__((overloadable)) sqrt(float v) { 729fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham return SC_sqrtf(v); 730fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham} 731f72e74660567181b79673f2a476a6957db2507e5Stephen Hines#endif // defined(RS_G_RUNTIME) 732fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham 733146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen HinesFN_FUNC_FN(sqrt) 734a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#else 735a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsextern float2 __attribute__((overloadable)) sqrt(float2); 736a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsextern float3 __attribute__((overloadable)) sqrt(float3); 737a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsextern float4 __attribute__((overloadable)) sqrt(float4); 738fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#endif // !defined(ARCH_X86_HAVE_SSSE3) || defined(RS_DEBUG_RUNTIME) || defined(RS_G_RUNTIME) 739146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 7405a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(rsqrt) 7415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 742e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_sinf(float); 743e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) sin(float v) { 744e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_sinf(v); 745e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 7465a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sin) 7475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sincos(float v, float *cosptr) { 7495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *cosptr = cos(v); 7505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v); 7515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) sincos(float2 v, float2 *cosptr) { 7535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *cosptr = cos(v); 7545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v); 7555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) sincos(float3 v, float3 *cosptr) { 7575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *cosptr = cos(v); 7585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v); 7595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) sincos(float4 v, float4 *cosptr) { 7615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *cosptr = cos(v); 7625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v); 7635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 765e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_sinhf(float); 766e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) sinh(float v) { 767e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_sinhf(v); 768e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 7695a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sinh) 7705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sinpi(float v) { 7725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v * M_PI); 7735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7745a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sinpi) 7755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 776e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_tanf(float); 777e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) tan(float v) { 778e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_tanf(v); 779e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 7805a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tan) 7815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 782e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_tanhf(float); 783e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) tanh(float v) { 784e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_tanhf(v); 785e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 7865a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tanh) 7875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) tanpi(float v) { 7895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return tan(v * M_PI); 7905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7915a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tanpi) 7925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 794e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_tgammaf(float); 795e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) tgamma(float v) { 796e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_tgammaf(v); 797e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 7985a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tgamma) 7995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 800e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_truncf(float); 801e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) trunc(float v) { 802e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham return SC_truncf(v); 803e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham} 8045a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(trunc) 8055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// Int ops (partial), 6.11.3 8075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define XN_FUNC_YN(typeout, fnc, typein) \ 8095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout __attribute__((overloadable)) fnc(typein); \ 8105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout##2 __attribute__((overloadable)) fnc(typein##2 v) { \ 8115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines typeout##2 r; \ 8125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 8135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 8145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 8155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 8165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout##3 __attribute__((overloadable)) fnc(typein##3 v) { \ 8175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines typeout##3 r; \ 8185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 8195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 8205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v.z); \ 8215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 8225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 8235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout##4 __attribute__((overloadable)) fnc(typein##4 v) { \ 8245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines typeout##4 r; \ 8255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 8265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 8275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v.z); \ 8285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v.w); \ 8295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 8305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define UIN_FUNC_IN(fnc) \ 8345a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uchar, fnc, char) \ 8355a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(ushort, fnc, short) \ 8365a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uint, fnc, int) 8375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define IN_FUNC_IN(fnc) \ 8395a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uchar, fnc, uchar) \ 8405a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(char, fnc, char) \ 8415a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(ushort, fnc, ushort) \ 8425a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(short, fnc, short) \ 8435a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uint, fnc, uint) \ 8445a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(int, fnc, int) 8455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define XN_FUNC_XN_XN_BODY(type, fnc, body) \ 8485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type __attribute__((overloadable)) \ 8495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(type v1, type v2) { \ 8505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return body; \ 8515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 8525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type##2 __attribute__((overloadable)) \ 8535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(type##2 v1, type##2 v2) { \ 8545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines type##2 r; \ 8555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 8565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 8575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 8585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 8595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type##3 __attribute__((overloadable)) \ 8605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(type##3 v1, type##3 v2) { \ 8615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines type##3 r; \ 8625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 8635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 8645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z); \ 8655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 8665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 8675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type##4 __attribute__((overloadable)) \ 8685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(type##4 v1, type##4 v2) { \ 8695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines type##4 r; \ 8705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 8715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 8725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z); \ 8735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, v2.w); \ 8745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 8755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define IN_FUNC_IN_IN_BODY(fnc, body) \ 8785a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(uchar, fnc, body) \ 8795a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(char, fnc, body) \ 8805a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(ushort, fnc, body) \ 8815a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(short, fnc, body) \ 8825a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(uint, fnc, body) \ 8835a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(int, fnc, body) \ 8845a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(float, fnc, body) 8855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/** 8885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines * abs 8895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines */ 8905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable)) abs(int32_t v) { 8915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v < 0) 8925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return -v; 8935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v; 8945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint16_t __attribute__((overloadable)) abs(int16_t v) { 8965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v < 0) 8975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return -v; 8985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v; 8995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint8_t __attribute__((overloadable)) abs(int8_t v) { 9015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v < 0) 9025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return -v; 9035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v; 9045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/** 9075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines * clz 908c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines * __builtin_clz only accepts a 32-bit unsigned int, so every input will be 909c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines * expanded to 32 bits. For our smaller data types, we need to subtract off 910c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines * these unused top bits (that will be always be composed of zeros). 9115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines */ 9125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable)) clz(uint32_t v) { 9135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return __builtin_clz(v); 9145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint16_t __attribute__((overloadable)) clz(uint16_t v) { 916c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines return __builtin_clz(v) - 16; 9175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint8_t __attribute__((overloadable)) clz(uint8_t v) { 919c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines return __builtin_clz(v) - 24; 9205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int32_t __attribute__((overloadable)) clz(int32_t v) { 922c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines return __builtin_clz(v); 9235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int16_t __attribute__((overloadable)) clz(int16_t v) { 925c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines return __builtin_clz(((uint32_t)v) & 0x0000ffff) - 16; 9265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int8_t __attribute__((overloadable)) clz(int8_t v) { 928c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines return __builtin_clz(((uint32_t)v) & 0x000000ff) - 24; 9295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9325a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesUIN_FUNC_IN(abs) 9335a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesIN_FUNC_IN(clz) 9345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// 6.11.4 9375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) degrees(float radians) { 9405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return radians * (180.f / M_PI); 9415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) degrees(float2 radians) { 9435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return radians * (180.f / M_PI); 9445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) degrees(float3 radians) { 9465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return radians * (180.f / M_PI); 9475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) degrees(float4 radians) { 9495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return radians * (180.f / M_PI); 9505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) mix(float start, float stop, float amount) { 9535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 9545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) mix(float2 start, float2 stop, float2 amount) { 9565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 9575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) mix(float3 start, float3 stop, float3 amount) { 9595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 9605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) mix(float4 start, float4 stop, float4 amount) { 9625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 9635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) mix(float2 start, float2 stop, float amount) { 9655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 9665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) mix(float3 start, float3 stop, float amount) { 9685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 9695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) mix(float4 start, float4 stop, float amount) { 9715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 9725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) radians(float degrees) { 9755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return degrees * (M_PI / 180.f); 9765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) radians(float2 degrees) { 9785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return degrees * (M_PI / 180.f); 9795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) radians(float3 degrees) { 9815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return degrees * (M_PI / 180.f); 9825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) radians(float4 degrees) { 9845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return degrees * (M_PI / 180.f); 9855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) step(float edge, float v) { 9885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (v < edge) ? 0.f : 1.f; 9895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) step(float2 edge, float2 v) { 9915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; 9925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v.x < edge.x) ? 0.f : 1.f; 9935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v.y < edge.y) ? 0.f : 1.f; 9945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 9955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) step(float3 edge, float3 v) { 9975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; 9985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v.x < edge.x) ? 0.f : 1.f; 9995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v.y < edge.y) ? 0.f : 1.f; 10005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = (v.z < edge.z) ? 0.f : 1.f; 10015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 10025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) step(float4 edge, float4 v) { 10045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; 10055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v.x < edge.x) ? 0.f : 1.f; 10065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v.y < edge.y) ? 0.f : 1.f; 10075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = (v.z < edge.z) ? 0.f : 1.f; 10085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = (v.w < edge.w) ? 0.f : 1.f; 10095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 10105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) step(float2 edge, float v) { 10125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; 10135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v < edge.x) ? 0.f : 1.f; 10145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v < edge.y) ? 0.f : 1.f; 10155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 10165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) step(float3 edge, float v) { 10185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; 10195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v < edge.x) ? 0.f : 1.f; 10205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v < edge.y) ? 0.f : 1.f; 10215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = (v < edge.z) ? 0.f : 1.f; 10225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 10235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) step(float4 edge, float v) { 10255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; 10265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v < edge.x) ? 0.f : 1.f; 10275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v < edge.y) ? 0.f : 1.f; 10285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = (v < edge.z) ? 0.f : 1.f; 10295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = (v < edge.w) ? 0.f : 1.f; 10305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 10315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10320ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouilletextern float2 __attribute__((overloadable)) step(float edge, float2 v) { 10330ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet float2 r; 10340ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.x = (v.x < edge) ? 0.f : 1.f; 10350ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.y = (v.y < edge) ? 0.f : 1.f; 10360ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet return r; 10370ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet} 10380ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouilletextern float3 __attribute__((overloadable)) step(float edge, float3 v) { 10390ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet float3 r; 10400ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.x = (v.x < edge) ? 0.f : 1.f; 10410ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.y = (v.y < edge) ? 0.f : 1.f; 10420ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.z = (v.z < edge) ? 0.f : 1.f; 10430ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet return r; 10440ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet} 10450ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouilletextern float4 __attribute__((overloadable)) step(float edge, float4 v) { 10460ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet float4 r; 10470ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.x = (v.x < edge) ? 0.f : 1.f; 10480ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.y = (v.y < edge) ? 0.f : 1.f; 10490ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.z = (v.z < edge) ? 0.f : 1.f; 10500ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.w = (v.w < edge) ? 0.f : 1.f; 10510ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet return r; 10520ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet} 10535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sign(float v) { 10555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v > 0) return 1.f; 10565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v < 0) return -1.f; 10575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v; 10585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10595a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sign) 10605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// 6.11.5 10635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) cross(float3 lhs, float3 rhs) { 10645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; 10655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = lhs.y * rhs.z - lhs.z * rhs.y; 10665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = lhs.z * rhs.x - lhs.x * rhs.z; 10675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = lhs.x * rhs.y - lhs.y * rhs.x; 10685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 10695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) cross(float4 lhs, float4 rhs) { 10725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; 10735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = lhs.y * rhs.z - lhs.z * rhs.y; 10745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = lhs.z * rhs.x - lhs.x * rhs.z; 10755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = lhs.x * rhs.y - lhs.y * rhs.x; 10765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = 0.f; 10775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 10785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1080fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#if !defined(ARCH_X86_HAVE_SSSE3) || defined(RS_DEBUG_RUNTIME) || defined(RS_G_RUNTIME) 1081a673fb0db28eac2300fcfa04549138c1c9202014Stephen Hines// These functions must be defined here if we are not using the SSE 1082a673fb0db28eac2300fcfa04549138c1c9202014Stephen Hines// implementation, which includes when we are built as part of the 1083fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// debug runtime (libclcore_debug.bc) or compiling with debug info. 1084146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 1085146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) dot(float lhs, float rhs) { 1086146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return lhs * rhs; 1087146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 1088146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) dot(float2 lhs, float2 rhs) { 1089146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return lhs.x*rhs.x + lhs.y*rhs.y; 1090146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 1091146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) dot(float3 lhs, float3 rhs) { 1092146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return lhs.x*rhs.x + lhs.y*rhs.y + lhs.z*rhs.z; 1093146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 1094146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) dot(float4 lhs, float4 rhs) { 1095146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return lhs.x*rhs.x + lhs.y*rhs.y + lhs.z*rhs.z + lhs.w*rhs.w; 1096146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 1097146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 1098146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) length(float v) { 1099146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return fabs(v); 1100146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 1101146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) length(float2 v) { 1102146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return sqrt(v.x*v.x + v.y*v.y); 1103146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 1104146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) length(float3 v) { 1105146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return sqrt(v.x*v.x + v.y*v.y + v.z*v.z); 1106146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 1107146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) length(float4 v) { 1108146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return sqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w); 1109146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 1110146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 1111146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines#else 1112146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 11135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float v); 11145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float2 v); 11155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float3 v); 11165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float4 v); 11175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1118fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#endif // !defined(ARCH_X86_HAVE_SSSE3) || defined(RS_DEBUG_RUNTIME) || defined(RS_G_RUNTIME) 1119146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 11205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float lhs, float rhs) { 11215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return length(lhs - rhs); 11225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float2 lhs, float2 rhs) { 11245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return length(lhs - rhs); 11255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float3 lhs, float3 rhs) { 11275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return length(lhs - rhs); 11285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float4 lhs, float4 rhs) { 11305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return length(lhs - rhs); 11315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11333e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet/* For the normalization functions, vectors of length 0 should simply be 11343e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet * returned (i.e. all the components of that vector are 0). 11353e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet */ 11365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) normalize(float v) { 11373e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet if (v == 0.0f) { 11383e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return 0.0f; 11393e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet } else if (v < 0.0f) { 11403e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return -1.0f; 11413e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet } else { 11423e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return 1.0f; 11433e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet } 11445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) normalize(float2 v) { 11463e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet float l = length(v); 11473e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return l == 0.0f ? v : v / l; 11485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) normalize(float3 v) { 11503e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet float l = length(v); 11513e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return l == 0.0f ? v : v / l; 11525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) normalize(float4 v) { 11543e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet float l = length(v); 11553e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return l == 0.0f ? v : v / l; 11565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1158ba92a7085bbb8916334a6571ff33355873883173Jason Samsextern float __attribute__((overloadable)) half_sqrt(float v) { 1159ba92a7085bbb8916334a6571ff33355873883173Jason Sams return sqrt(v); 1160ba92a7085bbb8916334a6571ff33355873883173Jason Sams} 1161ba92a7085bbb8916334a6571ff33355873883173Jason SamsFN_FUNC_FN(half_sqrt) 11625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float v) { 1164582b3646d6634f74a13828cceb1414823c18e66fStephen Hines return fabs(v); 11655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float2 v) { 11675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return half_sqrt(v.x*v.x + v.y*v.y); 11685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float3 v) { 11705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return half_sqrt(v.x*v.x + v.y*v.y + v.z*v.z); 11715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float4 v) { 11735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return half_sqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w); 11745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float lhs, float rhs) { 11775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fast_length(lhs - rhs); 11785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float2 lhs, float2 rhs) { 11805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fast_length(lhs - rhs); 11815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float3 lhs, float3 rhs) { 11835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fast_length(lhs - rhs); 11845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float4 lhs, float4 rhs) { 11865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fast_length(lhs - rhs); 11875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) half_rsqrt(float); 11905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11913e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet/* For the normalization functions, vectors of length 0 should simply be 11923e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet * returned (i.e. all the components of that vector are 0). 11933e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet */ 11945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_normalize(float v) { 11953e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet if (v == 0.0f) { 11963e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return 0.0f; 11973e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet } else if (v < 0.0f) { 11983e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return -1.0f; 11993e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet } else { 12003e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return 1.0f; 12013e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet } 12025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12033e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet// If the length is 0, then rlength should be NaN. 12045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fast_normalize(float2 v) { 12053e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet float rlength = half_rsqrt(v.x*v.x + v.y*v.y); 12063e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return (rlength == rlength) ? v * rlength : v; 12075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fast_normalize(float3 v) { 12093e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet float rlength = half_rsqrt(v.x*v.x + v.y*v.y + v.z*v.z); 12103e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return (rlength == rlength) ? v * rlength : v; 12115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fast_normalize(float4 v) { 12133e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet float rlength = half_rsqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w); 12143e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return (rlength == rlength) ? v * rlength : v; 12155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1217ba92a7085bbb8916334a6571ff33355873883173Jason Samsextern float __attribute__((overloadable)) half_recip(float v) { 1218ba92a7085bbb8916334a6571ff33355873883173Jason Sams return 1.f / v; 1219ba92a7085bbb8916334a6571ff33355873883173Jason Sams} 12205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/* 12225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) approx_atan(float x) { 12235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (x == 0.f) 12245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return 0.f; 12255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (x < 0.f) 12265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return -1.f * approx_atan(-1.f * x); 12275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (x > 1.f) 12285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return M_PI_2 - approx_atan(approx_recip(x)); 12295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return x * approx_recip(1.f + 0.28f * x*x); 12305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12315a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(approx_atan) 12325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines*/ 12335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinestypedef union 12355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines{ 12365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float fv; 12375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t iv; 12385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} ieee_float_shape_type; 12395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/* Get a 32 bit int from a float. */ 12415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define GET_FLOAT_WORD(i,d) \ 12435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesdo { \ 12445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ieee_float_shape_type gf_u; \ 12455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines gf_u.fv = (d); \ 12465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (i) = gf_u.iv; \ 12475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} while (0) 12485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/* Set a float from a 32 bit int. */ 12505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define SET_FLOAT_WORD(d,i) \ 12525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesdo { \ 12535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ieee_float_shape_type sf_u; \ 12545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines sf_u.iv = (i); \ 12555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (d) = sf_u.fv; \ 12565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} while (0) 12575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// Valid -125 to 125 12615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_exp2(float v) { 12625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t iv = (int)v; 12635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t x = iv + (iv >> 31); // ~floor(v) 12645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float r = (v - x); 12655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float fo; 12675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines SET_FLOAT_WORD(fo, (x + 127) << 23); 12685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r *= 0.694f; // ~ log(e) / log(2) 12705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float r2 = r*r; 12715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float adj = 1.f + r + (r2 * 0.5f) + (r2*r * 0.166666f) + (r2*r2 * 0.0416666f); 12725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fo * adj; 12735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_exp2(float2 v) { 12765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int2 iv = convert_int2(v); 12775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int2 x = iv + (iv >> (int2)31);//floor(v); 12785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r = (v - convert_float2(x)); 12795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines x += 127; 12815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 fo = (float2)(x << (int2)23); 12835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r *= 0.694f; // ~ log(e) / log(2) 12855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r2 = r*r; 12865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 adj = 1.f + r + (r2 * 0.5f) + (r2*r * 0.166666f) + (r2*r2 * 0.0416666f); 12875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fo * adj; 12885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_exp2(float4 v) { 12915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int4 iv = convert_int4(v); 12925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int4 x = iv + (iv >> (int4)31);//floor(v); 12935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r = (v - convert_float4(x)); 12945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines x += 127; 12965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 fo = (float4)(x << (int4)23); 12985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r *= 0.694f; // ~ log(e) / log(2) 13005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r2 = r*r; 13015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 adj = 1.f + r + (r2 * 0.5f) + (r2*r * 0.166666f) + (r2*r2 * 0.0416666f); 13025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fo * adj; 13035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 13055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_exp2(float3 v) { 13065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 t = 1.f; 13075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines t.xyz = v; 13085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(t).xyz; 13095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 13115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 13125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_exp(float v) { 13135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 1.442695041f); 13145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_exp(float2 v) { 13165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 1.442695041f); 13175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_exp(float3 v) { 13195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 1.442695041f); 13205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_exp(float4 v) { 13225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 1.442695041f); 13235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 13255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_exp10(float v) { 13265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 3.321928095f); 13275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_exp10(float2 v) { 13295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 3.321928095f); 13305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_exp10(float3 v) { 13325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 3.321928095f); 13335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_exp10(float4 v) { 13355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 3.321928095f); 13365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 13385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_log2(float v) { 13395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t ibits; 13405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines GET_FLOAT_WORD(ibits, v); 13415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 13425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t e = (ibits >> 23) & 0xff; 13435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 13445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ibits &= 0x7fffff; 13455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ibits |= 127 << 23; 13465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 13475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float ir; 13485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines SET_FLOAT_WORD(ir, ibits); 13495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ir -= 1.5f; 13505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float ir2 = ir*ir; 1351c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams float adj2 = (0.405465108f / 0.693147181f) + 1352c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams ((0.666666667f / 0.693147181f) * ir) - 1353c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams ((0.222222222f / 0.693147181f) * ir2) + 1354c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams ((0.098765432f / 0.693147181f) * ir*ir2) - 1355c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams ((0.049382716f / 0.693147181f) * ir2*ir2) + 1356c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams ((0.026337449f / 0.693147181f) * ir*ir2*ir2) - 1357c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams ((0.014631916f / 0.693147181f) * ir2*ir2*ir2); 13585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (float)(e - 127) + adj2; 13595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_log2(float2 v) { 13615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 v2 = {native_log2(v.x), native_log2(v.y)}; 13625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v2; 13635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_log2(float3 v) { 13655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 v2 = {native_log2(v.x), native_log2(v.y), native_log2(v.z)}; 13665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v2; 13675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_log2(float4 v) { 13695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 v2 = {native_log2(v.x), native_log2(v.y), native_log2(v.z), native_log2(v.w)}; 13705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v2; 13715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 13735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_log(float v) { 13745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 1.442695041f); 13755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_log(float2 v) { 13775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 1.442695041f); 13785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_log(float3 v) { 13805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 1.442695041f); 13815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_log(float4 v) { 13835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 1.442695041f); 13845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 13865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_log10(float v) { 13875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 3.321928095f); 13885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_log10(float2 v) { 13905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 3.321928095f); 13915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_log10(float3 v) { 13935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 3.321928095f); 13945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_log10(float4 v) { 13965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 3.321928095f); 13975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 13985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 13995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 14005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_powr(float v, float y) { 14015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float v2 = native_log2(v); 1402c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams v2 = fmax(v2 * y, -125.f); 1403c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams return native_exp2(v2); 14045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 14055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_powr(float2 v, float2 y) { 14065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 v2 = native_log2(v); 1407c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams v2 = fmax(v2 * y, -125.f); 1408c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams return native_exp2(v2); 14095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 14105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_powr(float3 v, float3 y) { 14115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 v2 = native_log2(v); 1412c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams v2 = fmax(v2 * y, -125.f); 1413c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams return native_exp2(v2); 14145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 14155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_powr(float4 v, float4 y) { 14165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 v2 = native_log2(v); 1417c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams v2 = fmax(v2 * y, -125.f); 1418c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams return native_exp2(v2); 14195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 14205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 142153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double __attribute__((overloadable)) min(double v1, double v2) { 142253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return v1 < v2 ? v1 : v2; 142353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 142453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 142553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double2 __attribute__((overloadable)) min(double2 v1, double2 v2) { 142653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams double2 r; 142753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 142853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 142953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 143053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 143153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 143253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double3 __attribute__((overloadable)) min(double3 v1, double3 v2) { 143353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams double3 r; 143453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 143553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 143653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z < v2.z ? v1.z : v2.z; 143753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 143853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 143953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 144053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double4 __attribute__((overloadable)) min(double4 v1, double4 v2) { 144153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams double4 r; 144253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 144353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 144453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z < v2.z ? v1.z : v2.z; 144553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.w = v1.w < v2.w ? v1.w : v2.w; 144653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 144753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 144853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 1449d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long __attribute__((overloadable)) min(long v1, long v2) { 145053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return v1 < v2 ? v1 : v2; 145153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1452d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long2 __attribute__((overloadable)) min(long2 v1, long2 v2) { 145353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams long2 r; 145453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 145553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 145653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 145753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1458d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long3 __attribute__((overloadable)) min(long3 v1, long3 v2) { 145953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams long3 r; 146053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 146153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 146253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z < v2.z ? v1.z : v2.z; 146353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 146453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1465d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long4 __attribute__((overloadable)) min(long4 v1, long4 v2) { 146653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams long4 r; 146753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 146853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 146953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z < v2.z ? v1.z : v2.z; 147053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.w = v1.w < v2.w ? v1.w : v2.w; 147153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 147253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 147353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 1474d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong __attribute__((overloadable)) min(ulong v1, ulong v2) { 147553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return v1 < v2 ? v1 : v2; 147653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1477d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong2 __attribute__((overloadable)) min(ulong2 v1, ulong2 v2) { 147853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams ulong2 r; 147953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 148053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 148153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 148253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1483d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong3 __attribute__((overloadable)) min(ulong3 v1, ulong3 v2) { 148453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams ulong3 r; 148553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 148653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 148753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z < v2.z ? v1.z : v2.z; 148853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 148953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1490d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong4 __attribute__((overloadable)) min(ulong4 v1, ulong4 v2) { 149153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams ulong4 r; 149253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 149353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 149453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z < v2.z ? v1.z : v2.z; 149553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.w = v1.w < v2.w ? v1.w : v2.w; 149653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 149753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 149853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 149953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double __attribute__((overloadable)) max(double v1, double v2) { 150053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return v1 > v2 ? v1 : v2; 150153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 150253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 150353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double2 __attribute__((overloadable)) max(double2 v1, double2 v2) { 150453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams double2 r; 150553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 150653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 150753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 150853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 150953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 151053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double3 __attribute__((overloadable)) max(double3 v1, double3 v2) { 151153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams double3 r; 151253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 151353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 151453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z > v2.z ? v1.z : v2.z; 151553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 151653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 151753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 151853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double4 __attribute__((overloadable)) max(double4 v1, double4 v2) { 151953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams double4 r; 152053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 152153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 152253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z > v2.z ? v1.z : v2.z; 152353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.w = v1.w > v2.w ? v1.w : v2.w; 152453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 152553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 152653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 1527d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long __attribute__((overloadable)) max(long v1, long v2) { 152853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return v1 > v2 ? v1 : v2; 152953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1530d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long2 __attribute__((overloadable)) max(long2 v1, long2 v2) { 153153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams long2 r; 153253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 153353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 153453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 153553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1536d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long3 __attribute__((overloadable)) max(long3 v1, long3 v2) { 153753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams long3 r; 153853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 153953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 154053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z > v2.z ? v1.z : v2.z; 154153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 154253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1543d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long4 __attribute__((overloadable)) max(long4 v1, long4 v2) { 154453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams long4 r; 154553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 154653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 154753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z > v2.z ? v1.z : v2.z; 154853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.w = v1.w > v2.w ? v1.w : v2.w; 154953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 155053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 155153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 1552d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong __attribute__((overloadable)) max(ulong v1, ulong v2) { 155353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return v1 > v2 ? v1 : v2; 155453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1555d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong2 __attribute__((overloadable)) max(ulong2 v1, ulong2 v2) { 155653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams ulong2 r; 155753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 155853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 155953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 156053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1561d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong3 __attribute__((overloadable)) max(ulong3 v1, ulong3 v2) { 156253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams ulong3 r; 156353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 156453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 156553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z > v2.z ? v1.z : v2.z; 156653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 156753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1568d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong4 __attribute__((overloadable)) max(ulong4 v1, ulong4 v2) { 156953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams ulong4 r; 157053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 157153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 157253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z > v2.z ? v1.z : v2.z; 157353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.w = v1.w > v2.w ? v1.w : v2.w; 157453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 157553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 157653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 1577a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#define THUNK_NATIVE_F(fn) \ 1578a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float __attribute__((overloadable)) native_##fn(float v) { return fn(v);} \ 1579a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float2 __attribute__((overloadable)) native_##fn(float2 v) { return fn(v);} \ 1580a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float3 __attribute__((overloadable)) native_##fn(float3 v) { return fn(v);} \ 1581a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float4 __attribute__((overloadable)) native_##fn(float4 v) { return fn(v);} 1582a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1583a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#define THUNK_NATIVE_F_F(fn) \ 1584a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float __attribute__((overloadable)) native_##fn(float v1, float v2) { return fn(v1, v2);} \ 1585a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float2 __attribute__((overloadable)) native_##fn(float2 v1, float2 v2) { return fn(v1, v2);} \ 1586a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float3 __attribute__((overloadable)) native_##fn(float3 v1, float3 v2) { return fn(v1, v2);} \ 1587a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float4 __attribute__((overloadable)) native_##fn(float4 v1, float4 v2) { return fn(v1, v2);} 1588a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1589a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#define THUNK_NATIVE_F_FP(fn) \ 1590a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float __attribute__((overloadable)) native_##fn(float v1, float *v2) { return fn(v1, v2);} \ 1591a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float2 __attribute__((overloadable)) native_##fn(float2 v1, float2 *v2) { return fn(v1, v2);} \ 1592a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float3 __attribute__((overloadable)) native_##fn(float3 v1, float3 *v2) { return fn(v1, v2);} \ 1593a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float4 __attribute__((overloadable)) native_##fn(float4 v1, float4 *v2) { return fn(v1, v2);} 1594a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1595a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#define THUNK_NATIVE_F_I(fn) \ 1596a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float __attribute__((overloadable)) native_##fn(float v1, int v2) { return fn(v1, v2);} \ 1597a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float2 __attribute__((overloadable)) native_##fn(float2 v1, int2 v2) { return fn(v1, v2);} \ 1598a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float3 __attribute__((overloadable)) native_##fn(float3 v1, int3 v2) { return fn(v1, v2);} \ 1599a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float4 __attribute__((overloadable)) native_##fn(float4 v1, int4 v2) { return fn(v1, v2);} 1600a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1601a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(acos) 1602a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(acosh) 1603a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(acospi) 1604a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(asin) 1605a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(asinh) 1606a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(asinpi) 1607a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(atan) 1608a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F_F(atan2) 1609a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(atanh) 1610a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(atanpi) 1611a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F_F(atan2pi) 1612a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(cbrt) 1613a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(cos) 1614a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(cosh) 1615a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(cospi) 1616a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(expm1) 1617a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F_F(hypot) 1618a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(log1p) 1619a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F_I(rootn) 1620a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(rsqrt) 1621a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(sqrt) 1622a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(sin) 1623a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F_FP(sincos) 1624a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(sinh) 1625a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(sinpi) 1626a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(tan) 1627a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(tanh) 1628a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(tanpi) 1629a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1630a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#undef THUNK_NATIVE_F 1631a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#undef THUNK_NATIVE_F_F 1632a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#undef THUNK_NATIVE_F_I 1633a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#undef THUNK_NATIVE_F_FP 1634a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1635a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_normalize(float v) { return fast_normalize(v);} 1636a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat2 __attribute__((overloadable)) native_normalize(float2 v) { return fast_normalize(v);} 1637a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat3 __attribute__((overloadable)) native_normalize(float3 v) { return fast_normalize(v);} 1638a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat4 __attribute__((overloadable)) native_normalize(float4 v) { return fast_normalize(v);} 1639a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1640a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_distance(float v1, float v2) { return fast_distance(v1, v2);} 1641a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_distance(float2 v1, float2 v2) { return fast_distance(v1, v2);} 1642a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_distance(float3 v1, float3 v2) { return fast_distance(v1, v2);} 1643a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_distance(float4 v1, float4 v2) { return fast_distance(v1, v2);} 1644a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1645a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_length(float v) { return fast_length(v);} 1646a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_length(float2 v) { return fast_length(v);} 1647a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_length(float3 v) { return fast_length(v);} 1648a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_length(float4 v) { return fast_length(v);} 1649a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1650a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_divide(float v1, float v2) { return v1 / v2;} 1651a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat2 __attribute__((overloadable)) native_divide(float2 v1, float2 v2) { return v1 / v2;} 1652a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat3 __attribute__((overloadable)) native_divide(float3 v1, float3 v2) { return v1 / v2;} 1653a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat4 __attribute__((overloadable)) native_divide(float4 v1, float4 v2) { return v1 / v2;} 1654a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1655a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_recip(float v) { return 1.f / v;} 1656a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat2 __attribute__((overloadable)) native_recip(float2 v) { return ((float2)1.f) / v;} 1657a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat3 __attribute__((overloadable)) native_recip(float3 v) { return ((float3)1.f) / v;} 1658a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat4 __attribute__((overloadable)) native_recip(float4 v) { return ((float4)1.f) / v;} 1659a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1660a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1661a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1662a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 16635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 16645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN 16655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef IN_FUNC_FN 16665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_FN 16675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_F 16685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_IN 16695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_I 16705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_PFN 16715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_PIN 16725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_FN_FN 16735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_FN_PIN 16745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef XN_FUNC_YN 16755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef UIN_FUNC_IN 16765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef IN_FUNC_IN 16775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef XN_FUNC_XN_XN_BODY 16785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef IN_FUNC_IN_IN_BODY 167954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 168054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarstatic const unsigned short kHalfPositiveInfinity = 0x7c00; 168154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 168254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form 168354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * HN output = fn(HN input) 168454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is scalar or vector half type 168554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */ 168654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define HN_FUNC_HN(fn) \ 168754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half h) { \ 168854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return (half) fn((float) h); \ 168954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 169054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) fn(half2 v) { \ 169154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half2(fn(convert_float2(v))); \ 169254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 169354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) fn(half3 v) { \ 169454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half3(fn(convert_float3(v))); \ 169554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 169654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) fn(half4 v) { \ 169754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half4(fn(convert_float4(v))); \ 169854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 169954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 170054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form 170154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * HN output = fn(HN input1, HN input2) 170254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is scalar or vector half type 170354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */ 170454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define HN_FUNC_HN_HN(fn) \ 170554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half h1, half h2) { \ 170654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return (half) fn((float) h1, (float) h2); \ 170754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 170854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) fn(half2 v1, half2 v2) { \ 170954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half2(fn(convert_float2(v1), \ 171054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar convert_float2(v2))); \ 171154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 171254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) fn(half3 v1, half3 v2) { \ 171354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half3(fn(convert_float3(v1), \ 171454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar convert_float3(v2))); \ 171554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 171654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) fn(half4 v1, half4 v2) { \ 171754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half4(fn(convert_float4(v1), \ 171854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar convert_float4(v2))); \ 171954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 172054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 172154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form 172254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * HN output = fn(HN input1, half input2) 172354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is scalar or vector half type 172454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */ 172554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define HN_FUNC_HN_H(fn) \ 172654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) fn(half2 v1, half v2) { \ 172754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half2(fn(convert_float2(v1), (float) v2)); \ 172854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 172954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) fn(half3 v1, half v2) { \ 173054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half3(fn(convert_float3(v1), (float) v2)); \ 173154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 173254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) fn(half4 v1, half v2) { \ 173354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half4(fn(convert_float4(v1), (float) v2)); \ 173454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 173554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 173654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form 173754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * HN output = fn(HN input1, HN input2, HN input3) 173854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is scalar or vector half type 173954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */ 174054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define HN_FUNC_HN_HN_HN(fn) \ 174154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half h1, half h2, half h3) { \ 174254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return (half) fn((float) h1, (float) h2, (float) h3); \ 174354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 174454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) fn(half2 v1, half2 v2, half2 v3) { \ 174554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half2(fn(convert_float2(v1), \ 174654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar convert_float2(v2), \ 174754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar convert_float2(v3))); \ 174854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 174954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) fn(half3 v1, half3 v2, half3 v3) { \ 175054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half3(fn(convert_float3(v1), \ 175154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar convert_float3(v2), \ 175254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar convert_float3(v3))); \ 175354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 175454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) fn(half4 v1, half4 v2, half4 v3) { \ 175554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half4(fn(convert_float4(v1), \ 175654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar convert_float4(v2), \ 175754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar convert_float4(v3))); \ 175854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 175954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 176054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form 176154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * HN output = fn(HN input1, IN input2) 176254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is scalar or vector half type and IN the equivalent integer type 176354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * of same vector length. 176454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */ 176554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define HN_FUNC_HN_IN(fn) \ 176654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half h1, int v) { \ 176754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return (half) fn((float) h1, v); \ 176854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 176954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) fn(half2 v1, int2 v2) { \ 177054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half2(fn(convert_float2(v1), v2)); \ 177154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 177254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) fn(half3 v1, int3 v2) { \ 177354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half3(fn(convert_float3(v1), v2)); \ 177454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 177554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) fn(half4 v1, int4 v2) { \ 177654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half4(fn(convert_float4(v1), v2)); \ 177754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 177854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 177954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form 178054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * half output = fn(HN input1) 178154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is a scalar or vector half type. 178254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */ 178354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define H_FUNC_HN(fn) \ 178454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half h) { \ 178554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return (half) fn((float) h); \ 178654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 178754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half2 v) { \ 178854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return fn(convert_float2(v)); \ 178954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 179054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half3 v) { \ 179154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return fn(convert_float3(v)); \ 179254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 179354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half4 v) { \ 179454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return fn(convert_float4(v)); \ 179554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 179654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 179754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form 179854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * half output = fn(HN input1, HN input2) 179954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is a scalar or vector half type. 180054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */ 180154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define H_FUNC_HN_HN(fn) \ 180254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half h1, half h2) { \ 180354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return (half) fn((float) h1, (float) h2); \ 180454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 180554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half2 v1, half2 v2) { \ 180654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return fn(convert_float2(v1), convert_float2(v2)); \ 180754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 180854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half3 v1, half3 v2) { \ 180954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return fn(convert_float3(v1), convert_float3(v2)); \ 181054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 181154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half4 v1, half4 v2) { \ 181254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return fn(convert_float4(v1), convert_float4(v2)); \ 181354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 181454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 1815b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar#define SCALARIZE_HN_FUNC_HN_PHN(fnc) \ 1816b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half2 __attribute__((overloadable)) fnc(half2 v1, half2 *v2) { \ 1817b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar half2 ret; \ 1818b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar half t[2]; \ 1819b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar ret.x = fnc(v1.x, &t[0]); \ 1820b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar ret.y = fnc(v1.y, &t[1]); \ 1821b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar v2->x = t[0]; \ 1822b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar v2->y = t[1]; \ 1823b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar return ret; \ 1824b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar} \ 1825b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half3 __attribute__((overloadable)) fnc(half3 v1, half3 *v2) { \ 1826b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar half3 ret; \ 1827b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar half t[3]; \ 1828b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar ret.x = fnc(v1.x, &t[0]); \ 1829b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar ret.y = fnc(v1.y, &t[1]); \ 1830b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar ret.z = fnc(v1.z, &t[2]); \ 1831b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar v2->x = t[0]; \ 1832b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar v2->y = t[1]; \ 1833b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar v2->z = t[2]; \ 1834b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar return ret; \ 1835b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar} \ 1836b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half4 __attribute__((overloadable)) fnc(half4 v1, half4 *v2) { \ 1837b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar half4 ret; \ 1838b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar half t[4]; \ 1839b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar ret.x = fnc(v1.x, &t[0]); \ 1840b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar ret.y = fnc(v1.y, &t[1]); \ 1841b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar ret.z = fnc(v1.z, &t[2]); \ 1842b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar ret.w = fnc(v1.w, &t[3]); \ 1843b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar v2->x = t[0]; \ 1844b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar v2->y = t[1]; \ 1845b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar v2->z = t[2]; \ 1846b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar v2->w = t[3]; \ 1847b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar return ret; \ 1848b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar} 1849b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar 185054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form 185154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * HN output = fn(HN input1, HN input2) 185254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is a vector half type. The functions are defined to call the 185354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * scalar function of the same name. 185454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */ 185554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define SCALARIZE_HN_FUNC_HN_HN(fn) \ 185654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) fn(half2 v1, half2 v2) { \ 185754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half2 ret; \ 185854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.x = fn(v1.x, v2.x); \ 185954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.y = fn(v1.y, v2.y); \ 186054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return ret; \ 186154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 186254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) fn(half3 v1, half3 v2) { \ 186354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half3 ret; \ 186454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.x = fn(v1.x, v2.x); \ 186554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.y = fn(v1.y, v2.y); \ 186654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.z = fn(v1.z, v2.z); \ 186754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return ret; \ 186854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 186954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) fn(half4 v1, half4 v2) { \ 187054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half4 ret; \ 187154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.x = fn(v1.x, v2.x); \ 187254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.y = fn(v1.y, v2.y); \ 187354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.z = fn(v1.z, v2.z); \ 187454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.w = fn(v1.w, v2.w); \ 187554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return ret; \ 187654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 187754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 187854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(acos); 187954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(acosh); 188054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(acospi); 188154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(asin); 188254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(asinh); 188354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(asinpi); 188454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(atan); 188554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(atanh); 188654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(atanpi); 188754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(atan2); 188854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(atan2pi); 188954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 189054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(cbrt); 189154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(ceil); 189254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 1893f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainarextern half __attribute__((overloadable)) copysign(half x, half y); 1894f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga NainarSCALARIZE_HN_FUNC_HN_HN(copysign); 189554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 189654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(cos); 189754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(cosh); 189854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(cospi); 189954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 190054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) cross(half3 lhs, half3 rhs) { 190154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half3 r; 190254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = lhs.y * rhs.z - lhs.z * rhs.y; 190354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = lhs.z * rhs.x - lhs.x * rhs.z; 190454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.z = lhs.x * rhs.y - lhs.y * rhs.x; 190554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 190654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 190754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 190854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) cross(half4 lhs, half4 rhs) { 190954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half4 r; 191054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = lhs.y * rhs.z - lhs.z * rhs.y; 191154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = lhs.z * rhs.x - lhs.x * rhs.z; 191254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.z = lhs.x * rhs.y - lhs.y * rhs.x; 191354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.w = 0.f; 191454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 191554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 191654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 191754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(degrees); 191854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarH_FUNC_HN_HN(distance); 191954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarH_FUNC_HN_HN(dot); 192054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 192154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(erf); 192254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(erfc); 192354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(exp); 192454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(exp10); 192554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(exp2); 192654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(expm1); 192754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 192854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(fabs); 192954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(fdim); 193054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(floor); 193154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN_HN(fma); 193254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(fmax); 193354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_H(fmax); 193454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(fmin); 193554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_H(fmin); 193654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(fmod); 193754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 1938b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half __attribute__((overloadable)) fract(half v, half *iptr) { 1939b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar // maxLessThanOne = 0.99951171875, the largest value < 1.0 1940b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar half maxLessThanOne; 1941b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar SET_HALF_WORD(maxLessThanOne, 0x3bff); 1942b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar 1943b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar int i = (int) floor(v); 1944b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar if (iptr) { 1945b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar *iptr = i; 1946b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar } 1947b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar // return v - floor(v), if strictly less than one 1948b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar return fmin(v - i, maxLessThanOne); 1949b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar} 1950b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar 1951b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga NainarSCALARIZE_HN_FUNC_HN_PHN(fract); 1952b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar 1953b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half __attribute__((const, overloadable)) fract(half v) { 1954b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar half unused; 1955b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar return fract(v, &unused); 1956b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar} 1957b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar 1958b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half2 __attribute__((const, overloadable)) fract(half2 v) { 1959b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar half2 unused; 1960b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar return fract(v, &unused); 1961b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar} 1962b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar 1963b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half3 __attribute__((const, overloadable)) fract(half3 v) { 1964b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar half3 unused; 1965b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar return fract(v, &unused); 1966b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar} 1967b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar 1968b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half4 __attribute__((const, overloadable)) fract(half4 v) { 1969b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar half4 unused; 1970b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar return fract(v, &unused); 1971b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar} 1972b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar 1973b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half __attribute__((overloadable)) frexp(half x, int *eptr); 1974b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar 1975b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half2 __attribute__((overloadable)) frexp(half2 v1, int2 *eptr) { 1976b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar half2 ret; 1977b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar int e[2]; 1978b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar ret.x = frexp(v1.x, &e[0]); 1979b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar ret.y = frexp(v1.y, &e[1]); 1980b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar eptr->x = e[0]; 1981b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar eptr->y = e[1]; 1982b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar return ret; 1983b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar} 1984b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar 1985b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half3 __attribute__((overloadable)) frexp(half3 v1, int3 *eptr) { 1986b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar half3 ret; 1987b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar int e[3]; 1988b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar ret.x = frexp(v1.x, &e[0]); 1989b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar ret.y = frexp(v1.y, &e[1]); 1990b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar ret.z = frexp(v1.z, &e[2]); 1991b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar eptr->x = e[0]; 1992b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar eptr->y = e[1]; 1993b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar eptr->z = e[2]; 1994b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar return ret; 1995b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar} 1996b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar 1997b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half4 __attribute__((overloadable)) frexp(half4 v1, int4 *eptr) { 1998b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar half4 ret; 1999b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar int e[4]; 2000b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar ret.x = frexp(v1.x, &e[0]); 2001b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar ret.y = frexp(v1.y, &e[1]); 2002b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar ret.z = frexp(v1.z, &e[2]); 2003b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar ret.w = frexp(v1.w, &e[3]); 2004b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar eptr->x = e[0]; 2005b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar eptr->y = e[1]; 2006b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar eptr->z = e[2]; 2007b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar eptr->w = e[3]; 2008b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar return ret; 2009b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar} 201054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 201154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(hypot); 201254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 2013f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainarextern int __attribute__((overloadable)) ilogb(half x); 2014f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar 2015f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainarextern int2 __attribute__((overloadable)) ilogb(half2 v) { 2016f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar int2 ret; 2017f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar ret.x = ilogb(v.x); 2018f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar ret.y = ilogb(v.y); 2019f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar return ret; 2020f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar} 2021f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainarextern int3 __attribute__((overloadable)) ilogb(half3 v) { 2022f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar int3 ret; 2023f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar ret.x = ilogb(v.x); 2024f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar ret.y = ilogb(v.y); 2025f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar ret.z = ilogb(v.z); 2026f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar return ret; 2027f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar} 2028f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainarextern int4 __attribute__((overloadable)) ilogb(half4 v) { 2029f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar int4 ret; 2030f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar ret.x = ilogb(v.x); 2031f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar ret.y = ilogb(v.y); 2032f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar ret.z = ilogb(v.z); 2033f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar ret.w = ilogb(v.w); 2034f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar return ret; 2035f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar} 203654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 203754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_IN(ldexp); 203854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) ldexp(half2 v, int exponent) { 203954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half2(ldexp(convert_float2(v), exponent)); 204054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 204154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) ldexp(half3 v, int exponent) { 204254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half3(ldexp(convert_float3(v), exponent)); 204354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 204454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) ldexp(half4 v, int exponent) { 204554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half4(ldexp(convert_float4(v), exponent)); 204654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 204754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 204854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarH_FUNC_HN(length); 204954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(lgamma); 205054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 205154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) lgamma(half h, int *signp) { 205254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return (half) lgamma((float) h, signp); 205354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 205454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) lgamma(half2 v, int2 *signp) { 205554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half2(lgamma(convert_float2(v), signp)); 205654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 205754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) lgamma(half3 v, int3 *signp) { 205854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half3(lgamma(convert_float3(v), signp)); 205954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 206054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) lgamma(half4 v, int4 *signp) { 206154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half4(lgamma(convert_float4(v), signp)); 206254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 206354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 206454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(log); 206554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(log10); 206654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(log1p); 206754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(log2); 206854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(logb); 206954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 207054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN_HN(mad); 207154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(max); 207254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_H(max); // TODO can this be arch-specific similar to _Z3maxDv2_ff? 207354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(min); 207454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_H(min); // TODO can this be arch-specific similar to _Z3minDv2_ff? 207554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 207654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) mix(half start, half stop, half amount) { 207754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return start + (stop - start) * amount; 207854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 207954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) mix(half2 start, half2 stop, half2 amount) { 208054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return start + (stop - start) * amount; 208154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 208254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) mix(half3 start, half3 stop, half3 amount) { 208354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return start + (stop - start) * amount; 208454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 208554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) mix(half4 start, half4 stop, half4 amount) { 208654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return start + (stop - start) * amount; 208754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 208854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) mix(half2 start, half2 stop, half amount) { 208954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return start + (stop - start) * amount; 209054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 209154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) mix(half3 start, half3 stop, half amount) { 209254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return start + (stop - start) * amount; 209354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 209454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) mix(half4 start, half4 stop, half amount) { 209554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return start + (stop - start) * amount; 209654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 209754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 2098b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half __attribute__((overloadable)) modf(half x, half *iptr); 2099b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga NainarSCALARIZE_HN_FUNC_HN_PHN(modf); 210054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 210154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarhalf __attribute__((overloadable)) nan_half() { 210254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar unsigned short nan_short = kHalfPositiveInfinity | 0x0200; 210354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half nan; 210454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar SET_HALF_WORD(nan, nan_short); 210554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return nan; 210654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 210754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 210854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(normalize); 210954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 2110f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainarextern half __attribute__((overloadable)) nextafter(half x, half y); 2111f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga NainarSCALARIZE_HN_FUNC_HN_HN(nextafter); 2112f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar 211354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(pow); 211454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_IN(pown); 211554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(powr); 211654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(radians); 211754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(remainder); 211854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 211954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) remquo(half n, half d, int *quo) { 212054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return (float) remquo((float) n, (float) d, quo); 212154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 212254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) remquo(half2 n, half2 d, int2 *quo) { 212354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half2(remquo(convert_float2(d), convert_float2(n), quo)); 212454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 212554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) remquo(half3 n, half3 d, int3 *quo) { 212654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half3(remquo(convert_float3(d), convert_float3(n), quo)); 212754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 212854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) remquo(half4 n, half4 d, int4 *quo) { 212954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half4(remquo(convert_float4(d), convert_float4(n), quo)); 213054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 213154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 213254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(rint); 213354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_IN(rootn); 213454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(round); 213554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(rsqrt); 213654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 213754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) sign(half h) { 213854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar if (h > 0) return (half) 1.f; 213954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar if (h < 0) return (half) -1.f; 214054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return h; 214154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 214254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) sign(half2 v) { 214354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half2 ret; 214454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.x = sign(v.x); 214554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.y = sign(v.y); 214654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return ret; 214754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 214854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) sign(half3 v) { 214954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half3 ret; 215054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.x = sign(v.x); 215154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.y = sign(v.y); 215254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.z = sign(v.z); 215354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return ret; 215454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 215554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) sign(half4 v) { 215654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half4 ret; 215754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.x = sign(v.x); 215854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.y = sign(v.y); 215954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.z = sign(v.z); 216054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.w = sign(v.w); 216154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return ret; 216254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 216354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 216454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(sin); 216554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 216654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) sincos(half v, half *cosptr) { 216754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar *cosptr = cos(v); 216854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return sin(v); 216954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 217054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar// TODO verify if LLVM eliminates the duplicate convert_float2 217154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) sincos(half2 v, half2 *cosptr) { 217254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar *cosptr = cos(v); 217354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return sin(v); 217454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 217554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) sincos(half3 v, half3 *cosptr) { 217654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar *cosptr = cos(v); 217754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return sin(v); 217854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 217954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) sincos(half4 v, half4 *cosptr) { 218054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar *cosptr = cos(v); 218154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return sin(v); 218254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 218354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 218454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(sinh); 218554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(sinpi); 218654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(sqrt); 218754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 218854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) step(half edge, half v) { 218954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return (v < edge) ? 0.f : 1.f; 219054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 219154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) step(half2 edge, half2 v) { 219254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half2 r; 219354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = (v.x < edge.x) ? 0.f : 1.f; 219454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = (v.y < edge.y) ? 0.f : 1.f; 219554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 219654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 219754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) step(half3 edge, half3 v) { 219854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half3 r; 219954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = (v.x < edge.x) ? 0.f : 1.f; 220054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = (v.y < edge.y) ? 0.f : 1.f; 220154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.z = (v.z < edge.z) ? 0.f : 1.f; 220254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 220354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 220454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) step(half4 edge, half4 v) { 220554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half4 r; 220654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = (v.x < edge.x) ? 0.f : 1.f; 220754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = (v.y < edge.y) ? 0.f : 1.f; 220854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.z = (v.z < edge.z) ? 0.f : 1.f; 220954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.w = (v.w < edge.w) ? 0.f : 1.f; 221054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 221154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 221254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) step(half2 edge, half v) { 221354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half2 r; 221454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = (v < edge.x) ? 0.f : 1.f; 221554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = (v < edge.y) ? 0.f : 1.f; 221654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 221754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 221854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) step(half3 edge, half v) { 221954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half3 r; 222054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = (v < edge.x) ? 0.f : 1.f; 222154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = (v < edge.y) ? 0.f : 1.f; 222254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.z = (v < edge.z) ? 0.f : 1.f; 222354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 222454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 222554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) step(half4 edge, half v) { 222654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half4 r; 222754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = (v < edge.x) ? 0.f : 1.f; 222854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = (v < edge.y) ? 0.f : 1.f; 222954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.z = (v < edge.z) ? 0.f : 1.f; 223054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.w = (v < edge.w) ? 0.f : 1.f; 223154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 223254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 223354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) step(half edge, half2 v) { 223454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half2 r; 223554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = (v.x < edge) ? 0.f : 1.f; 223654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = (v.y < edge) ? 0.f : 1.f; 223754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 223854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 223954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) step(half edge, half3 v) { 224054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half3 r; 224154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = (v.x < edge) ? 0.f : 1.f; 224254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = (v.y < edge) ? 0.f : 1.f; 224354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.z = (v.z < edge) ? 0.f : 1.f; 224454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 224554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 224654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) step(half edge, half4 v) { 224754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half4 r; 224854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = (v.x < edge) ? 0.f : 1.f; 224954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = (v.y < edge) ? 0.f : 1.f; 225054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.z = (v.z < edge) ? 0.f : 1.f; 225154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.w = (v.w < edge) ? 0.f : 1.f; 225254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 225354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 225454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 225554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(tan); 225654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(tanh); 225754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(tanpi); 225854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(tgamma); 225954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(trunc); // TODO: rethink: needs half-specific implementation? 226054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 226154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_acos); 226254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_acosh); 226354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_acospi); 226454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_asin); 226554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_asinh); 226654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_asinpi); 226754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_atan); 226854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_atanh); 226954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_atanpi); 227054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(native_atan2); 227154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(native_atan2pi); 227254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 227354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_cbrt); 227454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_cos); 227554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_cosh); 227654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_cospi); 227754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 227854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarH_FUNC_HN_HN(native_distance); 227954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(native_divide); 228054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 228154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_exp); 228254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_exp10); 228354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_exp2); 228454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_expm1); 228554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 228654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(native_hypot); 228754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarH_FUNC_HN(native_length); 228854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 228954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_log); 229054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_log10); 229154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_log1p); 229254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_log2); 229354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 229454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_normalize); 229554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 229654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(native_powr); // TODO are parameter limits different for half? 229754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 229854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_recip); 229954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_IN(native_rootn); 230054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_rsqrt); 230154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 230254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_sin); 230354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 230454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) native_sincos(half v, half *cosptr) { 230554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return sincos(v, cosptr); 230654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 230754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) native_sincos(half2 v, half2 *cosptr) { 230854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return sincos(v, cosptr); 230954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 231054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) native_sincos(half3 v, half3 *cosptr) { 231154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return sincos(v, cosptr); 231254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 231354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) native_sincos(half4 v, half4 *cosptr) { 231454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return sincos(v, cosptr); 231554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 231654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 231754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_sinh); 231854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_sinpi); 231954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_sqrt); 232054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 232154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_tan); 232254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_tanh); 232354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_tanpi); 232454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 232554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef HN_FUNC_HN 232654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef HN_FUNC_HN_HN 232754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef HN_FUNC_HN_H 232854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef HN_FUNC_HN_HN_HN 232954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef HN_FUNC_HN_IN 233054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef H_FUNC_HN 233154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef H_FUNC_HN_HN 233254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef SCALARIZE_HN_FUNC_HN_HN 233354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 2334e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham// exports unavailable mathlib functions to compat lib 2335e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham 2336e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham#ifdef RS_COMPATIBILITY_LIB 2337e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham 2338e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham// !!! DANGER !!! 2339e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham// These functions are potentially missing on older Android versions. 2340e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham// Work around the issue by supplying our own variants. 2341e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham// !!! DANGER !!! 2342e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham 2343e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham// The logbl() implementation is taken from the latest bionic/, since 2344e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham// double == long double on Android. 2345e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern "C" long double logbl(long double x) { return logb(x); } 2346e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham 2347e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham// __aeabi_idiv0 is a missing function in libcompiler_rt.so, so we just 2348e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham// pick the simplest implementation based on the ARM EABI doc. 2349e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern "C" int __aeabi_idiv0(int v) { return v; } 2350e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham 2351e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham#endif // compatibility lib 2352