This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: strange bug in gettimeofday function
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/