1be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet#include "rs_core.rsh"
2f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar#include "rs_f16_util.h"
35a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
45a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) convert_float2(int2 c);
55a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) convert_float3(int3 c);
65a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) convert_float4(int4 c);
75a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
85a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int2 __attribute__((overloadable)) convert_int2(float2 c);
95a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int3 __attribute__((overloadable)) convert_int3(float3 c);
105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int4 __attribute__((overloadable)) convert_int4(float4 c);
115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fmin(float v, float v2);
145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fmin(float2 v, float v2);
155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fmin(float3 v, float v2);
165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fmin(float4 v, float v2);
175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fmax(float v, float v2);
195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fmax(float2 v, float v2);
205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fmax(float3 v, float v2);
215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fmax(float4 v, float v2);
225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// Float ops, 6.11.2
245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN(fnc)                                         \
265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fnc(float2 v) { \
275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float2 r;                                                   \
285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v.x);                                             \
295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v.y);                                             \
305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                   \
315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                               \
325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fnc(float3 v) { \
335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float3 r;                                                   \
345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v.x);                                             \
355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v.y);                                             \
365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v.z);                                             \
375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                   \
385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                               \
395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fnc(float4 v) { \
405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float4 r;                                                   \
415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v.x);                                             \
425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v.y);                                             \
435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v.z);                                             \
445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.w = fnc(v.w);                                             \
455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                   \
465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define IN_FUNC_FN(fnc)                                         \
495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int2 __attribute__((overloadable)) fnc(float2 v) {   \
505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    int2 r;                                                     \
515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v.x);                                             \
525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v.y);                                             \
535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                   \
545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                               \
555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int3 __attribute__((overloadable)) fnc(float3 v) {   \
565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    int3 r;                                                     \
575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v.x);                                             \
585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v.y);                                             \
595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v.z);                                             \
605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                   \
615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                               \
625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int4 __attribute__((overloadable)) fnc(float4 v) {   \
635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    int4 r;                                                     \
645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v.x);                                             \
655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v.y);                                             \
665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v.z);                                             \
675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.w = fnc(v.w);                                             \
685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                   \
695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_FN(fnc)                                                  \
725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fnc(float2 v1, float2 v2) { \
735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float2 r;                                                               \
745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2.x);                                                  \
755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2.y);                                                  \
765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                               \
775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                                           \
785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fnc(float3 v1, float3 v2) { \
795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float3 r;                                                               \
805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2.x);                                                  \
815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2.y);                                                  \
825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v1.z, v2.z);                                                  \
835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                               \
845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                                           \
855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fnc(float4 v1, float4 v2) { \
865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float4 r;                                                               \
875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2.x);                                                  \
885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2.y);                                                  \
895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v1.z, v2.z);                                                  \
905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.w = fnc(v1.w, v2.w);                                                  \
915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                               \
925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_F(fnc)                                                   \
955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fnc(float2 v1, float v2) {  \
965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float2 r;                                                               \
975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2);                                                    \
985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2);                                                    \
995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                               \
1005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                                           \
1015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fnc(float3 v1, float v2) {  \
1025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float3 r;                                                               \
1035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2);                                                    \
1045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2);                                                    \
1055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v1.z, v2);                                                    \
1065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                               \
1075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                                           \
1085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fnc(float4 v1, float v2) {  \
1095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float4 r;                                                               \
1105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2);                                                    \
1115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2);                                                    \
1125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v1.z, v2);                                                    \
1135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.w = fnc(v1.w, v2);                                                    \
1145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                               \
1155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
1165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
1175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_IN(fnc)                                                  \
1185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fnc(float2 v1, int2 v2) {   \
1195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float2 r;                                                               \
1205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2.x);                                                  \
1215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2.y);                                                  \
1225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                               \
1235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                                           \
1245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fnc(float3 v1, int3 v2) {   \
1255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float3 r;                                                               \
1265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2.x);                                                  \
1275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2.y);                                                  \
1285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v1.z, v2.z);                                                  \
1295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                               \
1305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                                           \
1315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fnc(float4 v1, int4 v2) {   \
1325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float4 r;                                                               \
1335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2.x);                                                  \
1345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2.y);                                                  \
1355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v1.z, v2.z);                                                  \
1365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.w = fnc(v1.w, v2.w);                                                  \
1375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                               \
1385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
1395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
1405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_I(fnc)                                                   \
1415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fnc(float2 v1, int v2) {    \
1425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float2 r;                                                               \
1435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2);                                                    \
1445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2);                                                    \
1455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                               \
1465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                                           \
1475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fnc(float3 v1, int v2) {    \
1485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float3 r;                                                               \
1495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2);                                                    \
1505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2);                                                    \
1515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v1.z, v2);                                                    \
1525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                               \
1535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                                           \
1545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fnc(float4 v1, int v2) {    \
1555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float4 r;                                                               \
1565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2);                                                    \
1575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2);                                                    \
1585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v1.z, v2);                                                    \
1595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.w = fnc(v1.w, v2);                                                    \
1605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                               \
1615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
1625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
1635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_PFN(fnc)                     \
1645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) \
1655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        fnc(float2 v1, float2 *v2) {            \
1665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float2 r;                                   \
1675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float t[2];                                 \
1685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, &t[0]);                     \
1695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, &t[1]);                     \
1705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v2->x = t[0];                               \
1715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v2->y = t[1];                               \
1725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                   \
1735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                               \
1745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) \
1755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        fnc(float3 v1, float3 *v2) {            \
1765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float3 r;                                   \
1775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float t[3];                                 \
1785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, &t[0]);                     \
1795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, &t[1]);                     \
1805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v1.z, &t[2]);                     \
1815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v2->x = t[0];                               \
1825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v2->y = t[1];                               \
1835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v2->z = t[2];                               \
1845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                   \
1855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                               \
1865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) \
1875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        fnc(float4 v1, float4 *v2) {            \
1885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float4 r;                                   \
1895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float t[4];                                 \
1905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, &t[0]);                     \
1915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, &t[1]);                     \
1925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v1.z, &t[2]);                     \
1935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.w = fnc(v1.w, &t[3]);                     \
1945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v2->x = t[0];                               \
1955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v2->y = t[1];                               \
1965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v2->z = t[2];                               \
1975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v2->w = t[3];                               \
1985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                   \
1995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
2005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
2015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_PIN(fnc)                                                 \
2025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fnc(float2 v1, int2 *v2) {  \
2035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float2 r;                                                               \
2045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    int t[2];                                                               \
2055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, &t[0]);                                                 \
2065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, &t[1]);                                                 \
2075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v2->x = t[0];                                                           \
2085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v2->y = t[1];                                                           \
2095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                               \
2105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                                           \
2115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fnc(float3 v1, int3 *v2) {  \
2125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float3 r;                                                               \
2135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    int t[3];                                                               \
2145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, &t[0]);                                                 \
2155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, &t[1]);                                                 \
2165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v1.z, &t[2]);                                                 \
2175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v2->x = t[0];                                                           \
2185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v2->y = t[1];                                                           \
2195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v2->z = t[2];                                                           \
2205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                               \
2215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                                           \
2225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fnc(float4 v1, int4 *v2) {  \
2235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float4 r;                                                               \
2245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    int t[4];                                                               \
2255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, &t[0]);                                                 \
2265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, &t[1]);                                                 \
2275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v1.z, &t[2]);                                                 \
2285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.w = fnc(v1.w, &t[3]);                                                 \
2295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v2->x = t[0];                                                           \
2305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v2->y = t[1];                                                           \
2315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v2->z = t[2];                                                           \
2325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v2->w = t[3];                                                           \
2335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                               \
2345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
2355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
2365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_FN_FN(fnc)                   \
2375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) \
2385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        fnc(float2 v1, float2 v2, float2 v3) {  \
2395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float2 r;                                   \
2405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2.x, v3.x);                \
2415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2.y, v3.y);                \
2425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                   \
2435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                               \
2445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) \
2455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        fnc(float3 v1, float3 v2, float3 v3) {  \
2465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float3 r;                                   \
2475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2.x, v3.x);                \
2485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2.y, v3.y);                \
2495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v1.z, v2.z, v3.z);                \
2505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                   \
2515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                               \
2525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) \
2535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        fnc(float4 v1, float4 v2, float4 v3) {  \
2545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float4 r;                                   \
2555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2.x, v3.x);                \
2565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2.y, v3.y);                \
2575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v1.z, v2.z, v3.z);                \
2585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.w = fnc(v1.w, v2.w, v3.w);                \
2595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                   \
2605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
2615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
2625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define FN_FUNC_FN_FN_PIN(fnc)                  \
2635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) \
2645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        fnc(float2 v1, float2 v2, int2 *v3) {   \
2655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float2 r;                                   \
2665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    int t[2];                                   \
2675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2.x, &t[0]);               \
2685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2.y, &t[1]);               \
2695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v3->x = t[0];                               \
2705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v3->y = t[1];                               \
2715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                   \
2725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                               \
2735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) \
2745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        fnc(float3 v1, float3 v2, int3 *v3) {   \
2755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float3 r;                                   \
2765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    int t[3];                                   \
2775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2.x, &t[0]);               \
2785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2.y, &t[1]);               \
2795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v1.z, v2.z, &t[2]);               \
2805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v3->x = t[0];                               \
2815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v3->y = t[1];                               \
2825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v3->z = t[2];                               \
2835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                   \
2845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                               \
2855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) \
2865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        fnc(float4 v1, float4 v2, int4 *v3) {   \
2875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float4 r;                                   \
2885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    int t[4];                                   \
2895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2.x, &t[0]);               \
2905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2.y, &t[1]);               \
2915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v1.z, v2.z, &t[2]);               \
2925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.w = fnc(v1.w, v2.w, &t[3]);               \
2935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v3->x = t[0];                               \
2945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v3->y = t[1];                               \
2955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v3->z = t[2];                               \
2965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    v3->w = t[3];                               \
2975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                   \
2985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
2995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
300863237215cab4812df373b63ba3bbf2bc1d8647dJean-Luc Brouilletstatic const unsigned int iposinf = 0x7f800000;
301863237215cab4812df373b63ba3bbf2bc1d8647dJean-Luc Brouilletstatic const unsigned int ineginf = 0xff800000;
3025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
303863237215cab4812df373b63ba3bbf2bc1d8647dJean-Luc Brouilletstatic float posinf() {
3045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float f = *((float*)&iposinf);
3055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return f;
3065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
3075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
308863237215cab4812df373b63ba3bbf2bc1d8647dJean-Luc Brouilletstatic unsigned int float_bits(float f) {
309830763f83ccddb9f0457eaf30c724525b889bed8Jean-Luc Brouillet    /* TODO(jeanluc) Use this better approach once the Mac(SDK) build issues are fixed.
310863237215cab4812df373b63ba3bbf2bc1d8647dJean-Luc Brouillet    // Get the bits while following the strict aliasing rules.
311830763f83ccddb9f0457eaf30c724525b889bed8Jean-Luc Brouillet    unsigned int result;
312863237215cab4812df373b63ba3bbf2bc1d8647dJean-Luc Brouillet    memcpy(&result, &f, sizeof(f));
313863237215cab4812df373b63ba3bbf2bc1d8647dJean-Luc Brouillet    return result;
314830763f83ccddb9f0457eaf30c724525b889bed8Jean-Luc Brouillet    */
315830763f83ccddb9f0457eaf30c724525b889bed8Jean-Luc Brouillet    return *(unsigned int*)(char*)(&f);
3165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
3175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
3185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic bool isinf(float f) {
319863237215cab4812df373b63ba3bbf2bc1d8647dJean-Luc Brouillet    unsigned int i = float_bits(f);
3205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return (i == iposinf) || (i == ineginf);
3215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
3225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
3235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic bool isnan(float f) {
324863237215cab4812df373b63ba3bbf2bc1d8647dJean-Luc Brouillet    unsigned int i = float_bits(f);
3255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return (((i & 0x7f800000) == 0x7f800000) && (i & 0x007fffff));
3265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
3275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
3285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic bool isposzero(float f) {
329863237215cab4812df373b63ba3bbf2bc1d8647dJean-Luc Brouillet    return (float_bits(f) == 0x00000000);
3305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
3315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
3325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic bool isnegzero(float f) {
333863237215cab4812df373b63ba3bbf2bc1d8647dJean-Luc Brouillet    return (float_bits(f) == 0x80000000);
3345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
3355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
3365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic bool iszero(float f) {
3375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return isposzero(f) || isnegzero(f);
3385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
3395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
3405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
341e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_acosf(float);
342e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) acos(float v) {
343e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_acosf(v);
344e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
3455a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(acos)
3465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
347e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_acoshf(float);
348e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) acosh(float v) {
349e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_acoshf(v);
350e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
3515a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(acosh)
3525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
3535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
3545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) acospi(float v) {
3555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return acos(v) / M_PI;
3565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
3575a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(acospi)
3585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
359e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_asinf(float);
360e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) asin(float v) {
361e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_asinf(v);
362e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
3635a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(asin)
3645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
365e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_asinhf(float);
366e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) asinh(float v) {
367e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_asinhf(v);
368e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
3695a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(asinh)
3705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
3715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) asinpi(float v) {
3725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return asin(v) / M_PI;
3735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
3745a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(asinpi)
3755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
376e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_atanf(float);
377e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) atan(float v) {
378e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_atanf(v);
379e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
3805a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(atan)
3815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
382e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_atan2f(float, float);
383e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) atan2(float v1, float v2) {
384e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_atan2f(v1, v2);
385e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
3865a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(atan2)
3875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
388e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_atanhf(float);
389e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) atanh(float v) {
390e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_atanhf(v);
391e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
3925a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(atanh)
3935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
3945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) atanpi(float v) {
3955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return atan(v) / M_PI;
3965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
3975a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(atanpi)
3985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
3995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
4005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) atan2pi(float y, float x) {
4015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return atan2(y, x) / M_PI;
4025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
4035a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(atan2pi)
4045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
405e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_cbrtf(float);
406e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) cbrt(float v) {
407e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_cbrtf(v);
408e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
4095a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(cbrt)
4105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
411e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_ceilf(float);
412e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) ceil(float v) {
413e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_ceilf(v);
414e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
4155a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(ceil)
4165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
417e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_copysignf(float, float);
418e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) copysign(float v1, float v2) {
419e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_copysignf(v1, v2);
420e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
4215a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(copysign)
4225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
423e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_cosf(float);
424e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) cos(float v) {
425e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_cosf(v);
426e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
4275a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(cos)
4285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
429e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_coshf(float);
430e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) cosh(float v) {
431e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_coshf(v);
432e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
4335a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(cosh)
4345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
4355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) cospi(float v) {
4365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return cos(v * M_PI);
4375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
4385a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(cospi)
4395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
440e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_erfcf(float);
441e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) erfc(float v) {
442e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_erfcf(v);
443e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
4445a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(erfc)
4455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
446e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_erff(float);
447e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) erf(float v) {
448e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_erff(v);
449e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
4505a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(erf)
4515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
452e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_expf(float);
453e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) exp(float v) {
454e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_expf(v);
455e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
4565a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(exp)
4575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
458e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_exp2f(float);
459e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) exp2(float v) {
460e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_exp2f(v);
461e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
4625a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(exp2)
4635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
4645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) pow(float, float);
4655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
4665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) exp10(float v) {
4675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return exp2(v * 3.321928095f);
4685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
4695a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(exp10)
4705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
471e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_expm1f(float);
472e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) expm1(float v) {
473e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_expm1f(v);
474e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
4755a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(expm1)
4765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
4775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fabs(float v) {
4785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    int i = *((int*)(void*)&v) & 0x7fffffff;
4795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return  *((float*)(void*)&i);
4805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
4815a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(fabs)
4825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
483e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_fdimf(float, float);
484e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) fdim(float v1, float v2) {
485e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_fdimf(v1, v2);
486e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
4875a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(fdim)
4885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
489e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_floorf(float);
490e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) floor(float v) {
491e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_floorf(v);
492e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
4935a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(floor)
4945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
495e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_fmaf(float, float, float);
496e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) fma(float v1, float v2, float v3) {
497e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_fmaf(v1, v2, v3);
498e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
4995a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN_FN(fma)
5005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
501e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_fminf(float, float);
5025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
503e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_fmodf(float, float);
504e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) fmod(float v1, float v2) {
505e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_fmodf(v1, v2);
506e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
5075a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(fmod)
5085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
5095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fract(float v, float *iptr) {
5105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    int i = (int)floor(v);
5115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (iptr) {
5125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        iptr[0] = i;
5135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    }
5145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return fmin(v - i, 0x1.fffffep-1f);
5155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
5165a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_PFN(fract)
5175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
5189cbc99ba45126a6a30ba13fc6d4e75e51ca14ea7Verena Beckhamextern float __attribute__((const, overloadable)) fract(float v) {
5199cbc99ba45126a6a30ba13fc6d4e75e51ca14ea7Verena Beckham    float unused;
5209cbc99ba45126a6a30ba13fc6d4e75e51ca14ea7Verena Beckham    return fract(v, &unused);
5219cbc99ba45126a6a30ba13fc6d4e75e51ca14ea7Verena Beckham}
5229cbc99ba45126a6a30ba13fc6d4e75e51ca14ea7Verena BeckhamFN_FUNC_FN(fract)
5239cbc99ba45126a6a30ba13fc6d4e75e51ca14ea7Verena Beckham
524e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_frexpf(float, int *);
525e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) frexp(float v1, int* v2) {
526e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_frexpf(v1, v2);
527e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
5285a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_PIN(frexp)
5295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
530e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_hypotf(float, float);
531e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) hypot(float v1, float v2) {
532e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_hypotf(v1, v2);
533e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
5345a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(hypot)
5355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
536e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern int __attribute__((overloadable)) SC_ilogbf(float);
537e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamint __attribute__((overloadable)) ilogb(float v) {
538e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_ilogbf(v);
539e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
5405a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesIN_FUNC_FN(ilogb)
5415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
542e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_ldexpf(float, int);
543e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) ldexp(float v1, int v2) {
544e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_ldexpf(v1, v2);
545e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
5465a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_IN(ldexp)
5475a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_I(ldexp)
5485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
549e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_lgammaf(float);
550e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) lgamma(float v) {
551e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_lgammaf(v);
552e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
5535a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(lgamma)
554e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_lgammaf_r(float, int*);
555e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) lgamma(float v, int* ptr) {
556e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_lgammaf_r(v, ptr);
557e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
5585a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_PIN(lgamma)
5595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
560e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_logf(float);
561e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) log(float v) {
562e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_logf(v);
563e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
5645a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(log)
5655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
566e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_log10f(float);
567e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) log10(float v) {
568e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_log10f(v);
569e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
5705a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(log10)
5715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
5725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
5735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) log2(float v) {
5745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return log10(v) * 3.321928095f;
5755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
5765a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(log2)
5775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
578e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_log1pf(float);
579e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) log1p(float v) {
580e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_log1pf(v);
581e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
5825a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(log1p)
5835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
584e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_logbf(float);
585e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) logb(float v) {
586e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_logbf(v);
587e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
5885a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(logb)
5895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
5905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) mad(float a, float b, float c) {
5915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return a * b + c;
5925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
5935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) mad(float2 a, float2 b, float2 c) {
5945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return a * b + c;
5955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
5965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) mad(float3 a, float3 b, float3 c) {
5975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return a * b + c;
5985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
5995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) mad(float4 a, float4 b, float4 c) {
6005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return a * b + c;
6015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
6025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
603e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_modff(float, float *);
604e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) modf(float v1, float *v2) {
605e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_modff(v1, v2);
606e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
6075a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_PFN(modf);
6085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
6095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) nan(uint v) {
6105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float f[1];
6115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    uint32_t *ip = (uint32_t *)f;
6125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    *ip = v | 0x7fc00000;
6135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return f[0];
6145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
6155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
616e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_nextafterf(float, float);
617e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) nextafter(float v1, float v2) {
618e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_nextafterf(v1, v2);
619e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
6205a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(nextafter)
6215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
622fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// This function must be defined here if we're compiling with debug info
623fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// (libclcore_g.bc), because we need a C source to get debug information.
624fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// Otherwise the implementation can be found in IR.
625fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#if defined(RS_G_RUNTIME)
626fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckhamextern float __attribute__((overloadable)) SC_powf(float, float);
627fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckhamfloat __attribute__((overloadable)) pow(float v1, float v2) {
628fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham    return SC_powf(v1, v2);
629fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham}
630f72e74660567181b79673f2a476a6957db2507e5Stephen Hines#endif // defined(RS_G_RUNTIME)
6315a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(pow)
6325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
6335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) pown(float v, int p) {
6340b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet    /* The mantissa of a float has fewer bits than an int (24 effective vs. 31).
6350b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet     * For very large ints, we'll lose whether the exponent is even or odd, making
636bcd5b9af756d10317faf54fa3742f89dfacef152Jean-Luc Brouillet     * the selection of a correct sign incorrect.  We correct this.  Use copysign
637bcd5b9af756d10317faf54fa3742f89dfacef152Jean-Luc Brouillet     * to handle the negative zero case.
6380b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet     */
639bcd5b9af756d10317faf54fa3742f89dfacef152Jean-Luc Brouillet    float sign = (p & 0x1) ? copysign(1.f, v) : 1.f;
6400b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet    float f = pow(v, (float)p);
6410b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet    return copysign(f, sign);
6420b0bcff691d047da1d658889866c6a0347850f1cJean-Luc Brouillet}
6430b0bcff691d047da1d658889866c6a0347850f1cJean-Luc BrouilletFN_FUNC_FN_IN(pown)
6445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
6455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) powr(float v, float p) {
6465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return pow(v, p);
6475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
6485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) powr(float2 v, float2 p) {
6495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return pow(v, p);
6505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
6515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) powr(float3 v, float3 p) {
6525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return pow(v, p);
6535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
6545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) powr(float4 v, float4 p) {
6555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return pow(v, p);
6565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
6575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
658e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_remainderf(float, float);
659e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) remainder(float v1, float v2) {
660e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_remainderf(v1, v2);
661e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
6625a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN(remainder)
6635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
664e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_remquof(float, float, int *);
665e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) remquo(float v1, float v2, int *v3) {
666e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_remquof(v1, v2, v3);
667e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
6685a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_FN_PIN(remquo)
6695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
670e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_rintf(float);
671e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) rint(float v) {
672e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_rintf(v);
673e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
6745a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(rint)
6755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
6765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) rootn(float v, int r) {
6775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (r == 0) {
6783a3dfe7ecba55a3a832b44e4337276c09a6a25e9Dan Albert        return posinf();
6795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    }
6805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
6815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (iszero(v)) {
6825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        if (r < 0) {
6835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines            if (r & 1) {
6845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines                return copysign(posinf(), v);
6855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines            } else {
6865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines                return posinf();
6875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines            }
6885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        } else {
6895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines            if (r & 1) {
6905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines                return copysign(0.f, v);
6915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines            } else {
6925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines                return 0.f;
6935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines            }
6945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        }
6955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    }
6965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
6975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (!isinf(v) && !isnan(v) && (v < 0.f)) {
6985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        if (r & 1) {
6995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines            return (-1.f * pow(-1.f * v, 1.f / r));
7005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        } else {
7015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines            return nan(0);
7025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        }
7035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    }
7045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
7055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return pow(v, 1.f / r);
7065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
7075a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN_IN(rootn);
7085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
709e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_roundf(float);
710e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) round(float v) {
711e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_roundf(v);
712e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
7135a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(round)
7145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
715e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_randf2(float, float);
716e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) rsRand(float min, float max) {
717e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham  return SC_randf2(min, max);
718e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
719e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham
7205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
7215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) rsqrt(float v) {
7225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return 1.f / sqrt(v);
7235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
724146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines
725fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#if !defined(ARCH_X86_HAVE_SSSE3) || defined(RS_DEBUG_RUNTIME) || defined(RS_G_RUNTIME)
726a673fb0db28eac2300fcfa04549138c1c9202014Stephen Hines// These functions must be defined here if we are not using the SSE
727a673fb0db28eac2300fcfa04549138c1c9202014Stephen Hines// implementation, which includes when we are built as part of the
728fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// debug runtime (libclcore_debug.bc) or compiling with debug info.
729fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#if defined(RS_G_RUNTIME)
730fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckhamextern float __attribute__((overloadable)) SC_sqrtf(float);
731fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckhamfloat __attribute__((overloadable)) sqrt(float v) {
732fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham    return SC_sqrtf(v);
733fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham}
734f72e74660567181b79673f2a476a6957db2507e5Stephen Hines#endif // defined(RS_G_RUNTIME)
735fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham
736146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen HinesFN_FUNC_FN(sqrt)
737a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#else
738a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsextern float2 __attribute__((overloadable)) sqrt(float2);
739a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsextern float3 __attribute__((overloadable)) sqrt(float3);
740a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsextern float4 __attribute__((overloadable)) sqrt(float4);
741fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#endif // !defined(ARCH_X86_HAVE_SSSE3) || defined(RS_DEBUG_RUNTIME) || defined(RS_G_RUNTIME)
742146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines
7435a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(rsqrt)
7445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
745e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_sinf(float);
746e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) sin(float v) {
747e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_sinf(v);
748e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
7495a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sin)
7505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
7515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sincos(float v, float *cosptr) {
7525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    *cosptr = cos(v);
7535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return sin(v);
7545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
7555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) sincos(float2 v, float2 *cosptr) {
7565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    *cosptr = cos(v);
7575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return sin(v);
7585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
7595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) sincos(float3 v, float3 *cosptr) {
7605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    *cosptr = cos(v);
7615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return sin(v);
7625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
7635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) sincos(float4 v, float4 *cosptr) {
7645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    *cosptr = cos(v);
7655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return sin(v);
7665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
7675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
768e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_sinhf(float);
769e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) sinh(float v) {
770e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_sinhf(v);
771e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
7725a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sinh)
7735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
7745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sinpi(float v) {
7755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return sin(v * M_PI);
7765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
7775a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sinpi)
7785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
779e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_tanf(float);
780e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) tan(float v) {
781e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_tanf(v);
782e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
7835a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tan)
7845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
785e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_tanhf(float);
786e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) tanh(float v) {
787e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_tanhf(v);
788e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
7895a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tanh)
7905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
7915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) tanpi(float v) {
7925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return tan(v * M_PI);
7935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
7945a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tanpi)
7955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
7965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
797e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_tgammaf(float);
798e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) tgamma(float v) {
799e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_tgammaf(v);
800e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
8015a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(tgamma)
8025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
803e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern float __attribute__((overloadable)) SC_truncf(float);
804e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamfloat __attribute__((overloadable)) trunc(float v) {
805e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham    return SC_truncf(v);
806e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham}
8075a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(trunc)
8085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
8095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// Int ops (partial), 6.11.3
8105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
8115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define XN_FUNC_YN(typeout, fnc, typein)                                \
8125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout __attribute__((overloadable)) fnc(typein);               \
8135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout##2 __attribute__((overloadable)) fnc(typein##2 v) {  \
8145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    typeout##2 r;                                                       \
8155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v.x);                                                     \
8165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v.y);                                                     \
8175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                           \
8185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                                       \
8195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout##3 __attribute__((overloadable)) fnc(typein##3 v) {  \
8205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    typeout##3 r;                                                       \
8215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v.x);                                                     \
8225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v.y);                                                     \
8235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v.z);                                                     \
8245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                           \
8255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                                       \
8265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern typeout##4 __attribute__((overloadable)) fnc(typein##4 v) {  \
8275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    typeout##4 r;                                                       \
8285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v.x);                                                     \
8295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v.y);                                                     \
8305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v.z);                                                     \
8315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.w = fnc(v.w);                                                     \
8325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                           \
8335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
8345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
8355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
8365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define UIN_FUNC_IN(fnc)          \
8375a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uchar, fnc, char)      \
8385a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(ushort, fnc, short)    \
8395a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uint, fnc, int)
8405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
8415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define IN_FUNC_IN(fnc)           \
8425a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uchar, fnc, uchar)     \
8435a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(char, fnc, char)       \
8445a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(ushort, fnc, ushort)   \
8455a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(short, fnc, short)     \
8465a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(uint, fnc, uint)       \
8475a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_YN(int, fnc, int)
8485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
8495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
8505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define XN_FUNC_XN_XN_BODY(type, fnc, body)         \
8515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type __attribute__((overloadable))       \
8525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        fnc(type v1, type v2) {                     \
8535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return body;                                    \
8545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                   \
8555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type##2 __attribute__((overloadable))    \
8565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        fnc(type##2 v1, type##2 v2) {               \
8575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    type##2 r;                                      \
8585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2.x);                          \
8595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2.y);                          \
8605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                       \
8615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                   \
8625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type##3 __attribute__((overloadable))    \
8635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        fnc(type##3 v1, type##3 v2) {               \
8645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    type##3 r;                                      \
8655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2.x);                          \
8665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2.y);                          \
8675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v1.z, v2.z);                          \
8685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                       \
8695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                   \
8705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern type##4 __attribute__((overloadable))    \
8715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        fnc(type##4 v1, type##4 v2) {               \
8725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    type##4 r;                                      \
8735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = fnc(v1.x, v2.x);                          \
8745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = fnc(v1.y, v2.y);                          \
8755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = fnc(v1.z, v2.z);                          \
8765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.w = fnc(v1.w, v2.w);                          \
8775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                       \
8785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
8795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
8805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define IN_FUNC_IN_IN_BODY(fnc, body) \
8815a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(uchar, fnc, body)  \
8825a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(char, fnc, body)   \
8835a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(ushort, fnc, body) \
8845a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(short, fnc, body)  \
8855a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(uint, fnc, body)   \
8865a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(int, fnc, body)    \
8875a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesXN_FUNC_XN_XN_BODY(float, fnc, body)
8885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
8895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
8905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/**
8915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines * abs
8925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines */
8935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable)) abs(int32_t v) {
8945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (v < 0)
8955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        return -v;
8965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return v;
8975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
8985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint16_t __attribute__((overloadable)) abs(int16_t v) {
8995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (v < 0)
9005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        return -v;
9015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return v;
9025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint8_t __attribute__((overloadable)) abs(int8_t v) {
9045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (v < 0)
9055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        return -v;
9065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return v;
9075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
9095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/**
9105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines * clz
911c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines * __builtin_clz only accepts a 32-bit unsigned int, so every input will be
912c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines * expanded to 32 bits. For our smaller data types, we need to subtract off
913c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines * these unused top bits (that will be always be composed of zeros).
9145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines */
9155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable)) clz(uint32_t v) {
9165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return __builtin_clz(v);
9175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint16_t __attribute__((overloadable)) clz(uint16_t v) {
919c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines    return __builtin_clz(v) - 16;
9205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint8_t __attribute__((overloadable)) clz(uint8_t v) {
922c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines    return __builtin_clz(v) - 24;
9235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int32_t __attribute__((overloadable)) clz(int32_t v) {
925c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines    return __builtin_clz(v);
9265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int16_t __attribute__((overloadable)) clz(int16_t v) {
928c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines    return __builtin_clz(((uint32_t)v) & 0x0000ffff) - 16;
9295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern int8_t __attribute__((overloadable)) clz(int8_t v) {
931c117d8dad895ab9bae4ba6077365f0dfd33ece47Stephen Hines    return __builtin_clz(((uint32_t)v) & 0x000000ff) - 24;
9325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
9345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
9355a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesUIN_FUNC_IN(abs)
9365a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesIN_FUNC_IN(clz)
9375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
9385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
9395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// 6.11.4
9405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
9415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
9425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) degrees(float radians) {
9435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return radians * (180.f / M_PI);
9445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) degrees(float2 radians) {
9465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return radians * (180.f / M_PI);
9475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) degrees(float3 radians) {
9495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return radians * (180.f / M_PI);
9505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) degrees(float4 radians) {
9525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return radians * (180.f / M_PI);
9535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
9555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) mix(float start, float stop, float amount) {
9565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return start + (stop - start) * amount;
9575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) mix(float2 start, float2 stop, float2 amount) {
9595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return start + (stop - start) * amount;
9605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) mix(float3 start, float3 stop, float3 amount) {
9625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return start + (stop - start) * amount;
9635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) mix(float4 start, float4 stop, float4 amount) {
9655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return start + (stop - start) * amount;
9665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) mix(float2 start, float2 stop, float amount) {
9685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return start + (stop - start) * amount;
9695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) mix(float3 start, float3 stop, float amount) {
9715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return start + (stop - start) * amount;
9725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) mix(float4 start, float4 stop, float amount) {
9745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return start + (stop - start) * amount;
9755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
9775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) radians(float degrees) {
9785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return degrees * (M_PI / 180.f);
9795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) radians(float2 degrees) {
9815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return degrees * (M_PI / 180.f);
9825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) radians(float3 degrees) {
9845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return degrees * (M_PI / 180.f);
9855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) radians(float4 degrees) {
9875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return degrees * (M_PI / 180.f);
9885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
9905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) step(float edge, float v) {
9915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return (v < edge) ? 0.f : 1.f;
9925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) step(float2 edge, float2 v) {
9945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float2 r;
9955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = (v.x < edge.x) ? 0.f : 1.f;
9965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = (v.y < edge.y) ? 0.f : 1.f;
9975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;
9985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
9995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) step(float3 edge, float3 v) {
10005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float3 r;
10015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = (v.x < edge.x) ? 0.f : 1.f;
10025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = (v.y < edge.y) ? 0.f : 1.f;
10035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = (v.z < edge.z) ? 0.f : 1.f;
10045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;
10055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
10065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) step(float4 edge, float4 v) {
10075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float4 r;
10085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = (v.x < edge.x) ? 0.f : 1.f;
10095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = (v.y < edge.y) ? 0.f : 1.f;
10105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = (v.z < edge.z) ? 0.f : 1.f;
10115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.w = (v.w < edge.w) ? 0.f : 1.f;
10125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;
10135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
10145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) step(float2 edge, float v) {
10155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float2 r;
10165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = (v < edge.x) ? 0.f : 1.f;
10175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = (v < edge.y) ? 0.f : 1.f;
10185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;
10195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
10205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) step(float3 edge, float v) {
10215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float3 r;
10225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = (v < edge.x) ? 0.f : 1.f;
10235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = (v < edge.y) ? 0.f : 1.f;
10245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = (v < edge.z) ? 0.f : 1.f;
10255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;
10265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
10275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) step(float4 edge, float v) {
10285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float4 r;
10295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = (v < edge.x) ? 0.f : 1.f;
10305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = (v < edge.y) ? 0.f : 1.f;
10315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = (v < edge.z) ? 0.f : 1.f;
10325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.w = (v < edge.w) ? 0.f : 1.f;
10335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;
10345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
10350ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouilletextern float2 __attribute__((overloadable)) step(float edge, float2 v) {
10360ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet    float2 r;
10370ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet    r.x = (v.x < edge) ? 0.f : 1.f;
10380ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet    r.y = (v.y < edge) ? 0.f : 1.f;
10390ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet    return r;
10400ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet}
10410ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouilletextern float3 __attribute__((overloadable)) step(float edge, float3 v) {
10420ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet    float3 r;
10430ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet    r.x = (v.x < edge) ? 0.f : 1.f;
10440ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet    r.y = (v.y < edge) ? 0.f : 1.f;
10450ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet    r.z = (v.z < edge) ? 0.f : 1.f;
10460ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet    return r;
10470ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet}
10480ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouilletextern float4 __attribute__((overloadable)) step(float edge, float4 v) {
10490ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet    float4 r;
10500ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet    r.x = (v.x < edge) ? 0.f : 1.f;
10510ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet    r.y = (v.y < edge) ? 0.f : 1.f;
10520ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet    r.z = (v.z < edge) ? 0.f : 1.f;
10530ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet    r.w = (v.w < edge) ? 0.f : 1.f;
10540ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet    return r;
10550ec1635641a2075c9d2349219632650401f88881Jean-Luc Brouillet}
10565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
10575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) sign(float v) {
10585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (v > 0) return 1.f;
10595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (v < 0) return -1.f;
10605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return v;
10615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
10625a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(sign)
10635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
10645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
10655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// 6.11.5
10665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) cross(float3 lhs, float3 rhs) {
10675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float3 r;
10685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = lhs.y * rhs.z  - lhs.z * rhs.y;
10695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = lhs.z * rhs.x  - lhs.x * rhs.z;
10705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = lhs.x * rhs.y  - lhs.y * rhs.x;
10715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;
10725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
10735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
10745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) cross(float4 lhs, float4 rhs) {
10755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float4 r;
10765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = lhs.y * rhs.z  - lhs.z * rhs.y;
10775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = lhs.z * rhs.x  - lhs.x * rhs.z;
10785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = lhs.x * rhs.y  - lhs.y * rhs.x;
10795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.w = 0.f;
10805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;
10815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
10825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
1083fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#if !defined(ARCH_X86_HAVE_SSSE3) || defined(RS_DEBUG_RUNTIME) || defined(RS_G_RUNTIME)
1084a673fb0db28eac2300fcfa04549138c1c9202014Stephen Hines// These functions must be defined here if we are not using the SSE
1085a673fb0db28eac2300fcfa04549138c1c9202014Stephen Hines// implementation, which includes when we are built as part of the
1086fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham// debug runtime (libclcore_debug.bc) or compiling with debug info.
1087146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines
1088146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) dot(float lhs, float rhs) {
1089146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines    return lhs * rhs;
1090146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines}
1091146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) dot(float2 lhs, float2 rhs) {
1092146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines    return lhs.x*rhs.x + lhs.y*rhs.y;
1093146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines}
1094146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) dot(float3 lhs, float3 rhs) {
1095146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines    return lhs.x*rhs.x + lhs.y*rhs.y + lhs.z*rhs.z;
1096146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines}
1097146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) dot(float4 lhs, float4 rhs) {
1098146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines    return lhs.x*rhs.x + lhs.y*rhs.y + lhs.z*rhs.z + lhs.w*rhs.w;
1099146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines}
1100146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines
1101146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) length(float v) {
1102146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines    return fabs(v);
1103146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines}
1104146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) length(float2 v) {
1105146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines    return sqrt(v.x*v.x + v.y*v.y);
1106146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines}
1107146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) length(float3 v) {
1108146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines    return sqrt(v.x*v.x + v.y*v.y + v.z*v.z);
1109146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines}
1110146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hinesextern float __attribute__((overloadable)) length(float4 v) {
1111146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines    return sqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w);
1112146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines}
1113146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines
1114146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines#else
1115146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines
11165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float v);
11175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float2 v);
11185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float3 v);
11195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) length(float4 v);
11205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
1121fb99e0f905b0f73a505c7900b434531ce7c3e2e5Verena Beckham#endif // !defined(ARCH_X86_HAVE_SSSE3) || defined(RS_DEBUG_RUNTIME) || defined(RS_G_RUNTIME)
1122146e138f5c6eb4980ee6d85d33b951b87b6e8efeStephen Hines
11235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float lhs, float rhs) {
11245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return length(lhs - rhs);
11255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
11265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float2 lhs, float2 rhs) {
11275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return length(lhs - rhs);
11285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
11295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float3 lhs, float3 rhs) {
11305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return length(lhs - rhs);
11315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
11325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) distance(float4 lhs, float4 rhs) {
11335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return length(lhs - rhs);
11345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
11355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
11363e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet/* For the normalization functions, vectors of length 0 should simply be
11373e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet * returned (i.e. all the components of that vector are 0).
11383e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet */
11395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) normalize(float v) {
11403e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    if (v == 0.0f) {
11413e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet        return 0.0f;
11423e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    } else if (v < 0.0f) {
11433e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet        return -1.0f;
11443e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    } else {
11453e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet        return 1.0f;
11463e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    }
11475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
11485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) normalize(float2 v) {
11493e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    float l = length(v);
11503e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    return l == 0.0f ? v : v / l;
11515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
11525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) normalize(float3 v) {
11533e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    float l = length(v);
11543e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    return l == 0.0f ? v : v / l;
11555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
11565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) normalize(float4 v) {
11573e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    float l = length(v);
11583e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    return l == 0.0f ? v : v / l;
11595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
11605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
1161ba92a7085bbb8916334a6571ff33355873883173Jason Samsextern float __attribute__((overloadable)) half_sqrt(float v) {
1162ba92a7085bbb8916334a6571ff33355873883173Jason Sams    return sqrt(v);
1163ba92a7085bbb8916334a6571ff33355873883173Jason Sams}
1164ba92a7085bbb8916334a6571ff33355873883173Jason SamsFN_FUNC_FN(half_sqrt)
11655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
11665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float v) {
1167582b3646d6634f74a13828cceb1414823c18e66fStephen Hines    return fabs(v);
11685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
11695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float2 v) {
11705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return half_sqrt(v.x*v.x + v.y*v.y);
11715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
11725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float3 v) {
11735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return half_sqrt(v.x*v.x + v.y*v.y + v.z*v.z);
11745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
11755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_length(float4 v) {
11765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return half_sqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w);
11775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
11785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
11795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float lhs, float rhs) {
11805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return fast_length(lhs - rhs);
11815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
11825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float2 lhs, float2 rhs) {
11835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return fast_length(lhs - rhs);
11845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
11855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float3 lhs, float3 rhs) {
11865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return fast_length(lhs - rhs);
11875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
11885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_distance(float4 lhs, float4 rhs) {
11895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return fast_length(lhs - rhs);
11905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
11915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
11925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) half_rsqrt(float);
11935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
11943e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet/* For the normalization functions, vectors of length 0 should simply be
11953e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet * returned (i.e. all the components of that vector are 0).
11963e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet */
11975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) fast_normalize(float v) {
11983e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    if (v == 0.0f) {
11993e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet        return 0.0f;
12003e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    } else if (v < 0.0f) {
12013e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet        return -1.0f;
12023e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    } else {
12033e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet        return 1.0f;
12043e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    }
12055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
12063e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet// If the length is 0, then rlength should be NaN.
12075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) fast_normalize(float2 v) {
12083e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    float rlength = half_rsqrt(v.x*v.x + v.y*v.y);
12093e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    return (rlength == rlength) ? v * rlength : v;
12105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
12115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) fast_normalize(float3 v) {
12123e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    float rlength = half_rsqrt(v.x*v.x + v.y*v.y + v.z*v.z);
12133e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    return (rlength == rlength) ? v * rlength : v;
12145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
12155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) fast_normalize(float4 v) {
12163e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    float rlength = half_rsqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w);
12173e0d1e79789df55021b459ae13590844b67aebd2Jean-Luc Brouillet    return (rlength == rlength) ? v * rlength : v;
12185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
12195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
1220ba92a7085bbb8916334a6571ff33355873883173Jason Samsextern float __attribute__((overloadable)) half_recip(float v) {
1221ba92a7085bbb8916334a6571ff33355873883173Jason Sams    return 1.f / v;
1222ba92a7085bbb8916334a6571ff33355873883173Jason Sams}
12235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
12245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/*
12255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) approx_atan(float x) {
12265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (x == 0.f)
12275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        return 0.f;
12285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (x < 0.f)
12295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        return -1.f * approx_atan(-1.f * x);
12305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (x > 1.f)
12315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        return M_PI_2 - approx_atan(approx_recip(x));
12325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return x * approx_recip(1.f + 0.28f * x*x);
12335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
12345a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesFN_FUNC_FN(approx_atan)
12355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines*/
12365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
12375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinestypedef union
12385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines{
12395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines  float fv;
12405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines  int32_t iv;
12415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} ieee_float_shape_type;
12425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
12435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/* Get a 32 bit int from a float.  */
12445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
12455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define GET_FLOAT_WORD(i,d)                 \
12465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesdo {                                \
12475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines  ieee_float_shape_type gf_u;                   \
12485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines  gf_u.fv = (d);                     \
12495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines  (i) = gf_u.iv;                      \
12505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} while (0)
12515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
12525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/* Set a float from a 32 bit int.  */
12535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
12545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define SET_FLOAT_WORD(d,i)                 \
12555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesdo {                                \
12565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines  ieee_float_shape_type sf_u;                   \
12575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines  sf_u.iv = (i);                      \
12585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines  (d) = sf_u.fv;                     \
12595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} while (0)
12605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
12615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
12625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
12635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// Valid -125 to 125
12645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_exp2(float v) {
12655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    int32_t iv = (int)v;
12665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    int32_t x = iv + (iv >> 31); // ~floor(v)
12675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float r = (v - x);
12685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
12695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float fo;
12705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    SET_FLOAT_WORD(fo, (x + 127) << 23);
12715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
12725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r *= 0.694f; // ~ log(e) / log(2)
12735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float r2 = r*r;
12745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float adj = 1.f + r + (r2 * 0.5f) + (r2*r * 0.166666f) + (r2*r2 * 0.0416666f);
12755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return fo * adj;
12765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
12775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
12785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_exp2(float2 v) {
12795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    int2 iv = convert_int2(v);
12805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    int2 x = iv + (iv >> (int2)31);//floor(v);
12815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float2 r = (v - convert_float2(x));
12825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
12835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    x += 127;
12845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
12855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float2 fo = (float2)(x << (int2)23);
12865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
12875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r *= 0.694f; // ~ log(e) / log(2)
12885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float2 r2 = r*r;
12895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float2 adj = 1.f + r + (r2 * 0.5f) + (r2*r * 0.166666f) + (r2*r2 * 0.0416666f);
12905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return fo * adj;
12915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
12925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
12935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_exp2(float4 v) {
12945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    int4 iv = convert_int4(v);
12955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    int4 x = iv + (iv >> (int4)31);//floor(v);
12965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float4 r = (v - convert_float4(x));
12975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
12985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    x += 127;
12995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
13005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float4 fo = (float4)(x << (int4)23);
13015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
13025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r *= 0.694f; // ~ log(e) / log(2)
13035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float4 r2 = r*r;
13045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float4 adj = 1.f + r + (r2 * 0.5f) + (r2*r * 0.166666f) + (r2*r2 * 0.0416666f);
13055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return fo * adj;
13065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
13085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_exp2(float3 v) {
13095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float4 t = 1.f;
13105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    t.xyz = v;
13115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return native_exp2(t).xyz;
13125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
13145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
13155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_exp(float v) {
13165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return native_exp2(v * 1.442695041f);
13175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_exp(float2 v) {
13195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return native_exp2(v * 1.442695041f);
13205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_exp(float3 v) {
13225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return native_exp2(v * 1.442695041f);
13235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_exp(float4 v) {
13255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return native_exp2(v * 1.442695041f);
13265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
13285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_exp10(float v) {
13295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return native_exp2(v * 3.321928095f);
13305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_exp10(float2 v) {
13325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return native_exp2(v * 3.321928095f);
13335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_exp10(float3 v) {
13355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return native_exp2(v * 3.321928095f);
13365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_exp10(float4 v) {
13385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return native_exp2(v * 3.321928095f);
13395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
13415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_log2(float v) {
13425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    int32_t ibits;
13435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    GET_FLOAT_WORD(ibits, v);
13445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
13455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    int32_t e = (ibits >> 23) & 0xff;
13465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
13475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    ibits &= 0x7fffff;
13485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    ibits |= 127 << 23;
13495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
13505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float ir;
13515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    SET_FLOAT_WORD(ir, ibits);
13525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    ir -= 1.5f;
13535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float ir2 = ir*ir;
1354c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams    float adj2 = (0.405465108f / 0.693147181f) +
1355c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams                 ((0.666666667f / 0.693147181f) * ir) -
1356c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams                 ((0.222222222f / 0.693147181f) * ir2) +
1357c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams                 ((0.098765432f / 0.693147181f) * ir*ir2) -
1358c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams                 ((0.049382716f / 0.693147181f) * ir2*ir2) +
1359c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams                 ((0.026337449f / 0.693147181f) * ir*ir2*ir2) -
1360c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams                 ((0.014631916f / 0.693147181f) * ir2*ir2*ir2);
13615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return (float)(e - 127) + adj2;
13625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_log2(float2 v) {
13645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float2 v2 = {native_log2(v.x), native_log2(v.y)};
13655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return v2;
13665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_log2(float3 v) {
13685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float3 v2 = {native_log2(v.x), native_log2(v.y), native_log2(v.z)};
13695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return v2;
13705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_log2(float4 v) {
13725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float4 v2 = {native_log2(v.x), native_log2(v.y), native_log2(v.z), native_log2(v.w)};
13735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return v2;
13745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
13765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_log(float v) {
13775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return native_log2(v) * (1.f / 1.442695041f);
13785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_log(float2 v) {
13805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return native_log2(v) * (1.f / 1.442695041f);
13815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_log(float3 v) {
13835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return native_log2(v) * (1.f / 1.442695041f);
13845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_log(float4 v) {
13865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return native_log2(v) * (1.f / 1.442695041f);
13875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
13895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_log10(float v) {
13905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return native_log2(v) * (1.f / 3.321928095f);
13915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_log10(float2 v) {
13935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return native_log2(v) * (1.f / 3.321928095f);
13945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_log10(float3 v) {
13965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return native_log2(v) * (1.f / 3.321928095f);
13975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
13985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_log10(float4 v) {
13995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return native_log2(v) * (1.f / 3.321928095f);
14005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
14015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
14025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
14035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float __attribute__((overloadable)) native_powr(float v, float y) {
14045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float v2 = native_log2(v);
1405c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams    v2 = fmax(v2 * y, -125.f);
1406c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams    return native_exp2(v2);
14075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
14085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float2 __attribute__((overloadable)) native_powr(float2 v, float2 y) {
14095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float2 v2 = native_log2(v);
1410c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams    v2 = fmax(v2 * y, -125.f);
1411c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams    return native_exp2(v2);
14125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
14135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float3 __attribute__((overloadable)) native_powr(float3 v, float3 y) {
14145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float3 v2 = native_log2(v);
1415c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams    v2 = fmax(v2 * y, -125.f);
1416c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams    return native_exp2(v2);
14175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
14185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern float4 __attribute__((overloadable)) native_powr(float4 v, float4 y) {
14195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    float4 v2 = native_log2(v);
1420c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams    v2 = fmax(v2 * y, -125.f);
1421c944fc899e868612d25d5e70e3f038bbdb4a73b2Jason Sams    return native_exp2(v2);
14225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
14235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
142453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double __attribute__((overloadable)) min(double v1, double v2) {
142553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return v1 < v2 ? v1 : v2;
142653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
142753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams
142853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double2 __attribute__((overloadable)) min(double2 v1, double2 v2) {
142953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    double2 r;
143053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.x = v1.x < v2.x ? v1.x : v2.x;
143153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.y = v1.y < v2.y ? v1.y : v2.y;
143253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return r;
143353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
143453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams
143553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double3 __attribute__((overloadable)) min(double3 v1, double3 v2) {
143653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    double3 r;
143753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.x = v1.x < v2.x ? v1.x : v2.x;
143853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.y = v1.y < v2.y ? v1.y : v2.y;
143953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.z = v1.z < v2.z ? v1.z : v2.z;
144053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return r;
144153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
144253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams
144353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double4 __attribute__((overloadable)) min(double4 v1, double4 v2) {
144453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    double4 r;
144553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.x = v1.x < v2.x ? v1.x : v2.x;
144653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.y = v1.y < v2.y ? v1.y : v2.y;
144753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.z = v1.z < v2.z ? v1.z : v2.z;
144853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.w = v1.w < v2.w ? v1.w : v2.w;
144953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return r;
145053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
145153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams
1452d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long __attribute__((overloadable)) min(long v1, long v2) {
145353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return v1 < v2 ? v1 : v2;
145453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
1455d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long2 __attribute__((overloadable)) min(long2 v1, long2 v2) {
145653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    long2 r;
145753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.x = v1.x < v2.x ? v1.x : v2.x;
145853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.y = v1.y < v2.y ? v1.y : v2.y;
145953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return r;
146053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
1461d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long3 __attribute__((overloadable)) min(long3 v1, long3 v2) {
146253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    long3 r;
146353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.x = v1.x < v2.x ? v1.x : v2.x;
146453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.y = v1.y < v2.y ? v1.y : v2.y;
146553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.z = v1.z < v2.z ? v1.z : v2.z;
146653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return r;
146753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
1468d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long4 __attribute__((overloadable)) min(long4 v1, long4 v2) {
146953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    long4 r;
147053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.x = v1.x < v2.x ? v1.x : v2.x;
147153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.y = v1.y < v2.y ? v1.y : v2.y;
147253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.z = v1.z < v2.z ? v1.z : v2.z;
147353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.w = v1.w < v2.w ? v1.w : v2.w;
147453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return r;
147553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
147653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams
1477d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong __attribute__((overloadable)) min(ulong v1, ulong v2) {
147853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return v1 < v2 ? v1 : v2;
147953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
1480d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong2 __attribute__((overloadable)) min(ulong2 v1, ulong2 v2) {
148153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    ulong2 r;
148253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.x = v1.x < v2.x ? v1.x : v2.x;
148353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.y = v1.y < v2.y ? v1.y : v2.y;
148453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return r;
148553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
1486d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong3 __attribute__((overloadable)) min(ulong3 v1, ulong3 v2) {
148753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    ulong3 r;
148853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.x = v1.x < v2.x ? v1.x : v2.x;
148953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.y = v1.y < v2.y ? v1.y : v2.y;
149053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.z = v1.z < v2.z ? v1.z : v2.z;
149153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return r;
149253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
1493d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong4 __attribute__((overloadable)) min(ulong4 v1, ulong4 v2) {
149453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    ulong4 r;
149553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.x = v1.x < v2.x ? v1.x : v2.x;
149653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.y = v1.y < v2.y ? v1.y : v2.y;
149753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.z = v1.z < v2.z ? v1.z : v2.z;
149853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.w = v1.w < v2.w ? v1.w : v2.w;
149953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return r;
150053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
150153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams
150253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double __attribute__((overloadable)) max(double v1, double v2) {
150353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return v1 > v2 ? v1 : v2;
150453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
150553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams
150653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double2 __attribute__((overloadable)) max(double2 v1, double2 v2) {
150753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    double2 r;
150853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.x = v1.x > v2.x ? v1.x : v2.x;
150953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.y = v1.y > v2.y ? v1.y : v2.y;
151053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return r;
151153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
151253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams
151353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double3 __attribute__((overloadable)) max(double3 v1, double3 v2) {
151453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    double3 r;
151553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.x = v1.x > v2.x ? v1.x : v2.x;
151653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.y = v1.y > v2.y ? v1.y : v2.y;
151753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.z = v1.z > v2.z ? v1.z : v2.z;
151853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return r;
151953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
152053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams
152153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Samsextern double4 __attribute__((overloadable)) max(double4 v1, double4 v2) {
152253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    double4 r;
152353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.x = v1.x > v2.x ? v1.x : v2.x;
152453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.y = v1.y > v2.y ? v1.y : v2.y;
152553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.z = v1.z > v2.z ? v1.z : v2.z;
152653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.w = v1.w > v2.w ? v1.w : v2.w;
152753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return r;
152853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
152953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams
1530d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long __attribute__((overloadable)) max(long v1, long v2) {
153153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return v1 > v2 ? v1 : v2;
153253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
1533d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long2 __attribute__((overloadable)) max(long2 v1, long2 v2) {
153453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    long2 r;
153553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.x = v1.x > v2.x ? v1.x : v2.x;
153653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.y = v1.y > v2.y ? v1.y : v2.y;
153753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return r;
153853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
1539d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long3 __attribute__((overloadable)) max(long3 v1, long3 v2) {
154053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    long3 r;
154153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.x = v1.x > v2.x ? v1.x : v2.x;
154253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.y = v1.y > v2.y ? v1.y : v2.y;
154353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.z = v1.z > v2.z ? v1.z : v2.z;
154453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return r;
154553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
1546d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern long4 __attribute__((overloadable)) max(long4 v1, long4 v2) {
154753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    long4 r;
154853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.x = v1.x > v2.x ? v1.x : v2.x;
154953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.y = v1.y > v2.y ? v1.y : v2.y;
155053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.z = v1.z > v2.z ? v1.z : v2.z;
155153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.w = v1.w > v2.w ? v1.w : v2.w;
155253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return r;
155353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
155453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams
1555d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong __attribute__((overloadable)) max(ulong v1, ulong v2) {
155653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return v1 > v2 ? v1 : v2;
155753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
1558d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong2 __attribute__((overloadable)) max(ulong2 v1, ulong2 v2) {
155953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    ulong2 r;
156053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.x = v1.x > v2.x ? v1.x : v2.x;
156153826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.y = v1.y > v2.y ? v1.y : v2.y;
156253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return r;
156353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
1564d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong3 __attribute__((overloadable)) max(ulong3 v1, ulong3 v2) {
156553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    ulong3 r;
156653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.x = v1.x > v2.x ? v1.x : v2.x;
156753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.y = v1.y > v2.y ? v1.y : v2.y;
156853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.z = v1.z > v2.z ? v1.z : v2.z;
156953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return r;
157053826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
1571d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samsextern ulong4 __attribute__((overloadable)) max(ulong4 v1, ulong4 v2) {
157253826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    ulong4 r;
157353826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.x = v1.x > v2.x ? v1.x : v2.x;
157453826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.y = v1.y > v2.y ? v1.y : v2.y;
157553826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.z = v1.z > v2.z ? v1.z : v2.z;
157653826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    r.w = v1.w > v2.w ? v1.w : v2.w;
157753826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams    return r;
157853826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams}
157953826db2ea7f26a241be881c2b454ab3e1e5dd50Jason Sams
1580a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#define THUNK_NATIVE_F(fn) \
1581a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams    float __attribute__((overloadable)) native_##fn(float v) { return fn(v);} \
1582a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams    float2 __attribute__((overloadable)) native_##fn(float2 v) { return fn(v);} \
1583a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams    float3 __attribute__((overloadable)) native_##fn(float3 v) { return fn(v);} \
1584a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams    float4 __attribute__((overloadable)) native_##fn(float4 v) { return fn(v);}
1585a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams
1586a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#define THUNK_NATIVE_F_F(fn) \
1587a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams    float __attribute__((overloadable)) native_##fn(float v1, float v2) { return fn(v1, v2);} \
1588a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams    float2 __attribute__((overloadable)) native_##fn(float2 v1, float2 v2) { return fn(v1, v2);} \
1589a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams    float3 __attribute__((overloadable)) native_##fn(float3 v1, float3 v2) { return fn(v1, v2);} \
1590a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams    float4 __attribute__((overloadable)) native_##fn(float4 v1, float4 v2) { return fn(v1, v2);}
1591a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams
1592a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#define THUNK_NATIVE_F_FP(fn) \
1593a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams    float __attribute__((overloadable)) native_##fn(float v1, float *v2) { return fn(v1, v2);} \
1594a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams    float2 __attribute__((overloadable)) native_##fn(float2 v1, float2 *v2) { return fn(v1, v2);} \
1595a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams    float3 __attribute__((overloadable)) native_##fn(float3 v1, float3 *v2) { return fn(v1, v2);} \
1596a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams    float4 __attribute__((overloadable)) native_##fn(float4 v1, float4 *v2) { return fn(v1, v2);}
1597a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams
1598a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#define THUNK_NATIVE_F_I(fn) \
1599a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams    float __attribute__((overloadable)) native_##fn(float v1, int v2) { return fn(v1, v2);} \
1600a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams    float2 __attribute__((overloadable)) native_##fn(float2 v1, int2 v2) { return fn(v1, v2);} \
1601a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams    float3 __attribute__((overloadable)) native_##fn(float3 v1, int3 v2) { return fn(v1, v2);} \
1602a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams    float4 __attribute__((overloadable)) native_##fn(float4 v1, int4 v2) { return fn(v1, v2);}
1603a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams
1604a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(acos)
1605a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(acosh)
1606a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(acospi)
1607a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(asin)
1608a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(asinh)
1609a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(asinpi)
1610a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(atan)
1611a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F_F(atan2)
1612a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(atanh)
1613a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(atanpi)
1614a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F_F(atan2pi)
1615a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(cbrt)
1616a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(cos)
1617a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(cosh)
1618a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(cospi)
1619a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(expm1)
1620a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F_F(hypot)
1621a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(log1p)
1622a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F_I(rootn)
1623a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(rsqrt)
1624a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(sqrt)
1625a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(sin)
1626a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F_FP(sincos)
1627a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(sinh)
1628a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(sinpi)
1629a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(tan)
1630a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(tanh)
1631a140d9d93009aa5733f91bba86c9d5227279e457Jason SamsTHUNK_NATIVE_F(tanpi)
1632a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams
1633a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#undef THUNK_NATIVE_F
1634a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#undef THUNK_NATIVE_F_F
1635a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#undef THUNK_NATIVE_F_I
1636a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams#undef THUNK_NATIVE_F_FP
1637a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams
1638a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_normalize(float v) { return fast_normalize(v);}
1639a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat2 __attribute__((overloadable)) native_normalize(float2 v) { return fast_normalize(v);}
1640a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat3 __attribute__((overloadable)) native_normalize(float3 v) { return fast_normalize(v);}
1641a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat4 __attribute__((overloadable)) native_normalize(float4 v) { return fast_normalize(v);}
1642a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams
1643a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_distance(float v1, float v2) { return fast_distance(v1, v2);}
1644a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_distance(float2 v1, float2 v2) { return fast_distance(v1, v2);}
1645a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_distance(float3 v1, float3 v2) { return fast_distance(v1, v2);}
1646a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_distance(float4 v1, float4 v2) { return fast_distance(v1, v2);}
1647a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams
1648a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_length(float v) { return fast_length(v);}
1649a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_length(float2 v) { return fast_length(v);}
1650a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_length(float3 v) { return fast_length(v);}
1651a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_length(float4 v) { return fast_length(v);}
1652a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams
1653a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_divide(float v1, float v2) { return v1 / v2;}
1654a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat2 __attribute__((overloadable)) native_divide(float2 v1, float2 v2) { return v1 / v2;}
1655a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat3 __attribute__((overloadable)) native_divide(float3 v1, float3 v2) { return v1 / v2;}
1656a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat4 __attribute__((overloadable)) native_divide(float4 v1, float4 v2) { return v1 / v2;}
1657a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams
1658a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat __attribute__((overloadable)) native_recip(float v) { return 1.f / v;}
1659a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat2 __attribute__((overloadable)) native_recip(float2 v) { return ((float2)1.f) / v;}
1660a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat3 __attribute__((overloadable)) native_recip(float3 v) { return ((float3)1.f) / v;}
1661a140d9d93009aa5733f91bba86c9d5227279e457Jason Samsfloat4 __attribute__((overloadable)) native_recip(float4 v) { return ((float4)1.f) / v;}
1662a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams
1663a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams
1664a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams
1665a140d9d93009aa5733f91bba86c9d5227279e457Jason Sams
16665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
16675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN
16685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef IN_FUNC_FN
16695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_FN
16705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_F
16715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_IN
16725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_I
16735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_PFN
16745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_PIN
16755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_FN_FN
16765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef FN_FUNC_FN_FN_PIN
16775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef XN_FUNC_YN
16785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef UIN_FUNC_IN
16795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef IN_FUNC_IN
16805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef XN_FUNC_XN_XN_BODY
16815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef IN_FUNC_IN_IN_BODY
168254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
168354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarstatic const unsigned short kHalfPositiveInfinity = 0x7c00;
168454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
168554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form
168654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar *     HN output = fn(HN input)
168754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is scalar or vector half type
168854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */
168954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define HN_FUNC_HN(fn)                                                    \
169054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half h) {                    \
169154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return (half) fn((float) h);                                          \
169254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
169354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) fn(half2 v) {                  \
169454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return convert_half2(fn(convert_float2(v)));                            \
169554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
169654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) fn(half3 v) {                  \
169754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return convert_half3(fn(convert_float3(v)));                            \
169854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
169954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) fn(half4 v) {                  \
170054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return convert_half4(fn(convert_float4(v)));                            \
170154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
170254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
170354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form
170454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar *     HN output = fn(HN input1, HN input2)
170554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is scalar or vector half type
170654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */
170754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define HN_FUNC_HN_HN(fn)                                                 \
170854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half h1, half h2) {          \
170954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return (half) fn((float) h1, (float) h2);                             \
171054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
171154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) fn(half2 v1, half2 v2) {       \
171254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return convert_half2(fn(convert_float2(v1),                             \
171354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar                          convert_float2(v2)));                           \
171454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
171554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) fn(half3 v1, half3 v2) {       \
171654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return convert_half3(fn(convert_float3(v1),                             \
171754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar                          convert_float3(v2)));                           \
171854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
171954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) fn(half4 v1, half4 v2) {       \
172054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return convert_half4(fn(convert_float4(v1),                             \
172154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar                          convert_float4(v2)));                           \
172254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
172354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
172454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form
172554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar *     HN output = fn(HN input1, half input2)
172654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is scalar or vector half type
172754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */
172854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define HN_FUNC_HN_H(fn)                                                  \
172954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) fn(half2 v1, half v2) {        \
173054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return convert_half2(fn(convert_float2(v1), (float) v2));               \
173154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
173254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) fn(half3 v1, half v2) {        \
173354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return convert_half3(fn(convert_float3(v1), (float) v2));               \
173454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
173554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) fn(half4 v1, half v2) {        \
173654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return convert_half4(fn(convert_float4(v1), (float) v2));               \
173754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
173854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
173954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form
174054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar *     HN output = fn(HN input1, HN input2, HN input3)
174154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is scalar or vector half type
174254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */
174354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define HN_FUNC_HN_HN_HN(fn)                                                   \
174454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half h1, half h2, half h3) {      \
174554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return (half) fn((float) h1, (float) h2, (float) h3);                      \
174654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                              \
174754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) fn(half2 v1, half2 v2, half2 v3) {  \
174854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return convert_half2(fn(convert_float2(v1),                                  \
174954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar                          convert_float2(v2),                                  \
175054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar                          convert_float2(v3)));                                \
175154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                              \
175254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) fn(half3 v1, half3 v2, half3 v3) {  \
175354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return convert_half3(fn(convert_float3(v1),                                  \
175454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar                          convert_float3(v2),                                  \
175554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar                          convert_float3(v3)));                                \
175654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                              \
175754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) fn(half4 v1, half4 v2, half4 v3) {  \
175854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return convert_half4(fn(convert_float4(v1),                                  \
175954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar                          convert_float4(v2),                                  \
176054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar                          convert_float4(v3)));                                \
176154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
176254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
176354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form
176454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar *     HN output = fn(HN input1, IN input2)
176554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is scalar or vector half type and IN the equivalent integer type
176654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * of same vector length.
176754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */
176854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define HN_FUNC_HN_IN(fn)                                                 \
176954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half h1, int v) {            \
177054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return (half) fn((float) h1, v);                                      \
177154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
177254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) fn(half2 v1, int2 v2) {        \
177354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return convert_half2(fn(convert_float2(v1), v2));                       \
177454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
177554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) fn(half3 v1, int3 v2) {        \
177654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return convert_half3(fn(convert_float3(v1), v2));                       \
177754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
177854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) fn(half4 v1, int4 v2) {        \
177954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return convert_half4(fn(convert_float4(v1), v2));                       \
178054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
178154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
178254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form
178354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar *     half output = fn(HN input1)
178454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is a scalar or vector half type.
178554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */
178654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define H_FUNC_HN(fn)                                                     \
178754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half h) {                    \
178854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return (half) fn((float) h);                                          \
178954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
179054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half2 v) {                   \
179154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return fn(convert_float2(v));                                           \
179254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
179354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half3 v) {                   \
179454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return fn(convert_float3(v));                                           \
179554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
179654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half4 v) {                   \
179754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return fn(convert_float4(v));                                           \
179854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
179954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
180054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form
180154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar *     half output = fn(HN input1, HN input2)
180254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is a scalar or vector half type.
180354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */
180454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define H_FUNC_HN_HN(fn)                                                  \
180554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half h1, half h2) {          \
180654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return (half) fn((float) h1, (float) h2);                             \
180754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
180854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half2 v1, half2 v2) {        \
180954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return fn(convert_float2(v1), convert_float2(v2));                      \
181054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
181154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half3 v1, half3 v2) {        \
181254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return fn(convert_float3(v1), convert_float3(v2));                      \
181354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
181454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) fn(half4 v1, half4 v2) {        \
181554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return fn(convert_float4(v1), convert_float4(v2));                      \
181654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
181754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
1818b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar#define SCALARIZE_HN_FUNC_HN_PHN(fnc)                                 \
1819b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half2 __attribute__((overloadable)) fnc(half2 v1, half2 *v2) { \
1820b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    half2 ret;                                                        \
1821b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    half t[2];                                                        \
1822b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    ret.x = fnc(v1.x, &t[0]);                                         \
1823b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    ret.y = fnc(v1.y, &t[1]);                                         \
1824b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    v2->x = t[0];                                                     \
1825b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    v2->y = t[1];                                                     \
1826b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    return ret;                                                       \
1827b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar}                                                                     \
1828b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half3 __attribute__((overloadable)) fnc(half3 v1, half3 *v2) { \
1829b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    half3 ret;                                                        \
1830b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    half t[3];                                                        \
1831b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    ret.x = fnc(v1.x, &t[0]);                                         \
1832b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    ret.y = fnc(v1.y, &t[1]);                                         \
1833b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    ret.z = fnc(v1.z, &t[2]);                                         \
1834b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    v2->x = t[0];                                                     \
1835b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    v2->y = t[1];                                                     \
1836b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    v2->z = t[2];                                                     \
1837b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    return ret;                                                       \
1838b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar}                                                                     \
1839b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half4 __attribute__((overloadable)) fnc(half4 v1, half4 *v2) { \
1840b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    half4 ret;                                                        \
1841b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    half t[4];                                                        \
1842b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    ret.x = fnc(v1.x, &t[0]);                                         \
1843b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    ret.y = fnc(v1.y, &t[1]);                                         \
1844b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    ret.z = fnc(v1.z, &t[2]);                                         \
1845b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    ret.w = fnc(v1.w, &t[3]);                                         \
1846b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    v2->x = t[0];                                                     \
1847b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    v2->y = t[1];                                                     \
1848b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    v2->z = t[2];                                                     \
1849b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    v2->w = t[3];                                                     \
1850b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    return ret;                                                       \
1851b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar}
1852b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar
185354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar/* Define f16 functions of the form
185454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar *     HN output = fn(HN input1, HN input2)
185554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * where HN is a vector half type.  The functions are defined to call the
185654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar * scalar function of the same name.
185754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar */
185854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#define SCALARIZE_HN_FUNC_HN_HN(fn)                                       \
185954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) fn(half2 v1, half2 v2) {       \
186054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  half2 ret;                                                              \
186154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  ret.x = fn(v1.x, v2.x);                                                 \
186254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  ret.y = fn(v1.y, v2.y);                                                 \
186354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return ret;                                                             \
186454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
186554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) fn(half3 v1, half3 v2) {       \
186654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  half3 ret;                                                              \
186754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  ret.x = fn(v1.x, v2.x);                                                 \
186854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  ret.y = fn(v1.y, v2.y);                                                 \
186954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  ret.z = fn(v1.z, v2.z);                                                 \
187054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return ret;                                                             \
187154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
187254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) fn(half4 v1, half4 v2) {       \
187354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  half4 ret;                                                              \
187454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  ret.x = fn(v1.x, v2.x);                                                 \
187554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  ret.y = fn(v1.y, v2.y);                                                 \
187654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  ret.z = fn(v1.z, v2.z);                                                 \
187754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  ret.w = fn(v1.w, v2.w);                                                 \
187854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return ret;                                                             \
187954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}                                                                         \
188054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
188154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(acos);
188254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(acosh);
188354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(acospi);
188454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(asin);
188554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(asinh);
188654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(asinpi);
188754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(atan);
188854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(atanh);
188954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(atanpi);
189054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(atan2);
189154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(atan2pi);
189254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
189354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(cbrt);
189454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(ceil);
189554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
1896f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainarextern half __attribute__((overloadable)) copysign(half x, half y);
1897f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga NainarSCALARIZE_HN_FUNC_HN_HN(copysign);
189854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
189954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(cos);
190054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(cosh);
190154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(cospi);
190254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
190354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) cross(half3 lhs, half3 rhs) {
190454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    half3 r;
190554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.x = lhs.y * rhs.z  - lhs.z * rhs.y;
190654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.y = lhs.z * rhs.x  - lhs.x * rhs.z;
190754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.z = lhs.x * rhs.y  - lhs.y * rhs.x;
190854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return r;
190954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
191054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
191154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) cross(half4 lhs, half4 rhs) {
191254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    half4 r;
191354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.x = lhs.y * rhs.z  - lhs.z * rhs.y;
191454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.y = lhs.z * rhs.x  - lhs.x * rhs.z;
191554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.z = lhs.x * rhs.y  - lhs.y * rhs.x;
191654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.w = 0.f;
191754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return r;
191854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
191954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
192054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(degrees);
192154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarH_FUNC_HN_HN(distance);
192254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarH_FUNC_HN_HN(dot);
192354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
192454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(erf);
192554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(erfc);
192654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(exp);
192754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(exp10);
192854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(exp2);
192954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(expm1);
193054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
193154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(fabs);
193254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(fdim);
193354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(floor);
193454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN_HN(fma);
193554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(fmax);
193654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_H(fmax);
193754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(fmin);
193854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_H(fmin);
193954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(fmod);
194054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
1941b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half __attribute__((overloadable)) fract(half v, half *iptr) {
1942b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    // maxLessThanOne = 0.99951171875, the largest value < 1.0
1943b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    half maxLessThanOne;
1944b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    SET_HALF_WORD(maxLessThanOne, 0x3bff);
1945b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar
1946b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    int i = (int) floor(v);
1947b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    if (iptr) {
1948b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar        *iptr = i;
1949b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    }
1950b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    // return v - floor(v), if strictly less than one
1951b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    return fmin(v - i, maxLessThanOne);
1952b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar}
1953b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar
1954b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga NainarSCALARIZE_HN_FUNC_HN_PHN(fract);
1955b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar
1956b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half __attribute__((const, overloadable)) fract(half v) {
1957b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    half unused;
1958b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    return fract(v, &unused);
1959b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar}
1960b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar
1961b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half2 __attribute__((const, overloadable)) fract(half2 v) {
1962b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    half2 unused;
1963b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    return fract(v, &unused);
1964b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar}
1965b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar
1966b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half3 __attribute__((const, overloadable)) fract(half3 v) {
1967b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    half3 unused;
1968b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    return fract(v, &unused);
1969b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar}
1970b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar
1971b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half4 __attribute__((const, overloadable)) fract(half4 v) {
1972b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    half4 unused;
1973b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    return fract(v, &unused);
1974b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar}
1975b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar
1976b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half __attribute__((overloadable)) frexp(half x, int *eptr);
1977b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar
1978b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half2 __attribute__((overloadable)) frexp(half2 v1, int2 *eptr) {
1979b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    half2 ret;
1980b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    int e[2];
1981b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    ret.x = frexp(v1.x, &e[0]);
1982b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    ret.y = frexp(v1.y, &e[1]);
1983b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    eptr->x = e[0];
1984b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    eptr->y = e[1];
1985b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    return ret;
1986b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar}
1987b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar
1988b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half3 __attribute__((overloadable)) frexp(half3 v1, int3 *eptr) {
1989b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    half3 ret;
1990b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    int e[3];
1991b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    ret.x = frexp(v1.x, &e[0]);
1992b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    ret.y = frexp(v1.y, &e[1]);
1993b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    ret.z = frexp(v1.z, &e[2]);
1994b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    eptr->x = e[0];
1995b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    eptr->y = e[1];
1996b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    eptr->z = e[2];
1997b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    return ret;
1998b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar}
1999b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar
2000b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half4 __attribute__((overloadable)) frexp(half4 v1, int4 *eptr) {
2001b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    half4 ret;
2002b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    int e[4];
2003b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    ret.x = frexp(v1.x, &e[0]);
2004b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    ret.y = frexp(v1.y, &e[1]);
2005b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    ret.z = frexp(v1.z, &e[2]);
2006b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    ret.w = frexp(v1.w, &e[3]);
2007b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    eptr->x = e[0];
2008b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    eptr->y = e[1];
2009b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    eptr->z = e[2];
2010b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    eptr->w = e[3];
2011b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar    return ret;
2012b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainar}
201354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
201454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(hypot);
201554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
2016f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainarextern int __attribute__((overloadable)) ilogb(half x);
2017f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar
2018f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainarextern int2 __attribute__((overloadable)) ilogb(half2 v) {
2019f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar    int2 ret;
2020f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar    ret.x = ilogb(v.x);
2021f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar    ret.y = ilogb(v.y);
2022f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar    return ret;
2023f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar}
2024f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainarextern int3 __attribute__((overloadable)) ilogb(half3 v) {
2025f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar    int3 ret;
2026f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar    ret.x = ilogb(v.x);
2027f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar    ret.y = ilogb(v.y);
2028f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar    ret.z = ilogb(v.z);
2029f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar    return ret;
2030f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar}
2031f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainarextern int4 __attribute__((overloadable)) ilogb(half4 v) {
2032f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar    int4 ret;
2033f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar    ret.x = ilogb(v.x);
2034f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar    ret.y = ilogb(v.y);
2035f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar    ret.z = ilogb(v.z);
2036f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar    ret.w = ilogb(v.w);
2037f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar    return ret;
2038f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar}
203954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
204054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_IN(ldexp);
204154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) ldexp(half2 v, int exponent) {
204254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return convert_half2(ldexp(convert_float2(v), exponent));
204354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
204454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) ldexp(half3 v, int exponent) {
204554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return convert_half3(ldexp(convert_float3(v), exponent));
204654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
204754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) ldexp(half4 v, int exponent) {
204854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return convert_half4(ldexp(convert_float4(v), exponent));
204954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
205054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
205154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarH_FUNC_HN(length);
205254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(lgamma);
205354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
205454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) lgamma(half h, int *signp) {
205554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return (half) lgamma((float) h, signp);
205654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
205754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) lgamma(half2 v, int2 *signp) {
205854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return convert_half2(lgamma(convert_float2(v), signp));
205954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
206054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) lgamma(half3 v, int3 *signp) {
206154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return convert_half3(lgamma(convert_float3(v), signp));
206254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
206354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) lgamma(half4 v, int4 *signp) {
206454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return convert_half4(lgamma(convert_float4(v), signp));
206554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
206654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
206754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(log);
206854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(log10);
206954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(log1p);
207054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(log2);
207154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(logb);
207254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
207354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN_HN(mad);
207454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(max);
207554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_H(max); // TODO can this be arch-specific similar to _Z3maxDv2_ff?
207654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(min);
207754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_H(min); // TODO can this be arch-specific similar to _Z3minDv2_ff?
207854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
207954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) mix(half start, half stop, half amount) {
208054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return start + (stop - start) * amount;
208154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
208254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) mix(half2 start, half2 stop, half2 amount) {
208354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return start + (stop - start) * amount;
208454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
208554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) mix(half3 start, half3 stop, half3 amount) {
208654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return start + (stop - start) * amount;
208754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
208854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) mix(half4 start, half4 stop, half4 amount) {
208954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return start + (stop - start) * amount;
209054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
209154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) mix(half2 start, half2 stop, half amount) {
209254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return start + (stop - start) * amount;
209354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
209454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) mix(half3 start, half3 stop, half amount) {
209554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return start + (stop - start) * amount;
209654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
209754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) mix(half4 start, half4 stop, half amount) {
209854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return start + (stop - start) * amount;
209954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
210054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
2101b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga Nainarextern half __attribute__((overloadable)) modf(half x, half *iptr);
2102b32dc1237e7e158bab7d15ab18618c4916e64415Pirama Arumuga NainarSCALARIZE_HN_FUNC_HN_PHN(modf);
210354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
210454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarhalf __attribute__((overloadable)) nan_half() {
210554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  unsigned short nan_short = kHalfPositiveInfinity | 0x0200;
210654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  half nan;
210754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  SET_HALF_WORD(nan, nan_short);
210854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar  return nan;
210954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
211054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
211154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(normalize);
211254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
2113f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainarextern half __attribute__((overloadable)) nextafter(half x, half y);
2114f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga NainarSCALARIZE_HN_FUNC_HN_HN(nextafter);
2115f9760483073d9f452e4701fbf367dc518f7e6531Pirama Arumuga Nainar
211654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(pow);
211754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_IN(pown);
211854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(powr);
211954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(radians);
212054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(remainder);
212154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
212254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) remquo(half n, half d, int *quo) {
212354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return (float) remquo((float) n, (float) d, quo);
212454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
212554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) remquo(half2 n, half2 d, int2 *quo) {
212654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return convert_half2(remquo(convert_float2(d), convert_float2(n), quo));
212754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
212854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) remquo(half3 n, half3 d, int3 *quo) {
212954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return convert_half3(remquo(convert_float3(d), convert_float3(n), quo));
213054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
213154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) remquo(half4 n, half4 d, int4 *quo) {
213254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return convert_half4(remquo(convert_float4(d), convert_float4(n), quo));
213354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
213454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
213554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(rint);
213654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_IN(rootn);
213754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(round);
213854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(rsqrt);
213954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
214054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) sign(half h) {
214154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    if (h > 0) return (half) 1.f;
214254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    if (h < 0) return (half) -1.f;
214354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return h;
214454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
214554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) sign(half2 v) {
214654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    half2 ret;
214754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    ret.x = sign(v.x);
214854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    ret.y = sign(v.y);
214954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return ret;
215054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
215154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) sign(half3 v) {
215254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    half3 ret;
215354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    ret.x = sign(v.x);
215454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    ret.y = sign(v.y);
215554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    ret.z = sign(v.z);
215654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return ret;
215754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
215854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) sign(half4 v) {
215954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    half4 ret;
216054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    ret.x = sign(v.x);
216154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    ret.y = sign(v.y);
216254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    ret.z = sign(v.z);
216354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    ret.w = sign(v.w);
216454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return ret;
216554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
216654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
216754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(sin);
216854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
216954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) sincos(half v, half *cosptr) {
217054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    *cosptr = cos(v);
217154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return sin(v);
217254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
217354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar// TODO verify if LLVM eliminates the duplicate convert_float2
217454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) sincos(half2 v, half2 *cosptr) {
217554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    *cosptr = cos(v);
217654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return sin(v);
217754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
217854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) sincos(half3 v, half3 *cosptr) {
217954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    *cosptr = cos(v);
218054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return sin(v);
218154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
218254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) sincos(half4 v, half4 *cosptr) {
218354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    *cosptr = cos(v);
218454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return sin(v);
218554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
218654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
218754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(sinh);
218854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(sinpi);
218954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(sqrt);
219054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
219154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) step(half edge, half v) {
219254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return (v < edge) ? 0.f : 1.f;
219354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
219454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) step(half2 edge, half2 v) {
219554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    half2 r;
219654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.x = (v.x < edge.x) ? 0.f : 1.f;
219754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.y = (v.y < edge.y) ? 0.f : 1.f;
219854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return r;
219954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
220054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) step(half3 edge, half3 v) {
220154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    half3 r;
220254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.x = (v.x < edge.x) ? 0.f : 1.f;
220354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.y = (v.y < edge.y) ? 0.f : 1.f;
220454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.z = (v.z < edge.z) ? 0.f : 1.f;
220554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return r;
220654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
220754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) step(half4 edge, half4 v) {
220854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    half4 r;
220954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.x = (v.x < edge.x) ? 0.f : 1.f;
221054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.y = (v.y < edge.y) ? 0.f : 1.f;
221154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.z = (v.z < edge.z) ? 0.f : 1.f;
221254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.w = (v.w < edge.w) ? 0.f : 1.f;
221354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return r;
221454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
221554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) step(half2 edge, half v) {
221654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    half2 r;
221754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.x = (v < edge.x) ? 0.f : 1.f;
221854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.y = (v < edge.y) ? 0.f : 1.f;
221954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return r;
222054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
222154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) step(half3 edge, half v) {
222254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    half3 r;
222354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.x = (v < edge.x) ? 0.f : 1.f;
222454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.y = (v < edge.y) ? 0.f : 1.f;
222554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.z = (v < edge.z) ? 0.f : 1.f;
222654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return r;
222754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
222854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) step(half4 edge, half v) {
222954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    half4 r;
223054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.x = (v < edge.x) ? 0.f : 1.f;
223154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.y = (v < edge.y) ? 0.f : 1.f;
223254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.z = (v < edge.z) ? 0.f : 1.f;
223354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.w = (v < edge.w) ? 0.f : 1.f;
223454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return r;
223554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
223654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) step(half edge, half2 v) {
223754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    half2 r;
223854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.x = (v.x < edge) ? 0.f : 1.f;
223954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.y = (v.y < edge) ? 0.f : 1.f;
224054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return r;
224154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
224254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) step(half edge, half3 v) {
224354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    half3 r;
224454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.x = (v.x < edge) ? 0.f : 1.f;
224554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.y = (v.y < edge) ? 0.f : 1.f;
224654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.z = (v.z < edge) ? 0.f : 1.f;
224754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return r;
224854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
224954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) step(half edge, half4 v) {
225054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    half4 r;
225154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.x = (v.x < edge) ? 0.f : 1.f;
225254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.y = (v.y < edge) ? 0.f : 1.f;
225354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.z = (v.z < edge) ? 0.f : 1.f;
225454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    r.w = (v.w < edge) ? 0.f : 1.f;
225554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return r;
225654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
225754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
225854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(tan);
225954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(tanh);
226054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(tanpi);
226154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(tgamma);
226254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(trunc); // TODO: rethink: needs half-specific implementation?
226354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
226454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_acos);
226554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_acosh);
226654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_acospi);
226754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_asin);
226854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_asinh);
226954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_asinpi);
227054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_atan);
227154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_atanh);
227254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_atanpi);
227354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(native_atan2);
227454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(native_atan2pi);
227554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
227654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_cbrt);
227754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_cos);
227854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_cosh);
227954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_cospi);
228054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
228154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarH_FUNC_HN_HN(native_distance);
228254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(native_divide);
228354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
228454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_exp);
228554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_exp10);
228654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_exp2);
228754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_expm1);
228854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
228954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(native_hypot);
229054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarH_FUNC_HN(native_length);
229154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
229254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_log);
229354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_log10);
229454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_log1p);
229554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_log2);
229654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
229754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_normalize);
229854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
229954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_HN(native_powr); // TODO are parameter limits different for half?
230054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
230154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_recip);
230254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN_IN(native_rootn);
230354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_rsqrt);
230454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
230554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_sin);
230654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
230754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half __attribute__((overloadable)) native_sincos(half v, half *cosptr) {
230854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return sincos(v, cosptr);
230954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
231054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half2 __attribute__((overloadable)) native_sincos(half2 v, half2 *cosptr) {
231154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return sincos(v, cosptr);
231254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
231354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half3 __attribute__((overloadable)) native_sincos(half3 v, half3 *cosptr) {
231454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return sincos(v, cosptr);
231554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
231654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainarextern half4 __attribute__((overloadable)) native_sincos(half4 v, half4 *cosptr) {
231754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar    return sincos(v, cosptr);
231854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar}
231954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
232054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_sinh);
232154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_sinpi);
232254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_sqrt);
232354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
232454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_tan);
232554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_tanh);
232654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarHN_FUNC_HN(native_tanpi);
232754cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
232854cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef HN_FUNC_HN
232954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef HN_FUNC_HN_HN
233054cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef HN_FUNC_HN_H
233154cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef HN_FUNC_HN_HN_HN
233254cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef HN_FUNC_HN_IN
233354cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef H_FUNC_HN
233454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef H_FUNC_HN_HN
233554cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar#undef SCALARIZE_HN_FUNC_HN_HN
233654cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga Nainar
2337e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham// exports unavailable mathlib functions to compat lib
2338e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham
2339e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham#ifdef RS_COMPATIBILITY_LIB
2340e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham
2341e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham// !!! DANGER !!!
2342e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham// These functions are potentially missing on older Android versions.
2343e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham// Work around the issue by supplying our own variants.
2344e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham// !!! DANGER !!!
2345e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham
2346e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham// The logbl() implementation is taken from the latest bionic/, since
2347e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham// double == long double on Android.
2348e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern "C" long double logbl(long double x) { return logb(x); }
2349e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham
2350e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham// __aeabi_idiv0 is a missing function in libcompiler_rt.so, so we just
2351e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham// pick the simplest implementation based on the ARM EABI doc.
2352e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckhamextern "C" int __aeabi_idiv0(int v) { return v; }
2353e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham
2354e0f52d61fe6790093ef19c734dda2e2c9c0c0fbfVerena Beckham#endif // compatibility lib
2355