zimmerle@jimi.UUCP (Robert Zimerle) (08/27/87)
>Organization: UNLV Computer Science and Electrical Engineering
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?
Turbo Pascal and "C" have native bit-shifting operations, but not
Modula-2. Was this omission a wise design decision? I would like
to read some opinions on this question.
ken@CS.ROCHESTER.EDU (Ken Yap) (08/27/87)
>Organization: U of Rochester, CS Dept, Rochester, NY In article <632@jimi.cs.unlv.edu> zimmerle@jimi.cs.unlv.edu (Robert Zimmerle) w rites: |Turbo Pascal and "C" have native bit-shifting operations, but not |Modula-2. Was this omission a wise design decision? I would like |to read some opinions on this question. Yes, but if you're going to compare, Turbo Pascal is not standard Pascal. A good question though is: what do people use bit shifting for in C and how would one write the equivalent in M-2? I know I use bit shifting to (1) make bitmasks, which M-2 can do with BITSETs and (2) (not so much now) multiply and divide, which shouldn't be a BITSET operation anyhow. So what can BITSETs not do? Ken
smith@COS.COM (Steve Smith) (09/04/87)
In article <8708271750.AA03034@cayuga.cs.rochester.edu> ken@CS.ROCHESTER.EDU (Ken Yap) writes: >A good question though is: what do people use bit shifting for in >C and how would one write the equivalent in M-2? I know I use bit >shifting to (1) make bitmasks, which M-2 can do with BITSETs and >(2) (not so much now) multiply and divide, which shouldn't be >a BITSET operation anyhow. So what can BITSETs not do? The main use that I've found for bit twiddling, shifting, etc. is a devilish contraption known as a device regester. This refers especially to UARTs, DMA chips, etc, although CPU status regesters have the same problems. For their own good (:-) reasons, hardware designers tend to put the fields you're interested in someplace other than the beginning of a word. For single bit values, this is no problem - bitsets are just great. However, for multibit numeric values, this gets grubby. In assembly language, you just mask off the part you're interested in and shift it over into the least significant position, where your compare instructions can handle it sensibly. In Pascal, you declare your register as a PACKED RECORD of however you want things handled. This should compile into a mask-and-shift just like the assembly version. (I'm an optomist :-) I really don't see a clean way of doing a mask, shift, and compare in M2. The mask is done easily enough with a bitset, but then how do you do a sensible compare? How do you tell that (say) {10, 12} > {10, 11} without doing a type transfer onto a CARDINAL? Note that a program full of type transfers is prime ammunition for the anti-strong typing crowd. -- __ -- Steve / / \ / "Truth is stranger than S. G. Smith I \ O | _ O \ I fiction because fiction smith@cos.com / \__/ / has to make sense."
randy@oresoft.UUCP (Randy Bush) (09/04/87)
smith@cos.UUCP (Steve Smith) writes: >The main use that I've found for bit twiddling, shifting, etc. is a >devilish contraption known as a device regester. This refers especially >to UARTs, DMA chips, etc, although CPU status regesters have the same >problems... As Modula-2 is purported to be a SIL which provices for all aspects of programming a machine, one would expect reasonable implementations to allow one to describe a device register as a record and not have to mash on the bits by hand. -- Randy Bush, Compiler Group, Oregon Software, Portland Oregon (503) 245-2202 uucp: ..!tektronix!oresoft!randy Telemail: RBush Fidonet: 1:105/6