mirror of
https://github.com/vishapoberon/compiler.git
synced 2026-10-10 02:47:23 +00:00
adding big-endian support across compiler, runtime, and library modules
- adding Platform.LittleEndian to centralize endianness detection - using SYSTEM.GET with correct byte offset for HUGEINT to smaller type reads on big-endian - fixing Reals.BytesToHex iteration direction and InitEndian for big-endian - fixing oocLowReal fraction, IsInfinity, IsNaN using Reals.Expo/SetExpo - fixing Math.ToREAL and MathL.exponent for big-endian - fixing In.Int and In.LongInt for big-endian - fixing outtest.wh byte iteration direction for big-endian - regenerating all bootstrap C sources - tested on ppc32
This commit is contained in:
parent
93c0198f18
commit
4dd3c395fe
198 changed files with 788 additions and 409 deletions
|
|
@ -161,49 +161,22 @@ PROCEDURE fraction*(x: REAL): REAL;
|
|||
significant) part of `x'. Hence the following relationship shall
|
||||
hold: x = scale(fraction(x), exponent(x)).
|
||||
*)
|
||||
VAR c: CHAR;
|
||||
BEGIN
|
||||
IF x=ZERO THEN RETURN ZERO
|
||||
ELSE
|
||||
(* Set top 7 bits of exponent to 0111111 *)
|
||||
S.GET(S.ADR(x)+3, c);
|
||||
c := CHR(((ORD(c) DIV 128) * 128) + 63); (* Set X0111111 (X unchanged) *)
|
||||
S.PUT(S.ADR(x)+3, c);
|
||||
(* Set bottom bit of exponent to 0 *)
|
||||
S.GET(S.ADR(x)+2, c);
|
||||
c := CHR(ORD(c) MOD 128); (* Set 0XXXXXXX (X unchanged) *)
|
||||
S.PUT(S.ADR(x)+2, c);
|
||||
Reals.SetExpo(x, 126); (* biased exponent 126 = 2^(-1), so x*2 gives [1.0, 2.0) *)
|
||||
RETURN x * 2.0;
|
||||
END
|
||||
(*
|
||||
CONST eZero={(hiBit+2)..29};
|
||||
BEGIN
|
||||
IF x=ZERO THEN RETURN ZERO
|
||||
ELSE RETURN S.VAL(REAL,(S.VAL(SET,x)*nMask)+eZero)*2.0 (* set the mantissa's exponent to zero *)
|
||||
END
|
||||
*)
|
||||
END fraction;
|
||||
|
||||
PROCEDURE IsInfinity * (real: REAL) : BOOLEAN;
|
||||
VAR c0, c1, c2, c3: CHAR;
|
||||
BEGIN
|
||||
S.GET(S.ADR(real)+0, c3);
|
||||
S.GET(S.ADR(real)+1, c2);
|
||||
S.GET(S.ADR(real)+2, c1);
|
||||
S.GET(S.ADR(real)+3, c0);
|
||||
RETURN (ORD(c0) MOD 128 = 127) & (ORD(c1) = 128) & (ORD(c2) = 0) & (ORD(c3) = 0)
|
||||
RETURN (Reals.Expo(real) = 255) & (S.VAL(SET, real) * {0..22} = {})
|
||||
END IsInfinity;
|
||||
|
||||
PROCEDURE IsNaN * (real: REAL) : BOOLEAN;
|
||||
VAR c0, c1, c2, c3: CHAR;
|
||||
BEGIN
|
||||
S.GET(S.ADR(real)+0, c3);
|
||||
S.GET(S.ADR(real)+1, c2);
|
||||
S.GET(S.ADR(real)+2, c1);
|
||||
S.GET(S.ADR(real)+3, c0);
|
||||
RETURN (ORD(c0) MOD 128 = 127)
|
||||
& (ORD(c1) DIV 128 = 1)
|
||||
& ((ORD(c1) MOD 128 # 0) OR (ORD(c2) # 0) OR (ORD(c3) # 0))
|
||||
RETURN (Reals.Expo(real) = 255) & (S.VAL(SET, real) * {0..22} # {})
|
||||
END IsNaN;
|
||||
|
||||
PROCEDURE sign*(x: REAL): REAL;
|
||||
|
|
|
|||
|
|
@ -68,7 +68,6 @@ MODULE ulmTypes;
|
|||
CONST
|
||||
bigEndian* = 0; (* SPARC, M68K etc *)
|
||||
littleEndian* = 1; (* Intel 80x86, VAX etc *)
|
||||
byteorder* = littleEndian; (* machine-dependent constant *)
|
||||
TYPE
|
||||
ByteOrder* = SYS.INT8; (* bigEndian or littleEndian *)
|
||||
|
||||
|
|
@ -79,10 +78,20 @@ MODULE ulmTypes;
|
|||
TYPE
|
||||
SetInt* = SYS.INT32; (* Types.Int32 type that corresponds to Types.Set *)
|
||||
VAR
|
||||
byteorder*: ByteOrder; (* detected at module initialisation *)
|
||||
msb*: SYS.SET32;
|
||||
msbIsMax*, msbIs0*: SYS.INT8;
|
||||
msbindex*, lsbindex*, nofbits*: SYS.INT32;
|
||||
|
||||
PROCEDURE DetectByteOrder;
|
||||
VAR test: SYS.INT32; c: CHAR;
|
||||
BEGIN
|
||||
test := 1; SYS.GET(SYS.ADR(test), c);
|
||||
IF c = 1X THEN byteorder := littleEndian
|
||||
ELSE byteorder := bigEndian
|
||||
END
|
||||
END DetectByteOrder;
|
||||
|
||||
PROCEDURE ToInt8*(int: Int32) : Int8;
|
||||
BEGIN
|
||||
RETURN SHORT(SHORT(int))
|
||||
|
|
@ -109,6 +118,7 @@ MODULE ulmTypes;
|
|||
END ToReal64;
|
||||
|
||||
BEGIN
|
||||
DetectByteOrder;
|
||||
|
||||
msb := SYS.VAL(SYS.SET32, MIN(SetInt));
|
||||
(* most significant bit, converted to a Types.Set *)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue