Add half-precision float support

This commit is contained in:
Max G 2017-03-02 02:47:11 -05:00
parent fea2d6bdd0
commit ca19075ce7
5 changed files with 485 additions and 17 deletions

View File

@ -270,6 +270,7 @@ J_E_OFILES=\
jets/e/rd.o \
jets/e/rq.o \
jets/e/rs.o \
jets/e/rh.o \
jets/e/rub.o \
jets/e/scr.o \
jets/e/shax.o \

View File

@ -174,6 +174,18 @@
u3_noun u3qeq_gte(u3_atom, u3_atom);
u3_noun u3qeq_gth(u3_atom, u3_atom);
u3_noun u3qes_add(u3_atom, u3_atom, u3_atom);
u3_noun u3qes_sub(u3_atom, u3_atom, u3_atom);
u3_noun u3qes_mul(u3_atom, u3_atom, u3_atom);
u3_noun u3qes_div(u3_atom, u3_atom, u3_atom);
u3_noun u3qes_sqt(u3_atom, u3_atom);
u3_noun u3qes_fma(u3_atom, u3_atom, u3_atom, u3_atom);
u3_noun u3qes_lth(u3_atom, u3_atom);
u3_noun u3qes_lte(u3_atom, u3_atom);
u3_noun u3qes_equ(u3_atom, u3_atom);
u3_noun u3qes_gte(u3_atom, u3_atom);
u3_noun u3qes_gth(u3_atom, u3_atom);
/** Tier 6.
**/
u3_noun u3qf_bull(u3_noun, u3_noun);

View File

@ -204,6 +204,18 @@
u3_noun u3weq_gte(u3_noun);
u3_noun u3weq_gth(u3_noun);
u3_noun u3wes_add(u3_noun);
u3_noun u3wes_sub(u3_noun);
u3_noun u3wes_mul(u3_noun);
u3_noun u3wes_div(u3_noun);
u3_noun u3wes_sqt(u3_noun);
u3_noun u3wes_fma(u3_noun);
u3_noun u3wes_lth(u3_noun);
u3_noun u3wes_lte(u3_noun);
u3_noun u3wes_equ(u3_noun);
u3_noun u3wes_gte(u3_noun);
u3_noun u3wes_gth(u3_noun);
/** Tier 6.
**/
u3_noun u3wf_bull(u3_noun);

390
jets/e/rh.c Normal file
View File

