From mteterin@250-217.customer.cloud9.net  Mon Sep 23 12:16:54 2002
Return-Path: <mteterin@250-217.customer.cloud9.net>
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP
	id AE27D37B401; Mon, 23 Sep 2002 12:16:54 -0700 (PDT)
Received: from corbulon.video-collage.com (corbulon.video-collage.com [64.35.99.179])
	by mx1.FreeBSD.org (Postfix) with ESMTP
	id A4A0843E3B; Mon, 23 Sep 2002 12:16:53 -0700 (PDT)
	(envelope-from mteterin@250-217.customer.cloud9.net)
Received: from misha.murex.com (250-217.customer.cloud9.net [168.100.250.217])
	by corbulon.video-collage.com (8.12.2/8.12.2) with ESMTP id g8NJGfPW037295
	(version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO);
	Mon, 23 Sep 2002 15:16:42 -0400 (EDT)
	(envelope-from mteterin@250-217.customer.cloud9.net)
Received: from 250-217.customer.cloud9.net (mteterin@localhost [127.0.0.1])
	by misha.murex.com (8.12.6/8.12.5) with ESMTP id g8NJHUnr001236;
	Mon, 23 Sep 2002 15:17:42 -0400 (EDT)
	(envelope-from mteterin@250-217.customer.cloud9.net)
Received: (from mteterin@localhost)
	by 250-217.customer.cloud9.net (8.12.6/8.12.5/Submit) id g8NJHNMd001235;
	Mon, 23 Sep 2002 15:17:23 -0400 (EDT)
	(envelope-from mteterin)
Message-Id: <200209231917.g8NJHNMd001235@250-217.customer.cloud9.net>
Date: Mon, 23 Sep 2002 15:17:23 -0400 (EDT)
From: Mikhail Teteri <mi@aldan.algebra.com>
Reply-To: Mikhail Teterin <mi@aldan.algebra.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc: kan@freebsd.org
Subject: march=pentium4 miscompiles msun/src/e_pow.c
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         43299
>Category:       bin
>Synopsis:       march=pentium4 miscompiles msun/src/e_pow.c
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Sep 23 12:20:01 PDT 2002
>Closed-Date:    Fri Aug 15 21:20:15 PDT 2003
>Last-Modified:  Fri Aug 15 21:20:15 PDT 2003
>Originator:     Mikhail Teterin
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
Virtual Estates, Inc.
>Environment:
System: FreeBSD misha.murex.com 5.0-CURRENT FreeBSD 5.0-CURRENT #2: Tue Sep 17 11:27:30 EDT 2002 mteterin@misha.murex.com:/misha/obj/misha/src/sys/Misha-g i386


	The compiler:
		Using built-in specs.
		Configured with: FreeBSD/i386 system compiler
		Thread model: posix
		gcc version 3.2.1 [FreeBSD] 20020916 (prerelease)

>Description:

	If the e_pow.c is compiled with march=pentium4, the pow(3) will
	be returning 0 whenever y (the second argument) is not an integer.

>How-To-Repeat:

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

	double __ieee754_pow(double, double);

	int main() {
		printf("%g^%g is %g\n", 2.0, 2.1, __ieee754_pow(2.0, 2.1));
		return 0;
	}

	cd /usr/src/lib/msun/src
	cc -O -march=pentium4 t.c e_pow.c -lm
	./a.out
	2^2.1 is 0

	Notice, that I use -lm I eliminate other possible
	miscompilations from the equation...

>Fix:

	Use -O0 or -mno-sse2:

	2^2.1 is 4.28709
>Release-Note:
>Audit-Trail:

From: Mikhail Teterin <mi+mx@aldan.algebra.com>
To: FreeBSD-gnats-submit@FreeBSD.org, kan@FreeBSD.org
Cc: "David E. O'Brien" <obrien@FreeBSD.org>
Subject: Re: bin/43299: march=pentium4 miscompiles msun/src/e_pow.c
Date: Mon, 23 Sep 2002 16:32:17 -0400

 This has something to do with how the function's parameters are being
 passed in the SSE2 case. In the debugger, when entering the function,
 its second argument is already corrupted:
 
 (gdb) s
 main () at t.c:9
 9               printf("%g^%g is %g\n", 2.0, 2.1, __ieee754_pow(2.0, 2.1));
 (gdb) s
 __ieee754_pow (x=2.1000000000000001, y=-nan(0x8000000000000)) at e_pow.c:107
 107             EXTRACT_WORDS(hx,lx,x);
 
 
 Hope, this helps,
 
 	-mi
 

From: Mikhail Teterin <mi+mx@aldan.algebra.com>
To: freebsd-gnats-submit@FreeBSD.org, mi@aldan.algebra.com
Cc: deischen@FreeBSD.org, bde@FreeBSD.org
Subject: Re: bin/43299: march=pentium4 miscompiles msun/src/e_pow.c
Date: Tue, 17 Dec 2002 18:41:46 -0500

 The described problem no longer exists. Probably -- thanks to the
 recent commit:
 
 deischen    2002/12/02 11:58:55 PST
 
   Modified files:
     sys/i386/i386        genassym.c locore.s machdep.c 
     sys/i386/include     signal.h ucontext.h 
   Log:
   Align the FPU state in the ucontext and sigcontext to 16 bytes
   to accomodate the new SSE/XMM floating point save/restore
   instructions.
   
   This commit is mostly from bde and includes some style nits.
   
   Approved by:    re (jhb)
 
 However, on my 2GHz Pentium4, the pow(3) is between 10 to 15%
 slower, when compiled for pentium4, than it is, when compiled
 for pentium3. The little program follows. It prints out the
 results of the explicit __ieee754_pow(), and than goes to work.
 
 #include <math.h>
 #include <stdio.h>
 
 double __ieee754_pow(double, double);
 
 int main() {
 	int i;
 	printf("%g^%g is %g\n", 2.0, 2.1, __ieee754_pow(2.0, 2.1));
 	printf("%g^%g is %g\n", 11.0, -2.1, __ieee754_pow(11.0, -2.1));
 	for (i = 0; i < 10000000; i++)
 		__ieee754_pow(11.0, -2.1);
 	return 0;
 }
 
 I compile it (named t.c) as follows:
 
 	cd /usr/src/lib/msun/src
 	cc $FLAGS t.c e_exp.c ../i387/s_scalbn.S ../i387/e_sqrt.S e_pow.c
 
 To exclude the effects of the precompiled -lm.
 
 	-mi
 

From: Andrew Gallatin <gallatin@cs.duke.edu>
To: freebsd-gnats-submit@FreeBSD.org
Cc: mi@aldan.algebra.com
Subject: Re: bin/43299: march=pentium4 miscompiles msun/src/e_pow.c
Date: Fri, 10 Jan 2003 09:47:17 -0500 (EST)

 The problem seems to have re-appeared with more recent kernel and
 world.  With a kernel and world dated January 8th (noon EST),
 I see the following behaviour:
 
 
 % cc -O -march=pentium4 /home/gallatin/hacks/t.c ../i387/s_scalbn.S ../i387/e_sqrt.S e_pow.c
 % ./a.out
 2^2.1 is 0.5
 11^-2.1 is 0.0909091
 
 Leaving off the -O allows the binary to be built correctly:
 
 % cc  -march=pentium4 /home/gallatin/hacks/t.c ../i387/s_scalbn.S ../i387/e_sqrt.S e_pow.c
 % /a.out
 
 
 The problem seems to be gcc specific, as binaries built with icc seem
 to work correctly regardless of optimization level or use of sse2.
 
 Drew

