[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [f-cpu] IEEE FP exceptions



On Wed, Mar 05, 2003 at 10:25:38AM +0100, devik wrote:
[...]
> With one flag per register you could do:
> 
> divide(double x) attribute("force_all_floats_into_regs")
> {
>  clear_fpex(x); // remove exception flag from "x" register if any
>  y = seed(x);
>  for (i=0;i<6;i++)
>   y *= 2.0 - y*x;
>  if (is_bad_fp(y)) return divide_precise(x)
>  return y;
> }

Hmm... the canonical way is to return INF or NAN if something goes wrong.
You could also do it like this:

	double
	divide(double x) {
		double y;
		y = iterate(x, seed(x));
		switch (fpclassify(y)) {
			case FP_ZERO:
			case FP_NORMAL:
				return y;
			case FP_SUBNORMAL: /* gradual underflow */
			case FP_INFINITE:
			case FP_NAN:
				break;
		}
		return divide_precise(x)
	}

> all FP would set hidden flag of result register on computation
> error and then you could check it. You could not need to serialize
> FP at all.

What if you use an integer instruction to modify the result?  E.g.
clear or change the sign bit (fabs/fneg), modify the exponent (fscale)
and such?  They won't be aware of the extra bit, and won't maintain it
(or probably reset it to 0).  We would have to check the `fpex' flag
with an explicit `jmp.fpx' or `move.fpx' instruction (which would replace
the current `jmp.nan'/`move.nan').

> Alternate way is to have clear_fpex & is_bad_fp as global (aby
> FP would write to single status register) and then both of
> these would need to be FP barrier.

I prefer the non-serializing variant, with the option that the CPU may
trap if the flag is set on any of the input operands of an FP instruction
(just like it will do when the zero flag is set on a divisor).  That
means that the flag should go into the scoreboard.

We can also provide some bits in the FPU control register that specify
when the fpex flag will be set (to exclude conditions that aren't
interesting, e.g. inexact result or gradual underflow).

The remaining problem is that the fpex flags must be saved and restored
when a task switch occurs, either automatically or with an explicit
special instruction.

Another question is:  What do we do in SIMD mode?  Use a single flag
for all chunks?

-- 
 Michael "Tired" Riepe <Michael.Riepe@stud.uni-hannover.de>
 "All I wanna do is have a little fun before I die"
*************************************************************
To unsubscribe, send an e-mail to majordomo@seul.org with
unsubscribe f-cpu       in the body. http://f-cpu.seul.org/