NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: port-mips/57680: printf("%.1f") shows wrong resultsonR3000mipseb
The following reply was made to PR port-mips/57680; it has been noted by GNATS.
From: Izumi Tsutsui <tsutsui%ceres.dti.ne.jp@localhost>
To: rvp%SDF.ORG@localhost
Cc: gnats-bugs%netbsd.org@localhost, tsutsui%ceres.dti.ne.jp@localhost
Subject: Re: port-mips/57680: printf("%.1f") shows wrong resultsonR3000mipseb
Date: Sat, 4 Nov 2023 12:12:53 +0900
> On Fri, 3 Nov 2023, Izumi Tsutsui wrote:
>
> > So at least gcc -O2 (including dtoa.c in libc.so) causes
> > something wrong on MIPS1.
> >
>
> Very intriguing results! Does adding an explicit arch flag like `-march=mips1'
> along with `-O2' help?
Looks no change:
---
news3470-% uname -a
NetBSD galant 9.3 NetBSD 9.3 (GENERIC) #0: Sat Nov 4 02:48:54 JST 2023 tsutsui@mirage:/s/tsutsui/netbsd-src/sys/arch/newsmips/compile/obj.newsmips/GENERIC newsmips
news3470-% sysctl hw.model
hw.model = news3400
news3470-% grep ^cpu /var/run/dmesg.boot
cpu0 at mainbus0: MIPS R3000 CPU (0x220) Rev. 2.0 with MIPS R3010 FPC Rev. 2.0
cpu0: 64KB/4B direct-mapped Instruction cache, 64 TLB entries
cpu0: 64KB/4B direct-mapped write-through Data cache
news3470-% cc -O2 -march=mips1 -I/s/netbsd-9/src/lib/libc/gdtoa/ -I/s/netbsd-9/src/lib/libc/arch/mips/gdtoa/ -DDEBUG -DHonor_FLT_ROUNDS -DNO_LONG_LONG -o m2-O2-mips1 m.c /s/netbsd-9/src/lib/libc/gdtoa/dtoa.c /s/netbsd-9/src/lib/libc/gdtoa/dmisc.c /s/netbsd-9/src/lib/libc/gdtoa/misc.c
news3470-% ./m2-O2-mips1
.O
40490FD0
3*5.8
439D145A
?*8.7
44C45970
news3470-%
---
('*'s are also non US-ASCII 8bit chars)
>
> > (I still wonder if it's compiler bug or improper implementation like
> > undefined behaviour etc.)
> >
>
> I don't know anything about the MIPS arch. so I can't definitively say, but,
> IMO I think it's the code GCC is generating for MIPS1:
>
> a) One of the first things I tried on a recent 9.3_STABLE running on amd64
> was to try out different FE_* rounding modes--just like what you added.
> Compile with: cc -m32 -O2 -ffast-math (this last sometimes causes problems).
>
> No issues.
>
> b) Next I forced the FPU to do the rounding by calling fesetround(FE_*) first
> thing. This made some of the final bits in the precision differ, but, this
> is expected.
Yes, using FE_TOWARDZERO as default works around on NWS-3470 (R3000+R3010).
> c) The same binaries work on the newer MIPS arches.
Yes, at least on NWS-5000 (R4400 mipseb).
> d) You say it works fine in an emulator.
I've also confirmed on NetBSD/pmax 9.3 on GXemul emulating
DECstation5000/200 (3MAX) R3000:
https://gist.github.com/tsutsui/043243066bb77f3f0315c70b53269192
https://user-images.githubusercontent.com/3054480/280441532-81e27faf-1e5b-4bee-a9a1-170e8ded09ea.png
---
Unless some MIPS guru has proper idea how this issue should be fixed,
I'd like to commit workaround fix to disable -DHonor_FLT_ROUNDS in
src/lib/libc/gdtoa/Makefile.inc in ${MACHINE_CPU}=="mips" case.
Thanks,
---
Izumi Tsutsui
Home |
Main Index |
Thread Index |
Old Index