diff options
author | Bor Grošelj Simić <bor.groseljsimic@telemach.net> | 2022-01-28 02:06:17 +0100 |
---|---|---|
committer | Quentin Carbonneaux <quentin@c9x.me> | 2022-01-28 09:24:15 +0100 |
commit | 74d022f975f22fda20c0d1fe09a3f6fc7680f64f (patch) | |
tree | a8b7e9e1e822d8eee5eb694984f7d45d8a7f43f0 /test | |
parent | b0d27d8a019811d6a4e0c0cb7ec804ab27fcec80 (diff) | |
download | roux-74d022f975f22fda20c0d1fe09a3f6fc7680f64f.tar.gz |
implement unsigned -> float casts
amd64 lacks an instruction for this so it has to be implemented with signed -> float casts: - Word casting is done by zero-extending the word to a long and then doing a regular signed cast. - Long casting is done by dividing by two with correct rounding if the highest bit is set and casting that to float, then adding 1 to mantissa with integer addition
Diffstat (limited to 'test')
-rw-r--r-- | test/fpcnv.ssa | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/fpcnv.ssa b/test/fpcnv.ssa index d9851d8..4dac489 100644 --- a/test/fpcnv.ssa +++ b/test/fpcnv.ssa @@ -17,13 +17,62 @@ function d $ftrunc(d %f) { ret %rt } +export +function s $wtos(w %w) { +@start + %rt =s uwtof %w + ret %rt +} +export +function d $wtod(w %w) { +@start + %rt =d uwtof %w + ret %rt +} + +export +function s $ltos(l %l) { +@start + %rt =s ultof %l + ret %rt +} +export +function d $ltod(l %l) { +@start + %rt =d ultof %l + ret %rt +} + # >>> driver # extern float fneg(float); # extern double ftrunc(double); +# +# extern float wtos(unsigned int); +# extern double wtod(unsigned int); +# extern float ltos(long long unsigned int); +# extern double ltod(long long unsigned int); +# +# unsigned long long iin[] = { 0, 1, 16, 234987, 427386245, 0x7fff0000, +# 0xffff0000, 23602938196141, 72259248152500195, 9589010795705032704ull, +# 0xdcf5fbe299d0148aull, 0xffffffff00000000ull, -1 }; +# # int main() { +# int i; +# # if (fneg(1.23f) != -1.23f) return 1; # if (ftrunc(3.1415) != 3.0) return 2; # if (ftrunc(-1.234) != -1.0) return 3; +# +# for (i=0; i<sizeof(iin)/sizeof(iin[0]); i++) { +# if (wtos(iin[i]) != (float) (unsigned int)iin[i]) +# return 4; +# if (wtod(iin[i]) != (double)(unsigned int)iin[i]) +# return 5; +# if (ltos(iin[i]) != (float) iin[i]) +# return 6; +# if (ltod(iin[i]) != (double)iin[i]) +# return 7; +# } # return 0; # } # <<< |