dynamic vs. static rounding

David Stewart uunet!thrain.anu.edu.au!des
Wed May 20 16:56:07 PDT 1992


I agree with Jerry Leichter <leichteralrw.com> and David Hough
<David.HoughaEng.Sun.COM> that there is a bit of confusion about what is
meanst by "static" and "dynamic", and I fell into a trap in my previous
posting by not being clear about that. David Hough wrote to me with the
comment that I should have said

"you need to be able to specify that a particular instruction either
rounds up or rounds down"

which I agree with. Eric Gosse pointed out that negations can
turn rounding down into rounding up, so only one of these is absolutely
needed for interval arithmetic.

With regards to the issue of ** scoping **, I would argue that static
scoping of rounding is appropriate. Static vs. dynamic scoping has been
argued over by the Lisp community, and static scoping seems to be the (now)
undisputed victor. The "set-and-forget" approach, where FPU registers are
set globally is asking for trouble -- good programming practise would be
to restore the old values after doing the operations using specialised
rounding. Compilers can do this by making the rounding mode register part
of the stack frame in any function/procedure. And dynamic scoping for
some of the newer micros with rounding modes specified in the opcode
would be expensive (as e.g. Conor O'Neill <conorainmos.co.uk> writes).

The question of proper syntax for dealing with rounding is something to talk
about. I've written some basic interval arithmetic routines for the RS/6000
I'm using, and it uses a "set-and-forget" approach where FPU registers are
set. Rounding modes are set by function calls so syntax is unchanged
-- easy and convenient syntax -- bad semantics. As an alternative to 
Bill Gibbons' proposal for rounding-type casts, the semantics of the
"set-and-forget" approach can be cleaned up, and made more efficient for
T800's and alpha's:
	double foo(double x, double y)
	{
		double sum;
		sum = x + y;	/* default rounding here */
		ROUND_UP();	/* set rounding */
		/* save rounding for function call -- as rounding changed */
		sum = bar(x,y);
		/* restore ROUND_UP() */
		sum = x + y;
		return sum;
		/* default rounding restored on return */
	}
Notes:1) Functions not setting/resetting rounding modes would compile unchanged.
      2) For processors whose opcodes contain the rounding mode, if ROUND_UP()
	etc are recognised by the compiler, the compiler could compile the
	following operations with the appropriate opcode(s).
      3) The rounding mode can be set for a series of operations, without
	having to repeatedly set & restore FPU registers for that architecture.
      4) NCEG/X3J11 discussion seems to generally prefer predefined macros to
	#pragma's, though this is not a crucial issue.
------------------------------------------------------------------------
David Stewart			Program in Advanced Computation
desathrain.anu.edu.au		School of Mathematical Sciences
				Australian National University



More information about the Numeric-interest mailing list