Re: [NOVICE] [BUGS] Postgres storing time in strange manner

2002-09-18 Thread Peter Eisentraut

Tom Lane writes:

> Sean Chittenden <[EMAIL PROTECTED]> writes:
> > Is there a place where -fno-fast-math
> > could be used as a CC option if the CC is gcc?
>
> configure is what I had in mind ;-).  I can't think of any part of the
> code where we'd really want this sort of optimization enabled.

Today I read that __FAST_MATH__ is defined if -ffast-math is used, so it
should be easy to write a test in configure.

-- 
Peter Eisentraut   [EMAIL PROTECTED]


---(end of broadcast)---
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



Re: [NOVICE] [BUGS] Postgres storing time in strange manner

2002-09-18 Thread Sean Chittenden

> > After looking through gcc, using -O and -ffast-math will create broken
> > code, but -O2 -ffast-math _should_ be okay.
> 
> At least in the gcc shipped with Red Hat 7.2, it doesn't seem to matter:
> you get the wrong answer regardless of -O level.  Here's the test case
> I used:
> 
> [tgl@rh1 tgl]$ cat bug.c
> #include 
> 
> double d18000 = 18000.0;
> 
> main() {
>   int d = d18000 / 3600;
>   printf("18000.0 / 3600 = %d\n", d);
>   return 0;
> }
> [tgl@rh1 tgl]$ gcc  bug.c
> [tgl@rh1 tgl]$ ./a.out
> 18000.0 / 3600 = 5-- right
> [tgl@rh1 tgl]$ gcc -O2 -ffast-math bug.c
> [tgl@rh1 tgl]$ ./a.out
> 18000.0 / 3600 = 4-- wrong
> -- I get 4 if -ffast-math, -O doesn't affect it
> [tgl@rh1 tgl]$ gcc -v
> Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
> gcc version 2.96 2731 (Red Hat Linux 7.1 2.96-98)

Heh, chalk this one up as another Linux-ism then 'cause it's not
present in FreeBSD -stable or -current.  This actually makes me feel
better about setting an option in the -devel port for turning on
compilation with -O3.  -sc

stable$ gcc -v
Using builtin specs.
gcc version 2.95.4 20020320 [FreeBSD]

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

-- 
Sean Chittenden

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])



Re: [NOVICE] [BUGS] Postgres storing time in strange manner

2002-09-18 Thread Tom Lane

Sean Chittenden <[EMAIL PROTECTED]> writes:
> Is there a place where -fno-fast-math
> could be used as a CC option if the CC is gcc?

configure is what I had in mind ;-).  I can't think of any part of the
code where we'd really want this sort of optimization enabled.

> After looking through gcc, using -O and -ffast-math will create broken
> code, but -O2 -ffast-math _should_ be okay.

At least in the gcc shipped with Red Hat 7.2, it doesn't seem to matter:
you get the wrong answer regardless of -O level.  Here's the test case
I used:

[tgl@rh1 tgl]$ cat bug.c
#include 

double d18000 = 18000.0;

main() {
  int d = d18000 / 3600;
  printf("18000.0 / 3600 = %d\n", d);
  return 0;
}
[tgl@rh1 tgl]$ gcc  bug.c
[tgl@rh1 tgl]$ ./a.out
18000.0 / 3600 = 5  -- right
[tgl@rh1 tgl]$ gcc -O2 -ffast-math bug.c
[tgl@rh1 tgl]$ ./a.out
18000.0 / 3600 = 4  -- wrong
-- I get 4 if -ffast-math, -O doesn't affect it
[tgl@rh1 tgl]$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 2731 (Red Hat Linux 7.1 2.96-98)

regards, tom lane

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly



Re: [NOVICE] [BUGS] Postgres storing time in strange manner

2002-09-18 Thread Sean Chittenden

> > Out of curiosity: why does -ffast-math break the datetime rounding code?

What code bits is this for?  Is there a place where -fno-fast-math
could be used as a CC option if the CC is gcc?  After looking through
gcc, using -O and -ffast-math will create broken code, but -O2
-ffast-math _should_ be okay.  If it's not, then -O2 -fno-fast-math is
likely the correct work around for GCC.  -sc

-- 
Sean Chittenden

---(end of broadcast)---
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



Re: [NOVICE] [BUGS] Postgres storing time in strange manner

2002-09-17 Thread Bruce Momjian

Thomas Lockhart wrote:
> ...
> > > > Hard to imagine why anyone would want such an optimization.  How much
> > > > faster could it possibly be?
> > > Back in ye bad olde days, there was probably an order-of-magnitude
> > > difference between the speed of a float multiply and that of a float
> > > divide; so this used to be a pretty standard sort of optimization.
> > > I can remember doing the equivalent thing by hand in source code.
> > > On modern hardware I doubt it makes much difference...
> 
> The speed difference is still there; you can't do a divide with one pass
> through a barrel shifter, which is how the multiply operations were sped
> up. I vaguely recall something like a 40:1 ratio on a 604 PowerPC but
> that may not be accurate, or may be for integers which have similar
> issues.

Wow, 40:1 is a major difference.

> > And you would have to do a heck of a lot of them to see a difference.
> 
> ?? Some applications *do* do a heck of a lot of them ;)

Yep, I am sure.  The question is whether there is ever a reason to use
such a flag on the database code.  My guess is no.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])



Re: [NOVICE] [BUGS] Postgres storing time in strange manner

2002-09-17 Thread Bruce Momjian

Tom Lane wrote:
> Bruce Momjian <[EMAIL PROTECTED]> writes:
> > Tom Lane wrote:
> >> with -ffast-math gcc will "improve" it to
> >> 
> >> int hour = time * 0.000278;
> 
> > Hard to imagine why anyone would want such an optimization.  How much
> > faster could it possibly be?
> 
> Back in ye bad olde days, there was probably an order-of-magnitude
> difference between the speed of a float multiply and that of a float
> divide; so this used to be a pretty standard sort of optimization.
> I can remember doing the equivalent thing by hand in source code.
> 
> On modern hardware I doubt it makes much difference...

And you would have to do a heck of a lot of them to see a difference.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



Re: [NOVICE] [BUGS] Postgres storing time in strange manner

2002-09-17 Thread Tom Lane

Bruce Momjian <[EMAIL PROTECTED]> writes:
> Tom Lane wrote:
>> with -ffast-math gcc will "improve" it to
>> 
>> int hour = time * 0.000278;

> Hard to imagine why anyone would want such an optimization.  How much
> faster could it possibly be?

Back in ye bad olde days, there was probably an order-of-magnitude
difference between the speed of a float multiply and that of a float
divide; so this used to be a pretty standard sort of optimization.
I can remember doing the equivalent thing by hand in source code.

On modern hardware I doubt it makes much difference...

regards, tom lane

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster



Re: [NOVICE] [BUGS] Postgres storing time in strange manner

2002-09-17 Thread Bruce Momjian

Tom Lane wrote:
> Ron Johnson <[EMAIL PROTECTED]> writes:
> > Out of curiosity: why does -ffast-math break the datetime rounding code?
> 
> We dug into this last night, and it turns out that the culprit is code
> like
> 
>   int hour = time / 3600;
> 
> where time is a double.  This yields an exact result when done
> correctly, but with -ffast-math gcc will "improve" it to
> 
>   int hour = time * 0.000278;
> 
> the constant being the nearest double value to 1.0 / 3600.0.  The
> problem is that the constant is inexact and in fact is slightly too
> large; so for example if time is exactly 18000.0, you get a resulting
> hour value of 4, not 5, after truncation to integer.  Repeated a couple
> more times, what should have been 5:00:00 comes out as 4:59:60 ...

Hard to imagine why anyone would want such an optimization.  How much
faster could it possibly be?  I guess if you were doing only complex
math approximations, it would be a win, but that isn't really proper for
a database.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



Re: [NOVICE] [BUGS] Postgres storing time in strange manner

2002-09-17 Thread Tom Lane

Ron Johnson <[EMAIL PROTECTED]> writes:
> Out of curiosity: why does -ffast-math break the datetime rounding code?

We dug into this last night, and it turns out that the culprit is code
like

int hour = time / 3600;

where time is a double.  This yields an exact result when done
correctly, but with -ffast-math gcc will "improve" it to

int hour = time * 0.000278;

the constant being the nearest double value to 1.0 / 3600.0.  The
problem is that the constant is inexact and in fact is slightly too
large; so for example if time is exactly 18000.0, you get a resulting
hour value of 4, not 5, after truncation to integer.  Repeated a couple
more times, what should have been 5:00:00 comes out as 4:59:60 ...

regards, tom lane

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly