NetBSD Problem Report #36251

From grubba@grubba.org  Mon Apr 30 21:19:28 2007
Return-Path: <grubba@grubba.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id B7C5663B964
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 30 Apr 2007 21:19:28 +0000 (UTC)
Message-Id: <Pine.GSO.4.63.0704302213580.4035@shipon.roxen.com>
Date: Mon, 30 Apr 2007 22:18:20 +0200 (CEST)
From: Henrik Grubbstrom <grubba@grubba.org>
To: gnats-bugs@NetBSD.org
Cc: grubba@grubba.org
Subject: Support for denormalized 32-bit floats broken on sgimips

>Number:         36251
>Category:       port-mips
>Synopsis:       The emulation code for cvt.d.s seems broken for denormalized values.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    tsutsui
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Apr 30 21:20:00 +0000 2007
>Closed-Date:    Thu Mar 24 02:35:15 +0000 2011
>Last-Modified:  Thu Mar 24 02:35:15 +0000 2011
>Originator:     Henrik Grubbstrom
>Release:        NetBSD 3.1
>Organization:

>Environment:


System: NetBSD shinon.grubba.org 3.1 NetBSD 3.1 (GENERIC32_IP3x) #0: Tue Oct 31 08:26:30 UTC 2006 builds@b1.netbsd.org:/home/builds/ab/netbsd-3-1-RELEASE/sgimips/200610302053Z-obj/home/builds/ab/netbsd-3-1-RELEASE/src/sys/arch/sgimips/compile/GENERIC32_IP3x sgimips
Architecture: mipseb
Machine: sgimips
>Description:

   The emulation of the opcode cvt.d.s doesn't handle denormalized
   values correctly. Eg the value (float)pow(2.0, -128) is converted
   to the value pow(2.0, -125).

>How-To-Repeat:

Test program:

#include <stdio.h>
#include <math.h>

int main(int argc, char **argv)
{
   float f = (float)pow(2.0, -128.0);
   double d = f;
   float ff = (float)d;
   double dd = ff;
   int i;

   if (f == ff) return 0;
   fprintf(stderr, "f: ");
   for (i=0; i < sizeof(f); i++)
     fprintf(stderr, "%02x ", ((unsigned char *)&f)[i]);
   fprintf(stderr, "\nd: ");
   for (i=0; i < sizeof(d); i++)
     fprintf(stderr, "%02x ", ((unsigned char *)&d)[i]);
   fprintf(stderr, "\nff: ");
   for (i=0; i < sizeof(ff); i++)
     fprintf(stderr, "%02x ", ((unsigned char *)&ff)[i]);
   fprintf(stderr, "\ndd: ");
   for (i=0; i < sizeof(dd); i++)
     fprintf(stderr, "%02x ", ((unsigned char *)&dd)[i]);
   fprintf(stderr, "\n");
   return 1;
}

$ gcc bug.c -o bug -lm
$ ./bug 
f: 00 20 00 00 
d: 38 20 00 00 00 00 00 00 
ff: 01 00 00 00 
dd: 38 20 00 00 00 00 00 00

The expected value for d is:

   37 f0 00 00 00 00 00 00

>Fix:

   I believe the problem lies in sys/arch/mips/fp.S:cvt_d_s or in the renorm_*
   function it uses.

>Release-Note:

>Audit-Trail:
From: Marcus Comstedt <marcus@mc.pp.se>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: port-sgimips/36251
Date: Tue, 01 May 2007 23:12:43 +0200

 The problem here seems to be that while renorm_fs_s leaves the
 fractional part of the mantissa offsetted by SLEAD_ZEROS (8) bits,
 norm_d expects it to be offset by DLEAD_ZEROS (11) bits.  When
 shifting the mantissa into the right place, norm_d will add 3
 (DLEAD_ZEROS-SLEAD_ZEROS) to the exponent to compensate for the
 fact that it had to shift the mantissa down 3 bits.  cvt_d_s should
 either do

   addiu t1, t1, (SLEAD_ZEROS)-(DLEAD_ZEROS)

 (parentheses required due to the way xLEAD_ZEROS are defined...)
 to pre-adjust the exponent before jumping to norm_d, or shift the
 mantissa down 3 bits like the normalized case does.


   // Marcus


Responsible-Changed-From-To: port-sgimips-maintainer->tsutsui
Responsible-Changed-By: tsutsui@NetBSD.org
Responsible-Changed-When: Fri, 28 Jan 2011 18:18:44 +0900
Responsible-Changed-Why:


State-Changed-From-To: open->analyzed
State-Changed-By: tsutsui@NetBSD.org
State-Changed-When: Fri, 28 Jan 2011 18:18:44 +0900
State-Changed-Why:
marcus' analysis is correct.


From: "Izumi Tsutsui" <tsutsui@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/36251 CVS commit: src/sys/arch/mips/mips
Date: Fri, 25 Feb 2011 11:44:56 +0000

 Module Name:	src
 Committed By:	tsutsui
 Date:		Fri Feb 25 11:44:56 UTC 2011

 Modified Files:
 	src/sys/arch/mips/mips: fp.S

 Log Message:
 Fix cvt.d.s per analysis by Marcus Comstedt in PR port-mips/36251.
 Confirmed on ews4800mips.


 To generate a diff of this commit:
 cvs rdiff -u -r1.39 -r1.40 src/sys/arch/mips/mips/fp.S

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: analyzed->pending-pullups
State-Changed-By: tsutsui@NetBSD.org
State-Changed-When: Sat, 05 Mar 2011 20:45:02 +0900
State-Changed-Why:
Fixed in HEAD, filed pullup-5 #1572.


From: "Manuel Bouyer" <bouyer@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/36251 CVS commit: [netbsd-5] src/sys/arch/mips/mips
Date: Sun, 20 Mar 2011 21:31:33 +0000

 Module Name:	src
 Committed By:	bouyer
 Date:		Sun Mar 20 21:31:33 UTC 2011

 Modified Files:
 	src/sys/arch/mips/mips [netbsd-5]: fp.S

 Log Message:
 Pull up following revision(s) (requested by tsutsui in ticket #1572):
 	sys/arch/mips/mips/fp.S: revision 1.40 via patch
 Fix cvt.d.s per analysis by Marcus Comstedt in PR port-mips/36251.
 Confirmed on ews4800mips.


 To generate a diff of this commit:
 cvs rdiff -u -r1.33 -r1.33.30.1 src/sys/arch/mips/mips/fp.S

 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: dholland@NetBSD.org
State-Changed-When: Thu, 24 Mar 2011 02:35:15 +0000
State-Changed-Why:
Pullup completed.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(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-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.