9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] fp crash
@ 2013-01-28 23:37 erik quanstrom
  2013-01-28 23:50 ` Charles Forsyth
  0 siblings, 1 reply; 8+ messages in thread
From: erik quanstrom @ 2013-01-28 23:37 UTC (permalink / raw)
  To: 9fans

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	,



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-01-29 17:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-28 23:37 [9fans] fp crash erik quanstrom
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

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).