Skip to content

Commit d00c025

Browse files
jordancarlinAlasdair
authored andcommitted
Add quad floating point to float lib
1 parent ce27f52 commit d00c025

File tree

8 files changed

+145
-5
lines changed

8 files changed

+145
-5
lines changed

lib/float/common.sail

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ $define _FLOAT_COMMON
3232

3333
/* Floating point types definition */
3434
type fp_exception_flags = bits(5) /* Floating-point exception flags. */
35-
type fp_bits = { 'n, 'n in {16, 32, 64}. bits('n) } /* Floating-point in bits. */
36-
type fp_bits_x2 = { 'n, 'n in {16, 32, 64}. (bits('n), bits('n)) } /* Floating point x2 tuple */
35+
type fp_bits = { 'n, 'n in {16, 32, 64, 128}. bits('n) } /* Floating-point in bits. */
36+
type fp_bits_x2 = { 'n, 'n in {16, 32, 64, 128}. (bits('n), bits('n)) } /* Floating point x2 tuple */
3737
type fp_bool_and_flags = (bool, fp_exception_flags) /* Floating point bool and exception flags tuple */
3838

3939
/* Floating point constants */
@@ -47,16 +47,20 @@ struct float_bits('n : Int) = {
4747
then 5
4848
else (if 'n == 32
4949
then 8
50-
else 11)),
50+
else (if 'n == 64
51+
then 11
52+
else 15))),
5153
mantissa : bits(if 'n == 16
5254
then 10
5355
else (if 'n == 32
5456
then 23
55-
else 52)),
57+
else (if 'n == 64
58+
then 52
59+
else 112))),
5660
}
5761

5862
/* The val func implementations */
59-
val float_decompose : forall 'n, 'n in { 16, 32, 64 }. bits('n) -> float_bits('n)
63+
val float_decompose : forall 'n, 'n in { 16, 32, 64, 128 }. bits('n) -> float_bits('n)
6064
function float_decompose(op) = {
6165
match 'n {
6266
16 => struct {
@@ -73,6 +77,11 @@ function float_decompose(op) = {
7377
sign = op[63..63],
7478
exp = op[62..52],
7579
mantissa = op[51..0],
80+
},
81+
128 => struct {
82+
sign = op[127..127],
83+
exp = op[126..112],
84+
mantissa = op[111..0],
7685
}
7786
}
7887
}

test/float/eq_test.sail

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ function test_float_is_eq () -> unit = {
7575

7676
assert(float_is_eq((0x7ff7000000000000, 0x0000234db0000000)) == (false, fp_eflag_invalid));
7777
assert(float_is_eq((0x7ff0000000000001, 0xfff0000003000001)) == (false, fp_eflag_invalid));
78+
79+
/* Quad floating point */
80+
assert(float_is_eq((0x00000000000000000000000000000001, 0x00000000000000000000000000000001)) == (true, fp_eflag_none));
81+
assert(float_is_eq((0x0f00000000000000000000000000000f, 0x0f00000000000000000000000000000f)) == (true, fp_eflag_none));
82+
assert(float_is_eq((0x80000000000000000000000000000000, 0x00000000000000000000000000000000)) == (true, fp_eflag_none));
83+
assert(float_is_eq((0x7fff0000000000000000000000000000, 0x7fff0000000000000000000000000000)) == (true, fp_eflag_none));
84+
85+
assert(float_is_eq((0x00000000000000000000000000000001, 0x80000000000000000000000000000001)) == (false, fp_eflag_none));
86+
assert(float_is_eq((0x0f00000000000000000000000000000f, 0x3f00000000000000000000000000000f)) == (false, fp_eflag_none));
87+
assert(float_is_eq((0x7fff8000000000000000000000000000, 0x0000234db00000000000000000000000)) == (false, fp_eflag_none));
88+
assert(float_is_eq((0x7fff8000000000000000000000000000, 0xffff8000000000000000000000000000)) == (false, fp_eflag_none));
89+
90+
assert(float_is_eq((0x7fff7000000000000000000000000000, 0x0000234db00000000000000000000000)) == (false, fp_eflag_invalid));
91+
assert(float_is_eq((0x7fff0000000000000000000000000001, 0xfff00000030000000000000000000001)) == (false, fp_eflag_invalid));
7892
}
7993

