-- IeeeMode.mesa
-- Last Modified: August 27, 1982 1:02 pm
-- IEEE float mode control and exceptions

DIRECTORY
  Ieee USING [BitOn, IResultEnable, IResultSticky, MicroSticky, stickyFlags],
  Real USING [ExceptionFlags, Extended, Microcode, NoExceptions],
  RealOps USING [DefMode, InfinityMode, Mode, NormalizationMode, RoundingMode];

IeeeMode: CEDAR PROGRAM IMPORTS Ieee EXPORTS Ieee, Real, RealOps =
  BEGIN
  userMode: RealOps.Mode ← RealOps.DefMode;

  SetStickyFlags: PUBLIC PROC [new: Real.ExceptionFlags ← Real.NoExceptions]
    RETURNS [old: Real.ExceptionFlags] = {
    IF Real.Microcode THEN MicroStickySet[];
    old ← Ieee.stickyFlags;
    Ieee.stickyFlags ← new;
    };

  GetStickyFlags: PUBLIC PROC RETURNS [Real.ExceptionFlags] = {
    IF Real.Microcode THEN MicroStickySet[]; RETURN[Ieee.stickyFlags]; };

  SetMode: PUBLIC PROC [new: RealOps.Mode] RETURNS [old: RealOps.Mode] = {
    old ← userMode; userMode ← new; MicroStickySet[]; };

  GetMode: PUBLIC PROC RETURNS [RealOps.Mode] = {RETURN[userMode]; };

  MicroStickySet: PUBLIC PROC = TRUSTED {
    IF Real.Microcode THEN {
      xx: CARDINAL ←
	IF userMode.traps[inexactResult] THEN Ieee.IResultEnable ELSE 0;
      xx ← Ieee.MicroSticky[xx];
      IF Ieee.BitOn[xx, Ieee.IResultSticky] THEN
	Ieee.stickyFlags[inexactResult] ← TRUE;
      };
    };

  RealException: PUBLIC SIGNAL [
    flags: Real.ExceptionFlags, vp: REF Real.Extended]
    RETURNS [clientFixup: BOOLEAN ← FALSE] = CODE;

  RealError: PUBLIC ERROR = CODE;

  END.
L. Stewart, July 6, 1980  4:13 PM, Microcode sticky bit stuff added.
August 25, 1980  4:42 PM, LStewart; Formatting
September 28, 1980  8:06 PM; Stewart, Deleted individual twiddle procs.
17-Nov-81  1:12:39, Stewart, userMode uninitialized
June 3, 1982 11:41 am, L. Stewart, RealException REF
August 27, 1982 1:02 pm, L. Stewart, CEDAR