delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/02/19/16:34:18

X-Spam-Check-By: sourceware.org
Date: Mon, 19 Feb 2007 13:33:53 -0800
From: Christopher Layne <clayne AT anodized DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: strange bug in gettimeofday function
Message-ID: <20070219213352.GC25468@ns1.anodized.com>
References: <13811889795 DOT 20070215071733 AT gnu DOT org> <erd2lq$4ct$1 AT sea DOT gmane DOT org>
Mime-Version: 1.0
In-Reply-To: <erd2lq$4ct$1@sea.gmane.org>
User-Agent: Mutt/1.5.11
X-Assp-Spam-Prob: 0.00000
X-Assp-Whitelisted: Yes
X-Assp-Envelope-From: clayne AT ns1 DOT anodized DOT com
X-Assp-Intended-For: cygwin AT cygwin DOT com
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT 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

On Mon, Feb 19, 2007 at 12:52:10PM -0800, Shankar Unni wrote:
> Andrew Makhorin wrote:
> 
> >{       double t0 = get_time(), t1 = get_time();
> 
> [Maybe OT?]
> 
> 1. I can't remember if C guarantees that comma-separated *declarations* 
> are initialized in order or not..  And to think I used to be an ANSI C 
> guru :-(.

Should be fine in this case.

> 2. The reason that the "t0 > t1" fails, but t0 and t1 get dumped to be 
> the same, is that C allows the implementation to use larger-than-64-bit 
> (for 64-bit) intermediate double representations. In the case of X86, 
> the CPU's floating-point registers are 80 bits wide.
> 
> When they get written to stack, the value is rounded (or truncated?) to 
> 64 bits.

I don't understand why they just didn't write:

double t0, t1;

t0 = t1 = get_time();

Not everything *has* to be initialized at declaration time.

> 
> In the optimized code, I'll bet you that the two locals (t0 and t1) are 
> kept entirely in registers, at least until the "&t0" and "&t1" calls. So 
> at the point of comparison, it's comparing two 80-bit values, but when 
> you flush them to memory to dump them as integer values, they get 
> truncated to the (same) 64-bit value.

Possible. Consider SSE ops (64-bit vs 80-bit on x87) and use of
fast-math as well.

-cl

--
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