rounding modes for rd, rq, rs

This commit is contained in:
Max G 2015-08-04 06:00:09 +03:00
parent 1c5d0d08c4
commit eb76ec6c4f
7 changed files with 146 additions and 57 deletions

View File

@ -1110,6 +1110,7 @@
# define c3__twix c3_s4('t','w','i','x')
# define c3__txt c3_s3('t','x','t')
# define c3__type c3_s4('t','y','p','e')
# define c3__u c3_s1('u')
# define c3__ubin c3_s4('u','b','i','n')
# define c3__ubit c3_s4('u','b','i','t')
# define c3__ud c3_s2('u','d')
@ -1184,6 +1185,7 @@
# define c3__wyrd c3_s4('w','y','r','d')
# define c3__yew c3_s3('y','a','w')
# define c3__yell c3_s4('y','e','l','l')
# define c3__z c3_s1('z')
# define c3__yelp c3_s4('y','e','l','p')
# define c3__zact c3_s4('z','a','c','t')
# define c3__zalt c3_s4('z','a','l','t')

View File

@ -116,36 +116,36 @@
u3_noun u3qef_drg(u3_noun, u3_atom);
u3_noun u3qef_lug(u3_noun, u3_noun, u3_atom, u3_atom);
u3_noun u3qer_add(u3_atom, u3_atom);
u3_noun u3qer_sub(u3_atom, u3_atom);
u3_noun u3qer_mul(u3_atom, u3_atom);
u3_noun u3qer_div(u3_atom, u3_atom);
u3_noun u3qer_sqt(u3_atom);
u3_noun u3qer_fma(u3_atom, u3_atom, u3_atom);
u3_noun u3qer_add(u3_atom, u3_atom, u3_atom);
u3_noun u3qer_sub(u3_atom, u3_atom, u3_atom);
u3_noun u3qer_mul(u3_atom, u3_atom, u3_atom);
u3_noun u3qer_div(u3_atom, u3_atom, u3_atom);
u3_noun u3qer_sqt(u3_atom, u3_atom);
u3_noun u3qer_fma(u3_atom, u3_atom, u3_atom, u3_atom);
u3_noun u3qer_lth(u3_atom, u3_atom);
u3_noun u3qer_lte(u3_atom, u3_atom);
u3_noun u3qer_equ(u3_atom, u3_atom);
u3_noun u3qer_gte(u3_atom, u3_atom);
u3_noun u3qer_gth(u3_atom, u3_atom);
u3_noun u3qet_add(u3_atom, u3_atom);
u3_noun u3qet_sub(u3_atom, u3_atom);
u3_noun u3qet_mul(u3_atom, u3_atom);
u3_noun u3qet_div(u3_atom, u3_atom);
u3_noun u3qet_sqt(u3_atom);
u3_noun u3qet_fma(u3_atom, u3_atom, u3_atom);
u3_noun u3qet_add(u3_atom, u3_atom, u3_atom);
u3_noun u3qet_sub(u3_atom, u3_atom, u3_atom);
u3_noun u3qet_mul(u3_atom, u3_atom, u3_atom);
u3_noun u3qet_div(u3_atom, u3_atom, u3_atom);
u3_noun u3qet_sqt(u3_atom, u3_atom);
u3_noun u3qet_fma(u3_atom, u3_atom, u3_atom, u3_atom);
u3_noun u3qet_lth(u3_atom, u3_atom);
u3_noun u3qet_lte(u3_atom, u3_atom);
u3_noun u3qet_equ(u3_atom, u3_atom);
u3_noun u3qet_gte(u3_atom, u3_atom);
u3_noun u3qet_gth(u3_atom, u3_atom);
u3_noun u3qeq_add(u3_atom, u3_atom);
u3_noun u3qeq_sub(u3_atom, u3_atom);
u3_noun u3qeq_mul(u3_atom, u3_atom);
u3_noun u3qeq_div(u3_atom, u3_atom);
u3_noun u3qeq_sqt(u3_atom);
u3_noun u3qeq_fma(u3_atom, u3_atom, u3_atom);
u3_noun u3qeq_add(u3_atom, u3_atom, u3_atom);
u3_noun u3qeq_sub(u3_atom, u3_atom, u3_atom);
u3_noun u3qeq_mul(u3_atom, u3_atom, u3_atom);
u3_noun u3qeq_div(u3_atom, u3_atom, u3_atom);
u3_noun u3qeq_sqt(u3_atom, u3_atom);
u3_noun u3qeq_fma(u3_atom, u3_atom, u3_atom, u3_atom);
u3_noun u3qeq_lth(u3_atom, u3_atom);
u3_noun u3qeq_lte(u3_atom, u3_atom);
u3_noun u3qeq_equ(u3_atom, u3_atom);

View File

@ -211,7 +211,7 @@
break;
}
goto end;
}
}
_xpd(&c, &d);
switch ( i ) {
c3_ws x;
@ -267,7 +267,7 @@
}
break;
}
if ( mpz_sizeinbase(c.a, 2) != d.precision ) {
if ( mpz_sizeinbase(c.a, 2) == (d.precision + 1) ) {
mpz_tdiv_q_2exp(c.a, c.a, 1);
mpz_add_ui(c.e, c.e, 1);
}

View File

@ -29,12 +29,36 @@
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
u3qer_add(u3_atom a, u3_atom b)
u3qer_add(u3_atom a, u3_atom b, u3_atom r)
{
union doub c, d, e;
_set_rounding(r);
c.c = u3r_chub(0, a);
d.c = u3r_chub(0, b);
e.d = _nan_unify(f64_add(c.d, d.d));
@ -54,16 +78,17 @@
return u3m_bail(c3__exit);
}
else {
return u3qer_add(a, b);
return u3qer_add(a, b, u3x_at(30, cor));
}
}
/* sub
*/
u3_noun
u3qer_sub(u3_atom a, u3_atom b)
u3qer_sub(u3_atom a, u3_atom b, u3_atom r)
{
union doub c, d, e;
_set_rounding(r);
c.c = u3r_chub(0, a);
d.c = u3r_chub(0, b);
e.d = _nan_unify(f64_sub(c.d, d.d));
@ -83,16 +108,17 @@
return u3m_bail(c3__exit);
}
else {
return u3qer_sub(a, b);
return u3qer_sub(a, b, u3x_at(30, cor));
}
}
/* mul
*/
u3_noun
u3qer_mul(u3_atom a, u3_atom b)
u3qer_mul(u3_atom a, u3_atom b, u3_atom r)
{
union doub c, d, e;
_set_rounding(r);
c.c = u3r_chub(0, a);
d.c = u3r_chub(0, b);
e.d = _nan_unify(f64_mul(c.d, d.d));
@ -112,16 +138,17 @@
return u3m_bail(c3__exit);
}
else {
return u3qer_mul(a, b);
return u3qer_mul(a, b, u3x_at(30, cor));
}
}
/* div
*/
u3_noun
u3qer_div(u3_atom a, u3_atom b)
u3qer_div(u3_atom a, u3_atom b, u3_atom r)
{
union doub c, d, e;
_set_rounding(r);
c.c = u3r_chub(0, a);
d.c = u3r_chub(0, b);
e.d = _nan_unify(f64_div(c.d, d.d));
@ -141,16 +168,17 @@
return u3m_bail(c3__exit);
}
else {
return u3qer_div(a, b);
return u3qer_div(a, b, u3x_at(30, cor));
}
}
/* sqt
*/
u3_noun
u3qer_sqt(u3_atom a)
u3qer_sqt(u3_atom a, u3_atom r)
{
union doub c, d;
_set_rounding(r);
c.c = u3r_chub(0, a);
d.d = _nan_unify(f64_sqrt(c.d));
@ -168,16 +196,17 @@
return u3m_bail(c3__exit);
}
else {
return u3qer_sqt(a);
return u3qer_sqt(a, u3x_at(30, cor));
}
}
/* fma
*/
u3_noun
u3qer_fma(u3_atom a, u3_atom b, u3_atom c)
u3qer_fma(u3_atom a, u3_atom b, u3_atom c, u3_atom r)
{
union doub d, e, f, g;
_set_rounding(r);
d.c = u3r_chub(0, a);
e.c = u3r_chub(0, b);
f.c = u3r_chub(0, c);
@ -199,7 +228,7 @@
return u3m_bail(c3__exit);
}
else {
return u3qer_fma(a, b, c);
return u3qer_fma(a, b, c, u3x_at(30, cor));
}
}

View File

@ -29,12 +29,36 @@
}
}
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
u3qeq_add(u3_atom a, u3_atom b)
u3qeq_add(u3_atom a, u3_atom b, u3_atom r)
{
union quad c, d, e;
_set_rounding(r);
c.c = alloca(16);
d.c = alloca(16);
e.c = alloca(16);
@ -60,16 +84,17 @@
return u3m_bail(c3__exit);
}
else {
return u3qeq_add(a, b);
return u3qeq_add(a, b, u3x_at(30, cor));
}
}
/* sub
*/
u3_noun
u3qeq_sub(u3_atom a, u3_atom b)
u3qeq_sub(u3_atom a, u3_atom b, u3_atom r)
{
union quad c, d, e;
_set_rounding(r);
c.c = alloca(16);
d.c = alloca(16);
e.c = alloca(16);
@ -95,16 +120,17 @@
return u3m_bail(c3__exit);
}
else {
return u3qeq_sub(a, b);
return u3qeq_sub(a, b, u3x_at(30, cor));
}
}
/* mul
*/
u3_noun
u3qeq_mul(u3_atom a, u3_atom b)
u3qeq_mul(u3_atom a, u3_atom b, u3_atom r)
{
union quad c, d, e;
_set_rounding(r);
c.c = alloca(16);
d.c = alloca(16);
e.c = alloca(16);
@ -130,16 +156,17 @@
return u3m_bail(c3__exit);
}
else {
return u3qeq_mul(a, b);
return u3qeq_mul(a, b, u3x_at(30, cor));
}
}
/* div
*/
u3_noun
u3qeq_div(u3_atom a, u3_atom b)
u3qeq_div(u3_atom a, u3_atom b, u3_atom r)
{
union quad c, d, e;
_set_rounding(r);
c.c = alloca(16);
d.c = alloca(16);
e.c = alloca(16);
@ -165,16 +192,17 @@
return u3m_bail(c3__exit);
}
else {
return u3qeq_div(a, b);
return u3qeq_div(a, b, u3x_at(30, cor));
}
}
/* sqt
*/
u3_noun
u3qeq_sqt(u3_atom a)
u3qeq_sqt(u3_atom a, u3_atom r)
{
union quad c, d;
_set_rounding(r);
c.c = alloca(16);
d.c = alloca(16);
@ -197,16 +225,17 @@
return u3m_bail(c3__exit);
}
else {
return u3qeq_sqt(a);
return u3qeq_sqt(a, u3x_at(30, cor));
}
}
/* fma
*/
u3_noun
u3qeq_fma(u3_atom a, u3_atom b, u3_atom c)
u3qeq_fma(u3_atom a, u3_atom b, u3_atom c, u3_atom r)
{
union quad d, e, f, g;
_set_rounding(r);
d.c = alloca(16);
e.c = alloca(16);
f.c = alloca(16);
@ -235,7 +264,7 @@
return u3m_bail(c3__exit);
}
else {
return u3qeq_fma(a, b, c);
return u3qeq_fma(a, b, c, u3x_at(30, cor));
}
}

View File

@ -29,12 +29,36 @@
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
u3qet_add(u3_atom a, u3_atom b)
u3qet_add(u3_atom a, u3_atom b, u3_atom r)
{
union sing c, d, e;
_set_rounding(r);
c.c = u3r_word(0, a);
d.c = u3r_word(0, b);
e.s = _nan_unify(f32_add(c.s, d.s));
@ -54,16 +78,17 @@
return u3m_bail(c3__exit);
}
else {
return u3qet_add(a, b);
return u3qet_add(a, b, u3x_at(30, cor));
}
}
/* sub
*/
u3_noun
u3qet_sub(u3_atom a, u3_atom b)
u3qet_sub(u3_atom a, u3_atom b, u3_atom r)
{
union sing c, d, e;
_set_rounding(r);
c.c = u3r_word(0, a);
d.c = u3r_word(0, b);
e.s = _nan_unify(f32_sub(c.s, d.s));
@ -83,16 +108,17 @@
return u3m_bail(c3__exit);
}
else {
return u3qet_sub(a, b);
return u3qet_sub(a, b, u3x_at(30, cor));
}
}
/* mul
*/
u3_noun
u3qet_mul(u3_atom a, u3_atom b)
u3qet_mul(u3_atom a, u3_atom b, u3_atom r)
{
union sing c, d, e;
_set_rounding(r);
c.c = u3r_word(0, a);
d.c = u3r_word(0, b);
e.s = _nan_unify(f32_mul(c.s, d.s));
@ -112,16 +138,17 @@
return u3m_bail(c3__exit);
}
else {
return u3qet_mul(a, b);
return u3qet_mul(a, b, u3x_at(30, cor));
}
}
/* div
*/
u3_noun
u3qet_div(u3_atom a, u3_atom b)
u3qet_div(u3_atom a, u3_atom b, u3_atom r)
{
union sing c, d, e;
_set_rounding(r);
c.c = u3r_word(0, a);
d.c = u3r_word(0, b);
e.s = _nan_unify(f32_div(c.s, d.s));
@ -141,16 +168,17 @@
return u3m_bail(c3__exit);
}
else {
return u3qet_div(a, b);
return u3qet_div(a, b, u3x_at(30, cor));
}
}
/* sqt
*/
u3_noun
u3qet_sqt(u3_atom a)
u3qet_sqt(u3_atom a, u3_atom r)
{
union sing c, d;
_set_rounding(r);
c.c = u3r_word(0, a);
d.s = _nan_unify(f32_sqrt(c.s));
@ -168,16 +196,17 @@
return u3m_bail(c3__exit);
}
else {
return u3qet_sqt(a);
return u3qet_sqt(a, u3x_at(30, cor));
}
}
/* fma
*/
u3_noun
u3qet_fma(u3_atom a, u3_atom b, u3_atom c)
u3qet_fma(u3_atom a, u3_atom b, u3_atom c, u3_atom r)
{
union sing 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);
@ -199,7 +228,7 @@
return u3m_bail(c3__exit);
}
else {
return u3qet_fma(a, b, c);
return u3qet_fma(a, b, c, u3x_at(30, cor));
}
}

View File

@ -207,7 +207,7 @@ static u3j_core _mood__hoon__og_d[] =
};
static u3j_harm _mood__hoon__cofl__drg_a[] = {{".2", u3wef_drg}, {}};
static u3j_harm _mood__hoon__cofl__lug_a[] = {{".2", u3wef_lug}, {}};
static u3j_harm _mood__hoon__cofl__lug_a[] = {{".2", u3wef_lug, c3n}, {}};
static u3j_core _mood__hoon__cofl_d[] =
{ { "drg", _mood__hoon__cofl__drg_a },
{ "lug", _mood__hoon__cofl__lug_a },