Cedar Floating Point To Cedar Project Date January 14, 1984 From L. Stewart Location PARC Subject Cedar Floating Point Package Organization CSL XEROX Release as /Indigo/Cedar/Documentation/FloatingPointDoc.tioga Came from /Indigo/Cedar/Documentation/FloatingPointDoc.tioga Last edited by L. Stewart, January 14, 1984 5:11 pm 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]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]Doc>Compiler60.memo, May 22, 1980. Ê– "Cedar" style˜Icenter•Mark centerHeaderšÐbl˜ImemoHeadšÏsœžœžœ˜+Lšžœ žœ˜Lšžœž œ˜6Ilogošœ˜Iabstractš ž Ït3ž Ÿ3œž Ÿžœ Ÿ˜®šžŸœ3ŸE˜headšÏb ˜ Ibodyšœ†žœ€˜Š—š ˜Pšœš˜šPšœ~˜~—š  ˜ PšœžœÄžœžœ˜ÿ˜#P˜;P˜8P˜>P˜fP˜Z—Pšœžœ€˜Ÿ—š ˜Pšœ%žœOžœ'ž œž7œIžœ žœ6žœ%žœ˜«—š ˜Pšœž œð˜ýPšœ¼˜¼—š ˜PšœÏiœw¡œ¡œkžœ ¡ œ3žœ¡œÐ˜×P˜t—š  ˜ Pšœ}˜}—Oš ˜Oš ˜PšÏo Ðos œ˜š¢ £ œ˜Pšœ(žœ\žœG¡œa˜¸—PšÐbo £3˜@š¤ £˜Pš œ<¡œ¢œ¼žœF¢œbžœ$žœ˜€Pšœ›žœ žœ˜ÎPšž·˜·—šœ5žœnžœ]˜ŠOš¡)˜)PšœC˜CP˜=P˜PP˜8P˜0P˜)—P˜ÀP˜]š  ˜ Pšœg¡œ˜ˆP˜_———…—”7