@ -0,0 +1,390 @@
/* j/e/rh.c
**
*/
#include "all.h"
#include "softfloat.h"
#define HALFNAN 0x7e00
union half {
float16_t h;
c3_s c;
};
/* functions
*/
static inline c3_t
_nan_test(float16_t a)
{
return !f16_eq(a, a);
}
static inline float16_t
_nan_unify(float16_t a)
{
if ( _nan_test(a) )
{
*(c3_s*)(&a) = HALFNAN;
}
return a;
}
static inline void
_set_rounding(c3_w a)
{
switch ( a )
{
default:
u3m_bail(c3__fail);
break;
case c3__n:
softfloat_roundingMode = softfloat_round_near_even;
break;
case c3__z:
softfloat_roundingMode = softfloat_round_minMag;
break;
case c3__u:
softfloat_roundingMode = softfloat_round_max;
break;
case c3__d:
softfloat_roundingMode = softfloat_round_min;
break;
}
}
/* add
*/
u3_noun
u3qes_add(u3_atom a,
u3_atom b,
u3_atom r)
{
union half c, d, e;
_set_rounding(r);
c.c = u3r_word(0, a);
d.c = u3r_word(0, b);
e.h = _nan_unify(f16_add(c.h, d.h));
return e.c;
}
u3_noun
u3wes_add(u3_noun cor)
{
u3_noun a, b;
if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) )
{
return u3m_bail(c3__exit);
}
else {
return u3qes_add(a, b, u3x_at(30, cor));
}
}
/* sub
*/
u3_noun
u3qes_sub(u3_atom a,
u3_atom b,
u3_atom r)
{
union half c, d, e;
_set_rounding(r);
c.c = u3r_word(0, a);
d.c = u3r_word(0, b);
e.h = _nan_unify(f16_sub(c.h, d.h));
return e.c;
}
u3_noun
u3wes_sub(u3_noun cor)
{
u3_noun a, b;
if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) )
{
return u3m_bail(c3__exit);
}
else {
return u3qes_sub(a, b, u3x_at(30, cor));
}
}
/* mul
*/
u3_noun
u3qes_mul(u3_atom a,
u3_atom b,
u3_atom r)
{
union half c, d, e;
_set_rounding(r);
c.c = u3r_word(0, a);
d.c = u3r_word(0, b);
e.h = _nan_unify(f16_mul(c.h, d.h));
return e.c;
}
u3_noun
u3wes_mul(u3_noun cor)
{
u3_noun a, b;
if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) )
{
return u3m_bail(c3__exit);
}
else {
return u3qes_mul(a, b, u3x_at(30, cor));
}
}
/* div
*/
u3_noun
u3qes_div(u3_atom a,
u3_atom b,
u3_atom r)
{
union half c, d, e;
_set_rounding(r);
c.c = u3r_word(0, a);
d.c = u3r_word(0, b);
e.h = _nan_unify(f16_div(c.h, d.h));
return e.c;
}
u3_noun
u3wes_div(u3_noun cor)
{
u3_noun a, b;
if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) )
{
return u3m_bail(c3__exit);
}
else {
return u3qes_div(a, b, u3x_at(30, cor));
}
}
/* sqt
*/
u3_noun
u3qes_sqt(u3_atom a,
u3_atom r)
{
union half c, d;
_set_rounding(r);
c.c = u3r_word(0, a);
d.h = _nan_unify(f16_sqrt(c.h));
return d.c;
}
u3_noun
u3wes_sqt(u3_noun cor)
{
u3_noun a;
if ( c3n == (a = u3r_at(u3x_sam, cor)) ||
c3n == u3ud(a) )
{
return u3m_bail(c3__exit);
}
else {
return u3qes_sqt(a, u3x_at(30, cor));
}
}
/* fma
*/
u3_noun
u3qes_fma(u3_atom a,
u3_atom b,
u3_atom c,
u3_atom r)
{
union half d, e, f, g;
_set_rounding(r);
d.c = u3r_word(0, a);
e.c = u3r_word(0, b);
f.c = u3r_word(0, c);
g.h = _nan_unify(f16_mulAdd(d.h, e.h, f.h));
return g.c;
}
u3_noun
u3wes_fma(u3_noun cor)
{
u3_noun a, b, c;
if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &b, u3x_sam_7, &c, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) ||
c3n == u3ud(c) )
{
return u3m_bail(c3__exit);
}
else {
return u3qes_fma(a, b, c, u3x_at(30, cor));
}
}
/* lth
*/
u3_noun
u3qes_lth(u3_atom a,
u3_atom b)
{
union half c, d;
c.c = u3r_word(0, a);
d.c = u3r_word(0, b);
return __(f16_lt(c.h, d.h));
}
u3_noun
u3wes_lth(u3_noun cor)
{
u3_noun a, b;
if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) )
{
return u3m_bail(c3__exit);
}
else {
return u3qes_lth(a, b);
}
}
/* lte
*/
u3_noun
u3qes_lte(u3_atom a,
u3_atom b)
{
union half c, d;
c.c = u3r_word(0, a);
d.c = u3r_word(0, b);
return __(f16_le(c.h, d.h));
}
u3_noun
u3wes_lte(u3_noun cor)
{
u3_noun a, b;
if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) )
{
return u3m_bail(c3__exit);
}
else {
return u3qes_lte(a, b);
}
}
/* equ
*/
u3_noun
u3qes_equ(u3_atom a,
u3_atom b)
{
union half c, d;
c.c = u3r_word(0, a);
d.c = u3r_word(0, b);
return __(f16_eq(c.h, d.h));
}
u3_noun
u3wes_equ(u3_noun cor)
{
u3_noun a, b;
if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) )
{
return u3m_bail(c3__exit);
}
else {
return u3qes_equ(a, b);
}
}
/* gte
*/
u3_noun
u3qes_gte(u3_atom a,
u3_atom b)
{
union half c, d;
c.c = u3r_word(0, a);
d.c = u3r_word(0, b);
return __(f16_le(d.h, c.h));
}
u3_noun
u3wes_gte(u3_noun cor)
{
u3_noun a, b;
if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) )
{
return u3m_bail(c3__exit);
}
else {
return u3qes_gte(a, b);
}
}
/* gth
*/
u3_noun
u3qes_gth(u3_atom a,
u3_atom b)
{
union half c, d;
c.c = u3r_word(0, a);
d.c = u3r_word(0, b);
return __(f16_lt(d.h, c.h));
}
u3_noun
u3wes_gth(u3_noun cor)
{
u3_noun a, b;
if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) )
{
return u3m_bail(c3__exit);
}
else {
return u3qes_gth(a, b);
}
}

View File

@ -247,6 +247,14 @@ static u3j_core _149_qua_d[] =
/* layer three
*/
static u3j_harm _149_tri__cofl__drg_a[] = {{".2", u3wef_drg}, {}};
static u3j_harm _149_tri__cofl__lug_a[] = {{".2", u3wef_lug}, {}};
static u3j_core _149_tri__cofl_d[] =
{ { "drg", _149_tri__cofl__drg_a },
{ "lug", _149_tri__cofl__lug_a },
{}
};
static u3j_harm _149_tri__rd_add_a[] = {{".2", u3wer_add}, {}};
static u3j_harm _149_tri__rd_sub_a[] = {{".2", u3wer_sub}, {}};
static u3j_harm _149_tri__rd_mul_a[] = {{".2", u3wer_mul}, {}};
@ -272,15 +280,6 @@ static u3j_core _149_qua_d[] =
{ "gth", _149_tri__rd_gth_a },
{}
};
static u3j_harm _149_tri__cofl__drg_a[] = {{".2", u3wef_drg}, {}};
static u3j_harm _149_tri__cofl__lug_a[] = {{".2", u3wef_lug}, {}};
static u3j_core _149_tri__cofl_d[] =
{ { "drg", _149_tri__cofl__drg_a },
{ "lug", _149_tri__cofl__lug_a },
{}
};
static u3j_harm _149_tri__rs_add_a[] = {{".2", u3wet_add}, {}};
static u3j_harm _149_tri__rs_sub_a[] = {{".2", u3wet_sub}, {}};
static u3j_harm _149_tri__rs_mul_a[] = {{".2", u3wet_mul}, {}};
@ -333,6 +332,32 @@ static u3j_core _149_qua_d[] =
{}
};
static u3j_harm _149_tri__rh_add_a[] = {{".2", u3wes_add}, {}};
static u3j_harm _149_tri__rh_sub_a[] = {{".2", u3wes_sub}, {}};
static u3j_harm _149_tri__rh_mul_a[] = {{".2", u3wes_mul}, {}};
static u3j_harm _149_tri__rh_div_a[] = {{".2", u3wes_div}, {}};
static u3j_harm _149_tri__rh_sqt_a[] = {{".2", u3wes_sqt}, {}};
static u3j_harm _149_tri__rh_fma_a[] = {{".2", u3wes_fma}, {}};
static u3j_harm _149_tri__rh_lth_a[] = {{".2", u3wes_lth}, {}};
static u3j_harm _149_tri__rh_lte_a[] = {{".2", u3wes_lte}, {}};
static u3j_harm _149_tri__rh_equ_a[] = {{".2", u3wes_equ}, {}};
static u3j_harm _149_tri__rh_gte_a[] = {{".2", u3wes_gte}, {}};
static u3j_harm _149_tri__rh_gth_a[] = {{".2", u3wes_gth}, {}};
static u3j_core _149_tri__rh_d[] =
{ { "add", _149_tri__rh_add_a },
{ "sub", _149_tri__rh_sub_a },
{ "mul", _149_tri__rh_mul_a },
{ "div", _149_tri__rh_div_a },
{ "sqt", _149_tri__rh_sqt_a },
{ "fma", _149_tri__rh_fma_a },
{ "lth", _149_tri__rh_lth_a },
{ "lte", _149_tri__rh_lte_a },
{ "equ", _149_tri__rh_equ_a },
{ "gte", _149_tri__rh_gte_a },
{ "gth", _149_tri__rh_gth_a },
{}
};
static u3j_harm _149_tri__aesc_en_a[] = {{".2", u3wea_en}, {}};
static u3j_harm _149_tri__aesc_de_a[] = {{".2", u3wea_de}, {}};
static u3j_core _149_tri__aesc_d[] =
@ -359,6 +384,7 @@ static u3j_core _149_tri_d[] =
{ "rd", 0, _149_tri__rd_d },
{ "rs", 0, _149_tri__rs_d },
{ "rq", 0, _149_tri__rq_d },
{ "rh", 0, _149_tri__rh_d },
{ "og", 0, _149_tri__og_d },
{ "shax", _149_tri_shax_a },
{ "shay", _149_tri_shay_a },
@ -813,6 +839,14 @@ static u3j_core _150_qua_d[] =
/* layer three
*/
static u3j_harm _150_tri__cofl__drg_a[] = {{".2", u3wef_drg}, {}};
static u3j_harm _150_tri__cofl__lug_a[] = {{".2", u3wef_lug}, {}};
static u3j_core _150_tri__cofl_d[] =
{ { "drg", _150_tri__cofl__drg_a },
{ "lug", _150_tri__cofl__lug_a },
{}
};
static u3j_harm _150_tri__rd_add_a[] = {{".2", u3wer_add}, {}};
static u3j_harm _150_tri__rd_sub_a[] = {{".2", u3wer_sub}, {}};
static u3j_harm _150_tri__rd_mul_a[] = {{".2", u3wer_mul}, {}};
@ -839,14 +873,6 @@ static u3j_core _150_qua_d[] =
{}
};
static u3j_harm _150_tri__cofl__drg_a[] = {{".2", u3wef_drg}, {}};
static u3j_harm _150_tri__cofl__lug_a[] = {{".2", u3wef_lug}, {}};
static u3j_core _150_tri__cofl_d[] =
{ { "drg", _150_tri__cofl__drg_a },
{ "lug", _150_tri__cofl__lug_a },
{}
};
static u3j_harm _150_tri__rs_add_a[] = {{".2", u3wet_add}, {}};
static u3j_harm _150_tri__rs_sub_a[] = {{".2", u3wet_sub}, {}};
static u3j_harm _150_tri__rs_mul_a[] = {{".2", u3wet_mul}, {}};
@ -899,6 +925,32 @@ static u3j_core _150_qua_d[] =
{}
};
static u3j_harm _150_tri__rh_add_a[] = {{".2", u3wes_add}, {}};
static u3j_harm _150_tri__rh_sub_a[] = {{".2", u3wes_sub}, {}};
static u3j_harm _150_tri__rh_mul_a[] = {{".2", u3wes_mul}, {}};
static u3j_harm _150_tri__rh_div_a[] = {{".2", u3wes_div}, {}};
static u3j_harm _150_tri__rh_sqt_a[] = {{".2", u3wes_sqt}, {}};
static u3j_harm _150_tri__rh_fma_a[] = {{".2", u3wes_fma}, {}};
static u3j_harm _150_tri__rh_lth_a[] = {{".2", u3wes_lth}, {}};
static u3j_harm _150_tri__rh_lte_a[] = {{".2", u3wes_lte}, {}};
static u3j_harm _150_tri__rh_equ_a[] = {{".2", u3wes_equ}, {}};
static u3j_harm _150_tri__rh_gte_a[] = {{".2", u3wes_gte}, {}};
static u3j_harm _150_tri__rh_gth_a[] = {{".2", u3wes_gth}, {}};
static u3j_core _150_tri__rh_d[] =
{ { "add", _150_tri__rh_add_a },
{ "sub", _150_tri__rh_sub_a },
{ "mul", _150_tri__rh_mul_a },
{ "div", _150_tri__rh_div_a },
{ "sqt", _150_tri__rh_sqt_a },
{ "fma", _150_tri__rh_fma_a },
{ "lth", _150_tri__rh_lth_a },
{ "lte", _150_tri__rh_lte_a },
{ "equ", _150_tri__rh_equ_a },
{ "gte", _150_tri__rh_gte_a },
{ "gth", _150_tri__rh_gth_a },
{}
};
static u3j_harm _150_tri__aesc_en_a[] = {{".2", u3wea_en}, {}};
static u3j_harm _150_tri__aesc_de_a[] = {{".2", u3wea_de}, {}};
static u3j_core _150_tri__aesc_d[] =
@ -925,6 +977,7 @@ static u3j_core _150_tri_d[] =
{ "rd", 0, _150_tri__rd_d },
{ "rs", 0, _150_tri__rs_d },
{ "rq", 0, _150_tri__rq_d },
{ "rh", 0, _150_tri__rh_d },
{ "og", 0, _150_tri__og_d },
{ "shax", _150_tri_shax_a },
{ "shay", _150_tri_shay_a },