public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: wish: optimize  (x > 0.) floating point comparison.
@ 1998-09-22 19:31 Yotam Medini
  1998-09-22 16:05 ` Robert L Krawitz
  1998-09-22 19:59 ` Robert L Krawitz
  0 siblings, 2 replies; 20+ messages in thread
From: Yotam Medini @ 1998-09-22 19:31 UTC (permalink / raw)
  To: rlk; +Cc: egcs

>   Date: Tue, 22 Sep 1998 16:04:20 -0400
>   From: Robert L Krawitz <rlk@tiac.net>
>   Cc: egcs@cygnus.com
>
>      Date: Tue, 22 Sep 1998 08:55:30 -0700
>      From: Yotam Medini <yotam@avanticorp.com>
>
>      ...
>      I believe that floating-point comparisons (<, >, <=, >=) with 0.0 is
>      very frequent and worth the trouble of optimizing using the sign bit
>      within the (platform dependent) floating-point representation or some
>      other machine instruction.
>
>   That's not correct.  Consider -0.0 (all zeroes in the mantissa and
>   exponent, 1 in the sign bit).  This should compare >= 0 (it is, after
>   all, mathematically equal to zero).  Furthermore, it would not take an
>   exception if the bits do not in fact represent a valid number.

Good point.
I am not familier with the (IEEE?) standard of floating-point representation.
May be a the following pseudo code (with lazy || evaluation)
    bool positive(double x)
    { return((highBit(x) == 0) || ((bitwise)x == (bitwise)(-0.0))); }
is still faster?

Actually, a preliminary question should be if
there is a better way to check for equality to zero than
using 'ldd' (of zero complement?) and 'fcmpd'.

   .LLC5:
	   .uaword	0x0 ! ~0.00000000000000000000e0
     .....
     .....
	   .type	 zeq,#function
	   .proc	04
   zeq:
	   !#PROLOGUE# 0
	   add %sp,-120,%sp
	   !#PROLOGUE# 1
	   sethi %hi(.LLC5),%g2
	   ldd [%g2+%lo(.LLC5)],%f2
	   std %o0,[%sp+96]
	   ldd [%sp+96],%f4
      	   fcmpd %f4,%f2
     ....

Math exception - I would gladly lose the exception handling
for faster code if I can turn it back on with appropriate debugging flags.

>   Robert Krawitz <rlk@tiac.net>	       http://www.tiac.net/users/rlk/

-- yotam

^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: wish: optimize  (x > 0.) floating point comparison.
@ 1998-09-26 15:59 N8TM
  0 siblings, 0 replies; 20+ messages in thread
From: N8TM @ 1998-09-26 15:59 UTC (permalink / raw)
  To: root, rth; +Cc: egcs

In a message dated 9/26/98 2:43:31 PM Pacific Daylight Time, root@ihack.net
writes:

> > Incorrect.  Motorola uses a 96-bit format with different precision.
>  
>  Don't let the 96-bit length fool you.  It's really the same format,
>  but with 16 bits wasted (for alignment purposes, I assume).
>  
Thanks for the confirmation.  Intel, of course, lets you pack the 80-bit
quantities in memory, or use 128 bits, with 48 bits wasted (unless you have a
special use for them), for better performance alignment.

^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: wish: optimize  (x > 0.) floating point comparison.
@ 1998-09-26 15:59 Charles M. Hannum
  1998-09-28  3:19 ` Andreas Schwab
  0 siblings, 1 reply; 20+ messages in thread
From: Charles M. Hannum @ 1998-09-26 15:59 UTC (permalink / raw)
  To: Richard Henderson; +Cc: egcs

> On Sat, Sep 26, 1998 at 10:03:54AM -0400, Charles M. Hannum wrote:
> > Don't let the 96-bit length fool you.  It's really the same format,
> > but with 16 bits wasted (for alignment purposes, I assume).
> 
> No it isn't the same, as the representable precision is different.
> For example, LDBL_MIN:
> 
>         i386    3.36210314311209350626e-4932
>         m68k    1.68105157155604675313e-4932

I hate to drag this out, but unfortunately your include files are
wrong.

Unlike the single- and double-precision formats, the
extended-precision format includes the leading 1 digit explicitly in
the mantissa.  This is the same on both i386 and m68k.

See section 1.5.2 of the `M68000 Family Programmer's Reference
Manual'.


^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: wish: optimize  (x > 0.) floating point comparison.
@ 1998-09-26  7:00 Charles M. Hannum
  1998-09-26 10:41 ` Richard Henderson
  0 siblings, 1 reply; 20+ messages in thread
From: Charles M. Hannum @ 1998-09-26  7:00 UTC (permalink / raw)
  To: Richard Henderson; +Cc: egcs

> On Sat, Sep 26, 1998 at 01:32:18AM -0400, N8TM@aol.com wrote:
> > The same standard (extended double precision) was adopted by Motorola 6888[12]
> > and Intel.  
> 
> Incorrect.  Motorola uses a 96-bit format with different precision.

Don't let the 96-bit length fool you.  It's really the same format,
but with 16 bits wasted (for alignment purposes, I assume).


^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: wish: optimize  (x > 0.) floating point comparison.
@ 1998-09-26  0:52 N8TM
  1998-09-26  0:52 ` Richard Henderson
  0 siblings, 1 reply; 20+ messages in thread
