rs_cl.c revision fb99e0f905b0f73a505c7900b434531ce7c3e2e5
1be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet#include "rs_core.rsh" 25a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 35a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) convert_float2(int2 c); 45a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) convert_float3(int3 c); 55a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) convert_float4(int4 c); 65a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 75a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int2 __attribute__((overloadable)) convert_int2(float2 c); 85a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int3 __attribute__((overloadable)) convert_int3(float3 c); 95a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int4 __attribute__((overloadable)) convert_int4(float4 c); 105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fmin(float v, float v2); 135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fmin(float2 v, float v2); 145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fmin(float3 v, float v2); 155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fmin(float4 v, float v2); 165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fmax(float v, float v2); 185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fmax(float2 v, float v2); 195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fmax(float3 v, float v2); 205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fmax(float4 v, float v2); 215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// Float ops, 6.11.2 235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN(fnc) \ 255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fnc(float2 v) { \ 265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; \ 275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fnc(float3 v) { \ 325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; \ 335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v.z); \ 365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fnc(float4 v) { \ 395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; \ 405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v.z); \ 435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v.w); \ 445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define IN_FUNC_FN(fnc) \ 485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int2 __attribute__((overloadable)) fnc(float2 v) { \ 495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int2 r; \ 505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int3 __attribute__((overloadable)) fnc(float3 v) { \ 555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int3 r; \ 565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v.z); \ 595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int4 __attribute__((overloadable)) fnc(float4 v) { \ 625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int4 r; \ 635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v.z); \ 665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v.w); \ 675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_FN(fnc) \ 715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fnc(float2 v1, float2 v2) { \ 725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; \ 735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fnc(float3 v1, float3 v2) { \ 785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; \ 795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z); \ 825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fnc(float4 v1, float4 v2) { \ 855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; \ 865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z); \ 895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, v2.w); \ 905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_F(fnc) \ 945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fnc(float2 v1, float v2) { \ 955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; \ 965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2); \ 975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2); \ 985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 1005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fnc(float3 v1, float v2) { \ 1015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; \ 1025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2); \ 1035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2); \ 1045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2); \ 1055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 1075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fnc(float4 v1, float v2) { \ 1085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; \ 1095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2); \ 1105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2); \ 1115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2); \ 1125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, v2); \ 1135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 1155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_IN(fnc) \ 1175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fnc(float2 v1, int2 v2) { \ 1185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; \ 1195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 1205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 1215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 1235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fnc(float3 v1, int3 v2) { \ 1245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; \ 1255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 1265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 1275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z); \ 1285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 1305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fnc(float4 v1, int4 v2) { \ 1315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; \ 1325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 1335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 1345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z); \ 1355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, v2.w); \ 1365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 1385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_I(fnc) \ 1405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fnc(float2 v1, int v2) { \ 1415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; \ 1425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2); \ 1435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2); \ 1445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 1465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fnc(float3 v1, int v2) { \ 1475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; \ 1485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2); \ 1495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2); \ 1505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2); \ 1515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 1535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fnc(float4 v1, int v2) { \ 1545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; \ 1555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2); \ 1565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2); \ 1575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2); \ 1585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, v2); \ 1595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 1615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_PFN(fnc) \ 1635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) \ 1645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(float2 v1, float2 *v2) { \ 1655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; \ 1665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float t[2]; \ 1675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, &t[0]); \ 1685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, &t[1]); \ 1695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->x = t[0]; \ 1705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->y = t[1]; \ 1715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 1735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) \ 1745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(float3 v1, float3 *v2) { \ 1755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; \ 1765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float t[3]; \ 1775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, &t[0]); \ 1785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, &t[1]); \ 1795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, &t[2]); \ 1805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->x = t[0]; \ 1815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->y = t[1]; \ 1825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->z = t[2]; \ 1835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 1855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) \ 1865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(float4 v1, float4 *v2) { \ 1875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; \ 1885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float t[4]; \ 1895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, &t[0]); \ 1905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, &t[1]); \ 1915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, &t[2]); \ 1925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, &t[3]); \ 1935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->x = t[0]; \ 1945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->y = t[1]; \ 1955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->z = t[2]; \ 1965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->w = t[3]; \ 1975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 1985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 1995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_PIN(fnc) \ 2015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fnc(float2 v1, int2 *v2) { \ 2025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; \ 2035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int t[2]; \ 2045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, &t[0]); \ 2055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, &t[1]); \ 2065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->x = t[0]; \ 2075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->y = t[1]; \ 2085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 2095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 2105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fnc(float3 v1, int3 *v2) { \ 2115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; \ 2125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int t[3]; \ 2135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, &t[0]); \ 2145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, &t[1]); \ 2155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, &t[2]); \ 2165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->x = t[0]; \ 2175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->y = t[1]; \ 2185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->z = t[2]; \ 2195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 2205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 2215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fnc(float4 v1, int4 *v2) { \ 2225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; \ 2235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int t[4]; \ 2245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, &t[0]); \ 2255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, &t[1]); \ 2265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, &t[2]); \ 2275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, &t[3]); \ 2285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->x = t[0]; \ 2295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->y = t[1]; \ 2305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->z = t[2]; \ 2315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2->w = t[3]; \ 2325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 2335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_FN_FN(fnc) \ 2365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) \ 2375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(float2 v1, float2 v2, float2 v3) { \ 2385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; \ 2395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x, v3.x); \ 2405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y, v3.y); \ 2415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 2425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 2435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) \ 2445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(float3 v1, float3 v2, float3 v3) { \ 2455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; \ 2465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x, v3.x); \ 2475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y, v3.y); \ 2485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z, v3.z); \ 2495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 2505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 2515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) \ 2525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(float4 v1, float4 v2, float4 v3) { \ 2535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; \ 2545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x, v3.x); \ 2555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y, v3.y); \ 2565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z, v3.z); \ 2575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, v2.w, v3.w); \ 2585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 2595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_FN_PIN(fnc) \ 2625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) \ 2635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(float2 v1, float2 v2, int2 *v3) { \ 2645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; \ 2655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int t[2]; \ 2665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x, &t[0]); \ 2675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y, &t[1]); \ 2685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v3->x = t[0]; \ 2695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v3->y = t[1]; \ 2705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 2715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 2725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) \ 2735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(float3 v1, float3 v2, int3 *v3) { \ 2745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; \ 2755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int t[3]; \ 2765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x, &t[0]); \ 2775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y, &t[1]); \ 2785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z, &t[2]); \ 2795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v3->x = t[0]; \ 2805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v3->y = t[1]; \ 2815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v3->z = t[2]; \ 2825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 2835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 2845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) \ 2855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(float4 v1, float4 v2, int4 *v3) { \ 2865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; \ 2875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int t[4]; \ 2885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x, &t[0]); \ 2895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y, &t[1]); \ 2905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z, &t[2]); \ 2915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, v2.w, &t[3]); \ 2925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v3->x = t[0]; \ 2935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v3->y = t[1]; \ 2945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v3->z = t[2]; \ 2955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v3->w = t[3]; \ 2965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 2975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic const int iposinf = 0x7f800000; 3005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic const int ineginf = 0xff800000; 3015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic const float posinf() { 3035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float f = *((float*)&iposinf); 3045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return f; 3055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic const float neginf() { 3085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float f = *((float*)&ineginf); 3095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return f; 3105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic bool isinf(float f) { 3135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int i = *((int*)(void*)&f); 3145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (i == iposinf) || (i == ineginf); 3155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic bool isnan(float f) { 3185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int i = *((int*)(void*)&f); 3195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (((i & 0x7f800000) == 0x7f800000) && (i & 0x007fffff)); 3205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic bool isposzero(float f) { 3235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int i = *((int*)(void*)&f); 3245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (i == 0x00000000); 3255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic bool isnegzero(float f) { 3285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int i = *((int*)(void*)&f); 3295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (i == 0x80000000); 3305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic bool iszero(float f) { 3335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return isposzero(f) || isnegzero(f); 3345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) acos(float); 3385a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(acos) 3395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) acosh(float); 3415a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(acosh) 3425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) acospi(float v) { 3455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return acos(v) / M_PI; 3465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3475a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(acospi) 3485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) asin(float); 3505a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(asin) 3515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) asinh(float); 3535a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(asinh) 3545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) asinpi(float v) { 3565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return asin(v) / M_PI; 3575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3585a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(asinpi) 3595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) atan(float); 3615a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(atan) 3625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) atan2(float, float); 3645a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(atan2) 3655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) atanh(float); 3675a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(atanh) 3685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) atanpi(float v) { 3705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return atan(v) / M_PI; 3715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3725a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(atanpi) 3735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) atan2pi(float y, float x) { 3765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return atan2(y, x) / M_PI; 3775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3785a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(atan2pi) 3795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) cbrt(float); 3815a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(cbrt) 3825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) ceil(float); 3845a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(ceil) 3855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) copysign(float, float); 3875a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(copysign) 3885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) cos(float); 3905a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(cos) 3915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) cosh(float); 3935a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(cosh) 3945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) cospi(float v) { 3965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return cos(v * M_PI); 3975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3985a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(cospi) 3995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) erfc(float); 4015a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(erfc) 4025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) erf(float); 4045a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(erf) 4055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) exp(float); 4075a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(exp) 4085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) exp2(float); 4105a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(exp2) 4115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) pow(float, float); 4135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) exp10(float v) { 4155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return exp2(v * 3.321928095f); 4165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 4175a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(exp10) 4185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) expm1(float); 4205a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(expm1) 4215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fabs(float v) { 4235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int i = *((int*)(void*)&v) & 0x7fffffff; 4245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return *((float*)(void*)&i); 4255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 4265a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(fabs) 4275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fdim(float, float); 4295a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(fdim) 4305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) floor(float); 4325a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(floor) 4335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fma(float, float, float); 4355a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN_FN(fma) 4365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fmin(float, float); 4385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fmod(float, float); 4405a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(fmod) 4415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fract(float v, float *iptr) { 4435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int i = (int)floor(v); 4445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (iptr) { 4455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines iptr[0] = i; 4465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 4475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fmin(v - i, 0x1.fffffep-1f); 4485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 4495a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_PFN(fract) 4505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) frexp(float, int *); 4525a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_PIN(frexp) 4535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) hypot(float, float); 4555a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(hypot) 4565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int __attribute__((overloadable)) ilogb(float); 4585a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesIN_FUNC_FN(ilogb) 4595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) ldexp(float, int); 4615a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_IN(ldexp) 4625a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_I(ldexp) 4635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) lgamma(float); 4655a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(lgamma) 4665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) lgamma(float, int*); 4675a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_PIN(lgamma) 4685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) log(float); 4705a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(log) 4715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) log10(float); 4735a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(log10) 4745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) log2(float v) { 4775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return log10(v) * 3.321928095f; 4785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 4795a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(log2) 4805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) log1p(float); 4825a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(log1p) 4835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) logb(float); 4855a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(logb) 4865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 4875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) mad(float a, float b, float c) { 4885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return a * b + c; 4895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 4905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) mad(float2 a, float2 b, float2 c) { 4915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return a * b + c; 4925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 4935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) mad(float3 a, float3 b, float3 c) { 4945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return a * b + c; 4955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 4965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) mad(float4 a, float4 b, float4 c) { 4975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return a * b + c; 4985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 4995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) modf(float, float *); 5015a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_PFN(modf); 5025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) nan(uint v) { 5045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float f[1]; 5055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines uint32_t *ip = (uint32_t *)f; 5065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *ip = v | 0x7fc00000; 5075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return f[0]; 5085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) nextafter(float, float); 5115a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(nextafter) 5125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 513fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// This function must be defined here if we're compiling with debug info 514fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// (libclcore_g.bc), because we need a C source to get debug information. 515fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// Otherwise the implementation can be found in IR. 516fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#if defined(RS_G_RUNTIME) 517fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckhamextern float __attribute__((overloadable)) SC_powf(float, float); 518fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckhamfloat __attribute__((overloadable)) pow(float v1, float v2) { 519fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham return SC_powf(v1, v2); 520fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham} 521fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#endif defined(RS_G_RUNTIME) 5225a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(pow) 5235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) pown(float v, int p) { 5250b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet /* The mantissa of a float has fewer bits than an int (24 effective vs. 31). 5260b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet * For very large ints, we'll lose whether the exponent is even or odd, making 527bcd5b9af756d10317faf54fa3742f89dfacef152Jean-Luc Brouillet * the selection of a correct sign incorrect. We correct this. Use copysign 528bcd5b9af756d10317faf54fa3742f89dfacef152Jean-Luc Brouillet * to handle the negative zero case. 5290b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet */ 530bcd5b9af756d10317faf54fa3742f89dfacef152Jean-Luc Brouillet float sign = (p & 0x1) ? copysign(1.f, v) : 1.f; 5310b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet float f = pow(v, (float)p); 5320b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet return copysign(f, sign); 5330b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet} 5340b0bcff691d047da1d658889866c6a0347850f1cJean-Luc BrouilletFN_FUNC_FN_IN(pown) 5355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) powr(float v, float p) { 5375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, p); 5385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) powr(float2 v, float2 p) { 5405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, p); 5415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) powr(float3 v, float3 p) { 5435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, p); 5445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) powr(float4 v, float4 p) { 5465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, p); 5475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) remainder(float, float); 5505a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(remainder) 5515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) remquo(float, float, int *); 5535a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN_PIN(remquo) 5545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) rint(float); 5565a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(rint) 5575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) rootn(float v, int r) { 5595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r == 0) { 5603a3dfe7ecba55a3a832b44e4337276c09a6a25e9Dan Albert return posinf(); 5615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (iszero(v)) { 5645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r < 0) { 5655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r & 1) { 5665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return copysign(posinf(), v); 5675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } else { 5685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return posinf(); 5695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } else { 5715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r & 1) { 5725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return copysign(0.f, v); 5735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } else { 5745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return 0.f; 5755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (!isinf(v) && !isnan(v) && (v < 0.f)) { 5805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r & 1) { 5815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (-1.f * pow(-1.f * v, 1.f / r)); 5825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } else { 5835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return nan(0); 5845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, 1.f / r); 5885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5895a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_IN(rootn); 5905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) round(float); 5925a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(round) 5935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sqrt(float); 5965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) rsqrt(float v) { 5975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return 1.f / sqrt(v); 5985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 599146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 600fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#if !defined(ARCH_X86_HAVE_SSSE3) || defined(RS_DEBUG_RUNTIME) || defined(RS_G_RUNTIME) 601a673fb0db28eac2300fcfa04549138c1c9202014Stephen Hines// These functions must be defined here if we are not using the SSE 602a673fb0db28eac2300fcfa04549138c1c9202014Stephen Hines// implementation, which includes when we are built as part of the 603fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// debug runtime (libclcore_debug.bc) or compiling with debug info. 604fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#if defined(RS_G_RUNTIME) 605fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckhamextern float __attribute__((overloadable)) SC_sqrtf(float); 606fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckhamfloat __attribute__((overloadable)) sqrt(float v) { 607fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham return SC_sqrtf(v); 608fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham} 609fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#endif defined(RS_G_RUNTIME) 610fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham 611146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen HinesFN_FUNC_FN(sqrt) 612a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#else 613a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsextern float2 __attribute__((overloadable)) sqrt(float2); 614a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsextern float3 __attribute__((overloadable)) sqrt(float3); 615a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsextern float4 __attribute__((overloadable)) sqrt(float4); 616fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#endif // !defined(ARCH_X86_HAVE_SSSE3) || defined(RS_DEBUG_RUNTIME) || defined(RS_G_RUNTIME) 617146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 6185a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(rsqrt) 6195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sin(float); 6215a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sin) 6225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sincos(float v, float *cosptr) { 6245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *cosptr = cos(v); 6255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v); 6265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) sincos(float2 v, float2 *cosptr) { 6285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *cosptr = cos(v); 6295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v); 6305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) sincos(float3 v, float3 *cosptr) { 6325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *cosptr = cos(v); 6335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v); 6345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) sincos(float4 v, float4 *cosptr) { 6365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *cosptr = cos(v); 6375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v); 6385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sinh(float); 6415a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sinh) 6425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sinpi(float v) { 6445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v * M_PI); 6455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6465a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sinpi) 6475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) tan(float); 6495a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tan) 6505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) tanh(float); 6525a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tanh) 6535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) tanpi(float v) { 6555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return tan(v * M_PI); 6565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6575a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tanpi) 6585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) tgamma(float); 6615a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tgamma) 6625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) trunc(float); 6645a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(trunc) 6655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// Int ops (partial), 6.11.3 6675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define XN_FUNC_YN(typeout, fnc, typein) \ 6695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout __attribute__((overloadable)) fnc(typein); \ 6705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout##2 __attribute__((overloadable)) fnc(typein##2 v) { \ 6715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines typeout##2 r; \ 6725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 6735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 6745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 6755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 6765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout##3 __attribute__((overloadable)) fnc(typein##3 v) { \ 6775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines typeout##3 r; \ 6785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 6795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 6805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v.z); \ 6815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 6825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 6835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout##4 __attribute__((overloadable)) fnc(typein##4 v) { \ 6845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines typeout##4 r; \ 6855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 6865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 6875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v.z); \ 6885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v.w); \ 6895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 6905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define UIN_FUNC_IN(fnc) \ 6945a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uchar, fnc, char) \ 6955a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(ushort, fnc, short) \ 6965a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uint, fnc, int) 6975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define IN_FUNC_IN(fnc) \ 6995a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uchar, fnc, uchar) \ 7005a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(char, fnc, char) \ 7015a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(ushort, fnc, ushort) \ 7025a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(short, fnc, short) \ 7035a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uint, fnc, uint) \ 7045a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(int, fnc, int) 7055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define XN_FUNC_XN_XN_BODY(type, fnc, body) \ 7085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type __attribute__((overloadable)) \ 7095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(type v1, type v2) { \ 7105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return body; \ 7115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 7125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type##2 __attribute__((overloadable)) \ 7135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(type##2 v1, type##2 v2) { \ 7145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines type##2 r; \ 7155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 7165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 7175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 7185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 7195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type##3 __attribute__((overloadable)) \ 7205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(type##3 v1, type##3 v2) { \ 7215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines type##3 r; \ 7225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 7235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 7245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z); \ 7255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 7265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 7275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type##4 __attribute__((overloadable)) \ 7285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(type##4 v1, type##4 v2) { \ 7295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines type##4 r; \ 7305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 7315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 7325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z); \ 7335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, v2.w); \ 7345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 7355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define IN_FUNC_IN_IN_BODY(fnc, body) \ 7385a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(uchar, fnc, body) \ 7395a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(char, fnc, body) \ 7405a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(ushort, fnc, body) \ 7415a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(short, fnc, body) \ 7425a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(uint, fnc, body) \ 7435a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(int, fnc, body) \ 7445a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(float, fnc, body) 7455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/** 7485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines * abs 7495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines */ 7505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable)) abs(int32_t v) { 7515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v < 0) 7525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return -v; 7535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v; 7545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint16_t __attribute__((overloadable)) abs(int16_t v) { 7565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v < 0) 7575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return -v; 7585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v; 7595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint8_t __attribute__((overloadable)) abs(int8_t v) { 7615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v < 0) 7625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return -v; 7635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v; 7645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/** 7675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines * clz 768c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines * __builtin_clz only accepts a 32-bit unsigned int, so every input will be 769c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines * expanded to 32 bits. For our smaller data types, we need to subtract off 770c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines * these unused top bits (that will be always be composed of zeros). 7715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines */ 7725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable)) clz(uint32_t v) { 7735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return __builtin_clz(v); 7745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint16_t __attribute__((overloadable)) clz(uint16_t v) { 776c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines return __builtin_clz(v) - 16; 7775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint8_t __attribute__((overloadable)) clz(uint8_t v) { 779c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines return __builtin_clz(v) - 24; 7805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int32_t __attribute__((overloadable)) clz(int32_t v) { 782c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines return __builtin_clz(v); 7835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int16_t __attribute__((overloadable)) clz(int16_t v) { 785c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines return __builtin_clz(((uint32_t)v) & 0x0000ffff) - 16; 7865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int8_t __attribute__((overloadable)) clz(int8_t v) { 788c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines return __builtin_clz(((uint32_t)v) & 0x000000ff) - 24; 7895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7925a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesUIN_FUNC_IN(abs) 7935a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesIN_FUNC_IN(clz) 7945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// 6.11.4 7975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) degrees(float radians) { 8005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return radians * (180.f / M_PI); 8015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) degrees(float2 radians) { 8035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return radians * (180.f / M_PI); 8045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) degrees(float3 radians) { 8065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return radians * (180.f / M_PI); 8075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) degrees(float4 radians) { 8095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return radians * (180.f / M_PI); 8105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) mix(float start, float stop, float amount) { 8135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 8145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) mix(float2 start, float2 stop, float2 amount) { 8165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 8175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) mix(float3 start, float3 stop, float3 amount) { 8195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 8205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) mix(float4 start, float4 stop, float4 amount) { 8225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 8235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) mix(float2 start, float2 stop, float amount) { 8255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 8265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) mix(float3 start, float3 stop, float amount) { 8285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 8295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) mix(float4 start, float4 stop, float amount) { 8315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 8325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) radians(float degrees) { 8355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return degrees * (M_PI / 180.f); 8365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) radians(float2 degrees) { 8385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return degrees * (M_PI / 180.f); 8395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) radians(float3 degrees) { 8415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return degrees * (M_PI / 180.f); 8425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) radians(float4 degrees) { 8445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return degrees * (M_PI / 180.f); 8455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) step(float edge, float v) { 8485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (v < edge) ? 0.f : 1.f; 8495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) step(float2 edge, float2 v) { 8515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; 8525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v.x < edge.x) ? 0.f : 1.f; 8535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v.y < edge.y) ? 0.f : 1.f; 8545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) step(float3 edge, float3 v) { 8575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; 8585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v.x < edge.x) ? 0.f : 1.f; 8595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v.y < edge.y) ? 0.f : 1.f; 8605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = (v.z < edge.z) ? 0.f : 1.f; 8615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) step(float4 edge, float4 v) { 8645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; 8655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v.x < edge.x) ? 0.f : 1.f; 8665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v.y < edge.y) ? 0.f : 1.f; 8675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = (v.z < edge.z) ? 0.f : 1.f; 8685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = (v.w < edge.w) ? 0.f : 1.f; 8695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) step(float2 edge, float v) { 8725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; 8735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v < edge.x) ? 0.f : 1.f; 8745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v < edge.y) ? 0.f : 1.f; 8755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) step(float3 edge, float v) { 8785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; 8795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v < edge.x) ? 0.f : 1.f; 8805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v < edge.y) ? 0.f : 1.f; 8815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = (v < edge.z) ? 0.f : 1.f; 8825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) step(float4 edge, float v) { 8855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; 8865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v < edge.x) ? 0.f : 1.f; 8875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v < edge.y) ? 0.f : 1.f; 8885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = (v < edge.z) ? 0.f : 1.f; 8895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = (v < edge.w) ? 0.f : 1.f; 8905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8920ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouilletextern float2 __attribute__((overloadable)) step(float edge, float2 v) { 8930ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet float2 r; 8940ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.x = (v.x < edge) ? 0.f : 1.f; 8950ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.y = (v.y < edge) ? 0.f : 1.f; 8960ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet return r; 8970ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet} 8980ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouilletextern float3 __attribute__((overloadable)) step(float edge, float3 v) { 8990ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet float3 r; 9000ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.x = (v.x < edge) ? 0.f : 1.f; 9010ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.y = (v.y < edge) ? 0.f : 1.f; 9020ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.z = (v.z < edge) ? 0.f : 1.f; 9030ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet return r; 9040ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet} 9050ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouilletextern float4 __attribute__((overloadable)) step(float edge, float4 v) { 9060ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet float4 r; 9070ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.x = (v.x < edge) ? 0.f : 1.f; 9080ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.y = (v.y < edge) ? 0.f : 1.f; 9090ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.z = (v.z < edge) ? 0.f : 1.f; 9100ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.w = (v.w < edge) ? 0.f : 1.f; 9110ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet return r; 9120ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet} 9135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sign(float v) { 9155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v > 0) return 1.f; 9165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v < 0) return -1.f; 9175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v; 9185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9195a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sign) 9205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// 6.11.5 9235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) cross(float3 lhs, float3 rhs) { 9245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; 9255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = lhs.y * rhs.z - lhs.z * rhs.y; 9265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = lhs.z * rhs.x - lhs.x * rhs.z; 9275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = lhs.x * rhs.y - lhs.y * rhs.x; 9285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 9295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) cross(float4 lhs, float4 rhs) { 9325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; 9335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = lhs.y * rhs.z - lhs.z * rhs.y; 9345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = lhs.z * rhs.x - lhs.x * rhs.z; 9355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = lhs.x * rhs.y - lhs.y * rhs.x; 9365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = 0.f; 9375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 9385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 940fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#if !defined(ARCH_X86_HAVE_SSSE3) || defined(RS_DEBUG_RUNTIME) || defined(RS_G_RUNTIME) 941a673fb0db28eac2300fcfa04549138c1c9202014Stephen Hines// These functions must be defined here if we are not using the SSE 942a673fb0db28eac2300fcfa04549138c1c9202014Stephen Hines// implementation, which includes when we are built as part of the 943fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// debug runtime (libclcore_debug.bc) or compiling with debug info. 944146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 945146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) dot(float lhs, float rhs) { 946146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return lhs * rhs; 947146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 948146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) dot(float2 lhs, float2 rhs) { 949146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return lhs.x*rhs.x + lhs.y*rhs.y; 950146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 951146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) dot(float3 lhs, float3 rhs) { 952146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return lhs.x*rhs.x + lhs.y*rhs.y + lhs.z*rhs.z; 953146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 954146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) dot(float4 lhs, float4 rhs) { 955146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return lhs.x*rhs.x + lhs.y*rhs.y + lhs.z*rhs.z + lhs.w*rhs.w; 956146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 957146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 958146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) length(float v) { 959146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return fabs(v); 960146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 961146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) length(float2 v) { 962146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return sqrt(v.x*v.x + v.y*v.y); 963146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 964146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) length(float3 v) { 965146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return sqrt(v.x*v.x + v.y*v.y + v.z*v.z); 966146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 967146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) length(float4 v) { 968146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return sqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w); 969146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 970146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 971146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines#else 972146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 9735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float v); 9745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float2 v); 9755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float3 v); 9765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float4 v); 9775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 978fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#endif // !defined(ARCH_X86_HAVE_SSSE3) || defined(RS_DEBUG_RUNTIME) || defined(RS_G_RUNTIME) 979146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 9805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float lhs, float rhs) { 9815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return length(lhs - rhs); 9825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float2 lhs, float2 rhs) { 9845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return length(lhs - rhs); 9855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float3 lhs, float3 rhs) { 9875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return length(lhs - rhs); 9885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float4 lhs, float4 rhs) { 9905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return length(lhs - rhs); 9915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9933e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet/* For the normalization functions, vectors of length 0 should simply be 9943e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet * returned (i.e. all the components of that vector are 0). 9953e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet */ 9965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) normalize(float v) { 9973e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet if (v == 0.0f) { 9983e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return 0.0f; 9993e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet } else if (v < 0.0f) { 10003e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return -1.0f; 10013e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet } else { 10023e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return 1.0f; 10033e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet } 10045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) normalize(float2 v) { 10063e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet float l = length(v); 10073e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return l == 0.0f ? v : v / l; 10085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) normalize(float3 v) { 10103e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet float l = length(v); 10113e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return l == 0.0f ? v : v / l; 10125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) normalize(float4 v) { 10143e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet float l = length(v); 10153e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return l == 0.0f ? v : v / l; 10165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1018ba92a7085bbb8916334a6571ff33355873883173Jason Samsextern float __attribute__((overloadable)) half_sqrt(float v) { 1019ba92a7085bbb8916334a6571ff33355873883173Jason Sams return sqrt(v); 1020ba92a7085bbb8916334a6571ff33355873883173Jason Sams} 1021ba92a7085bbb8916334a6571ff33355873883173Jason SamsFN_FUNC_FN(half_sqrt) 10225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float v) { 1024582b3646d6634f74a13828cceb1414823c18e66fStephen Hines return fabs(v); 10255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float2 v) { 10275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return half_sqrt(v.x*v.x + v.y*v.y); 10285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float3 v) { 10305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return half_sqrt(v.x*v.x + v.y*v.y + v.z*v.z); 10315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float4 v) { 10335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return half_sqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w); 10345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float lhs, float rhs) { 10375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fast_length(lhs - rhs); 10385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float2 lhs, float2 rhs) { 10405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fast_length(lhs - rhs); 10415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float3 lhs, float3 rhs) { 10435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fast_length(lhs - rhs); 10445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float4 lhs, float4 rhs) { 10465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fast_length(lhs - rhs); 10475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) half_rsqrt(float); 10505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10513e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet/* For the normalization functions, vectors of length 0 should simply be 10523e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet * returned (i.e. all the components of that vector are 0). 10533e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet */ 10545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_normalize(float v) { 10553e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet if (v == 0.0f) { 10563e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return 0.0f; 10573e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet } else if (v < 0.0f) { 10583e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return -1.0f; 10593e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet } else { 10603e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return 1.0f; 10613e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet } 10625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10633e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet// If the length is 0, then rlength should be NaN. 10645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fast_normalize(float2 v) { 10653e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet float rlength = half_rsqrt(v.x*v.x + v.y*v.y); 10663e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return (rlength == rlength) ? v * rlength : v; 10675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fast_normalize(float3 v) { 10693e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet float rlength = half_rsqrt(v.x*v.x + v.y*v.y + v.z*v.z); 10703e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return (rlength == rlength) ? v * rlength : v; 10715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fast_normalize(float4 v) { 10733e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet float rlength = half_rsqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w); 10743e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return (rlength == rlength) ? v * rlength : v; 10755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1077ba92a7085bbb8916334a6571ff33355873883173Jason Samsextern float __attribute__((overloadable)) half_recip(float v) { 1078ba92a7085bbb8916334a6571ff33355873883173Jason Sams return 1.f / v; 1079ba92a7085bbb8916334a6571ff33355873883173Jason Sams} 10805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/* 10825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) approx_atan(float x) { 10835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (x == 0.f) 10845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return 0.f; 10855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (x < 0.f) 10865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return -1.f * approx_atan(-1.f * x); 10875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (x > 1.f) 10885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return M_PI_2 - approx_atan(approx_recip(x)); 10895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return x * approx_recip(1.f + 0.28f * x*x); 10905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10915a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(approx_atan) 10925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines*/ 10935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinestypedef union 10955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines{ 10965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float fv; 10975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t iv; 10985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} ieee_float_shape_type; 10995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/* Get a 32 bit int from a float. */ 11015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define GET_FLOAT_WORD(i,d) \ 11035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesdo { \ 11045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ieee_float_shape_type gf_u; \ 11055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines gf_u.fv = (d); \ 11065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (i) = gf_u.iv; \ 11075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} while (0) 11085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/* Set a float from a 32 bit int. */ 11105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define SET_FLOAT_WORD(d,i) \ 11125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesdo { \ 11135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ieee_float_shape_type sf_u; \ 11145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines sf_u.iv = (i); \ 11155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (d) = sf_u.fv; \ 11165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} while (0) 11175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// Valid -125 to 125 11215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_exp2(float v) { 11225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t iv = (int)v; 11235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t x = iv + (iv >> 31); // ~floor(v) 11245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float r = (v - x); 11255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float fo; 11275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines SET_FLOAT_WORD(fo, (x + 127) << 23); 11285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r *= 0.694f; // ~ log(e) / log(2) 11305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float r2 = r*r; 11315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float adj = 1.f + r + (r2 * 0.5f) + (r2*r * 0.166666f) + (r2*r2 * 0.0416666f); 11325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fo * adj; 11335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_exp2(float2 v) { 11365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int2 iv = convert_int2(v); 11375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int2 x = iv + (iv >> (int2)31);//floor(v); 11385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r = (v - convert_float2(x)); 11395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines x += 127; 11415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 fo = (float2)(x << (int2)23); 11435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r *= 0.694f; // ~ log(e) / log(2) 11455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r2 = r*r; 11465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 adj = 1.f + r + (r2 * 0.5f) + (r2*r * 0.166666f) + (r2*r2 * 0.0416666f); 11475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fo * adj; 11485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_exp2(float4 v) { 11515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int4 iv = convert_int4(v); 11525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int4 x = iv + (iv >> (int4)31);//floor(v); 11535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r = (v - convert_float4(x)); 11545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines x += 127; 11565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 fo = (float4)(x << (int4)23); 11585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r *= 0.694f; // ~ log(e) / log(2) 11605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r2 = r*r; 11615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 adj = 1.f + r + (r2 * 0.5f) + (r2*r * 0.166666f) + (r2*r2 * 0.0416666f); 11625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fo * adj; 11635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_exp2(float3 v) { 11665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 t = 1.f; 11675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines t.xyz = v; 11685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(t).xyz; 11695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_exp(float v) { 11735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 1.442695041f); 11745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_exp(float2 v) { 11765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 1.442695041f); 11775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_exp(float3 v) { 11795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 1.442695041f); 11805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_exp(float4 v) { 11825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 1.442695041f); 11835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_exp10(float v) { 11865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 3.321928095f); 11875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_exp10(float2 v) { 11895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 3.321928095f); 11905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_exp10(float3 v) { 11925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 3.321928095f); 11935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_exp10(float4 v) { 11955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 3.321928095f); 11965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_log2(float v) { 11995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t ibits; 12005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines GET_FLOAT_WORD(ibits, v); 12015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t e = (ibits >> 23) & 0xff; 12035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ibits &= 0x7fffff; 12055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ibits |= 127 << 23; 12065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float ir; 12085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines SET_FLOAT_WORD(ir, ibits); 12095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ir -= 1.5f; 12105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float ir2 = ir*ir; 1211c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams float adj2 = (0.405465108f / 0.693147181f) + 1212c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams ((0.666666667f / 0.693147181f) * ir) - 1213c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams ((0.222222222f / 0.693147181f) * ir2) + 1214c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams ((0.098765432f / 0.693147181f) * ir*ir2) - 1215c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams ((0.049382716f / 0.693147181f) * ir2*ir2) + 1216c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams ((0.026337449f / 0.693147181f) * ir*ir2*ir2) - 1217c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams ((0.014631916f / 0.693147181f) * ir2*ir2*ir2); 12185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (float)(e - 127) + adj2; 12195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_log2(float2 v) { 12215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 v2 = {native_log2(v.x), native_log2(v.y)}; 12225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v2; 12235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_log2(float3 v) { 12255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 v2 = {native_log2(v.x), native_log2(v.y), native_log2(v.z)}; 12265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v2; 12275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_log2(float4 v) { 12295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 v2 = {native_log2(v.x), native_log2(v.y), native_log2(v.z), native_log2(v.w)}; 12305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v2; 12315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_log(float v) { 12345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 1.442695041f); 12355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_log(float2 v) { 12375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 1.442695041f); 12385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_log(float3 v) { 12405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 1.442695041f); 12415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_log(float4 v) { 12435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 1.442695041f); 12445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_log10(float v) { 12475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 3.321928095f); 12485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_log10(float2 v) { 12505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 3.321928095f); 12515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_log10(float3 v) { 12535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 3.321928095f); 12545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_log10(float4 v) { 12565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 3.321928095f); 12575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_powr(float v, float y) { 12615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float v2 = native_log2(v); 1262c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams v2 = fmax(v2 * y, -125.f); 1263c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams return native_exp2(v2); 12645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_powr(float2 v, float2 y) { 12665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 v2 = native_log2(v); 1267c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams v2 = fmax(v2 * y, -125.f); 1268c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams return native_exp2(v2); 12695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_powr(float3 v, float3 y) { 12715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 v2 = native_log2(v); 1272c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams v2 = fmax(v2 * y, -125.f); 1273c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams return native_exp2(v2); 12745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_powr(float4 v, float4 y) { 12765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 v2 = native_log2(v); 1277c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams v2 = fmax(v2 * y, -125.f); 1278c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams return native_exp2(v2); 12795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 128153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double __attribute__((overloadable)) min(double v1, double v2) { 128253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return v1 < v2 ? v1 : v2; 128353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 128453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 128553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double2 __attribute__((overloadable)) min(double2 v1, double2 v2) { 128653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams double2 r; 128753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 128853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 128953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 129053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 129153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 129253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double3 __attribute__((overloadable)) min(double3 v1, double3 v2) { 129353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams double3 r; 129453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 129553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 129653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z < v2.z ? v1.z : v2.z; 129753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 129853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 129953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 130053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double4 __attribute__((overloadable)) min(double4 v1, double4 v2) { 130153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams double4 r; 130253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 130353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 130453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z < v2.z ? v1.z : v2.z; 130553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.w = v1.w < v2.w ? v1.w : v2.w; 130653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 130753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 130853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 1309d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long __attribute__((overloadable)) min(long v1, long v2) { 131053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return v1 < v2 ? v1 : v2; 131153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1312d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long2 __attribute__((overloadable)) min(long2 v1, long2 v2) { 131353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams long2 r; 131453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 131553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 131653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 131753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1318d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long3 __attribute__((overloadable)) min(long3 v1, long3 v2) { 131953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams long3 r; 132053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 132153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 132253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z < v2.z ? v1.z : v2.z; 132353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 132453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1325d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long4 __attribute__((overloadable)) min(long4 v1, long4 v2) { 132653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams long4 r; 132753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 132853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 132953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z < v2.z ? v1.z : v2.z; 133053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.w = v1.w < v2.w ? v1.w : v2.w; 133153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 133253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 133353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 1334d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong __attribute__((overloadable)) min(ulong v1, ulong v2) { 133553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return v1 < v2 ? v1 : v2; 133653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1337d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong2 __attribute__((overloadable)) min(ulong2 v1, ulong2 v2) { 133853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams ulong2 r; 133953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 134053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 134153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 134253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1343d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong3 __attribute__((overloadable)) min(ulong3 v1, ulong3 v2) { 134453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams ulong3 r; 134553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 134653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 134753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z < v2.z ? v1.z : v2.z; 134853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 134953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1350d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong4 __attribute__((overloadable)) min(ulong4 v1, ulong4 v2) { 135153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams ulong4 r; 135253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 135353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 135453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z < v2.z ? v1.z : v2.z; 135553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.w = v1.w < v2.w ? v1.w : v2.w; 135653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 135753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 135853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 135953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double __attribute__((overloadable)) max(double v1, double v2) { 136053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return v1 > v2 ? v1 : v2; 136153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 136253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 136353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double2 __attribute__((overloadable)) max(double2 v1, double2 v2) { 136453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams double2 r; 136553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 136653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 136753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 136853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 136953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 137053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double3 __attribute__((overloadable)) max(double3 v1, double3 v2) { 137153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams double3 r; 137253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 137353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 137453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z > v2.z ? v1.z : v2.z; 137553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 137653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 137753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 137853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double4 __attribute__((overloadable)) max(double4 v1, double4 v2) { 137953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams double4 r; 138053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 138153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 138253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z > v2.z ? v1.z : v2.z; 138353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.w = v1.w > v2.w ? v1.w : v2.w; 138453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 138553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 138653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 1387d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long __attribute__((overloadable)) max(long v1, long v2) { 138853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return v1 > v2 ? v1 : v2; 138953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1390d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long2 __attribute__((overloadable)) max(long2 v1, long2 v2) { 139153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams long2 r; 139253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 139353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 139453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 139553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1396d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long3 __attribute__((overloadable)) max(long3 v1, long3 v2) { 139753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams long3 r; 139853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 139953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 140053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z > v2.z ? v1.z : v2.z; 140153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 140253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1403d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long4 __attribute__((overloadable)) max(long4 v1, long4 v2) { 140453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams long4 r; 140553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 140653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 140753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z > v2.z ? v1.z : v2.z; 140853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.w = v1.w > v2.w ? v1.w : v2.w; 140953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 141053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 141153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 1412d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong __attribute__((overloadable)) max(ulong v1, ulong v2) { 141353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return v1 > v2 ? v1 : v2; 141453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1415d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong2 __attribute__((overloadable)) max(ulong2 v1, ulong2 v2) { 141653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams ulong2 r; 141753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 141853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 141953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 142053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1421d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong3 __attribute__((overloadable)) max(ulong3 v1, ulong3 v2) { 142253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams ulong3 r; 142353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 142453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 142553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z > v2.z ? v1.z : v2.z; 142653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 142753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 1428d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong4 __attribute__((overloadable)) max(ulong4 v1, ulong4 v2) { 142953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams ulong4 r; 143053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 143153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 143253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z > v2.z ? v1.z : v2.z; 143353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.w = v1.w > v2.w ? v1.w : v2.w; 143453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 143553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 143653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 1437a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#define THUNK_NATIVE_F(fn) \ 1438a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float __attribute__((overloadable)) native_##fn(float v) { return fn(v);} \ 1439a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float2 __attribute__((overloadable)) native_##fn(float2 v) { return fn(v);} \ 1440a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float3 __attribute__((overloadable)) native_##fn(float3 v) { return fn(v);} \ 1441a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float4 __attribute__((overloadable)) native_##fn(float4 v) { return fn(v);} 1442a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1443a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#define THUNK_NATIVE_F_F(fn) \ 1444a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float __attribute__((overloadable)) native_##fn(float v1, float v2) { return fn(v1, v2);} \ 1445a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float2 __attribute__((overloadable)) native_##fn(float2 v1, float2 v2) { return fn(v1, v2);} \ 1446a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float3 __attribute__((overloadable)) native_##fn(float3 v1, float3 v2) { return fn(v1, v2);} \ 1447a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float4 __attribute__((overloadable)) native_##fn(float4 v1, float4 v2) { return fn(v1, v2);} 1448a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1449a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#define THUNK_NATIVE_F_FP(fn) \ 1450a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float __attribute__((overloadable)) native_##fn(float v1, float *v2) { return fn(v1, v2);} \ 1451a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float2 __attribute__((overloadable)) native_##fn(float2 v1, float2 *v2) { return fn(v1, v2);} \ 1452a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float3 __attribute__((overloadable)) native_##fn(float3 v1, float3 *v2) { return fn(v1, v2);} \ 1453a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float4 __attribute__((overloadable)) native_##fn(float4 v1, float4 *v2) { return fn(v1, v2);} 1454a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1455a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#define THUNK_NATIVE_F_I(fn) \ 1456a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float __attribute__((overloadable)) native_##fn(float v1, int v2) { return fn(v1, v2);} \ 1457a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float2 __attribute__((overloadable)) native_##fn(float2 v1, int2 v2) { return fn(v1, v2);} \ 1458a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float3 __attribute__((overloadable)) native_##fn(float3 v1, int3 v2) { return fn(v1, v2);} \ 1459a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams float4 __attribute__((overloadable)) native_##fn(float4 v1, int4 v2) { return fn(v1, v2);} 1460a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1461a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(acos) 1462a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(acosh) 1463a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(acospi) 1464a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(asin) 1465a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(asinh) 1466a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(asinpi) 1467a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(atan) 1468a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F_F(atan2) 1469a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(atanh) 1470a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(atanpi) 1471a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F_F(atan2pi) 1472a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(cbrt) 1473a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(cos) 1474a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(cosh) 1475a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(cospi) 1476a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(expm1) 1477a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F_F(hypot) 1478a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(log1p) 1479a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F_I(rootn) 1480a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(rsqrt) 1481a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(sqrt) 1482a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(sin) 1483a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F_FP(sincos) 1484a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(sinh) 1485a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(sinpi) 1486a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(tan) 1487a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(tanh) 1488a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(tanpi) 1489a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1490a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#undef THUNK_NATIVE_F 1491a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#undef THUNK_NATIVE_F_F 1492a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#undef THUNK_NATIVE_F_I 1493a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#undef THUNK_NATIVE_F_FP 1494a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1495a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_normalize(float v) { return fast_normalize(v);} 1496a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat2 __attribute__((overloadable)) native_normalize(float2 v) { return fast_normalize(v);} 1497a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat3 __attribute__((overloadable)) native_normalize(float3 v) { return fast_normalize(v);} 1498a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat4 __attribute__((overloadable)) native_normalize(float4 v) { return fast_normalize(v);} 1499a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1500a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_distance(float v1, float v2) { return fast_distance(v1, v2);} 1501a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_distance(float2 v1, float2 v2) { return fast_distance(v1, v2);} 1502a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_distance(float3 v1, float3 v2) { return fast_distance(v1, v2);} 1503a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_distance(float4 v1, float4 v2) { return fast_distance(v1, v2);} 1504a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1505a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_length(float v) { return fast_length(v);} 1506a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_length(float2 v) { return fast_length(v);} 1507a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_length(float3 v) { return fast_length(v);} 1508a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_length(float4 v) { return fast_length(v);} 1509a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1510a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_divide(float v1, float v2) { return v1 / v2;} 1511a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat2 __attribute__((overloadable)) native_divide(float2 v1, float2 v2) { return v1 / v2;} 1512a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat3 __attribute__((overloadable)) native_divide(float3 v1, float3 v2) { return v1 / v2;} 1513a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat4 __attribute__((overloadable)) native_divide(float4 v1, float4 v2) { return v1 / v2;} 1514a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1515a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_recip(float v) { return 1.f / v;} 1516a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat2 __attribute__((overloadable)) native_recip(float2 v) { return ((float2)1.f) / v;} 1517a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat3 __attribute__((overloadable)) native_recip(float3 v) { return ((float3)1.f) / v;} 1518a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat4 __attribute__((overloadable)) native_recip(float4 v) { return ((float4)1.f) / v;} 1519a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1520a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1521a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 1522a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams 15235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 15245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN 15255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef IN_FUNC_FN 15265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_FN 15275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_F 15285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_IN 15295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_I 15305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_PFN 15315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_PIN 15325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_FN_FN 15335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_FN_PIN 15345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef XN_FUNC_YN 15355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef UIN_FUNC_IN 15365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef IN_FUNC_IN 15375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef XN_FUNC_XN_XN_BODY 15385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef IN_FUNC_IN_IN_BODY 153954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 154054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainartypedef union { 154154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half hval; 154254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar short sval; 154354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} fp16_shape_type; 154454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 154554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* half h = unsigned short s; */ 154654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define SET_HALF_WORD(h, s) \ 154754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainardo { \ 154854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar fp16_shape_type fp16_u; \ 154954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar fp16_u.sval = (s); \ 155054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar (h) = fp16_u.hval; \ 155154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} while (0) 155254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 155354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarstatic const unsigned short kHalfPositiveInfinity = 0x7c00; 155454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 155554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form 155654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * HN output = fn(HN input) 155754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is scalar or vector half type 155854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */ 155954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define HN_FUNC_HN(fn) \ 156054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half h) { \ 156154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return (half) fn((float) h); \ 156254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 156354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) fn(half2 v) { \ 156454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half2(fn(convert_float2(v))); \ 156554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 156654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) fn(half3 v) { \ 156754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half3(fn(convert_float3(v))); \ 156854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 156954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) fn(half4 v) { \ 157054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half4(fn(convert_float4(v))); \ 157154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 157254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 157354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form 157454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * HN output = fn(HN input1, HN input2) 157554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is scalar or vector half type 157654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */ 157754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define HN_FUNC_HN_HN(fn) \ 157854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half h1, half h2) { \ 157954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return (half) fn((float) h1, (float) h2); \ 158054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 158154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) fn(half2 v1, half2 v2) { \ 158254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half2(fn(convert_float2(v1), \ 158354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar convert_float2(v2))); \ 158454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 158554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) fn(half3 v1, half3 v2) { \ 158654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half3(fn(convert_float3(v1), \ 158754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar convert_float3(v2))); \ 158854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 158954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) fn(half4 v1, half4 v2) { \ 159054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half4(fn(convert_float4(v1), \ 159154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar convert_float4(v2))); \ 159254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 159354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 159454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form 159554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * HN output = fn(HN input1, half input2) 159654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is scalar or vector half type 159754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */ 159854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define HN_FUNC_HN_H(fn) \ 159954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) fn(half2 v1, half v2) { \ 160054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half2(fn(convert_float2(v1), (float) v2)); \ 160154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 160254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) fn(half3 v1, half v2) { \ 160354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half3(fn(convert_float3(v1), (float) v2)); \ 160454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 160554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) fn(half4 v1, half v2) { \ 160654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half4(fn(convert_float4(v1), (float) v2)); \ 160754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 160854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 160954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form 161054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * HN output = fn(HN input1, HN input2, HN input3) 161154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is scalar or vector half type 161254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */ 161354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define HN_FUNC_HN_HN_HN(fn) \ 161454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half h1, half h2, half h3) { \ 161554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return (half) fn((float) h1, (float) h2, (float) h3); \ 161654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 161754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) fn(half2 v1, half2 v2, half2 v3) { \ 161854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half2(fn(convert_float2(v1), \ 161954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar convert_float2(v2), \ 162054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar convert_float2(v3))); \ 162154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 162254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) fn(half3 v1, half3 v2, half3 v3) { \ 162354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half3(fn(convert_float3(v1), \ 162454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar convert_float3(v2), \ 162554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar convert_float3(v3))); \ 162654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 162754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) fn(half4 v1, half4 v2, half4 v3) { \ 162854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half4(fn(convert_float4(v1), \ 162954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar convert_float4(v2), \ 163054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar convert_float4(v3))); \ 163154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 163254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 163354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form 163454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * HN output = fn(HN input1, IN input2) 163554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is scalar or vector half type and IN the equivalent integer type 163654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * of same vector length. 163754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */ 163854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define HN_FUNC_HN_IN(fn) \ 163954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half h1, int v) { \ 164054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return (half) fn((float) h1, v); \ 164154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 164254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) fn(half2 v1, int2 v2) { \ 164354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half2(fn(convert_float2(v1), v2)); \ 164454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 164554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) fn(half3 v1, int3 v2) { \ 164654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half3(fn(convert_float3(v1), v2)); \ 164754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 164854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) fn(half4 v1, int4 v2) { \ 164954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half4(fn(convert_float4(v1), v2)); \ 165054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 165154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 165254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form 165354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * half output = fn(HN input1) 165454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is a scalar or vector half type. 165554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */ 165654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define H_FUNC_HN(fn) \ 165754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half h) { \ 165854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return (half) fn((float) h); \ 165954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 166054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half2 v) { \ 166154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return fn(convert_float2(v)); \ 166254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 166354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half3 v) { \ 166454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return fn(convert_float3(v)); \ 166554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 166654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half4 v) { \ 166754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return fn(convert_float4(v)); \ 166854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 166954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 167054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form 167154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * half output = fn(HN input1, HN input2) 167254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is a scalar or vector half type. 167354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */ 167454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define H_FUNC_HN_HN(fn) \ 167554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half h1, half h2) { \ 167654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return (half) fn((float) h1, (float) h2); \ 167754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 167854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half2 v1, half2 v2) { \ 167954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return fn(convert_float2(v1), convert_float2(v2)); \ 168054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 168154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half3 v1, half3 v2) { \ 168254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return fn(convert_float3(v1), convert_float3(v2)); \ 168354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 168454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half4 v1, half4 v2) { \ 168554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return fn(convert_float4(v1), convert_float4(v2)); \ 168654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 168754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 168854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form 168954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * HN output = fn(HN input1, HN input2) 169054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is a vector half type. The functions are defined to call the 169154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * scalar function of the same name. 169254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */ 169354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define SCALARIZE_HN_FUNC_HN_HN(fn) \ 169454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) fn(half2 v1, half2 v2) { \ 169554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half2 ret; \ 169654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.x = fn(v1.x, v2.x); \ 169754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.y = fn(v1.y, v2.y); \ 169854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return ret; \ 169954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 170054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) fn(half3 v1, half3 v2) { \ 170154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half3 ret; \ 170254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.x = fn(v1.x, v2.x); \ 170354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.y = fn(v1.y, v2.y); \ 170454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.z = fn(v1.z, v2.z); \ 170554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return ret; \ 170654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 170754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) fn(half4 v1, half4 v2) { \ 170854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half4 ret; \ 170954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.x = fn(v1.x, v2.x); \ 171054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.y = fn(v1.y, v2.y); \ 171154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.z = fn(v1.z, v2.z); \ 171254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.w = fn(v1.w, v2.w); \ 171354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return ret; \ 171454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} \ 171554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 171654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(acos); 171754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(acosh); 171854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(acospi); 171954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(asin); 172054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(asinh); 172154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(asinpi); 172254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(atan); 172354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(atanh); 172454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(atanpi); 172554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(atan2); 172654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(atan2pi); 172754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 172854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(cbrt); 172954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(ceil); 173054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 173154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar// TODO Add copysign 173254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 173354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(cos); 173454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(cosh); 173554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(cospi); 173654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 173754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) cross(half3 lhs, half3 rhs) { 173854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half3 r; 173954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = lhs.y * rhs.z - lhs.z * rhs.y; 174054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = lhs.z * rhs.x - lhs.x * rhs.z; 174154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.z = lhs.x * rhs.y - lhs.y * rhs.x; 174254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 174354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 174454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 174554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) cross(half4 lhs, half4 rhs) { 174654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half4 r; 174754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = lhs.y * rhs.z - lhs.z * rhs.y; 174854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = lhs.z * rhs.x - lhs.x * rhs.z; 174954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.z = lhs.x * rhs.y - lhs.y * rhs.x; 175054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.w = 0.f; 175154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 175254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 175354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 175454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(degrees); 175554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarH_FUNC_HN_HN(distance); 175654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarH_FUNC_HN_HN(dot); 175754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 175854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(erf); 175954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(erfc); 176054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(exp); 176154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(exp10); 176254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(exp2); 176354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(expm1); 176454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 176554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(fabs); 176654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(fdim); 176754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(floor); 176854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN_HN(fma); 176954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(fmax); 177054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_H(fmax); 177154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(fmin); 177254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_H(fmin); 177354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(fmod); 177454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 177554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar// TODO Add (both variants) of fract 177654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar// TODO Add frexp 177754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 177854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(hypot); 177954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 178054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar// TODO Add ilogb 178154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 178254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_IN(ldexp); 178354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) ldexp(half2 v, int exponent) { 178454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half2(ldexp(convert_float2(v), exponent)); 178554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 178654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) ldexp(half3 v, int exponent) { 178754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half3(ldexp(convert_float3(v), exponent)); 178854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 178954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) ldexp(half4 v, int exponent) { 179054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half4(ldexp(convert_float4(v), exponent)); 179154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 179254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 179354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarH_FUNC_HN(length); 179454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(lgamma); 179554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 179654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) lgamma(half h, int *signp) { 179754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return (half) lgamma((float) h, signp); 179854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 179954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) lgamma(half2 v, int2 *signp) { 180054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half2(lgamma(convert_float2(v), signp)); 180154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 180254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) lgamma(half3 v, int3 *signp) { 180354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half3(lgamma(convert_float3(v), signp)); 180454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 180554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) lgamma(half4 v, int4 *signp) { 180654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half4(lgamma(convert_float4(v), signp)); 180754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 180854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 180954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(log); 181054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(log10); 181154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(log1p); 181254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(log2); 181354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(logb); 181454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 181554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN_HN(mad); 181654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(max); 181754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_H(max); // TODO can this be arch-specific similar to _Z3maxDv2_ff? 181854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(min); 181954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_H(min); // TODO can this be arch-specific similar to _Z3minDv2_ff? 182054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 182154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) mix(half start, half stop, half amount) { 182254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return start + (stop - start) * amount; 182354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 182454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) mix(half2 start, half2 stop, half2 amount) { 182554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return start + (stop - start) * amount; 182654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 182754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) mix(half3 start, half3 stop, half3 amount) { 182854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return start + (stop - start) * amount; 182954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 183054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) mix(half4 start, half4 stop, half4 amount) { 183154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return start + (stop - start) * amount; 183254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 183354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) mix(half2 start, half2 stop, half amount) { 183454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return start + (stop - start) * amount; 183554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 183654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) mix(half3 start, half3 stop, half amount) { 183754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return start + (stop - start) * amount; 183854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 183954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) mix(half4 start, half4 stop, half amount) { 184054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return start + (stop - start) * amount; 184154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 184254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 184354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar// TODO Define modf. Does it make sense to delegate to the float? 184454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 184554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarhalf __attribute__((overloadable)) nan_half() { 184654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar unsigned short nan_short = kHalfPositiveInfinity | 0x0200; 184754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half nan; 184854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar SET_HALF_WORD(nan, nan_short); 184954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return nan; 185054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 185154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 185254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar// TODO Add nextafter 185354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 185454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(normalize); 185554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 185654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(pow); 185754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_IN(pown); 185854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(powr); 185954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(radians); 186054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(remainder); 186154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 186254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) remquo(half n, half d, int *quo) { 186354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return (float) remquo((float) n, (float) d, quo); 186454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 186554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) remquo(half2 n, half2 d, int2 *quo) { 186654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half2(remquo(convert_float2(d), convert_float2(n), quo)); 186754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 186854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) remquo(half3 n, half3 d, int3 *quo) { 186954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half3(remquo(convert_float3(d), convert_float3(n), quo)); 187054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 187154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) remquo(half4 n, half4 d, int4 *quo) { 187254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return convert_half4(remquo(convert_float4(d), convert_float4(n), quo)); 187354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 187454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 187554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(rint); 187654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_IN(rootn); 187754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(round); 187854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(rsqrt); 187954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 188054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) sign(half h) { 188154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar if (h > 0) return (half) 1.f; 188254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar if (h < 0) return (half) -1.f; 188354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return h; 188454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 188554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) sign(half2 v) { 188654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half2 ret; 188754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.x = sign(v.x); 188854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.y = sign(v.y); 188954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return ret; 189054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 189154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) sign(half3 v) { 189254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half3 ret; 189354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.x = sign(v.x); 189454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.y = sign(v.y); 189554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.z = sign(v.z); 189654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return ret; 189754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 189854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) sign(half4 v) { 189954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half4 ret; 190054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.x = sign(v.x); 190154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.y = sign(v.y); 190254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.z = sign(v.z); 190354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar ret.w = sign(v.w); 190454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return ret; 190554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 190654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 190754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(sin); 190854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 190954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) sincos(half v, half *cosptr) { 191054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar *cosptr = cos(v); 191154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return sin(v); 191254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 191354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar// TODO verify if LLVM eliminates the duplicate convert_float2 191454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) sincos(half2 v, half2 *cosptr) { 191554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar *cosptr = cos(v); 191654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return sin(v); 191754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 191854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) sincos(half3 v, half3 *cosptr) { 191954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar *cosptr = cos(v); 192054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return sin(v); 192154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 192254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) sincos(half4 v, half4 *cosptr) { 192354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar *cosptr = cos(v); 192454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return sin(v); 192554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 192654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 192754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(sinh); 192854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(sinpi); 192954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(sqrt); 193054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 193154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) step(half edge, half v) { 193254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return (v < edge) ? 0.f : 1.f; 193354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 193454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) step(half2 edge, half2 v) { 193554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half2 r; 193654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = (v.x < edge.x) ? 0.f : 1.f; 193754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = (v.y < edge.y) ? 0.f : 1.f; 193854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 193954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 194054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) step(half3 edge, half3 v) { 194154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half3 r; 194254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = (v.x < edge.x) ? 0.f : 1.f; 194354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = (v.y < edge.y) ? 0.f : 1.f; 194454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.z = (v.z < edge.z) ? 0.f : 1.f; 194554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 194654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 194754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) step(half4 edge, half4 v) { 194854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half4 r; 194954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = (v.x < edge.x) ? 0.f : 1.f; 195054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = (v.y < edge.y) ? 0.f : 1.f; 195154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.z = (v.z < edge.z) ? 0.f : 1.f; 195254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.w = (v.w < edge.w) ? 0.f : 1.f; 195354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 195454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 195554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) step(half2 edge, half v) { 195654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half2 r; 195754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = (v < edge.x) ? 0.f : 1.f; 195854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = (v < edge.y) ? 0.f : 1.f; 195954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 196054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 196154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) step(half3 edge, half v) { 196254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half3 r; 196354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = (v < edge.x) ? 0.f : 1.f; 196454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = (v < edge.y) ? 0.f : 1.f; 196554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.z = (v < edge.z) ? 0.f : 1.f; 196654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 196754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 196854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) step(half4 edge, half v) { 196954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half4 r; 197054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = (v < edge.x) ? 0.f : 1.f; 197154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = (v < edge.y) ? 0.f : 1.f; 197254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.z = (v < edge.z) ? 0.f : 1.f; 197354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.w = (v < edge.w) ? 0.f : 1.f; 197454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 197554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 197654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) step(half edge, half2 v) { 197754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half2 r; 197854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = (v.x < edge) ? 0.f : 1.f; 197954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = (v.y < edge) ? 0.f : 1.f; 198054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 198154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 198254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) step(half edge, half3 v) { 198354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half3 r; 198454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = (v.x < edge) ? 0.f : 1.f; 198554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = (v.y < edge) ? 0.f : 1.f; 198654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.z = (v.z < edge) ? 0.f : 1.f; 198754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 198854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 198954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) step(half edge, half4 v) { 199054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar half4 r; 199154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.x = (v.x < edge) ? 0.f : 1.f; 199254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.y = (v.y < edge) ? 0.f : 1.f; 199354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.z = (v.z < edge) ? 0.f : 1.f; 199454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar r.w = (v.w < edge) ? 0.f : 1.f; 199554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return r; 199654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 199754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 199854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(tan); 199954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(tanh); 200054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(tanpi); 200154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(tgamma); 200254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(trunc); // TODO: rethink: needs half-specific implementation? 200354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 200454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_acos); 200554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_acosh); 200654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_acospi); 200754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_asin); 200854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_asinh); 200954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_asinpi); 201054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_atan); 201154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_atanh); 201254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_atanpi); 201354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(native_atan2); 201454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(native_atan2pi); 201554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 201654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_cbrt); 201754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_cos); 201854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_cosh); 201954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_cospi); 202054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 202154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarH_FUNC_HN_HN(native_distance); 202254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(native_divide); 202354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 202454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_exp); 202554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_exp10); 202654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_exp2); 202754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_expm1); 202854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 202954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(native_hypot); 203054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarH_FUNC_HN(native_length); 203154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 203254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_log); 203354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_log10); 203454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_log1p); 203554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_log2); 203654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 203754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_normalize); 203854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 203954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(native_powr); // TODO are parameter limits different for half? 204054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 204154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_recip); 204254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_IN(native_rootn); 204354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_rsqrt); 204454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 204554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_sin); 204654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 204754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) native_sincos(half v, half *cosptr) { 204854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return sincos(v, cosptr); 204954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 205054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) native_sincos(half2 v, half2 *cosptr) { 205154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return sincos(v, cosptr); 205254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 205354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) native_sincos(half3 v, half3 *cosptr) { 205454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return sincos(v, cosptr); 205554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 205654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) native_sincos(half4 v, half4 *cosptr) { 205754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar return sincos(v, cosptr); 205854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar} 205954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 206054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_sinh); 206154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_sinpi); 206254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_sqrt); 206354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 206454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_tan); 206554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_tanh); 206654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_tanpi); 206754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 206854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef HN_FUNC_HN 206954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef HN_FUNC_HN_HN 207054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef HN_FUNC_HN_H 207154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef HN_FUNC_HN_HN_HN 207254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef HN_FUNC_HN_IN 207354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef H_FUNC_HN 207454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef H_FUNC_HN_HN 207554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef SCALARIZE_HN_FUNC_HN_HN 207654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar 2077fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// exports unavailable mathlib functions to compat lib 2078fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham 2079fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#ifdef RS_COMPATIBILITY_LIB 2080fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham 2081fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// !!! DANGER !!! 2082fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// These functions are potentially missing on older Android versions. 2083fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// Work around the issue by supplying our own variants. 2084fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// !!! DANGER !!! 2085fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham 2086fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// The logbl() implementation is taken from the latest bionic/, since 2087fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// double == long double on Android. 2088fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckhamextern "C" long double logbl(long double x) { return logb(x); } 2089fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham 2090fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// __aeabi_idiv0 is a missing function in libcompiler_rt.so, so we just 2091fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// pick the simplest implementation based on the ARM EABI doc. 2092fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckhamextern "C" int __aeabi_idiv0(int v) { return v; } 2093fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham 2094fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#endif // compatibility lib 2095