From mboxrd@z Thu Jan 1 00:00:00 1970 From: erik quanstrom Date: Mon, 28 Jan 2013 18:37:32 -0500 To: 9fans@9fans.net Message-ID: <4deb4818bb26c316406212a8d1146e14@ladd.quanstro.net> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Subject: [9fans] fp crash Topicbox-Message-UUID: 10797ce6-ead8-11e9-9d60-3106f5b1d025 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 #include #include void main(void) { printf("%10.4lf\n", 9306112.0000); exits(""); } the "problem" boils down to this #include #include #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 ,