summaryrefslogtreecommitdiff
path: root/amd64
diff options
context:
space:
mode:
authorBor Grošelj Simić <bor.groseljsimic@telemach.net>2022-01-28 02:06:17 +0100
committerQuentin Carbonneaux <quentin@c9x.me>2022-01-28 09:24:15 +0100
commit74d022f975f22fda20c0d1fe09a3f6fc7680f64f (patch)
treea8b7e9e1e822d8eee5eb694984f7d45d8a7f43f0 /amd64
parentb0d27d8a019811d6a4e0c0cb7ec804ab27fcec80 (diff)
downloadroux-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 'amd64')
-rw-r--r--amd64/isel.c45
1 files changed, 43 insertions, 2 deletions
diff --git a/amd64/isel.c b/amd64/isel.c
index 404b714..17ab86d 100644
--- a/amd64/isel.c
+++ b/amd64/isel.c
@@ -201,8 +201,8 @@ selcmp(Ref arg[2], int k, int swap, Fn *fn)
static void
sel(Ins i, ANum *an, Fn *fn)
{
- Ref r0, r1;
- int x, k, kc, swap;
+ Ref r0, r1, tmp[7];
+ int x, j, k, kc, swap;
int64_t sz;
Ins *i0, *i1;
@@ -266,6 +266,47 @@ sel(Ins i, ANum *an, Fn *fn)
emit(Ocopy, Kw, TMP(RCX), r0, R);
fixarg(&i1->arg[0], argcls(&i, 0), i1, fn);
break;
+ case Ouwtof:
+ r0 = newtmp("utof", Kl, fn);
+ emit(Osltof, k, i.to, r0, R);
+ emit(Oextuw, Kl, r0, i.arg[0], R);
+ fixarg(&curi->arg[0], k, curi, fn);
+ break;
+ case Oultof:
+ /*
+ %mask =l and %arg.0, 1
+ %isbig =l shr %arg.0, 63
+ %divided =l shr %arg.0, %isbig
+ %or =l or %mask, %divided
+ %float =d sltof %or
+ %cast =l cast %float
+ %addend =l shl %isbig, 52
+ %sum =l add %cast, %addend
+ %result =d cast %sum
+ */
+ r0 = newtmp("utof", k, fn);
+ if (k == Ks)
+ kc = Kw;
+ else
+ kc = Kl;
+ for (j=0; j<4; j++)
+ tmp[j] = newtmp("utof", Kl, fn);
+ for (; j<7; j++)
+ tmp[j] = newtmp("utof", kc, fn);
+ emit(Ocast, k, i.to, tmp[6], R);
+ emit(Oadd, kc, tmp[6], tmp[4], tmp[5]);
+ emit(Oshl, kc, tmp[5], tmp[1], getcon(k == Ks ? 23 : 52, fn));
+ emit(Ocast, kc, tmp[4], r0, R);
+
+ emit(Osltof, k, r0, tmp[3], R);
+ emit(Oor, Kl, tmp[3], tmp[0], tmp[2]);
+ emit(Oshr, Kl, tmp[2], i.arg[0], tmp[1]);
+ sel(*curi++, an, fn);
+ emit(Oshr, Kl, tmp[1], i.arg[0], getcon(63, fn));
+ fixarg(&curi->arg[0], Kl, curi, fn);
+ emit(Oand, Kl, tmp[0], i.arg[0], getcon(1, fn));
+ fixarg(&curi->arg[0], Kl, curi, fn);
+ break;
case Onop:
break;
case Ostored: