9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: erik quanstrom <quanstro@quanstro.net>
To: 9fans@9fans.net
Subject: [9fans] 5c ulong -> double/float bug
Date: Sun, 26 Sep 2010 22:53:10 -0400	[thread overview]
Message-ID: <77b15d6e9236ea728971b7e51186e0c7@plug.quanstro.net> (raw)

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:



                 reply	other threads:[~2010-09-27  2:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=77b15d6e9236ea728971b7e51186e0c7@plug.quanstro.net \
    --to=quanstro@quanstro.net \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).