[comp.lang.modula2] Bitshift operations

wille@ethz.UUCP (M. Wille) (09/10/87)

zimmerle@jimi.UUCP (Robert Zimerle)

>Supposedly, Modula-2 is a good systems programming language; but it
>has no native bit-shifting operations.  Aren't bit-shifting 
>operations important tools for EFFICIENT systems programming?

>>Actually, Prof. Wirth provided a slew of extremely machine
>>dependent procedures in module SYSTEM for his single pass compiler.
>>These procs expand to inline code and are extremely efficient.

The one-pass-compiler mentioned in the last message is a version for
the NS32000 family of processors. It provides three shift procedures
with the module SYSTEM that are specified as follows:

  PROCEDURE ASH(x: T; n: INTEGER):T;
  PROCEDURE LSH(x: T; n: INTEGER):T;
  PROCEDURE ROT(x: T; n: INTEGER):T;

The procedures are directly compiled into the corresponding 
instructions of the NS32000 processor. The parameter type T may be any
of the predefined types, e.g. INTEGER, LONGINT, CARDINAL.

>>Since such things are going to vary from machine to machine anyway,
>>perhaps Prof. Wirth decided that it should be up to Modula implementors
>>for various machines to include shifts or not.

The above mentioned compiler produces shift operations when powers of two
are used as constant operands in multiplications and divisions. Depending
on the type of the first operand, i.e. signed or unsigned, an arithmetic
or logical shift is generated. For MOD operations that have powers of two
as constant operand mask operations are used.

Although the first solution is very efficient, it is bad concerning
the portability of the program. However, when the special procedures are
used e.g. within device drivers machine independance is lost anyway.
Other tasks to use the shift procedures, e.g. to speed up the calculation
of expressions seem to be bad. This should be left to the compiler
which may solve it as described above.
                Matthias Wille
------------------------------------------------------------------
   Matthias Wille             |  CSNET: wille@ifi.ethz.ch
   Institut fuer Informatik   |         wille@komsys.ifi.ethz.ch
   ETH - Zentrum              |  UUCP:  ..mcvax!cernvax!ethz!wille
CH-8092 Zuerich Switzerland   |  Phone: (00411) 256 23 51

soper@encore.UUCP (09/13/87)

In article <198@bernina.UUCP> wille@ethz.UUCP (M. Wille) writes:
>The above mentioned compiler produces shift operations when powers of two
>are used as constant operands in multiplications and divisions. Depending
>on the type of the first operand, i.e. signed or unsigned, an arithmetic

It astonishes me that Wirth could fall for the idea of using shifts in place
of signed division. I ripped this out of the compiler when I ported it to
my company's system.
-- 
Pete Soper, Encore Computer Corp
uucp: {necntc,talcott,ihnp4,decvax,allegra}!encore!soper