From: Mikhail Teterin <mi+mx@aldan.algebra.com>
To: freebsd-gnats-submit@FreeBSD.org, mi@aldan.algebra.com
Cc: das@FreeBSD.org, ura@euro-bill.net, re@FreeBSD.org
Subject: Re: bin/43299: march=pentium4 miscompiles msun/src/e_pow.c
Date: Mon, 12 May 2003 14:02:49 -0400

 My most recent encounter with this bug is the failure of the selftest of
 ports/graphics/lcms.
 
 I recompiled the libm (lib/msun) with -march=pentium3 and reinstalled
 it. After that the lcms passed its own self-test. Note, that lcms did
 NOT require recompiling -- using the pentium3 version of libm it had no
 problems.
 
 Linux, where most of the gcc's development is going on, does not appear
 to suffer. gallatin says, icc does not have this problem. Could it be,
 that our own i387 implementation of some of the functions fail on
 pentium4 and its SSE2?
 
 May be, the -march setting should be forced down to pentium3 in the
 lib/msun subdirectory in case CPUTYPE is set to p4 -- for the time
 being?
 
 	-mi
 
 P.S. The i386/51210 appears to document the same bug:
 
 	http://www.FreeBSD.org/cgi/query-pr.cgi?pr=i386/51210
 
 
 

From: Mikhail Teterin <Mikhail.Teterin@murex.com>
To: freebsd-gnats-submit@FreeBSD.org
Cc: bde@FreeBSD.org
Subject: Re: bin/43299: march=pentium4 miscompiles msun/src/e_pow.c
Date: Mon, 12 May 2003 14:26:35 -0400

 The problem with our libm (msun) vs. gcc-3 is reproduceable on Linux:
 
 	(Note, FreeBSD's /usr is mounted as /misha on the Linux machine)
 
 mteterin@nylinux:lib/msun/src (982) cc -v
 Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2/specs
 Configured with: ../configure --prefix=/usr --mandir=/usr/share/man 
 --infodir=/usr/share/info --enable-shared --enable-threads=posix 
 --disable-checking --host=i386-redhat-linux --with-system-zlib 
 --enable-__cxa_atexit
 Thread model: posix
 gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
 mteterin@nylinux:lib/msun/src (983) cc -O -march=pentium3 -I- -I. 
 -I/misha/src/include -I/misha/src/sys -I/misha/obj/misha/src/i386/usr/include 
 e_pow.c t.c e_sqrt.c -D__generic___ieee754_sqrt=__ieee754_sqrt
 mteterin@nylinux:lib/msun/src (984) ./a.out                                     
 2^2.1 is 4.28709
 mteterin@nylinux:lib/msun/src (985) cc -O -march=pentium4 -I- -I. 
 -I/misha/src/include -I/misha/src/sys -I/misha/obj/misha/src/i386/usr/include 
 e_pow.c t.c e_sqrt.c -D__generic___ieee754_sqrt=__ieee754_sqrt
 mteterin@nylinux:lib/msun/src (986) ./a.out                                     
 2^2.1 is 0
 
 As can be seen above, using pentium3 produces the correct result, while
 pentium4 produces the incorrect 0. We can, pretty much, rule out a kernel
 problem in handling MMX/SSE. Which is it -- our __ieee754_pow or the gcc?
 
 	-mi
 
 

From: Mikhail Teterin <mi+kde@aldan.algebra.com>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/43299: march=pentium4 miscompiles msun/src/e_pow.c
Date: Wed, 14 May 2003 08:21:43 -0400

 See also
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&pr=10774
 
 which contains the narrowed-down test case.
 
 	-mi
 
State-Changed-From-To: open->feedback 
State-Changed-By: kris 
State-Changed-When: Sat Jul 12 21:08:50 PDT 2003 
State-Changed-Why:  
Can you please confirm the status of this bug with the new 
gcc 3.3 compiler in -current? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=43299 
State-Changed-From-To: feedback->closed 
State-Changed-By: kris 
State-Changed-When: Fri Aug 15 21:20:07 PDT 2003 
State-Changed-Why:  
Feedback timeout 

http://www.freebsd.org/cgi/query-pr.cgi?pr=43299 
>Unformatted:
