From: David Given Date: Sat, 8 Sep 2018 20:06:38 +0000 (+0200) Subject: Rework floating point conversion. Bash enough of the table into workingness X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=379c1a4a3cb5d057251782c6d31b001b9ec94be4;p=ack.git Rework floating point conversion. Bash enough of the table into workingness that the libraries build now. --- diff --git a/mach/mips/libem/fromud.s b/mach/mips/libem/c_ud_i.s similarity index 78% rename from mach/mips/libem/fromud.s rename to mach/mips/libem/c_ud_i.s index 3b2c459ca..e9c9dda19 100644 --- a/mach/mips/libem/fromud.s +++ b/mach/mips/libem/c_ud_i.s @@ -6,8 +6,8 @@ .data -.define .fromud -.fromud: +.define .c_ud_i +.c_ud_i: /* Input: f0 * Output: r2 * Only at and f31 may be used. @@ -30,8 +30,3 @@ toobig: addiu r2, r2, 0x8000 jr ra nop - -sect .rom -.fd_80000000: - !float 2.147483648e+9 sz 8 - .data4 0x41e00000, 0 diff --git a/mach/mips/libem/fromuf.s b/mach/mips/libem/c_uf_i.s similarity index 78% rename from mach/mips/libem/fromuf.s rename to mach/mips/libem/c_uf_i.s index 0b9517134..ac0642fc7 100644 --- a/mach/mips/libem/fromuf.s +++ b/mach/mips/libem/c_uf_i.s @@ -6,8 +6,8 @@ .data -.define .fromuf -.fromuf: +.define .c_uf_i +.c_uf_i: /* Input: f0 * Output: r2 * Only at and f31 may be used. @@ -31,7 +31,3 @@ toobig: jr ra nop -sect .rom -.fd_80000000: - !float 2.147483648e+9 sz 4 - .data4 0x4f000000, 0 diff --git a/mach/mips/libem/fd_80000000.s b/mach/mips/libem/fd_80000000.s new file mode 100644 index 000000000..1cc52cab0 --- /dev/null +++ b/mach/mips/libem/fd_80000000.s @@ -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 + diff --git a/mach/mips/libem/ff_80000000.s b/mach/mips/libem/ff_80000000.s new file mode 100644 index 000000000..54e274fb5 --- /dev/null +++ b/mach/mips/libem/ff_80000000.s @@ -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 + diff --git a/mach/mips/mcg/platform.c b/mach/mips/mcg/platform.c index 0b7ee65bb..cd3a3762b 100644 --- a/mach/mips/mcg/platform.c +++ b/mach/mips/mcg/platform.c @@ -269,7 +269,7 @@ struct hop* platform_move(struct basicblock* bb, struct vreg* vreg, struct hreg* break; 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; case burm_double_ATTR: @@ -320,9 +320,9 @@ struct hop* platform_swap(struct basicblock* bb, struct hreg* src, struct hreg* break; case burm_float_ATTR: - hop_add_insel(hop, "mov.f f31, %H", src); - hop_add_insel(hop, "mov.f %H, %H", src, dest); - hop_add_insel(hop, "mov.f %H, f31", dest); + hop_add_insel(hop, "mov.s f31, %H", src); + hop_add_insel(hop, "mov.s %H, %H", src, dest); + hop_add_insel(hop, "mov.s %H, f31", dest); break; case burm_double_ATTR: diff --git a/mach/mips/mcg/table b/mach/mips/mcg/table index c2b7e3eb3..76ca419f2 100644 --- a/mach/mips/mcg/table +++ b/mach/mips/mcg/table @@ -504,13 +504,26 @@ PATTERNS emit "1:" 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) emit "c.lt.d 0, %left, %right" + emit "li %out, -1" emit "bc1t 0, 1f" - emit "li %out, -1" /* delay slot */ + emit "nop" emit "c.lt.d 0, %right, %left" emit "li %out, 1" emit "movf %out, zero, 0" + emit "1:" cost 28; /* Booleans */ @@ -527,7 +540,7 @@ PATTERNS /* If 1 or 0 then 1, else 0 */ out:(int)reg = IFLE.I(in:(int)reg) - emit "slt %out, %in, 1" + emit "slti %out, %in, 1" cost 4; @@ -676,14 +689,24 @@ PATTERNS emit "cvt.d.w %out, %out" 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) emit "trunc.w.d f31, %in" emit "mfc1 %out, f31" 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) with corrupted(dret) - emit "jal .fromud" + emit "jal .c_ud_i" emit "nop" cost 30; @@ -716,7 +739,7 @@ PATTERNS cost 4; out:(float)reg = NEGF.F(left:(float)reg) - emit "neg.f %out, %left" + emit "neg.s %out, %left" cost 4; out:(float)reg = FROMSI.F(in:(int)reg) @@ -729,19 +752,34 @@ PATTERNS emit "mfc1 %out, f31" 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) - emit "jal .fromuf" + emit "jal .c_uf_i" emit "nop" cost 30; out:(float)reg = COPYI.F(in:(int)reg) emit "mtc1 %in, %out" /* mtc1 has reversed parameters */ - cost 8; + cost 4; out:(int)reg = COPYF.I(in:(float)reg) 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 : */