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] fp crash
Date: Mon, 28 Jan 2013 18:37:32 -0500	[thread overview]
Message-ID: <4deb4818bb26c316406212a8d1146e14@ladd.quanstro.net> (raw)

i've been looking at the program below, which calculates
some bad values on arm and amd64 and thus crashes.
(i added an a few asserts to make the crashes more reliable.)
386 does not have this issue.

#include <u.h>
#include <libc.h>
#include <stdio.h>

void
main(void)
{
	printf("%10.4lf\n", 9306112.0000);
	exits("");
}

the "problem" boils down to this

#include <u.h>
#include <libc.h>

#define fpword0(x) ((FPdbleword*)&x)->hi

#define Exp_11 0x3ff00000
#define Frac_mask1 0xfffff

void
badcalc(double d)
{
	double d2;

	d2 = d;
	fpword0(d2) &= Frac_mask1;
	fpword0(d2) |= Exp_11;

	print("%g %g\n", d, d2);
}

void
main(void)
{
	badcalc(9306112.0000);
	exits("");
}

so the question is, is the compiler free to assume that
d2 has not been modified?  (it does not do this if uvlong
is subsituted)

- erik

---
; 5c -S fh.c
	TEXT	badcalc+0(SB),0,$28
	MOVD	d+0(FP),F3
	MOVW	d2-4(SP),R3
	AND	$1048575,R3
	MOVW	R3,d2-4(SP)
	MOVW	d2-4(SP),R1
	ORR	$1072693248,R1
	MOVW	R1,d2-4(SP)
	MOVW	$.string<>+0(SB),R0
	MOVD	F3,8(R13)
	MOVD	F3,16(R13)
	BL	,print+0(SB)
	RET	,
	TEXT	main+0(SB),0,$8
	MOVD	$9.30611200000000000e+06,F0
	MOVD	F0,4(R13)
	BL	,badcalc+0(SB)
	DATA	.string<>+0(SB)/8,$"%g %g\n\z\z"
	MOVW	$.string<>+7(SB),R0
	BL	,exits+0(SB)
	RET	,
	GLOBL	.string<>+0(SB),$8
	END	,



             reply	other threads:[~2013-01-28 23:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-28 23:37 erik quanstrom [this message]
2013-01-28 23:50 ` Charles Forsyth
2013-01-29  0:08   ` erik quanstrom
2013-01-29  1:41     ` erik quanstrom
2013-01-29  3:27       ` Charles Forsyth
2013-01-29  3:34         ` erik quanstrom
2013-01-29 17:17           ` Charles Forsyth
2013-01-29 17:19             ` erik quanstrom

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=4deb4818bb26c316406212a8d1146e14@ladd.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).