Rework floating point conversion. Bash enough of the table into workingness

that the libraries build now.
This commit is contained in:
David Given 2018-09-08 22:06:38 +02:00
parent d2c14ca44f
commit 379c1a4a3c
6 changed files with 76 additions and 25 deletions

View file

@ -6,8 +6,8 @@
.data .data
.define .fromud .define .c_ud_i
.fromud: .c_ud_i:
/* Input: f0 /* Input: f0
* Output: r2 * Output: r2
* Only at and f31 may be used. * Only at and f31 may be used.
@ -30,8 +30,3 @@ toobig:
addiu r2, r2, 0x8000 addiu r2, r2, 0x8000
jr ra jr ra
nop nop
sect .rom
.fd_80000000:
!float 2.147483648e+9 sz 8
.data4 0x41e00000, 0

View file

@ -6,8 +6,8 @@
.data .data
.define .fromuf .define .c_uf_i
.fromuf: .c_uf_i:
/* Input: f0 /* Input: f0
* Output: r2 * Output: r2
* Only at and f31 may be used. * Only at and f31 may be used.
@ -31,7 +31,3 @@ toobig:
jr ra jr ra
nop nop
sect .rom
.fd_80000000:
!float 2.147483648e+9 sz 4
.data4 0x4f000000, 0

View file

@ -0,0 +1,11 @@
#
.sect .text; .sect .rom; .sect .data; .sect .bss
.sect .rom
/* 2147483648 as a double; used as a pivot for double->unsigned and unsigned->double. */
.define .fd_80000000
.fd_80000000:
.data4 0x41e00000, 0

View file

@ -0,0 +1,11 @@
#
.sect .text; .sect .rom; .sect .data; .sect .bss
.sect .rom
/* 2147483648 as a float; used as a pivot for double->float and unsigned->float. */
.define .ff_80000000
.ff_80000000:
.data4 0x4f000000

View file

@ -269,7 +269,7 @@ struct hop* platform_move(struct basicblock* bb, struct vreg* vreg, struct hreg*
break; break;
case burm_float_ATTR: case burm_float_ATTR:
hop_add_insel(hop, "mov.f %H, %H", dest, src); hop_add_insel(hop, "mov.s %H, %H", dest, src);
break; break;
case burm_double_ATTR: case burm_double_ATTR:
@ -320,9 +320,9 @@ struct hop* platform_swap(struct basicblock* bb, struct hreg* src, struct hreg*
break; break;
case burm_float_ATTR: case burm_float_ATTR:
hop_add_insel(hop, "mov.f f31, %H", src); hop_add_insel(hop, "mov.s f31, %H", src);
hop_add_insel(hop, "mov.f %H, %H", src, dest); hop_add_insel(hop, "mov.s %H, %H", src, dest);
hop_add_insel(hop, "mov.f %H, f31", dest); hop_add_insel(hop, "mov.s %H, f31", dest);
break; break;
case burm_double_ATTR: case burm_double_ATTR:

View file

@ -504,13 +504,26 @@ PATTERNS
emit "1:" emit "1:"
cost 20; cost 20;
out:(int)reg = COMPAREF.I(left:(float)reg, right:(float)reg)
emit "c.lt.s 0, %left, %right"
emit "li %out, -1"
emit "bc1t 0, 1f"
emit "nop"
emit "c.lt.s 0, %right, %left"
emit "li %out, 1"
emit "movf %out, zero, 0"
emit "1:"
cost 28;
out:(int)reg = COMPARED.I(left:(double)reg, right:(double)reg) out:(int)reg = COMPARED.I(left:(double)reg, right:(double)reg)
emit "c.lt.d 0, %left, %right" emit "c.lt.d 0, %left, %right"
emit "li %out, -1"
emit "bc1t 0, 1f" emit "bc1t 0, 1f"
emit "li %out, -1" /* delay slot */ emit "nop"
emit "c.lt.d 0, %right, %left" emit "c.lt.d 0, %right, %left"
emit "li %out, 1" emit "li %out, 1"
emit "movf %out, zero, 0" emit "movf %out, zero, 0"
emit "1:"
cost 28; cost 28;
/* Booleans */ /* Booleans */
@ -527,7 +540,7 @@ PATTERNS
/* If 1 or 0 then 1, else 0 */ /* If 1 or 0 then 1, else 0 */
out:(int)reg = IFLE.I(in:(int)reg) out:(int)reg = IFLE.I(in:(int)reg)
emit "slt %out, %in, 1" emit "slti %out, %in, 1"
cost 4; cost 4;
@ -676,14 +689,24 @@ PATTERNS
emit "cvt.d.w %out, %out" emit "cvt.d.w %out, %out"
cost 4; cost 4;
out:(dret)reg = FROMUI.D(in:(iret)reg)
emit "jal .c_ui_d"
emit "nop"
cost 30;
out:(int)reg = FROMSD.I(in:(double)reg) out:(int)reg = FROMSD.I(in:(double)reg)
emit "trunc.w.d f31, %in" emit "trunc.w.d f31, %in"
emit "mfc1 %out, f31" emit "mfc1 %out, f31"
cost 8; cost 8;
out:(lret)reg = FROMSD.L(in:(dret)reg)
emit "jal .c_sd_l"
emit "nop"
cost 30;
out:(iret)reg = FROMUD.I(in:(dret)reg) out:(iret)reg = FROMUD.I(in:(dret)reg)
with corrupted(dret) with corrupted(dret)
emit "jal .fromud" emit "jal .c_ud_i"
emit "nop" emit "nop"
cost 30; cost 30;
@ -716,7 +739,7 @@ PATTERNS
cost 4; cost 4;
out:(float)reg = NEGF.F(left:(float)reg) out:(float)reg = NEGF.F(left:(float)reg)
emit "neg.f %out, %left" emit "neg.s %out, %left"
cost 4; cost 4;
out:(float)reg = FROMSI.F(in:(int)reg) out:(float)reg = FROMSI.F(in:(int)reg)
@ -729,19 +752,34 @@ PATTERNS
emit "mfc1 %out, f31" emit "mfc1 %out, f31"
cost 8; cost 8;
out:(iret)reg = FROMUD.I(in:(fret)reg) out:(lret)reg = FROMSF.L(in:(fret)reg)
emit "jal .c_sf_l"
emit "nop"
cost 30;
out:(fret)reg = FROMUI.F(in:(iret)reg)
emit "jal .c_ui_f"
emit "nop"
cost 30;
out:(iret)reg = FROMUF.I(in:(fret)reg)
with corrupted(fret) with corrupted(fret)
emit "jal .fromuf" emit "jal .c_uf_i"
emit "nop" emit "nop"
cost 30; cost 30;
out:(float)reg = COPYI.F(in:(int)reg) out:(float)reg = COPYI.F(in:(int)reg)
emit "mtc1 %in, %out" /* mtc1 has reversed parameters */ emit "mtc1 %in, %out" /* mtc1 has reversed parameters */
cost 8; cost 4;
out:(int)reg = COPYF.I(in:(float)reg) out:(int)reg = COPYF.I(in:(float)reg)
emit "mfc1 %out, %in" emit "mfc1 %out, %in"
cost 8; cost 4;
out:(float)reg = value:CONST.F
when specific_constant(%value, 0)
emit "mtc1 zero, %out" /* mtc1 has reversed parameters */
cost 4;
/* vim: set sw=4 ts=4 expandtab : */ /* vim: set sw=4 ts=4 expandtab : */