rs_cl.c revision 53826db2ea7f26a241be881c2b454ab3e1e5dd50
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) { 5160b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet /* The mantissa of a float has fewer bits than an int (24 effective vs. 31). 5170b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet * For very large ints, we'll lose whether the exponent is even or odd, making 518bcd5b9af756d10317faf54fa3742f89dfacef152Jean-Luc Brouillet * the selection of a correct sign incorrect. We correct this. Use copysign 519bcd5b9af756d10317faf54fa3742f89dfacef152Jean-Luc Brouillet * to handle the negative zero case. 5200b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet */ 521bcd5b9af756d10317faf54fa3742f89dfacef152Jean-Luc Brouillet float sign = (p & 0x1) ? copysign(1.f, v) : 1.f; 5220b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet float f = pow(v, (float)p); 5230b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet return copysign(f, sign); 5240b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet} 5250b0bcff691d047da1d658889866c6a0347850f1cJean-Luc BrouilletFN_FUNC_FN_IN(pown) 5265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) powr(float v, float p) { 5285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, p); 5295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) powr(float2 v, float2 p) { 5315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, p); 5325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) powr(float3 v, float3 p) { 5345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, p); 5355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) powr(float4 v, float4 p) { 5375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, p); 5385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) remainder(float, float); 5415a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(remainder) 5425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) remquo(float, float, int *); 5445a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN_PIN(remquo) 5455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) rint(float); 5475a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(rint) 5485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) rootn(float v, int r) { 5505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r == 0) { 5515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return nan(0); 5525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (iszero(v)) { 5555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r < 0) { 5565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r & 1) { 5575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return copysign(posinf(), v); 5585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } else { 5595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return posinf(); 5605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } else { 5625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r & 1) { 5635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return copysign(0.f, v); 5645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } else { 5655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return 0.f; 5665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (!isinf(v) && !isnan(v) && (v < 0.f)) { 5715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (r & 1) { 5725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (-1.f * pow(-1.f * v, 1.f / r)); 5735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } else { 5745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return nan(0); 5755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 5775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return pow(v, 1.f / r); 5795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 5805a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_IN(rootn); 5815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) round(float); 5835a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(round) 5845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sqrt(float); 5875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) rsqrt(float v) { 5885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return 1.f / sqrt(v); 5895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 590146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 5913a830c08a468ffba0caa22da00001230117d7a84Stephen Hines#if !defined(__i386__) && !defined(__x86_64__) 592146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen HinesFN_FUNC_FN(sqrt) 5933a830c08a468ffba0caa22da00001230117d7a84Stephen Hines#endif // !defined(__i386__) && !defined(__x86_64__) 594146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 5955a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(rsqrt) 5965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 5975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sin(float); 5985a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sin) 5995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sincos(float v, float *cosptr) { 6015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *cosptr = cos(v); 6025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v); 6035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) sincos(float2 v, float2 *cosptr) { 6055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *cosptr = cos(v); 6065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v); 6075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) sincos(float3 v, float3 *cosptr) { 6095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *cosptr = cos(v); 6105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v); 6115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) sincos(float4 v, float4 *cosptr) { 6135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *cosptr = cos(v); 6145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v); 6155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sinh(float); 6185a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sinh) 6195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sinpi(float v) { 6215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return sin(v * M_PI); 6225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6235a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sinpi) 6245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) tan(float); 6265a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tan) 6275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) tanh(float); 6295a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tanh) 6305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) tanpi(float v) { 6325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return tan(v * M_PI); 6335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6345a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tanpi) 6355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) tgamma(float); 6385a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tgamma) 6395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) trunc(float); 6415a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(trunc) 6425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// Int ops (partial), 6.11.3 6445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define XN_FUNC_YN(typeout, fnc, typein) \ 6465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout __attribute__((overloadable)) fnc(typein); \ 6475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout##2 __attribute__((overloadable)) fnc(typein##2 v) { \ 6485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines typeout##2 r; \ 6495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 6505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 6515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 6525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 6535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout##3 __attribute__((overloadable)) fnc(typein##3 v) { \ 6545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines typeout##3 r; \ 6555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 6565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 6575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v.z); \ 6585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 6595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 6605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout##4 __attribute__((overloadable)) fnc(typein##4 v) { \ 6615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines typeout##4 r; \ 6625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v.x); \ 6635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v.y); \ 6645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v.z); \ 6655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v.w); \ 6665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 6675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 6685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define UIN_FUNC_IN(fnc) \ 6715a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uchar, fnc, char) \ 6725a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(ushort, fnc, short) \ 6735a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uint, fnc, int) 6745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define IN_FUNC_IN(fnc) \ 6765a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uchar, fnc, uchar) \ 6775a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(char, fnc, char) \ 6785a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(ushort, fnc, ushort) \ 6795a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(short, fnc, short) \ 6805a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uint, fnc, uint) \ 6815a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(int, fnc, int) 6825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 6845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define XN_FUNC_XN_XN_BODY(type, fnc, body) \ 6855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type __attribute__((overloadable)) \ 6865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(type v1, type v2) { \ 6875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return body; \ 6885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 6895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type##2 __attribute__((overloadable)) \ 6905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(type##2 v1, type##2 v2) { \ 6915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines type##2 r; \ 6925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 6935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 6945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 6955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 6965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type##3 __attribute__((overloadable)) \ 6975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(type##3 v1, type##3 v2) { \ 6985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines type##3 r; \ 6995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 7005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 7015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z); \ 7025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 7035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 7045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type##4 __attribute__((overloadable)) \ 7055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines fnc(type##4 v1, type##4 v2) { \ 7065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines type##4 r; \ 7075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = fnc(v1.x, v2.x); \ 7085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = fnc(v1.y, v2.y); \ 7095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = fnc(v1.z, v2.z); \ 7105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = fnc(v1.w, v2.w); \ 7115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 7125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define IN_FUNC_IN_IN_BODY(fnc, body) \ 7155a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(uchar, fnc, body) \ 7165a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(char, fnc, body) \ 7175a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(ushort, fnc, body) \ 7185a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(short, fnc, body) \ 7195a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(uint, fnc, body) \ 7205a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(int, fnc, body) \ 7215a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(float, fnc, body) 7225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/** 7255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines * abs 7265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines */ 7275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable)) abs(int32_t v) { 7285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v < 0) 7295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return -v; 7305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v; 7315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint16_t __attribute__((overloadable)) abs(int16_t v) { 7335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v < 0) 7345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return -v; 7355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v; 7365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint8_t __attribute__((overloadable)) abs(int8_t v) { 7385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v < 0) 7395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return -v; 7405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v; 7415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/** 7445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines * clz 745c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines * __builtin_clz only accepts a 32-bit unsigned int, so every input will be 746c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines * expanded to 32 bits. For our smaller data types, we need to subtract off 747c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines * these unused top bits (that will be always be composed of zeros). 7485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines */ 7495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable)) clz(uint32_t v) { 7505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return __builtin_clz(v); 7515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint16_t __attribute__((overloadable)) clz(uint16_t v) { 753c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines return __builtin_clz(v) - 16; 7545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint8_t __attribute__((overloadable)) clz(uint8_t v) { 756c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines return __builtin_clz(v) - 24; 7575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int32_t __attribute__((overloadable)) clz(int32_t v) { 759c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines return __builtin_clz(v); 7605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int16_t __attribute__((overloadable)) clz(int16_t v) { 762c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines return __builtin_clz(((uint32_t)v) & 0x0000ffff) - 16; 7635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int8_t __attribute__((overloadable)) clz(int8_t v) { 765c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines return __builtin_clz(((uint32_t)v) & 0x000000ff) - 24; 7665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7695a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesUIN_FUNC_IN(abs) 7705a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesIN_FUNC_IN(clz) 7715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// 6.11.4 7745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) degrees(float radians) { 7775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return radians * (180.f / M_PI); 7785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) degrees(float2 radians) { 7805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return radians * (180.f / M_PI); 7815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) degrees(float3 radians) { 7835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return radians * (180.f / M_PI); 7845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) degrees(float4 radians) { 7865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return radians * (180.f / M_PI); 7875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 7895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) mix(float start, float stop, float amount) { 7905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 7915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) mix(float2 start, float2 stop, float2 amount) { 7935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 7945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) mix(float3 start, float3 stop, float3 amount) { 7965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 7975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 7985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) mix(float4 start, float4 stop, float4 amount) { 7995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 8005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) mix(float2 start, float2 stop, float amount) { 8025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 8035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) mix(float3 start, float3 stop, float amount) { 8055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 8065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) mix(float4 start, float4 stop, float amount) { 8085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return start + (stop - start) * amount; 8095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) radians(float degrees) { 8125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return degrees * (M_PI / 180.f); 8135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) radians(float2 degrees) { 8155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return degrees * (M_PI / 180.f); 8165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) radians(float3 degrees) { 8185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return degrees * (M_PI / 180.f); 8195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) radians(float4 degrees) { 8215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return degrees * (M_PI / 180.f); 8225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) step(float edge, float v) { 8255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (v < edge) ? 0.f : 1.f; 8265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) step(float2 edge, float2 v) { 8285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; 8295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v.x < edge.x) ? 0.f : 1.f; 8305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v.y < edge.y) ? 0.f : 1.f; 8315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) step(float3 edge, float3 v) { 8345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; 8355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v.x < edge.x) ? 0.f : 1.f; 8365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v.y < edge.y) ? 0.f : 1.f; 8375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = (v.z < edge.z) ? 0.f : 1.f; 8385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) step(float4 edge, float4 v) { 8415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; 8425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v.x < edge.x) ? 0.f : 1.f; 8435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v.y < edge.y) ? 0.f : 1.f; 8445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = (v.z < edge.z) ? 0.f : 1.f; 8455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = (v.w < edge.w) ? 0.f : 1.f; 8465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) step(float2 edge, float v) { 8495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r; 8505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v < edge.x) ? 0.f : 1.f; 8515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v < edge.y) ? 0.f : 1.f; 8525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) step(float3 edge, float v) { 8555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; 8565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v < edge.x) ? 0.f : 1.f; 8575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v < edge.y) ? 0.f : 1.f; 8585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = (v < edge.z) ? 0.f : 1.f; 8595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) step(float4 edge, float v) { 8625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; 8635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = (v < edge.x) ? 0.f : 1.f; 8645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = (v < edge.y) ? 0.f : 1.f; 8655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = (v < edge.z) ? 0.f : 1.f; 8665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = (v < edge.w) ? 0.f : 1.f; 8675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 8685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 8690ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouilletextern float2 __attribute__((overloadable)) step(float edge, float2 v) { 8700ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet float2 r; 8710ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.x = (v.x < edge) ? 0.f : 1.f; 8720ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.y = (v.y < edge) ? 0.f : 1.f; 8730ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet return r; 8740ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet} 8750ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouilletextern float3 __attribute__((overloadable)) step(float edge, float3 v) { 8760ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet float3 r; 8770ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.x = (v.x < edge) ? 0.f : 1.f; 8780ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.y = (v.y < edge) ? 0.f : 1.f; 8790ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.z = (v.z < edge) ? 0.f : 1.f; 8800ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet return r; 8810ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet} 8820ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouilletextern float4 __attribute__((overloadable)) step(float edge, float4 v) { 8830ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet float4 r; 8840ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.x = (v.x < edge) ? 0.f : 1.f; 8850ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.y = (v.y < edge) ? 0.f : 1.f; 8860ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.z = (v.z < edge) ? 0.f : 1.f; 8870ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet r.w = (v.w < edge) ? 0.f : 1.f; 8880ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet return r; 8890ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet} 8905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) smoothstep(float, float, float); 8925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) smoothstep(float2, float2, float2); 8935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) smoothstep(float3, float3, float3); 8945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) smoothstep(float4, float4, float4); 8955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) smoothstep(float, float, float2); 8965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) smoothstep(float, float, float3); 8975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) smoothstep(float, float, float4); 8985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 8995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sign(float v) { 9005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v > 0) return 1.f; 9015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (v < 0) return -1.f; 9025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v; 9035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9045a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sign) 9055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// 6.11.5 9085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) cross(float3 lhs, float3 rhs) { 9095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 r; 9105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = lhs.y * rhs.z - lhs.z * rhs.y; 9115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = lhs.z * rhs.x - lhs.x * rhs.z; 9125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = lhs.x * rhs.y - lhs.y * rhs.x; 9135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 9145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) cross(float4 lhs, float4 rhs) { 9175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r; 9185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = lhs.y * rhs.z - lhs.z * rhs.y; 9195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = lhs.z * rhs.x - lhs.x * rhs.z; 9205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = lhs.x * rhs.y - lhs.y * rhs.x; 9215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = 0.f; 9225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; 9235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9253a830c08a468ffba0caa22da00001230117d7a84Stephen Hines#if !defined(__i386__) && !defined(__x86_64__) 926146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 927146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) dot(float lhs, float rhs) { 928146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return lhs * rhs; 929146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 930146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) dot(float2 lhs, float2 rhs) { 931146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return lhs.x*rhs.x + lhs.y*rhs.y; 932146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 933146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) dot(float3 lhs, float3 rhs) { 934146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return lhs.x*rhs.x + lhs.y*rhs.y + lhs.z*rhs.z; 935146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 936146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) dot(float4 lhs, float4 rhs) { 937146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return lhs.x*rhs.x + lhs.y*rhs.y + lhs.z*rhs.z + lhs.w*rhs.w; 938146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 939146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 940146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) length(float v) { 941146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return fabs(v); 942146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 943146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) length(float2 v) { 944146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return sqrt(v.x*v.x + v.y*v.y); 945146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 946146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) length(float3 v) { 947146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return sqrt(v.x*v.x + v.y*v.y + v.z*v.z); 948146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 949146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) length(float4 v) { 950146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines return sqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w); 951146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines} 952146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 953146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines#else 954146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 9555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float v); 9565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float2 v); 9575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float3 v); 9585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float4 v); 9595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9603a830c08a468ffba0caa22da00001230117d7a84Stephen Hines#endif // !defined(__i386__) && !defined(__x86_64__) 961146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines 9625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float lhs, float rhs) { 9635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return length(lhs - rhs); 9645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float2 lhs, float2 rhs) { 9665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return length(lhs - rhs); 9675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float3 lhs, float3 rhs) { 9695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return length(lhs - rhs); 9705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float4 lhs, float4 rhs) { 9725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return length(lhs - rhs); 9735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 9753e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet/* For the normalization functions, vectors of length 0 should simply be 9763e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet * returned (i.e. all the components of that vector are 0). 9773e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet */ 9785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) normalize(float v) { 9793e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet if (v == 0.0f) { 9803e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return 0.0f; 9813e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet } else if (v < 0.0f) { 9823e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return -1.0f; 9833e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet } else { 9843e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return 1.0f; 9853e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet } 9865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) normalize(float2 v) { 9883e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet float l = length(v); 9893e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return l == 0.0f ? v : v / l; 9905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) normalize(float3 v) { 9923e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet float l = length(v); 9933e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return l == 0.0f ? v : v / l; 9945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) normalize(float4 v) { 9963e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet float l = length(v); 9973e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return l == 0.0f ? v : v / l; 9985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 9995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1000ba92a7085bbb8916334a6571ff33355873883173Jason Samsextern float __attribute__((overloadable)) half_sqrt(float v) { 1001ba92a7085bbb8916334a6571ff33355873883173Jason Sams return sqrt(v); 1002ba92a7085bbb8916334a6571ff33355873883173Jason Sams} 1003ba92a7085bbb8916334a6571ff33355873883173Jason SamsFN_FUNC_FN(half_sqrt) 10045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float v) { 1006582b3646d6634f74a13828cceb1414823c18e66fStephen Hines return fabs(v); 10075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float2 v) { 10095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return half_sqrt(v.x*v.x + v.y*v.y); 10105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float3 v) { 10125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return half_sqrt(v.x*v.x + v.y*v.y + v.z*v.z); 10135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float4 v) { 10155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return half_sqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w); 10165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float lhs, float rhs) { 10195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fast_length(lhs - rhs); 10205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float2 lhs, float2 rhs) { 10225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fast_length(lhs - rhs); 10235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float3 lhs, float3 rhs) { 10255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fast_length(lhs - rhs); 10265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float4 lhs, float4 rhs) { 10285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fast_length(lhs - rhs); 10295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) half_rsqrt(float); 10325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10333e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet/* For the normalization functions, vectors of length 0 should simply be 10343e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet * returned (i.e. all the components of that vector are 0). 10353e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet */ 10365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_normalize(float v) { 10373e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet if (v == 0.0f) { 10383e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return 0.0f; 10393e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet } else if (v < 0.0f) { 10403e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return -1.0f; 10413e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet } else { 10423e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return 1.0f; 10433e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet } 10445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10453e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet// If the length is 0, then rlength should be NaN. 10465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fast_normalize(float2 v) { 10473e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet float rlength = half_rsqrt(v.x*v.x + v.y*v.y); 10483e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return (rlength == rlength) ? v * rlength : v; 10495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fast_normalize(float3 v) { 10513e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet float rlength = half_rsqrt(v.x*v.x + v.y*v.y + v.z*v.z); 10523e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return (rlength == rlength) ? v * rlength : v; 10535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fast_normalize(float4 v) { 10553e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet float rlength = half_rsqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w); 10563e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet return (rlength == rlength) ? v * rlength : v; 10575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1059ba92a7085bbb8916334a6571ff33355873883173Jason Samsextern float __attribute__((overloadable)) half_recip(float v) { 1060ba92a7085bbb8916334a6571ff33355873883173Jason Sams return 1.f / v; 1061ba92a7085bbb8916334a6571ff33355873883173Jason Sams} 10625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/* 10645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) approx_atan(float x) { 10655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (x == 0.f) 10665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return 0.f; 10675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (x < 0.f) 10685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return -1.f * approx_atan(-1.f * x); 10695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (x > 1.f) 10705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return M_PI_2 - approx_atan(approx_recip(x)); 10715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return x * approx_recip(1.f + 0.28f * x*x); 10725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 10735a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(approx_atan) 10745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines*/ 10755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinestypedef union 10775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines{ 10785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float fv; 10795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t iv; 10805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} ieee_float_shape_type; 10815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/* Get a 32 bit int from a float. */ 10835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define GET_FLOAT_WORD(i,d) \ 10855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesdo { \ 10865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ieee_float_shape_type gf_u; \ 10875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines gf_u.fv = (d); \ 10885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (i) = gf_u.iv; \ 10895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} while (0) 10905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/* Set a float from a 32 bit int. */ 10925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 10935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define SET_FLOAT_WORD(d,i) \ 10945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesdo { \ 10955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ieee_float_shape_type sf_u; \ 10965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines sf_u.iv = (i); \ 10975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (d) = sf_u.fv; \ 10985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} while (0) 10995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// Valid -125 to 125 11035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_exp2(float v) { 11045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t iv = (int)v; 11055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t x = iv + (iv >> 31); // ~floor(v) 11065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float r = (v - x); 11075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float fo; 11095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines SET_FLOAT_WORD(fo, (x + 127) << 23); 11105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r *= 0.694f; // ~ log(e) / log(2) 11125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float r2 = r*r; 11135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float adj = 1.f + r + (r2 * 0.5f) + (r2*r * 0.166666f) + (r2*r2 * 0.0416666f); 11145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fo * adj; 11155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_exp2(float2 v) { 11185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int2 iv = convert_int2(v); 11195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int2 x = iv + (iv >> (int2)31);//floor(v); 11205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r = (v - convert_float2(x)); 11215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines x += 127; 11235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 fo = (float2)(x << (int2)23); 11255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r *= 0.694f; // ~ log(e) / log(2) 11275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 r2 = r*r; 11285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 adj = 1.f + r + (r2 * 0.5f) + (r2*r * 0.166666f) + (r2*r2 * 0.0416666f); 11295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fo * adj; 11305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_exp2(float4 v) { 11335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int4 iv = convert_int4(v); 11345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int4 x = iv + (iv >> (int4)31);//floor(v); 11355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r = (v - convert_float4(x)); 11365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines x += 127; 11385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 fo = (float4)(x << (int4)23); 11405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r *= 0.694f; // ~ log(e) / log(2) 11425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 r2 = r*r; 11435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 adj = 1.f + r + (r2 * 0.5f) + (r2*r * 0.166666f) + (r2*r2 * 0.0416666f); 11445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return fo * adj; 11455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_exp2(float3 v) { 11485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 t = 1.f; 11495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines t.xyz = v; 11505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(t).xyz; 11515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_exp(float v) { 11555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 1.442695041f); 11565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_exp(float2 v) { 11585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 1.442695041f); 11595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_exp(float3 v) { 11615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 1.442695041f); 11625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_exp(float4 v) { 11645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 1.442695041f); 11655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_exp10(float v) { 11685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 3.321928095f); 11695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_exp10(float2 v) { 11715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 3.321928095f); 11725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_exp10(float3 v) { 11745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 3.321928095f); 11755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_exp10(float4 v) { 11775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v * 3.321928095f); 11785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 11795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_log2(float v) { 11815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t ibits; 11825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines GET_FLOAT_WORD(ibits, v); 11835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines int32_t e = (ibits >> 23) & 0xff; 11855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ibits &= 0x7fffff; 11875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ibits |= 127 << 23; 11885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float ir; 11905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines SET_FLOAT_WORD(ir, ibits); 11915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 11925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines ir -= 1.5f; 11935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float ir2 = ir*ir; 11945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float adj2 = 0.405465108f + // -0.00009f + 11955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (0.666666667f * ir) - 11965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (0.222222222f * ir2) + 11975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (0.098765432f * ir*ir2) - 11985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (0.049382716f * ir2*ir2) + 11995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (0.026337449f * ir*ir2*ir2) - 12005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines (0.014631916f * ir2*ir2*ir2); 12015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines adj2 *= (1.f / 0.693147181f); 12025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return (float)(e - 127) + adj2; 12045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_log2(float2 v) { 12065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 v2 = {native_log2(v.x), native_log2(v.y)}; 12075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v2; 12085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_log2(float3 v) { 12105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 v2 = {native_log2(v.x), native_log2(v.y), native_log2(v.z)}; 12115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v2; 12125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_log2(float4 v) { 12145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 v2 = {native_log2(v.x), native_log2(v.y), native_log2(v.z), native_log2(v.w)}; 12155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return v2; 12165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_log(float v) { 12195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 1.442695041f); 12205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_log(float2 v) { 12225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 1.442695041f); 12235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_log(float3 v) { 12255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 1.442695041f); 12265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_log(float4 v) { 12285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 1.442695041f); 12295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_log10(float v) { 12325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 3.321928095f); 12335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_log10(float2 v) { 12355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 3.321928095f); 12365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_log10(float3 v) { 12385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 3.321928095f); 12395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_log10(float4 v) { 12415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_log2(v) * (1.f / 3.321928095f); 12425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 12455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_powr(float v, float y) { 12465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float v2 = native_log2(v); 12475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2 = fmax(v2, -125.f); 12485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v2 * y); 12495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_powr(float2 v, float2 y) { 12515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float2 v2 = native_log2(v); 12525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2 = fmax(v2, -125.f); 12535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v2 * y); 12545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_powr(float3 v, float3 y) { 12565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float3 v2 = native_log2(v); 12575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2 = fmax(v2, -125.f); 12585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v2 * y); 12595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_powr(float4 v, float4 y) { 12615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines float4 v2 = native_log2(v); 12625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines v2 = fmax(v2, -125.f); 12635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return native_exp2(v2 * y); 12645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 12655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 126653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double __attribute__((overloadable)) min(double v1, double v2) { 126753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return v1 < v2 ? v1 : v2; 126853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 126953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 127053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double2 __attribute__((overloadable)) min(double2 v1, double2 v2) { 127153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams double2 r; 127253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 127353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 127453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 127553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 127653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 127753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double3 __attribute__((overloadable)) min(double3 v1, double3 v2) { 127853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams double3 r; 127953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 128053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 128153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z < v2.z ? v1.z : v2.z; 128253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 128353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 128453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 128553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double4 __attribute__((overloadable)) min(double4 v1, double4 v2) { 128653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams double4 r; 128753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 128853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 128953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z < v2.z ? v1.z : v2.z; 129053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.w = v1.w < v2.w ? v1.w : v2.w; 129153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 129253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 129353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 129453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern int64_t _Z3minll(int64_t v1, int64_t v2) { 129553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return v1 < v2 ? v1 : v2; 129653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 129753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern long2 _Z3minDv2_lS_(long2 v1, long2 v2) { 129853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams long2 r; 129953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 130053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 130153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 130253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 130353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern long3 _Z3minDv3_lS_(long3 v1, long3 v2) { 130453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams long3 r; 130553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 130653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 130753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z < v2.z ? v1.z : v2.z; 130853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 130953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 131053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern long4 _Z3minDv4_lS_(long4 v1, long4 v2) { 131153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams long4 r; 131253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 131353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 131453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z < v2.z ? v1.z : v2.z; 131553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.w = v1.w < v2.w ? v1.w : v2.w; 131653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 131753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 131853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 131953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern uint64_t _Z3minyy(uint64_t v1, uint64_t v2) { 132053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return v1 < v2 ? v1 : v2; 132153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 132253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern ulong2 _Z3minDv2_yS_(ulong2 v1, ulong2 v2) { 132353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams ulong2 r; 132453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 132553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 132653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 132753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 132853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern ulong3 _Z3minDv3_yS_(ulong3 v1, ulong3 v2) { 132953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams ulong3 r; 133053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 133153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 133253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z < v2.z ? v1.z : v2.z; 133353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 133453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 133553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern ulong4 _Z3minDv4_yS_(ulong4 v1, ulong4 v2) { 133653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams ulong4 r; 133753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x < v2.x ? v1.x : v2.x; 133853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y < v2.y ? v1.y : v2.y; 133953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z < v2.z ? v1.z : v2.z; 134053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.w = v1.w < v2.w ? v1.w : v2.w; 134153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 134253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 134353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 134453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double __attribute__((overloadable)) max(double v1, double v2) { 134553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return v1 > v2 ? v1 : v2; 134653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 134753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 134853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double2 __attribute__((overloadable)) max(double2 v1, double2 v2) { 134953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams double2 r; 135053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 135153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 135253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 135353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 135453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 135553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double3 __attribute__((overloadable)) max(double3 v1, double3 v2) { 135653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams double3 r; 135753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 135853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 135953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z > v2.z ? v1.z : v2.z; 136053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 136153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 136253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 136353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double4 __attribute__((overloadable)) max(double4 v1, double4 v2) { 136453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams double4 r; 136553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 136653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 136753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z > v2.z ? v1.z : v2.z; 136853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.w = v1.w > v2.w ? v1.w : v2.w; 136953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 137053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 137153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 137253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern int64_t _Z3maxll(int64_t v1, int64_t v2) { 137353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return v1 > v2 ? v1 : v2; 137453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 137553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern long2 _Z3maxDv2_lS_(long2 v1, long2 v2) { 137653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams long2 r; 137753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 137853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 137953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 138053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 138153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern long3 _Z3maxDv3_lS_(long3 v1, long3 v2) { 138253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams long3 r; 138353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 138453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 138553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z > v2.z ? v1.z : v2.z; 138653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 138753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 138853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern long4 _Z3maxDv4_lS_(long4 v1, long4 v2) { 138953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams long4 r; 139053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 139153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 139253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z > v2.z ? v1.z : v2.z; 139353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.w = v1.w > v2.w ? v1.w : v2.w; 139453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 139553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 139653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 139753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern uint64_t _Z3maxyy(uint64_t v1, uint64_t v2) { 139853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return v1 > v2 ? v1 : v2; 139953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 140053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern ulong2 _Z3maxDv2_yS_(ulong2 v1, ulong2 v2) { 140153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams ulong2 r; 140253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 140353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 140453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 140553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 140653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern ulong3 _Z3maxDv3_yS_(ulong3 v1, ulong3 v2) { 140753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams ulong3 r; 140853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 140953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 141053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z > v2.z ? v1.z : v2.z; 141153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 141253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 141353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern ulong4 _Z3maxDv4_yS_(ulong4 v1, ulong4 v2) { 141453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams ulong4 r; 141553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.x = v1.x > v2.x ? v1.x : v2.x; 141653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.y = v1.y > v2.y ? v1.y : v2.y; 141753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.z = v1.z > v2.z ? v1.z : v2.z; 141853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams r.w = v1.w > v2.w ? v1.w : v2.w; 141953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams return r; 142053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams} 142153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams 14225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 14235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN 14245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef IN_FUNC_FN 14255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_FN 14265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_F 14275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_IN 14285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_I 14295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_PFN 14305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_PIN 14315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_FN_FN 14325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_FN_PIN 14335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef XN_FUNC_YN 14345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef UIN_FUNC_IN 14355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef IN_FUNC_IN 14365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef XN_FUNC_XN_XN_BODY 14375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef IN_FUNC_IN_IN_BODY 1438