9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] 5c ulong -> double/float bug
@ 2010-09-27  2:53 erik quanstrom
  0 siblings, 0 replies; only message in thread
From: erik quanstrom @ 2010-09-27  2:53 UTC (permalink / raw)
  To: 9fans

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 <u.h>
#include <libc.h>

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:



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-09-27  2:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-27  2:53 [9fans] 5c ulong -> double/float bug erik quanstrom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).