Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* Floating point problems
@ 1998-11-28 13:15 Heinz Ulrich Stille
  1998-11-28 14:24 ` Johannes G.D. Hausmann
  0 siblings, 1 reply; 24+ messages in thread
From: Heinz Ulrich Stille @ 1998-11-28 13:15 UTC (permalink / raw)
  To: axp-list

Hi!

What's wrong with the following program?

main() {
	double x = 1.0;
	x *= 1e-310;
}

This results in a floating point exception on my Ruffian (for values
somwhere between 1e-300 and 1e-325, independent of kernel and compiler),
but not on any intel. The assembler output seems to indicate that the
two values are just loaded into registers and multiplied.
What is going on?

MfG, Ulrich

--
"If you were a boy I'd say are you going to seek your fortune?" "Can't girls
seek their fortune?" "I think they're supposed to seek a boy with a fortune."
                                               T. Pratchett, "Equal Rites"


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

* Re: Floating point problems
  1998-11-28 14:24 ` Johannes G.D. Hausmann
@ 1998-11-28 13:58   ` Heinz Ulrich Stille
  1998-11-28 14:48     ` Stefan Schroepfer
  0 siblings, 1 reply; 24+ messages in thread
From: Heinz Ulrich Stille @ 1998-11-28 13:58 UTC (permalink / raw)
  To: axp-list

Hi!

On Sat, 28 Nov 1998, Johannes G.D. Hausmann wrote:
>> main() {
>>         double x = 1.0;
>>         x *= 1e-310;
>> }
>> 
>
>This is a denormal. From float.h:
>
>   /* Minimum normalised double */
>#undef DBL_MIN
>#define DBL_MIN 2.2250738585072014e-308

This does not seem to be the problem: I get the same results with
	double a = 1.0, b = 1e-310, c = a * b; printf("%lg\n", c):
This gives `1e-310' on intel, but an error on alpha.
OTOH, might it be related to storing the value? I get the same error
with { double a = 1e-310; float b = a; }, instead of zero like on
intel, but I get no error when I switch the values around in the
first example (didn't check wheter the compiler is cheating and
am away from my alpha at the moment).

MfG, Ulrich

--
"Never trust any ruler who puts his faith in tunnels and bunkers and escape
routes. The chances are that his heart isn't in the job."
                                           T. Pratchett, "Guards! Guards!"


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

* Re: Floating point problems
  1998-11-28 13:15 Heinz Ulrich Stille
@ 1998-11-28 14:24 ` Johannes G.D. Hausmann
  1998-11-28 13:58   ` Heinz Ulrich Stille
  0 siblings, 1 reply; 24+ messages in thread
From: Johannes G.D. Hausmann @ 1998-11-28 14:24 UTC (permalink / raw)
  To: axp-list

> What's wrong with the following program?
> 
> main() {
>         double x = 1.0;
>         x *= 1e-310;
> }
> 

This is a denormal. From float.h:

   /* Minimum normalised double */
#undef DBL_MIN
#define DBL_MIN 2.2250738585072014e-308

cu,

Jo
-- 
-----------------------------------------
Johannes Hausmann
Carl von Ossietzky Universitaet Oldenburg
FB Physik -- AG Komplexe Systeme

EMail : joe@neuro.uni-oldenburg.de
-----------------------------------------


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

* Re: Floating point problems
  1998-11-28 13:58   ` Heinz Ulrich Stille
@ 1998-11-28 14:48     ` Stefan Schroepfer
  1998-11-28 14:57       ` Heinz Ulrich Stille
  0 siblings, 1 reply; 24+ messages in thread
From: Stefan Schroepfer @ 1998-11-28 14:48 UTC (permalink / raw)
  To: axp-list

Heinz Ulrich Stille wrote:
> 
> On Sat, 28 Nov 1998, Johannes G.D. Hausmann wrote:
> > 
> >This is a denormal.
> 
> This does not seem to be the problem: [...]

But all your code examples work (at least with gcc 2.7.2.1)
if compiled with `-mieee'. Also be aware that `%lg' is not
ANSI compiant (`%g' is for doubles, `%Lg' is for long doubles,
which are not available in generic form on Alphas).

scr


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

