(* Copyright (C) 1991, Digital Equipment Corporation *) (* All rights reserved. *) (* See the file COPYRIGHT for a full description. *) (* Last modified on Wed Oct 28 15:39:31 MET 1992 by preschern *) (* modified on Thu Feb 20 22:57:50 PST 1992 by muller *) (* modified on Wed Sep 25 00:47:04 1991 by kalsow *) INTERFACE FPU; IMPORT Ctypes, Word; (* This interface defines the i387 hardware (and libm.a) defined interface to floating-point values *) (*------------------------------------------------- binary representation ---*) TYPE RealRep = RECORD significand: BITS 23 FOR [0 .. 8*1024*1024-1]; exponent: BITS 8 FOR [0 .. 255]; sign: BITS 1 FOR [0..1]; END; CONST RealBias = 127; TYPE LongRealRep = RECORD significand1 : BITS 32 FOR Word.T; significand0 : BITS 20 FOR [0..16_FFFFF]; exponent : BITS 11 FOR [0..16_7FF]; sign : BITS 1 FOR [0..1]; END; CONST LongRealBias = 1023; TYPE ExtendedRep = LongRealRep; CONST ExtendedBias = LongRealBias; (*--------------------------------------------------- IEEE classification ---*) TYPE FPClass = { SignalingNaN, QuietNaN, PosInfinity, NegInfinity, PosNormal, NegNormal, PosDenormal, NegDenormal, PosZero, NegZero }; PROCEDURE LongClass (x: LONGREAL): Ctypes.int; PROCEDURE RealClass (x: REAL): Ctypes.int; (* returns the IEEE defined class of its argument *) (*----------------------------------------------- control/status register ---*) TYPE Flag = BITS 1 FOR BOOLEAN; TYPE ControlStatus = RECORD rounding_mode : BITS 2 FOR RoundingMode; (* "sticky" bits, only reset by writing the control register *) se_inexact : Flag; se_underflow : Flag; se_overflow : Flag; se_divide0 : Flag; se_invalid : Flag; (* trap enable flags for the exceptions *) en_inexact : Flag; en_underflow : Flag; en_overflow : Flag; en_divide0 : Flag; en_invalid : Flag; (* exceptions that occurred during the most recent instruction *) ex_inexact : Flag; ex_underflow : Flag; ex_overflow : Flag; ex_divide0 : Flag; ex_invalid : Flag; ex_unimplemented : Flag; reserved1 : BITS 5 FOR [0..31]; condition : Flag; (* result of most recent compare instruction *) reserved0 : BITS 8 FOR [0..255]; END; TYPE RoundingMode = { ToNearest, ToZero, ToPlusInfinity, ToMinusInfinity }; PROCEDURE GetStatus (): INTEGER(*ControlStatus*); (* returns the current setting of the floating point control registers *) PROCEDURE SetStatus (new: INTEGER): INTEGER(*ControlStatus*); (* sets the floating point control registers and returns their previous state*) PROCEDURE SetRounding(new: INTEGER):INTEGER(*RoundingMode*); (* sets the rounding mode and returns its previous value *) PROCEDURE SetInexact (new: INTEGER): INTEGER(*BOOLEAN*); (* sets the "sticky inexact bit" and returns its old value *) (*--------------------------------------------- standard? IEEE operations ---*) PROCEDURE IsNaN (x: LONGREAL): INTEGER (*BOOLEAN*); (* return 1 if x is NaN, 0 otherwise. *) PROCEDURE CopySign (x, y: LONGREAL): LONGREAL; (* return 'x' with the sign of 'y'. *) PROCEDURE Remainder (x, y: LONGREAL): LONGREAL; (* returns the remainder r := x - n*y where n is the integer nearest the exact value of x/y. Additionally if |n-x/y|=1/2, then n is even. Consequently the remainder is computed exactly and |r| < |y|/2. Remainder (x, 0.0) and Remainder (infinity, y) produce NaN. *) PROCEDURE IsFinite (x: LONGREAL): INTEGER (*BOOLEAN*); (* = 1 if -infinity < x < +infinity, otherwise = 0 *) PROCEDURE BinaryLog (x: LONGREAL): LONGREAL; (* for x finite, non-zero, and above the underflow threshold, returns the integer valued floating-point number n, such that 1 < ABS (x) / (2^n) < 2. Note that BinaryLog (+infinity) = +infinity, and BinaryLog (0) = -infinity (and causes a division-by-zero error). *) PROCEDURE BinaryPower (x: LONGREAL; n: INTEGER): LONGREAL; (* returns x * (2^n) *) END FPU.