[M3devel] Arithmetic Shift
dirk muysers
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;
BEGIN
Read (ch);
WHILE ch >= 128 DO
INC (y, Word.LeftShift (ORD (ch) - 128, n));
INC (n, 7);
Read (ch)
END;
x := arithmetic-shift (Word.LeftShift (ORD (ch), 25), n - 25) + y
END ReadInt;
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) =
BEGIN
WHILE x < –64 OR x > 63 DO
Write (VAL (i MOD 128 + 128, CHAR));
i := i DIV 128;
END;
Write (VAL (i MOD 128), CHAR));
END Write;
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
https://mail.elegosoft.com/cgi-bin/mailman/listinfo/m3devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20150704/beadc2c2/attachment-0002.html>
More information about the M3devel
mailing list