🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #3817

Re: Bitshift operations

#3817
From: M. Wille
Date: Thu, 10 Sep 1987 07:40
44 lines
2716 bytes
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
Technical Details
Message-ID: <198@bernina.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!seismo!mcvax!cernvax!ethz!wille

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!seismo!mcvax!cernvax!ethz!wille
From: wille@ethz.UUCP (M. Wille)
Newsgroups: comp.lang.modula2
Subject: Re: Bitshift operations
Message-ID: <198@bernina.UUCP>
Date: Thu, 10-Sep-87 03:40:50 EDT
Article-I.D.: bernina.198
Posted: Thu Sep 10 03:40:50 1987
Date-Received: Sat, 12-Sep-87 15:34:29 EDT
Reply-To: wille@ethz.UUCP (M. Wille)
Organization: ETH Zuerich, Switzerland
Lines: 44