[M3devel] Arithmetic Shift
dmuysers at hotmail.com
Sat Jul 4 12:31:46 CEST 2015
Sure, but then, since the amount of shift is a variable, it will oblige one
to index into a table of such constants, which is rather clumsy, and
possibly (?) poorly optimised by the compiler.
PROCEDURE ReadInt (VAR x: INTEGER) =
VAR ch: CHAR; n, y := 0;
WHILE ch >= 128 DO
INC (y, Word.LeftShift (ORD (ch) - 128, n));
INC (n, 7);
x := arithmetic-shift (Word.LeftShift (ORD (ch), 25), n - 25) + y
From: Antony Hosking
Sent: Saturday, July 04, 2015 12:11 PM
To: dirk muysers
Cc: m3devel at elegosoft.com
Subject: Re: [M3devel] Arithmetic Shift
In this code you use DIV by a constant power of two. That will turn into an arithmetic right shift.
On Jul 4, 2015, at 7:48 PM, dirk muysers <dmuysers at hotmail.com> wrote:
Why is there no arithmetic right shift operation in Modula-3 ?
Oberon software has a clever way to minimally encode
signed integers independently of their size.
PROCEDURE WriteInt (i: INTEGER) =
WHILE x < –64 OR x > 63 DO
Write (VAL (i MOD 128 + 128, CHAR));
i := i DIV 128;
Write (VAL (i MOD 128), CHAR));
Unfortunately it is impossible to implement the corresponding
decoder in M3, because it requires an arithmetic right shift
where the sign bit is replicated into the left end.
M3devel mailing list
M3devel at elegosoft.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the M3devel