8094
function main () -> unit = {

test/float/inf_test.sail

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ function test_float_is_inf () -> unit = {
6565
assert(float_is_inf(0xfff8000000000000) == false);
6666
assert(float_is_inf(0xfff0000000000001) == false);
6767
assert(float_is_inf(0xffc0000000000000) == false);
68+
69+
/* Quad floating point */
70+
assert(float_is_inf(0x7fff0000000000000000000000000000));
71+
assert(float_is_inf(0xffff0000000000000000000000000000));
72+
73+
assert(float_is_inf(0x7fff8000000000000000000000000000) == false);
74+
assert(float_is_inf(0x7fff0000000000000000000000000001) == false);
75+
assert(float_is_inf(0x7ffc0000000000000000000000000000) == false);
76+
assert(float_is_inf(0xffff8000000000000000000000000000) == false);
77+
assert(float_is_inf(0xffff0000000000000000000000000001) == false);
78+
assert(float_is_inf(0xfffc0000000000000000000000000000) == false);
6879
}
6980

7081
function main () -> unit = {

test/float/nan_test.sail

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,24 @@ function test_float_is_nan () -> unit = {
8686
assert(float_is_nan(0xfff0000000000000) == false);
8787
assert(float_is_nan(0xffe0000000000000) == false);
8888
assert(float_is_nan(0xffc0000000000000) == false);
89+
90+
/* Quad floating point */
91+
assert(float_is_nan(0x7fff8000000000000000000000000000));
92+
assert(float_is_nan(0x7fff0000000000000000000000000001));
93+
assert(float_is_nan(0x7fff8000000000000000000000000100));
94+
assert(float_is_nan(0x7fffc000000000001000000000000000));
95+
96+
assert(float_is_nan(0xffff8000000000000000000000000000));
97+
assert(float_is_nan(0xffff0000000000000000000000000001));
98+
assert(float_is_nan(0xffff8000000000000000000000000100));
99+
assert(float_is_nan(0xffffc000000000001000000000000000));
100+
101+
assert(float_is_nan(0x7fff0000000000000000000000000000) == false);
102+
assert(float_is_nan(0x7ffe0000000000000000000000000000) == false);
103+
assert(float_is_nan(0x7ffc0000000000000000000000000000) == false);
104+
assert(float_is_nan(0xffff0000000000000000000000000000) == false);
105+
assert(float_is_nan(0xfffe0000000000000000000000000000) == false);
106+
assert(float_is_nan(0xfffc0000000000000000000000000000) == false);
89107
}
90108

91109
function test_float_is_snan () -> unit = {
@@ -121,6 +139,18 @@ function test_float_is_snan () -> unit = {
121139
assert(float_is_snan(0x7ff8000000000000) == false);
122140
assert(float_is_snan(0xfff8000000000000) == false);
123141
assert(float_is_snan(0xfef8000000000001) == false);
142+
143+
/* Quad floating point */
144+
assert(float_is_snan(0x7fff7000000000000000000000000000));
145+
assert(float_is_snan(0x7fff7000000000000000000000000001));
146+
147+
assert(float_is_snan(0xffff7000000000000000000000000000));
148+
assert(float_is_snan(0xffff7000000000000000000000000001));
149+
150+
assert(float_is_snan(0x7fff8000000000000000000000000000) == false);
151+
assert(float_is_snan(0xffff8000000000000000000000000000) == false);
152+
assert(float_is_snan(0xfeff8000000000000000000000000001) == false);
153+
124154
}
125155

126156
function test_float_is_qnan () -> unit = {
@@ -156,6 +186,17 @@ function test_float_is_qnan () -> unit = {
156186
assert(float_is_qnan(0x7ff7000000000000) == false);
157187
assert(float_is_qnan(0xfff7000000000000) == false);
158188
assert(float_is_qnan(0xfef7000000000001) == false);
189+
190+
/* Quad floating point */
191+
assert(float_is_qnan(0x7fff8000000000000000000000000000));
192+
assert(float_is_qnan(0x7fff8000000000000000000000000001));
193+
194+
assert(float_is_qnan(0xffff8000000000000000000000000000));
195+
assert(float_is_qnan(0xffff8000000000000000000000000001));
196+
197+
assert(float_is_qnan(0x7fff7000000000000000000000000000) == false);
198+
assert(float_is_qnan(0xffff7000000000000000000000000000) == false);
199+
assert(float_is_qnan(0xfeff7000000000000000000000000001) == false);
159200
}
160201

161202
function main () -> unit = {

test/float/ne_test.sail

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ function test_float_is_ne () -> unit = {
7575

7676
assert(float_is_ne((0x7ff7000000000000, 0x0000234db0000000)) == (false, fp_eflag_invalid));
7777
assert(float_is_ne((0x7ff0000000000001, 0xfff0000003000001)) == (false, fp_eflag_invalid));
78+
79+
/* Quad floating point */
80+
assert(float_is_ne((0x80000000000000000000000000000001, 0x00000000000000000000000000000001)) == (true, fp_eflag_none));
81+
assert(float_is_ne((0x8f00000000000000000000000000000f, 0x0f00000000000000000000000000000f)) == (true, fp_eflag_none));
82+
assert(float_is_ne((0x80000000000000000000000000000000, 0x00000000000000000000000000000001)) == (true, fp_eflag_none));
83+
assert(float_is_ne((0x7fff0000000000000000000000000000, 0xffff0000000000000000000000000000)) == (true, fp_eflag_none));
84+
85+
assert(float_is_ne((0x00000000000000000000000000000011, 0x00000000000000000000000000000011)) == (false, fp_eflag_none));
86+
assert(float_is_ne((0x0ffff00000000000000000000000000f, 0x0ffff00000000000000000000000000f)) == (false, fp_eflag_none));
87+
assert(float_is_ne((0x00000000000000000000000000000000, 0x80000000000000000000000000000000)) == (false, fp_eflag_none));
88+
assert(float_is_ne((0x7fff8000000000000000000000000100, 0x7fff8000000000000000000000000100)) == (false, fp_eflag_none));
89+
90+
assert(float_is_ne((0x7fff7000000000000000000000000000, 0x0000000000000234db00000000000000)) == (false, fp_eflag_invalid));
91+
assert(float_is_ne((0x7fff0000000000000000000000000001, 0xffff0000000000000000000003000001)) == (false, fp_eflag_invalid));
7892
}
7993

8094
function main () -> unit = {

test/float/normal_test.sail

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ function test_float_is_normal () -> unit = {
6565
assert(float_is_normal(0x7ff0000000000000) == false);
6666
assert(float_is_normal(0x0008000000000000) == false);
6767
assert(float_is_normal(0x8008000000000000) == false);
68+
69+
/* Quad floating point */
70+
assert(float_is_normal(0x7ffe0000000000000000000000000000));
71+
assert(float_is_normal(0x7ffe0000000000000000000000000001));
72+
assert(float_is_normal(0xfffc000000000000000000000000000f));
73+
assert(float_is_normal(0x80030000000000000001000000000000));
74+
75+
assert(float_is_normal(0x7fff8000000000000000000000000000) == false);
76+
assert(float_is_normal(0x7fff0000000000000000000000000000) == false);
77+
assert(float_is_normal(0x00008000000000000000000000000000) == false);
78+
assert(float_is_normal(0x80008000000000000000000000000000) == false);
6879
}
6980

7081
function test_float_is_denormal () -> unit = {
@@ -100,6 +111,17 @@ function test_float_is_denormal () -> unit = {
100111
assert(float_is_denormal(0x7ff0000000000000) == false);
101112
assert(float_is_denormal(0xffc000000000000f) == false);
102113
assert(float_is_denormal(0x8030000000100000) == false);
114+
115+
/* Quad floating point */
116+
assert(float_is_denormal(0x00008000000000000000000000000000));
117+
assert(float_is_denormal(0x80008000000000000000000000000000));
118+
assert(float_is_denormal(0x80000000000000000000000000000001));
119+
assert(float_is_denormal(0x80008000000000000001000000000000));
120+
121+
assert(float_is_denormal(0x7fff8000000000000000000000000000) == false);
122+
assert(float_is_denormal(0x7fff0000000000000000000000000000) == false);
123+
assert(float_is_denormal(0xfffc000000000000000000000000000f) == false);
124+
assert(float_is_denormal(0x80030000000000000001000000000000) == false);
103125
}
104126

105127
function main () -> unit = {

test/float/sign_test.sail

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ function test_float_is_positive () -> unit = {
6262
assert(float_is_positive(0xf8f0000000023000) == false);
6363
assert(float_is_positive(0xfce0000000000000) == false);
6464
assert(float_is_positive(0xe8c0000000000000) == false);
65+
66+
/* Quad floating point */
67+
assert(float_is_positive(0x7ff080000f0f00000000000000000000));
68+
assert(float_is_positive(0x0000000000000fedc000000000000001));
69+
assert(float_is_positive(0x7fffffffffffffffffffffffffffffff));
70+
assert(float_is_positive(0x00000000003000000000010000000000));
71+
72+
assert(float_is_positive(0xf8ff0000000000000023000000000000) == false);
73+
assert(float_is_positive(0xffce0000000000000000000000000000) == false);
74+
assert(float_is_positive(0xe88c0000000000000000000000000000) == false);
6575
}
6676

6777
function test_float_is_negative () -> unit = {
@@ -94,6 +104,16 @@ function test_float_is_negative () -> unit = {
94104
assert(float_is_negative(0x78f0000000023000) == false);
95105
assert(float_is_negative(0x7ce0000000000000) == false);
96106
assert(float_is_negative(0x68c0000000000000) == false);
107+
108+
/* Quad floating point */
109+
assert(float_is_negative(0xfff0000000800000000f0f0000000000));
110+
assert(float_is_negative(0x8000000000000fedc000000000000001));
111+
assert(float_is_negative(0xffffffffffffffffffffffffffffffff));
112+
assert(float_is_negative(0x80000000003000000000010000000000));
113+
114+
assert(float_is_negative(0x78ff0000000000000000023000000000) == false);
115+
assert(float_is_negative(0x7fce0000000000000000000000000000) == false);
116+
assert(float_is_negative(0x688c0000000000000000000000000000) == false);
97117
}
98118

99119
function main () -> unit = {

test/float/zero_test.sail

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ function test_float_is_zero () -> unit = {
5959
assert(float_is_zero(0x7ff0000000000001) == false);
6060
assert(float_is_zero(0xfff8000000000000) == false);
6161
assert(float_is_zero(0xfff0000000000001) == false);
62+
63+
/* Quad floating point */
64+
assert(float_is_zero(0x80000000000000000000000000000000));
65+
assert(float_is_zero(0x00000000000000000000000000000000));
66+
67+
assert(float_is_zero(0x7fff8000000000000000000000000000) == false);
68+
assert(float_is_zero(0x7fff0000000000000000000000000001) == false);
69+
assert(float_is_zero(0xffff8000000000000000000000000000) == false);
70+
assert(float_is_zero(0xffff0000000000000000000000000001) == false);
6271
}
6372

6473
function main () -> unit = {

0 commit comments

Comments
 (0)