From mboxrd@z Thu Jan 1 00:00:00 1970 From: erik quanstrom Date: Sun, 26 Sep 2010 22:53:10 -0400 To: 9fans@9fans.net Message-ID: <77b15d6e9236ea728971b7e51186e0c7@plug.quanstro.net> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Subject: [9fans] 5c ulong -> double/float bug Topicbox-Message-UUID: 5b274fa4-ead6-11e9-9d60-3106f5b1d025 the problem was that (double)~0ul -> -1.0. i'm sure that someone will come up with more elegant assembly than the attached fix. - erik ----- ; cat gbug.c #include #include void main(void) { print("%g\n", (double)0xfffffffful); print("%g\n", (double)0xffffffffull); ulong u; uvlong v; u = 0xfffffffful; v = 0xffffffffull; print("%g u\n", (double)u); print("%g uv\n", (double)v); } ; tmk gbug.c 5c -FVTw gbug.c 5l -o 5.gbug gbug.5 ; 5.gbug 4.294967e+09 4.294967e+09 4.294967e+09 u 4.294967e+09 uv ; bind `{yesterday /arm} /arm ; tmk gbug.c 5c -FVTw gbug.c 5l -o 5.gbug gbug.5 ; 5.out -1 -1 -1 u -1 uv ----- fix: ; diffy -c /sys/src/cmd/5c/txt.c /n/dump/2010/0926/sys/src/cmd/5c/txt.c:696,701 - /sys/src/cmd/5c/txt.c:696,722 case TIND: switch(tt) { case TDOUBLE: + a = AMOVWD; + adju: + gins(a, f, t); + if(ft == TUINT || ft == TULONG || ft == TIND) { + Prog *p1; + Node dnod; + + regalloc(&nod, f, Z); + gmove(nodconst(1<<31), &nod); + gins(AAND, f, &nod); + p->scond |= C_SBIT; + gins(ABEQ, Z, Z); + p1 = p; + regalloc(&dnod, t, Z); + gmove(nodfconst(4294967296.), &dnod); + gins(a==AMOVWD? AADDD: AADDF, &dnod, t); + regfree(&dnod); + patch(p1, pc); + regfree(&nod); + } + return; case TVLONG: gins(AMOVWD, f, t); if(ft == TULONG) { /n/dump/2010/0926/sys/src/cmd/5c/txt.c:702,711 - /sys/src/cmd/5c/txt.c:723,730 } return; case TFLOAT: - gins(AMOVWF, f, t); - if(ft == TULONG) { - } - return; + a = AMOVWF; + goto adju; case TINT: case TUINT: case TLONG: