delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/08/04/02:17:56

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Message-ID: <48969EE4.5720D900@dessent.net>
Date: Sun, 03 Aug 2008 23:17:09 -0700
From: Brian Dessent <brian AT dessent DOT net>
X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U)
MIME-Version: 1.0
To: "cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com>
Subject: Re: cygwin gcc: Different numerical results in thread vs in main()
References: <40C7B1BFC291ED4E9D10436D07736A33127AB73C9D AT EXMAIL7 DOT haas DOT uc DOT berkeley DOT edu>
X-IsSubscribed: yes
Reply-To: cygwin AT cygwin DOT com
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Richard Stanton wrote:

> Main:        t/1+t =    0.0005609048868329022342546
> Thread 0: t/1+t =    0.0005609048868329021258344
> Thread 1: t/1+t =    0.0005609048868329021258344
> Thread 2: t/1+t =    0.0005609048868329021258344
> Thread 3: t/1+t =    0.0005609048868329021258344

The difference is because the 387 in the main thread has its rounding
mode set to extended precision, whereas in the threads it's set to
double precision.  Cygwin sets the control word to extended precision in
its crt startup code; apparently the Windows default for new threads is
double precision and it's not explicitly set by Cygwin in
pthread::thread_init_wrapper.  Arguably it should set it there too for
consistency.

But the results are the same to 15 significant digits which is all you
can expect out of an IEEE double, so this is technically correct.  The
excess precision issue with 387 math is well known, see gcc PR323.

If your architecture supports sse2 then you can use that instead of the
387 unit with -fpmath=sse2 (in conjunction with the relevant -march= of
course, or -msse2).  The sse2 unit always does double calculations in
double precision, there is no extended mode, so this is not an issue.

You could also set the 387 control word yourself at your thread's start
function.  

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019