From: N8TM @ 1998-09-26  0:52 UTC (permalink / raw)
  To: rth, branko.cibej; +Cc: rlk, yotam_medini, egcs

In a message dated 9/25/98 7:56:20 AM Pacific Daylight Time, rth@cygnus.com
writes:

> the 80-bit float format used is
>  > an IEEE standard, as far as I know.
>  
>  Well, if you consider a standard used by exactly one machine "standard"...
>
The same standard (extended double precision) was adopted by Motorola 6888[12]
and Intel.  
  
>  > And what's wrong with having 80-bit
>  > long doubles instead of 128-bit ones?
>  
>  No, what's wrong is that it is impossible to get intermediate results
>  properly rounded without sacrificing all performance.
The 80-bit intermediate precision is sufficient in a number of documented
cases to protect the accuracy of the final standard double precision result.
My results using CELEFUNT, for example, bear this out.   Using 128-bit
intermediate results will achieve this with a far greater loss of performance.
The rounding mode switch has been provided to enable 53-bit rounding mode, in
case that is desired, with a significant increase in speed of division and
sqrt().   It's true that changing the rounding mode consumes quit a bit of
time, but in practice that's more of a problem for integer truncation and for
Fortran ANINT() and NINT(), where the Fortran and IEEE standards are at odds.

How did we stray so far from the original topic of this thread?


^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: wish: optimize  (x > 0.) floating point comparison.
@ 1998-09-23 20:50 N8TM
  0 siblings, 0 replies; 20+ messages in thread
From: N8TM @ 1998-09-23 20:50 UTC (permalink / raw)
  To: yotam_medini, rlk; +Cc: egcs

In a message dated 9/23/98 2:37:10 PM Pacific Daylight Time,
yotam@avanticorp.com writes:

> I wonder if there are primitive FPU compare instructions with (+/- 0.0)
>  with a single operand. 
There have been architectures which kept the positive and zero condition flags
automatically set in accordance with the last changed floating point register,
but this doesn't seem to be too useful now that most CPU's have multiple
register pipelined operations and out-of-order execution.  Architectures which
keep a "register" which always shows as containing zero provide the ability to
compare with zero without having to find a zero variable datum.

^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: wish: optimize  (x > 0.) floating point comparison.
@ 1998-09-23  9:38 Yotam Medini
  1998-09-23 21:30 ` Richard Henderson
  0 siblings, 1 reply; 20+ messages in thread
From: Yotam Medini @ 1998-09-23  9:38 UTC (permalink / raw)
  To: rlk; +Cc: egcs

Now that I realized how much I lack knowledge of FPU issues,
I wonder if there are primitive FPU compare instructions with (+/- 0.0)
with a single operand. 

-- yotam


^ permalink raw reply	[flat|nested] 20+ messages in thread
* wish: optimize  (x > 0.) floating point comparison.
@ 1998-09-22  9:00 Yotam Medini
  1998-09-22 14:32 ` Robert L Krawitz
  0 siblings, 1 reply; 20+ messages in thread
From: Yotam Medini @ 1998-09-22  9:00 UTC (permalink / raw)
  To: egcs

My assembly-code reading skill is very poor.
Still, given:
    double x;
and viewing the code generated (gcc -S -O?) I think the following
two logical expressions
       (x >= 0.)
       (x >= 13.)
result with the same computational complexity.

I believe that floating-point comparisons (<, >, <=, >=) with 0.0 is
very frequent and worth the trouble of optimizing using the sign bit
within the (platform dependent) floating-point representation or some
other machine instruction.

Hope this idea could help. -- yotam


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~1998-09-28  3:19 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-09-22 19:31 wish: optimize (x > 0.) floating point comparison Yotam Medini
1998-09-22 16:05 ` Robert L Krawitz
1998-09-23 21:30   ` Richard Henderson
1998-09-24 10:37     ` Joe Buck
1998-09-25  2:09     ` Branko Cibej
1998-09-25  2:09       ` Richard Henderson
1998-09-22 19:59 ` Robert L Krawitz
  -- strict thread matches above, loose matches on Subject: below --
1998-09-26 15:59 N8TM
1998-09-26 15:59 Charles M. Hannum
1998-09-28  3:19 ` Andreas Schwab
1998-09-26  7:00 Charles M. Hannum
1998-09-26 10:41 ` Richard Henderson
1998-09-26  0:52 N8TM
1998-09-26  0:52 ` Richard Henderson
1998-09-28  3:19   ` Andreas Schwab
1998-09-23 20:50 N8TM
1998-09-23  9:38 Yotam Medini
1998-09-23 21:30 ` Richard Henderson
1998-09-22  9:00 Yotam Medini
1998-09-22 14:32 ` Robert L Krawitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).