gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Moving along with mc


From: Benjamin Kowarsch
Subject: Re: Moving along with mc
Date: Mon, 26 Jul 2021 13:51:13 +0900



On Mon, 26 Jul 2021 at 07:04, Gaius Mulley <mulley.gaius@gmail.com> wrote:

it should be possible to extend mc to translate SHIFT and ROTATE of word sized quantities fairly easily - will look into this at some point.

Since the dialect to be translated here is PIM, not ISO, may I suggest that you implement this in a Wirthian and not in an ISO manner.

Wirth has always implemented bit operations with specific discrete procedures, never one-size-fits-all procedures.

By contrast, SHIFT and ROTATE are distinctly ISO and they are problematic, typical committee creations.

The reason why these are bad designs is that there are logic and arithmetic variants.

For left shift/rotate, logic and arithmetic variants are identical, but for right shift/rotate they are not.

Consequently, in his various Modula-2 and Oberon compilers, Wirth has consistently implemented

* SHL for left shift
* SHR for logical right shift
* ASHR for arithmetic right shift

There is also the possibility one may need a shift through a carry bit as this allows the construction of cascading shifts on arbitrary sized data.

SHLC for left shift through a carry bit

https://github.com/m2sf/m2bsk/blob/master/src/lib/IntBitOps.def#L40

This way, user code can shift arbitrarily sized data one chunk at a time, using the carry bit to fill the right most bit in the next chunk.

A similar argument can be made for rotation. Besides, the procedures should be consistent, that is to say, if shifting is provided by separate procedures, then so should rotation if only for the sake of consistency of interface.

regards
benjamin
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]