ref: d4ce962fe33f3eca8da0b4ab2b5a81cc5359b71f
parent: 5e4b3a7490d301a7547a021bf1cf1e2d0f25de21
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue May 16 11:39:00 EDT 2023
7l: use floating point immediates where possible
--- a/sys/src/cmd/7l/asm.c
+++ b/sys/src/cmd/7l/asm.c
@@ -589,27 +589,17 @@
write(cout, buf.dbuf, n);
}
-static Ieee chipfloats[] = {
- {0x00000000, 0x00000000}, /* 0 */
- {0x00000000, 0x3ff00000}, /* 1 */
- {0x00000000, 0x40000000}, /* 2 */
- {0x00000000, 0x40080000}, /* 3 */
- {0x00000000, 0x40100000}, /* 4 */
- {0x00000000, 0x40140000}, /* 5 */
- {0x00000000, 0x3fe00000}, /* .5 */
- {0x00000000, 0x40240000}, /* 10 */
-};
-
int
chipfloat(Ieee *e)
{
- Ieee *p;
- int n;
+ int n, Bbbbbbbbb;
- for(n = sizeof(chipfloats)/sizeof(chipfloats[0]); --n >= 0;){
- p = &chipfloats[n];
- if(p->l == e->l && p->h == e->h && 0)
- return n; /* TO DO: return imm8 encoding */
- }
- return -1;
+ if(e->l != 0 || (e->h & 0xffffU) != 0)
+ return -1;
+ n = e->h >> 16;
+ Bbbbbbbbb = (n>>6) & 0x1ff;
+ if(Bbbbbbbbb != 0x100 && Bbbbbbbbb != 0xff)
+ return -1;
+ n = (n & 0x8000) >> 8 | (n & 0x7f);
+ return n;
}
--- a/sys/src/cmd/7l/asmout.c
+++ b/sys/src/cmd/7l/asmout.c
@@ -742,12 +742,11 @@
o1 = oprrr(p->as);
if(p->from.type == D_FCONST) {
rf = chipfloat(p->from.ieee);
- if(rf < 0 || 1){
+ if(rf < 0)
diag("invalid floating-point immediate\n%P", p);
- rf = 0;
- }
- rf |= (1<<3);
- } else
+ rf = rf<<(13-5) | 1<<(12-5);
+ o1 &= ~(0x10<<10);
+ }else
rf = p->from.reg;
rt = p->to.reg;
r = p->reg;
@@ -756,7 +755,7 @@
rf = 0;
}else if(r == NREG)
r = rt;
- o1 |= (rf << 16) | (r<<5) | rt;
+ o1 |= rf<<16 | r<<5 | rt;
break;
case 56: /* floating point compare */