BitOps.mesa
Last edited by: Barth, April 12, 1984 2:19:15 pm PST
Last Edited by: Spreitzer, March 19, 1984 8:59:08 pm PST
DIRECTORY Basics;
BitOps: CEDAR DEFINITIONS =
BEGIN
This is an interface for sloshing around bit fields and switch values, extracting and inserting bit fields, and converting between switch values and booleans. There are two sets of procedures here: extractors/insertors, and movers/converters. The switch value routines are in a companion interface, BitSOps.
The first class, extractors/insertors, mediates between containers and "external" TYPEs. There are three kinds of containers: CARDINAL, ARRAY OF CARDINAL (the sub-case of 2-element ARRAYs has procedures specific to it), and ARRAY OF SwitchVal. There are three external TYPEs: BOOLEAN, CARDINAL, and LONG CARDINAL (a.k.a. Long). Thus, there are 2*4*3 = 24 of these procedures.

The second class, movers/converters, moves bit/switch fields between two containers, possibly doing conversion. There are 4^2 = 16 of these.
Increasing index means decreasing significance (the most significant bit is numbered 0). The least significant bit of a field is stored in the least significant bit of a container so that Mesa operations can be performed directly on containers which are 16 bits wide. Because of the method of numbering the bits and the alignment requirements the field width must be passed to each operation in order to compute how the bits in the containers are numbered.
There are also some boolean operations defined upon the multiple word containers.
The containers
BitWord: TYPE = CARDINAL;
BitDWord: TYPE = ARRAY [0 .. 2) OF CARDINAL;
BitMWord: TYPE = LONG DESCRIPTOR FOR ARRAY CARDINAL OF BitWord;
The externals
BOOL and CARDINAL already exist!
Long: TYPE = LONG CARDINAL;
Handy constants
LastWBit: CARDINAL = Basics.bitsPerWord - 1;
LastDBit: CARDINAL = 2*Basics.bitsPerWord - 1;
BitWordZero: BitWord = 0;
BitWordOnes: BitWord = 65535;
BitDWordZero: BitDWord = [0, 0];
BitDWordOnes: BitDWord = [BitWordOnes, BitWordOnes];
Extraction and Insertion procedures
Definition of parameters and results:
container: The array of bits/switch-values that the field is inserted into or extracted from.
containerWidth: The number of bits being used in the container. Must be less than or equal to the maximum size which the container can hold.
bitPosition, fieldPosition: The position of the bit, or most significant bit of a field, within the container. The most significant bit is labeled bit zero and the least significant bit is labeled as the field width - 1.
fieldWidth: The width of the field in bits. The last bit position of a field is fieldPosition + fieldWidth - 1.
source: An argument to insertion procedures. It is the value assigned to the described field.
result: The value of the described field. It is returned by the extraction procedures.
newContainer: The updated container returned by insertion procedures except for the multiple word procedures which utilize a call by address argument mechanism rather than a call by value mechanism.
si, how: Converting from booleans to switch values means updating one of the Q, U, or D strengths of the switch value. The si argument says which strength. The how argument says which strengths are used for TRUE and FALSE.
Bools
ExtractBoolFWord, EBFW: PROC [container: BitWord, containerWidth, bitPosition: CARDINAL] RETURNS [result: BOOL];
InsertBoolInWord, IBIW: PROC [source: BOOL, container: BitWord, containerWidth, bitPosition: CARDINAL] RETURNS [newContainer: BitWord];
ExtractBoolFDouble, EBFD: PROC [container: BitDWord, containerWidth, bitPosition: CARDINAL] RETURNS [result: BOOL];
InsertBoolInDouble, IBID: PROC [source: BOOL, container: BitDWord, containerWidth, bitPosition: CARDINAL] RETURNS [newContainer: BitDWord];
ExtractBoolFMultiple, EBFM: PROC [container: BitMWord, containerWidth, bitPosition: CARDINAL] RETURNS [result: BOOL];
InsertBoolInMultiple, IBIM: PROC [source: BOOL, container: BitMWord, containerWidth, bitPosition: CARDINAL];
Cardinals
ExtractCardinalFWord, ECFW: PROC [container: BitWord, containerWidth, fieldPosition, fieldWidth: CARDINAL] RETURNS [result: CARDINAL];
InsertCardinalInWord, ICIW: PROC [source: CARDINAL, container: BitWord, containerWidth, fieldPosition, fieldWidth: CARDINAL] RETURNS [newContainer: BitWord];
ExtractCardinalFDouble, ECFD: PROC [container: BitDWord, containerWidth, fieldPosition, fieldWidth: CARDINAL] RETURNS [result: CARDINAL];
InsertCardinalInDouble, ICID: PROC [source: CARDINAL, container: BitDWord, containerWidth, fieldPosition, fieldWidth: CARDINAL] RETURNS [newContainer: BitDWord];
ExtractCardinalFMultiple, ECFM: PROC [container: BitMWord, containerWidth, fieldPosition, fieldWidth: CARDINAL] RETURNS [result: CARDINAL];
InsertCardinalInMultiple, ICIM: PROC [source: CARDINAL, container: BitMWord, containerWidth, fieldPosition, fieldWidth: CARDINAL];
Longs
ExtractLongFWord, ELFW: PROC [container: BitWord, containerWidth, fieldPosition, fieldWidth: CARDINAL] RETURNS [result: Long];
InsertLongInWord, ILIW: PROC [source: Long, container: BitWord, containerWidth, fieldPosition, fieldWidth: CARDINAL] RETURNS [newContainer: BitWord];
ExtractLongFDouble, ELFD: PROC [container: BitDWord, containerWidth, fieldPosition, fieldWidth: CARDINAL] RETURNS [result: Long];
InsertLongInDouble, ILID: PROC [source: Long, container: BitDWord, containerWidth, fieldPosition, fieldWidth: CARDINAL] RETURNS [newContainer: BitDWord];
ExtractLongFMultiple, ELFM: PROC [container: BitMWord, containerWidth, fieldPosition, fieldWidth: CARDINAL] RETURNS [result: Long];
InsertLongInMultiple, ILIM: PROC [source: Long, container: BitMWord, containerWidth, fieldPosition, fieldWidth: CARDINAL];
Moving bit fields
Word as source
MoveWordToWord, MWTW: PROC [sourceContainer: BitWord, sourceContainerWidth, sourcePosition, sourceWidth: CARDINAL, destinationContainer: BitWord, destinationContainerWidth, destinationPosition, destinationWidth: CARDINAL] RETURNS [newContainer: BitWord];
MoveWordToDouble, MWTD: PROC [sourceContainer: BitWord, sourceContainerWidth, sourcePosition, sourceWidth: CARDINAL, destinationContainer: BitDWord, destinationContainerWidth, destinationPosition, destinationWidth: CARDINAL] RETURNS [newContainer: BitDWord];
MoveWordToMultiple, MWTM: PROC [sourceContainer: BitWord, sourceContainerWidth, sourcePosition, sourceWidth: CARDINAL, destinationContainer: BitMWord, destinationContainerWidth, destinationPosition, destinationWidth: CARDINAL];
Double as source
MoveDoubleToWord, MDTW: PROC [sourceContainer: BitDWord, sourceContainerWidth, sourcePosition, sourceWidth: CARDINAL, destinationContainer: BitWord, destinationContainerWidth, destinationPosition, destinationWidth: CARDINAL] RETURNS [newContainer: BitWord];
MoveDoubleToDouble, MDTD: PROC [sourceContainer: BitDWord, sourceContainerWidth, sourcePosition, sourceWidth: CARDINAL, destinationContainer: BitDWord, destinationContainerWidth, destinationPosition, destinationWidth: CARDINAL] RETURNS [newContainer: BitDWord];
MoveDoubleToMultiple, MDTM: PROC [sourceContainer: BitDWord, sourceContainerWidth, sourcePosition, sourceWidth: CARDINAL, destinationContainer: BitMWord, destinationContainerWidth, destinationPosition, destinationWidth: CARDINAL];
Multiple as source
MoveMultipleToWord, MMTW: PROC [sourceContainer: BitMWord, sourceContainerWidth, sourcePosition, sourceWidth: CARDINAL, destinationContainer: BitWord, destinationContainerWidth, destinationPosition, destinationWidth: CARDINAL] RETURNS [newContainer: BitWord];
MoveMultipleToDouble, MMTD: PROC [sourceContainer: BitMWord, sourceContainerWidth, sourcePosition, sourceWidth: CARDINAL, destinationContainer: BitDWord, destinationContainerWidth, destinationPosition, destinationWidth: CARDINAL] RETURNS [newContainer: BitDWord];
MoveMultipleToMultiple, MMTM: PROC [sourceContainer: BitMWord, sourceContainerWidth, sourcePosition, sourceWidth: CARDINAL, destinationContainer: BitMWord, destinationContainerWidth, destinationPosition, destinationWidth: CARDINAL];
Handy operations for containers
WordAND, WAND: PROC [op1, op2: BitWord] RETURNS [result: BitWord];
WordOR, WOR: PROC [op1, op2: BitWord] RETURNS [result: BitWord];
WordXOR, WXOR: PROC [op1, op2: BitWord] RETURNS [result: BitWord];
WordNOT, WNOT: PROC [op: BitWord, containerWidth: CARDINAL] RETURNS [result: BitWord];
WordShift, WShift: PROC [op: BitWord, containerWidth: CARDINAL, shift: INTEGER] RETURNS [result: BitWord];
DoubleAND, DAND: PROC [op1, op2: BitDWord] RETURNS [result: BitDWord];
DoubleOR, DOR: PROC [op1, op2: BitDWord] RETURNS [result: BitDWord];
DoubleXOR, DXOR: PROC [op1, op2: BitDWord] RETURNS [result: BitDWord];
DoubleNOT, DNOT: PROC [op: BitDWord, containerWidth: CARDINAL] RETURNS [result: BitDWord];
DoubleShift, DShift: PROC [op: BitDWord, containerWidth: CARDINAL, shift: INTEGER] RETURNS [result: BitDWord];
MulitipleAND, MAND: PROC [op1: BitMWord, op2: BitMWord, result: BitMWord];
MulitipleOR, MOR: PROC [op1: BitMWord, op2: BitMWord, result: BitMWord];
MulitipleXOR, MXOR: PROC [op1: BitMWord, op2: BitMWord, result: BitMWord];
MulitipleNOT, MNOT: PROC [op: BitMWord, containerWidth: CARDINAL, result: BitMWord];
MulitipleShift, MShift: PROC [op: BitMWord, containerWidth: CARDINAL, shift: INTEGER, result: BitMWord];
Masking Arrays:
wordMasks: ARRAY [0 .. Basics.bitsPerWord] OF CARDINAL;
doubleMasks: ARRAY [0 .. 2*Basics.bitsPerWord] OF BitDWord;
Indexed by number of right-justified ones
END.