Abstract
This memo describes the Floating Point package for
Cedar. It has not changed much from the Mesa 6 package for the Alto.
Compatibility
There have been many changes from the Mesa 5 floating point. In particular, the number format has changed to conform to the proposed IEEE floating point standard, the floating point definitions files have all changed, and compiler support is considerably different.
Distribution and support
For users within PARC/CSL, this package is described by [Ivy]<CedarX.X>Top>Real.df. Messages about floating point should be directed to CedarSupport^.pa.
There are various test programs available for floating point. If you need help, send a message to CedarSupport^.pa, as above.
Number Format
A Mesa REAL is a 32 bit floating point number consisting of a sign bit, 8-bit excess 127 exponent, hidden bit, and 23 bit mantissa with interpretation as the fraction part of a number between 1 and 2. Mesa REALs conform to the proposed IEEE standard [1].
Major features of the proposal are:
Careful specification of formats and arithmetic operations.
Careful specification of conversion to and from Decimal.
Gradual underflow, which reduces the bad effects of underflow.
Not-A-Numbers, distinguished bit patterns which either trap or propagate unchanged through operations.
Client settable rounding mode, exceptions individually maskable, "sticky" exception flags.
The Mesa implementation of IEEE floating point provides fixed modes for handling of rounding, denormalized numbers, and infinity. The implementation also enables a fixed set of exceptions. An optional interface provides variable modes for access to the full generality of the standard.
New language support
The Cedar Compiler provides the type REAL, and generates code for evaluation of expressions involving the operations on REALs +, -, *, /, ←, Float (conversion from LONG INTEGER to REAL, a widening automatically supplied by the compiler), and compare (=, #, <, <=, >=, >). In addition, the compiler supports REAL literals, REAL intervals, and the unary operations - (negation) and ABS [2]. The Cedar debugger will print REALs.
About the implementation
The Mesa compiler generates instructions for the operations mentioned above. Additional operations (Fix, Round) are declared as MACHINE CODE, they generate instructions as well. Floating point is part of the Cedar virtual machine. All operations appear to be implemented by microcode although parts of operations or all of an operation may in fact be implemented by a trap to software. Naturally, operations which trap are vastly slower than those implemented solely by microcode. It is the nature of the floating point standard that certain values are harder to handle than others so some operations are incompletely implemented.
There is a compiler switch (/f, /-f) for floating point. It should be used as /f or just left off altogether. (The -f switch generates procedure calls for the floating point operations.)
Available Interfaces
The interface Real provides the basic facilities needed by most users of floating point. Additional numerical functions are provided by RealFns. The interface RealOps supplies the same operations as Real, but with all the modes explicit, giving the full generality of the IEEE standard. RealConvert supplies some procedures for conversion of Mesa 6 REALs to and from other formats. Ieee supplies access to internal details of floating point numbers. Some of these facilities are described below. Users should look at the definitions files in case of any uncertainty; they represent the truth.
Do not use any of the procedures declared in Ieee, but feel free to reference the declarations of the number format.
What you need
Real, RealFns, and RealOps are implemented by the Cedar boot file. RealConvert is implemented by the module RealConvertImpl.
Notes on the definitions files
in Real (exported by RealImpl)
InitReals: PROCEDURE;
RealControl
: PROGRAM;
InitReals must be called or RealControl STARTed before any floating point operations are executed (including any initialization other than REAL literals which occur in a global frame containing a call to InitReals). It is ok to call InitReals more than once. Thi is done by something in the internals of Cedar.
RealException: SIGNAL [flags: ExceptionFlags, vp: REF Extended];
RealError
: ERROR;
RealException is raised whenever an enabled exception occurs. The parameter flags indicates which exceptions occurred during the faulted operation (including any which occurred but were not enabled). For operations called through the interface Real (or by the Mesa compiler), the only enabled exceptions are those listed under UsualExceptions above. Usually a catch phrase for RealException can RESUME. The client is expected to fix up the initial result represented by vp, then return the new value to use as the result of the faulted operation. If the client returns NIL, a default result specified by the IEEE standard will be used.
The exception invalidOperation when raised as a result of compare or any of the real to fixed point conversion operations is not resumable. If the client RESUMEs anyway, the ERROR RealError will be raised.
Fine point: because of the way SIGNAL catching is implemented, a catch phrase on a MACHINE CODE procedure (such as Fix or Round) or a catch phrase on a block enclosing floating point operations will not work; however, a catch phrase at least one procedure call removed from a floating point operation will work.
Clients wishing to test for uninitialized storage of
REAL types may wish to set that storage to the value Real.TrappingNaN. This distinguished operand will produce a
SIGNAL if it is ever picked up as an operand of a floating point operation (other than assignment).
Default results of exceptional conditions
fixOverflow: returns least significant bits of the correct result.
inexactResult: returns rounded version of preliminary result
invalidOperation: returns Not-a-Number characteristic of the faulted operation.
divisionByZero: returns Not-a-Number DivideInfinityNaN.
overflow: returns infinity of the correct sign.
underFlow: returns de-normalized number.
The Fix operations use rounding mode round-to-zero (truncation). The Round operations use mode round-to-nearest These operations can raise exceptions such as fixOverflow or invalidOperation.
Float is generated automatically by the compiler, but a client may wish to use it explicitly.
References
[1] "An Implementation Guide to a Proposed Standard for Floating Point Arithmetic", Jerome T. Coonen, Computer Magazine, January, 1980.
[2] Mesa 6.0 Compiler Update, Ed Satterthwaite, [Iris]<Mesa>Doc>Compiler60.memo, May 22, 1980.