DIRECTORY Basics; BitOps: CEDAR DEFINITIONS = BEGIN BitWord: TYPE = CARDINAL; BitDWord: TYPE = ARRAY [0 .. 2) OF CARDINAL; BitMWord: TYPE = LONG DESCRIPTOR FOR ARRAY CARDINAL OF BitWord; Long: TYPE = LONG CARDINAL; 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]; 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]; 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]; 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]; 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]; 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]; 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]; 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]; wordMasks: ARRAY [0 .. Basics.bitsPerWord] OF CARDINAL; doubleMasks: ARRAY [0 .. 2*Basics.bitsPerWord] OF BitDWord; END. Κ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 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 The externals BOOL and CARDINAL already exist! Handy constants 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 Cardinals Longs Moving bit fields Word as source Double as source Multiple as source Handy operations for containers Masking Arrays: Indexed by number of right-justified ones Κε˜Icodešœ ™ K™4K™8K˜KšΟk œ˜K˜KšΠbxœœ œ˜K˜Kšœ˜K˜Kšœ΅™΅K™Kšœϊ™ϊK™ŽK™KšœΚ™ΚK™K™QK˜K˜šœ™K˜Kšœ œœ˜Kš œ œœ œœ˜,Kšœ œœ œœœœœ ˜?—K˜šœ ™ K˜Kšœ ™ Kšœœœœ˜K˜—™K˜Kšœ œ˜,Kšœ œ˜.K˜Kšœ˜Kšœ˜K˜ Kšœ4˜4—K™šœ#™#K™™%K™]Kšœ™Kšœέ™έKšœp™pKšœ^™^KšœW™WKšœΖ™ΖK™ί—K™™K˜Kš ΟbœΠbkœœ3œœ œ˜pK˜Kš Ÿœ œœ œ3œœ˜‡K˜Kš Ÿœ œœ4œœ œ˜sK˜Kš Ÿœ œœ œ4œœ˜‹K˜Kš Ÿœ œœ4œœ œ˜uK˜Kš Ÿœ œœ œ4œ˜lK˜—šœ ™ K˜Kš Ÿœ œœAœœ œ˜†K˜Kš Ÿœ œœ œAœœ˜K˜Kš Ÿœ œœBœœ œ˜‰K˜Kš Ÿœ œœ œBœœ˜‘K˜Kš Ÿœ œœBœœ œ˜‹K˜Kš Ÿœ œœ œBœ˜‚K˜—™K˜Kš Ÿœ œœAœœ˜~K˜Kš Ÿœ œœOœœ˜•K˜Kš Ÿœ œœBœœ˜K˜Kš Ÿœ œœPœœ˜™K˜Kš Ÿœ œœBœœ˜ƒK˜KšŸœ œœPœ˜zK˜——K˜šœ™K˜šœ™K˜Kš Ÿœ œœOœcœœ˜ώK˜Kš Ÿœ œœOœdœœ˜‚K˜Kš Ÿœ œœOœdœ˜γK˜—K˜šœ™K˜Kš Ÿœ œœPœcœœ˜K˜Kš Ÿœ œœPœdœœ˜…K˜Kš Ÿœ œœPœdœ˜ζK˜K˜—šœ™K˜Kš Ÿœ œœPœcœœ˜ƒK˜Kš Ÿœ œœPœdœœ˜‡K˜Kš Ÿœ œœPœdœ˜θK˜——K˜™K˜KšŸœ œœœ˜BK˜KšŸœ œœœ˜@K˜KšŸœ œœœ˜BK˜Kš Ÿœ œœœœ˜VK˜Kš Ÿ œ œœœ œœ˜jK˜KšŸ œ œœœ˜FK˜KšŸœ œœœ˜DK˜KšŸ œ œœœ˜FK˜Kš Ÿ œ œœ œœ˜ZK˜Kš Ÿ œ œœ œ œœ˜nK˜KšŸ œ œœ2˜JK˜KšŸ œ œœ2˜HK˜KšŸ œ œœ2˜JK˜KšŸ œ œœ œ˜TK˜Kš Ÿœ œœ œ œ˜h—K˜™K˜Kšœ œœœ˜7šœ œœ ˜;K™)—K˜—Kšœ˜K˜—…—|,+