rs_cl.c revision 582b3646d6634f74a13828cceb1414823c18e66f
15a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#include "rs_types.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 5135a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(pow) 5145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) pown(float v, int p) { 5165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, (float)p); 5175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) pown(float2 v, int2 p) { 5195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 f2 = convert_float2(p); 5205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, f2); 5215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) pown(float3 v, int3 p) { 5235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 f3 = convert_float3(p); 5245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, f3); 5255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) pown(float4 v, int4 p) { 5275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 f4 = convert_float4(p); 5285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, f4); 5295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) powr(float v, float p) { 5325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, p); 5335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) powr(float2 v, float2 p) { 5355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, p); 5365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) powr(float3 v, float3 p) { 5385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, p); 5395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) powr(float4 v, float4 p) { 5415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, p); 5425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) remainder(float, float); 5455a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(remainder) 5465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) remquo(float, float, int *); 5485a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN_PIN(remquo) 5495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) rint(float); 5515a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(rint) 5525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) rootn(float v, int r) { 5545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r == 0) { 5555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return nan(0); 5565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (iszero(v)) { 5595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r < 0) { 5605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r & 1) { 5615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return copysign(posinf(), v); 5625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } else { 5635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return posinf(); 5645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } else { 5665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r & 1) { 5675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return copysign(0.f, v); 5685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } else { 5695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return 0.f; 5705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (!isinf(v) && !isnan(v) && (v < 0.f)) { 5755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r & 1) { 5765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (-1.f * pow(-1.f * v, 1.f / r)); 5775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } else { 5785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return nan(0); 5795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, 1.f / r); 5835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5845a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_IN(rootn); 5855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) round(float); 5875a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(round) 5885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sqrt(float); 5915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) rsqrt(float v) { 5925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return 1.f / sqrt(v); 5935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5945a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(rsqrt) 5955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sin(float); 5975a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sin) 5985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sincos(float v, float *cosptr) { 6005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *cosptr = cos(v); 6015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v); 6025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) sincos(float2 v, float2 *cosptr) { 6045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *cosptr = cos(v); 6055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v); 6065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) sincos(float3 v, float3 *cosptr) { 6085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *cosptr = cos(v); 6095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v); 6105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) sincos(float4 v, float4 *cosptr) { 6125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *cosptr = cos(v); 6135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v); 6145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sinh(float); 6175a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sinh) 6185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sinpi(float v) { 6205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v * M_PI); 6215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6225a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sinpi) 6235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) tan(float); 6255a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tan) 6265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) tanh(float); 6285a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tanh) 6295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) tanpi(float v) { 6315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return tan(v * M_PI); 6325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6335a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tanpi) 6345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) tgamma(float); 6375a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tgamma) 6385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) trunc(float); 6405a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(trunc) 6415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// Int ops (partial), 6.11.3 6435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define XN_FUNC_YN(typeout, fnc, typein) \ 6455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout __attribute__((overloadable)) fnc(typein); \ 6465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout##2 __attribute__((overloadable)) fnc(typein##2 v) { \ 6475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines typeout##2 r; \ 6485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 6495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 6505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 6515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 6525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout##3 __attribute__((overloadable)) fnc(typein##3 v) { \ 6535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines typeout##3 r; \ 6545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 6555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 6565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v.z); \ 6575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 6585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 6595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout##4 __attribute__((overloadable)) fnc(typein##4 v) { \ 6605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines typeout##4 r; \ 6615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 6625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 6635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v.z); \ 6645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v.w); \ 6655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 6665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define UIN_FUNC_IN(fnc) \ 6705a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uchar, fnc, char) \ 6715a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(ushort, fnc, short) \ 6725a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uint, fnc, int) 6735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define IN_FUNC_IN(fnc) \ 6755a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uchar, fnc, uchar) \ 6765a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(char, fnc, char) \ 6775a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(ushort, fnc, ushort) \ 6785a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(short, fnc, short) \ 6795a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uint, fnc, uint) \ 6805a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(int, fnc, int) 6815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define XN_FUNC_XN_XN_BODY(type, fnc, body) \ 6845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type __attribute__((overloadable)) \ 6855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(type v1, type v2) { \ 6865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return body; \ 6875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 6885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type##2 __attribute__((overloadable)) \ 6895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(type##2 v1, type##2 v2) { \ 6905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines type##2 r; \ 6915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 6925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 6935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 6945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 6955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type##3 __attribute__((overloadable)) \ 6965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(type##3 v1, type##3 v2) { \ 6975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines type##3 r; \ 6985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 6995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 7005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z); \ 7015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 7025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 7035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type##4 __attribute__((overloadable)) \ 7045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(type##4 v1, type##4 v2) { \ 7055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines type##4 r; \ 7065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 7075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 7085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z); \ 7095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, v2.w); \ 7105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 7115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define IN_FUNC_IN_IN_BODY(fnc, body) \ 7145a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(uchar, fnc, body) \ 7155a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(char, fnc, body) \ 7165a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(ushort, fnc, body) \ 7175a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(short, fnc, body) \ 7185a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(uint, fnc, body) \ 7195a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(int, fnc, body) \ 7205a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(float, fnc, body) 7215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/** 7245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines * abs 7255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines */ 7265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable)) abs(int32_t v) { 7275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v < 0) 7285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return -v; 7295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v; 7305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint16_t __attribute__((overloadable)) abs(int16_t v) { 7325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v < 0) 7335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return -v; 7345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v; 7355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint8_t __attribute__((overloadable)) abs(int8_t v) { 7375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v < 0) 7385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return -v; 7395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v; 7405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/** 7435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines * clz 7445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines */ 7455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable)) clz(uint32_t v) { 7465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return __builtin_clz(v); 7475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint16_t __attribute__((overloadable)) clz(uint16_t v) { 7495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (uint16_t)__builtin_clz(v); 7505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint8_t __attribute__((overloadable)) clz(uint8_t v) { 7525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (uint8_t)__builtin_clz(v); 7535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int32_t __attribute__((overloadable)) clz(int32_t v) { 7555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (int32_t)__builtin_clz((uint32_t)v); 7565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int16_t __attribute__((overloadable)) clz(int16_t v) { 7585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (int16_t)__builtin_clz(v); 7595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int8_t __attribute__((overloadable)) clz(int8_t v) { 7615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (int8_t)__builtin_clz(v); 7625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7655a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesUIN_FUNC_IN(abs) 7665a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesIN_FUNC_IN(clz) 7675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// 6.11.4 7705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) degrees(float radians) { 7735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return radians * (180.f / M_PI); 7745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) degrees(float2 radians) { 7765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return radians * (180.f / M_PI); 7775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) degrees(float3 radians) { 7795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return radians * (180.f / M_PI); 7805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) degrees(float4 radians) { 7825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return radians * (180.f / M_PI); 7835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) mix(float start, float stop, float amount) { 7865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 7875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) mix(float2 start, float2 stop, float2 amount) { 7895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 7905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) mix(float3 start, float3 stop, float3 amount) { 7925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 7935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) mix(float4 start, float4 stop, float4 amount) { 7955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 7965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) mix(float2 start, float2 stop, float amount) { 7985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 7995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) mix(float3 start, float3 stop, float amount) { 8015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 8025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) mix(float4 start, float4 stop, float amount) { 8045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 8055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) radians(float degrees) { 8085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return degrees * (M_PI / 180.f); 8095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) radians(float2 degrees) { 8115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return degrees * (M_PI / 180.f); 8125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) radians(float3 degrees) { 8145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return degrees * (M_PI / 180.f); 8155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) radians(float4 degrees) { 8175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return degrees * (M_PI / 180.f); 8185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) step(float edge, float v) { 8215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (v < edge) ? 0.f : 1.f; 8225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) step(float2 edge, float2 v) { 8245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; 8255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v.x < edge.x) ? 0.f : 1.f; 8265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v.y < edge.y) ? 0.f : 1.f; 8275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) step(float3 edge, float3 v) { 8305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; 8315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v.x < edge.x) ? 0.f : 1.f; 8325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v.y < edge.y) ? 0.f : 1.f; 8335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = (v.z < edge.z) ? 0.f : 1.f; 8345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) step(float4 edge, float4 v) { 8375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; 8385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v.x < edge.x) ? 0.f : 1.f; 8395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v.y < edge.y) ? 0.f : 1.f; 8405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = (v.z < edge.z) ? 0.f : 1.f; 8415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = (v.w < edge.w) ? 0.f : 1.f; 8425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) step(float2 edge, float v) { 8455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; 8465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v < edge.x) ? 0.f : 1.f; 8475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v < edge.y) ? 0.f : 1.f; 8485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) step(float3 edge, float v) { 8515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; 8525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v < edge.x) ? 0.f : 1.f; 8535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v < edge.y) ? 0.f : 1.f; 8545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = (v < edge.z) ? 0.f : 1.f; 8555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) step(float4 edge, float v) { 8585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; 8595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v < edge.x) ? 0.f : 1.f; 8605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v < edge.y) ? 0.f : 1.f; 8615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = (v < edge.z) ? 0.f : 1.f; 8625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = (v < edge.w) ? 0.f : 1.f; 8635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) smoothstep(float, float, float); 8675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) smoothstep(float2, float2, float2); 8685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) smoothstep(float3, float3, float3); 8695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) smoothstep(float4, float4, float4); 8705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) smoothstep(float, float, float2); 8715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) smoothstep(float, float, float3); 8725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) smoothstep(float, float, float4); 8735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sign(float v) { 8755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v > 0) return 1.f; 8765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v < 0) return -1.f; 8775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v; 8785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8795a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sign) 8805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// 6.11.5 8835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) cross(float3 lhs, float3 rhs) { 8845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; 8855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = lhs.y * rhs.z - lhs.z * rhs.y; 8865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = lhs.z * rhs.x - lhs.x * rhs.z; 8875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = lhs.x * rhs.y - lhs.y * rhs.x; 8885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) cross(float4 lhs, float4 rhs) { 8925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; 8935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = lhs.y * rhs.z - lhs.z * rhs.y; 8945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = lhs.z * rhs.x - lhs.x * rhs.z; 8955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = lhs.x * rhs.y - lhs.y * rhs.x; 8965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = 0.f; 8975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float v); 9015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float2 v); 9025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float3 v); 9035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float4 v); 9045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float lhs, float rhs) { 9065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return length(lhs - rhs); 9075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float2 lhs, float2 rhs) { 9095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return length(lhs - rhs); 9105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float3 lhs, float3 rhs) { 9125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return length(lhs - rhs); 9135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float4 lhs, float4 rhs) { 9155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return length(lhs - rhs); 9165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) normalize(float v) { 9195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return 1.f; 9205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) normalize(float2 v) { 9225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v / length(v); 9235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) normalize(float3 v) { 9255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v / length(v); 9265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) normalize(float4 v) { 9285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v / length(v); 9295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) half_sqrt(float); 9325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float v) { 934582b3646d6634f74a13828cceb1414823c18e66fStephen Hines return fabs(v); 9355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float2 v) { 9375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return half_sqrt(v.x*v.x + v.y*v.y); 9385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float3 v) { 9405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return half_sqrt(v.x*v.x + v.y*v.y + v.z*v.z); 9415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float4 v) { 9435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return half_sqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w); 9445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float lhs, float rhs) { 9475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fast_length(lhs - rhs); 9485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float2 lhs, float2 rhs) { 9505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fast_length(lhs - rhs); 9515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float3 lhs, float3 rhs) { 9535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fast_length(lhs - rhs); 9545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float4 lhs, float4 rhs) { 9565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fast_length(lhs - rhs); 9575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) half_rsqrt(float); 9605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_normalize(float v) { 9625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return 1.f; 9635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fast_normalize(float2 v) { 9655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v * half_rsqrt(v.x*v.x + v.y*v.y); 9665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fast_normalize(float3 v) { 9685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v * half_rsqrt(v.x*v.x + v.y*v.y + v.z*v.z); 9695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fast_normalize(float4 v) { 9715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v * half_rsqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w); 9725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) half_recip(float); 9755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/* 9775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) approx_atan(float x) { 9785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (x == 0.f) 9795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return 0.f; 9805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (x < 0.f) 9815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return -1.f * approx_atan(-1.f * x); 9825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (x > 1.f) 9835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return M_PI_2 - approx_atan(approx_recip(x)); 9845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return x * approx_recip(1.f + 0.28f * x*x); 9855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9865a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(approx_atan) 9875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines*/ 9885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinestypedef union 9905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines{ 9915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float fv; 9925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t iv; 9935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} ieee_float_shape_type; 9945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/* Get a 32 bit int from a float. */ 9965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define GET_FLOAT_WORD(i,d) \ 9985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesdo { \ 9995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ieee_float_shape_type gf_u; \ 10005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines gf_u.fv = (d); \ 10015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (i) = gf_u.iv; \ 10025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} while (0) 10035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/* Set a float from a 32 bit int. */ 10055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define SET_FLOAT_WORD(d,i) \ 10075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesdo { \ 10085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ieee_float_shape_type sf_u; \ 10095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines sf_u.iv = (i); \ 10105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (d) = sf_u.fv; \ 10115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} while (0) 10125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// Valid -125 to 125 10165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_exp2(float v) { 10175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t iv = (int)v; 10185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t x = iv + (iv >> 31); // ~floor(v) 10195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float r = (v - x); 10205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float fo; 10225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines SET_FLOAT_WORD(fo, (x + 127) << 23); 10235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r *= 0.694f; // ~ log(e) / log(2) 10255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float r2 = r*r; 10265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float adj = 1.f + r + (r2 * 0.5f) + (r2*r * 0.166666f) + (r2*r2 * 0.0416666f); 10275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fo * adj; 10285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_exp2(float2 v) { 10315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int2 iv = convert_int2(v); 10325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int2 x = iv + (iv >> (int2)31);//floor(v); 10335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r = (v - convert_float2(x)); 10345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines x += 127; 10365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 fo = (float2)(x << (int2)23); 10385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r *= 0.694f; // ~ log(e) / log(2) 10405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r2 = r*r; 10415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 adj = 1.f + r + (r2 * 0.5f) + (r2*r * 0.166666f) + (r2*r2 * 0.0416666f); 10425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fo * adj; 10435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_exp2(float4 v) { 10465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int4 iv = convert_int4(v); 10475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int4 x = iv + (iv >> (int4)31);//floor(v); 10485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r = (v - convert_float4(x)); 10495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines x += 127; 10515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 fo = (float4)(x << (int4)23); 10535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r *= 0.694f; // ~ log(e) / log(2) 10555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r2 = r*r; 10565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 adj = 1.f + r + (r2 * 0.5f) + (r2*r * 0.166666f) + (r2*r2 * 0.0416666f); 10575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fo * adj; 10585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_exp2(float3 v) { 10615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 t = 1.f; 10625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines t.xyz = v; 10635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(t).xyz; 10645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_exp(float v) { 10685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 1.442695041f); 10695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_exp(float2 v) { 10715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 1.442695041f); 10725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_exp(float3 v) { 10745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 1.442695041f); 10755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_exp(float4 v) { 10775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 1.442695041f); 10785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_exp10(float v) { 10815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 3.321928095f); 10825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_exp10(float2 v) { 10845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 3.321928095f); 10855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_exp10(float3 v) { 10875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 3.321928095f); 10885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_exp10(float4 v) { 10905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 3.321928095f); 10915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_log2(float v) { 10945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t ibits; 10955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines GET_FLOAT_WORD(ibits, v); 10965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t e = (ibits >> 23) & 0xff; 10985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ibits &= 0x7fffff; 11005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ibits |= 127 << 23; 11015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float ir; 11035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines SET_FLOAT_WORD(ir, ibits); 11045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ir -= 1.5f; 11065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float ir2 = ir*ir; 11075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float adj2 = 0.405465108f + // -0.00009f + 11085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (0.666666667f * ir) - 11095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (0.222222222f * ir2) + 11105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (0.098765432f * ir*ir2) - 11115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (0.049382716f * ir2*ir2) + 11125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (0.026337449f * ir*ir2*ir2) - 11135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (0.014631916f * ir2*ir2*ir2); 11145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines adj2 *= (1.f / 0.693147181f); 11155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (float)(e - 127) + adj2; 11175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_log2(float2 v) { 11195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 v2 = {native_log2(v.x), native_log2(v.y)}; 11205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v2; 11215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_log2(float3 v) { 11235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 v2 = {native_log2(v.x), native_log2(v.y), native_log2(v.z)}; 11245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v2; 11255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_log2(float4 v) { 11275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 v2 = {native_log2(v.x), native_log2(v.y), native_log2(v.z), native_log2(v.w)}; 11285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v2; 11295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_log(float v) { 11325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 1.442695041f); 11335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_log(float2 v) { 11355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 1.442695041f); 11365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_log(float3 v) { 11385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 1.442695041f); 11395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_log(float4 v) { 11415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 1.442695041f); 11425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_log10(float v) { 11455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 3.321928095f); 11465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_log10(float2 v) { 11485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 3.321928095f); 11495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_log10(float3 v) { 11515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 3.321928095f); 11525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_log10(float4 v) { 11545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 3.321928095f); 11555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_powr(float v, float y) { 11595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float v2 = native_log2(v); 11605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2 = fmax(v2, -125.f); 11615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v2 * y); 11625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_powr(float2 v, float2 y) { 11645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 v2 = native_log2(v); 11655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2 = fmax(v2, -125.f); 11665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v2 * y); 11675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_powr(float3 v, float3 y) { 11695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 v2 = native_log2(v); 11705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2 = fmax(v2, -125.f); 11715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v2 * y); 11725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_powr(float4 v, float4 y) { 11745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 v2 = native_log2(v); 11755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2 = fmax(v2, -125.f); 11765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v2 * y); 11775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN 11815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef IN_FUNC_FN 11825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_FN 11835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_F 11845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_IN 11855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_I 11865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_PFN 11875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_PIN 11885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_FN_FN 11895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_FN_PIN 11905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef XN_FUNC_YN 11915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef UIN_FUNC_IN 11925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef IN_FUNC_IN 11935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef XN_FUNC_XN_XN_BODY 11945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef IN_FUNC_IN_IN_BODY 1195