NetBSD Problem Report #51368
From www@NetBSD.org Wed Jul 27 15:08:05 2016
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
by mollari.NetBSD.org (Postfix) with ESMTPS id 230807A219
for <gnats-bugs@gnats.NetBSD.org>; Wed, 27 Jul 2016 15:08:05 +0000 (UTC)
Message-Id: <20160727150803.888BC7A264@mollari.NetBSD.org>
Date: Wed, 27 Jul 2016 15:08:03 +0000 (UTC)
From: rokuyama@rk.phys.keio.ac.jp
Reply-To: rokuyama@rk.phys.keio.ac.jp
To: gnats-bugs@NetBSD.org
Subject: powerpc FPU emulation fails for single precision floating point arithmetic
X-Send-Pr-Version: www-1.0
>Number: 51368
>Category: port-powerpc
>Synopsis: powerpc FPU emulation fails for single precision floating point arithmetic
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: port-powerpc-maintainer
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Jul 27 15:10:01 +0000 2016
>Closed-Date: Mon Jan 09 00:09:39 +0000 2017
>Last-Modified: Mon Jan 09 00:09:39 +0000 2017
>Originator: Rin Okuyama
>Release: HEAD
>Organization:
Faculty of Science and Technology, Keio University
>Environment:
NetBSD obs266 7.99.34 NetBSD 7.99.34 (OPENBLOCKS266) #1: Wed Jul 27 22:09:26 JST 2016 rin@XXX:XXX evbppc
>Description:
FPU emulation of powerpc fails for single precision floating point
arithmetic. On a machine without FPU (e.g., ibm4xx like
evbppc/OPENBLOCKS266),
====================
% cat fp.c
#include <stdio.h>
int main(){
double dx = 1.0, dy = 2.0;
float sx = 1.0, sy = 2.0;
printf("DP: %f / %f = %f\n", dx, dy, dx / dy);
printf("SP: %f / %f = %f\n", sx, sy, sx / sy);
return 0;
}
% cc fp.c && ./a.out
DP: 1.000000 / 2.000000 = 0.500000
SP: 1.000000 / 2.000000 = 0.003906
====================
This failure triggers corrupted display output of X clients, e.g., xterm
or oclock, where single precision calculation is utilized.
>How-To-Repeat:
Described above.
>Fix:
FreeBSD also uses FPU emulation codes derived from ours, and they fixed
this bug by commit r258250:
====================
https://svnweb.freebsd.org/base?view=revision&revision=258250
Make single precision floating point arithmetic actually work -- I think
it never did -- and fix an obvious missing line. Floating point emulation
on Book-E still needs some work but this gets it basically functional on
soft-FPU systems (hard FPU for Book-E is not yet implemented).
MFC after: 1 week
====================
With this fix, X clients as well as the test above works fine.
====================
--- src/sys/arch/powerpc/fpu/fpu_emu.c.orig 2016-07-27 10:04:00.737524067 +0900
+++ src/sys/arch/powerpc/fpu/fpu_emu.c 2016-07-27 10:03:44.803486129 +0900
@@ -626,9 +626,11 @@
rb = instr.i_a.i_frb;
rc = instr.i_a.i_frc;
- type = FTYPE_SNG;
- if (instr.i_any.i_opcd & 0x4)
- type = FTYPE_DBL;
+ /*
+ * All arithmetic operations work on registers, which
+ * are stored as doubles.
+ */
+ type = FTYPE_DBL;
switch ((unsigned int)instr.i_a.i_xo) {
case OPC59_FDIVS:
FPU_EMU_EVCNT_INCR(fdiv);
@@ -745,6 +747,13 @@
return (NOTFPU);
break;
}
+
+ /* If the instruction was single precision, round */
+ if (!(instr.i_any.i_opcd & 0x4)) {
+ fpu_implode(fe, fp, FTYPE_SNG,
+ (u_int *)&fs->fpreg[rt]);
+ fpu_explode(fe, fp = &fe->fe_f1, FTYPE_SNG, rt);
+ }
}
} else {
return (NOTFPU);
--- src/sys/arch/powerpc/fpu/fpu_explode.c.orig 2016-07-27 10:00:01.060507066 +0900
+++ src/sys/arch/powerpc/fpu/fpu_explode.c 2016-07-27 10:00:12.431852649 +0900
@@ -235,6 +235,7 @@
s = fpu_dtof(fp, s, space[1]);
break;
+ default:
panic("fpu_explode");
panic("fpu_explode: invalid type %d", type);
}
====================
>Release-Note:
>Audit-Trail:
From: "Rin Okuyama" <rin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/51368 CVS commit: src/sys/arch/powerpc/fpu
Date: Wed, 28 Dec 2016 10:52:30 +0000
Module Name: src
Committed By: rin
Date: Wed Dec 28 10:52:30 UTC 2016
Modified Files:
src/sys/arch/powerpc/fpu: fpu_emu.c
Log Message:
PR port-powerpc/51368: powerpc FPU emulation fails for single precision
floating point arithmetic
For single precision instruction, calculate first in double precision,
and then round it. With this fix, single precision arithmetic gets sane
on ibm4xx and booke.
Taken from FreeBSD commit r258250:
https://svnweb.freebsd.org/base?view=revision&revision=258250
Ok matt and simonb.
To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/powerpc/fpu/fpu_emu.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->pending-pullups
State-Changed-By: rin@NetBSD.org
State-Changed-When: Wed, 28 Dec 2016 20:57:18 +0000
State-Changed-Why:
Fix committed. Pull-up requested to netbsd-7.
From: "Soren Jacobsen" <snj@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/51368 CVS commit: [netbsd-7] src/sys/arch/powerpc/fpu
Date: Tue, 3 Jan 2017 06:19:21 +0000
Module Name: src
Committed By: snj
Date: Tue Jan 3 06:19:21 UTC 2017
Modified Files:
src/sys/arch/powerpc/fpu [netbsd-7]: fpu_emu.c fpu_explode.c
Log Message:
Pull up following revision(s) (requested by rin in ticket #1341):
sys/arch/powerpc/fpu/fpu_emu.c: revision 1.19
sys/arch/powerpc/fpu/fpu_explode.c: revision 1.7
- add missing default from FreeBSD
- remove duplicate panic pointed out by matt
--
PR port-powerpc/51368: powerpc FPU emulation fails for single precision
floating point arithmetic
For single precision instruction, calculate first in double precision,
and then round it. With this fix, single precision arithmetic gets sane
on ibm4xx and booke.
Taken from FreeBSD commit r258250:
https://svnweb.freebsd.org/base?view=revision&revision=258250
Ok matt and simonb.
To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.16.14.1 src/sys/arch/powerpc/fpu/fpu_emu.c
cvs rdiff -u -r1.6 -r1.6.140.1 src/sys/arch/powerpc/fpu/fpu_explode.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: pending-pullups->closed
State-Changed-By: rin@NetBSD.org
State-Changed-When: Mon, 09 Jan 2017 00:09:39 +0000
State-Changed-Why:
The fix is to be in NetBSD 7.1.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.