* Re: Floating point problems
  1998-11-28 14:48     ` Stefan Schroepfer
@ 1998-11-28 14:57       ` Heinz Ulrich Stille
  1998-11-29 13:15         ` Johannes G.D. Hausmann
  0 siblings, 1 reply; 24+ messages in thread
From: Heinz Ulrich Stille @ 1998-11-28 14:57 UTC (permalink / raw)
  To: axp-list

Hi!

On Sat, 28 Nov 1998, Stefan Schroepfer wrote:

>But all your code examples work (at least with gcc 2.7.2.1)
>if compiled with `-mieee'. Also be aware that `%lg' is not

Thanks, that should do it (I'll test it as soon as I get home).
I did remember that there was something about `ieee', but not
where it did belong.

>ANSI compiant (`%g' is for doubles, `%Lg' is for long doubles,
>which are not available in generic form on Alphas).

I know, but gcc is rather lenient and does what I want anyway.

MfG, Ulrich

--
But mysterious caves and tunnels always have luminous fungi, strangely
bright crystals or at a pinch merely an eldritch glow in the air, just in
case a human hero comes in and needs to see in the dark. Strange but true.
                                               T. Pratchett, "Men at Arms"


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

* Re: Floating point problems
  1998-11-29 13:15         ` Johannes G.D. Hausmann
@ 1998-11-29 13:02           ` Heinz Ulrich Stille
  1998-11-29 18:01           ` B. James Phillippe
  1 sibling, 0 replies; 24+ messages in thread
From: Heinz Ulrich Stille @ 1998-11-29 13:02 UTC (permalink / raw)
  To: axp-list

Hi!

On Sun, 29 Nov 1998, Johannes G.D. Hausmann wrote:
> But using -miee may lead to slower code, at least that's what I
> understood from several discussions about it on this list. So you

Well, yes, speed is important, but I prefer a program that works to
one that crashes very fast :-)

> Why do you want to use this number anyway?

*I* don't, but povray does. In calculating lighting there appear
large powers of values near 1.0, sometimes with such results.
Treating them as zero would suffice, but I see no way to do so without
sacrificing still more speed.

Is there an alpha-optimized version of povray?

MfG, Ulrich

---

It is well known that a vital ingredient of success is not knowing that
what you're attempting can't be done. A person ignorant of the possibility
of failure can be a halfbrick in the path of the bicycle of history.
                                               T. Pratchett, "Equal Rites"


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

* Re: Floating point problems
  1998-11-28 14:57       ` Heinz Ulrich Stille
@ 1998-11-29 13:15         ` Johannes G.D. Hausmann
  1998-11-29 13:02           ` Heinz Ulrich Stille
  1998-11-29 18:01           ` B. James Phillippe
  0 siblings, 2 replies; 24+ messages in thread
From: Johannes G.D. Hausmann @ 1998-11-29 13:15 UTC (permalink / raw)
  To: axp-list

Hi again,

> >But all your code examples work (at least with gcc 2.7.2.1)
> >if compiled with `-mieee'. Also be aware that `%lg' is not
> 
> Thanks, that should do it (I'll test it as soon as I get home).
> I did remember that there was something about `ieee', but not
> where it did belong.
> 

But using -miee may lead to slower code, at least that's what I
understood from several discussions about it on this list. So you
probably do not want to do it this way. As I said, 1.0e-310 is a
denormal, it is not zero, and further references to it lead to FPEs.
It's these things that give me headaches - C. Whaley found one
uninitialized array in the superscalar gemm-based BLAS that happened
to hold several of these denormals => FPEs. Using -mieee (instead of
proper init) solves the problem, too, but the cost is too high.

Why do you want to use this number anyway?

Jo
-- 
-----------------------------------------
Johannes Hausmann
Carl von Ossietzky Universitaet Oldenburg
FB Physik -- AG Komplexe Systeme

EMail : joe@neuro.uni-oldenburg.de
-----------------------------------------


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

* Re: Floating point problems
  1998-11-29 13:15         ` Johannes G.D. Hausmann
  1998-11-29 13:02           ` Heinz Ulrich Stille
@ 1998-11-29 18:01           ` B. James Phillippe
  1 sibling, 0 replies; 24+ messages in thread
From: B. James Phillippe @ 1998-11-29 18:01 UTC (permalink / raw)
  To: axp-list

On Sun, 29 Nov 1998, Johannes G.D. Hausmann wrote:

> As I said, 1.0e-310 is a denormal, it is not zero, and further references
> to it lead to FPEs.  It's these things that give me headaches - C. Whaley
> found one uninitialized array in the superscalar gemm-based BLAS that
> happened to hold several of these denormals => FPEs. Using -mieee

Funny you mention that.  The BYTEmark tool I used to get benchmarks for
some different Linux architectures** had the same problem; FPE on Alpha due
to uninitialized array accesses.  I wonder what causes it....

**available from the URL in the signature.

cheers,
-bp
--
B. James Phillippe	. bryan@terran.org
Linux Engineer/Admin	. http://www.terran.org/~bryan
Member since 1.1.59	. finger:bryan@earth.terran.org


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

* Re: Floating point problems
@ 1998-11-30  8:16 y0000218
  1998-11-30  9:08 ` Carles Perello
                   ` (3 more replies)
  0 siblings, 4 replies; 24+ messages in thread
From: y0000218 @ 1998-11-30  8:16 UTC (permalink / raw)


Heinz Ulrich Stille <Heinz.Ulrich.Stille@mbi-os.de> wrote:
: Hi!

: What's wrong with the following program?

: main() {
: 	double x = 1.0;
: 	x *= 1e-310;
: }

: This results in a floating point exception on my Ruffian (for values
: somwhere between 1e-300 and 1e-325, independent of kernel and compiler),
: but not on any intel. The assembler output seems to indicate that the
: two values are just loaded into registers and multiplied.
: What is going on?


This looks _very_ familiar - I had the same problem, same range of numbers.

It still reproducibly FP-exeptions on a RH 5.2 system here.

I think its weird, and noone could plausibly tell me why yet.

-mieee works, also fixing my code so it doesnt produce such
small numbers did it.

Could any guru tell me _why_ this code crashes?

Just doing anything with a number around 1e-310 raises an FP exception,
smaller _and_ larger numbers dont.

Olaf

-- 
"The number of Unix installations       Olaf Schnapauff,
has grown to 10, with more expected."   O.Schnapauff@tu-bs.de  
- The Unix Programmer's Manual,1972     http://www.tu-bs.de/~c0033014/
       See Web page and keyservers  for pgp public key


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

* Re: Floating point problems
  1998-11-30  8:16 Floating point problems y0000218
@ 1998-11-30  9:08 ` Carles Perello
  1998-11-30  9:53 ` Joachim Wesner
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 24+ messages in thread
From: Carles Perello @ 1998-11-30  9:08 UTC (permalink / raw)
  To: axp-list


On Mon, 30 Nov 1998 y0000218@rzsrv2.rz.tu-bs.de wrote:

> Heinz Ulrich Stille <Heinz.Ulrich.Stille@mbi-os.de> wrote:
> 
> : main() {
> : 	double x = 1.0;
> : 	x *= 1e-310;
> : }
> 
> : This results in a floating point exception on my Ruffian (for values
> : somwhere between 1e-300 and 1e-325, independent of kernel and compiler),

> Just doing anything with a number around 1e-310 raises an FP exception,
> smaller _and_ larger numbers dont.

Same report here. I am trying to port an assembler for Motorola 56K DSP
to alpha (working in intel and ppc) anf rises the same FP exception with
similar values.

I thought it was a porting problem though...

cheerio

carles


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

* Re: Floating point problems
  1998-11-30  8:16 Floating point problems y0000218
  1998-11-30  9:08 ` Carles Perello
@ 1998-11-30  9:53 ` Joachim Wesner
  1998-11-30 14:22   ` Alvin Starr
  1998-11-30 17:06 ` Joachim Wesner
  1998-12-01  8:42 ` Jochen Kuepper
  3 siblings, 1 reply; 24+ messages in thread
From: Joachim Wesner @ 1998-11-30  9:53 UTC (permalink / raw)
  To: axp-list

y0000218@rzsrv2.rz.tu-bs.de wrote:
> 
> Heinz Ulrich Stille <Heinz.Ulrich.Stille@mbi-os.de> wrote:
> : Hi!
> 
> : What's wrong with the following program?
> 
> : main() {
> :       double x = 1.0;
> :       x *= 1e-310;
> : }
> 
> : This results in a floating point exception on my Ruffian (for values
> : somwhere between 1e-300 and 1e-325, independent of kernel and compiler),
> : but not on any intel. The assembler output seems to indicate that the
> : two values are just loaded into registers and multiplied.
> : What is going on?
> 
> This looks _very_ familiar - I had the same problem, same range of numbers.
> 
> It still reproducibly FP-exeptions on a RH 5.2 system here.
> 
> I think its weird, and noone could plausibly tell me why yet.
> 
> -mieee works, also fixing my code so it doesnt produce such
> small numbers did it.
> 
> Could any guru tell me _why_ this code crashes?
> 
> Just doing anything with a number around 1e-310 raises an FP exception,
> smaller _and_ larger numbers dont.


Numbers smaller around 1e-308 but larger 1e-324 are denormalized
numbers. Even smaller ones cannot be expressed in double precision and
will be replaced by zero already by the compiler in the constant used in
the above code.

Unfortunatelly, and this is one of the biggest flaws of the Alpha
architecture IMHO, the Alpha cannot handle denormalized numbers without
trapping and software support. I can't understand why DEC made that
choice, as it causes so many problems in much code. Clearly, FULL
denormalized handling maybe somewhat complicated, BUT a hardware option
that silently replaces/treats any denormal by/like zero would sure have
costed very few transistors and would have helped critical code alot, if
you really need the full precision, you could still activate the
trapping and use -mieee.

Joachim


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

* Re: Floating point problems
@ 1998-11-30 10:24 y0000218
  1998-11-30 13:30 ` Alvin Starr
  0 siblings, 1 reply; 24+ messages in thread
From: y0000218 @ 1998-11-30 10:24 UTC (permalink / raw)


Joachim Wesner <joachim.wesner@frankfurt.netsurf.de> wrote:
: denormalized handling maybe somewhat complicated, BUT a hardware option
: that silently replaces/treats any denormal by/like zero would sure have
: costed very few transistors and would have helped critical code alot, if
: you really need the full precision, you could still activate the
: trapping and use -mieee.

: Joachim

Hmm, so whats the "right" way to do this if I dont need the
full precision? (RayTracing doesnt really, whats not visible isnt important).
Currently I do check for "smaller than <some constant>" in critical places
and set things to 0. Nasty. But -mieee seems worse performance-wise.
The worst thing is that I _think_ I check in critical places
and things _usually_ work but i can guarantee it.

Olaf


-- 
"The number of Unix installations       Olaf Schnapauff,
has grown to 10, with more expected."   O.Schnapauff@tu-bs.de  
- The Unix Programmer's Manual,1972     http://www.tu-bs.de/~c0033014/
       See Web page and keyservers  for pgp public key


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

* Re: Floating point problems
  1998-11-30 14:22   ` Alvin Starr
@ 1998-11-30 13:27     ` krebs
  0 siblings, 0 replies; 24+ messages in thread
From: krebs @ 1998-11-30 13:27 UTC (permalink / raw)
  To: axp-list

> 
> try the following 
>  main() {
>        double x = 1.0;
>        double y = 1e-155;
> 
>        x *=(1e-155*y);
>        printf("%e %e %e\n",(1e-155*y),x,1e-310);
>  }

compiling under digital unix (cc no options) generates:
cc: Warning: fp2.c, line 6: In this statement, underflow occurs in evaluating the expression "1.e-310".
       printf("%e %e %e\n",(1e-155*y),x,1e-310);
----------------------------------------^

the output is:
0.000000e+00 0.000000e+00 0.000000e+00

compiled with cc -fptm u generates the output:
Floating point exception (core dumped)

here is what man cc, has to say about -fptm:
  -fptm n
      Generates instructions that do not trigger floating-point underflow or
      inexact trapping modes.  Any floating point overflow, divide-by-zero,
      or invalid operation will unconditionally generate a trap.  -fptm n is
      the default.

  -fptm u
      Generates traps on floating-point underflow as well as overflow,
      divide-by-zero, and invalid operation.

so you don't need -ieee to fix this under digital unix.

-- 
_____________________________________________________________________________

                               Andreas S. Krebs

  Email mailto:krebs@kar.dec.com
_____________________________________________________________________________


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

* Re: Floating point problems
  1998-11-30 10:24 y0000218
@ 1998-11-30 13:30 ` Alvin Starr
  1998-12-03  0:48   ` Richard Henderson
  0 siblings, 1 reply; 24+ messages in thread
From: Alvin Starr @ 1998-11-30 13:30 UTC (permalink / raw)
  To: axp-list


This may sound like a stupid question but. How does DEC handle this 
problem in Digital Unix?. Could not the same scheme be used in linux.

Alvin Starr                   ||   voice: (416)585-9971
Interlink Connectivity        ||   fax:   (416)585-9974
alvin@iplink.net              ||


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

* Re: Floating point problems
  1998-11-30  9:53 ` Joachim Wesner
@ 1998-11-30 14:22   ` Alvin Starr
  1998-11-30 13:27     ` krebs
  0 siblings, 1 reply; 24+ messages in thread
From: Alvin Starr @ 1998-11-30 14:22 UTC (permalink / raw)
  To: axp-list


try the following 
 main() {
       double x = 1.0;
       double y = 1e-155;

       x *=(1e-155*y);
       printf("%e %e %e\n",(1e-155*y),x,1e-310);
 }

this generates the same result as the original program but will not cause a 
trap.


Alvin Starr                   ||   voice: (416)585-9971
Interlink Connectivity        ||   fax:   (416)585-9974
alvin@iplink.net              ||


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

* Re: Floating point problems
  1998-11-30  8:16 Floating point problems y0000218
  1998-11-30  9:08 ` Carles Perello
  1998-11-30  9:53 ` Joachim Wesner
@ 1998-11-30 17:06 ` Joachim Wesner
  1998-12-03  0:48   ` Richard Henderson
  1998-12-01  8:42 ` Jochen Kuepper
  3 siblings, 1 reply; 24+ messages in thread
From: Joachim Wesner @ 1998-11-30 17:06 UTC (permalink / raw)
  To: axp-list

y0000218@rzsrv2.rz.tu-bs.de wrote:
> 
> Heinz Ulrich Stille <Heinz.Ulrich.Stille@mbi-os.de> wrote:
> : Hi!
> 
> : What's wrong with the following program?
> 
> : main() {
> :       double x = 1.0;
> :       x *= 1e-310;
> : }
> 
> : This results in a floating point exception on my Ruffian (for values
> : somwhere between 1e-300 and 1e-325, independent of kernel and compiler),
> : but not on any intel. The assembler output seems to indicate that the
> : two values are just loaded into registers and multiplied.
> : What is going on?
> 

and Alvin Starr wrote:

>try the following 
> main() {
>       double x = 1.0;
>       double y = 1e-155;
>       x *=(1e-155*y);
>       printf("%e %e %e\n",(1e-155*y),x,1e-310);
> }
>
>this generates the same result as the original program but will not >cause a trap.

This starts to look confusing........

However, I studied the Alpha Architecture Handbook again and - hopefully
- begin to understand what is happening und a way to find the real cause
of this and a way out

We have to distinguish 2 cases here:

1) Denormals as OPERANDS to a fp op

2) Denormals as RESULT of an fp op

to 1)

The Alpha hardware definitely cannot handle denormals as input to fp
ops. This has to be fixed in software, by the trap handler AND for this
to REALLY work in REAL code, due to the (damned !!) imprecise trap
handling will require extensive use of trapb instructions, that
basically serialize the fpu and make a scalar machine out of a pipelined
one, basically what -mieee does, it slows down the code a lot.
Basically, the idea of the dec engineers was that in critical code you
might be able to identify the few ops that are really critical and put a
trapb only here, but it seems that neither gcc/egcs or even the DEC cc
is smart enough to do this efiiciently, instead, you have to clutter
your code with those instructions.

to 2)

Here the DEC documentation is a bit misleading, it seems I was wrong !
The fp ops have an additional qualifier /U that determines the underflow
behavior. HOWEVER, at a first look (what I had done till now,, it seems,
sorry), you only have two possibilities

- either you do not use /U, then the documentation says any fp op will
trap with all the above problems when a denormal is a result of the op

- or you use /U, then no trap will happen, but also, the denormal will
not be replaced by a true zero and the code will trap via 1) the next
time the result is used in further calculations.

HOWEVER, reading on reveals a bit more, 1st, there is an additional
underflow trap disable bit in the fp control register, and 2nd, when the
trap happens, the setting by zero that I missed, will already happen by
the hardware !!! Huh, why not with /U but instead vice-versa ???

This seems, that the way to go would be "enable" the underflow trap
(with replacing by zero) by NOT using /u (as is usually already done),
but later again DISABLE that very same trap in the fp control register.
Yet, and it seems, LINUX AXP is already configured to do just this !!

This would explain the two codes :

In the code with 1e-310, which already IS a denormal 1) applies and you
get a trap and as long you did not compile the stuff with trapb
instructions, even a probably better trap handler could not fix it.
BTW, the very same should happen also on DEC Unix, when reading 1e-310
from a binary file or if you code it as a hex number (Somebody could try
that ?). DEC CC seems to try to avoid such by never allowing you to
input such numbers in a regular way, what explains the warning in the
DEC output and that it did not print 1e-310 as last result.

In the code with 1e-155**2 instead, all things seems to go as they
should, 2) applies.

BUT, so why do still many people see so many problems with denormals
under AXP Linux ?? When you never input a denormal and all fp op never
return a denormal, NO problems should happen !!

I have the impression that might be the function routines that are not
written to NOT return denormals, for example exp of a large negative
number could return a denormal. This should be changed.

Incidentially - <Advertisement on> the new version of libffm 0.28 is out
that now fully handles illegal arguments and results. It should never
return a denormal (ONLY in the linear regions for small args of sin,
tan, asin, atan, where the arg is simply returned as is, but then you
already HAD the problem earlier on) and anybody with the above problems
should give it a try if it fixes the probs. As is does not yet contain
ALL libm functions, it still could happen, in such case could somebody
try to trace which function would be missing to be fixed/replaced first.

Actually, I HAD been wondering when designing libffm, if exp needs to
return a denormal for very small arguments, and now I see, it was a good
decision (to be lazy and) not to add that !! <Advertisement OFF>

Hope this turns out to be right and helps !!

If you still find a code that does not seem to fit to the above
explanation, please send it to me.


Joachim


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

* Re: Floating point problems
  1998-11-30  8:16 Floating point problems y0000218
                   ` (2 preceding siblings ...)
  1998-11-30 17:06 ` Joachim Wesner
@ 1998-12-01  8:42 ` Jochen Kuepper
  3 siblings, 0 replies; 24+ messages in thread
From: Jochen Kuepper @ 1998-12-01  8:42 UTC (permalink / raw)
  To: axp-list, y0000218

On Mon, 30 Nov 1998 y0000218@rzsrv2.rz.tu-bs.de wrote:

> Just doing anything with a number around 1e-310 raises an FP exception,
> smaller _and_ larger numbers dont.

I guess this is because these numbers are represented as denormals, and the
Alpha chip cannot deal any operations on these in hardware :-?

Greetings,
Jochen
-----------------------------------------------------------------------
  Jochen K"upper

  Heinrich-Heine-Universit"at D"usseldorf   jochen@uni-duesseldorf.de
  Institut f"ur Physikalische Chemie I
  Universit"atsstr. 1, Geb 26.43 Raum 02.29    phone ++49-211-8113681
  40225 D"usseldorf                            fax   ++49-211-8115195
  Germany             http://www-public.rz.uni-duesseldorf.de/~jochen
-----------------------------------------------------------------------


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

* Re: Floating point problems
  1998-11-30 17:06 ` Joachim Wesner
@ 1998-12-03  0:48   ` Richard Henderson
  1998-12-03 16:59     ` Greg Lindahl
  0 siblings, 1 reply; 24+ messages in thread
From: Richard Henderson @ 1998-12-03  0:48 UTC (permalink / raw)
  To: axp-list

On Mon, Nov 30, 1998 at 06:06:33PM +0100, Joachim Wesner wrote:
> Here the DEC documentation is a bit misleading, it seems I was wrong !
> The fp ops have an additional qualifier /U that determines the underflow
> behavior. HOWEVER, at a first look (what I had done till now,, it seems,
> sorry), you only have two possibilities
> 
> - either you do not use /U, then the documentation says any fp op will
> trap with all the above problems when a denormal is a result of the op
> 
> - or you use /U, then no trap will happen, but also, the denormal will
> not be replaced by a true zero and the code will trap via 1) the next
> time the result is used in further calculations.

You are misreading.  The /u qualifier _enables_ underflow detection
for the instruction.  To quote:

  If an underflow occurs, a true zero is always stored in the result
  register, even if the proper IEEE result would have been -0.

  If an underflow occurs and underflow traps are enabled by the 
  instruction, an underflow arithmetic trap is signaled.

So if you don't use /u, you'll never get underflow traps.

> I have the impression that might be the function routines that are not
> written to NOT return denormals, for example exp of a large negative
> number could return a denormal. This should be changed.

Possibly. 

OTOH, I would think only if we can determine that the caller
is not prepared for such a value.  I do not know how best to 
do this though.


r~


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

* Re: Floating point problems
  1998-11-30 13:30 ` Alvin Starr
@ 1998-12-03  0:48   ` Richard Henderson
  0 siblings, 0 replies; 24+ messages in thread
From: Richard Henderson @ 1998-12-03  0:48 UTC (permalink / raw)
  To: axp-list

On Mon, Nov 30, 1998 at 08:30:41AM -0500, Alvin Starr wrote:
> This may sound like a stupid question but. How does DEC handle this 
> problem in Digital Unix?

The _exact_ same way we do on Linux.


r~


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

* Re: Floating point problems
  1998-12-03  0:48   ` Richard Henderson
@ 1998-12-03 16:59     ` Greg Lindahl
  1998-12-03 19:35       ` Joachim Wesner
  1998-12-03 20:04       ` Richard Henderson
  0 siblings, 2 replies; 24+ messages in thread
From: Greg Lindahl @ 1998-12-03 16:59 UTC (permalink / raw)
  To: rth; +Cc: axp-list

> > I have the impression that might be the function routines that are not
> > written to NOT return denormals, for example exp of a large negative
> > number could return a denormal. This should be changed.
> 
> Possibly. 
> 
> OTOH, I would think only if we can determine that the caller
> is not prepared for such a value.  I do not know how best to 
> do this though.

If the compiler would make a symbol available based on the -mieee flag,
i.e. #define __mieee 0 or 1, then the include files for the math
library could pick routines which do or don't generate denorms.

#if defined(__mieee)
#define sqrt sqrt
#else
#define sqrt sqrt_no_denorms
#fi

-- g


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

* Re: Floating point problems
  1998-12-03 16:59     ` Greg Lindahl
@ 1998-12-03 19:35       ` Joachim Wesner
  1998-12-03 20:04       ` Richard Henderson
  1 sibling, 0 replies; 24+ messages in thread
From: Joachim Wesner @ 1998-12-03 19:35 UTC (permalink / raw)
  To: axp-list

Greg Lindahl wrote:
> 
> > > I have the impression that might be the function routines that are not
> > > written to NOT return denormals, for example exp of a large negative
> > > number could return a denormal. This should be changed.
> >
> > Possibly.
> >
> > OTOH, I would think only if we can determine that the caller
> > is not prepared for such a value.  I do not know how best to
> > do this though.
> 
> If the compiler would make a symbol available based on the -mieee flag,
> i.e. #define __mieee 0 or 1, then the include files for the math
> library could pick routines which do or don't generate denorms.
> 
> #if defined(__mieee)
> #define sqrt sqrt
> #else
> #define sqrt sqrt_no_denorms
> #fi

YEP, sorry I did not follow this for some time. This is about what I was
finally thinking, too. We would at least need 2 different libms. The
current lib(d)m has even more problems on it's own. Instead of returning
+/-Inf as a (hex) value, for example, it's written that way that
+/-1./0. is executed, relying on the trap handling to clean it up,
clearly not good for non -mieee programs. Hopefully later versions of
libffm can replace that.

BTW, do you know how "mother" DEC handles this ?? Are **there**
different libm's used for different compiler switches (-mieee and -fptm
n/u) ?? Or how do they resolve that ??


Joachim


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

* Re: Floating point problems
  1998-12-03 16:59     ` Greg Lindahl
  1998-12-03 19:35       ` Joachim Wesner
@ 1998-12-03 20:04       ` Richard Henderson
  1998-12-03 20:16         ` Greg Lindahl
  1998-12-03 23:44         ` Joachim Wesner
  1 sibling, 2 replies; 24+ messages in thread
From: Richard Henderson @ 1998-12-03 20:04 UTC (permalink / raw)
  To: Greg Lindahl, rth; +Cc: axp-list

On Thu, Dec 03, 1998 at 11:59:08AM -0500, Greg Lindahl wrote:
> If the compiler would make a symbol available based on the -mieee flag,
> i.e. #define __mieee 0 or 1, then the include files for the math
> library could pick routines which do or don't generate denorms.

Actually this is a good idea.  And the compiler already defines
-D_IEEE_FP.  And the define can even be replaced by

   extern double sqrt (double) __asm__("_sqrt_no_denorm");

which works out better on the whole.

The question, then, is what to do with the other problematic
return values, Inf and NaN?  Should Inf be replaced by the 
largest finite value?


r~


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

* Re: Floating point problems
  1998-12-03 20:04       ` Richard Henderson
@ 1998-12-03 20:16         ` Greg Lindahl
  1998-12-03 23:44         ` Joachim Wesner
  1 sibling, 0 replies; 24+ messages in thread
From: Greg Lindahl @ 1998-12-03 20:16 UTC (permalink / raw)
  To: rth; +Cc: axp-list

> Actually this is a good idea.  And the compiler already defines
> -D_IEEE_FP.  And the define can even be replaced by
> 
>    extern double sqrt (double) __asm__("_sqrt_no_denorm");

Yes, that's all clean. We just have to incite the library writers to
produce the *_no_denorm routines.

> The question, then, is what to do with the other problematic
> return values, Inf and NaN?  Should Inf be replaced by the 
> largest finite value?

No. The object here is to allow code to run fast while changing its
semantics as little as possible. Messing with Inf and NaN would not
really help anyone.

There are users who would like their code to crash whenever Inf or NaN
is produced; we should document how to do that.

-- g


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

* Re: Floating point problems
  1998-12-03 20:04       ` Richard Henderson
  1998-12-03 20:16         ` Greg Lindahl
@ 1998-12-03 23:44         ` Joachim Wesner
  1 sibling, 0 replies; 24+ messages in thread
From: Joachim Wesner @ 1998-12-03 23:44 UTC (permalink / raw)
  To: axp-list

Richard Henderson wrote:
>
> The question, then, is what to do with the other problematic
> return values, Inf and NaN?  Should Inf be replaced by the
> largest finite value?
> 

IMHO, clearly not. Instead of Denormals, for NaN and Infs, there is
no meaningful replacement value, any program where those appear should
be considered in error and it should trap - as it does already now -
when those occur.

 Joachim


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

end of thread, other threads:[~1998-12-03 23:49 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-11-30  8:16 Floating point problems y0000218
1998-11-30  9:08 ` Carles Perello
1998-11-30  9:53 ` Joachim Wesner
1998-11-30 14:22   ` Alvin Starr
1998-11-30 13:27     ` krebs
1998-11-30 17:06 ` Joachim Wesner
1998-12-03  0:48   ` Richard Henderson
1998-12-03 16:59     ` Greg Lindahl
1998-12-03 19:35       ` Joachim Wesner
1998-12-03 20:04       ` Richard Henderson
1998-12-03 20:16         ` Greg Lindahl
1998-12-03 23:44         ` Joachim Wesner
1998-12-01  8:42 ` Jochen Kuepper
  -- strict thread matches above, loose matches on Subject: below --
1998-11-30 10:24 y0000218
1998-11-30 13:30 ` Alvin Starr
1998-12-03  0:48   ` Richard Henderson
1998-11-28 13:15 Heinz Ulrich Stille
1998-11-28 14:24 ` Johannes G.D. Hausmann
1998-11-28 13:58   ` Heinz Ulrich Stille
1998-11-28 14:48     ` Stefan Schroepfer
1998-11-28 14:57       ` Heinz Ulrich Stille
1998-11-29 13:15         ` Johannes G.D. Hausmann
1998-11-29 13:02           ` Heinz Ulrich Stille
1998-11-29 18:01           ` B. James Phillippe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox